Changeset View
Changeset View
Standalone View
Standalone View
src/platformtheme/kwaylandintegration.cpp
Show All 30 Lines | |||||
31 | #include <KWayland/Client/server_decoration.h> | 31 | #include <KWayland/Client/server_decoration.h> | ||
32 | #include <KWindowEffects> | 32 | #include <KWindowEffects> | ||
33 | 33 | | |||
34 | using namespace KWayland::Client; | 34 | using namespace KWayland::Client; | ||
35 | 35 | | |||
36 | static const QByteArray s_schemePropertyName = QByteArrayLiteral("KDE_COLOR_SCHEME_PATH"); | 36 | static const QByteArray s_schemePropertyName = QByteArrayLiteral("KDE_COLOR_SCHEME_PATH"); | ||
37 | static const QByteArray s_blurBehindPropertyName = QByteArrayLiteral("ENABLE_BLUR_BEHIND_HINT"); | 37 | static const QByteArray s_blurBehindPropertyName = QByteArrayLiteral("ENABLE_BLUR_BEHIND_HINT"); | ||
38 | 38 | | |||
39 | KWaylandIntegration::KWaylandIntegration() | 39 | KWaylandIntegration::KWaylandIntegration() | ||
graesslin: I don't really like the name of the variable as it's going to be the future way and not "a… | |||||
40 | : QObject() | 40 | : QObject() | ||
41 | , m_decoration(Q_NULLPTR) | 41 | , m_decoration(Q_NULLPTR) | ||
42 | { | 42 | { | ||
43 | } | 43 | } | ||
44 | 44 | | |||
45 | KWaylandIntegration::~KWaylandIntegration() = default; | 45 | KWaylandIntegration::~KWaylandIntegration() = default; | ||
46 | 46 | | |||
47 | void KWaylandIntegration::init() | 47 | void KWaylandIntegration::init() | ||
Show All 18 Lines | 48 | { | |||
66 | registry->setup(); | 66 | registry->setup(); | ||
67 | connection->roundtrip(); | 67 | connection->roundtrip(); | ||
68 | } | 68 | } | ||
69 | 69 | | |||
70 | bool KWaylandIntegration::eventFilter(QObject *watched, QEvent *event) | 70 | bool KWaylandIntegration::eventFilter(QObject *watched, QEvent *event) | ||
71 | { | 71 | { | ||
72 | if (!m_decoration) { | 72 | if (!m_decoration) { | ||
73 | return false; | 73 | return false; | ||
74 | } else if (event->type() == QEvent::Expose) { | ||||
75 | auto ee = static_cast<QExposeEvent*>(event); | ||||
76 | if (ee->region().isNull()) { | ||||
77 | return false; | ||||
78 | } | ||||
79 | QWindow *w = qobject_cast<QWindow*>(watched); | ||||
80 | if (!w || w->parent()) { | ||||
81 | return false; | ||||
74 | } | 82 | } | ||
75 | if (event->type() == QEvent::PlatformSurface) { | 83 | shellSurfaceCreated(w); | ||
84 | } else if (event->type() == QEvent::Hide) { | ||||
76 | QWindow *w = qobject_cast<QWindow*>(watched); | 85 | QWindow *w = qobject_cast<QWindow*>(watched); | ||
77 | if (!w || w->parent()) { | 86 | if (!w || w->parent()) { | ||
78 | return false; | 87 | return false; | ||
79 | } | 88 | } | ||
80 | if (auto e = dynamic_cast<QPlatformSurfaceEvent*>(event)) { | 89 | shellSurfaceDestroyed(w); | ||
81 | switch (e->surfaceEventType()) { | 90 | } else if (event->type() == QEvent::ApplicationPaletteChange) { | ||
82 | case QPlatformSurfaceEvent::SurfaceCreated: { | 91 | const auto topLevelWindows = QGuiApplication::topLevelWindows(); | ||
92 | for (QWindow *w : topLevelWindows) { | ||||
93 | installColorScheme(w); | ||||
94 | } | ||||
95 | } | ||||
96 | | ||||
97 | return false; | ||||
98 | } | ||||
99 | | ||||
100 | void KWaylandIntegration::shellSurfaceCreated(QWindow *w) | ||||
101 | { | ||||
83 | // set colorscheme hint | 102 | // set colorscheme hint | ||
84 | if (qApp->property(s_schemePropertyName.constData()).isValid()) { | 103 | if (qApp->property(s_schemePropertyName.constData()).isValid()) { | ||
85 | installColorScheme(w); | 104 | installColorScheme(w); | ||
86 | } | 105 | } | ||
87 | const auto blurBehindProperty = w->property(s_blurBehindPropertyName.constData()); | 106 | const auto blurBehindProperty = w->property(s_blurBehindPropertyName.constData()); | ||
88 | if (blurBehindProperty.isValid()) { | 107 | if (blurBehindProperty.isValid()) { | ||
89 | KWindowEffects::enableBlurBehind(w->winId(), blurBehindProperty.toBool()); | 108 | KWindowEffects::enableBlurBehind(w->winId(), blurBehindProperty.toBool()); | ||
90 | } | 109 | } | ||
91 | // create deco | 110 | // create deco | ||
92 | Surface *s = Surface::fromWindow(w); | 111 | Surface *s = Surface::fromWindow(w); | ||
93 | if (!s) { | 112 | if (!s) { | ||
94 | return false; | 113 | return; | ||
95 | } | 114 | } | ||
96 | auto deco = m_decoration->create(s, w); | 115 | auto deco = m_decoration->create(s, w); | ||
97 | connect(deco, &ServerSideDecoration::modeChanged, w, | 116 | connect(deco, &ServerSideDecoration::modeChanged, w, | ||
98 | [deco, w] { | 117 | [deco, w] { | ||
99 | const auto flags = w->flags(); | 118 | const auto flags = w->flags(); | ||
100 | const auto ourMode = (flags.testFlag(Qt::FramelessWindowHint) || flags.testFlag(Qt::Popup) || flags.testFlag(Qt::ToolTip)) ? ServerSideDecoration::Mode::None : ServerSideDecoration::Mode::Server; | 119 | const auto ourMode = (flags.testFlag(Qt::FramelessWindowHint) || flags.testFlag(Qt::Popup) || flags.testFlag(Qt::ToolTip)) ? ServerSideDecoration::Mode::None : ServerSideDecoration::Mode::Server; | ||
101 | if (deco->mode() != ourMode) { | 120 | if (deco->mode() != ourMode) { | ||
102 | deco->requestMode(ourMode); | 121 | deco->requestMode(ourMode); | ||
103 | } | 122 | } | ||
104 | } | 123 | } | ||
105 | ); | 124 | ); | ||
106 | const auto flags = w->flags(); | 125 | const auto flags = w->flags(); | ||
107 | const auto ourMode = (flags.testFlag(Qt::FramelessWindowHint) || flags.testFlag(Qt::Popup) || flags.testFlag(Qt::ToolTip)) ? ServerSideDecoration::Mode::None : ServerSideDecoration::Mode::Server; | 126 | const auto ourMode = (flags.testFlag(Qt::FramelessWindowHint) || flags.testFlag(Qt::Popup) || flags.testFlag(Qt::ToolTip)) ? ServerSideDecoration::Mode::None : ServerSideDecoration::Mode::Server; | ||
108 | if (deco->defaultMode() != ourMode) { | 127 | if (deco->defaultMode() != ourMode) { | ||
109 | deco->requestMode(ourMode); | 128 | deco->requestMode(ourMode); | ||
110 | } | 129 | } | ||
111 | w->setProperty("org.kde.plasma.integration.waylandserverdecoration", QVariant::fromValue(deco)); | 130 | w->setProperty("org.kde.plasma.integration.waylandserverdecoration", QVariant::fromValue(deco)); | ||
112 | break; | | |||
113 | } | 131 | } | ||
114 | case QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed: { | 132 | | ||
133 | void KWaylandIntegration::shellSurfaceDestroyed(QWindow *w) | ||||
134 | { | ||||
115 | delete w->property("org.kde.plasma.integration.waylandserverdecoration").value<ServerSideDecoration*>(); | 135 | delete w->property("org.kde.plasma.integration.waylandserverdecoration").value<ServerSideDecoration*>(); | ||
116 | break; | 136 | w->setProperty("org.kde.plasma.integration.waylandserverdecoration", 0); | ||
117 | } | | |||
118 | default: | | |||
119 | // nothing | | |||
120 | break; | | |||
121 | } | | |||
122 | } | | |||
123 | } | | |||
124 | if (event->type() == QEvent::ApplicationPaletteChange) { | | |||
125 | const auto topLevelWindows = QGuiApplication::topLevelWindows(); | | |||
126 | for (QWindow *w : topLevelWindows) { | | |||
127 | installColorScheme(w); | | |||
128 | } | | |||
129 | } | | |||
130 | return false; | | |||
131 | } | 137 | } | ||
132 | 138 | | |||
133 | void KWaylandIntegration::installColorScheme(QWindow *w) | 139 | void KWaylandIntegration::installColorScheme(QWindow *w) | ||
134 | { | 140 | { | ||
135 | if (QPlatformNativeInterface *native = qApp->platformNativeInterface()) { | 141 | if (QPlatformNativeInterface *native = qApp->platformNativeInterface()) { | ||
136 | if (QPlatformWindow *pw = w->handle()) { | 142 | if (QPlatformWindow *pw = w->handle()) { | ||
137 | native->setWindowProperty(pw, QString::fromUtf8(s_schemePropertyName), qApp->property(s_schemePropertyName.constData())); | 143 | native->setWindowProperty(pw, QString::fromUtf8(s_schemePropertyName), qApp->property(s_schemePropertyName.constData())); | ||
138 | } | 144 | } | ||
139 | } | 145 | } | ||
140 | } | 146 | } | ||
141 | 147 | | |||
142 | void KWaylandIntegration::setWindowProperty(QWindow *window, const QByteArray &name, const QByteArray &value) | 148 | void KWaylandIntegration::setWindowProperty(QWindow *window, const QByteArray &name, const QByteArray &value) | ||
143 | { | 149 | { | ||
144 | if (QPlatformNativeInterface *nativeInterface = qApp->platformNativeInterface()) { | 150 | if (QPlatformNativeInterface *nativeInterface = qApp->platformNativeInterface()) { | ||
145 | if (QPlatformWindow *platformWindow = window->handle()) { | 151 | if (QPlatformWindow *platformWindow = window->handle()) { | ||
146 | nativeInterface->setWindowProperty(platformWindow, QString::fromUtf8(name), QString::fromUtf8(value)); | 152 | nativeInterface->setWindowProperty(platformWindow, QString::fromUtf8(name), QString::fromUtf8(value)); | ||
147 | } | 153 | } | ||
148 | } | 154 | } | ||
149 | } | 155 | } | ||
156 | | ||||
157 | #include "kwaylandintegration.moc" | ||||
graesslin: Just wondering: why is the moc file needed now? |
I don't really like the name of the variable as it's going to be the future way and not "a workaround" once we depend on Qt 5.8 or later.