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
=== modified file 'launcher/app/launcherview.cpp'
--- launcher/app/launcherview.cpp 2011-04-29 16:26:25 +0000
+++ launcher/app/launcherview.cpp 2011-05-03 18:41:22 +0000
@@ -65,7 +65,6 @@
65 m_superKeyHoldTimer.setInterval(KEY_HOLD_THRESHOLD);65 m_superKeyHoldTimer.setInterval(KEY_HOLD_THRESHOLD);
66 connect(&m_superKeyHoldTimer, SIGNAL(timeout()), SLOT(updateSuperKeyHoldState()));66 connect(&m_superKeyHoldTimer, SIGNAL(timeout()), SLOT(updateSuperKeyHoldState()));
67 connect(this, SIGNAL(superKeyTapped()), SLOT(toggleDash()));67 connect(this, SIGNAL(superKeyTapped()), SLOT(toggleDash()));
68 connect(this, SIGNAL(superKeyHeldChanged(bool)), SLOT(changeKeyboardShortcutsState(bool)));
6968
70 m_enableSuperKey.setKey("/desktop/unity-2d/launcher/super_key_enable");69 m_enableSuperKey.setKey("/desktop/unity-2d/launcher/super_key_enable");
71 connect(&m_enableSuperKey, SIGNAL(valueChanged()), SLOT(updateSuperKeyMonitoring()));70 connect(&m_enableSuperKey, SIGNAL(valueChanged()), SLOT(updateSuperKeyMonitoring()));
@@ -79,9 +78,15 @@
79 Hotkey* altF2 = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_F2, Qt::AltModifier);78 Hotkey* altF2 = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_F2, Qt::AltModifier);
80 connect(altF2, SIGNAL(pressed()), SLOT(showCommandsPlace()));79 connect(altF2, SIGNAL(pressed()), SLOT(showCommandsPlace()));
8180
82 /* Super+s activated the workspaces switcher. */81 /* Super+s activates the workspaces switcher. */
83 Hotkey* superS = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_S, Qt::MetaModifier);82 Hotkey* superS = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_S, Qt::MetaModifier);
84 connect(superS, SIGNAL(pressed()), SLOT(showWorkspaceSwitcher()));83 connect(superS, SIGNAL(pressed()), SLOT(showWorkspaceSwitcher()));
84
85 /* Super+{n} for 0 ≤ n ≤ 9 activates the item with index (n + 9) % 10. */
86 for (Qt::Key key = Qt::Key_0; key <= Qt::Key_9; key = (Qt::Key) (key + 1)) {
87 Hotkey* hotkey = HotkeyMonitor::instance().getHotkeyFor(key, Qt::MetaModifier);
88 connect(hotkey, SIGNAL(pressed()), SLOT(forwardNumericHotkey()));
89 }
85}90}
8691
87void92void
@@ -168,43 +173,18 @@
168}173}
169174
170void175void
171LauncherView::changeKeyboardShortcutsState(bool enabled)176LauncherView::forwardNumericHotkey()
172{177{
173 /* We are going to connect 10 Hotkeys, but to make things simpler on the QML178 Hotkey* hotkey = qobject_cast<Hotkey*>(sender());
174 side we want to have only one signal with the number of the item that needs to
175 be activated in response to the hotkey press.
176 So we connect all of them to a single slot where we emit a single signal with
177 an index based on which Hotkey was the sender. */
178 Qt::Key key = Qt::Key_0;
179 while (key <= Qt::Key_9) {
180 Hotkey *hotkey = HotkeyMonitor::instance().getHotkeyFor(key, Qt::MetaModifier);
181
182 if (enabled) {
183 QObject::connect(hotkey, SIGNAL(pressed()), this, SLOT(forwardHotkey()));
184 } else {
185 QObject::disconnect(hotkey, SIGNAL(pressed()), this, SLOT(forwardHotkey()));
186 }
187 key = (Qt::Key) (key + 1);
188 }
189}
190
191void
192LauncherView::forwardHotkey()
193{
194 Hotkey *hotkey = qobject_cast<Hotkey*>(sender());
195 if (hotkey != NULL) {179 if (hotkey != NULL) {
196 /* Shortcuts from 1 to 9 should activate the items with index180 /* Shortcuts from 1 to 9 should activate the items with index
197 from 0 to 8. Shortcut for 0 should activate item with index 10.181 from 0 to 8. Shortcut for 0 should activate item with index 9.
198 In other words, the indexes are activated in the same order as182 In other words, the indexes are activated in the same order as
199 the keys appear on a standard keyboard. */183 the keys appear on a standard keyboard. */
200 if (hotkey->key() < Qt::Key_0 || hotkey->key() > Qt::Key_9) {184 Qt::Key key = hotkey->key();
201 return;185 if (key >= Qt::Key_0 && key <= Qt::Key_9) {
202 }186 int index = (key - Qt::Key_0 + 9) % 10;
203 int itemIndex = hotkey->key() - Qt::Key_0;187 Q_EMIT keyboardShortcutPressed(index);
204 itemIndex = (itemIndex == 0) ? 9 : itemIndex - 1;
205
206 if (itemIndex >= 0 && itemIndex <= 10) {
207 Q_EMIT keyboardShortcutPressed(itemIndex);
208 }188 }
209 }189 }
210}190}
211191
=== modified file 'launcher/app/launcherview.h'
--- launcher/app/launcherview.h 2011-04-29 16:26:25 +0000
+++ launcher/app/launcherview.h 2011-05-03 18:41:22 +0000
@@ -57,11 +57,10 @@
5757
58private Q_SLOTS:58private Q_SLOTS:
59 void setHotkeysForModifiers(Qt::KeyboardModifiers modifiers);59 void setHotkeysForModifiers(Qt::KeyboardModifiers modifiers);
60 void forwardHotkey();60 void forwardNumericHotkey();
61 void updateSuperKeyMonitoring();61 void updateSuperKeyMonitoring();
62 void updateSuperKeyHoldState();62 void updateSuperKeyHoldState();
63 void toggleDash();63 void toggleDash();
64 void changeKeyboardShortcutsState(bool enabled);
65 void showCommandsPlace();64 void showCommandsPlace();
66 void showWorkspaceSwitcher();65 void showWorkspaceSwitcher();
6766

Subscribers

People subscribed via source and target branches