aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Gräßlin <[email protected]>2016-10-13 08:16:11 +0200
committerMartin Gräßlin <[email protected]>2016-10-13 08:22:30 +0200
commite47245f96ed1f7decc7209eafe969889579b1c38 (patch)
tree68f67e62686e79c77a8f89747a969fae0de06652
parent3258d996565bec01c3a2e7d1ab4362bdb747483c (diff)
Set color scheme X property in the X11Integration
Summary: So for the _KDE_NET_WM_COLOR_SCHEME property was set in KStyle. This has a few disadvantages: * it only works for QWidgets * it requires a style inheriting from KStyle This change brings the behavior into the plasma-integration QPT. It's an integration feature for our platform theme as it's a hint for KWin. The existing event filter in the X11Integration is used to monitor for all PlatformSurface events and sets the required property on the newly created X11 window. In addition it monitors for the ApplicationPaletteChange to update the property as needed on all toplevel windows. Test Plan: Removed code from kstyle and used the KColorSchemeManager test application. Reviewers: #plasma Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D3044
-rw-r--r--CMakeLists.txt8
-rw-r--r--autotests/CMakeLists.txt2
-rw-r--r--src/platformtheme/CMakeLists.txt1
-rw-r--r--src/platformtheme/x11integration.cpp46
-rw-r--r--src/platformtheme/x11integration.h4
5 files changed, 59 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7a780dc..9b447d2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -38,6 +38,14 @@ find_package(KF5WidgetsAddons ${KF5_DEP_VERSION} REQUIRED)
find_package(KF5WindowSystem ${KF5_DEP_VERSION} REQUIRED)
find_package(KF5Wayland 5.5 CONFIG REQUIRED)
+find_package(XCB COMPONENTS XCB)
+set_package_properties(XCB PROPERTIES
+ DESCRIPTION "X protocol C-language Binding"
+ URL "http://xcb.freedesktop.org"
+ TYPE REQUIRED
+ PURPOSE "Required to pass style properties to native Windows on X11 Platform"
+)
+
find_package(Breeze ${PROJECT_VERSION} CONFIG)
set_package_properties(Breeze PROPERTIES
TYPE REQUIRED
diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
index 9e4a3ae..858ebd8 100644
--- a/autotests/CMakeLists.txt
+++ b/autotests/CMakeLists.txt
@@ -27,7 +27,7 @@ macro(FRAMEWORKINTEGRATION_TESTS _testname)
add_test(frameworkintegration-${_testname} ${_testname})
ecm_mark_as_test(${_testname})
ecm_mark_nongui_executable(${_testname})
- target_link_libraries(${_testname} Qt5::Test Qt5::DBus Qt5::X11Extras KF5::ConfigWidgets KF5::ConfigCore KF5::IconThemes KF5::KIOFileWidgets KF5::I18n KF5::Notifications KF5::WindowSystem KF5::WaylandClient)
+ target_link_libraries(${_testname} Qt5::Test Qt5::DBus Qt5::X11Extras KF5::ConfigWidgets KF5::ConfigCore KF5::IconThemes KF5::KIOFileWidgets KF5::I18n KF5::Notifications KF5::WindowSystem KF5::WaylandClient XCB::XCB)
endmacro()
set(platformThemeSRCS
diff --git a/src/platformtheme/CMakeLists.txt b/src/platformtheme/CMakeLists.txt
index 1955a2a..e7050f8 100644
--- a/src/platformtheme/CMakeLists.txt
+++ b/src/platformtheme/CMakeLists.txt
@@ -43,6 +43,7 @@ target_link_libraries(KDEPlasmaPlatformTheme
KF5::Notifications
KF5::WindowSystem
KF5::WaylandClient
+ XCB::XCB
)
if(HAVE_X11)
diff --git a/src/platformtheme/x11integration.cpp b/src/platformtheme/x11integration.cpp
index 8260a6a..6a8b5d0 100644
--- a/src/platformtheme/x11integration.cpp
+++ b/src/platformtheme/x11integration.cpp
@@ -22,9 +22,15 @@
#include <QCoreApplication>
#include <QX11Info>
+#include <QPlatformSurfaceEvent>
+#include <QGuiApplication>
#include <QWindow>
#include <NETWM>
+#include <xcb/xcb.h>
+
+static const char s_schemePropertyName[] = "KDE_COLOR_SCHEME_PATH";
+
X11Integration::X11Integration()
: QObject()
{
@@ -48,6 +54,46 @@ bool X11Integration::eventFilter(QObject *watched, QEvent *event)
info.setWindowType(NET::DNDIcon);
// TODO: does this flash the xcb connection?
}
+ if (event->type() == QEvent::PlatformSurface) {
+ if (QWindow *w = qobject_cast<QWindow*>(watched)) {
+ QPlatformSurfaceEvent *pe = static_cast<QPlatformSurfaceEvent*>(event);
+ if (pe->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated && qApp->property(s_schemePropertyName).isValid()) {
+ installColorScheme(w);
+ }
+ }
+ }
+ if (event->type() == QEvent::ApplicationPaletteChange) {
+ const auto topLevelWindows = QGuiApplication::topLevelWindows();
+ for (QWindow *w : topLevelWindows) {
+ installColorScheme(w);
+ }
+ }
return false;
}
+void X11Integration::installColorScheme(QWindow *w)
+{
+ if (!w->isTopLevel()) {
+ return;
+ }
+ static xcb_atom_t atom = XCB_ATOM_NONE;
+ xcb_connection_t *c = QX11Info::connection();
+ if (atom == XCB_ATOM_NONE) {
+ const QByteArray name = QByteArrayLiteral("_KDE_NET_WM_COLOR_SCHEME");
+ const xcb_intern_atom_cookie_t cookie = xcb_intern_atom(c, false, name.length(), name.constData());
+ QScopedPointer<xcb_intern_atom_reply_t, QScopedPointerPodDeleter> reply(xcb_intern_atom_reply(c, cookie, Q_NULLPTR));
+ if (!reply.isNull()) {
+ atom = reply->atom;
+ } else {
+ // no point in continuing, we don't have the atom
+ return;
+ }
+ }
+ const QString path = qApp->property(s_schemePropertyName).toString();
+ if (path.isEmpty()) {
+ xcb_delete_property(c, w->winId(), atom);
+ } else {
+ xcb_change_property(c, XCB_PROP_MODE_REPLACE, w->winId(), atom, XCB_ATOM_STRING,
+ 8, path.size(), qPrintable(path));
+ }
+}
diff --git a/src/platformtheme/x11integration.h b/src/platformtheme/x11integration.h
index bb93b57..471f292 100644
--- a/src/platformtheme/x11integration.h
+++ b/src/platformtheme/x11integration.h
@@ -23,6 +23,8 @@
#include <QObject>
+class QWindow;
+
class X11Integration : public QObject
{
Q_OBJECT
@@ -34,7 +36,7 @@ public:
bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;
private:
-
+ void installColorScheme(QWindow *w);
};
#endif