@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -81,6 +81,7 @@ private Q_SLOTS:
8181 void touchTapTouch();
8282
8383 void tapWhileTouching();
84+ void multipleHomeKeys();
8485
8586private:
8687 void passTime(qint64 timeSpanMs);
@@ -112,13 +113,15 @@ void WindowInputMonitorTest::touchTapTouch_data()
112113 QTest::addColumn<int>("tapDuration");
113114 QTest::addColumn<int>("silenceAfterTap");
114115 QTest::addColumn<int>("expectedActivatedCount");
115−
116− QTest::newRow("tap followed by touch") << 2000 << 50 << 10 << 0;
117− QTest::newRow("touch, tap and touch") << 10 << 50 << 10 << 0;
118− QTest::newRow("touch followed by tap") << 10 << 50 << 2000 << 0;
119− QTest::newRow("touch followed by long tap") << 10 << 500 << 2000 << 0;
120− QTest::newRow("isolated tap") << 1000 << 50 << 1000 << 1;
121− QTest::newRow("isolated long press") << 1000 << 200 << 1000 << 0;
116+ QTest::addColumn<Qt::Key>("key");
117+
118+ QTest::newRow("tap followed by touch") << 2000 << 50 << 10 << 0 << Qt::Key_Super_L;
119+ QTest::newRow("touch, tap and touch") << 10 << 50 << 10 << 0 << Qt::Key_Super_L;
120+ QTest::newRow("touch followed by tap") << 10 << 50 << 2000 << 0 << Qt::Key_Super_L;
121+ QTest::newRow("touch followed by long tap") << 10 << 500 << 2000 << 0 << Qt::Key_Super_L;
122+ QTest::newRow("isolated tap, Super_L") << 1000 << 50 << 1000 << 1 << Qt::Key_Super_L;
123+ QTest::newRow("isolated tap, HomePage") << 1000 << 50 << 1000 << 1 << Qt::Key_HomePage;
124+ QTest::newRow("isolated long press") << 1000 << 200 << 1000 << 0 << Qt::Key_Super_L;
122125}
123126
124127void WindowInputMonitorTest::touchTapTouch()
@@ -127,6 +130,7 @@ void WindowInputMonitorTest::touchTapTouch()
127130 QFETCH(int, tapDuration);
128131 QFETCH(int, silenceAfterTap);
129132 QFETCH(int, expectedActivatedCount);
133+ QFETCH(Qt::Key, key);
130134 WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(), new FakeElapsedTimer);
131135 QSignalSpy activatedSpy(&homeKeyWatcher, &WindowInputMonitor::homeKeyActivated);
132136 QVERIFY(activatedSpy.isValid());
@@ -149,7 +153,7 @@ void WindowInputMonitorTest::touchTapTouch()
149153 passTime(silenceBeforeTap);
150154
151155 {
152− QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Super_L, Qt::NoModifier);
156+ QKeyEvent keyEvent(QEvent::KeyPress, key, Qt::NoModifier);
153157 homeKeyWatcher.update(&keyEvent);
154158 }
155159 int tapTime = 0;
@@ -157,10 +161,10 @@ void WindowInputMonitorTest::touchTapTouch()
157161 passTime(10);
158162 tapTime += 10;
159163 if (tapTime + 10 >= tapDuration) {
160− QKeyEvent keyEvent(QEvent::KeyRelease, Qt::Key_Super_L, Qt::NoModifier);
164+ QKeyEvent keyEvent(QEvent::KeyRelease, key, Qt::NoModifier);
161165 homeKeyWatcher.update(&keyEvent);
162166 } else {
163− QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Super_L, Qt::NoModifier, QString(), true /*autorepeat*/);
167+ QKeyEvent keyEvent(QEvent::KeyPress, key, Qt::NoModifier, QString(), true /*autorepeat*/);
164168 homeKeyWatcher.update(&keyEvent);
165169 }
166170 }
@@ -217,6 +221,41 @@ void WindowInputMonitorTest::tapWhileTouching()
217221 QCOMPARE(activatedSpy.count(), 0);
218222}
219223
224+/*
225+ Press multiple of the mapped home keys roughly at the same time.
226+ The first pressed will be recognized and the other ignored
227+ */
228+void WindowInputMonitorTest::multipleHomeKeys()
229+{
230+ WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(), new FakeElapsedTimer);
231+ QSignalSpy activatedSpy(&homeKeyWatcher, &WindowInputMonitor::homeKeyActivated);
232+ QVERIFY(activatedSpy.isValid());
233+
234+ passTime(1000);
235+ {
236+ QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_HomePage, Qt::NoModifier);
237+ homeKeyWatcher.update(&keyEvent);
238+ }
239+ passTime(50);
240+ {
241+ QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Super_L, Qt::NoModifier);
242+ homeKeyWatcher.update(&keyEvent);
243+ }
244+ passTime(50);
245+ {
246+ QKeyEvent keyEvent(QEvent::KeyRelease, Qt::Key_HomePage, Qt::NoModifier);
247+ homeKeyWatcher.update(&keyEvent);
248+ }
249+ passTime(10);
250+ {
251+ QKeyEvent keyEvent(QEvent::KeyRelease, Qt::Key_Super_L, Qt::NoModifier);
252+ homeKeyWatcher.update(&keyEvent);
253+ }
254+ passTime(1000);
255+
256+ QCOMPARE(activatedSpy.count(), 1);
257+}
258+
220259/////////////////////////////////// FakeTimer //////////////////////////////////
221260
222261FakeTimer::FakeTimer(QObject *parent)