Merge lp:~aacid/unity-2d/unity-2d_hud_configuration_key into lp:unity-2d
- unity-2d_hud_configuration_key
- Merge into trunk
Proposed by
Albert Astals Cid
Status: | Merged |
---|---|
Approved by: | Michał Sawicz |
Approved revision: | 1035 |
Merged at revision: | 1030 |
Proposed branch: | lp:~aacid/unity-2d/unity-2d_hud_configuration_key |
Merge into: | lp:unity-2d |
Diff against target: |
605 lines (+302/-31) 15 files modified
libunity-2d-private/src/CMakeLists.txt (+1/-0) libunity-2d-private/src/gkeysequenceparser.cpp (+73/-0) libunity-2d-private/src/gkeysequenceparser.h (+28/-0) libunity-2d-private/src/hotkey.cpp (+37/-15) libunity-2d-private/src/hotkey.h (+7/-4) libunity-2d-private/src/hotkeymonitor.cpp (+15/-0) libunity-2d-private/src/hotkeymonitor.h (+1/-0) libunity-2d-private/src/hotmodifier.cpp (+9/-5) libunity-2d-private/src/hotmodifier.h (+1/-0) libunity-2d-private/tests/CMakeLists.txt (+1/-0) libunity-2d-private/tests/gkeysequenceparser.cpp (+66/-0) libunity-2d-private/tests/hotkeytest.cpp (+1/-1) shell/app/shellmanager.cpp (+50/-6) shell/app/shellmanager.h (+2/-0) tests/manual-tests/hud.txt (+10/-0) |
To merge this branch: | bzr merge lp:~aacid/unity-2d/unity-2d_hud_configuration_key |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Paweł Stołowski (community) | Approve | ||
Michał Sawicz | Pending | ||
Review via email: mp+100418@code.launchpad.net |
Commit message
[HUD] Read the unity setting for hud toggling
For that we need to introduce a parser of the gsettings unity conf key and modify the hotmodifier so it supports multiple modifiers (like shift + alt)
Description of the change
[HUD] Read the unity setting for hud toggling
For that we need to introduce a parser of the gsettings unity conf key and modify the hotmodifier so it supports multiple modifiers (like shift + alt)
To post a comment you must log in.
Revision history for this message
Unity Merger (unity-merger) wrote : | # |
The Jenkins job https:/
Not merging it.
- 1035. By Albert Astals Cid
-
Use a more usual letter that works with xvfb
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-03-20 14:50:42 +0000 |
3 | +++ libunity-2d-private/src/CMakeLists.txt 2012-04-02 16:31:23 +0000 |
4 | @@ -87,6 +87,7 @@ |
5 | pointerbarrier.cpp |
6 | pointerbarriermanager.cpp |
7 | decayedvalue.cpp |
8 | + gkeysequenceparser.cpp |
9 | ) |
10 | |
11 | # Build |
12 | |
13 | === added file 'libunity-2d-private/src/gkeysequenceparser.cpp' |
14 | --- libunity-2d-private/src/gkeysequenceparser.cpp 1970-01-01 00:00:00 +0000 |
15 | +++ libunity-2d-private/src/gkeysequenceparser.cpp 2012-04-02 16:31:23 +0000 |
16 | @@ -0,0 +1,73 @@ |
17 | +/* |
18 | + * Copyright (C) 2012 Canonical, Ltd. |
19 | + * |
20 | + * This program is free software; you can redistribute it and/or modify |
21 | + * it under the terms of the GNU General Public License as published by |
22 | + * the Free Software Foundation; version 3. |
23 | + * |
24 | + * This program is distributed in the hope that it will be useful, |
25 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
26 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
27 | + * GNU General Public License for more details. |
28 | + * |
29 | + * You should have received a copy of the GNU General Public License |
30 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
31 | + */ |
32 | + |
33 | +#include "gkeysequenceparser.h" |
34 | + |
35 | +#include <QDebug> |
36 | +#include <QString> |
37 | +#include <QX11Info> |
38 | + |
39 | +#include <X11/XKBlib.h> |
40 | + |
41 | +bool GKeySequenceParser::parse(const QString &keySequence, int *x11KeyCode, Qt::KeyboardModifiers *modifiers) |
42 | +{ |
43 | + // Parses a string in the form created by the gtk shortcut dialog into x11 keycode and qt modifiers |
44 | + // The expected format is |
45 | + // <Modifier>*Keyname? |
46 | + // i.e. there can be none or multiple modifiers followed or not by the name of a key |
47 | + bool success = true; |
48 | + *x11KeyCode = 0; |
49 | + *modifiers = Qt::NoModifier; |
50 | + if (keySequence == "Disabled") { |
51 | + return success; |
52 | + } |
53 | + |
54 | + QString aux = keySequence; |
55 | + while (success && aux.startsWith('<')) { |
56 | + const int closing = aux.indexOf('>'); |
57 | + if (closing > 0) { |
58 | + const QString modifier = aux.mid(1, closing - 1); |
59 | + if (modifier == "Control" || modifier == "Primary") { |
60 | + *modifiers = *modifiers | Qt::ControlModifier; |
61 | + } else if (modifier == "Shift") { |
62 | + *modifiers = *modifiers | Qt::ShiftModifier; |
63 | + } else if (modifier == "Alt") { |
64 | + *modifiers = *modifiers | Qt::AltModifier; |
65 | + } else if (modifier == "Super") { |
66 | + *modifiers = *modifiers | Qt::MetaModifier; |
67 | + } else { |
68 | + qWarning() << "Could not parse modifier" << modifier << "in key sequence" << keySequence; |
69 | + success = false; |
70 | + } |
71 | + aux = aux.mid(closing + 1); |
72 | + } else { |
73 | + qWarning() << "Could not find modifier end in key sequence" << keySequence; |
74 | + success = false; |
75 | + } |
76 | + } |
77 | + |
78 | + if (success && !aux.isEmpty()) { |
79 | + KeySym keysym = XStringToKeysym(aux.toLatin1().constData()); |
80 | + if (keysym == NoSymbol) { |
81 | + qWarning() << "Could not parse key" << aux << "in key sequence" << keySequence; |
82 | + success = false; |
83 | + } else { |
84 | + *x11KeyCode = XKeysymToKeycode(QX11Info::display(), keysym); |
85 | + } |
86 | + } |
87 | + |
88 | + return success; |
89 | +} |
90 | |
91 | === added file 'libunity-2d-private/src/gkeysequenceparser.h' |
92 | --- libunity-2d-private/src/gkeysequenceparser.h 1970-01-01 00:00:00 +0000 |
93 | +++ libunity-2d-private/src/gkeysequenceparser.h 2012-04-02 16:31:23 +0000 |
94 | @@ -0,0 +1,28 @@ |
95 | +/* |
96 | + * Copyright (C) 2012 Canonical, Ltd. |
97 | + * |
98 | + * This program is free software; you can redistribute it and/or modify |
99 | + * it under the terms of the GNU General Public License as published by |
100 | + * the Free Software Foundation; version 3. |
101 | + * |
102 | + * This program is distributed in the hope that it will be useful, |
103 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
104 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
105 | + * GNU General Public License for more details. |
106 | + * |
107 | + * You should have received a copy of the GNU General Public License |
108 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
109 | + */ |
110 | + |
111 | +#ifndef GKEYSEQUENCEPARSER_H |
112 | +#define GKEYSEQUENCEPARSER_H |
113 | + |
114 | +#include <Qt> |
115 | + |
116 | +namespace GKeySequenceParser |
117 | +{ |
118 | + bool parse(const QString &keySequence, int *x11KeyCode, Qt::KeyboardModifiers *modifiers); |
119 | +} |
120 | + |
121 | +#endif // GKEYSEQUENCEPARSER_H |
122 | + |
123 | |
124 | === modified file 'libunity-2d-private/src/hotkey.cpp' |
125 | --- libunity-2d-private/src/hotkey.cpp 2012-03-16 16:48:19 +0000 |
126 | +++ libunity-2d-private/src/hotkey.cpp 2012-04-02 16:31:23 +0000 |
127 | @@ -54,20 +54,8 @@ |
128 | m_key(key), m_modifiers(modifiers), |
129 | m_x11key(0), m_x11modifiers(0) |
130 | { |
131 | - /* Translate the QT modifiers to X11 modifiers */ |
132 | + translateModifiers(modifiers); |
133 | |
134 | - if (modifiers.testFlag(Qt::ShiftModifier)) { |
135 | - m_x11modifiers |= ShiftMask ; |
136 | - } |
137 | - if (modifiers.testFlag(Qt::ControlModifier)) { |
138 | - m_x11modifiers |= ControlMask ; |
139 | - } |
140 | - if (modifiers.testFlag(Qt::AltModifier)) { |
141 | - m_x11modifiers |= Mod1Mask; |
142 | - } |
143 | - if (modifiers.testFlag(Qt::MetaModifier)) { |
144 | - m_x11modifiers |= Mod4Mask; |
145 | - } |
146 | if (modifiers.testFlag(Qt::KeypadModifier)) { |
147 | /* Support 0..9 numpad keys only. |
148 | If we ever need to support additional numpad keys, then this logic should be extended |
149 | @@ -102,12 +90,24 @@ |
150 | } |
151 | } |
152 | |
153 | +Hotkey::Hotkey(uint x11key, Qt::KeyboardModifiers modifiers, QObject *parent) |
154 | + : QObject(parent), m_connections(0), |
155 | + m_key(0), m_modifiers(modifiers), |
156 | + m_x11key(x11key), m_x11modifiers(0) |
157 | +{ |
158 | + translateModifiers(modifiers); |
159 | +} |
160 | + |
161 | void |
162 | Hotkey::connectNotify(const char * signal) |
163 | { |
164 | Q_UNUSED(signal); |
165 | if (m_connections == 0) { |
166 | - UQ_DEBUG << "Grabbing hotkey" << QKeySequence(m_key | m_modifiers).toString(); |
167 | + if (m_key != 0) { |
168 | + UQ_DEBUG << "Grabbing hotkey" << QKeySequence(m_key | m_modifiers).toString(); |
169 | + } else { |
170 | + UQ_DEBUG.nospace() << "Grabbing hotkey" << QKeySequence(m_modifiers).toString() << XKeysymToString(XKeycodeToKeysym(QX11Info::display(), m_x11key, 0)); |
171 | + } |
172 | _x_old_errhandler = XSetErrorHandler(_x_grabkey_errhandler); |
173 | XGrabKey(QX11Info::display(), m_x11key, m_x11modifiers, |
174 | QX11Info::appRootWindow(), True, GrabModeAsync, GrabModeAsync); |
175 | @@ -122,7 +122,11 @@ |
176 | { |
177 | Q_UNUSED(signal); |
178 | if (m_connections == 1) { |
179 | - UQ_DEBUG << "Ungrabbing hotkey" << QKeySequence(m_key | m_modifiers).toString(); |
180 | + if (m_key != 0) { |
181 | + UQ_DEBUG << "Ungrabbing hotkey" << QKeySequence(m_key | m_modifiers).toString(); |
182 | + } else { |
183 | + UQ_DEBUG.nospace() << "Ungrabbing hotkey" << QKeySequence(m_modifiers).toString() << XKeysymToString(XKeycodeToKeysym(QX11Info::display(), m_x11key, 0)); |
184 | + } |
185 | XUngrabKey(QX11Info::display(), m_x11key, m_x11modifiers, |
186 | QX11Info::appRootWindow()); |
187 | } |
188 | @@ -139,4 +143,22 @@ |
189 | return false; |
190 | } |
191 | |
192 | +void |
193 | +Hotkey::translateModifiers(Qt::KeyboardModifiers modifiers) |
194 | +{ |
195 | + /* Translate the QT modifiers to X11 modifiers */ |
196 | + if (modifiers.testFlag(Qt::ShiftModifier)) { |
197 | + m_x11modifiers |= ShiftMask ; |
198 | + } |
199 | + if (modifiers.testFlag(Qt::ControlModifier)) { |
200 | + m_x11modifiers |= ControlMask ; |
201 | + } |
202 | + if (modifiers.testFlag(Qt::AltModifier)) { |
203 | + m_x11modifiers |= Mod1Mask; |
204 | + } |
205 | + if (modifiers.testFlag(Qt::MetaModifier)) { |
206 | + m_x11modifiers |= Mod4Mask; |
207 | + } |
208 | +} |
209 | + |
210 | #include "hotkey.moc" |
211 | |
212 | === modified file 'libunity-2d-private/src/hotkey.h' |
213 | --- libunity-2d-private/src/hotkey.h 2012-02-03 13:36:16 +0000 |
214 | +++ libunity-2d-private/src/hotkey.h 2012-04-02 16:31:23 +0000 |
215 | @@ -27,15 +27,16 @@ |
216 | friend class HotkeyMonitor; |
217 | |
218 | Q_OBJECT |
219 | - Q_PROPERTY(Qt::Key key READ key NOTIFY keyChanged) |
220 | + Q_PROPERTY(int key READ key NOTIFY keyChanged) |
221 | Q_PROPERTY(Qt::KeyboardModifiers modifiers READ modifiers NOTIFY modifiersChanged) |
222 | |
223 | public: |
224 | - Qt::Key key() const { return m_key; } |
225 | + int key() const { return m_key; } |
226 | + uint x11key() const { return m_x11key; } |
227 | Qt::KeyboardModifiers modifiers() const { return m_modifiers; } |
228 | |
229 | Q_SIGNALS: |
230 | - void keyChanged(Qt::Key key); |
231 | + void keyChanged(int key); |
232 | void modifiersChanged(Qt::KeyboardModifiers modifiers); |
233 | void pressed(); |
234 | void released(); |
235 | @@ -46,11 +47,13 @@ |
236 | |
237 | private: |
238 | Hotkey(Qt::Key key, Qt::KeyboardModifiers modifiers, QObject *parent); |
239 | + Hotkey(uint x11key, Qt::KeyboardModifiers modifiers, QObject *parent); |
240 | bool processNativeEvent(uint x11Keycode, uint x11Modifiers, bool isPressEvent); |
241 | + void translateModifiers(Qt::KeyboardModifiers modifiers); |
242 | |
243 | private: |
244 | uint m_connections; |
245 | - Qt::Key m_key; |
246 | + int m_key; |
247 | Qt::KeyboardModifiers m_modifiers; |
248 | uint m_x11key; |
249 | uint m_x11modifiers; |
250 | |
251 | === modified file 'libunity-2d-private/src/hotkeymonitor.cpp' |
252 | --- libunity-2d-private/src/hotkeymonitor.cpp 2012-02-06 12:07:47 +0000 |
253 | +++ libunity-2d-private/src/hotkeymonitor.cpp 2012-04-02 16:31:23 +0000 |
254 | @@ -78,6 +78,21 @@ |
255 | return hotkey; |
256 | } |
257 | |
258 | +Hotkey* |
259 | +HotkeyMonitor::getHotkeyFor(uint x11Keycode, Qt::KeyboardModifiers modifiers) |
260 | +{ |
261 | + Q_FOREACH(Hotkey* currentHotkey, m_hotkeys) { |
262 | + if (currentHotkey->x11key() == x11Keycode && |
263 | + currentHotkey->modifiers() == modifiers) { |
264 | + return currentHotkey; |
265 | + } |
266 | + } |
267 | + |
268 | + Hotkey *hotkey = new Hotkey(x11Keycode, modifiers, this); |
269 | + m_hotkeys.append(hotkey); |
270 | + return hotkey; |
271 | +} |
272 | + |
273 | void HotkeyMonitor::disableModifiers(Qt::KeyboardModifiers modifiers) |
274 | { |
275 | m_disabledModifiers |= modifiers; |
276 | |
277 | === modified file 'libunity-2d-private/src/hotkeymonitor.h' |
278 | --- libunity-2d-private/src/hotkeymonitor.h 2012-02-06 12:07:47 +0000 |
279 | +++ libunity-2d-private/src/hotkeymonitor.h 2012-04-02 16:31:23 +0000 |
280 | @@ -34,6 +34,7 @@ |
281 | ~HotkeyMonitor(); |
282 | |
283 | Hotkey* getHotkeyFor(Qt::Key key, Qt::KeyboardModifiers modifiers); |
284 | + Hotkey* getHotkeyFor(uint x11Keycode, Qt::KeyboardModifiers modifiers); |
285 | |
286 | void disableModifiers(Qt::KeyboardModifiers modifiers); |
287 | void enableModifiers(Qt::KeyboardModifiers modifiers); |
288 | |
289 | === modified file 'libunity-2d-private/src/hotmodifier.cpp' |
290 | --- libunity-2d-private/src/hotmodifier.cpp 2012-02-20 16:51:19 +0000 |
291 | +++ libunity-2d-private/src/hotmodifier.cpp 2012-04-02 16:31:23 +0000 |
292 | @@ -29,6 +29,7 @@ |
293 | QObject(parent) |
294 | , m_modifiers(modifiers) |
295 | , m_pressed(false) |
296 | +, m_partiallyPressed(false) |
297 | , m_held(false) |
298 | , m_ignored(false) |
299 | , m_otherModifierPressed(false) |
300 | @@ -56,13 +57,14 @@ |
301 | void |
302 | HotModifier::onModifiersChanged(Qt::KeyboardModifiers modifiers) |
303 | { |
304 | - bool pressed = m_modifiers & modifiers; |
305 | - bool otherModifierPressed = modifiers ^ m_modifiers; |
306 | + const bool partiallyPressed = m_modifiers & modifiers; |
307 | + const bool pressed = m_modifiers == modifiers; |
308 | + const bool otherModifierPressed = modifiers & ~m_modifiers; |
309 | |
310 | /* if a modifier other than m_modifier is pressed, we take note of it because when the |
311 | other modifier is released, m_modifier is emitted again. If we don't ignore this |
312 | event, we generate a tap, which is wrong */ |
313 | - if (otherModifierPressed && pressed) { |
314 | + if (otherModifierPressed && partiallyPressed) { |
315 | m_otherModifierPressed = true; |
316 | } |
317 | |
318 | @@ -72,17 +74,18 @@ |
319 | m_held = false; |
320 | Q_EMIT heldChanged(m_held); |
321 | } |
322 | - if (!m_pressed && pressed) { |
323 | + if (!m_partiallyPressed && partiallyPressed) { |
324 | m_ignored = false; |
325 | m_holdTimer.start(); |
326 | } |
327 | /* Case where "other modifier" is released while m_modifier still pressed. In this case |
328 | we want to have the entire modifier press event ignored, to prevent generating a tap */ |
329 | - if (m_otherModifierPressed && otherModifierPressed && pressed) { |
330 | + if (m_otherModifierPressed && otherModifierPressed && partiallyPressed) { |
331 | m_otherModifierPressed = false; |
332 | m_ignored = true; |
333 | } |
334 | m_pressed = pressed; |
335 | + m_partiallyPressed = partiallyPressed; |
336 | } |
337 | |
338 | void |
339 | @@ -109,6 +112,7 @@ |
340 | { |
341 | m_holdTimer.stop(); |
342 | m_pressed = false; |
343 | + m_partiallyPressed = false; |
344 | m_ignored = false; |
345 | if (m_held) { |
346 | m_held = false; |
347 | |
348 | === modified file 'libunity-2d-private/src/hotmodifier.h' |
349 | --- libunity-2d-private/src/hotmodifier.h 2012-02-20 16:51:19 +0000 |
350 | +++ libunity-2d-private/src/hotmodifier.h 2012-04-02 16:31:23 +0000 |
351 | @@ -52,6 +52,7 @@ |
352 | QTimer m_holdTimer; |
353 | Qt::KeyboardModifiers m_modifiers; |
354 | bool m_pressed; |
355 | + bool m_partiallyPressed; |
356 | bool m_held; |
357 | bool m_ignored; |
358 | bool m_otherModifierPressed; |
359 | |
360 | === modified file 'libunity-2d-private/tests/CMakeLists.txt' |
361 | --- libunity-2d-private/tests/CMakeLists.txt 2012-03-20 14:50:42 +0000 |
362 | +++ libunity-2d-private/tests/CMakeLists.txt 2012-04-02 16:31:23 +0000 |
363 | @@ -41,6 +41,7 @@ |
364 | imageutilitiestest |
365 | pointerbarriertest |
366 | hotkeytest |
367 | + gkeysequenceparser |
368 | ) |
369 | |
370 | target_link_libraries(pointerbarriertest ${X11_XTest_LIB}) |
371 | |
372 | === added file 'libunity-2d-private/tests/gkeysequenceparser.cpp' |
373 | --- libunity-2d-private/tests/gkeysequenceparser.cpp 1970-01-01 00:00:00 +0000 |
374 | +++ libunity-2d-private/tests/gkeysequenceparser.cpp 2012-04-02 16:31:23 +0000 |
375 | @@ -0,0 +1,66 @@ |
376 | +/* |
377 | + * This file is part of unity-2d |
378 | + * |
379 | + * Copyright 2012 Canonical Ltd. |
380 | + * |
381 | + * This program is free software; you can redistribute it and/or modify |
382 | + * it under the terms of the GNU General Public License as published by |
383 | + * the Free Software Foundation; version 3. |
384 | + * |
385 | + * This program is distributed in the hope that it will be useful, |
386 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
387 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
388 | + * GNU General Public License for more details. |
389 | + * |
390 | + * You should have received a copy of the GNU General Public License |
391 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
392 | + */ |
393 | + |
394 | +#include <QObject> |
395 | +#include <unitytestmacro.h> |
396 | + |
397 | +#include "gkeysequenceparser.h" |
398 | + |
399 | +class GKeySequenceParserTest : public QObject |
400 | +{ |
401 | + Q_OBJECT |
402 | +private Q_SLOTS: |
403 | + void testParsing() |
404 | + { |
405 | + int x11Code; |
406 | + Qt::KeyboardModifiers modifiers; |
407 | + bool success; |
408 | + |
409 | + success = GKeySequenceParser::parse("<Alt>", &x11Code, &modifiers); |
410 | + QVERIFY(success); |
411 | + QCOMPARE(x11Code, 0); |
412 | + QCOMPARE(modifiers, Qt::AltModifier); |
413 | + |
414 | + success = GKeySequenceParser::parse("<Control><Shift><Alt><Super>k", &x11Code, &modifiers); |
415 | + QVERIFY(success); |
416 | + QCOMPARE(x11Code, 45); |
417 | + QCOMPARE(modifiers, Qt::AltModifier | Qt::ShiftModifier | Qt::ControlModifier | Qt::MetaModifier); |
418 | + |
419 | + success = GKeySequenceParser::parse("<Control><Shift><Alt><Super>ccedillaj", &x11Code, &modifiers); |
420 | + QVERIFY(!success); |
421 | + |
422 | + success = GKeySequenceParser::parse("<Controll><Shift><Alt><Super>ccedillaj", &x11Code, &modifiers); |
423 | + QVERIFY(!success); |
424 | + |
425 | + success = GKeySequenceParser::parse("<Control<Shift><Alt><Super>ccedillaj", &x11Code, &modifiers); |
426 | + QVERIFY(!success); |
427 | + |
428 | + success = GKeySequenceParser::parse("<Alt>+p", &x11Code, &modifiers); |
429 | + QVERIFY(!success); |
430 | + |
431 | + success = GKeySequenceParser::parse("<>", &x11Code, &modifiers); |
432 | + QVERIFY(!success); |
433 | + |
434 | + success = GKeySequenceParser::parse("><", &x11Code, &modifiers); |
435 | + QVERIFY(!success); |
436 | + } |
437 | +}; |
438 | + |
439 | +QAPP_TEST_MAIN(GKeySequenceParserTest) |
440 | + |
441 | +#include "gkeysequenceparser.moc" |
442 | \ No newline at end of file |
443 | |
444 | === modified file 'libunity-2d-private/tests/hotkeytest.cpp' |
445 | --- libunity-2d-private/tests/hotkeytest.cpp 2012-03-16 17:15:17 +0000 |
446 | +++ libunity-2d-private/tests/hotkeytest.cpp 2012-04-02 16:31:23 +0000 |
447 | @@ -51,7 +51,7 @@ |
448 | void onKeyPressed() { |
449 | Hotkey* hotkey = qobject_cast<Hotkey*>(sender()); |
450 | |
451 | - m_key = hotkey->key(); |
452 | + m_key = (Qt::Key)hotkey->key(); |
453 | m_modifiers = hotkey->modifiers(); |
454 | ++m_count; |
455 | } |
456 | |
457 | === modified file 'shell/app/shellmanager.cpp' |
458 | --- shell/app/shellmanager.cpp 2012-03-16 11:03:24 +0000 |
459 | +++ shell/app/shellmanager.cpp 2012-04-02 16:31:23 +0000 |
460 | @@ -27,6 +27,7 @@ |
461 | |
462 | // libunity-2d-private |
463 | #include <debug_p.h> |
464 | +#include <gkeysequenceparser.h> |
465 | #include <hotmodifier.h> |
466 | #include <hotkeymonitor.h> |
467 | #include <hotkey.h> |
468 | @@ -42,6 +43,9 @@ |
469 | #include <unity2ddebug.h> |
470 | #include <gobjectcallback.h> |
471 | |
472 | +// libqtgconf |
473 | +#include <gconfitem-qml-wrapper.h> |
474 | + |
475 | // bamf |
476 | #include "bamf-window.h" |
477 | #include "bamf-matcher.h" |
478 | @@ -55,6 +59,7 @@ |
479 | static const char* COMMANDS_LENS_ID = "commands.lens"; |
480 | static const int DASH_MIN_SCREEN_WIDTH = 1280; |
481 | static const int DASH_MIN_SCREEN_HEIGHT = 1084; |
482 | +static const char* HUD_SHORTCUT_KEY = "/apps/compiz-1/plugins/unityshell/screen0/options/show_hud"; |
483 | |
484 | GOBJECT_CALLBACK1(activeWorkspaceChangedCB, "onActiveWorkspaceChanged"); |
485 | |
486 | @@ -96,9 +101,14 @@ |
487 | QString m_dashActiveLens; /* Lens id of the active lens */ |
488 | |
489 | HotModifier* m_superHotModifier; |
490 | - HotModifier* m_altHotModifier; |
491 | + |
492 | + // Only one of the two is non null at a time |
493 | + HotModifier* m_hudHotModifier; |
494 | + Hotkey* m_hudHotKey; |
495 | |
496 | WId m_last_focused_window; |
497 | + |
498 | + GConfItemQmlWrapper *m_gconfItem; |
499 | }; |
500 | |
501 | |
502 | @@ -270,6 +280,13 @@ |
503 | { |
504 | d->q = this; |
505 | d->m_sourceFileUrl = sourceFileUrl; |
506 | + d->m_hudHotModifier = NULL; |
507 | + d->m_hudHotKey = NULL; |
508 | + |
509 | + d->m_gconfItem = new GConfItemQmlWrapper(this); |
510 | + connect(d->m_gconfItem, SIGNAL(valueChanged()), this, SLOT(onHudActivationShortcutChanged())); |
511 | + d->m_gconfItem->setKey(HUD_SHORTCUT_KEY); |
512 | + onHudActivationShortcutChanged(); |
513 | |
514 | qmlRegisterUncreatableType<ShellDeclarativeView>("Unity2d", 1, 0, "ShellDeclarativeView", "This can only be created from C++"); |
515 | qmlRegisterUncreatableType<ShellManager>("Unity2d", 1, 0, "ShellManager", "This can only be created from C++"); |
516 | @@ -288,10 +305,6 @@ |
517 | connect(d->m_superHotModifier, SIGNAL(tapped()), SLOT(toggleDashRequested())); |
518 | connect(d->m_superHotModifier, SIGNAL(heldChanged(bool)), SIGNAL(superKeyHeldChanged(bool))); |
519 | |
520 | - /* Alt tap shows the HUD */ |
521 | - d->m_altHotModifier = KeyboardModifiersMonitor::instance()->getHotModifierFor(Qt::AltModifier); |
522 | - connect(d->m_altHotModifier, SIGNAL(tapped()), SLOT(toggleHudRequested())); |
523 | - |
524 | /* Alt+F1 reveals the launcher and gives the keyboard focus to the Dash Button. */ |
525 | Hotkey* altF1 = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_F1, Qt::AltModifier); |
526 | connect(altF1, SIGNAL(pressed()), SLOT(onAltF1Pressed())); |
527 | @@ -479,6 +492,37 @@ |
528 | Q_EMIT lastFocusedWindowChanged(d->m_last_focused_window); |
529 | } |
530 | |
531 | +void ShellManager::onHudActivationShortcutChanged() |
532 | +{ |
533 | + // TODO It might make sense to abstract this logic |
534 | + // of switching between hotkey and hotmodifier and put it |
535 | + // in a class in libunity-2d-private |
536 | + if (d->m_hudHotModifier) { |
537 | + d->m_hudHotModifier->disconnect(this); |
538 | + d->m_hudHotModifier = NULL; |
539 | + } |
540 | + if (d->m_hudHotKey) { |
541 | + d->m_hudHotKey->disconnect(this); |
542 | + d->m_hudHotKey = NULL; |
543 | + } |
544 | + |
545 | + int x11KeyCode; |
546 | + Qt::KeyboardModifiers modifiers; |
547 | + const QString shortcut = d->m_gconfItem->getValue().toString(); |
548 | + const bool success = GKeySequenceParser::parse(shortcut, &x11KeyCode, &modifiers); |
549 | + if (success) { |
550 | + if (x11KeyCode != 0) { |
551 | + d->m_hudHotKey = HotkeyMonitor::instance().getHotkeyFor(x11KeyCode, modifiers); |
552 | + connect(d->m_hudHotKey, SIGNAL(pressed()), SLOT(toggleHudRequested())); |
553 | + } else if (modifiers != Qt::NoModifier) { |
554 | + d->m_hudHotModifier = KeyboardModifiersMonitor::instance()->getHotModifierFor(modifiers); |
555 | + connect(d->m_hudHotModifier, SIGNAL(tapped()), SLOT(toggleHudRequested())); |
556 | + } |
557 | + } else { |
558 | + qWarning().nospace() << "Could not parse the key sequence " << shortcut << ". HUD won't be activated"; |
559 | + } |
560 | +} |
561 | + |
562 | /* ----------------- super key handling ---------------- */ |
563 | |
564 | void |
565 | @@ -580,7 +624,7 @@ |
566 | Shortcut for 0 should activate item with index 10. |
567 | In other words, the indexes are activated in the same order as |
568 | the keys appear on a standard keyboard. */ |
569 | - Qt::Key key = hotkey->key(); |
570 | + const int key = hotkey->key(); |
571 | if (key >= Qt::Key_1 && key <= Qt::Key_9) { |
572 | int index = key - Qt::Key_0; |
573 | if (hotkey->modifiers() & Qt::ShiftModifier) { |
574 | |
575 | === modified file 'shell/app/shellmanager.h' |
576 | --- shell/app/shellmanager.h 2012-03-14 08:29:06 +0000 |
577 | +++ shell/app/shellmanager.h 2012-04-02 16:31:23 +0000 |
578 | @@ -117,6 +117,8 @@ |
579 | |
580 | void onActiveWorkspaceChanged(); |
581 | |
582 | + void onHudActivationShortcutChanged(); |
583 | + |
584 | private: |
585 | Q_DISABLE_COPY(ShellManager) |
586 | ShellManagerPrivate * const d; |
587 | |
588 | === modified file 'tests/manual-tests/hud.txt' |
589 | --- tests/manual-tests/hud.txt 2012-03-20 11:14:30 +0000 |
590 | +++ tests/manual-tests/hud.txt 2012-04-02 16:31:23 +0000 |
591 | @@ -15,3 +15,13 @@ |
592 | * Use arrow keys to navigate up/down through the options returned |
593 | |
594 | --> Check Orca speaks the contents of the results |
595 | + |
596 | +---- |
597 | + * Go into ccsm |
598 | + * Change Key to Show HUD to Super+Alt |
599 | +--> Verify Super+Alt shows the HUD |
600 | + |
601 | +---- |
602 | + * Go into ccsm |
603 | + * Change Key to Show HUD to Super+Alt |
604 | +--> Verify Super+Alt shows the HUD |
605 | \ No newline at end of file |
Looks good!