Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/input_stacking_order.cpp
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | |||||
52 | private Q_SLOTS: | 52 | private Q_SLOTS: | ||
53 | void initTestCase(); | 53 | void initTestCase(); | ||
54 | void init(); | 54 | void init(); | ||
55 | void cleanup(); | 55 | void cleanup(); | ||
56 | void testPointerFocusUpdatesOnStackingOrderChange(); | 56 | void testPointerFocusUpdatesOnStackingOrderChange(); | ||
57 | 57 | | |||
58 | private: | 58 | private: | ||
59 | void render(KWayland::Client::Surface *surface); | 59 | void render(KWayland::Client::Surface *surface); | ||
60 | KWayland::Client::ConnectionThread *m_connection = nullptr; | | |||
61 | KWayland::Client::Compositor *m_compositor = nullptr; | | |||
62 | KWayland::Client::Seat *m_seat = nullptr; | | |||
63 | KWayland::Client::ShmPool *m_shm = nullptr; | | |||
64 | KWayland::Client::Shell *m_shell = nullptr; | | |||
65 | KWayland::Client::EventQueue *m_queue = nullptr; | | |||
66 | QThread *m_thread = nullptr; | | |||
67 | }; | 60 | }; | ||
68 | 61 | | |||
69 | void InputStackingOrderTest::initTestCase() | 62 | void InputStackingOrderTest::initTestCase() | ||
70 | { | 63 | { | ||
71 | qRegisterMetaType<KWin::ShellClient*>(); | 64 | qRegisterMetaType<KWin::ShellClient*>(); | ||
72 | qRegisterMetaType<KWin::AbstractClient*>(); | 65 | qRegisterMetaType<KWin::AbstractClient*>(); | ||
73 | qRegisterMetaType<KWin::Deleted*>(); | 66 | qRegisterMetaType<KWin::Deleted*>(); | ||
74 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | 67 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||
Show All 9 Lines | |||||
84 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | 77 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | ||
85 | setenv("QT_QPA_PLATFORM", "wayland", true); | 78 | setenv("QT_QPA_PLATFORM", "wayland", true); | ||
86 | waylandServer()->initWorkspace(); | 79 | waylandServer()->initWorkspace(); | ||
87 | } | 80 | } | ||
88 | 81 | | |||
89 | void InputStackingOrderTest::init() | 82 | void InputStackingOrderTest::init() | ||
90 | { | 83 | { | ||
91 | using namespace KWayland::Client; | 84 | using namespace KWayland::Client; | ||
92 | // setup connection | 85 | QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat)); | ||
93 | m_connection = new ConnectionThread; | 86 | QVERIFY(Test::waitForWaylandPointer()); | ||
94 | QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); | | |||
95 | QVERIFY(connectedSpy.isValid()); | | |||
96 | m_connection->setSocketName(s_socketName); | | |||
97 | | ||||
98 | m_thread = new QThread(this); | | |||
99 | m_connection->moveToThread(m_thread); | | |||
100 | m_thread->start(); | | |||
101 | | ||||
102 | m_connection->initConnection(); | | |||
103 | QVERIFY(connectedSpy.wait()); | | |||
104 | | ||||
105 | m_queue = new EventQueue(this); | | |||
106 | QVERIFY(!m_queue->isValid()); | | |||
107 | m_queue->setup(m_connection); | | |||
108 | QVERIFY(m_queue->isValid()); | | |||
109 | | ||||
110 | Registry registry; | | |||
111 | registry.setEventQueue(m_queue); | | |||
112 | QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); | | |||
113 | QSignalSpy shmSpy(®istry, &Registry::shmAnnounced); | | |||
114 | QSignalSpy shellSpy(®istry, &Registry::shellAnnounced); | | |||
115 | QSignalSpy seatSpy(®istry, &Registry::seatAnnounced); | | |||
116 | QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); | | |||
117 | QVERIFY(allAnnounced.isValid()); | | |||
118 | QVERIFY(shmSpy.isValid()); | | |||
119 | QVERIFY(shellSpy.isValid()); | | |||
120 | QVERIFY(compositorSpy.isValid()); | | |||
121 | QVERIFY(seatSpy.isValid()); | | |||
122 | registry.create(m_connection->display()); | | |||
123 | QVERIFY(registry.isValid()); | | |||
124 | registry.setup(); | | |||
125 | QVERIFY(allAnnounced.wait()); | | |||
126 | QVERIFY(!compositorSpy.isEmpty()); | | |||
127 | QVERIFY(!shmSpy.isEmpty()); | | |||
128 | QVERIFY(!shellSpy.isEmpty()); | | |||
129 | QVERIFY(!seatSpy.isEmpty()); | | |||
130 | | ||||
131 | m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this); | | |||
132 | QVERIFY(m_compositor->isValid()); | | |||
133 | m_shm = registry.createShmPool(shmSpy.first().first().value<quint32>(), shmSpy.first().last().value<quint32>(), this); | | |||
134 | QVERIFY(m_shm->isValid()); | | |||
135 | m_shell = registry.createShell(shellSpy.first().first().value<quint32>(), shellSpy.first().last().value<quint32>(), this); | | |||
136 | QVERIFY(m_shell->isValid()); | | |||
137 | m_seat = registry.createSeat(seatSpy.first().first().value<quint32>(), seatSpy.first().last().value<quint32>(), this); | | |||
138 | QVERIFY(m_seat->isValid()); | | |||
139 | QSignalSpy hasPointerSpy(m_seat, &Seat::hasPointerChanged); | | |||
140 | QVERIFY(hasPointerSpy.isValid()); | | |||
141 | QVERIFY(hasPointerSpy.wait()); | | |||
142 | 87 | | |||
143 | screens()->setCurrent(0); | 88 | screens()->setCurrent(0); | ||
144 | Cursor::setPos(QPoint(640, 512)); | 89 | Cursor::setPos(QPoint(640, 512)); | ||
145 | } | 90 | } | ||
146 | 91 | | |||
147 | void InputStackingOrderTest::cleanup() | 92 | void InputStackingOrderTest::cleanup() | ||
148 | { | 93 | { | ||
149 | delete m_compositor; | 94 | Test::destroyWaylandConnection(); | ||
150 | m_compositor = nullptr; | | |||
151 | delete m_seat; | | |||
152 | m_seat = nullptr; | | |||
153 | delete m_shm; | | |||
154 | m_shm = nullptr; | | |||
155 | delete m_shell; | | |||
156 | m_shell = nullptr; | | |||
157 | delete m_queue; | | |||
158 | m_queue = nullptr; | | |||
159 | if (m_thread) { | | |||
160 | m_connection->deleteLater(); | | |||
161 | m_thread->quit(); | | |||
162 | m_thread->wait(); | | |||
163 | delete m_thread; | | |||
164 | m_thread = nullptr; | | |||
165 | m_connection = nullptr; | | |||
166 | } | | |||
167 | } | 95 | } | ||
168 | 96 | | |||
169 | void InputStackingOrderTest::render(KWayland::Client::Surface *surface) | 97 | void InputStackingOrderTest::render(KWayland::Client::Surface *surface) | ||
170 | { | 98 | { | ||
171 | QImage img(QSize(100, 50), QImage::Format_ARGB32); | 99 | Test::render(surface, QSize(100, 50), Qt::blue); | ||
172 | img.fill(Qt::blue); | 100 | Test::flushWaylandConnection(); | ||
173 | surface->attachBuffer(m_shm->createBuffer(img)); | | |||
174 | surface->damage(QRect(0, 0, 100, 50)); | | |||
175 | surface->commit(KWayland::Client::Surface::CommitFlag::None); | | |||
176 | m_connection->flush(); | | |||
177 | } | 101 | } | ||
178 | 102 | | |||
179 | void InputStackingOrderTest::testPointerFocusUpdatesOnStackingOrderChange() | 103 | void InputStackingOrderTest::testPointerFocusUpdatesOnStackingOrderChange() | ||
180 | { | 104 | { | ||
181 | // this test creates two windows which overlap | 105 | // this test creates two windows which overlap | ||
182 | // the pointer is in the overlapping area which means the top most window has focus | 106 | // the pointer is in the overlapping area which means the top most window has focus | ||
183 | // as soon as the top most window gets lowered the window should lose focus and the | 107 | // as soon as the top most window gets lowered the window should lose focus and the | ||
184 | // other window should gain focus without a mouse event in between | 108 | // other window should gain focus without a mouse event in between | ||
185 | using namespace KWayland::Client; | 109 | using namespace KWayland::Client; | ||
186 | // create pointer and signal spy for enter and leave signals | 110 | // create pointer and signal spy for enter and leave signals | ||
187 | auto pointer = m_seat->createPointer(m_seat); | 111 | auto pointer = Test::waylandSeat()->createPointer(Test::waylandSeat()); | ||
188 | QVERIFY(pointer); | 112 | QVERIFY(pointer); | ||
189 | QVERIFY(pointer->isValid()); | 113 | QVERIFY(pointer->isValid()); | ||
190 | QSignalSpy enteredSpy(pointer, &Pointer::entered); | 114 | QSignalSpy enteredSpy(pointer, &Pointer::entered); | ||
191 | QVERIFY(enteredSpy.isValid()); | 115 | QVERIFY(enteredSpy.isValid()); | ||
192 | QSignalSpy leftSpy(pointer, &Pointer::left); | 116 | QSignalSpy leftSpy(pointer, &Pointer::left); | ||
193 | QVERIFY(leftSpy.isValid()); | 117 | QVERIFY(leftSpy.isValid()); | ||
194 | 118 | | |||
195 | // now create the two windows and make them overlap | 119 | // now create the two windows and make them overlap | ||
196 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | 120 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | ||
197 | QVERIFY(clientAddedSpy.isValid()); | 121 | QVERIFY(clientAddedSpy.isValid()); | ||
198 | Surface *surface1 = m_compositor->createSurface(m_compositor); | 122 | Surface *surface1 = Test::createSurface(Test::waylandCompositor()); | ||
199 | QVERIFY(surface1); | 123 | QVERIFY(surface1); | ||
200 | ShellSurface *shellSurface1 = m_shell->createSurface(surface1, surface1); | 124 | ShellSurface *shellSurface1 = Test::createShellSurface(surface1, surface1); | ||
201 | QVERIFY(shellSurface1); | 125 | QVERIFY(shellSurface1); | ||
202 | render(surface1); | 126 | render(surface1); | ||
203 | QVERIFY(clientAddedSpy.wait()); | 127 | QVERIFY(clientAddedSpy.wait()); | ||
204 | AbstractClient *window1 = workspace()->activeClient(); | 128 | AbstractClient *window1 = workspace()->activeClient(); | ||
205 | QVERIFY(window1); | 129 | QVERIFY(window1); | ||
206 | 130 | | |||
207 | Surface *surface2 = m_compositor->createSurface(m_compositor); | 131 | Surface *surface2 = Test::createSurface(Test::waylandCompositor()); | ||
208 | QVERIFY(surface2); | 132 | QVERIFY(surface2); | ||
209 | ShellSurface *shellSurface2 = m_shell->createSurface(surface2, surface2); | 133 | ShellSurface *shellSurface2 = Test::createShellSurface(surface2, surface2); | ||
210 | QVERIFY(shellSurface2); | 134 | QVERIFY(shellSurface2); | ||
211 | render(surface2); | 135 | render(surface2); | ||
212 | QVERIFY(clientAddedSpy.wait()); | 136 | QVERIFY(clientAddedSpy.wait()); | ||
213 | 137 | | |||
214 | AbstractClient *window2 = workspace()->activeClient(); | 138 | AbstractClient *window2 = workspace()->activeClient(); | ||
215 | QVERIFY(window2); | 139 | QVERIFY(window2); | ||
216 | QVERIFY(window1 != window2); | 140 | QVERIFY(window1 != window2); | ||
217 | 141 | | |||
Show All 39 Lines |