Merge lp:~dyams/unity-2d/centralized-superkey into lp:~dyams/unity-2d/Shell-MultiMonitor
- centralized-superkey
- Merge into Shell-MultiMonitor
Proposed by
Lohith D Shivamurthy
Status: | Merged |
---|---|
Approved by: | Lohith D Shivamurthy |
Approved revision: | 921 |
Merge reported by: | Lohith D Shivamurthy |
Merged at revision: | not available |
Proposed branch: | lp:~dyams/unity-2d/centralized-superkey |
Merge into: | lp:~dyams/unity-2d/Shell-MultiMonitor |
Diff against target: |
440 lines (+147/-124) 6 files modified
shell/app/shelldeclarativeview.cpp (+0/-104) shell/app/shelldeclarativeview.h (+1/-16) shell/app/shellmanager.cpp (+130/-2) shell/app/shellmanager.h (+14/-0) shell/launcher/LauncherList.qml (+1/-1) shell/launcher/LauncherLoader.qml (+1/-1) |
To merge this branch: | bzr merge lp:~dyams/unity-2d/centralized-superkey |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Albert Astals Cid (community) | Approve | ||
Review via email: mp+93152@code.launchpad.net |
Commit message
Description of the change
[shell] Move super key handling stuff to shellmanager.cpp
To post a comment you must log in.
- 921. By Lohith D Shivamurthy
-
Added a TODO to handle Dash in every shell
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'shell/app/shelldeclarativeview.cpp' |
2 | --- shell/app/shelldeclarativeview.cpp 2012-02-14 11:01:49 +0000 |
3 | +++ shell/app/shelldeclarativeview.cpp 2012-02-15 09:37:18 +0000 |
4 | @@ -22,11 +22,6 @@ |
5 | // libunity-2d-private |
6 | #include <debug_p.h> |
7 | #include <hotkey.h> |
8 | -#include <hotkeymonitor.h> |
9 | -#include <keyboardmodifiersmonitor.h> |
10 | -#include <keymonitor.h> |
11 | -#include <dashclient.h> |
12 | -#include <launcherclient.h> |
13 | #include <screeninfo.h> |
14 | #include <strutmanager.h> |
15 | |
16 | @@ -47,8 +42,6 @@ |
17 | #include <X11/Xlib.h> |
18 | #include <X11/Xatom.h> |
19 | |
20 | -static const int KEY_HOLD_THRESHOLD = 250; |
21 | - |
22 | static const char* COMMANDS_LENS_ID = "commands.lens"; |
23 | |
24 | ShellDeclarativeView::ShellDeclarativeView(const QUrl &sourceFileUrl, bool isTopLeftShell, int screen) |
25 | @@ -56,8 +49,6 @@ |
26 | , m_mode(DesktopMode) |
27 | , m_expanded(true) |
28 | , m_active(false) |
29 | - , m_superKeyPressed(false) |
30 | - , m_superKeyHeld(false) |
31 | , m_isTopLeftShell(isTopLeftShell) |
32 | , m_sourceFileUrl(sourceFileUrl) |
33 | { |
34 | @@ -66,14 +57,6 @@ |
35 | |
36 | m_screenInfo = new ScreenInfo(screen, this); |
37 | |
38 | - m_superKeyHoldTimer.setSingleShot(true); |
39 | - m_superKeyHoldTimer.setInterval(KEY_HOLD_THRESHOLD); |
40 | - connect(&m_superKeyHoldTimer, SIGNAL(timeout()), SLOT(updateSuperKeyHoldState())); |
41 | - connect(this, SIGNAL(superKeyTapped()), SLOT(toggleDash())); |
42 | - |
43 | - connect(&launcher2dConfiguration(), SIGNAL(superKeyEnableChanged(bool)), SLOT(updateSuperKeyMonitoring())); |
44 | - updateSuperKeyMonitoring(); |
45 | - |
46 | connect(m_screenInfo, SIGNAL(availableGeometryChanged(QRect)), SLOT(updateShellPosition())); |
47 | updateShellPosition(); |
48 | } |
49 | @@ -268,93 +251,6 @@ |
50 | } |
51 | } |
52 | |
53 | -/* ----------------- super key handling ---------------- */ |
54 | - |
55 | -void |
56 | -ShellDeclarativeView::updateSuperKeyHoldState() |
57 | -{ |
58 | - /* If the key was released in the meantime, just do nothing, otherwise |
59 | - consider the key being held, unless we're told to ignore it. */ |
60 | - if (m_superKeyPressed && !m_superPressIgnored) { |
61 | - m_superKeyHeld = true; |
62 | - Q_EMIT superKeyHeldChanged(m_superKeyHeld); |
63 | - } |
64 | -} |
65 | - |
66 | -void |
67 | -ShellDeclarativeView::updateSuperKeyMonitoring() |
68 | -{ |
69 | - KeyboardModifiersMonitor *modifiersMonitor = KeyboardModifiersMonitor::instance(); |
70 | - KeyMonitor *keyMonitor = KeyMonitor::instance(); |
71 | - HotkeyMonitor& hotkeyMonitor = HotkeyMonitor::instance(); |
72 | - |
73 | - QVariant value = launcher2dConfiguration().property("superKeyEnable"); |
74 | - if (!value.isValid() || value.toBool() == true) { |
75 | - hotkeyMonitor.enableModifiers(Qt::MetaModifier); |
76 | - QObject::connect(modifiersMonitor, |
77 | - SIGNAL(keyboardModifiersChanged(Qt::KeyboardModifiers)), |
78 | - this, SLOT(setHotkeysForModifiers(Qt::KeyboardModifiers))); |
79 | - /* Ignore Super presses if another key was pressed simultaneously |
80 | - (i.e. a shortcut). https://bugs.launchpad.net/unity-2d/+bug/801073 */ |
81 | - QObject::connect(keyMonitor, |
82 | - SIGNAL(keyPressed()), |
83 | - this, SLOT(ignoreSuperPress())); |
84 | - setHotkeysForModifiers(modifiersMonitor->keyboardModifiers()); |
85 | - } else { |
86 | - hotkeyMonitor.disableModifiers(Qt::MetaModifier); |
87 | - QObject::disconnect(modifiersMonitor, |
88 | - SIGNAL(keyboardModifiersChanged(Qt::KeyboardModifiers)), |
89 | - this, SLOT(setHotkeysForModifiers(Qt::KeyboardModifiers))); |
90 | - QObject::disconnect(keyMonitor, |
91 | - SIGNAL(keyPressed()), |
92 | - this, SLOT(ignoreSuperPress())); |
93 | - m_superKeyHoldTimer.stop(); |
94 | - m_superKeyPressed = false; |
95 | - if (m_superKeyHeld) { |
96 | - m_superKeyHeld = false; |
97 | - Q_EMIT superKeyHeldChanged(false); |
98 | - } |
99 | - } |
100 | -} |
101 | - |
102 | -void |
103 | -ShellDeclarativeView::setHotkeysForModifiers(Qt::KeyboardModifiers modifiers) |
104 | -{ |
105 | - /* This is the new new state of the Super key (AKA Meta key), while |
106 | - m_superKeyPressed is the previous state of the key at the last modifiers change. */ |
107 | - bool superKeyPressed = modifiers.testFlag(Qt::MetaModifier); |
108 | - |
109 | - if (m_superKeyPressed != superKeyPressed) { |
110 | - m_superKeyPressed = superKeyPressed; |
111 | - if (superKeyPressed) { |
112 | - m_superPressIgnored = false; |
113 | - /* If the key is pressed, start up a timer to monitor if it's being held short |
114 | - enough to qualify as just a "tap" or as a proper hold */ |
115 | - m_superKeyHoldTimer.start(); |
116 | - } else { |
117 | - m_superKeyHoldTimer.stop(); |
118 | - |
119 | - /* If the key is released, and was not being held, it means that the user just |
120 | - performed a "tap". Unless we're told to ignore that tap, that is. */ |
121 | - if (!m_superKeyHeld && !m_superPressIgnored) { |
122 | - Q_EMIT superKeyTapped(); |
123 | - } |
124 | - /* Otherwise the user just terminated a hold. */ |
125 | - else if(m_superKeyHeld){ |
126 | - m_superKeyHeld = false; |
127 | - Q_EMIT superKeyHeldChanged(m_superKeyHeld); |
128 | - } |
129 | - } |
130 | - } |
131 | -} |
132 | - |
133 | -void |
134 | -ShellDeclarativeView::ignoreSuperPress() |
135 | -{ |
136 | - /* There was a key pressed, ignore current super tap/hold */ |
137 | - m_superPressIgnored = true; |
138 | -} |
139 | - |
140 | void |
141 | ShellDeclarativeView::processNumericHotkey(Hotkey* hotkey) |
142 | { |
143 | |
144 | === modified file 'shell/app/shelldeclarativeview.h' |
145 | --- shell/app/shelldeclarativeview.h 2012-02-14 11:01:49 +0000 |
146 | +++ shell/app/shelldeclarativeview.h 2012-02-15 09:37:18 +0000 |
147 | @@ -39,7 +39,6 @@ |
148 | Q_PROPERTY(DashMode dashMode READ dashMode WRITE setDashMode NOTIFY dashModeChanged) |
149 | Q_PROPERTY(QString activeLens READ activeLens WRITE setActiveLens NOTIFY activeLensChanged) |
150 | Q_PROPERTY(bool focus READ hasFocus NOTIFY focusChanged) // overridden to add notify |
151 | - Q_PROPERTY(bool superKeyHeld READ superKeyHeld NOTIFY superKeyHeldChanged) |
152 | Q_PROPERTY(bool isTopLeftShell READ isTopLeftShell WRITE setIsTopLeftShell NOTIFY isTopLeftShellChanged) |
153 | Q_PROPERTY(bool haveCustomHomeShortcuts READ haveCustomHomeShortcuts) |
154 | |
155 | @@ -66,7 +65,6 @@ |
156 | DashMode dashMode() const; |
157 | const QString& activeLens() const; |
158 | bool expanded() const; |
159 | - bool superKeyHeld() const { return m_superKeyHeld; } |
160 | QRect monitoredArea() const; |
161 | bool monitoredAreaContainsMouse() const; |
162 | bool isTopLeftShell() const { return m_isTopLeftShell; } |
163 | @@ -83,6 +81,7 @@ |
164 | |
165 | virtual bool x11EventFilter(XEvent* event); |
166 | |
167 | + void toggleDash(); |
168 | void toggleLauncher(); |
169 | void showCommandsLens(); |
170 | |
171 | @@ -100,21 +99,11 @@ |
172 | void monitoredAreaContainsMouseChanged(); |
173 | |
174 | void addWebFavoriteRequested(const QUrl& url); |
175 | - void superKeyHeldChanged(bool superKeyHeld); |
176 | - void superKeyTapped(); |
177 | void activateShortcutPressed(int itemIndex); |
178 | void newInstanceShortcutPressed(int itemIndex); |
179 | void launcherFocusRequested(); |
180 | void isTopLeftShellChanged(bool); |
181 | |
182 | -private Q_SLOTS: |
183 | - void updateSuperKeyMonitoring(); |
184 | - void updateSuperKeyHoldState(); |
185 | - void setHotkeysForModifiers(Qt::KeyboardModifiers modifiers); |
186 | - void ignoreSuperPress(); |
187 | - |
188 | - void toggleDash(); |
189 | - |
190 | protected: |
191 | virtual void showEvent(QShowEvent *event); |
192 | virtual void mouseMoveEvent(QMouseEvent *event); |
193 | @@ -135,10 +124,6 @@ |
194 | QString m_activeLens; /* Lens id of the active lens */ |
195 | bool m_active; |
196 | |
197 | - bool m_superKeyPressed; |
198 | - bool m_superKeyHeld; |
199 | - bool m_superPressIgnored; |
200 | - QTimer m_superKeyHoldTimer; |
201 | QRect m_monitoredArea; |
202 | bool m_monitoredAreaContainsMouse; |
203 | bool m_isTopLeftShell; |
204 | |
205 | === modified file 'shell/app/shellmanager.cpp' |
206 | --- shell/app/shellmanager.cpp 2012-02-14 12:26:47 +0000 |
207 | +++ shell/app/shellmanager.cpp 2012-02-15 09:37:18 +0000 |
208 | @@ -33,6 +33,8 @@ |
209 | // libunity-2d-private |
210 | #include <hotkeymonitor.h> |
211 | #include <hotkey.h> |
212 | +#include <keyboardmodifiersmonitor.h> |
213 | +#include <keymonitor.h> |
214 | #include <screeninfo.h> |
215 | |
216 | // Local |
217 | @@ -50,10 +52,16 @@ |
218 | // X11 |
219 | #include <X11/Xlib.h> |
220 | |
221 | +static const int KEY_HOLD_THRESHOLD = 250; |
222 | + |
223 | struct ShellManagerPrivate |
224 | { |
225 | - ShellManagerPrivate() : |
226 | - q(0), m_dashDBus(0), m_launcherDBus(0) |
227 | + ShellManagerPrivate() |
228 | + : q(0) |
229 | + , m_dashDBus(0) |
230 | + , m_launcherDBus(0) |
231 | + , m_superKeyPressed(false) |
232 | + , m_superKeyHeld(false) |
233 | {} |
234 | |
235 | ShellDeclarativeView* initShell(bool isTopLeft, int screen); |
236 | @@ -65,6 +73,11 @@ |
237 | DashDBus * m_dashDBus; |
238 | LauncherDBus* m_launcherDBus; |
239 | QUrl m_sourceFileUrl; |
240 | + |
241 | + bool m_superKeyPressed; |
242 | + bool m_superKeyHeld; |
243 | + bool m_superPressIgnored; |
244 | + QTimer m_superKeyHoldTimer; |
245 | }; |
246 | |
247 | |
248 | @@ -86,6 +99,7 @@ |
249 | /* Load the QML UI, focus and show the window */ |
250 | view->setResizeMode(QDeclarativeView::SizeViewToRootObject); |
251 | view->rootContext()->setContextProperty("declarativeView", view); |
252 | + view->rootContext()->setContextProperty("shellManager", q); |
253 | // WARNING This declaration of dashClient used to be in Unity2d/plugin.cpp |
254 | // but it lead to locks when both the shell and the spread were started |
255 | // at the same time since SpreadMonitor QDBusServiceWatcher::serviceRegistered |
256 | @@ -190,6 +204,13 @@ |
257 | |
258 | connect(desktop, SIGNAL(screenCountChanged(int)), SLOT(onScreenCountChanged(int))); |
259 | |
260 | + d->m_superKeyHoldTimer.setSingleShot(true); |
261 | + d->m_superKeyHoldTimer.setInterval(KEY_HOLD_THRESHOLD); |
262 | + connect(&d->m_superKeyHoldTimer, SIGNAL(timeout()), SLOT(updateSuperKeyHoldState())); |
263 | + |
264 | + connect(&launcher2dConfiguration(), SIGNAL(superKeyEnableChanged(bool)), SLOT(updateSuperKeyMonitoring())); |
265 | + updateSuperKeyMonitoring(); |
266 | + |
267 | /* Alt+F1 reveal the launcher and gives the keyboard focus to the Dash Button. */ |
268 | Hotkey* altF1 = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_F1, Qt::AltModifier); |
269 | connect(altF1, SIGNAL(pressed()), SLOT(onAltF1Pressed())); |
270 | @@ -219,6 +240,113 @@ |
271 | d->updateScreenCount(newCount); |
272 | } |
273 | |
274 | +/* ----------------- super key handling ---------------- */ |
275 | + |
276 | +void |
277 | +ShellManager::updateSuperKeyHoldState() |
278 | +{ |
279 | + /* If the key was released in the meantime, just do nothing, otherwise |
280 | + consider the key being held, unless we're told to ignore it. */ |
281 | + if (d->m_superKeyPressed && !d->m_superPressIgnored) { |
282 | + d->m_superKeyHeld = true; |
283 | + Q_EMIT superKeyHeldChanged(d->m_superKeyHeld); |
284 | + } |
285 | +} |
286 | + |
287 | +void |
288 | +ShellManager::updateSuperKeyMonitoring() |
289 | +{ |
290 | + KeyboardModifiersMonitor *modifiersMonitor = KeyboardModifiersMonitor::instance(); |
291 | + KeyMonitor *keyMonitor = KeyMonitor::instance(); |
292 | + HotkeyMonitor& hotkeyMonitor = HotkeyMonitor::instance(); |
293 | + |
294 | + QVariant value = launcher2dConfiguration().property("superKeyEnable"); |
295 | + if (!value.isValid() || value.toBool() == true) { |
296 | + hotkeyMonitor.enableModifiers(Qt::MetaModifier); |
297 | + QObject::connect(modifiersMonitor, |
298 | + SIGNAL(keyboardModifiersChanged(Qt::KeyboardModifiers)), |
299 | + this, SLOT(setHotkeysForModifiers(Qt::KeyboardModifiers))); |
300 | + /* Ignore Super presses if another key was pressed simultaneously |
301 | + (i.e. a shortcut). https://bugs.launchpad.net/unity-2d/+bug/801073 */ |
302 | + QObject::connect(keyMonitor, |
303 | + SIGNAL(keyPressed()), |
304 | + this, SLOT(ignoreSuperPress())); |
305 | + setHotkeysForModifiers(modifiersMonitor->keyboardModifiers()); |
306 | + } else { |
307 | + hotkeyMonitor.disableModifiers(Qt::MetaModifier); |
308 | + QObject::disconnect(modifiersMonitor, |
309 | + SIGNAL(keyboardModifiersChanged(Qt::KeyboardModifiers)), |
310 | + this, SLOT(setHotkeysForModifiers(Qt::KeyboardModifiers))); |
311 | + QObject::disconnect(keyMonitor, |
312 | + SIGNAL(keyPressed()), |
313 | + this, SLOT(ignoreSuperPress())); |
314 | + d->m_superKeyHoldTimer.stop(); |
315 | + d->m_superKeyPressed = false; |
316 | + if (d->m_superKeyHeld) { |
317 | + d->m_superKeyHeld = false; |
318 | + Q_EMIT superKeyHeldChanged(false); |
319 | + } |
320 | + } |
321 | +} |
322 | + |
323 | +void |
324 | +ShellManager::setHotkeysForModifiers(Qt::KeyboardModifiers modifiers) |
325 | +{ |
326 | + /* This is the new new state of the Super key (AKA Meta key), while |
327 | + d->m_superKeyPressed is the previous state of the key at the last modifiers change. */ |
328 | + bool superKeyPressed = modifiers.testFlag(Qt::MetaModifier); |
329 | + |
330 | + if (d->m_superKeyPressed != superKeyPressed) { |
331 | + d->m_superKeyPressed = superKeyPressed; |
332 | + if (superKeyPressed) { |
333 | + d->m_superPressIgnored = false; |
334 | + /* If the key is pressed, start up a timer to monitor if it's being held short |
335 | + enough to qualify as just a "tap" or as a proper hold */ |
336 | + d->m_superKeyHoldTimer.start(); |
337 | + } else { |
338 | + d->m_superKeyHoldTimer.stop(); |
339 | + |
340 | + /* If the key is released, and was not being held, it means that the user just |
341 | + performed a "tap". Unless we're told to ignore that tap, that is. */ |
342 | + if (!d->m_superKeyHeld && !d->m_superPressIgnored) { |
343 | + onSuperKeyTapped(); |
344 | + } |
345 | + /* Otherwise the user just terminated a hold. */ |
346 | + else if(d->m_superKeyHeld){ |
347 | + d->m_superKeyHeld = false; |
348 | + Q_EMIT superKeyHeldChanged(d->m_superKeyHeld); |
349 | + } |
350 | + } |
351 | + } |
352 | +} |
353 | + |
354 | +void |
355 | +ShellManager::ignoreSuperPress() |
356 | +{ |
357 | + /* There was a key pressed, ignore current super tap/hold */ |
358 | + d->m_superPressIgnored = true; |
359 | +} |
360 | + |
361 | +void |
362 | +ShellManager::onSuperKeyTapped() |
363 | +{ |
364 | + // TODO : In future, All shells should be able to handle the Dash |
365 | + // Note: Always, first item in the list is the topLeft shell |
366 | + // In any case, just iterate through the list |
367 | + Q_FOREACH(ShellDeclarativeView *shell, d->m_viewList) { |
368 | + if (shell->isTopLeftShell()) { |
369 | + shell->toggleDash(); |
370 | + break; |
371 | + } |
372 | + } |
373 | +} |
374 | + |
375 | +bool |
376 | +ShellManager::superKeyHeld() const |
377 | +{ |
378 | + return d->m_superKeyHeld; |
379 | +} |
380 | + |
381 | /*------------------ Hotkeys Handling -----------------------*/ |
382 | |
383 | void |
384 | |
385 | === modified file 'shell/app/shellmanager.h' |
386 | --- shell/app/shellmanager.h 2012-02-14 09:27:26 +0000 |
387 | +++ shell/app/shellmanager.h 2012-02-15 09:37:18 +0000 |
388 | @@ -26,12 +26,26 @@ |
389 | class ShellManager : public QObject |
390 | { |
391 | Q_OBJECT |
392 | + Q_PROPERTY(bool superKeyHeld READ superKeyHeld NOTIFY superKeyHeldChanged) |
393 | + |
394 | public: |
395 | ShellManager(const QUrl &sourceFileUrl, QObject* parent = 0); |
396 | ~ShellManager(); |
397 | |
398 | + bool superKeyHeld() const; |
399 | + |
400 | +Q_SIGNALS: |
401 | + void superKeyHeldChanged(bool superKeyHeld); |
402 | + |
403 | private Q_SLOTS: |
404 | void onScreenCountChanged(int); |
405 | + |
406 | + void updateSuperKeyMonitoring(); |
407 | + void updateSuperKeyHoldState(); |
408 | + void setHotkeysForModifiers(Qt::KeyboardModifiers modifiers); |
409 | + void ignoreSuperPress(); |
410 | + void onSuperKeyTapped(); |
411 | + |
412 | void onAltF1Pressed(); |
413 | void onAltF2Pressed(); |
414 | void onNumericHotkeyPressed(); |
415 | |
416 | === modified file 'shell/launcher/LauncherList.qml' |
417 | --- shell/launcher/LauncherList.qml 2012-02-09 11:59:16 +0000 |
418 | +++ shell/launcher/LauncherList.qml 2012-02-15 09:37:18 +0000 |
419 | @@ -125,7 +125,7 @@ |
420 | emblemVisible: item.emblemVisible |
421 | |
422 | /* Launcher of index 0 is the so-called BFB or Dash launcher */ |
423 | - shortcutVisible: declarativeView.superKeyHeld && |
424 | + shortcutVisible: shellManager.superKeyHeld && |
425 | ((item.toString().indexOf("LauncherApplication") == 0 && index > 0 && index <= 10) || |
426 | item.shortcutKey != 0) |
427 | shortcutText: { |
428 | |
429 | === modified file 'shell/launcher/LauncherLoader.qml' |
430 | --- shell/launcher/LauncherLoader.qml 2012-02-10 11:17:36 +0000 |
431 | +++ shell/launcher/LauncherLoader.qml 2012-02-15 09:37:18 +0000 |
432 | @@ -70,7 +70,7 @@ |
433 | } |
434 | |
435 | Connections { |
436 | - target: declarativeView |
437 | + target: shellManager |
438 | onSuperKeyHeldChanged: { |
439 | if (superKeyHeld) visibilityController.beginForceVisible() |
440 | else visibilityController.endForceVisible() |
Approved, makes sense