Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/transient_no_input_test.cpp
Show All 21 Lines | |||||
22 | #include "abstract_client.h" | 22 | #include "abstract_client.h" | ||
23 | #include "screens.h" | 23 | #include "screens.h" | ||
24 | #include "wayland_server.h" | 24 | #include "wayland_server.h" | ||
25 | #include "workspace.h" | 25 | #include "workspace.h" | ||
26 | #include "shell_client.h" | 26 | #include "shell_client.h" | ||
27 | 27 | | |||
28 | #include <KWayland/Client/connection_thread.h> | 28 | #include <KWayland/Client/connection_thread.h> | ||
29 | #include <KWayland/Client/compositor.h> | 29 | #include <KWayland/Client/compositor.h> | ||
30 | #include <KWayland/Client/event_queue.h> | | |||
31 | #include <KWayland/Client/registry.h> | | |||
32 | #include <KWayland/Client/shell.h> | 30 | #include <KWayland/Client/shell.h> | ||
33 | #include <KWayland/Client/shm_pool.h> | | |||
34 | #include <KWayland/Client/surface.h> | 31 | #include <KWayland/Client/surface.h> | ||
35 | 32 | | |||
36 | namespace KWin | 33 | namespace KWin | ||
37 | { | 34 | { | ||
38 | 35 | | |||
39 | static const QString s_socketName = QStringLiteral("wayland_test_kwin_transient_no_input-0"); | 36 | static const QString s_socketName = QStringLiteral("wayland_test_kwin_transient_no_input-0"); | ||
40 | 37 | | |||
41 | class TransientNoInputTest : public QObject | 38 | class TransientNoInputTest : public QObject | ||
42 | { | 39 | { | ||
43 | Q_OBJECT | 40 | Q_OBJECT | ||
44 | private Q_SLOTS: | 41 | private Q_SLOTS: | ||
45 | void initTestCase(); | 42 | void initTestCase(); | ||
46 | void init(); | 43 | void init(); | ||
47 | void cleanup(); | 44 | void cleanup(); | ||
48 | void testTransientNoFocus(); | 45 | void testTransientNoFocus(); | ||
49 | | ||||
50 | private: | | |||
51 | KWayland::Client::ConnectionThread *m_connection = nullptr; | | |||
52 | KWayland::Client::Compositor *m_compositor = nullptr; | | |||
53 | KWayland::Client::ShmPool *m_shm = nullptr; | | |||
54 | KWayland::Client::Shell *m_shell = nullptr; | | |||
55 | KWayland::Client::EventQueue *m_queue = nullptr; | | |||
56 | QThread *m_thread = nullptr; | | |||
57 | }; | 46 | }; | ||
58 | 47 | | |||
59 | void TransientNoInputTest::initTestCase() | 48 | void TransientNoInputTest::initTestCase() | ||
60 | { | 49 | { | ||
61 | qRegisterMetaType<KWin::ShellClient*>(); | 50 | qRegisterMetaType<KWin::ShellClient*>(); | ||
62 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | 51 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||
63 | QVERIFY(workspaceCreatedSpy.isValid()); | 52 | QVERIFY(workspaceCreatedSpy.isValid()); | ||
64 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | 53 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | ||
65 | waylandServer()->init(s_socketName.toLocal8Bit()); | 54 | waylandServer()->init(s_socketName.toLocal8Bit()); | ||
66 | kwinApp()->start(); | 55 | kwinApp()->start(); | ||
67 | QVERIFY(workspaceCreatedSpy.wait()); | 56 | QVERIFY(workspaceCreatedSpy.wait()); | ||
68 | } | 57 | } | ||
69 | 58 | | |||
70 | void TransientNoInputTest::init() | 59 | void TransientNoInputTest::init() | ||
71 | { | 60 | { | ||
72 | using namespace KWayland::Client; | 61 | QVERIFY(Test::setupWaylandConnection(s_socketName)); | ||
73 | // setup connection | | |||
74 | m_connection = new ConnectionThread; | | |||
75 | QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); | | |||
76 | QVERIFY(connectedSpy.isValid()); | | |||
77 | m_connection->setSocketName(s_socketName); | | |||
78 | | ||||
79 | m_thread = new QThread(this); | | |||
80 | m_connection->moveToThread(m_thread); | | |||
81 | m_thread->start(); | | |||
82 | | ||||
83 | m_connection->initConnection(); | | |||
84 | QVERIFY(connectedSpy.wait()); | | |||
85 | | ||||
86 | m_queue = new EventQueue(this); | | |||
87 | QVERIFY(!m_queue->isValid()); | | |||
88 | m_queue->setup(m_connection); | | |||
89 | QVERIFY(m_queue->isValid()); | | |||
90 | | ||||
91 | Registry registry; | | |||
92 | registry.setEventQueue(m_queue); | | |||
93 | QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); | | |||
94 | QSignalSpy shmSpy(®istry, &Registry::shmAnnounced); | | |||
95 | QSignalSpy shellSpy(®istry, &Registry::shellAnnounced); | | |||
96 | QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); | | |||
97 | QVERIFY(allAnnounced.isValid()); | | |||
98 | QVERIFY(shmSpy.isValid()); | | |||
99 | QVERIFY(shellSpy.isValid()); | | |||
100 | QVERIFY(compositorSpy.isValid()); | | |||
101 | registry.create(m_connection->display()); | | |||
102 | QVERIFY(registry.isValid()); | | |||
103 | registry.setup(); | | |||
104 | QVERIFY(allAnnounced.wait()); | | |||
105 | QVERIFY(!compositorSpy.isEmpty()); | | |||
106 | QVERIFY(!shmSpy.isEmpty()); | | |||
107 | QVERIFY(!shellSpy.isEmpty()); | | |||
108 | | ||||
109 | m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this); | | |||
110 | QVERIFY(m_compositor->isValid()); | | |||
111 | m_shm = registry.createShmPool(shmSpy.first().first().value<quint32>(), shmSpy.first().last().value<quint32>(), this); | | |||
112 | QVERIFY(m_shm->isValid()); | | |||
113 | m_shell = registry.createShell(shellSpy.first().first().value<quint32>(), shellSpy.first().last().value<quint32>(), this); | | |||
114 | QVERIFY(m_shell->isValid()); | | |||
115 | } | 62 | } | ||
116 | 63 | | |||
117 | void TransientNoInputTest::cleanup() | 64 | void TransientNoInputTest::cleanup() | ||
118 | { | 65 | { | ||
119 | delete m_compositor; | 66 | Test::destroyWaylandConnection(); | ||
120 | m_compositor = nullptr; | | |||
121 | delete m_shm; | | |||
122 | m_shm = nullptr; | | |||
123 | delete m_shell; | | |||
124 | m_shell = nullptr; | | |||
125 | delete m_queue; | | |||
126 | m_queue = nullptr; | | |||
127 | if (m_thread) { | | |||
128 | m_thread->quit(); | | |||
129 | m_thread->wait(); | | |||
130 | delete m_thread; | | |||
131 | m_thread = nullptr; | | |||
132 | } | | |||
133 | | ||||
134 | } | 67 | } | ||
135 | 68 | | |||
136 | void TransientNoInputTest::testTransientNoFocus() | 69 | void TransientNoInputTest::testTransientNoFocus() | ||
137 | { | 70 | { | ||
138 | using namespace KWayland::Client; | 71 | using namespace KWayland::Client; | ||
139 | 72 | | |||
140 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | 73 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | ||
141 | QVERIFY(clientAddedSpy.isValid()); | 74 | QVERIFY(clientAddedSpy.isValid()); | ||
142 | 75 | | |||
143 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | 76 | QScopedPointer<Surface> surface(Test::createSurface()); | ||
144 | QVERIFY(!surface.isNull()); | 77 | QVERIFY(!surface.isNull()); | ||
145 | 78 | | |||
146 | QScopedPointer<ShellSurface> shellSurface(m_shell->createSurface(surface.data())); | 79 | QScopedPointer<ShellSurface> shellSurface(Test::createShellSurface(surface.data())); | ||
147 | QVERIFY(!shellSurface.isNull()); | 80 | QVERIFY(!shellSurface.isNull()); | ||
148 | // let's render | 81 | // let's render | ||
149 | QImage img(QSize(100, 50), QImage::Format_ARGB32); | 82 | Test::render(surface.data(), QSize(100, 50), Qt::blue); | ||
150 | img.fill(Qt::blue); | | |||
151 | surface->attachBuffer(m_shm->createBuffer(img)); | | |||
152 | surface->damage(QRect(0, 0, 100, 50)); | | |||
153 | surface->commit(); | | |||
154 | 83 | | |||
155 | m_connection->flush(); | 84 | Test::flushWaylandConnection(); | ||
156 | QVERIFY(clientAddedSpy.wait()); | 85 | QVERIFY(clientAddedSpy.wait()); | ||
157 | AbstractClient *c = workspace()->activeClient(); | 86 | AbstractClient *c = workspace()->activeClient(); | ||
158 | QVERIFY(c); | 87 | QVERIFY(c); | ||
159 | QCOMPARE(clientAddedSpy.first().first().value<ShellClient*>(), c); | 88 | QCOMPARE(clientAddedSpy.first().first().value<ShellClient*>(), c); | ||
160 | 89 | | |||
161 | // let's create a transient with no input | 90 | // let's create a transient with no input | ||
162 | QScopedPointer<Surface> transientSurface(m_compositor->createSurface()); | 91 | QScopedPointer<Surface> transientSurface(Test::createSurface()); | ||
163 | QVERIFY(!transientSurface.isNull()); | 92 | QVERIFY(!transientSurface.isNull()); | ||
164 | QScopedPointer<ShellSurface> transientShellSurface(m_shell->createSurface(transientSurface.data())); | 93 | QScopedPointer<ShellSurface> transientShellSurface(Test::createShellSurface(transientSurface.data())); | ||
165 | QVERIFY(!transientShellSurface.isNull()); | 94 | QVERIFY(!transientShellSurface.isNull()); | ||
166 | transientShellSurface->setTransient(surface.data(), QPoint(10, 20), ShellSurface::TransientFlag::NoFocus); | 95 | transientShellSurface->setTransient(surface.data(), QPoint(10, 20), ShellSurface::TransientFlag::NoFocus); | ||
167 | m_connection->flush(); | 96 | Test::flushWaylandConnection(); | ||
168 | // let's render | 97 | // let's render | ||
169 | QImage img2(QSize(200, 20), QImage::Format_ARGB32); | 98 | Test::render(transientSurface.data(), QSize(200, 20), Qt::red); | ||
170 | img2.fill(Qt::red); | 99 | Test::flushWaylandConnection(); | ||
171 | transientSurface->attachBuffer(m_shm->createBuffer(img2)); | | |||
172 | transientSurface->damage(QRect(0, 0, 200, 20)); | | |||
173 | transientSurface->commit(); | | |||
174 | m_connection->flush(); | | |||
175 | QVERIFY(clientAddedSpy.wait()); | 100 | QVERIFY(clientAddedSpy.wait()); | ||
176 | // get the latest ShellClient | 101 | // get the latest ShellClient | ||
177 | auto transientClient = clientAddedSpy.last().first().value<ShellClient*>(); | 102 | auto transientClient = clientAddedSpy.last().first().value<ShellClient*>(); | ||
178 | QVERIFY(transientClient != c); | 103 | QVERIFY(transientClient != c); | ||
179 | QCOMPARE(transientClient->geometry(), QRect(c->x() + 10, c->y() + 20, 200, 20)); | 104 | QCOMPARE(transientClient->geometry(), QRect(c->x() + 10, c->y() + 20, 200, 20)); | ||
180 | QVERIFY(transientClient->isTransient()); | 105 | QVERIFY(transientClient->isTransient()); | ||
181 | QCOMPARE(transientClient->transientPlacementHint(), QPoint(10, 20)); | 106 | QCOMPARE(transientClient->transientPlacementHint(), QPoint(10, 20)); | ||
182 | QVERIFY(!transientClient->wantsInput()); | 107 | QVERIFY(!transientClient->wantsInput()); | ||
Show All 9 Lines |