Merge lp:~dyams/unity-2d/centralized-hotkeys into lp:~dyams/unity-2d/Shell-MultiMonitor

Proposed by Lohith D Shivamurthy
Status: Merged
Approved by: Lohith D Shivamurthy
Approved revision: 923
Merge reported by: Lohith D Shivamurthy
Merged at revision: not available
Proposed branch: lp:~dyams/unity-2d/centralized-hotkeys
Merge into: lp:~dyams/unity-2d/Shell-MultiMonitor
Diff against target: 282 lines (+109/-44)
6 files modified
libunity-2d-private/src/screeninfo.cpp (+8/-0)
libunity-2d-private/src/screeninfo.h (+1/-0)
shell/app/shelldeclarativeview.cpp (+20/-39)
shell/app/shelldeclarativeview.h (+6/-3)
shell/app/shellmanager.cpp (+71/-2)
shell/app/shellmanager.h (+3/-0)
To merge this branch: bzr merge lp:~dyams/unity-2d/centralized-hotkeys
Reviewer Review Type Date Requested Status
Albert Astals Cid (community) Approve
Review via email: mp+92936@code.launchpad.net

This proposal supersedes a proposal from 2012-02-14.

Description of the change

[shell][multimonitor] Move Hotkeys AltF1, AltF2 and Super[0..9] to shellmanager.cpp

To post a comment you must log in.
Revision history for this message
Albert Astals Cid (aacid) wrote : Posted in a previous version of this proposal

Why is this against lp:unity-2d instead of against lp:~dyams/unity-2d/Shell-MultiMonitor ?

Revision history for this message
Albert Astals Cid (aacid) wrote :

I'd prefer that "activeScreen" was called "cursorScreen" so it is clear it is returning the screen that contains the cursor

I don't like how we have the removeFocus and emitActivateShortcutPressed and emitNewInstanceShortcutPressed, this happens because you moved the logic of handling the keypress to ShellManager, for example ShellManager::onNumericHotkeyPressed does all the handling, i think you should change ShellManager::onNumericHotkeyPressed so it only does

void
ShellManager::onNumericHotkeyPressed()
{
    Hotkey* hotkey = qobject_cast<Hotkey*>(sender());
    if (hotkey) {
        d->m_activeShell = d->activeShell();
        if (d->m_activeShell) {
            d->m_activeShell->processNumericHotkey(hotkey);
       }
    }
}

and something similar for ShellManager::onAltF1Pressed(), this way you don't need to create functions in ShellDeclarativeView that the only thing they do is make some protected functions public.

review: Needs Fixing
919. By Lohith D Shivamurthy

process the numeric hotkeys in shelldeclarativeview.cpp

920. By Lohith D Shivamurthy

Rename activeScreen to cursorScreen

921. By Lohith D Shivamurthy

Remove ShellDeclarativeView::removeFocus, use toggleLauncher instead

Revision history for this message
Albert Astals Cid (aacid) wrote :

As discussed on irc, please rename m_activeShell to m_previousActiveShell

Also i found out that Alt+F1 toggling stops working after a while, this is what i do.
Kill unity-2d-shell
Start unity-2d-shell
Move cursor to primary screen
Press Alt+F1 -> launcher shows in primary screen
Move cursor to secondary screen
Press Alt+F1 -> launcher hides in primary screen and shows in secondary screen
Move cursor to primary screen
Press Alt+F1 -> launcher hides in secondary screen but DOES NOT show in primary screen

review: Needs Fixing
922. By Lohith D Shivamurthy

Rename m_activeShell to m_previousActiveShell

923. By Lohith D Shivamurthy

We don't need to remember previous active shell

Revision history for this message
Albert Astals Cid (aacid) wrote :

I still find a problem doing:
Kill unity-2d-shell
Start unity-2d-shell
Move cursor to primary screen
Press Alt+F1 -> launcher shows in primary screen
Quickly move cursor to secondary screen
Press Alt+F1 -> launcher hides in primary screen and shows in secondary screen
Quickly move cursor to primary screen
Press Alt+F1 -> launcher does not hide immediately in secondary screen (it hides after a while), it shows in primary screen but never hides

review: Needs Fixing
Revision history for this message
Albert Astals Cid (aacid) wrote :

Looks good. Please merge into lp:~dyams/unity-2d/Shell-MultiMonitor

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libunity-2d-private/src/screeninfo.cpp'
2--- libunity-2d-private/src/screeninfo.cpp 2012-02-01 16:28:13 +0000
3+++ libunity-2d-private/src/screeninfo.cpp 2012-02-14 12:30:20 +0000
4@@ -198,6 +198,14 @@
5 return m_corner;
6 }
7
8+int
9+ScreenInfo::cursorScreen()
10+{
11+ QDesktopWidget* desktop = QApplication::desktop();
12+ QPoint cursorPos(QCursor::pos());
13+ return desktop->screenNumber(cursorPos);
14+}
15+
16 void
17 ScreenInfo::setCorner(Corner corner)
18 {
19
20=== modified file 'libunity-2d-private/src/screeninfo.h'
21--- libunity-2d-private/src/screeninfo.h 2012-02-01 15:01:21 +0000
22+++ libunity-2d-private/src/screeninfo.h 2012-02-14 12:30:20 +0000
23@@ -39,6 +39,7 @@
24 int screen() const;
25 QWidget* widget() const;
26 Corner corner() const;
27+ static int cursorScreen();
28
29 /* Setters */
30 void setScreen(int screen);
31
32=== modified file 'shell/app/shelldeclarativeview.cpp'
33--- shell/app/shelldeclarativeview.cpp 2012-02-14 07:13:39 +0000
34+++ shell/app/shelldeclarativeview.cpp 2012-02-14 12:30:20 +0000
35@@ -74,22 +74,6 @@
36 connect(&launcher2dConfiguration(), SIGNAL(superKeyEnableChanged(bool)), SLOT(updateSuperKeyMonitoring()));
37 updateSuperKeyMonitoring();
38
39- /* Alt+F1 reveal the launcher and gives the keyboard focus to the Dash Button. */
40- Hotkey* altF1 = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_F1, Qt::AltModifier);
41- connect(altF1, SIGNAL(pressed()), SLOT(onAltF1Pressed()));
42-
43- /* Alt+F2 shows the dash with the commands lens activated. */
44- Hotkey* altF2 = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_F2, Qt::AltModifier);
45- connect(altF2, SIGNAL(pressed()), SLOT(showCommandsLens()));
46-
47- /* Super+{n} for 0 ≤ n ≤ 9 activates the item with index (n + 9) % 10. */
48- for (Qt::Key key = Qt::Key_0; key <= Qt::Key_9; key = (Qt::Key) (key + 1)) {
49- Hotkey* hotkey = HotkeyMonitor::instance().getHotkeyFor(key, Qt::MetaModifier);
50- connect(hotkey, SIGNAL(pressed()), SLOT(forwardNumericHotkey()));
51- hotkey = HotkeyMonitor::instance().getHotkeyFor(key, Qt::MetaModifier | Qt::ShiftModifier);
52- connect(hotkey, SIGNAL(pressed()), SLOT(forwardNumericHotkey()));
53- }
54-
55 connect(m_screenInfo, SIGNAL(availableGeometryChanged(QRect)), SLOT(updateShellPosition()));
56 updateShellPosition();
57 }
58@@ -267,7 +251,7 @@
59 }
60
61 void
62-ShellDeclarativeView::onAltF1Pressed()
63+ShellDeclarativeView::toggleLauncher()
64 {
65 if (!isActiveWindow()) {
66 forceActivateWindow();
67@@ -372,29 +356,26 @@
68 }
69
70 void
71-ShellDeclarativeView::forwardNumericHotkey()
72+ShellDeclarativeView::processNumericHotkey(Hotkey* hotkey)
73 {
74- Hotkey* hotkey = qobject_cast<Hotkey*>(sender());
75- if (hotkey != NULL) {
76- /* Shortcuts from 1 to 9 should activate the items with index
77- from 1 to 9 (index 0 being the so-called "BFB" or Dash launcher).
78- Shortcut for 0 should activate item with index 10.
79- In other words, the indexes are activated in the same order as
80- the keys appear on a standard keyboard. */
81- Qt::Key key = hotkey->key();
82- if (key >= Qt::Key_1 && key <= Qt::Key_9) {
83- int index = key - Qt::Key_0;
84- if (hotkey->modifiers() & Qt::ShiftModifier) {
85- Q_EMIT newInstanceShortcutPressed(index);
86- } else {
87- Q_EMIT activateShortcutPressed(index);
88- }
89- } else if (key == Qt::Key_0) {
90- if (hotkey->modifiers() & Qt::ShiftModifier) {
91- Q_EMIT newInstanceShortcutPressed(10);
92- } else {
93- Q_EMIT activateShortcutPressed(10);
94- }
95+ /* Shortcuts from 1 to 9 should activate the items with index
96+ from 1 to 9 (index 0 being the so-called "BFB" or Dash launcher).
97+ Shortcut for 0 should activate item with index 10.
98+ In other words, the indexes are activated in the same order as
99+ the keys appear on a standard keyboard. */
100+ Qt::Key key = hotkey->key();
101+ if (key >= Qt::Key_1 && key <= Qt::Key_9) {
102+ int index = key - Qt::Key_0;
103+ if (hotkey->modifiers() & Qt::ShiftModifier) {
104+ Q_EMIT newInstanceShortcutPressed(index);
105+ } else {
106+ Q_EMIT activateShortcutPressed(index);
107+ }
108+ } else if (key == Qt::Key_0) {
109+ if (hotkey->modifiers() & Qt::ShiftModifier) {
110+ Q_EMIT newInstanceShortcutPressed(10);
111+ } else {
112+ Q_EMIT activateShortcutPressed(10);
113 }
114 }
115 }
116
117=== modified file 'shell/app/shelldeclarativeview.h'
118--- shell/app/shelldeclarativeview.h 2012-02-14 07:13:39 +0000
119+++ shell/app/shelldeclarativeview.h 2012-02-14 12:30:20 +0000
120@@ -27,6 +27,7 @@
121 class LauncherClient;
122 class DashDBus;
123 class ScreenInfo;
124+class Hotkey;
125
126 class ShellDeclarativeView : public Unity2DDeclarativeView, public AbstractX11EventFilter
127 {
128@@ -82,6 +83,11 @@
129
130 virtual bool x11EventFilter(XEvent* event);
131
132+ void toggleLauncher();
133+ void showCommandsLens();
134+
135+ void processNumericHotkey(Hotkey*);
136+
137 Q_SIGNALS:
138 void dashActiveChanged(bool);
139 void dashModeChanged(DashMode);
140@@ -105,12 +111,9 @@
141 void updateSuperKeyMonitoring();
142 void updateSuperKeyHoldState();
143 void setHotkeysForModifiers(Qt::KeyboardModifiers modifiers);
144- void forwardNumericHotkey();
145 void ignoreSuperPress();
146
147 void toggleDash();
148- void showCommandsLens();
149- void onAltF1Pressed();
150
151 protected:
152 virtual void showEvent(QShowEvent *event);
153
154=== modified file 'shell/app/shellmanager.cpp'
155--- shell/app/shellmanager.cpp 2012-02-14 07:22:49 +0000
156+++ shell/app/shellmanager.cpp 2012-02-14 12:30:20 +0000
157@@ -30,6 +30,11 @@
158 #include <QDeclarativeContext>
159 #include <QAbstractEventDispatcher>
160
161+// libunity-2d-private
162+#include <hotkeymonitor.h>
163+#include <hotkey.h>
164+#include <screeninfo.h>
165+
166 // Local
167 #include "shelldeclarativeview.h"
168 #include "dashclient.h"
169@@ -53,6 +58,7 @@
170
171 ShellDeclarativeView* initShell(bool isTopLeft, int screen);
172 void updateScreenCount(int newCount);
173+ ShellDeclarativeView* activeShell() const;
174
175 ShellManager *q;
176 QList<ShellDeclarativeView *> m_viewList;
177@@ -61,7 +67,9 @@
178 QUrl m_sourceFileUrl;
179 };
180
181-ShellDeclarativeView* ShellManagerPrivate::initShell(bool isTopLeft, int screen)
182+
183+ShellDeclarativeView *
184+ShellManagerPrivate::initShell(bool isTopLeft, int screen)
185 {
186 const QStringList arguments = qApp->arguments();
187 ShellDeclarativeView * view = new ShellDeclarativeView(m_sourceFileUrl, isTopLeft, screen);
188@@ -107,7 +115,20 @@
189 return view;
190 }
191
192-void ShellManagerPrivate::updateScreenCount(int newCount)
193+ShellDeclarativeView *
194+ShellManagerPrivate::activeShell() const
195+{
196+ int cursorScreen = ScreenInfo::cursorScreen();
197+ Q_FOREACH(ShellDeclarativeView * shell, m_viewList) {
198+ if (shell->screenNumber() == cursorScreen) {
199+ return shell;
200+ }
201+ }
202+ return 0;
203+}
204+
205+void
206+ShellManagerPrivate::updateScreenCount(int newCount)
207 {
208 if (newCount > 0) {
209 QDesktopWidget* desktop = QApplication::desktop();
210@@ -168,6 +189,22 @@
211 d->updateScreenCount(desktop->screenCount());
212
213 connect(desktop, SIGNAL(screenCountChanged(int)), SLOT(onScreenCountChanged(int)));
214+
215+ /* Alt+F1 reveal the launcher and gives the keyboard focus to the Dash Button. */
216+ Hotkey* altF1 = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_F1, Qt::AltModifier);
217+ connect(altF1, SIGNAL(pressed()), SLOT(onAltF1Pressed()));
218+
219+ /* Alt+F2 shows the dash with the commands lens activated. */
220+ Hotkey* altF2 = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_F2, Qt::AltModifier);
221+ connect(altF2, SIGNAL(pressed()), SLOT(onAltF2Pressed()));
222+
223+ /* Super+{n} for 0 ≤ n ≤ 9 activates the item with index (n + 9) % 10. */
224+ for (Qt::Key key = Qt::Key_0; key <= Qt::Key_9; key = (Qt::Key) (key + 1)) {
225+ Hotkey* hotkey = HotkeyMonitor::instance().getHotkeyFor(key, Qt::MetaModifier);
226+ connect(hotkey, SIGNAL(pressed()), SLOT(onNumericHotkeyPressed()));
227+ hotkey = HotkeyMonitor::instance().getHotkeyFor(key, Qt::MetaModifier | Qt::ShiftModifier);
228+ connect(hotkey, SIGNAL(pressed()), SLOT(onNumericHotkeyPressed()));
229+ }
230 }
231
232 ShellManager::~ShellManager()
233@@ -181,3 +218,35 @@
234 {
235 d->updateScreenCount(newCount);
236 }
237+
238+/*------------------ Hotkeys Handling -----------------------*/
239+
240+void
241+ShellManager::onAltF1Pressed()
242+{
243+ ShellDeclarativeView * activeShell = d->activeShell();
244+ if (activeShell) {
245+ activeShell->toggleLauncher();
246+ }
247+}
248+
249+void
250+ShellManager::onAltF2Pressed()
251+{
252+ ShellDeclarativeView * activeShell = d->activeShell();
253+ if (activeShell) {
254+ activeShell->showCommandsLens();
255+ }
256+}
257+
258+void
259+ShellManager::onNumericHotkeyPressed()
260+{
261+ Hotkey* hotkey = qobject_cast<Hotkey*>(sender());
262+ if (hotkey) {
263+ ShellDeclarativeView * activeShell = d->activeShell();
264+ if (activeShell) {
265+ activeShell->processNumericHotkey(hotkey);
266+ }
267+ }
268+}
269
270=== modified file 'shell/app/shellmanager.h'
271--- shell/app/shellmanager.h 2012-02-14 07:22:49 +0000
272+++ shell/app/shellmanager.h 2012-02-14 12:30:20 +0000
273@@ -32,6 +32,9 @@
274
275 private Q_SLOTS:
276 void onScreenCountChanged(int);
277+ void onAltF1Pressed();
278+ void onAltF2Pressed();
279+ void onNumericHotkeyPressed();
280
281 private:
282 Q_DISABLE_COPY(ShellManager)

Subscribers

People subscribed via source and target branches

to all changes: