Changeset View
Changeset View
Standalone View
Standalone View
src/platformtheme/kwaylandintegration.cpp
Show All 13 Lines | |||||
14 | * | 14 | * | ||
15 | * You should have received a copy of the GNU Lesser General Public License | 15 | * You should have received a copy of the GNU Lesser General Public License | ||
16 | * along with this library; see the file COPYING.LIB. If not, write to | 16 | * along with this library; see the file COPYING.LIB. If not, write to | ||
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | * Boston, MA 02110-1301, USA. | 18 | * Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | #include "kwaylandintegration.h" | 20 | #include "kwaylandintegration.h" | ||
21 | 21 | | |||
22 | #include <QCoreApplication> | 22 | #include <QGuiApplication> | ||
23 | #include <QPlatformSurfaceEvent> | 23 | #include <QPlatformSurfaceEvent> | ||
24 | #include <qpa/qplatformnativeinterface.h> | ||||
24 | 25 | | |||
25 | #include <KWayland/Client/connection_thread.h> | 26 | #include <KWayland/Client/connection_thread.h> | ||
26 | #include <KWayland/Client/registry.h> | 27 | #include <KWayland/Client/registry.h> | ||
27 | #include <KWayland/Client/surface.h> | 28 | #include <KWayland/Client/surface.h> | ||
28 | #include <KWayland/Client/server_decoration.h> | 29 | #include <KWayland/Client/server_decoration.h> | ||
29 | 30 | | |||
30 | using namespace KWayland::Client; | 31 | using namespace KWayland::Client; | ||
31 | 32 | | |||
33 | static const QByteArray s_schemePropertyName = QByteArrayLiteral("KDE_COLOR_SCHEME_PATH"); | ||||
34 | | ||||
32 | KWaylandIntegration::KWaylandIntegration() | 35 | KWaylandIntegration::KWaylandIntegration() | ||
33 | : QObject() | 36 | : QObject() | ||
34 | , m_decoration(Q_NULLPTR) | 37 | , m_decoration(Q_NULLPTR) | ||
35 | { | 38 | { | ||
36 | } | 39 | } | ||
37 | 40 | | |||
38 | KWaylandIntegration::~KWaylandIntegration() = default; | 41 | KWaylandIntegration::~KWaylandIntegration() = default; | ||
39 | 42 | | |||
40 | void KWaylandIntegration::init() | 43 | void KWaylandIntegration::init() | ||
41 | { | 44 | { | ||
42 | auto connection = ConnectionThread::fromApplication(this); | 45 | auto connection = ConnectionThread::fromApplication(this); | ||
43 | if (!connection) { | 46 | if (!connection) { | ||
44 | return; | 47 | return; | ||
45 | } | 48 | } | ||
46 | Registry *registry = new Registry(this); | 49 | Registry *registry = new Registry(this); | ||
47 | registry->create(connection); | 50 | registry->create(connection); | ||
48 | QObject::connect(registry, &Registry::interfacesAnnounced, this, | 51 | QObject::connect(registry, &Registry::interfacesAnnounced, this, | ||
49 | [registry, this] { | 52 | [registry, this] { | ||
50 | const auto interface = registry->interface(Registry::Interface::ServerSideDecorationManager); | 53 | const auto interface = registry->interface(Registry::Interface::ServerSideDecorationManager); | ||
51 | if (interface.name != 0) { | 54 | if (interface.name != 0) { | ||
52 | m_decoration = registry->createServerSideDecorationManager(interface.name, interface.version, this); | 55 | m_decoration = registry->createServerSideDecorationManager(interface.name, interface.version, this); | ||
53 | qputenv("QT_WAYLAND_DISABLE_WINDOWDECORATION", "1"); | 56 | qputenv("QT_WAYLAND_DISABLE_WINDOWDECORATION", "1"); | ||
54 | QCoreApplication::instance()->installEventFilter(this); | 57 | QCoreApplication::instance()->installEventFilter(this); | ||
usta: QCoreApplication -> QGuiApplication | |||||
graesslin: this is completely unrelated code not touched in this change. | |||||
#include <QCoreApplication> removed and #include <QGuiApplication added so isn't this also should be change ? usta:
#include <QCoreApplication> removed and #include <QGuiApplication added so isn't this also… | |||||
no? We try to not change unrelated code. The include of QGuiApplication is due to the usage of QGuiApplication::topLevelWindows. For this code it doesn't make any difference whether it's QCoreApplication or QGuiApplication. So there is no need to change it. The code is correct and a change would clutter up the commit. graesslin: no? We try to not change unrelated code. The include of QGuiApplication is due to the usage of… | |||||
55 | } | 58 | } | ||
56 | } | 59 | } | ||
57 | ); | 60 | ); | ||
58 | 61 | | |||
59 | registry->setup(); | 62 | registry->setup(); | ||
60 | connection->roundtrip(); | 63 | connection->roundtrip(); | ||
61 | } | 64 | } | ||
62 | 65 | | |||
63 | bool KWaylandIntegration::eventFilter(QObject *watched, QEvent *event) | 66 | bool KWaylandIntegration::eventFilter(QObject *watched, QEvent *event) | ||
64 | { | 67 | { | ||
65 | if (!m_decoration) { | 68 | if (!m_decoration) { | ||
66 | return false; | 69 | return false; | ||
67 | } | 70 | } | ||
68 | if (event->type() == QEvent::PlatformSurface) { | 71 | if (event->type() == QEvent::PlatformSurface) { | ||
69 | QWindow *w = qobject_cast<QWindow*>(watched); | 72 | QWindow *w = qobject_cast<QWindow*>(watched); | ||
70 | if (!w || w->parent()) { | 73 | if (!w || w->parent()) { | ||
71 | return false; | 74 | return false; | ||
72 | } | 75 | } | ||
73 | if (auto e = dynamic_cast<QPlatformSurfaceEvent*>(event)) { | 76 | if (auto e = dynamic_cast<QPlatformSurfaceEvent*>(event)) { | ||
74 | switch (e->surfaceEventType()) { | 77 | switch (e->surfaceEventType()) { | ||
75 | case QPlatformSurfaceEvent::SurfaceCreated: { | 78 | case QPlatformSurfaceEvent::SurfaceCreated: { | ||
79 | // set colorscheme hint | ||||
80 | if (qApp->property(s_schemePropertyName.constData()).isValid()) { | ||||
81 | installColorScheme(w); | ||||
82 | } | ||||
83 | // create deco | ||||
76 | Surface *s = Surface::fromWindow(w); | 84 | Surface *s = Surface::fromWindow(w); | ||
77 | if (!s) { | 85 | if (!s) { | ||
78 | return false; | 86 | return false; | ||
79 | } | 87 | } | ||
80 | auto deco = m_decoration->create(s, w); | 88 | auto deco = m_decoration->create(s, w); | ||
81 | connect(deco, &ServerSideDecoration::modeChanged, w, | 89 | connect(deco, &ServerSideDecoration::modeChanged, w, | ||
82 | [deco, w] { | 90 | [deco, w] { | ||
83 | const auto flags = w->flags(); | 91 | const auto flags = w->flags(); | ||
Show All 16 Lines | 106 | case QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed: { | |||
100 | break; | 108 | break; | ||
101 | } | 109 | } | ||
102 | default: | 110 | default: | ||
103 | // nothing | 111 | // nothing | ||
104 | break; | 112 | break; | ||
105 | } | 113 | } | ||
106 | } | 114 | } | ||
107 | } | 115 | } | ||
116 | if (event->type() == QEvent::ApplicationPaletteChange) { | ||||
117 | const auto topLevelWindows = QGuiApplication::topLevelWindows(); | ||||
118 | for (QWindow *w : topLevelWindows) { | ||||
119 | installColorScheme(w); | ||||
120 | } | ||||
121 | } | ||||
108 | return false; | 122 | return false; | ||
109 | } | 123 | } | ||
124 | | ||||
125 | void KWaylandIntegration::installColorScheme(QWindow *w) | ||||
126 | { | ||||
127 | if (QPlatformNativeInterface *native = qApp->platformNativeInterface()) { | ||||
128 | if (QPlatformWindow *pw = w->handle()) { | ||||
129 | native->setWindowProperty(pw, QString::fromUtf8(s_schemePropertyName), qApp->property(s_schemePropertyName.constData())); | ||||
130 | } | ||||
131 | } | ||||
132 | } |
QCoreApplication -> QGuiApplication