Merge lp:~aacid/unity-2d/kill_keyboardmodifiersmonitor into lp:unity-2d
- kill_keyboardmodifiersmonitor
- Merge into trunk
Proposed by
Albert Astals Cid
Status: | Merged |
---|---|
Approved by: | Gerry Boland |
Approved revision: | 1075 |
Merged at revision: | 1072 |
Proposed branch: | lp:~aacid/unity-2d/kill_keyboardmodifiersmonitor |
Merge into: | lp:unity-2d |
Diff against target: |
600 lines (+136/-252) 9 files modified
libunity-2d-private/src/CMakeLists.txt (+0/-1) libunity-2d-private/src/keyboardmodifiersmonitor.cpp (+0/-162) libunity-2d-private/src/keyboardmodifiersmonitor.h (+0/-69) libunity-2d-private/src/keymonitor.cpp (+83/-3) libunity-2d-private/src/keymonitor.h (+13/-3) libunity-2d-private/tests/CMakeLists.txt (+3/-1) libunity-2d-private/tests/keymonitortest.cpp (+31/-6) panel/applets/appname/appnameapplet.cpp (+3/-3) shell/app/shellmanager.cpp (+3/-4) |
To merge this branch: | bzr merge lp:~aacid/unity-2d/kill_keyboardmodifiersmonitor |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Gerry Boland (community) | Approve | ||
Review via email: mp+102646@code.launchpad.net |
This proposal supersedes a proposal from 2012-04-18.
Commit message
[lib] Kill keyboardmodifie
This helps to prevent wrong HUD triggers on ultrafast alt+key presses
Description of the change
Kill keyboardmodifie
Integrate its functionality in keymonitor, helps preventing wrong HUD triggers on ultrafast alt+key presses
UNBLOCK
To post a comment you must log in.
Revision history for this message
Albert Astals Cid (aacid) wrote : Posted in a previous version of this proposal | # |
Revision history for this message
Albert Astals Cid (aacid) wrote : | # |
Branch dependency on lp:~aacid/unity-2d/fast_alt_left_press_fail_test removed as per Gerry's request
Revision history for this message
Gerry Boland (gerboland) wrote : | # |
Works well, I notice a improvement in the tap detection so I get even fewer false HUD appearances. Approved!
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'libunity-2d-private/src/CMakeLists.txt' |
2 | --- libunity-2d-private/src/CMakeLists.txt 2012-04-02 14:03:32 +0000 |
3 | +++ libunity-2d-private/src/CMakeLists.txt 2012-04-19 08:51:21 +0000 |
4 | @@ -9,7 +9,6 @@ |
5 | gconnector.cpp |
6 | gimageutils.cpp |
7 | gnomesessionclient.cpp |
8 | - keyboardmodifiersmonitor.cpp |
9 | hotmodifier.cpp |
10 | hotkeymonitor.cpp |
11 | hotkey.cpp |
12 | |
13 | === removed file 'libunity-2d-private/src/keyboardmodifiersmonitor.cpp' |
14 | --- libunity-2d-private/src/keyboardmodifiersmonitor.cpp 2012-02-15 14:45:17 +0000 |
15 | +++ libunity-2d-private/src/keyboardmodifiersmonitor.cpp 1970-01-01 00:00:00 +0000 |
16 | @@ -1,162 +0,0 @@ |
17 | -/* |
18 | - * This file is part of unity-2d |
19 | - * |
20 | - * Copyright 2011 Canonical Ltd. |
21 | - * |
22 | - * Authors: |
23 | - * - Aurélien Gâteau <aurelien.gateau@canonical.com> |
24 | - * |
25 | - * This program is free software; you can redistribute it and/or modify |
26 | - * it under the terms of the GNU General Public License as published by |
27 | - * the Free Software Foundation; version 3. |
28 | - * |
29 | - * This program is distributed in the hope that it will be useful, |
30 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
31 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
32 | - * GNU General Public License for more details. |
33 | - * |
34 | - * You should have received a copy of the GNU General Public License |
35 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
36 | - */ |
37 | - |
38 | -// Self |
39 | -#include "keyboardmodifiersmonitor.h" |
40 | - |
41 | -// Local |
42 | -#include <hotmodifier.h> |
43 | -#include <debug_p.h> |
44 | - |
45 | -// Qt |
46 | -#include <QX11Info> |
47 | - |
48 | -// X11 |
49 | -#include <X11/Xlib.h> |
50 | -#include <X11/XKBlib.h> |
51 | -#include <X11/extensions/XKB.h> |
52 | - |
53 | -static int sXkbBaseEventType = 0; |
54 | - |
55 | -static void setupXkb() |
56 | -{ |
57 | - int opcode, error; |
58 | - XkbQueryExtension(QX11Info::display(), &opcode, &sXkbBaseEventType, &error, NULL, NULL); |
59 | - XkbSelectEvents(QX11Info::display(), XkbUseCoreKbd, XkbStateNotifyMask, XkbStateNotifyMask); |
60 | -} |
61 | - |
62 | -struct KeyboardModifiersMonitorPrivate |
63 | -{ |
64 | - KeyboardModifiersMonitorPrivate() |
65 | - : m_modifiers(0) |
66 | - {} |
67 | - |
68 | - int m_modifiers; |
69 | -}; |
70 | - |
71 | -KeyboardModifiersMonitor::KeyboardModifiersMonitor(QObject *parent) |
72 | -: QObject(parent) |
73 | -, d(new KeyboardModifiersMonitorPrivate) |
74 | -{ |
75 | - if (sXkbBaseEventType == 0) { |
76 | - setupXkb(); |
77 | - } |
78 | - |
79 | - Unity2dApplication* application = Unity2dApplication::instance(); |
80 | - if (application == NULL) { |
81 | - /* This can happen for example when using qmlviewer to run the launcher */ |
82 | - UQ_WARNING << "The application is not an Unity2dApplication." |
83 | - "Modifiers will not be monitored."; |
84 | - } else { |
85 | - application->installX11EventFilter(this); |
86 | - } |
87 | -} |
88 | - |
89 | -KeyboardModifiersMonitor::~KeyboardModifiersMonitor() |
90 | -{ |
91 | - delete d; |
92 | -} |
93 | - |
94 | -KeyboardModifiersMonitor* KeyboardModifiersMonitor::instance() |
95 | -{ |
96 | - static KeyboardModifiersMonitor* monitor = new KeyboardModifiersMonitor(); |
97 | - return monitor; |
98 | -} |
99 | - |
100 | -bool KeyboardModifiersMonitor::x11EventFilter(XEvent* event) |
101 | -{ |
102 | - if (event->type == sXkbBaseEventType + XkbEventCode) { |
103 | - XkbEvent *xkbEvent = (XkbEvent*)event; |
104 | - if (xkbEvent->any.xkb_type == XkbStateNotify) { |
105 | - d->m_modifiers = xkbEvent->state.mods; |
106 | - Qt::KeyboardModifiers modifiers = keyboardModifiers(); |
107 | - keyboardModifiersChanged(modifiers); |
108 | - |
109 | - Q_FOREACH(HotModifier* hotModifier, m_hotModifiers) { |
110 | - if (hotModifier->modifiers() & m_disabledModifiers) { |
111 | - /* If any of the modifiers have been disabled, the |
112 | - * hotModifier cannot be triggered */ |
113 | - continue; |
114 | - } |
115 | - hotModifier->onModifiersChanged(modifiers); |
116 | - } |
117 | - } |
118 | - } |
119 | - return false; |
120 | -} |
121 | - |
122 | -Qt::KeyboardModifiers KeyboardModifiersMonitor::keyboardModifiers() const |
123 | -{ |
124 | - Qt::KeyboardModifiers value = 0; |
125 | - if (d->m_modifiers & ShiftMask) { |
126 | - value |= Qt::ShiftModifier; |
127 | - } |
128 | - if (d->m_modifiers & ControlMask) { |
129 | - value |= Qt::ControlModifier; |
130 | - } |
131 | - if (d->m_modifiers & Mod1Mask) { |
132 | - value |= Qt::AltModifier; |
133 | - } |
134 | - if (d->m_modifiers & Mod4Mask) { |
135 | - value |= Qt::MetaModifier; |
136 | - } |
137 | - return value; |
138 | -} |
139 | - |
140 | -HotModifier* |
141 | -KeyboardModifiersMonitor::getHotModifierFor(Qt::KeyboardModifiers modifiers) |
142 | -{ |
143 | - Q_FOREACH(HotModifier* hotModifier, m_hotModifiers) { |
144 | - if (hotModifier->modifiers() == modifiers) { |
145 | - return hotModifier; |
146 | - } |
147 | - } |
148 | - |
149 | - HotModifier *hotModifier = new HotModifier(modifiers, this); |
150 | - m_hotModifiers.append(hotModifier); |
151 | - return hotModifier; |
152 | -} |
153 | - |
154 | -void |
155 | -KeyboardModifiersMonitor::disableModifiers(Qt::KeyboardModifiers modifiers) |
156 | -{ |
157 | - m_disabledModifiers |= modifiers; |
158 | - Q_FOREACH(HotModifier* hotModifier, m_hotModifiers) { |
159 | - if (hotModifier->modifiers() & m_disabledModifiers) { |
160 | - hotModifier->disable(); |
161 | - } |
162 | - } |
163 | -} |
164 | - |
165 | -void |
166 | -KeyboardModifiersMonitor::enableModifiers(Qt::KeyboardModifiers modifiers) |
167 | -{ |
168 | - Qt::KeyboardModifiers previouslyDisabled = m_disabledModifiers; |
169 | - m_disabledModifiers &= ~modifiers; |
170 | - Q_FOREACH(HotModifier* hotModifier, m_hotModifiers) { |
171 | - if (hotModifier->modifiers() & previouslyDisabled |
172 | - && !hotModifier->modifiers() & m_disabledModifiers) { |
173 | - hotModifier->onModifiersChanged(keyboardModifiers()); |
174 | - } |
175 | - } |
176 | -} |
177 | - |
178 | -#include "keyboardmodifiersmonitor.moc" |
179 | |
180 | === removed file 'libunity-2d-private/src/keyboardmodifiersmonitor.h' |
181 | --- libunity-2d-private/src/keyboardmodifiersmonitor.h 2012-02-15 14:45:17 +0000 |
182 | +++ libunity-2d-private/src/keyboardmodifiersmonitor.h 1970-01-01 00:00:00 +0000 |
183 | @@ -1,69 +0,0 @@ |
184 | -/* |
185 | - * This file is part of unity-2d |
186 | - * |
187 | - * Copyright 2011 Canonical Ltd. |
188 | - * |
189 | - * Authors: |
190 | - * - Aurélien Gâteau <aurelien.gateau@canonical.com> |
191 | - * |
192 | - * This program is free software; you can redistribute it and/or modify |
193 | - * it under the terms of the GNU General Public License as published by |
194 | - * the Free Software Foundation; version 3. |
195 | - * |
196 | - * This program is distributed in the hope that it will be useful, |
197 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
198 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
199 | - * GNU General Public License for more details. |
200 | - * |
201 | - * You should have received a copy of the GNU General Public License |
202 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
203 | - */ |
204 | - |
205 | -#ifndef KEYBOARDMODIFIERMONITOR_H |
206 | -#define KEYBOARDMODIFIERMONITOR_H |
207 | - |
208 | -// Local |
209 | -#include <unity2dapplication.h> |
210 | - |
211 | -class HotModifier; |
212 | - |
213 | -struct KeyboardModifiersMonitorPrivate; |
214 | - |
215 | -/** |
216 | - * This class monitor keyboard modifiers. It is able to track changes even if |
217 | - * the active window does not belong to the application. |
218 | - * |
219 | - * You *must* use Unity2dApplication to be able to use this class. |
220 | - * |
221 | - * In most case you don't need your own instance: use the one returned by |
222 | - * instance() instead. |
223 | - */ |
224 | -class KeyboardModifiersMonitor : public QObject, protected AbstractX11EventFilter |
225 | -{ |
226 | -Q_OBJECT |
227 | -public: |
228 | - KeyboardModifiersMonitor(QObject *parent = 0); |
229 | - ~KeyboardModifiersMonitor(); |
230 | - |
231 | - Qt::KeyboardModifiers keyboardModifiers() const; |
232 | - |
233 | - HotModifier* getHotModifierFor(Qt::KeyboardModifiers modifiers); |
234 | - |
235 | - void disableModifiers(Qt::KeyboardModifiers modifiers); |
236 | - void enableModifiers(Qt::KeyboardModifiers modifiers); |
237 | - |
238 | - static KeyboardModifiersMonitor* instance(); |
239 | - |
240 | -Q_SIGNALS: |
241 | - void keyboardModifiersChanged(Qt::KeyboardModifiers); |
242 | - |
243 | -protected: |
244 | - bool x11EventFilter(XEvent*); |
245 | - |
246 | -private: |
247 | - KeyboardModifiersMonitorPrivate* const d; |
248 | - QList<HotModifier*> m_hotModifiers; |
249 | - Qt::KeyboardModifiers m_disabledModifiers; |
250 | -}; |
251 | - |
252 | -#endif /* KEYBOARDMODIFIERMONITOR_H */ |
253 | |
254 | === modified file 'libunity-2d-private/src/keymonitor.cpp' |
255 | --- libunity-2d-private/src/keymonitor.cpp 2012-04-10 16:05:39 +0000 |
256 | +++ libunity-2d-private/src/keymonitor.cpp 2012-04-19 08:51:21 +0000 |
257 | @@ -27,20 +27,23 @@ |
258 | // X11 |
259 | #include <X11/Xlib.h> |
260 | #include <X11/keysym.h> |
261 | +#include <X11/XKBlib.h> |
262 | |
263 | // Local |
264 | #include <debug_p.h> |
265 | +#include <hotmodifier.h> |
266 | |
267 | #define INVALID_EVENT_TYPE -1 |
268 | |
269 | static int key_press_type = INVALID_EVENT_TYPE; |
270 | static int notify_type = INVALID_EVENT_TYPE; |
271 | - |
272 | +static int sXkbBaseEventType = 0; |
273 | |
274 | KeyMonitor::KeyMonitor(QObject* parent) |
275 | -: QObject(parent) |
276 | +: QObject(parent), |
277 | + m_modifiers(Qt::NoModifier) |
278 | { |
279 | - if (this->registerEvents()) { |
280 | + if (registerEvents()) { |
281 | getModifiers(); |
282 | } |
283 | } |
284 | @@ -57,6 +60,45 @@ |
285 | return monitor; |
286 | } |
287 | |
288 | +Qt::KeyboardModifiers KeyMonitor::keyboardModifiers() const |
289 | +{ |
290 | + return m_modifiers; |
291 | +} |
292 | + |
293 | +HotModifier *KeyMonitor::getHotModifierFor(Qt::KeyboardModifiers modifiers) |
294 | +{ |
295 | + Q_FOREACH(HotModifier* hotModifier, m_hotModifiers) { |
296 | + if (hotModifier->modifiers() == modifiers) { |
297 | + return hotModifier; |
298 | + } |
299 | + } |
300 | + |
301 | + HotModifier *hotModifier = new HotModifier(modifiers, this); |
302 | + m_hotModifiers.append(hotModifier); |
303 | + return hotModifier; |
304 | +} |
305 | + |
306 | +void KeyMonitor::disableModifiers(Qt::KeyboardModifiers modifiers) |
307 | +{ |
308 | + m_disabledModifiers |= modifiers; |
309 | + Q_FOREACH(HotModifier* hotModifier, m_hotModifiers) { |
310 | + if (hotModifier->modifiers() & m_disabledModifiers) { |
311 | + hotModifier->disable(); |
312 | + } |
313 | + } |
314 | +} |
315 | + |
316 | +void KeyMonitor::enableModifiers(Qt::KeyboardModifiers modifiers) |
317 | +{ |
318 | + Qt::KeyboardModifiers previouslyDisabled = m_disabledModifiers; |
319 | + m_disabledModifiers &= ~modifiers; |
320 | + Q_FOREACH(HotModifier* hotModifier, m_hotModifiers) { |
321 | + if (hotModifier->modifiers() & previouslyDisabled |
322 | + && !hotModifier->modifiers() & m_disabledModifiers) { |
323 | + hotModifier->onModifiersChanged(keyboardModifiers()); |
324 | + } |
325 | + } |
326 | +} |
327 | |
328 | void KeyMonitor::getModifiers() |
329 | { |
330 | @@ -134,6 +176,10 @@ |
331 | return false; |
332 | } |
333 | |
334 | + int opcode, error; |
335 | + XkbQueryExtension(m_display, &opcode, &sXkbBaseEventType, &error, NULL, NULL); |
336 | + XkbSelectEvents(m_display, XkbUseCoreKbd, XkbStateNotifyMask, XkbStateNotifyMask); |
337 | + |
338 | /* Dispatch XEvents when there is activity on the X11 file descriptor */ |
339 | x11FileDescriptor = ConnectionNumber(m_display); |
340 | QSocketNotifier* socketNotifier = new QSocketNotifier(x11FileDescriptor, QSocketNotifier::Read, this); |
341 | @@ -142,6 +188,23 @@ |
342 | return true; |
343 | } |
344 | |
345 | +static Qt::KeyboardModifiers qtModifiersFromXcbMods(int xcbModifiers) |
346 | +{ |
347 | + Qt::KeyboardModifiers value = Qt::NoModifier; |
348 | + if (xcbModifiers & ShiftMask) { |
349 | + value |= Qt::ShiftModifier; |
350 | + } |
351 | + if (xcbModifiers & ControlMask) { |
352 | + value |= Qt::ControlModifier; |
353 | + } |
354 | + if (xcbModifiers & Mod1Mask) { |
355 | + value |= Qt::AltModifier; |
356 | + } |
357 | + if (xcbModifiers & Mod4Mask) { |
358 | + value |= Qt::MetaModifier; |
359 | + } |
360 | + return value; |
361 | +} |
362 | |
363 | void KeyMonitor::x11EventDispatch() |
364 | { |
365 | @@ -158,6 +221,23 @@ |
366 | } |
367 | else if (event.type == notify_type) { |
368 | getModifiers(); |
369 | + } else if (event.type == sXkbBaseEventType + XkbEventCode) { |
370 | + XkbEvent *xkbEvent = (XkbEvent*)&event; |
371 | + if (xkbEvent->any.xkb_type == XkbStateNotify) { |
372 | + const Qt::KeyboardModifiers prevMods = m_modifiers; |
373 | + m_modifiers = qtModifiersFromXcbMods(xkbEvent->state.mods); |
374 | + if (prevMods != m_modifiers) { |
375 | + Q_EMIT keyboardModifiersChanged(m_modifiers); |
376 | + Q_FOREACH(HotModifier* hotModifier, m_hotModifiers) { |
377 | + if (hotModifier->modifiers() & m_disabledModifiers) { |
378 | + /* If any of the modifiers have been disabled, the |
379 | + * hotModifier cannot be triggered */ |
380 | + continue; |
381 | + } |
382 | + hotModifier->onModifiersChanged(m_modifiers); |
383 | + } |
384 | + } |
385 | + } |
386 | } |
387 | } |
388 | } |
389 | |
390 | === modified file 'libunity-2d-private/src/keymonitor.h' |
391 | --- libunity-2d-private/src/keymonitor.h 2011-10-28 22:14:18 +0000 |
392 | +++ libunity-2d-private/src/keymonitor.h 2012-04-19 08:51:21 +0000 |
393 | @@ -28,12 +28,11 @@ |
394 | // X11 |
395 | #include <X11/extensions/XInput.h> |
396 | |
397 | +class HotModifier; |
398 | + |
399 | /** |
400 | * This class monitors global keypresses. Whenever a non-modifier is pressed, |
401 | * keyPressed() is emitted. |
402 | - * |
403 | - * In most case you don't need your own instance: use the one returned by |
404 | - * instance() instead. |
405 | */ |
406 | class KeyMonitor : public QObject |
407 | { |
408 | @@ -43,8 +42,16 @@ |
409 | static KeyMonitor* instance(); |
410 | ~KeyMonitor(); |
411 | |
412 | + Qt::KeyboardModifiers keyboardModifiers() const; |
413 | + |
414 | + HotModifier* getHotModifierFor(Qt::KeyboardModifiers modifiers); |
415 | + |
416 | + void disableModifiers(Qt::KeyboardModifiers modifiers); |
417 | + void enableModifiers(Qt::KeyboardModifiers modifiers); |
418 | + |
419 | Q_SIGNALS: |
420 | void keyPressed(); |
421 | + void keyboardModifiersChanged(Qt::KeyboardModifiers); |
422 | |
423 | private: |
424 | KeyMonitor(QObject* parent=0); |
425 | @@ -59,6 +66,9 @@ |
426 | Display *m_display; |
427 | QVector<XEventClass> m_eventList; |
428 | QVector<KeyCode> m_modList; |
429 | + Qt::KeyboardModifiers m_modifiers; |
430 | + QList<HotModifier*> m_hotModifiers; |
431 | + Qt::KeyboardModifiers m_disabledModifiers; |
432 | }; |
433 | |
434 | #endif // KEYMONITOR_H |
435 | |
436 | === modified file 'libunity-2d-private/tests/CMakeLists.txt' |
437 | --- libunity-2d-private/tests/CMakeLists.txt 2012-04-02 15:15:59 +0000 |
438 | +++ libunity-2d-private/tests/CMakeLists.txt 2012-04-19 08:51:21 +0000 |
439 | @@ -33,7 +33,7 @@ |
440 | |
441 | libunity_2d_tests( |
442 | gconnectortest |
443 | - keyboardmodifiersmonitortest |
444 | + keymonitortest |
445 | launchermenutest |
446 | listaggregatormodeltest |
447 | qsortfilterproxymodeltest |
448 | @@ -47,6 +47,8 @@ |
449 | target_link_libraries(pointerbarriertest ${X11_XTest_LIB}) |
450 | |
451 | target_link_libraries(hotkeytest ${X11_XTest_LIB}) |
452 | + |
453 | +target_link_libraries(keymonitortest ${X11_XTest_LIB}) |
454 | |
455 | # unity2dtrtest - FIXME |
456 | #add_test(NAME unity2dtrtest_check |
457 | |
458 | === renamed file 'libunity-2d-private/tests/keyboardmodifiersmonitortest.cpp' => 'libunity-2d-private/tests/keymonitortest.cpp' |
459 | --- libunity-2d-private/tests/keyboardmodifiersmonitortest.cpp 2011-11-17 20:10:19 +0000 |
460 | +++ libunity-2d-private/tests/keymonitortest.cpp 2012-04-19 08:51:21 +0000 |
461 | @@ -22,7 +22,8 @@ |
462 | // Local |
463 | #include <unitytestmacro.h> |
464 | #include <debug_p.h> |
465 | -#include <keyboardmodifiersmonitor.h> |
466 | +#include <keymonitor.h> |
467 | +#include <hotmodifier.h> |
468 | |
469 | // Qt |
470 | #include <QSignalSpy> |
471 | @@ -33,6 +34,8 @@ |
472 | #include <X11/Xlib.h> |
473 | #include <X11/XKBlib.h> |
474 | #include <X11/extensions/XKB.h> |
475 | +#include <X11/extensions/XTest.h> |
476 | +#include <X11/keysym.h> |
477 | |
478 | Q_DECLARE_METATYPE(Qt::KeyboardModifiers) |
479 | |
480 | @@ -70,23 +73,45 @@ |
481 | { |
482 | QFETCH(int, x11Mask); |
483 | QFETCH(Qt::KeyboardModifiers, qtModifiers); |
484 | - KeyboardModifiersMonitor monitor; |
485 | - QSignalSpy spy(&monitor, SIGNAL(keyboardModifiersChanged(Qt::KeyboardModifiers))); |
486 | + KeyMonitor *monitor = KeyMonitor::instance(); |
487 | + QSignalSpy spy(monitor, SIGNAL(keyboardModifiersChanged(Qt::KeyboardModifiers))); |
488 | |
489 | setModifierState(x11Mask, true); |
490 | QTest::qWait(200); |
491 | - QCOMPARE(monitor.keyboardModifiers(), qtModifiers); |
492 | + QCOMPARE(monitor->keyboardModifiers(), qtModifiers); |
493 | QCOMPARE(spy.count(), 1); |
494 | QCOMPARE(spy.takeFirst().at(0).value<Qt::KeyboardModifiers>(), qtModifiers); |
495 | |
496 | setModifierState(x11Mask, false); |
497 | QTest::qWait(200); |
498 | - QCOMPARE(monitor.keyboardModifiers(), 0); |
499 | + QCOMPARE(monitor->keyboardModifiers(), 0); |
500 | QCOMPARE(spy.count(), 1); |
501 | QCOMPARE(spy.takeFirst().at(0).value<Qt::KeyboardModifiers>(), 0); |
502 | } |
503 | + |
504 | + void testFastModifierKeyPress() |
505 | + { |
506 | + Display *display = XOpenDisplay(0); |
507 | + |
508 | + HotModifier* hm = KeyMonitor::instance()->getHotModifierFor(Qt::AltModifier); |
509 | + QSignalSpy spy(hm, SIGNAL(tapped())); |
510 | + |
511 | + XTestGrabControl(display, 1); |
512 | + XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Alt_L), 1 /* PRESS */, CurrentTime); |
513 | + XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Left), 1 /* PRESS */, CurrentTime); |
514 | + XFlush(display); |
515 | + |
516 | + XTestGrabControl(display, 1); |
517 | + XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Alt_L), 0 /* RELEASE */, CurrentTime); |
518 | + XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Left), 0 /* RELEASE */, CurrentTime); |
519 | + XFlush(display); |
520 | + |
521 | + QTest::qWait(200); |
522 | + |
523 | + QCOMPARE(spy.count(), 0); |
524 | + } |
525 | }; |
526 | |
527 | UAPP_TEST_MAIN(KeyboardModifiersMonitorTest) |
528 | |
529 | -#include "keyboardmodifiersmonitortest.moc" |
530 | +#include "keymonitortest.moc" |
531 | |
532 | === modified file 'panel/applets/appname/appnameapplet.cpp' |
533 | --- panel/applets/appname/appnameapplet.cpp 2012-04-05 09:34:40 +0000 |
534 | +++ panel/applets/appname/appnameapplet.cpp 2012-04-19 08:51:21 +0000 |
535 | @@ -34,7 +34,7 @@ |
536 | |
537 | // Unity-2d |
538 | #include <debug_p.h> |
539 | -#include <keyboardmodifiersmonitor.h> |
540 | +#include <keymonitor.h> |
541 | #include <launcherclient.h> |
542 | #include <hotkey.h> |
543 | #include <hotkeymonitor.h> |
544 | @@ -271,7 +271,7 @@ |
545 | |
546 | void setupKeyboardModifiersMonitor() |
547 | { |
548 | - QObject::connect(KeyboardModifiersMonitor::instance(), SIGNAL(keyboardModifiersChanged(Qt::KeyboardModifiers)), |
549 | + QObject::connect(KeyMonitor::instance(), SIGNAL(keyboardModifiersChanged(Qt::KeyboardModifiers)), |
550 | q, SLOT(updateWidgets())); |
551 | } |
552 | }; |
553 | @@ -321,7 +321,7 @@ |
554 | bool isUnderMouse = rect().contains(mapFromGlobal(QCursor::pos())); |
555 | bool isOpened = isOnSameScreen && |
556 | (isUnderMouse |
557 | - || KeyboardModifiersMonitor::instance()->keyboardModifiers() == Qt::AltModifier |
558 | + || KeyMonitor::instance()->keyboardModifiers() == Qt::AltModifier |
559 | || d->m_menuBarWidget->isOpened() |
560 | ); |
561 | bool showDesktopLabel = !app; |
562 | |
563 | === modified file 'shell/app/shellmanager.cpp' |
564 | --- shell/app/shellmanager.cpp 2012-04-06 15:16:39 +0000 |
565 | +++ shell/app/shellmanager.cpp 2012-04-19 08:51:21 +0000 |
566 | @@ -31,7 +31,6 @@ |
567 | #include <hotmodifier.h> |
568 | #include <hotkeymonitor.h> |
569 | #include <hotkey.h> |
570 | -#include <keyboardmodifiersmonitor.h> |
571 | #include <keymonitor.h> |
572 | #include <screeninfo.h> |
573 | |
574 | @@ -300,7 +299,7 @@ |
575 | updateSuperKeyMonitoring(); |
576 | |
577 | /* Super tap shows the dash, super held shows the launcher hints */ |
578 | - d->m_superHotModifier = KeyboardModifiersMonitor::instance()->getHotModifierFor(Qt::MetaModifier); |
579 | + d->m_superHotModifier = KeyMonitor::instance()->getHotModifierFor(Qt::MetaModifier); |
580 | connect(d->m_superHotModifier, SIGNAL(tapped()), SLOT(toggleDashRequested())); |
581 | connect(d->m_superHotModifier, SIGNAL(heldChanged(bool)), SIGNAL(superKeyHeldChanged(bool))); |
582 | |
583 | @@ -514,7 +513,7 @@ |
584 | d->m_hudHotKey = HotkeyMonitor::instance().getHotkeyFor(x11KeyCode, modifiers); |
585 | connect(d->m_hudHotKey, SIGNAL(pressed()), SLOT(toggleHudRequested())); |
586 | } else if (modifiers != Qt::NoModifier) { |
587 | - d->m_hudHotModifier = KeyboardModifiersMonitor::instance()->getHotModifierFor(modifiers); |
588 | + d->m_hudHotModifier = KeyMonitor::instance()->getHotModifierFor(modifiers); |
589 | connect(d->m_hudHotModifier, SIGNAL(tapped()), SLOT(toggleHudRequested())); |
590 | } |
591 | } else { |
592 | @@ -527,7 +526,7 @@ |
593 | void |
594 | ShellManager::updateSuperKeyMonitoring() |
595 | { |
596 | - KeyboardModifiersMonitor *modifiersMonitor = KeyboardModifiersMonitor::instance(); |
597 | + KeyMonitor *modifiersMonitor = KeyMonitor::instance(); |
598 | HotkeyMonitor& hotkeyMonitor = HotkeyMonitor::instance(); |
599 | |
600 | QVariant value = launcher2dConfiguration().property("superKeyEnable"); |
I'll try to integrate the test code from https:/ /bugs.launchpad .net/unity- 2d/+bug/ 968840/ comments/ 4 next