From e16069ae77cbacaeae1db9bca6641918ae3ada5e Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Wed, 12 Jun 2024 16:16:54 +0200 Subject: [PATCH] autotests: add Xwayland scale changes to the output changes test CCBUG: 487409 --- autotests/integration/CMakeLists.txt | 2 +- autotests/integration/outputchanges_test.cpp | 78 ++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/autotests/integration/CMakeLists.txt b/autotests/integration/CMakeLists.txt index 1fea5bada7..3a5a9b62af 100644 --- a/autotests/integration/CMakeLists.txt +++ b/autotests/integration/CMakeLists.txt @@ -144,7 +144,7 @@ integrationTest(NAME testActivation SRCS activation_test.cpp) integrationTest(NAME testInputMethod SRCS inputmethod_test.cpp LIBS XKB::XKB) integrationTest(NAME testScreens SRCS screens_test.cpp) integrationTest(NAME testScreenEdges SRCS screenedges_test.cpp LIBS XCB::ICCCM) -integrationTest(NAME testOutputChanges SRCS outputchanges_test.cpp) +integrationTest(NAME testOutputChanges SRCS outputchanges_test.cpp LIBS XCB::ICCCM) integrationTest(NAME testTiles SRCS tiles_test.cpp) integrationTest(NAME testFractionalScaling SRCS fractional_scaling_test.cpp) integrationTest(NAME testMoveResize SRCS move_resize_window_test.cpp LIBS XCB::ICCCM) diff --git a/autotests/integration/outputchanges_test.cpp b/autotests/integration/outputchanges_test.cpp index 7977f7b179..26f584e6ee 100644 --- a/autotests/integration/outputchanges_test.cpp +++ b/autotests/integration/outputchanges_test.cpp @@ -14,8 +14,11 @@ #include "wayland_server.h" #include "window.h" #include "workspace.h" +#include "x11window.h" #include +#include +#include using namespace std::chrono_literals; @@ -51,6 +54,7 @@ private Q_SLOTS: void testInvalidGeometryRestoreAfterEnablingOutput(); void testMaximizedWindowDoesntDisappear_data(); void testMaximizedWindowDoesntDisappear(); + void testXwaylandScaleChange(); void testWindowNotRestoredAfterMovingWindowAndEnablingOutput(); void testLaptopLidClosed(); @@ -1004,6 +1008,80 @@ void OutputChangesTest::testLaptopLidClosed() input()->removeInputDevice(lidSwitch.get()); } +static X11Window *createX11Window(xcb_connection_t *connection, const QRect &geometry, std::function setup = {}) +{ + xcb_window_t windowId = xcb_generate_id(connection); + xcb_create_window(connection, XCB_COPY_FROM_PARENT, windowId, rootWindow(), + geometry.x(), + geometry.y(), + geometry.width(), + geometry.height(), + 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr); + + xcb_size_hints_t hints; + memset(&hints, 0, sizeof(hints)); + xcb_icccm_size_hints_set_position(&hints, 1, geometry.x(), geometry.y()); + xcb_icccm_size_hints_set_size(&hints, 1, geometry.width(), geometry.height()); + xcb_icccm_set_wm_normal_hints(connection, windowId, &hints); + + if (setup) { + setup(windowId); + } + + xcb_map_window(connection, windowId); + xcb_flush(connection); + + QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded); + if (!windowCreatedSpy.wait()) { + return nullptr; + } + return windowCreatedSpy.last().first().value(); +} + +void OutputChangesTest::testXwaylandScaleChange() +{ + Test::setOutputConfig({ + QRect(0, 0, 1280, 1024), + QRect(1280, 0, 1280, 1024), + }); + const auto outputs = workspace()->outputs(); + + { + OutputConfiguration config; + config.changeSet(outputs[0])->scale = 2; + config.changeSet(outputs[1])->scale = 1; + workspace()->applyOutputConfiguration(config); + } + QCOMPARE(kwinApp()->xwaylandScale(), 2); + + Test::XcbConnectionPtr c = Test::createX11Connection(); + QVERIFY(!xcb_connection_has_error(c.get())); + X11Window *window = createX11Window(c.get(), QRect(0, 0, 100, 200)); + const QRectF originalGeometry = window->frameGeometry(); + + // disable the left output -> window gets moved to the right output + { + OutputConfiguration config; + config.changeSet(outputs[0])->enabled = false; + workspace()->applyOutputConfiguration(config); + } + + // the window should still have logical size of 100, 200 + QCOMPARE(kwinApp()->xwaylandScale(), 1); + QCOMPARE(window->frameGeometry().size(), originalGeometry.size()); + + // enable the left output again + { + OutputConfiguration config; + config.changeSet(outputs[0])->enabled = true; + workspace()->applyOutputConfiguration(config); + } + + // the window should be back in its original geometry + QCOMPARE(kwinApp()->xwaylandScale(), 2); + QCOMPARE(window->frameGeometry(), originalGeometry); +} + } // namespace KWin WAYLANDTEST_MAIN(KWin::OutputChangesTest)