KWin
Loading...
Searching...
No Matches
shade_test.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#include "kwin_wayland_test.h"
10
11#include "core/output.h"
12#include "pointer_input.h"
13#include "wayland_server.h"
14#include "workspace.h"
15#include "x11window.h"
16
17#include <KDecoration2/Decoration>
18
19#include <netwm.h>
20#include <xcb/xcb_icccm.h>
21
22namespace KWin
23{
24
25static const QString s_socketName = QStringLiteral("wayland_test_kwin_shade-0");
26
27class ShadeTest : public QObject
28{
29 Q_OBJECT
30private Q_SLOTS:
31 void initTestCase();
32 void init();
33 void testShadeGeometry();
34};
35
36void ShadeTest::initTestCase()
37{
38 qRegisterMetaType<KWin::Window *>();
39 QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
40 QVERIFY(waylandServer()->init(s_socketName));
42 QRect(0, 0, 1280, 1024),
43 QRect(1280, 0, 1280, 1024),
44 });
45
46 kwinApp()->start();
47 QVERIFY(applicationStartedSpy.wait());
48 const auto outputs = workspace()->outputs();
49 QCOMPARE(outputs.count(), 2);
50 QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1280, 1024));
51 QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 1280, 1024));
52 setenv("QT_QPA_PLATFORM", "wayland", true);
53}
54
55void ShadeTest::init()
56{
57 workspace()->setActiveOutput(QPoint(640, 512));
58 input()->pointer()->warp(QPoint(640, 512));
59}
60
61void ShadeTest::testShadeGeometry()
62{
63 // this test verifies that the geometry is properly restored after shading
64 // see BUG: 362501
65 // create an xcb window
66
68 QVERIFY(!xcb_connection_has_error(c.get()));
69 const QRect windowGeometry(0, 0, 100, 200);
70 xcb_window_t windowId = xcb_generate_id(c.get());
71 xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
72 windowGeometry.x(),
73 windowGeometry.y(),
74 windowGeometry.width(),
75 windowGeometry.height(),
76 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
77 xcb_size_hints_t hints;
78 memset(&hints, 0, sizeof(hints));
79 xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
80 xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
81 xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
82 xcb_map_window(c.get(), windowId);
83 xcb_flush(c.get());
84
85 // we should get a window for it
86 QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
87 QVERIFY(windowCreatedSpy.wait());
88 X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
89 QVERIFY(window);
90 QCOMPARE(window->window(), windowId);
91 QVERIFY(window->isDecorated());
92 QVERIFY(window->isShadeable());
93 QVERIFY(!window->isShade());
94 QVERIFY(window->isActive());
95
96 // now shade the window
97 const QRectF geoBeforeShade = window->frameGeometry();
98 QVERIFY(geoBeforeShade.isValid());
99 QVERIFY(!geoBeforeShade.isEmpty());
101 QVERIFY(window->isShade());
102 QVERIFY(window->frameGeometry() != geoBeforeShade);
103 // and unshade again
105 QVERIFY(!window->isShade());
106 QCOMPARE(window->frameGeometry(), geoBeforeShade);
107
108 // and destroy the window again
109 xcb_unmap_window(c.get(), windowId);
110 xcb_destroy_window(c.get(), windowId);
111 xcb_flush(c.get());
112 c.reset();
113
114 QSignalSpy windowClosedSpy(window, &X11Window::closed);
115 QVERIFY(windowClosedSpy.wait());
116}
117
118}
119
121#include "shade_test.moc"
PointerInputRedirection * pointer() const
Definition input.h:220
void warp(const QPointF &pos)
void windowAdded(KWin::Window *)
QList< Output * > outputs() const
Definition workspace.h:762
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()
Definition xcb.h:24
WaylandServer * waylandServer()
Workspace * workspace()
Definition workspace.h:830
InputRedirection * input()
Definition input.h:549