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