KWin
Loading...
Searching...
No Matches
test_virtual_desktops.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: 2012 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#include "input.h"
10#include "virtualdesktops.h"
11// KDE
12#include <KConfigGroup>
13
14#include <QAction>
15#include <QSignalSpy>
16#include <QTest>
17
18namespace KWin
19{
20
21InputRedirection *InputRedirection::s_self = nullptr;
22
23void InputRedirection::registerAxisShortcut(Qt::KeyboardModifiers modifiers, PointerAxisDirection axis, QAction *action)
24{
25}
26
27void InputRedirection::registerTouchpadSwipeShortcut(SwipeDirection direction, uint32_t fingerCount, QAction *onUp, std::function<void(qreal)> progressCallback)
28{
29}
30
31void InputRedirection::registerTouchpadPinchShortcut(PinchDirection direction, uint32_t fingerCount, QAction *onUp, std::function<void(qreal)> progressCallback)
32{
33}
34
35void InputRedirection::registerTouchscreenSwipeShortcut(SwipeDirection direction, uint32_t fingerCount, QAction *action, std::function<void(qreal)> progressCallback)
36{
37}
38
39}
40
41Q_DECLARE_METATYPE(Qt::Orientation)
42
43using namespace KWin;
44
45class TestVirtualDesktops : public QObject
46{
47 Q_OBJECT
48private Q_SLOTS:
49 void init();
50 void cleanup();
51 void count_data();
52 void count();
53 void navigationWrapsAround_data();
54 void navigationWrapsAround();
55 void current_data();
56 void current();
57 void currentChangeOnCountChange_data();
58 void currentChangeOnCountChange();
59 void next_data();
60 void next();
61 void previous_data();
62 void previous();
63 void left_data();
64 void left();
65 void right_data();
66 void right();
67 void above_data();
68 void above();
69 void below_data();
70 void below();
71 void updateGrid_data();
72 void updateGrid();
73 void updateLayout_data();
74 void updateLayout();
75 void name_data();
76 void name();
77 void switchToShortcuts();
78 void changeRows();
79 void load();
80 void save();
81
82private:
83 void addDirectionColumns();
84 void testDirection(const QString &actionName, VirtualDesktopManager::Direction direction);
85};
86
87void TestVirtualDesktops::init()
88{
89 VirtualDesktopManager::create();
90}
91
92void TestVirtualDesktops::cleanup()
93{
94 delete VirtualDesktopManager::self();
95}
96
97static const uint s_countInitValue = 2;
98
99void TestVirtualDesktops::count_data()
100{
101 QTest::addColumn<uint>("request");
102 QTest::addColumn<uint>("result");
103 QTest::addColumn<bool>("signal");
104 QTest::addColumn<bool>("removedSignal");
105
106 QTest::newRow("Minimum") << (uint)1 << (uint)1 << true << true;
107 QTest::newRow("Below Minimum") << (uint)0 << (uint)1 << true << true;
108 QTest::newRow("Normal Value") << (uint)10 << (uint)10 << true << false;
109 QTest::newRow("Maximum") << VirtualDesktopManager::maximum() << VirtualDesktopManager::maximum() << true << false;
110 QTest::newRow("Above Maximum") << VirtualDesktopManager::maximum() + 1 << VirtualDesktopManager::maximum() << true << false;
111 QTest::newRow("Unchanged") << s_countInitValue << s_countInitValue << false << false;
112}
113
114void TestVirtualDesktops::count()
115{
116 VirtualDesktopManager *vds = VirtualDesktopManager::self();
117 QCOMPARE(vds->count(), (uint)0);
118 // start with a useful desktop count
119 vds->setCount(s_countInitValue);
120
121 QSignalSpy spy(vds, &VirtualDesktopManager::countChanged);
122 QSignalSpy desktopsRemoved(vds, &VirtualDesktopManager::desktopRemoved);
123
124 auto vdToRemove = vds->desktops().last();
125
126 QFETCH(uint, request);
127 QFETCH(uint, result);
128 QFETCH(bool, signal);
129 QFETCH(bool, removedSignal);
130 vds->setCount(request);
131 QCOMPARE(vds->count(), result);
132 QCOMPARE(spy.isEmpty(), !signal);
133 if (!spy.isEmpty()) {
134 QList<QVariant> arguments = spy.takeFirst();
135 QCOMPARE(arguments.count(), 2);
136 QCOMPARE(arguments.at(0).type(), QVariant::UInt);
137 QCOMPARE(arguments.at(1).type(), QVariant::UInt);
138 QCOMPARE(arguments.at(0).toUInt(), s_countInitValue);
139 QCOMPARE(arguments.at(1).toUInt(), result);
140 }
141 QCOMPARE(desktopsRemoved.isEmpty(), !removedSignal);
142 if (!desktopsRemoved.isEmpty()) {
143 QList<QVariant> arguments = desktopsRemoved.takeFirst();
144 QCOMPARE(arguments.count(), 1);
145 QCOMPARE(arguments.at(0).value<KWin::VirtualDesktop *>(), vdToRemove);
146 }
147}
148
149void TestVirtualDesktops::navigationWrapsAround_data()
150{
151 QTest::addColumn<bool>("init");
152 QTest::addColumn<bool>("request");
153 QTest::addColumn<bool>("result");
154 QTest::addColumn<bool>("signal");
155
156 QTest::newRow("enable") << false << true << true << true;
157 QTest::newRow("disable") << true << false << false << true;
158 QTest::newRow("keep enabled") << true << true << true << false;
159 QTest::newRow("keep disabled") << false << false << false << false;
160}
161
162void TestVirtualDesktops::navigationWrapsAround()
163{
164 VirtualDesktopManager *vds = VirtualDesktopManager::self();
165 QCOMPARE(vds->isNavigationWrappingAround(), false);
166 QFETCH(bool, init);
167 QFETCH(bool, request);
168 QFETCH(bool, result);
169 QFETCH(bool, signal);
170
171 // set to init value
173 QCOMPARE(vds->isNavigationWrappingAround(), init);
174
176 vds->setNavigationWrappingAround(request);
177 QCOMPARE(vds->isNavigationWrappingAround(), result);
178 QCOMPARE(spy.isEmpty(), !signal);
179}
180
181void TestVirtualDesktops::current_data()
182{
183 QTest::addColumn<uint>("count");
184 QTest::addColumn<uint>("init");
185 QTest::addColumn<uint>("request");
186 QTest::addColumn<uint>("result");
187 QTest::addColumn<bool>("signal");
188
189 QTest::newRow("lower") << (uint)4 << (uint)3 << (uint)2 << (uint)2 << true;
190 QTest::newRow("higher") << (uint)4 << (uint)1 << (uint)2 << (uint)2 << true;
191 QTest::newRow("maximum") << (uint)4 << (uint)1 << (uint)4 << (uint)4 << true;
192 QTest::newRow("above maximum") << (uint)4 << (uint)1 << (uint)5 << (uint)1 << false;
193 QTest::newRow("minimum") << (uint)4 << (uint)2 << (uint)1 << (uint)1 << true;
194 QTest::newRow("below minimum") << (uint)4 << (uint)2 << (uint)0 << (uint)2 << false;
195 QTest::newRow("unchanged") << (uint)4 << (uint)2 << (uint)2 << (uint)2 << false;
196}
197
198void TestVirtualDesktops::current()
199{
200 VirtualDesktopManager *vds = VirtualDesktopManager::self();
201 QCOMPARE(vds->current(), (uint)0);
202 QFETCH(uint, count);
203 QFETCH(uint, init);
204 vds->setCount(count);
205 vds->setCurrent(init);
206 QCOMPARE(vds->current(), init);
207
208 QSignalSpy spy(vds, &VirtualDesktopManager::currentChanged);
209
210 QFETCH(uint, request);
211 QFETCH(uint, result);
212 QFETCH(bool, signal);
213 QCOMPARE(vds->setCurrent(request), signal);
214 QCOMPARE(vds->current(), result);
215 QCOMPARE(spy.isEmpty(), !signal);
216 if (!spy.isEmpty()) {
217 QList<QVariant> arguments = spy.takeFirst();
218 QCOMPARE(arguments.count(), 2);
219
220 VirtualDesktop *previous = arguments.at(0).value<VirtualDesktop *>();
221 QCOMPARE(previous->x11DesktopNumber(), init);
222
223 VirtualDesktop *current = arguments.at(1).value<VirtualDesktop *>();
224 QCOMPARE(current->x11DesktopNumber(), result);
225 }
226}
227
228void TestVirtualDesktops::currentChangeOnCountChange_data()
229{
230 QTest::addColumn<uint>("initCount");
231 QTest::addColumn<uint>("initCurrent");
232 QTest::addColumn<uint>("request");
233 QTest::addColumn<uint>("current");
234 QTest::addColumn<bool>("signal");
235
236 QTest::newRow("increment") << (uint)4 << (uint)2 << (uint)5 << (uint)2 << false;
237 QTest::newRow("increment on last") << (uint)4 << (uint)4 << (uint)5 << (uint)4 << false;
238 QTest::newRow("decrement") << (uint)4 << (uint)2 << (uint)3 << (uint)2 << false;
239 QTest::newRow("decrement on second last") << (uint)4 << (uint)3 << (uint)3 << (uint)3 << false;
240 QTest::newRow("decrement on last") << (uint)4 << (uint)4 << (uint)3 << (uint)3 << true;
241 QTest::newRow("multiple decrement") << (uint)4 << (uint)2 << (uint)1 << (uint)1 << true;
242}
243
244void TestVirtualDesktops::currentChangeOnCountChange()
245{
246 VirtualDesktopManager *vds = VirtualDesktopManager::self();
247 QFETCH(uint, initCount);
248 QFETCH(uint, initCurrent);
249 vds->setCount(initCount);
250 vds->setCurrent(initCurrent);
251
252 QSignalSpy spy(vds, &VirtualDesktopManager::currentChanged);
253
254 QFETCH(uint, request);
255 QFETCH(uint, current);
256 QFETCH(bool, signal);
257
258 vds->setCount(request);
259 QCOMPARE(vds->current(), current);
260 QCOMPARE(spy.isEmpty(), !signal);
261}
262
263void TestVirtualDesktops::addDirectionColumns()
264{
265 QTest::addColumn<uint>("initCount");
266 QTest::addColumn<uint>("initCurrent");
267 QTest::addColumn<bool>("wrap");
268 QTest::addColumn<uint>("result");
269}
270
271void TestVirtualDesktops::testDirection(const QString &actionName, VirtualDesktopManager::Direction direction)
272{
273 VirtualDesktopManager *vds = VirtualDesktopManager::self();
274 QFETCH(uint, initCount);
275 QFETCH(uint, initCurrent);
276 vds->setCount(initCount);
277 vds->setCurrent(initCurrent);
278
279 QFETCH(bool, wrap);
280 QFETCH(uint, result);
281 QCOMPARE(vds->inDirection(nullptr, direction, wrap)->x11DesktopNumber(), result);
282
284 vds->initShortcuts();
285 QAction *action = vds->findChild<QAction *>(actionName);
286 QVERIFY(action);
287 action->trigger();
288 QCOMPARE(vds->current(), result);
289 QCOMPARE(vds->inDirection(initCurrent, direction, wrap), result);
290}
291
292void TestVirtualDesktops::next_data()
293{
294 addDirectionColumns();
295
296 QTest::newRow("one desktop, wrap") << (uint)1 << (uint)1 << true << (uint)1;
297 QTest::newRow("one desktop, no wrap") << (uint)1 << (uint)1 << false << (uint)1;
298 QTest::newRow("desktops, wrap") << (uint)4 << (uint)1 << true << (uint)2;
299 QTest::newRow("desktops, no wrap") << (uint)4 << (uint)1 << false << (uint)2;
300 QTest::newRow("desktops at end, wrap") << (uint)4 << (uint)4 << true << (uint)1;
301 QTest::newRow("desktops at end, no wrap") << (uint)4 << (uint)4 << false << (uint)4;
302}
303
304void TestVirtualDesktops::next()
305{
306 testDirection(QStringLiteral("Switch to Next Desktop"), VirtualDesktopManager::Direction::Next);
307}
308
309void TestVirtualDesktops::previous_data()
310{
311 addDirectionColumns();
312
313 QTest::newRow("one desktop, wrap") << (uint)1 << (uint)1 << true << (uint)1;
314 QTest::newRow("one desktop, no wrap") << (uint)1 << (uint)1 << false << (uint)1;
315 QTest::newRow("desktops, wrap") << (uint)4 << (uint)3 << true << (uint)2;
316 QTest::newRow("desktops, no wrap") << (uint)4 << (uint)3 << false << (uint)2;
317 QTest::newRow("desktops at start, wrap") << (uint)4 << (uint)1 << true << (uint)4;
318 QTest::newRow("desktops at start, no wrap") << (uint)4 << (uint)1 << false << (uint)1;
319}
320
321void TestVirtualDesktops::previous()
322{
323 testDirection(QStringLiteral("Switch to Previous Desktop"), VirtualDesktopManager::Direction::Previous);
324}
325
326void TestVirtualDesktops::left_data()
327{
328 addDirectionColumns();
329 QTest::newRow("one desktop, wrap") << (uint)1 << (uint)1 << true << (uint)1;
330 QTest::newRow("one desktop, no wrap") << (uint)1 << (uint)1 << false << (uint)1;
331 QTest::newRow("desktops, wrap, 1st row") << (uint)4 << (uint)2 << true << (uint)1;
332 QTest::newRow("desktops, no wrap, 1st row") << (uint)4 << (uint)2 << false << (uint)1;
333 QTest::newRow("desktops, wrap, 2nd row") << (uint)4 << (uint)4 << true << (uint)3;
334 QTest::newRow("desktops, no wrap, 2nd row") << (uint)4 << (uint)4 << false << (uint)3;
335
336 QTest::newRow("desktops at start, wrap, 1st row") << (uint)4 << (uint)1 << true << (uint)2;
337 QTest::newRow("desktops at start, no wrap, 1st row") << (uint)4 << (uint)1 << false << (uint)1;
338 QTest::newRow("desktops at start, wrap, 2nd row") << (uint)4 << (uint)3 << true << (uint)4;
339 QTest::newRow("desktops at start, no wrap, 2nd row") << (uint)4 << (uint)3 << false << (uint)3;
340
341 QTest::newRow("non symmetric, start") << (uint)5 << (uint)5 << false << (uint)4;
342 QTest::newRow("non symmetric, end, no wrap") << (uint)5 << (uint)4 << false << (uint)4;
343 QTest::newRow("non symmetric, end, wrap") << (uint)5 << (uint)4 << true << (uint)5;
344}
345
346void TestVirtualDesktops::left()
347{
348 testDirection(QStringLiteral("Switch One Desktop to the Left"), VirtualDesktopManager::Direction::Left);
349}
350
351void TestVirtualDesktops::right_data()
352{
353 addDirectionColumns();
354 QTest::newRow("one desktop, wrap") << (uint)1 << (uint)1 << true << (uint)1;
355 QTest::newRow("one desktop, no wrap") << (uint)1 << (uint)1 << false << (uint)1;
356 QTest::newRow("desktops, wrap, 1st row") << (uint)4 << (uint)1 << true << (uint)2;
357 QTest::newRow("desktops, no wrap, 1st row") << (uint)4 << (uint)1 << false << (uint)2;
358 QTest::newRow("desktops, wrap, 2nd row") << (uint)4 << (uint)3 << true << (uint)4;
359 QTest::newRow("desktops, no wrap, 2nd row") << (uint)4 << (uint)3 << false << (uint)4;
360
361 QTest::newRow("desktops at start, wrap, 1st row") << (uint)4 << (uint)2 << true << (uint)1;
362 QTest::newRow("desktops at start, no wrap, 1st row") << (uint)4 << (uint)2 << false << (uint)2;
363 QTest::newRow("desktops at start, wrap, 2nd row") << (uint)4 << (uint)4 << true << (uint)3;
364 QTest::newRow("desktops at start, no wrap, 2nd row") << (uint)4 << (uint)4 << false << (uint)4;
365
366 QTest::newRow("non symmetric, start") << (uint)5 << (uint)4 << false << (uint)5;
367 QTest::newRow("non symmetric, end, no wrap") << (uint)5 << (uint)5 << false << (uint)5;
368 QTest::newRow("non symmetric, end, wrap") << (uint)5 << (uint)5 << true << (uint)4;
369}
370
371void TestVirtualDesktops::right()
372{
373 testDirection(QStringLiteral("Switch One Desktop to the Right"), VirtualDesktopManager::Direction::Right);
374}
375
376void TestVirtualDesktops::above_data()
377{
378 addDirectionColumns();
379 QTest::newRow("one desktop, wrap") << (uint)1 << (uint)1 << true << (uint)1;
380 QTest::newRow("one desktop, no wrap") << (uint)1 << (uint)1 << false << (uint)1;
381 QTest::newRow("desktops, wrap, 1st column") << (uint)4 << (uint)3 << true << (uint)1;
382 QTest::newRow("desktops, no wrap, 1st column") << (uint)4 << (uint)3 << false << (uint)1;
383 QTest::newRow("desktops, wrap, 2nd column") << (uint)4 << (uint)4 << true << (uint)2;
384 QTest::newRow("desktops, no wrap, 2nd column") << (uint)4 << (uint)4 << false << (uint)2;
385
386 QTest::newRow("desktops at start, wrap, 1st column") << (uint)4 << (uint)1 << true << (uint)3;
387 QTest::newRow("desktops at start, no wrap, 1st column") << (uint)4 << (uint)1 << false << (uint)1;
388 QTest::newRow("desktops at start, wrap, 2nd column") << (uint)4 << (uint)2 << true << (uint)4;
389 QTest::newRow("desktops at start, no wrap, 2nd column") << (uint)4 << (uint)2 << false << (uint)2;
390}
391
392void TestVirtualDesktops::above()
393{
394 testDirection(QStringLiteral("Switch One Desktop Up"), VirtualDesktopManager::Direction::Up);
395}
396
397void TestVirtualDesktops::below_data()
398{
399 addDirectionColumns();
400 QTest::newRow("one desktop, wrap") << (uint)1 << (uint)1 << true << (uint)1;
401 QTest::newRow("one desktop, no wrap") << (uint)1 << (uint)1 << false << (uint)1;
402 QTest::newRow("desktops, wrap, 1st column") << (uint)4 << (uint)1 << true << (uint)3;
403 QTest::newRow("desktops, no wrap, 1st column") << (uint)4 << (uint)1 << false << (uint)3;
404 QTest::newRow("desktops, wrap, 2nd column") << (uint)4 << (uint)2 << true << (uint)4;
405 QTest::newRow("desktops, no wrap, 2nd column") << (uint)4 << (uint)2 << false << (uint)4;
406
407 QTest::newRow("desktops at start, wrap, 1st column") << (uint)4 << (uint)3 << true << (uint)1;
408 QTest::newRow("desktops at start, no wrap, 1st column") << (uint)4 << (uint)3 << false << (uint)3;
409 QTest::newRow("desktops at start, wrap, 2nd column") << (uint)4 << (uint)4 << true << (uint)2;
410 QTest::newRow("desktops at start, no wrap, 2nd column") << (uint)4 << (uint)4 << false << (uint)4;
411}
412
413void TestVirtualDesktops::below()
414{
415 testDirection(QStringLiteral("Switch One Desktop Down"), VirtualDesktopManager::Direction::Down);
416}
417
418void TestVirtualDesktops::updateGrid_data()
419{
420 QTest::addColumn<uint>("initCount");
421 QTest::addColumn<QSize>("size");
422 QTest::addColumn<QPoint>("coords");
423 QTest::addColumn<uint>("desktop");
424
425 QTest::newRow("one desktop, h") << (uint)1 << QSize(1, 1) << QPoint(0, 0) << (uint)1;
426 QTest::newRow("one desktop, h, 0") << (uint)1 << QSize(1, 1) << QPoint(1, 0) << (uint)0;
427
428 QTest::newRow("two desktops, h, 1") << (uint)2 << QSize(2, 1) << QPoint(0, 0) << (uint)1;
429 QTest::newRow("two desktops, h, 2") << (uint)2 << QSize(2, 1) << QPoint(1, 0) << (uint)2;
430 QTest::newRow("two desktops, h, 3") << (uint)2 << QSize(2, 1) << QPoint(0, 1) << (uint)0;
431 QTest::newRow("two desktops, h, 4") << (uint)2 << QSize(2, 1) << QPoint(2, 0) << (uint)0;
432
433 QTest::newRow("four desktops, h, one row, 1") << (uint)4 << QSize(4, 1) << QPoint(0, 0) << (uint)1;
434 QTest::newRow("four desktops, h, one row, 2") << (uint)4 << QSize(4, 1) << QPoint(1, 0) << (uint)2;
435 QTest::newRow("four desktops, h, one row, 3") << (uint)4 << QSize(4, 1) << QPoint(2, 0) << (uint)3;
436 QTest::newRow("four desktops, h, one row, 4") << (uint)4 << QSize(4, 1) << QPoint(3, 0) << (uint)4;
437
438 QTest::newRow("four desktops, h, grid, 1") << (uint)4 << QSize(2, 2) << QPoint(0, 0) << (uint)1;
439 QTest::newRow("four desktops, h, grid, 2") << (uint)4 << QSize(2, 2) << QPoint(1, 0) << (uint)2;
440 QTest::newRow("four desktops, h, grid, 3") << (uint)4 << QSize(2, 2) << QPoint(0, 1) << (uint)3;
441 QTest::newRow("four desktops, h, grid, 4") << (uint)4 << QSize(2, 2) << QPoint(1, 1) << (uint)4;
442 QTest::newRow("four desktops, h, grid, 0/3") << (uint)4 << QSize(2, 2) << QPoint(0, 3) << (uint)0;
443
444 QTest::newRow("three desktops, h, grid, 1") << (uint)3 << QSize(2, 2) << QPoint(0, 0) << (uint)1;
445 QTest::newRow("three desktops, h, grid, 2") << (uint)3 << QSize(2, 2) << QPoint(1, 0) << (uint)2;
446 QTest::newRow("three desktops, h, grid, 3") << (uint)3 << QSize(2, 2) << QPoint(0, 1) << (uint)3;
447 QTest::newRow("three desktops, h, grid, 4") << (uint)3 << QSize(2, 2) << QPoint(1, 1) << (uint)0;
448}
449
450void TestVirtualDesktops::updateGrid()
451{
452 VirtualDesktopManager *vds = VirtualDesktopManager::self();
453 QFETCH(uint, initCount);
454 vds->setCount(initCount);
456
457 QFETCH(QSize, size);
458 QCOMPARE(vds->desktops().count(), int(initCount));
459 grid.update(size, vds->desktops());
460 QCOMPARE(grid.size(), size);
461 QCOMPARE(grid.width(), size.width());
462 QCOMPARE(grid.height(), size.height());
463 QFETCH(QPoint, coords);
464 QFETCH(uint, desktop);
465 QCOMPARE(grid.at(coords), vds->desktopForX11Id(desktop));
466 if (desktop != 0) {
467 QCOMPARE(grid.gridCoords(desktop), coords);
468 }
469}
470
471void TestVirtualDesktops::updateLayout_data()
472{
473 QTest::addColumn<uint>("desktop");
474 QTest::addColumn<QSize>("result");
475
476 QTest::newRow("01") << (uint)1 << QSize(1, 1);
477 QTest::newRow("02") << (uint)2 << QSize(1, 2);
478 QTest::newRow("03") << (uint)3 << QSize(2, 2);
479 QTest::newRow("04") << (uint)4 << QSize(2, 2);
480 QTest::newRow("05") << (uint)5 << QSize(3, 2);
481 QTest::newRow("06") << (uint)6 << QSize(3, 2);
482 QTest::newRow("07") << (uint)7 << QSize(4, 2);
483 QTest::newRow("08") << (uint)8 << QSize(4, 2);
484 QTest::newRow("09") << (uint)9 << QSize(5, 2);
485 QTest::newRow("10") << (uint)10 << QSize(5, 2);
486 QTest::newRow("11") << (uint)11 << QSize(6, 2);
487 QTest::newRow("12") << (uint)12 << QSize(6, 2);
488 QTest::newRow("13") << (uint)13 << QSize(7, 2);
489 QTest::newRow("14") << (uint)14 << QSize(7, 2);
490 QTest::newRow("15") << (uint)15 << QSize(8, 2);
491 QTest::newRow("16") << (uint)16 << QSize(8, 2);
492 QTest::newRow("17") << (uint)17 << QSize(9, 2);
493 QTest::newRow("18") << (uint)18 << QSize(9, 2);
494 QTest::newRow("19") << (uint)19 << QSize(10, 2);
495 QTest::newRow("20") << (uint)20 << QSize(10, 2);
496}
497
498void TestVirtualDesktops::updateLayout()
499{
500 VirtualDesktopManager *vds = VirtualDesktopManager::self();
501 QSignalSpy spy(vds, &VirtualDesktopManager::layoutChanged);
502 // call update layout - implicitly through setCount
503 QFETCH(uint, desktop);
504 QFETCH(QSize, result);
505 vds->setCount(desktop);
506 QCOMPARE(vds->grid().size(), result);
507 QCOMPARE(spy.count(), 1);
508 const QVariantList &arguments = spy.at(0);
509 QCOMPARE(arguments.at(0).toInt(), result.width());
510 QCOMPARE(arguments.at(1).toInt(), result.height());
511 // calling update layout again should not change anything
512 vds->updateLayout();
513 QCOMPARE(vds->grid().size(), result);
514 QCOMPARE(spy.count(), 2);
515 const QVariantList &arguments2 = spy.at(1);
516 QCOMPARE(arguments2.at(0).toInt(), result.width());
517 QCOMPARE(arguments2.at(1).toInt(), result.height());
518}
519
520void TestVirtualDesktops::name_data()
521{
522 QTest::addColumn<uint>("initCount");
523 QTest::addColumn<uint>("desktop");
524 QTest::addColumn<QString>("desktopName");
525
526 QTest::newRow("desktop 1") << (uint)5 << (uint)1 << "Desktop 1";
527 QTest::newRow("desktop 2") << (uint)5 << (uint)2 << "Desktop 2";
528 QTest::newRow("desktop 3") << (uint)5 << (uint)3 << "Desktop 3";
529 QTest::newRow("desktop 4") << (uint)5 << (uint)4 << "Desktop 4";
530 QTest::newRow("desktop 5") << (uint)5 << (uint)5 << "Desktop 5";
531}
532
533void TestVirtualDesktops::name()
534{
535 VirtualDesktopManager *vds = VirtualDesktopManager::self();
536 QFETCH(uint, initCount);
537 vds->setCount(initCount);
538 QFETCH(uint, desktop);
539
540 const VirtualDesktop *vd = vds->desktopForX11Id(desktop);
541 QTEST(vd->name(), "desktopName");
542}
543
544void TestVirtualDesktops::switchToShortcuts()
545{
546 VirtualDesktopManager *vds = VirtualDesktopManager::self();
547 vds->setCount(vds->maximum());
548 vds->setCurrent(vds->maximum());
549 QCOMPARE(vds->current(), vds->maximum());
550 vds->initShortcuts();
551 const QString toDesktop = QStringLiteral("Switch to Desktop %1");
552 for (uint i = 1; i <= vds->maximum(); ++i) {
553 const QString desktop(toDesktop.arg(i));
554 QAction *action = vds->findChild<QAction *>(desktop);
555 QVERIFY2(action, desktop.toUtf8().constData());
556 action->trigger();
557 QCOMPARE(vds->current(), i);
558 }
559 // invoke switchTo not from a QAction
560 QMetaObject::invokeMethod(vds, "slotSwitchTo");
561 // should still be on max
562 QCOMPARE(vds->current(), vds->maximum());
563}
564
565void TestVirtualDesktops::changeRows()
566{
567 VirtualDesktopManager *vds = VirtualDesktopManager::self();
568
569 vds->setCount(4);
570 vds->setRows(4);
571 QCOMPARE(vds->rows(), 4);
572
573 vds->setRows(5);
574 QCOMPARE(vds->rows(), 4);
575
576 vds->setCount(2);
577 QCOMPARE(vds->rows(), 2);
578}
579
580void TestVirtualDesktops::load()
581{
582 VirtualDesktopManager *vds = VirtualDesktopManager::self();
583 // no config yet, load should not change anything
584 vds->load();
585 QCOMPARE(vds->count(), (uint)0);
586 // empty config should create one desktop
587 KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
588 vds->setConfig(config);
589 vds->load();
590 QCOMPARE(vds->count(), (uint)1);
591 // setting a sensible number
592 config->group(QStringLiteral("Desktops")).writeEntry("Number", 4);
593 vds->load();
594 QCOMPARE(vds->count(), (uint)4);
595
596 // setting the config value and reloading should update
597 config->group(QStringLiteral("Desktops")).writeEntry("Number", 5);
598 vds->load();
599 QCOMPARE(vds->count(), (uint)5);
600}
601
602void TestVirtualDesktops::save()
603{
604 VirtualDesktopManager *vds = VirtualDesktopManager::self();
605 vds->setCount(4);
606 // no config yet, just to ensure it actually works
607 vds->save();
608 KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
609 vds->setConfig(config);
610
611 // now save should create the group "Desktops"
612 QCOMPARE(config->hasGroup(QStringLiteral("Desktops")), false);
613 vds->save();
614 QCOMPARE(config->hasGroup(QStringLiteral("Desktops")), true);
615 KConfigGroup desktops = config->group(QStringLiteral("Desktops"));
616 QCOMPARE(desktops.readEntry<int>("Number", 1), 4);
617 QCOMPARE(desktops.hasKey("Name_1"), false);
618 QCOMPARE(desktops.hasKey("Name_2"), false);
619 QCOMPARE(desktops.hasKey("Name_3"), false);
620 QCOMPARE(desktops.hasKey("Name_4"), false);
621}
622
624#include "test_virtual_desktops.moc"
This class is responsible for redirecting incoming input to the surface which currently has input or ...
Definition input.h:70
void registerTouchscreenSwipeShortcut(SwipeDirection direction, uint32_t fingerCount, QAction *action, std::function< void(qreal)> progressCallback={})
void registerAxisShortcut(Qt::KeyboardModifiers modifiers, PointerAxisDirection axis, QAction *action)
void registerTouchpadPinchShortcut(PinchDirection direction, uint32_t fingerCount, QAction *onUp, std::function< void(qreal)> progressCallback={})
void registerTouchpadSwipeShortcut(SwipeDirection direction, uint32_t fingerCount, QAction *onUp, std::function< void(qreal)> progressCallback={})
Two dimensional grid containing the ID of the virtual desktop at a specific position in the grid.
void update(const QSize &size, const QList< VirtualDesktop * > &desktops)
QPoint gridCoords(uint id) const
VirtualDesktop * at(const QPoint &coords) const
const QSize & size() const
Manages the number of available virtual desktops, the layout of those and which virtual desktop is th...
const VirtualDesktopGrid & grid() const
void layoutChanged(int columns, int rows)
void setConfig(KSharedConfig::Ptr config)
void countChanged(uint previousCount, uint newCount)
QList< VirtualDesktop * > desktops() const
VirtualDesktop * inDirection(VirtualDesktop *desktop, Direction direction, bool wrap=true)
void currentChanged(KWin::VirtualDesktop *previousDesktop, KWin::VirtualDesktop *newDesktop)
VirtualDesktop * desktopForX11Id(uint id) const
void setNavigationWrappingAround(bool enabled)
void desktopRemoved(KWin::VirtualDesktop *desktop)
Q_DECLARE_METATYPE(KWin::SwitchEvent::State)
PointerAxisDirection
The direction in which a pointer axis is moved.
Definition globals.h:104
PinchDirection
Definition globals.h:123
SwipeDirection
Directions for swipe gestures.
Definition globals.h:115
QTEST_MAIN(OnScreenNotificationTest)