From fe9873e4b12650afe565e75914095321c65b96c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 18 Feb 2015 08:31:53 +0100 Subject: [PATCH] Provide x11RootWindow as a property on the KWin::Application KWin::rootWindow() uses the property to resolve the value instead of using QX11Info. In practice this doesn't change anything at the moment, but allows kwin_wayland to provide a root window without depending on QX11Info. --- autotests/test_client_machine.cpp | 2 ++ autotests/test_screen_edges.cpp | 1 + autotests/test_xcb_size_hints.cpp | 6 ++++++ autotests/test_xcb_window.cpp | 6 ++++++ autotests/test_xcb_wrapper.cpp | 6 ++++++ autotests/test_xrandr_screens.cpp | 5 +---- libkwineffects/kwinglobals.h | 4 +++- main.cpp | 1 + main.h | 16 ++++++++++++++++ 9 files changed, 42 insertions(+), 5 deletions(-) diff --git a/autotests/test_client_machine.cpp b/autotests/test_client_machine.cpp index 6bafd5cd2d..0258fa8cce 100644 --- a/autotests/test_client_machine.cpp +++ b/autotests/test_client_machine.cpp @@ -82,6 +82,8 @@ void TestClientMachine::initTestCase() } } freeaddrinfo(res); + + qApp->setProperty("x11RootWindow", QVariant::fromValue(QX11Info::appRootWindow())); } void TestClientMachine::cleanupTestCase() diff --git a/autotests/test_screen_edges.cpp b/autotests/test_screen_edges.cpp index 270fcfae2b..0a2271703e 100644 --- a/autotests/test_screen_edges.cpp +++ b/autotests/test_screen_edges.cpp @@ -134,6 +134,7 @@ private Q_SLOTS: void TestScreenEdges::initTestCase() { + qApp->setProperty("x11RootWindow", QVariant::fromValue(QX11Info::appRootWindow())); KWin::atoms = new KWin::Atoms; qRegisterMetaType(); } diff --git a/autotests/test_xcb_size_hints.cpp b/autotests/test_xcb_size_hints.cpp index 48fe7aa14c..249fe35b5b 100644 --- a/autotests/test_xcb_size_hints.cpp +++ b/autotests/test_xcb_size_hints.cpp @@ -35,6 +35,7 @@ class TestXcbSizeHints : public QObject { Q_OBJECT private Q_SLOTS: + void initTestCase(); void init(); void cleanup(); void testSizeHints_data(); @@ -48,6 +49,11 @@ private: Window m_testWindow; }; +void TestXcbSizeHints::initTestCase() +{ + qApp->setProperty("x11RootWindow", QVariant::fromValue(QX11Info::appRootWindow())); +} + void TestXcbSizeHints::init() { const uint32_t values[] = { true }; diff --git a/autotests/test_xcb_window.cpp b/autotests/test_xcb_window.cpp index 8a9a76a36d..5a55e39e1a 100644 --- a/autotests/test_xcb_window.cpp +++ b/autotests/test_xcb_window.cpp @@ -32,6 +32,7 @@ class TestXcbWindow : public QObject { Q_OBJECT private Q_SLOTS: + void initTestCase(); void defaultCtor(); void ctor(); void classCtor(); @@ -42,6 +43,11 @@ private Q_SLOTS: void destroyNotManaged(); }; +void TestXcbWindow::initTestCase() +{ + qApp->setProperty("x11RootWindow", QVariant::fromValue(QX11Info::appRootWindow())); +} + void TestXcbWindow::defaultCtor() { Xcb::Window window; diff --git a/autotests/test_xcb_wrapper.cpp b/autotests/test_xcb_wrapper.cpp index 9efa3fb85e..6e0073a045 100644 --- a/autotests/test_xcb_wrapper.cpp +++ b/autotests/test_xcb_wrapper.cpp @@ -34,6 +34,7 @@ class TestXcbWrapper : public QObject { Q_OBJECT private Q_SLOTS: + void initTestCase(); void init(); void cleanup(); void defaultCtor(); @@ -60,6 +61,11 @@ private: Window m_testWindow; }; +void TestXcbWrapper::initTestCase() +{ + qApp->setProperty("x11RootWindow", QVariant::fromValue(QX11Info::appRootWindow())); +} + void TestXcbWrapper::init() { const uint32_t values[] = { true }; diff --git a/autotests/test_xrandr_screens.cpp b/autotests/test_xrandr_screens.cpp index 8f896aaa83..b0f25cd095 100644 --- a/autotests/test_xrandr_screens.cpp +++ b/autotests/test_xrandr_screens.cpp @@ -39,10 +39,6 @@ QPoint Cursor::pos() static xcb_window_t s_rootWindow = XCB_WINDOW_NONE; static xcb_connection_t *s_connection = nullptr; -unsigned long QX11Info::appRootWindow(int) -{ - return s_rootWindow; -} xcb_connection_t *QX11Info::connection() { return s_connection; @@ -101,6 +97,7 @@ void TestXRandRScreens::initTestCase() } } QVERIFY(s_rootWindow != XCB_WINDOW_NONE); + qApp->setProperty("x11RootWindow", QVariant::fromValue(s_rootWindow)); // get the extensions if (!Extensions::self()->isRandrAvailable()) { diff --git a/libkwineffects/kwinglobals.h b/libkwineffects/kwinglobals.h index 35c49cfdda..46086b6b66 100644 --- a/libkwineffects/kwinglobals.h +++ b/libkwineffects/kwinglobals.h @@ -24,6 +24,8 @@ along with this program. If not, see . #include #include #include +#include +#include #include @@ -150,7 +152,7 @@ KWIN_EXPORT xcb_window_t rootWindow() { static xcb_window_t s_rootWindow = XCB_WINDOW_NONE; if (s_rootWindow == XCB_WINDOW_NONE) { - s_rootWindow = QX11Info::appRootWindow(); + s_rootWindow = qApp->property("x11RootWindow").value(); } return s_rootWindow; } diff --git a/main.cpp b/main.cpp index 2451549fea..44e9ec7b73 100644 --- a/main.cpp +++ b/main.cpp @@ -148,6 +148,7 @@ Application::Application(Application::OperationMode mode, int &argc, char **argv , m_configLock(false) , m_operationMode(mode) { + setX11RootWindow(QX11Info::appRootWindow()); qRegisterMetaType("Options::WindowOperation"); } diff --git a/main.h b/main.h index be487ca35f..36621a8c97 100644 --- a/main.h +++ b/main.h @@ -46,6 +46,7 @@ class KWIN_EXPORT Application : public QApplication { Q_OBJECT Q_PROPERTY(quint32 x11Time READ x11Time WRITE setX11Time) + Q_PROPERTY(quint32 x11RootWindow READ x11RootWindow CONSTANT) public: /** * @brief This enum provides the various operation modes of KWin depending on the available @@ -119,6 +120,13 @@ public: */ static void setX11MultiHead(bool multiHead); + /** + * @returns the X11 root window. + **/ + xcb_window_t x11RootWindow() const { + return m_rootWindow; + } + static void setupMalloc(); static void setupLocalizedString(); static void setupLoggingCategoryFilters(); @@ -136,6 +144,13 @@ protected: void createOptions(); void setupEventFilters(); void destroyWorkspace(); + /** + * Inheriting classes should use this method to set the X11 root window + * before accessing any X11 specific code pathes. + **/ + void setX11RootWindow(xcb_window_t root) { + m_rootWindow = root; + } bool notify(QObject* o, QEvent* e); static void crashHandler(int signal); @@ -149,6 +164,7 @@ private: bool m_configLock; OperationMode m_operationMode; xcb_timestamp_t m_x11Time = XCB_TIME_CURRENT_TIME; + xcb_window_t m_rootWindow = XCB_WINDOW_NONE; static int crashes; };