Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 20 additions & 27 deletions frame/qml/PanelToolTip.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Window 2.15
import org.deepin.ds 1.0
import org.deepin.dtk 1.0
import org.deepin.dtk.style as DStyle

Item {
id: control
Expand All @@ -17,7 +17,7 @@ Item {
property var toolTipWindow: Panel.toolTipWindow
property int toolTipX: 0
property int toolTipY: 0
property bool readyBinding: false
readonly property bool readyBinding: !!toolTipWindow && toolTipWindow.currentItem === control
property bool openPending: false
// WM_NAME, used for kwin.
property string windowTitle: "dde-shell/paneltooltip"
Expand Down Expand Up @@ -50,37 +50,16 @@ Item {
if (!toolTipWindow)
return

if (toolTipWindow.visible) {
toolTipWindow.close()
toolTipWindow.currentItem = null
Qt.callLater(function () {
if (!toolTip.visible) {
control.open()
}
})
return
}

readyBinding = Qt.binding(function () {
return toolTipWindow && toolTipWindow.currentItem === control
})

if (toolTipWindow.currentItem)
toolTipWindow.currentItem.close()
toolTipWindow.currentItem = control
openPending = true
Qt.callLater(function () {
if (!toolTipWindow || !openPending || !readyBinding || toolTipWindow.currentItem !== control)
return

toolTipWindow.requestUpdateGeometry()
})
toolTipWindow.requestUpdateGeometry()
}

function close()
{
openPending = false
if (!toolTipWindow)
return

if (!readyBinding)
return

Expand All @@ -103,6 +82,20 @@ Item {
toolTipWindow.show()
}

onVisibleChanged: {
if (!visible)
close()
}
Component.onDestruction: close()

Connections {
target: control.Window.window
function onVisibleChanged() {
if (!target.visible)
control.close()
}
}

Connections {
target: toolTipWindow
function onUpdateGeometryFinished()
Expand All @@ -115,7 +108,7 @@ Item {
id: toolTip
visible: readyBinding
anchors.centerIn: parent
parent: toolTipWindow ? toolTipWindow.contentItem : control
parent: readyBinding ? toolTipWindow.contentItem : control
font {
family: DTK.fontManager.t8.family
pixelSize: DTK.fontManager.t8.pixelSize
Expand Down
3 changes: 2 additions & 1 deletion panels/dock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ configure_file(environments.h.in environments.h @ONLY)
find_package(PkgConfig REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} COMPONENTS Core DBus Gui Qml WaylandCompositor Widgets WaylandClient)
find_package(DdeTrayLoader REQUIRED)
find_package(TreelandProtocols 0.7.0 REQUIRED)
find_package(TreelandProtocols 0.9.0 REQUIRED)
pkg_check_modules(WaylandClient REQUIRED IMPORTED_TARGET wayland-client)

file(
Expand Down Expand Up @@ -63,6 +63,7 @@ qt_generate_wayland_protocol_client_sources(dockpanel
NO_INCLUDE_CORE_ONLY
FILES
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-wallpaper-color-v1.xml
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-foreign-toplevel-manager-unstable-v3.xml
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-xwindow-control-unstable-v1.xml
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-region-watch-unstable-v1.xml
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-layer-shell-extension-unstable-v1.xml
Expand Down
2 changes: 2 additions & 0 deletions panels/dock/dockhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class DockHelper : public QObject

void enterScreen(QScreen *screen);
void leaveScreen();

virtual QObject *dockPreviewContext(QWindow *anchor) { return nullptr; }

// Move XEmbed window relative to anchor window's surface (no-op on X11)
virtual bool moveXEmbedWindow(uint32_t wid, double dx, double dy, QQuickWindow *anchorWindow = nullptr) { return false; }
Expand Down
5 changes: 5 additions & 0 deletions panels/dock/dockpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ bool DockPanel::debugMode() const
#endif
}

QObject *DockPanel::dockPreviewContext(QObject *anchor)
{
return m_helper ? m_helper->dockPreviewContext(qobject_cast<QWindow *>(anchor)) : nullptr;
}

void DockPanel::openDockSettings()
{
qCDebug(dockLog) << "openDockSettings";
Expand Down
5 changes: 4 additions & 1 deletion panels/dock/dockpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ class DockPanel : public DS_NAMESPACE::DPanel, public QDBusContext

Q_INVOKABLE void openDockSettings();

// All dock applets share the panel's Wayland tooltip/preview context.
Q_INVOKABLE QObject *dockPreviewContext(QObject *anchor);

Q_INVOKABLE void notifyDockPositionChanged(int offsetX, int offsetY);

// Move XEmbed window relative to anchor window's surface (Wayland only)
Expand Down Expand Up @@ -183,7 +186,7 @@ private Q_SLOTS:
QPointF m_cursorPosition;
ColorTheme m_theme;
HideState m_hideState;
DockHelper* m_helper;
DockHelper* m_helper = nullptr;
QPointer<QScreen> m_dockScreen;
bool m_compositorReady;
bool m_launcherShown;
Expand Down
2 changes: 1 addition & 1 deletion panels/dock/taskmanager/taskmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ bool TaskManager::load()
{
auto platformName = QGuiApplication::platformName();
if (QStringLiteral("wayland") == platformName) {
m_windowMonitor.reset(new TreeLandWindowMonitor());
m_windowMonitor.reset(new TreeLandWindowMonitor(parentApplet()));
}

#ifdef BUILD_WITH_X11
Expand Down
144 changes: 55 additions & 89 deletions panels/dock/taskmanager/treelandwindowmonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
#include "taskmanager.h"
#include "treelandwindow.h"

#include <QPointer>
#include <QWindow>

Check warning on line 12 in panels/dock/taskmanager/treelandwindowmonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QWindow> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QIODevice>

Check warning on line 14 in panels/dock/taskmanager/treelandwindowmonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QIODevice> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QPointer>

Check warning on line 15 in panels/dock/taskmanager/treelandwindowmonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPointer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QVarLengthArray>

Check warning on line 16 in panels/dock/taskmanager/treelandwindowmonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QVarLengthArray> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QtWaylandClient/private/qwaylandwindow_p.h>

#include <cstdint>

Check warning on line 18 in panels/dock/taskmanager/treelandwindowmonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <cstdint> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <utility>

Check warning on line 19 in panels/dock/taskmanager/treelandwindowmonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <utility> not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace dock {
ForeignToplevelManager::ForeignToplevelManager(TreeLandWindowMonitor* monitor)
Expand All @@ -30,58 +31,16 @@
connect(handle, &ForeignToplevelHandle::handlerIsReady, m_monitor, &TreeLandWindowMonitor::handleForeignToplevelHandleAdded, Qt::UniqueConnection);
}

TreeLandDockPreviewContext::TreeLandDockPreviewContext(struct ::treeland_dock_preview_context_v3 *context)
: QWaylandClientExtensionTemplate<TreeLandDockPreviewContext>(1)
, m_isPreviewEntered(false)
, m_isDockMouseAreaEnter(false)
, m_hideTimer(new QTimer(this))
{
init(context);

m_hideTimer->setSingleShot(true);
m_hideTimer->setInterval(800);

connect(m_hideTimer, &QTimer::timeout, this, [this](){
if (!m_isDockMouseAreaEnter && !m_isPreviewEntered) {
emit closed();
close();
}
}, Qt::QueuedConnection);
}

TreeLandDockPreviewContext::~TreeLandDockPreviewContext()
{
if (isInitialized())
destroy();
}

void TreeLandDockPreviewContext::showWindowsPreview(QByteArray windowsId, int32_t previewXoffset, int32_t previewYoffset, uint32_t direction)
{
m_isDockMouseAreaEnter = true;
show(windowsId, previewXoffset, previewYoffset, direction);
}

void TreeLandDockPreviewContext::hideWindowsPreview()
{
m_isDockMouseAreaEnter = false;
m_hideTimer->start();
}

void TreeLandDockPreviewContext::treeland_dock_preview_context_v3_enter()
{
m_isPreviewEntered = true;
}

void TreeLandDockPreviewContext::treeland_dock_preview_context_v3_leave()
TreeLandWindowMonitor::TreeLandWindowMonitor(QObject *panel, QObject *parent)
:AbstractWindowMonitor(parent)
, m_panel(panel)
, m_fullscreenState(false)
{
m_isPreviewEntered = false;
m_hideTimer->start();
}

TreeLandWindowMonitor::TreeLandWindowMonitor(QObject* parent)
:AbstractWindowMonitor(parent)
, m_fullscreenState(false)
TreeLandWindowMonitor::~TreeLandWindowMonitor()
{
releaseDockPreviewContext();
}

void TreeLandWindowMonitor::start()
Expand All @@ -97,15 +56,15 @@

void TreeLandWindowMonitor::stop()
{
releaseDockPreviewContext();
m_foreignToplevelManager.reset(nullptr);
}


void TreeLandWindowMonitor::clear()
{
clearTrackedWindows();
m_windows.clear();
m_dockPreview.reset(nullptr);
releaseDockPreviewContext();
updateFullscreenState();
}

Expand All @@ -121,9 +80,33 @@

void TreeLandWindowMonitor::hideItemPreview()
{
if (m_dockPreview.isNull())
if (m_dockPreview)
QMetaObject::invokeMethod(m_dockPreview, "hideWindowsPreview", Qt::DirectConnection);
}

void TreeLandWindowMonitor::ensureDockPreviewContext(QWindow *anchor)
{
QObject *context = nullptr;
if (m_panel)
QMetaObject::invokeMethod(m_panel, "dockPreviewContext", Qt::DirectConnection,
Q_RETURN_ARG(QObject *, context), Q_ARG(QObject *, anchor));
if (m_dockPreview == context)
return;

releaseDockPreviewContext();
if (!context)
return;
m_dockPreview->hideWindowsPreview();
m_dockPreview = context;
connect(context, SIGNAL(closed()), this, SIGNAL(previewShouldClear()));
connect(context, &QObject::destroyed, this, &TreeLandWindowMonitor::previewShouldClear);
}

void TreeLandWindowMonitor::releaseDockPreviewContext()
{
hideItemPreview();
if (m_dockPreview)
disconnect(m_dockPreview, nullptr, this, nullptr);
m_dockPreview.clear();
}

void TreeLandWindowMonitor::requestPreview(QAbstractItemModel *sourceModel,
Expand All @@ -132,47 +115,30 @@
int32_t previewYoffset,
uint32_t direction)
{
if (!m_foreignToplevelManager->isActive()) {
if (!sourceModel || !m_foreignToplevelManager || !m_foreignToplevelManager->isActive()) {
return;
}

if (m_dockPreview.isNull()) {
auto window = relativePositionItem;
if (!window) return;
auto waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow*>(window->handle());
if (!waylandWindow) return;

auto context = m_foreignToplevelManager->get_dock_preview_context(waylandWindow->wlSurface());
m_dockPreview.reset(new TreeLandDockPreviewContext(context));
connect(window, &QWindow::visibleChanged, m_dockPreview.get(), [this]() {
m_dockPreview.reset();
});
connect(m_dockPreview.get(), &TreeLandDockPreviewContext::closed, this, [this]() {
// 当预览关闭时,发出信号清空过滤状态
emit previewShouldClear();
});
QVarLengthArray<uint32_t> array;
for (int i = 0; i < sourceModel->rowCount(); ++i) {
QModelIndex index = sourceModel->index(i, 0);
uint32_t winId = index.data(TaskManager::WinIdRole).toUInt();
if (winId != 0) {
array.append(winId);
}
}

m_dockPreview->m_isDockMouseAreaEnter = true;
if (array.isEmpty())
return;

if (sourceModel && sourceModel->rowCount() > 0) {
QVarLengthArray<uint32_t> array;
for (int i = 0; i < sourceModel->rowCount(); ++i) {
QModelIndex index = sourceModel->index(i, 0);
uint32_t winId = index.data(TaskManager::WinIdRole).toUInt();
if (winId != 0) {
array.append(winId);
}
}
ensureDockPreviewContext(relativePositionItem);
if (!m_dockPreview)
return;

if (!array.isEmpty()) {
QByteArray byteArray;
int size = array.size() * sizeof(uint32_t);
byteArray.resize(size);
memcpy(byteArray.data(), array.constData(), size);
m_dockPreview->showWindowsPreview(byteArray, previewXoffset, previewYoffset, direction);
}
}
const QByteArray windows(reinterpret_cast<const char *>(array.constData()), array.size() * sizeof(uint32_t));
QMetaObject::invokeMethod(m_dockPreview, "showWindowsPreview", Qt::DirectConnection,
Q_ARG(QByteArray, windows), Q_ARG(int, previewXoffset),
Q_ARG(int, previewYoffset), Q_ARG(uint, direction));
}

void TreeLandWindowMonitor::requestUpdateWindowIconGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) const
Expand Down
Loading
Loading