20#include <xcb/xcb_icccm.h>
25static const QString s_socketName = QStringLiteral(
"wayland_test_kwin_x11_desktop_window-0");
34 void testDesktopWindow();
39void X11DesktopWindowTest::initTestCase()
41 qRegisterMetaType<KWin::Window *>();
45 QRect(0, 0, 1280, 1024),
46 QRect(1280, 0, 1280, 1024),
50 QVERIFY(applicationStartedSpy.wait());
52 QCOMPARE(outputs.count(), 2);
53 QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1280, 1024));
54 QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 1280, 1024));
55 setenv(
"QT_QPA_PLATFORM",
"wayland",
true);
58void X11DesktopWindowTest::init()
64void X11DesktopWindowTest::cleanup()
68void X11DesktopWindowTest::testDesktopWindow()
75 QVERIFY(!xcb_connection_has_error(c.get()));
77 xcb_window_t windowId = xcb_generate_id(c.get());
78 const QRect windowGeometry(0, 0, 1280, 1024);
81 auto findDepth = [&c]() -> xcb_visualid_t {
83 const xcb_setup_t *setup = xcb_get_setup(c.get());
85 for (
auto screen = xcb_setup_roots_iterator(setup); screen.rem; xcb_screen_next(&screen)) {
86 for (
auto depth = xcb_screen_allowed_depths_iterator(screen.data); depth.rem; xcb_depth_next(&depth)) {
87 if (depth.data->depth != 32) {
90 const int len = xcb_depth_visuals_length(depth.data);
91 const xcb_visualtype_t *visuals = xcb_depth_visuals(depth.data);
93 for (
int i = 0; i < len; i++) {
94 return visuals[0].visual_id;
100 auto visualId = findDepth();
101 auto colormapId = xcb_generate_id(c.get());
102 auto cmCookie = xcb_create_colormap_checked(c.get(), XCB_COLORMAP_ALLOC_NONE, colormapId,
rootWindow(), visualId);
103 QVERIFY(!xcb_request_check(c.get(), cmCookie));
105 const uint32_t values[] = {XCB_PIXMAP_NONE, Xcb::defaultScreen()->black_pixel, colormapId};
106 auto cookie = xcb_create_window_checked(c.get(), 32, windowId,
rootWindow(),
109 windowGeometry.width(),
110 windowGeometry.height(),
111 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, visualId, XCB_CW_BACK_PIXMAP | XCB_CW_BORDER_PIXEL | XCB_CW_COLORMAP, values);
112 QVERIFY(!xcb_request_check(c.get(), cookie));
113 xcb_size_hints_t hints;
114 memset(&hints, 0,
sizeof(hints));
115 xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
116 xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
117 xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
118 NETWinInfo info(c.get(), windowId,
rootWindow(), NET::WMAllProperties, NET::WM2AllProperties);
119 info.setWindowType(NET::Desktop);
120 xcb_map_window(c.get(), windowId);
124 Xcb::WindowGeometry geo(windowId);
125 QCOMPARE(geo->depth, uint8_t(32));
129 QVERIFY(windowCreatedSpy.wait());
130 X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
132 QCOMPARE(window->window(), windowId);
133 QVERIFY(!window->isDecorated());
134 QCOMPARE(window->windowType(), NET::Desktop);
135 QCOMPARE(window->frameGeometry(), windowGeometry);
136 QVERIFY(window->isDesktop());
137 QCOMPARE(window->depth(), 24);
138 QVERIFY(!window->hasAlpha());
141 xcb_unmap_window(c.get(), windowId);
142 xcb_destroy_window(c.get(), windowId);
147 QVERIFY(windowClosedSpy.wait());
153#include "desktop_window_x11_test.moc"
void windowAdded(KWin::Window *)
QList< Output * > outputs() const
void setActiveOutput(Output *output)
#define WAYLANDTEST_MAIN(TestObject)
void setOutputConfig(const QList< QRect > &geometries)
XcbConnectionPtr createX11Connection()
std::unique_ptr< xcb_connection_t, XcbConnectionDeleter > XcbConnectionPtr
KWIN_EXPORT xcb_window_t rootWindow()
WaylandServer * waylandServer()
InputRedirection * input()