From d002f224180c1251f1e492948378d527e3412257 Mon Sep 17 00:00:00 2001 From: deepin-ci-robot Date: Mon, 2 Dec 2024 09:40:37 +0000 Subject: [PATCH] sync: from linuxdeepin/dtkgui Synchronize source files from linuxdeepin/dtkgui. Source-pull-request: https://github.com/linuxdeepin/dtkgui/pull/285 --- .../dtreelandplatformwindowinterface.cpp | 101 ++++++++++-------- .../dtreelandplatformwindowinterface.h | 13 +++ 2 files changed, 68 insertions(+), 46 deletions(-) diff --git a/src/plugins/platform/treeland/dtreelandplatformwindowinterface.cpp b/src/plugins/platform/treeland/dtreelandplatformwindowinterface.cpp index ac65737..4c603de 100644 --- a/src/plugins/platform/treeland/dtreelandplatformwindowinterface.cpp +++ b/src/plugins/platform/treeland/dtreelandplatformwindowinterface.cpp @@ -148,35 +148,11 @@ bool MoveWindowHelper::windowEvent(QWindow *w, QEvent *event) return true; } - -class Q_DECL_HIDDEN WindowEventFilter : public QObject { -public: - WindowEventFilter(QObject *parent = nullptr, DTreeLandPlatformWindowInterface *interface = nullptr) - : QObject(parent) - , m_interface(interface) - { - } - -public: - bool eventFilter(QObject *watched, QEvent *event) override { - if (event->type() == QEvent::PlatformSurface) { - QPlatformSurfaceEvent *se = static_cast(event); - if (se->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated) { - m_interface->doSetEnabledNoTitlebar(); - } - } - return QObject::eventFilter(watched, event); - } -private: - DTreeLandPlatformWindowInterface *m_interface; -}; - DTreeLandPlatformWindowInterface::DTreeLandPlatformWindowInterface(QObject *parent, QWindow *window) : QObject(parent) , m_window(window) { m_manager = PersonalizationManager::instance(); - m_window->installEventFilter(new WindowEventFilter(this, this)); connect(m_manager, &PersonalizationManager::activeChanged, this, [this](){ if (m_manager->isActive()) { handlePendingTasks(); @@ -186,6 +162,29 @@ DTreeLandPlatformWindowInterface::DTreeLandPlatformWindowInterface(QObject *pare if (!MoveWindowHelper::mapped.value(window)) { Q_UNUSED(new MoveWindowHelper(window)) } + + m_window->winId(); + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + auto waylandWindow = m_window->nativeInterface(); +#else + auto waylandWindow = dynamic_cast(m_window->handle()); +#endif + + if (!waylandWindow) { + qWarning() << "waylandWindow is nullptr!!!"; + return; + } + + m_waylandWindow = waylandWindow; + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + connect(waylandWindow, &QNativeInterface::Private::QWaylandWindow::surfaceCreated, this, &DTreeLandPlatformWindowInterface::onSurfaceCreated); + connect(waylandWindow, &QNativeInterface::Private::QWaylandWindow::surfaceDestroyed, this, &DTreeLandPlatformWindowInterface::onSurfaceDestroyed); +#else + connect(waylandWindow, &QtWaylandClient::QWaylandWindow::wlSurfaceCreated, this, &DTreeLandPlatformWindowInterface::onSurfaceCreated); + connect(waylandWindow, &QtWaylandClient::QWaylandWindow::wlSurfaceDestroyed, this, &DTreeLandPlatformWindowInterface::onSurfaceDestroyed); +#endif } DTreeLandPlatformWindowInterface::~DTreeLandPlatformWindowInterface() @@ -193,6 +192,20 @@ DTreeLandPlatformWindowInterface::~DTreeLandPlatformWindowInterface() } +void DTreeLandPlatformWindowInterface::onSurfaceCreated() +{ + doSetEnabledNoTitlebar(); + doSetEnabledBlurWindow(); +} + +void DTreeLandPlatformWindowInterface::onSurfaceDestroyed() +{ + if (m_windowContext) { + m_windowContext->deleteLater(); + m_windowContext = nullptr; + } +} + PersonalizationWindowContext *DTreeLandPlatformWindowInterface::getWindowContext() { if (!m_manager->isSupported()) { @@ -205,20 +218,16 @@ PersonalizationWindowContext *DTreeLandPlatformWindowInterface::getWindowContext if (m_windowContext) { return m_windowContext; } - m_window->winId(); -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - auto waylandWindow = m_window->nativeInterface(); -#else - auto waylandWindow = dynamic_cast(m_window->handle()); -#endif - if (!waylandWindow) { + + if (!m_waylandWindow) { qWarning() << "waylandWindow is nullptr!!!"; return nullptr; } + #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - auto surface = waylandWindow->surface(); + auto surface = m_waylandWindow->surface(); #else - auto surface = waylandWindow->waylandSurface()->object(); + auto surface = m_waylandWindow->waylandSurface()->object(); #endif if (!surface) { qWarning() << "waylandSurface is nullptr!!!"; @@ -227,12 +236,6 @@ PersonalizationWindowContext *DTreeLandPlatformWindowInterface::getWindowContext if (!m_windowContext) { m_windowContext = new PersonalizationWindowContext(m_manager->get_window_context(surface)); - connect(m_window, &QWindow::visibleChanged, m_windowContext, [this](bool visible){ - if (!visible) { - m_windowContext->deleteLater(); - m_windowContext = nullptr; - } - }); } return m_windowContext; @@ -255,13 +258,20 @@ bool DTreeLandPlatformWindowInterface::setEnabledNoTitlebar(bool enable) void DTreeLandPlatformWindowInterface::setEnableBlurWindow(bool enable) { - auto handleFunc = [this, enable](){ + m_isWindowBlur = enable; + doSetEnabledBlurWindow(); +} + +void DTreeLandPlatformWindowInterface::doSetEnabledNoTitlebar() +{ + auto handleFunc = [this](){ auto windowContext = getWindowContext(); if (!windowContext) { qWarning() << "windowContext is nullptr!"; - return; + return false; } - windowContext->set_blend_mode(enable ? PersonalizationWindowContext::blend_mode_blur : PersonalizationWindowContext::blend_mode_transparent); + windowContext->set_titlebar(m_isNoTitlebar ? PersonalizationWindowContext::enable_mode_disable : PersonalizationWindowContext::enable_mode_enable); + return true; }; if (m_manager->isActive()) { handleFunc(); @@ -270,16 +280,15 @@ void DTreeLandPlatformWindowInterface::setEnableBlurWindow(bool enable) } } -void DTreeLandPlatformWindowInterface::doSetEnabledNoTitlebar() +void DTreeLandPlatformWindowInterface::doSetEnabledBlurWindow() { auto handleFunc = [this](){ auto windowContext = getWindowContext(); if (!windowContext) { qWarning() << "windowContext is nullptr!"; - return false; + return; } - windowContext->set_titlebar(m_isNoTitlebar ? PersonalizationWindowContext::enable_mode_disable : PersonalizationWindowContext::enable_mode_enable); - return true; + windowContext->set_blend_mode(m_isWindowBlur ? PersonalizationWindowContext::blend_mode_blur : PersonalizationWindowContext::blend_mode_transparent); }; if (m_manager->isActive()) { handleFunc(); diff --git a/src/plugins/platform/treeland/dtreelandplatformwindowinterface.h b/src/plugins/platform/treeland/dtreelandplatformwindowinterface.h index a6e1f46..f2d6e10 100644 --- a/src/plugins/platform/treeland/dtreelandplatformwindowinterface.h +++ b/src/plugins/platform/treeland/dtreelandplatformwindowinterface.h @@ -8,6 +8,7 @@ #include "dtkgui_global.h" #include "dtreelandplatforminterface.h" #include +#include DGUI_USE_NAMESPACE class DTreeLandPlatformWindowInterface : public QObject @@ -19,8 +20,13 @@ class DTreeLandPlatformWindowInterface : public QObject bool setEnabledNoTitlebar(bool enable); void setEnableBlurWindow(bool enable); void doSetEnabledNoTitlebar(); + void doSetEnabledBlurWindow(); [[nodiscard]]QWindow *getWindow() const { return m_window; } +private slots: + void onSurfaceCreated(); + void onSurfaceDestroyed(); + private: PersonalizationWindowContext *getWindowContext(); void handlePendingTasks(); @@ -31,6 +37,13 @@ class DTreeLandPlatformWindowInterface : public QObject PersonalizationManager *m_manager = nullptr; PersonalizationWindowContext *m_windowContext = nullptr; bool m_isNoTitlebar = true; + bool m_isWindowBlur = false; + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QNativeInterface::Private::QWaylandWindow *m_waylandWindow = nullptr; +#else + QtWaylandClient::QWaylandWindow *m_waylandWindow = nullptr; +#endif }; #endif // DTREELANDPLATFORMWINDOWINTERFACE_H