Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/keyboard_layout_test.cpp
Show All 15 Lines | |||||
16 | 16 | | |||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "kwin_wayland_test.h" | 20 | #include "kwin_wayland_test.h" | ||
21 | #include "keyboard_input.h" | 21 | #include "keyboard_input.h" | ||
22 | #include "keyboard_layout.h" | 22 | #include "keyboard_layout.h" | ||
23 | #include "platform.h" | 23 | #include "platform.h" | ||
24 | #include "virtualdesktops.h" | ||||
24 | #include "wayland_server.h" | 25 | #include "wayland_server.h" | ||
25 | 26 | | |||
26 | #include <KConfigGroup> | 27 | #include <KConfigGroup> | ||
27 | #include <KGlobalAccel> | 28 | #include <KGlobalAccel> | ||
28 | 29 | | |||
29 | #include <QAction> | 30 | #include <QAction> | ||
30 | #include <QDBusConnection> | 31 | #include <QDBusConnection> | ||
31 | #include <QDBusConnectionInterface> | 32 | #include <QDBusConnectionInterface> | ||
Show All 14 Lines | 46 | private Q_SLOTS: | |||
46 | void initTestCase(); | 47 | void initTestCase(); | ||
47 | void init(); | 48 | void init(); | ||
48 | void cleanup(); | 49 | void cleanup(); | ||
49 | 50 | | |||
50 | void testReconfigure(); | 51 | void testReconfigure(); | ||
51 | void testChangeLayoutThroughDBus(); | 52 | void testChangeLayoutThroughDBus(); | ||
52 | void testPerLayoutShortcut(); | 53 | void testPerLayoutShortcut(); | ||
53 | void testDBusServiceExport(); | 54 | void testDBusServiceExport(); | ||
55 | void testVirtualDesktopPolicy(); | ||||
54 | 56 | | |||
55 | private: | 57 | private: | ||
56 | void reconfigureLayouts(); | 58 | void reconfigureLayouts(); | ||
57 | }; | 59 | }; | ||
58 | 60 | | |||
59 | void KeyboardLayoutTest::reconfigureLayouts() | 61 | void KeyboardLayoutTest::reconfigureLayouts() | ||
60 | { | 62 | { | ||
61 | // create DBus signal to reload | 63 | // create DBus signal to reload | ||
▲ Show 20 Lines • Show All 208 Lines • ▼ Show 20 Line(s) | 250 | { | |||
270 | // and back to one layout | 272 | // and back to one layout | ||
271 | layoutGroup.writeEntry("LayoutList", QStringLiteral("us")); | 273 | layoutGroup.writeEntry("LayoutList", QStringLiteral("us")); | ||
272 | layoutGroup.sync(); | 274 | layoutGroup.sync(); | ||
273 | reconfigureLayouts(); | 275 | reconfigureLayouts(); | ||
274 | QTRY_COMPARE(xkb->numberOfLayouts(), 1u); | 276 | QTRY_COMPARE(xkb->numberOfLayouts(), 1u); | ||
275 | QTRY_VERIFY(!QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.keyboard")).value()); | 277 | QTRY_VERIFY(!QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.keyboard")).value()); | ||
276 | } | 278 | } | ||
277 | 279 | | |||
280 | void KeyboardLayoutTest::testVirtualDesktopPolicy() | ||||
281 | { | ||||
282 | KConfigGroup layoutGroup = kwinApp()->kxkbConfig()->group("Layout"); | ||||
283 | layoutGroup.writeEntry("LayoutList", QStringLiteral("us,de,de(neo)")); | ||||
284 | layoutGroup.writeEntry("SwitchMode", QStringLiteral("Desktop")); | ||||
285 | layoutGroup.sync(); | ||||
286 | reconfigureLayouts(); | ||||
287 | auto xkb = input()->keyboard()->xkb(); | ||||
288 | QTRY_COMPARE(xkb->numberOfLayouts(), 3u); | ||||
289 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("English (US)")); | ||||
290 | | ||||
291 | VirtualDesktopManager::self()->setCount(4); | ||||
292 | QCOMPARE(VirtualDesktopManager::self()->count(), 4u); | ||||
293 | | ||||
294 | auto changeLayout = [] (const QString &layoutName) { | ||||
295 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.keyboard"), QStringLiteral("/Layouts"), QStringLiteral("org.kde.KeyboardLayouts"), QStringLiteral("setLayout")); | ||||
296 | msg << layoutName; | ||||
297 | return QDBusConnection::sessionBus().asyncCall(msg); | ||||
298 | }; | ||||
299 | auto reply = changeLayout(QStringLiteral("German")); | ||||
300 | reply.waitForFinished(); | ||||
301 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German")); | ||||
302 | | ||||
303 | // switch to another virtual desktop | ||||
304 | auto desktops = VirtualDesktopManager::self()->desktops(); | ||||
305 | QCOMPARE(desktops.count(), 4); | ||||
306 | QCOMPARE(desktops.first(), VirtualDesktopManager::self()->currentDesktop()); | ||||
307 | VirtualDesktopManager::self()->setCurrent(desktops.at(1)); | ||||
308 | QCOMPARE(desktops.at(1), VirtualDesktopManager::self()->currentDesktop()); | ||||
309 | // should be reset to English | ||||
310 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("English (US)"));reply = changeLayout(QStringLiteral("German (Neo 2)")); | ||||
311 | reply.waitForFinished(); | ||||
312 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)")); | ||||
313 | | ||||
314 | // back to desktop 0 -> German | ||||
315 | VirtualDesktopManager::self()->setCurrent(desktops.at(0)); | ||||
316 | QCOMPARE(desktops.first(), VirtualDesktopManager::self()->currentDesktop()); | ||||
317 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German")); | ||||
318 | // desktop 2 -> English | ||||
319 | VirtualDesktopManager::self()->setCurrent(desktops.at(2)); | ||||
320 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("English (US)")); | ||||
321 | // desktop 1 -> Neo | ||||
322 | VirtualDesktopManager::self()->setCurrent(desktops.at(1)); | ||||
323 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)")); | ||||
324 | | ||||
325 | // remove virtual desktops | ||||
326 | VirtualDesktopManager::self()->setCount(1); | ||||
327 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German")); | ||||
328 | | ||||
329 | // add another desktop | ||||
330 | VirtualDesktopManager::self()->setCount(2); | ||||
331 | // switching to it should result in going to default | ||||
332 | desktops = VirtualDesktopManager::self()->desktops(); | ||||
333 | QCOMPARE(desktops.count(), 2); | ||||
334 | QCOMPARE(desktops.first(), VirtualDesktopManager::self()->currentDesktop()); | ||||
335 | VirtualDesktopManager::self()->setCurrent(desktops.last()); | ||||
336 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("English (US)")); | ||||
337 | | ||||
338 | } | ||||
339 | | ||||
278 | WAYLANDTEST_MAIN(KeyboardLayoutTest) | 340 | WAYLANDTEST_MAIN(KeyboardLayoutTest) | ||
279 | #include "keyboard_layout_test.moc" | 341 | #include "keyboard_layout_test.moc" |