Merge lp:~osomon/unity-2d/grab-shortcut-keys-once into lp:unity-2d/3.0

Proposed by Olivier Tilloy
Status: Merged
Approved by: Ugo Riboni
Approved revision: 558
Merged at revision: 559
Proposed branch: lp:~osomon/unity-2d/grab-shortcut-keys-once
Merge into: lp:unity-2d/3.0
Diff against target: 96 lines (+16/-37)
2 files modified
launcher/app/launcherview.cpp (+15/-35)
launcher/app/launcherview.h (+1/-2)
To merge this branch: bzr merge lp:~osomon/unity-2d/grab-shortcut-keys-once
Reviewer Review Type Date Requested Status
Ugo Riboni (community) Approve
Review via email: mp+59814@code.launchpad.net

Commit message

[launcher] Grab the Meta+n (for 0 ≤ n ≤ 9) hotkeys at startup, and release them only when exiting.

To post a comment you must log in.
Revision history for this message
Ugo Riboni (uriboni) wrote :

Good job at simplifying lots of parts of the code.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/app/launcherview.cpp'
2--- launcher/app/launcherview.cpp 2011-04-29 16:26:25 +0000
3+++ launcher/app/launcherview.cpp 2011-05-03 18:41:22 +0000
4@@ -65,7 +65,6 @@
5 m_superKeyHoldTimer.setInterval(KEY_HOLD_THRESHOLD);
6 connect(&m_superKeyHoldTimer, SIGNAL(timeout()), SLOT(updateSuperKeyHoldState()));
7 connect(this, SIGNAL(superKeyTapped()), SLOT(toggleDash()));
8- connect(this, SIGNAL(superKeyHeldChanged(bool)), SLOT(changeKeyboardShortcutsState(bool)));
9
10 m_enableSuperKey.setKey("/desktop/unity-2d/launcher/super_key_enable");
11 connect(&m_enableSuperKey, SIGNAL(valueChanged()), SLOT(updateSuperKeyMonitoring()));
12@@ -79,9 +78,15 @@
13 Hotkey* altF2 = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_F2, Qt::AltModifier);
14 connect(altF2, SIGNAL(pressed()), SLOT(showCommandsPlace()));
15
16- /* Super+s activated the workspaces switcher. */
17+ /* Super+s activates the workspaces switcher. */
18 Hotkey* superS = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_S, Qt::MetaModifier);
19 connect(superS, SIGNAL(pressed()), SLOT(showWorkspaceSwitcher()));
20+
21+ /* Super+{n} for 0 ≤ n ≤ 9 activates the item with index (n + 9) % 10. */
22+ for (Qt::Key key = Qt::Key_0; key <= Qt::Key_9; key = (Qt::Key) (key + 1)) {
23+ Hotkey* hotkey = HotkeyMonitor::instance().getHotkeyFor(key, Qt::MetaModifier);
24+ connect(hotkey, SIGNAL(pressed()), SLOT(forwardNumericHotkey()));
25+ }
26 }
27
28 void
29@@ -168,43 +173,18 @@
30 }
31
32 void
33-LauncherView::changeKeyboardShortcutsState(bool enabled)
34-{
35- /* We are going to connect 10 Hotkeys, but to make things simpler on the QML
36- side we want to have only one signal with the number of the item that needs to
37- be activated in response to the hotkey press.
38- So we connect all of them to a single slot where we emit a single signal with
39- an index based on which Hotkey was the sender. */
40- Qt::Key key = Qt::Key_0;
41- while (key <= Qt::Key_9) {
42- Hotkey *hotkey = HotkeyMonitor::instance().getHotkeyFor(key, Qt::MetaModifier);
43-
44- if (enabled) {
45- QObject::connect(hotkey, SIGNAL(pressed()), this, SLOT(forwardHotkey()));
46- } else {
47- QObject::disconnect(hotkey, SIGNAL(pressed()), this, SLOT(forwardHotkey()));
48- }
49- key = (Qt::Key) (key + 1);
50- }
51-}
52-
53-void
54-LauncherView::forwardHotkey()
55-{
56- Hotkey *hotkey = qobject_cast<Hotkey*>(sender());
57+LauncherView::forwardNumericHotkey()
58+{
59+ Hotkey* hotkey = qobject_cast<Hotkey*>(sender());
60 if (hotkey != NULL) {
61 /* Shortcuts from 1 to 9 should activate the items with index
62- from 0 to 8. Shortcut for 0 should activate item with index 10.
63+ from 0 to 8. Shortcut for 0 should activate item with index 9.
64 In other words, the indexes are activated in the same order as
65 the keys appear on a standard keyboard. */
66- if (hotkey->key() < Qt::Key_0 || hotkey->key() > Qt::Key_9) {
67- return;
68- }
69- int itemIndex = hotkey->key() - Qt::Key_0;
70- itemIndex = (itemIndex == 0) ? 9 : itemIndex - 1;
71-
72- if (itemIndex >= 0 && itemIndex <= 10) {
73- Q_EMIT keyboardShortcutPressed(itemIndex);
74+ Qt::Key key = hotkey->key();
75+ if (key >= Qt::Key_0 && key <= Qt::Key_9) {
76+ int index = (key - Qt::Key_0 + 9) % 10;
77+ Q_EMIT keyboardShortcutPressed(index);
78 }
79 }
80 }
81
82=== modified file 'launcher/app/launcherview.h'
83--- launcher/app/launcherview.h 2011-04-29 16:26:25 +0000
84+++ launcher/app/launcherview.h 2011-05-03 18:41:22 +0000
85@@ -57,11 +57,10 @@
86
87 private Q_SLOTS:
88 void setHotkeysForModifiers(Qt::KeyboardModifiers modifiers);
89- void forwardHotkey();
90+ void forwardNumericHotkey();
91 void updateSuperKeyMonitoring();
92 void updateSuperKeyHoldState();
93 void toggleDash();
94- void changeKeyboardShortcutsState(bool enabled);
95 void showCommandsPlace();
96 void showWorkspaceSwitcher();
97

Subscribers

People subscribed via source and target branches