diff --git a/autotests/integration/activities_test.cpp b/autotests/integration/activities_test.cpp index bef20c35cb..689312b546 100644 --- a/autotests/integration/activities_test.cpp +++ b/autotests/integration/activities_test.cpp @@ -82,19 +82,11 @@ void ActivitiesTest::cleanup() { } -struct XcbConnectionDeleter -{ - void operator()(xcb_connection_t *pointer) - { - xcb_disconnect(pointer); - } -}; - void ActivitiesTest::testSetOnActivitiesValidates() { // this test verifies that windows can't be placed on activities that don't exist // create an xcb window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); xcb_window_t windowId = xcb_generate_id(c.get()); diff --git a/autotests/integration/dbus_interface_test.cpp b/autotests/integration/dbus_interface_test.cpp index 77b1ae6abc..d9d1804757 100644 --- a/autotests/integration/dbus_interface_test.cpp +++ b/autotests/integration/dbus_interface_test.cpp @@ -217,17 +217,9 @@ void TestDbusInterface::testGetWindowInfoXdgShellClient() QVERIFY(reply.value().empty()); } -struct XcbConnectionDeleter -{ - void operator()(xcb_connection_t *pointer) - { - xcb_disconnect(pointer); - } -}; - void TestDbusInterface::testGetWindowInfoX11Client() { - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 600, 400); xcb_window_t windowId = xcb_generate_id(c.get()); diff --git a/autotests/integration/desktop_window_x11_test.cpp b/autotests/integration/desktop_window_x11_test.cpp index ee550cb94e..ab0c9f45bf 100644 --- a/autotests/integration/desktop_window_x11_test.cpp +++ b/autotests/integration/desktop_window_x11_test.cpp @@ -66,21 +66,13 @@ void X11DesktopWindowTest::cleanup() { } -struct XcbConnectionDeleter -{ - void operator()(xcb_connection_t *pointer) - { - xcb_disconnect(pointer); - } -}; - void X11DesktopWindowTest::testDesktopWindow() { // this test creates a desktop window with an RGBA visual and verifies that it's only considered // as an RGB (opaque) window in KWin // create an xcb window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); xcb_window_t windowId = xcb_generate_id(c.get()); diff --git a/autotests/integration/dont_crash_aurorae_destroy_deco.cpp b/autotests/integration/dont_crash_aurorae_destroy_deco.cpp index 545ce56040..1c3019befc 100644 --- a/autotests/integration/dont_crash_aurorae_destroy_deco.cpp +++ b/autotests/integration/dont_crash_aurorae_destroy_deco.cpp @@ -84,7 +84,8 @@ void DontCrashAuroraeDestroyDecoTest::testBorderlessMaximizedWindows() QCOMPARE(options->borderlessMaximizedWindows(), true); // create an xcb window - xcb_connection_t *c = xcb_connect(nullptr, nullptr); + Test::XcbConnectionPtr connection = Test::createX11Connection(); + auto c = connection.get(); QVERIFY(!xcb_connection_has_error(c)); xcb_window_t windowId = xcb_generate_id(c); @@ -126,7 +127,6 @@ void DontCrashAuroraeDestroyDecoTest::testBorderlessMaximizedWindows() xcb_unmap_window(c, windowId); xcb_destroy_window(c, windowId); xcb_flush(c); - xcb_disconnect(c); QSignalSpy windowClosedSpy(window, &X11Window::windowClosed); QVERIFY(windowClosedSpy.wait()); diff --git a/autotests/integration/dont_crash_empty_deco.cpp b/autotests/integration/dont_crash_empty_deco.cpp index 1ec7285916..df80f1d5b0 100644 --- a/autotests/integration/dont_crash_empty_deco.cpp +++ b/autotests/integration/dont_crash_empty_deco.cpp @@ -69,7 +69,10 @@ void DontCrashEmptyDecorationTest::testBug361551() // there a repaint is scheduled and the resulting texture is invalid if the window size is invalid // create an xcb window - xcb_connection_t *c = xcb_connect(nullptr, nullptr); + Test::XcbConnectionPtr connection = Test::createX11Connection(); + auto c = connection.get(); + + QVERIFY(c); QVERIFY(!xcb_connection_has_error(c)); xcb_window_t windowId = xcb_generate_id(c); @@ -93,7 +96,6 @@ void DontCrashEmptyDecorationTest::testBug361551() xcb_unmap_window(c, windowId); xcb_destroy_window(c, windowId); xcb_flush(c); - xcb_disconnect(c); QSignalSpy windowClosedSpy(window, &X11Window::windowClosed); QVERIFY(windowClosedSpy.wait()); diff --git a/autotests/integration/effects/slidingpopups_test.cpp b/autotests/integration/effects/slidingpopups_test.cpp index 9bce0ac023..44e4a942a6 100644 --- a/autotests/integration/effects/slidingpopups_test.cpp +++ b/autotests/integration/effects/slidingpopups_test.cpp @@ -95,14 +95,6 @@ void SlidingPopupsTest::cleanup() } } -struct XcbConnectionDeleter -{ - void operator()(xcb_connection_t *pointer) - { - xcb_disconnect(pointer); - } -}; - void SlidingPopupsTest::testWithOtherEffect_data() { QTest::addColumn("effectsToLoad"); @@ -159,7 +151,7 @@ void SlidingPopupsTest::testWithOtherEffect() QSignalSpy windowAddedSpy(effects, &EffectsHandler::windowAdded); // create an xcb window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); diff --git a/autotests/integration/effects/translucency_test.cpp b/autotests/integration/effects/translucency_test.cpp index af4c0c34de..9d6267c32a 100644 --- a/autotests/integration/effects/translucency_test.cpp +++ b/autotests/integration/effects/translucency_test.cpp @@ -96,14 +96,6 @@ void TranslucencyTest::cleanup() m_translucencyEffect = nullptr; } -struct XcbConnectionDeleter -{ - void operator()(xcb_connection_t *pointer) - { - xcb_disconnect(pointer); - } -}; - void TranslucencyTest::testMoveAfterDesktopChange() { // test tries to simulate the condition of bug 366081 @@ -112,7 +104,7 @@ void TranslucencyTest::testMoveAfterDesktopChange() QSignalSpy windowAddedSpy(effects, &EffectsHandler::windowAdded); // create an xcb window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); @@ -175,7 +167,7 @@ void TranslucencyTest::testDialogClose() QSignalSpy windowAddedSpy(effects, &EffectsHandler::windowAdded); // create an xcb window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); diff --git a/autotests/integration/effects/wobbly_shade_test.cpp b/autotests/integration/effects/wobbly_shade_test.cpp index 914a81a96b..ffdeb68bfb 100644 --- a/autotests/integration/effects/wobbly_shade_test.cpp +++ b/autotests/integration/effects/wobbly_shade_test.cpp @@ -84,14 +84,6 @@ void WobblyWindowsShadeTest::cleanup() QVERIFY(effectsImpl->loadedEffects().isEmpty()); } -struct XcbConnectionDeleter -{ - void operator()(xcb_connection_t *pointer) - { - xcb_disconnect(pointer); - } -}; - void WobblyWindowsShadeTest::testShadeMove() { // this test simulates the condition from BUG 390953 @@ -99,7 +91,7 @@ void WobblyWindowsShadeTest::testShadeMove() QVERIFY(e->loadEffect(QStringLiteral("wobblywindows"))); QVERIFY(e->isEffectLoaded(QStringLiteral("wobblywindows"))); - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); diff --git a/autotests/integration/globalshortcuts_test.cpp b/autotests/integration/globalshortcuts_test.cpp index 93a9a64881..626473ef68 100644 --- a/autotests/integration/globalshortcuts_test.cpp +++ b/autotests/integration/globalshortcuts_test.cpp @@ -279,21 +279,13 @@ void GlobalShortcutsTest::testComponseKey() QTRY_COMPARE(triggeredSpy.count(), 0); } -struct XcbConnectionDeleter -{ - void operator()(xcb_connection_t *pointer) - { - xcb_disconnect(pointer); - } -}; - void GlobalShortcutsTest::testX11WindowShortcut() { #ifdef NO_XWAYLAND QSKIP("x11 test, unnecessary without xwayland"); #endif // create an X11 window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); xcb_window_t windowId = xcb_generate_id(c.get()); const QRect windowGeometry = QRect(0, 0, 10, 20); diff --git a/autotests/integration/kwin_wayland_test.h b/autotests/integration/kwin_wayland_test.h index e98ea565b3..ac78b1de91 100644 --- a/autotests/integration/kwin_wayland_test.h +++ b/autotests/integration/kwin_wayland_test.h @@ -675,6 +675,20 @@ bool lockScreen(); */ bool unlockScreen(); +/** + * Creates an X11 connection + * Internally a nested event loop is spawned whilst we connect to avoid a deadlock + * with X on demand + */ + +struct XcbConnectionDeleter +{ + void operator()(xcb_connection_t *pointer); +}; + +typedef std::unique_ptr XcbConnectionPtr; +XcbConnectionPtr createX11Connection(); + MockInputMethod *inputMethod(); KWayland::Client::Surface *inputPanelSurface(); diff --git a/autotests/integration/move_resize_window_test.cpp b/autotests/integration/move_resize_window_test.cpp index e244774e22..e522a1df11 100644 --- a/autotests/integration/move_resize_window_test.cpp +++ b/autotests/integration/move_resize_window_test.cpp @@ -589,19 +589,11 @@ void MoveResizeWindowTest::testPlasmaShellSurfaceMovable() QVERIFY(Test::waitForWindowDestroyed(window)); } -struct XcbConnectionDeleter -{ - void operator()(xcb_connection_t *pointer) - { - xcb_disconnect(pointer); - } -}; - void MoveResizeWindowTest::testNetMove() { // this test verifies that a move request for an X11 window through NET API works // create an xcb window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); xcb_window_t windowId = xcb_generate_id(c.get()); @@ -685,7 +677,7 @@ void MoveResizeWindowTest::testAdjustClientGeometryOfAutohidingX11Panel() // see BUG 365892 // first create our panel - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); xcb_window_t windowId = xcb_generate_id(c.get()); diff --git a/autotests/integration/plasmawindow_test.cpp b/autotests/integration/plasmawindow_test.cpp index 72e0c246a5..0b93b91970 100644 --- a/autotests/integration/plasmawindow_test.cpp +++ b/autotests/integration/plasmawindow_test.cpp @@ -92,14 +92,7 @@ void PlasmaWindowTest::testCreateDestroyX11PlasmaWindow() QSignalSpy plasmaWindowCreatedSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated); // create an xcb window - struct XcbConnectionDeleter - { - void operator()(xcb_connection_t *pointer) - { - xcb_disconnect(pointer); - } - }; - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); diff --git a/autotests/integration/quick_tiling_test.cpp b/autotests/integration/quick_tiling_test.cpp index 60ed17f81b..e8990ea11f 100644 --- a/autotests/integration/quick_tiling_test.cpp +++ b/autotests/integration/quick_tiling_test.cpp @@ -518,14 +518,6 @@ void QuickTilingTest::testQuickTilingTouchMove() QCOMPARE(false, toplevelConfigureRequestedSpy.last().first().toSize().isEmpty()); } -struct XcbConnectionDeleter -{ - void operator()(xcb_connection_t *pointer) - { - xcb_disconnect(pointer); - } -}; - void QuickTilingTest::testX11QuickTiling_data() { QTest::addColumn("mode"); @@ -551,7 +543,7 @@ void QuickTilingTest::testX11QuickTiling_data() } void QuickTilingTest::testX11QuickTiling() { - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); @@ -631,7 +623,7 @@ void QuickTilingTest::testX11QuickTilingAfterVertMaximize_data() void QuickTilingTest::testX11QuickTilingAfterVertMaximize() { - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); diff --git a/autotests/integration/screenedge_client_show_test.cpp b/autotests/integration/screenedge_client_show_test.cpp index 0d9bf3f278..55e47190da 100644 --- a/autotests/integration/screenedge_client_show_test.cpp +++ b/autotests/integration/screenedge_client_show_test.cpp @@ -70,14 +70,6 @@ void ScreenEdgeClientShowTest::init() QVERIFY(waylandServer()->windows().isEmpty()); } -struct XcbConnectionDeleter -{ - void operator()(xcb_connection_t *pointer) - { - xcb_disconnect(pointer); - } -}; - void ScreenEdgeClientShowTest::testScreenEdgeShowHideX11_data() { QTest::addColumn("windowGeometry"); @@ -99,7 +91,7 @@ void ScreenEdgeClientShowTest::testScreenEdgeShowHideX11() // that should trigger a show of the window whenever the cursor is pushed against the screen edge // create the test window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); // atom for the screenedge show hide functionality Xcb::Atom atom(QByteArrayLiteral("_KDE_NET_WM_SCREEN_EDGE_SHOW"), false, c.get()); @@ -197,7 +189,7 @@ void ScreenEdgeClientShowTest::testScreenEdgeShowX11Touch() // that should trigger a show of the window whenever the touch screen swipe gesture is triggered // create the test window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); // atom for the screenedge show hide functionality Xcb::Atom atom(QByteArrayLiteral("_KDE_NET_WM_SCREEN_EDGE_SHOW"), false, c.get()); diff --git a/autotests/integration/shade_test.cpp b/autotests/integration/shade_test.cpp index 23111b43c6..3029b5de57 100644 --- a/autotests/integration/shade_test.cpp +++ b/autotests/integration/shade_test.cpp @@ -62,14 +62,8 @@ void ShadeTest::testShadeGeometry() // this test verifies that the geometry is properly restored after shading // see BUG: 362501 // create an xcb window - struct XcbConnectionDeleter - { - void operator()(xcb_connection_t *pointer) - { - xcb_disconnect(pointer); - } - }; - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); diff --git a/autotests/integration/stacking_order_test.cpp b/autotests/integration/stacking_order_test.cpp index 19d3810191..d3760e8c96 100644 --- a/autotests/integration/stacking_order_test.cpp +++ b/autotests/integration/stacking_order_test.cpp @@ -306,14 +306,6 @@ static xcb_window_t createGroupWindow(xcb_connection_t *conn, return wid; } -struct XcbConnectionDeleter -{ - void operator()(xcb_connection_t *c) - { - xcb_disconnect(c); - } -}; - void StackingOrderTest::testGroupTransientIsAboveWindowGroup() { // This test verifies that group transients are always above other @@ -321,8 +313,7 @@ void StackingOrderTest::testGroupTransientIsAboveWindowGroup() const QRect geometry = QRect(0, 0, 128, 128); - std::unique_ptr conn( - xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr conn = Test::createX11Connection(); QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded); @@ -434,8 +425,7 @@ void StackingOrderTest::testRaiseGroupTransient() { const QRect geometry = QRect(0, 0, 128, 128); - std::unique_ptr conn( - xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr conn = Test::createX11Connection(); QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded); @@ -565,8 +555,7 @@ void StackingOrderTest::testDeletedGroupTransient() const QRect geometry = QRect(0, 0, 128, 128); - std::unique_ptr conn( - xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr conn = Test::createX11Connection(); QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded); @@ -680,8 +669,7 @@ void StackingOrderTest::testDontKeepAboveNonModalDialogGroupTransients() const QRect geometry = QRect(0, 0, 128, 128); - std::unique_ptr conn( - xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr conn = Test::createX11Connection(); QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded); diff --git a/autotests/integration/struts_test.cpp b/autotests/integration/struts_test.cpp index 8d65f58ab5..6c25b2eafe 100644 --- a/autotests/integration/struts_test.cpp +++ b/autotests/integration/struts_test.cpp @@ -526,14 +526,6 @@ void StrutsTest::testX11Struts_data() << StrutRects(); } -struct XcbConnectionDeleter -{ - void operator()(xcb_connection_t *pointer) - { - xcb_disconnect(pointer); - } -}; - void StrutsTest::testX11Struts() { // this test verifies that struts are applied correctly for X11 windows @@ -562,7 +554,7 @@ void StrutsTest::testX11Struts() QCOMPARE(workspace()->restrictedMoveArea(desktop), StrutRects()); // create an xcb window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); xcb_window_t windowId = xcb_generate_id(c.get()); @@ -689,7 +681,7 @@ void StrutsTest::test363804() QCOMPARE(outputs[1]->geometry(), geometries[1]); // create an xcb window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); xcb_window_t windowId = xcb_generate_id(c.get()); @@ -771,7 +763,7 @@ void StrutsTest::testLeftScreenSmallerBottomAligned() VirtualDesktop *desktop = VirtualDesktopManager::self()->currentDesktop(); // create the panel - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); xcb_window_t windowId = xcb_generate_id(c.get()); @@ -884,7 +876,7 @@ void StrutsTest::testWindowMoveWithPanelBetweenScreens() VirtualDesktop *desktop = VirtualDesktopManager::self()->currentDesktop(); // create the panel on the right screen, left edge - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); xcb_window_t windowId = xcb_generate_id(c.get()); diff --git a/autotests/integration/test_helpers.cpp b/autotests/integration/test_helpers.cpp index 9321d17978..8f23490288 100644 --- a/autotests/integration/test_helpers.cpp +++ b/autotests/integration/test_helpers.cpp @@ -9,6 +9,7 @@ #include #include "kwin_wayland_test.h" +#include "qtconcurrentrun.h" #if KWIN_BUILD_SCREENLOCKER #include "screenlockerwatcher.h" @@ -41,7 +42,9 @@ #include #endif +#include #include +#include // system #include @@ -985,6 +988,16 @@ bool unlockScreen() } #endif // KWIN_BUILD_LOCKSCREEN +void XcbConnectionDeleter::operator()(xcb_connection_t *pointer) +{ + xcb_disconnect(pointer); +}; + +Test::XcbConnectionPtr createX11Connection() +{ + return Test::XcbConnectionPtr(xcb_connect(null, null)); +} + WaylandOutputManagementV2::WaylandOutputManagementV2(struct ::wl_registry *registry, int id, int version) : QObject() , QtWayland::kde_output_management_v2() diff --git a/autotests/integration/window_rules_test.cpp b/autotests/integration/window_rules_test.cpp index 3de4268d19..40921d9afb 100644 --- a/autotests/integration/window_rules_test.cpp +++ b/autotests/integration/window_rules_test.cpp @@ -93,7 +93,7 @@ void WindowRuleTest::testApplyInitialMaximizeVert() workspace()->slotReconfigure(); // create the test window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); xcb_window_t windowId = xcb_generate_id(c.get()); @@ -159,7 +159,7 @@ void WindowRuleTest::testWindowClassChange() workspace()->slotReconfigure(); // create the test window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); xcb_window_t windowId = xcb_generate_id(c.get()); diff --git a/autotests/integration/x11_window_test.cpp b/autotests/integration/x11_window_test.cpp index 49888a860b..7b5cd64662 100644 --- a/autotests/integration/x11_window_test.cpp +++ b/autotests/integration/x11_window_test.cpp @@ -84,14 +84,6 @@ void X11WindowTest::cleanup() Test::destroyWaylandConnection(); } -struct XcbConnectionDeleter -{ - void operator()(xcb_connection_t *pointer) - { - xcb_disconnect(pointer); - } -}; - void X11WindowTest::testMinimumSize() { // This test verifies that the minimum size constraint is correctly applied. @@ -100,7 +92,7 @@ void X11WindowTest::testMinimumSize() kwinApp()->setXwaylandScale(scale); // Create an xcb window. - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); @@ -206,7 +198,7 @@ void X11WindowTest::testMaximumSize() kwinApp()->setXwaylandScale(scale); // Create an xcb window. - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); @@ -311,7 +303,7 @@ void X11WindowTest::testResizeIncrements() kwinApp()->setXwaylandScale(scale); // Create an xcb window. - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); @@ -395,7 +387,7 @@ void X11WindowTest::testResizeIncrementsNoBaseSize() kwinApp()->setXwaylandScale(scale); // Create an xcb window. - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); @@ -498,7 +490,7 @@ void X11WindowTest::testTrimCaption() // this test verifies that caption is properly trimmed // create an xcb window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); @@ -548,7 +540,7 @@ void X11WindowTest::testFullscreenLayerWithActiveWaylandWindow() QCOMPARE(workspace()->outputs().count(), 1); // first create an X11 window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); @@ -667,7 +659,7 @@ void X11WindowTest::testFocusInWithWaylandLastActiveWindow() kwinApp()->setXwaylandScale(scale); // create an X11 window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); @@ -726,7 +718,7 @@ void X11WindowTest::testX11WindowId() kwinApp()->setXwaylandScale(scale); // create an X11 window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); @@ -801,7 +793,7 @@ void X11WindowTest::testCaptionChanges() // verifies that caption is updated correctly when the X11 window updates it // BUG: 383444 - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); @@ -876,7 +868,7 @@ void X11WindowTest::testCaptionMultipleWindows() // BUG 384760 // create first window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); @@ -952,7 +944,7 @@ void X11WindowTest::testFullscreenWindowGroups() QFETCH_GLOBAL(qreal, scale); kwinApp()->setXwaylandScale(scale); - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); @@ -1028,7 +1020,7 @@ void X11WindowTest::testActivateFocusedWindow() QFETCH_GLOBAL(qreal, scale); kwinApp()->setXwaylandScale(scale); - std::unique_ptr connection(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr connection = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(connection.get())); QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded); @@ -1096,7 +1088,7 @@ void X11WindowTest::testReentrantMoveResize() kwinApp()->setXwaylandScale(scale); // Create a test window. - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get()); diff --git a/autotests/integration/xwayland_input_test.cpp b/autotests/integration/xwayland_input_test.cpp index e024db0e2e..60c8f3f1bc 100644 --- a/autotests/integration/xwayland_input_test.cpp +++ b/autotests/integration/xwayland_input_test.cpp @@ -63,14 +63,6 @@ void XWaylandInputTest::init() QVERIFY(waylandServer()->windows().isEmpty()); } -struct XcbConnectionDeleter -{ - void operator()(xcb_connection_t *pointer) - { - xcb_disconnect(pointer); - } -}; - class X11EventReaderHelper : public QObject { Q_OBJECT @@ -123,7 +115,7 @@ void XWaylandInputTest::testPointerEnterLeaveSsd() // this test simulates a pointer enter and pointer leave on a server-side decorated X11 window // create the test window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); if (xcb_get_setup(c.get())->release_number < 11800000) { QSKIP("XWayland 1.18 required"); @@ -192,7 +184,7 @@ void XWaylandInputTest::testPointerEventLeaveCsd() { // this test simulates a pointer enter and pointer leave on a client-side decorated X11 window - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); if (xcb_get_setup(c.get())->release_number < 11800000) { diff --git a/autotests/integration/xwaylandserver_crash_test.cpp b/autotests/integration/xwaylandserver_crash_test.cpp index ed23dc1382..122fe5d4c3 100644 --- a/autotests/integration/xwaylandserver_crash_test.cpp +++ b/autotests/integration/xwaylandserver_crash_test.cpp @@ -23,14 +23,6 @@ namespace KWin { -struct XcbConnectionDeleter -{ - void operator()(xcb_connection_t *pointer) - { - xcb_disconnect(pointer); - } -}; - static const QString s_socketName = QStringLiteral("wayland_test_kwin_xwayland_server_crash-0"); class XwaylandServerCrashTest : public QObject @@ -69,7 +61,7 @@ void XwaylandServerCrashTest::testCrash() // This test verifies that all connected X11 clients get destroyed when Xwayland crashes. // Create a normal window. - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect windowGeometry(0, 0, 100, 200); xcb_window_t windowId1 = xcb_generate_id(c.get()); diff --git a/autotests/integration/xwaylandserver_restart_test.cpp b/autotests/integration/xwaylandserver_restart_test.cpp index df80e69475..91d257e821 100644 --- a/autotests/integration/xwaylandserver_restart_test.cpp +++ b/autotests/integration/xwaylandserver_restart_test.cpp @@ -21,14 +21,6 @@ namespace KWin { -struct XcbConnectionDeleter -{ - void operator()(xcb_connection_t *pointer) - { - xcb_disconnect(pointer); - } -}; - static const QString s_socketName = QStringLiteral("wayland_test_kwin_xwayland_server_restart-0"); class XwaylandServerRestartTest : public QObject @@ -75,7 +67,7 @@ void XwaylandServerRestartTest::testRestart() QCOMPARE(startedSpy.count(), 1); // Check that the compositor still accepts new X11 clients. - std::unique_ptr c(xcb_connect(nullptr, nullptr)); + Test::XcbConnectionPtr c = Test::createX11Connection(); QVERIFY(!xcb_connection_has_error(c.get())); const QRect rect(0, 0, 100, 200); xcb_window_t windowId = xcb_generate_id(c.get());