Skip to content

Commit

Permalink
fix: window blur invalid
Browse files Browse the repository at this point in the history
Set blur again when creating the surface

pms: BUG-278281
  • Loading branch information
mhduiy authored and 18202781743 committed Dec 2, 2024
1 parent 79440d4 commit ab6192f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 46 deletions.
101 changes: 55 additions & 46 deletions src/plugins/platform/treeland/dtreelandplatformwindowinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,35 +144,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<QPlatformSurfaceEvent*>(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();
Expand All @@ -182,13 +158,50 @@ 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<QNativeInterface::Private::QWaylandWindow>();
#else
auto waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(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()
{

}

void DTreeLandPlatformWindowInterface::onSurfaceCreated()
{
doSetEnabledNoTitlebar();
doSetEnabledBlurWindow();
}

void DTreeLandPlatformWindowInterface::onSurfaceDestroyed()
{
if (m_windowContext) {
m_windowContext->deleteLater();
m_windowContext = nullptr;
}
}

PersonalizationWindowContext *DTreeLandPlatformWindowInterface::getWindowContext()
{
if (!m_manager->isSupported()) {
Expand All @@ -201,20 +214,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<QNativeInterface::Private::QWaylandWindow>();
#else
auto waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(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!!!";
Expand All @@ -223,12 +232,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;
Expand All @@ -251,13 +254,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();
Expand All @@ -266,16 +276,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();
Expand Down
13 changes: 13 additions & 0 deletions src/plugins/platform/treeland/dtreelandplatformwindowinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "dtkgui_global.h"
#include "dtreelandplatforminterface.h"
#include <QObject>
#include <QtWaylandClient/private/qwaylandwindow_p.h>

DGUI_USE_NAMESPACE
class DTreeLandPlatformWindowInterface : public QObject
Expand All @@ -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();
Expand All @@ -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

0 comments on commit ab6192f

Please sign in to comment.