From 0d51952d78e9ec8e3811d727522517135d826376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 18 Feb 2015 11:19:04 +0100 Subject: [PATCH] Provide x11Connection as a property on the KWin::Application KWin::connection() 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 an xcb connection without depending on QX11Info. As we cannot make xcb_connection_t* available as a metatype, the property's type is set to void*. --- autotests/test_builtin_effectloader.cpp | 6 ++++++ autotests/test_client_machine.cpp | 1 + autotests/test_screen_edges.cpp | 1 + autotests/test_xcb_size_hints.cpp | 1 + autotests/test_xcb_window.cpp | 1 + autotests/test_xcb_wrapper.cpp | 1 + autotests/test_xrandr_screens.cpp | 6 +----- libkwineffects/kwinglobals.h | 2 +- main.cpp | 1 + main.h | 20 ++++++++++++++++++++ tabbox/autotests/test_tabbox_clientmodel.cpp | 6 ++++++ tabbox/autotests/test_tabbox_clientmodel.h | 1 + tabbox/autotests/test_tabbox_handler.cpp | 7 +++++++ 13 files changed, 48 insertions(+), 6 deletions(-) diff --git a/autotests/test_builtin_effectloader.cpp b/autotests/test_builtin_effectloader.cpp index 3c268c64f8..1ee2be36d4 100644 --- a/autotests/test_builtin_effectloader.cpp +++ b/autotests/test_builtin_effectloader.cpp @@ -49,6 +49,7 @@ class TestBuiltInEffectLoader : public QObject { Q_OBJECT private Q_SLOTS: + void initTestCase(); void testHasEffect_data(); void testHasEffect(); void testKnownEffects(); @@ -61,6 +62,11 @@ private Q_SLOTS: void testLoadAllEffects(); }; +void TestBuiltInEffectLoader::initTestCase() +{ + qApp->setProperty("x11Connection", QVariant::fromValue(QX11Info::connection())); +} + void TestBuiltInEffectLoader::testHasEffect_data() { QTest::addColumn("name"); diff --git a/autotests/test_client_machine.cpp b/autotests/test_client_machine.cpp index 0258fa8cce..d19b82a55f 100644 --- a/autotests/test_client_machine.cpp +++ b/autotests/test_client_machine.cpp @@ -84,6 +84,7 @@ void TestClientMachine::initTestCase() freeaddrinfo(res); qApp->setProperty("x11RootWindow", QVariant::fromValue(QX11Info::appRootWindow())); + qApp->setProperty("x11Connection", QVariant::fromValue(QX11Info::connection())); } void TestClientMachine::cleanupTestCase() diff --git a/autotests/test_screen_edges.cpp b/autotests/test_screen_edges.cpp index 0a2271703e..c217bc2461 100644 --- a/autotests/test_screen_edges.cpp +++ b/autotests/test_screen_edges.cpp @@ -135,6 +135,7 @@ private Q_SLOTS: void TestScreenEdges::initTestCase() { qApp->setProperty("x11RootWindow", QVariant::fromValue(QX11Info::appRootWindow())); + qApp->setProperty("x11Connection", QVariant::fromValue(QX11Info::connection())); KWin::atoms = new KWin::Atoms; qRegisterMetaType(); } diff --git a/autotests/test_xcb_size_hints.cpp b/autotests/test_xcb_size_hints.cpp index 249fe35b5b..79d1a379fa 100644 --- a/autotests/test_xcb_size_hints.cpp +++ b/autotests/test_xcb_size_hints.cpp @@ -52,6 +52,7 @@ private: void TestXcbSizeHints::initTestCase() { qApp->setProperty("x11RootWindow", QVariant::fromValue(QX11Info::appRootWindow())); + qApp->setProperty("x11Connection", QVariant::fromValue(QX11Info::connection())); } void TestXcbSizeHints::init() diff --git a/autotests/test_xcb_window.cpp b/autotests/test_xcb_window.cpp index 5a55e39e1a..9d263fa360 100644 --- a/autotests/test_xcb_window.cpp +++ b/autotests/test_xcb_window.cpp @@ -46,6 +46,7 @@ private Q_SLOTS: void TestXcbWindow::initTestCase() { qApp->setProperty("x11RootWindow", QVariant::fromValue(QX11Info::appRootWindow())); + qApp->setProperty("x11Connection", QVariant::fromValue(QX11Info::connection())); } void TestXcbWindow::defaultCtor() diff --git a/autotests/test_xcb_wrapper.cpp b/autotests/test_xcb_wrapper.cpp index 6e0073a045..b7ae0845de 100644 --- a/autotests/test_xcb_wrapper.cpp +++ b/autotests/test_xcb_wrapper.cpp @@ -64,6 +64,7 @@ private: void TestXcbWrapper::initTestCase() { qApp->setProperty("x11RootWindow", QVariant::fromValue(QX11Info::appRootWindow())); + qApp->setProperty("x11Connection", QVariant::fromValue(QX11Info::connection())); } void TestXcbWrapper::init() diff --git a/autotests/test_xrandr_screens.cpp b/autotests/test_xrandr_screens.cpp index b0f25cd095..3f0246ec10 100644 --- a/autotests/test_xrandr_screens.cpp +++ b/autotests/test_xrandr_screens.cpp @@ -39,11 +39,6 @@ QPoint Cursor::pos() static xcb_window_t s_rootWindow = XCB_WINDOW_NONE; static xcb_connection_t *s_connection = nullptr; -xcb_connection_t *QX11Info::connection() -{ - return s_connection; -} - using namespace KWin; using namespace KWin::Xcb; @@ -98,6 +93,7 @@ void TestXRandRScreens::initTestCase() } QVERIFY(s_rootWindow != XCB_WINDOW_NONE); qApp->setProperty("x11RootWindow", QVariant::fromValue(s_rootWindow)); + qApp->setProperty("x11Connection", QVariant::fromValue(s_connection)); // get the extensions if (!Extensions::self()->isRandrAvailable()) { diff --git a/libkwineffects/kwinglobals.h b/libkwineffects/kwinglobals.h index 46086b6b66..00aa446305 100644 --- a/libkwineffects/kwinglobals.h +++ b/libkwineffects/kwinglobals.h @@ -142,7 +142,7 @@ KWIN_EXPORT xcb_connection_t *connection() { static xcb_connection_t *s_con = nullptr; if (!s_con) { - s_con = QX11Info::connection(); + s_con = reinterpret_cast(qApp->property("x11Connection").value()); } return s_con; } diff --git a/main.cpp b/main.cpp index 44e9ec7b73..1e890ea960 100644 --- a/main.cpp +++ b/main.cpp @@ -149,6 +149,7 @@ Application::Application(Application::OperationMode mode, int &argc, char **argv , m_operationMode(mode) { setX11RootWindow(QX11Info::appRootWindow()); + setX11Connection(QX11Info::connection()); qRegisterMetaType("Options::WindowOperation"); } diff --git a/main.h b/main.h index 36621a8c97..d0c79b7c78 100644 --- a/main.h +++ b/main.h @@ -47,6 +47,7 @@ class KWIN_EXPORT Application : public QApplication Q_OBJECT Q_PROPERTY(quint32 x11Time READ x11Time WRITE setX11Time) Q_PROPERTY(quint32 x11RootWindow READ x11RootWindow CONSTANT) + Q_PROPERTY(void *x11Connection READ x11Connection NOTIFY x11ConnectionChanged) public: /** * @brief This enum provides the various operation modes of KWin depending on the available @@ -127,6 +128,13 @@ public: return m_rootWindow; } + /** + * @returns the X11 xcb connection + **/ + xcb_connection_t *x11Connection() const { + return m_connection; + } + static void setupMalloc(); static void setupLocalizedString(); static void setupLoggingCategoryFilters(); @@ -134,6 +142,9 @@ public: static bool usesLibinput(); static void setUseLibinput(bool use); +Q_SIGNALS: + void x11ConnectionChanged(); + protected: Application(OperationMode mode, int &argc, char **argv); virtual void performStartup() = 0; @@ -151,6 +162,14 @@ protected: void setX11RootWindow(xcb_window_t root) { m_rootWindow = root; } + /** + * Inheriting classes should use this method to set the xcb connection + * before accessing any X11 specific code pathes. + **/ + void setX11Connection(xcb_connection_t *c) { + m_connection = c; + emit x11ConnectionChanged(); + } bool notify(QObject* o, QEvent* e); static void crashHandler(int signal); @@ -165,6 +184,7 @@ private: OperationMode m_operationMode; xcb_timestamp_t m_x11Time = XCB_TIME_CURRENT_TIME; xcb_window_t m_rootWindow = XCB_WINDOW_NONE; + xcb_connection_t *m_connection = nullptr; static int crashes; }; diff --git a/tabbox/autotests/test_tabbox_clientmodel.cpp b/tabbox/autotests/test_tabbox_clientmodel.cpp index cee9860d08..72109a29d6 100644 --- a/tabbox/autotests/test_tabbox_clientmodel.cpp +++ b/tabbox/autotests/test_tabbox_clientmodel.cpp @@ -22,8 +22,14 @@ along with this program. If not, see . #include "clientmodel.h" #include +#include using namespace KWin; +void TestTabBoxClientModel::initTestCase() +{ + qApp->setProperty("x11Connection", QVariant::fromValue(QX11Info::connection())); +} + void TestTabBoxClientModel::testLongestCaptionWithNullClient() { MockTabBoxHandler tabboxhandler; diff --git a/tabbox/autotests/test_tabbox_clientmodel.h b/tabbox/autotests/test_tabbox_clientmodel.h index fad79874fe..35390a9c9c 100644 --- a/tabbox/autotests/test_tabbox_clientmodel.h +++ b/tabbox/autotests/test_tabbox_clientmodel.h @@ -25,6 +25,7 @@ class TestTabBoxClientModel : public QObject { Q_OBJECT private slots: + void initTestCase(); /** * Tests that calculating the longest caption does not * crash in case the internal m_clientList contains a weak diff --git a/tabbox/autotests/test_tabbox_handler.cpp b/tabbox/autotests/test_tabbox_handler.cpp index ff624ab8fb..b3ed194c31 100644 --- a/tabbox/autotests/test_tabbox_handler.cpp +++ b/tabbox/autotests/test_tabbox_handler.cpp @@ -20,6 +20,7 @@ along with this program. If not, see . #include "mock_tabboxhandler.h" #include "clientmodel.h" #include +#include using namespace KWin; @@ -27,6 +28,7 @@ class TestTabBoxHandler : public QObject { Q_OBJECT private slots: + void initTestCase(); /** * Test to verify that update outline does not crash * if the ModelIndex for which the outline should be @@ -37,6 +39,11 @@ private slots: void testDontCrashUpdateOutlineNullClient(); }; +void TestTabBoxHandler::initTestCase() +{ + qApp->setProperty("x11Connection", QVariant::fromValue(QX11Info::connection())); +} + void TestTabBoxHandler::testDontCrashUpdateOutlineNullClient() { MockTabBoxHandler tabboxhandler;