Merge lp:~dyams/unity-2d/super-plus-keypad-key-enabled into lp:unity-2d

Proposed by Lohith D Shivamurthy
Status: Rejected
Rejected by: Gerry Boland
Proposed branch: lp:~dyams/unity-2d/super-plus-keypad-key-enabled
Merge into: lp:unity-2d
Diff against target: 206 lines (+75/-33)
5 files modified
launcher/app/launcherview.cpp (+43/-11)
libunity-2d-private/src/hotkey.cpp (+24/-18)
libunity-2d-private/src/hotkey.h (+5/-1)
libunity-2d-private/src/hotkeymonitor.cpp (+2/-2)
libunity-2d-private/src/hotkeymonitor.h (+1/-1)
To merge this branch: bzr merge lp:~dyams/unity-2d/super-plus-keypad-key-enabled
Reviewer Review Type Date Requested Status
Gerry Boland (community) Disapprove
Florian Boucault (community) Needs Fixing
Review via email: mp+82664@code.launchpad.net

Description of the change

Qt won't distinguish between keys[0-9] below the Function-keys and keys[0-9] on the keypad.
X11 has separate keycodes for them.
You may be interested to check <X11/keysymdef.h>

To post a comment you must log in.
Revision history for this message
Florian Boucault (fboucault) wrote :

The merge request misses a 'description'.

review: Needs Fixing
Revision history for this message
Lohith D Shivamurthy (dyams) wrote :

> The merge request misses a 'description'.

Description added

Revision history for this message
Gerry Boland (gerboland) wrote :

Hi Lohith
sorry about the delay. Can you please get clarification from Design for this?

We have a document which details all keyboard shortcuts, these are not mentioned. Would be good to confirm.

review: Needs Information
Revision history for this message
Gerry Boland (gerboland) wrote :

To update the info on this MR, Lohith consulted with Design about this and was told that this is incorrect. Marking this MR as Rejected.

review: Disapprove

Unmerged revisions

784. By Lohith D Shivamurthy

[launcher] Tests added

783. By Lohith D Shivamurthy

[launcher] {super-key + numbers on the keypad} combination is enabled to show/launch the window selected

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-11-18 10:15:49 +0000
3+++ launcher/app/launcherview.cpp 2011-11-18 10:44:35 +0000
4@@ -91,6 +91,18 @@
5 hotkey = HotkeyMonitor::instance().getHotkeyFor(key, Qt::MetaModifier | Qt::ShiftModifier);
6 connect(hotkey, SIGNAL(pressed()), SLOT(forwardNumericHotkey()));
7 }
8+
9+ /* Super+{n} for 0 ≤ n ≤ 9 activates the item with index (n + 9) % 10.*/
10+ /* Qt won't distinguish between keys[0-9] below the Functionkeys and keypad keys[0-9] on the Keypad.
11+ X11 has separate keycodes for them.
12+ You may please also check <X11/keysymdef.h>
13+ */
14+ for (Qt::Key key = (Qt::Key)(0xffb0); key <= (Qt::Key)(0xffb9); key = (Qt::Key) (key + 1)) {
15+ Hotkey* hotkey = HotkeyMonitor::instance().getHotkeyFor((Qt::Key)(key), Qt::MetaModifier, true);
16+ connect(hotkey, SIGNAL(pressed()), SLOT(forwardNumericHotkey()));
17+ hotkey = HotkeyMonitor::instance().getHotkeyFor((Qt::Key)(key), Qt::MetaModifier | Qt::ShiftModifier, true);
18+ connect(hotkey, SIGNAL(pressed()), SLOT(forwardNumericHotkey()));
19+ }
20 }
21
22 LauncherView::~LauncherView()
23@@ -207,18 +219,38 @@
24 In other words, the indexes are activated in the same order as
25 the keys appear on a standard keyboard. */
26 Qt::Key key = hotkey->key();
27- if (key >= Qt::Key_1 && key <= Qt::Key_9) {
28- int index = key - Qt::Key_0;
29- if (hotkey->modifiers() & Qt::ShiftModifier) {
30- Q_EMIT newInstanceShortcutPressed(index);
31- } else {
32- Q_EMIT activateShortcutPressed(index);
33+
34+ if (hotkey->isX11Keysym()) {
35+ if (key >= 0xffb1 && key <= 0xffb9) {
36+ int index = key - 0xffb0;
37+ if (hotkey->modifiers() & Qt::ShiftModifier) {
38+ Q_EMIT newInstanceShortcutPressed(index);
39+ } else {
40+ Q_EMIT activateShortcutPressed(index);
41+ }
42+ } else if (key == 0xffb0) {
43+ if (hotkey->modifiers() & Qt::ShiftModifier) {
44+ Q_EMIT newInstanceShortcutPressed(10);
45+ } else {
46+ Q_EMIT activateShortcutPressed(10);
47+ }
48 }
49- } else if (key == Qt::Key_0) {
50- if (hotkey->modifiers() & Qt::ShiftModifier) {
51- Q_EMIT newInstanceShortcutPressed(10);
52- } else {
53- Q_EMIT activateShortcutPressed(10);
54+ }
55+
56+ else {
57+ if (key >= Qt::Key_1 && key <= Qt::Key_9) {
58+ int index = key - Qt::Key_0;
59+ if (hotkey->modifiers() & Qt::ShiftModifier) {
60+ Q_EMIT newInstanceShortcutPressed(index);
61+ } else {
62+ Q_EMIT activateShortcutPressed(index);
63+ }
64+ } else if (key == Qt::Key_0) {
65+ if (hotkey->modifiers() & Qt::ShiftModifier) {
66+ Q_EMIT newInstanceShortcutPressed(10);
67+ } else {
68+ Q_EMIT activateShortcutPressed(10);
69+ }
70 }
71 }
72 }
73
74=== modified file 'libunity-2d-private/src/hotkey.cpp'
75--- libunity-2d-private/src/hotkey.cpp 2011-05-03 15:28:49 +0000
76+++ libunity-2d-private/src/hotkey.cpp 2011-11-18 10:44:35 +0000
77@@ -45,9 +45,9 @@
78 return 0;
79 }
80
81-Hotkey::Hotkey(Qt::Key key, Qt::KeyboardModifiers modifiers, QObject *parent) :
82+Hotkey::Hotkey(Qt::Key key, Qt::KeyboardModifiers modifiers, QObject *parent, bool isX11keysym) :
83 QObject(parent), m_connections(0),
84- m_key(key), m_modifiers(modifiers),
85+ m_key(key), m_modifiers(modifiers), m_isX11keysym(isX11keysym),
86 m_x11key(0), m_x11modifiers(0)
87 {
88 /* Translate the QT modifiers to X11 modifiers */
89@@ -65,23 +65,29 @@
90 m_x11modifiers |= Mod4Mask;
91 }
92
93- /* Translate the QT key to X11 keycode */
94-
95- /* QKeySequence can be used to translate a Qt::Key in a format that is
96- understood by XStringToKeysym if the sequence is composed only by the key */
97- QString keyString = QKeySequence(key).toString();
98- KeySym keysym = XStringToKeysym(keyString.toLatin1().data());
99- if (keysym == NoSymbol) {
100- /* XStringToKeysym doesn’t work well with exotic characters (such as
101- 'É'). Note that this fallback code path looks much simpler but doesn’t
102- work for special keys such as the function keys (e.g. F1), which is
103- why the translation with XStringToKeysym is attempted first. */
104- keysym = (ushort) key;
105+ if (isX11keysym) {
106+ m_x11key = XKeysymToKeycode(QX11Info::display(), key);
107 }
108- m_x11key = XKeysymToKeycode(QX11Info::display(), keysym);
109- if (m_x11key == 0) {
110- UQ_WARNING << "Could not get keycode for keysym" << keysym
111- << "(" << keyString << ")";
112+ else {
113+ /* Translate the QT key to X11 keycode */
114+
115+ /* QKeySequence can be used to translate a Qt::Key in a format that is
116+ understood by XStringToKeysym if the sequence is composed only by the key */
117+ QString keyString = QKeySequence(key).toString();
118+ KeySym keysym = XStringToKeysym(keyString.toLatin1().data());
119+
120+ if (keysym == NoSymbol) {
121+ /* XStringToKeysym doesn’t work well with exotic characters (such as
122+ 'É'). Note that this fallback code path looks much simpler but doesn’t
123+ work for special keys such as the function keys (e.g. F1), which is
124+ why the translation with XStringToKeysym is attempted first. */
125+ keysym = (ushort) key;
126+ }
127+ m_x11key = XKeysymToKeycode(QX11Info::display(), keysym);
128+ if (m_x11key == 0) {
129+ UQ_WARNING << "Could not get keycode for keysym" << keysym
130+ << "(" << keyString << ")";
131+ }
132 }
133 }
134
135
136=== modified file 'libunity-2d-private/src/hotkey.h'
137--- libunity-2d-private/src/hotkey.h 2011-02-23 17:03:50 +0000
138+++ libunity-2d-private/src/hotkey.h 2011-11-18 10:44:35 +0000
139@@ -22,6 +22,8 @@
140
141 #include <QObject>
142
143+typedef unsigned long KeySym;
144+
145 class Hotkey : public QObject
146 {
147 friend class HotkeyMonitor;
148@@ -33,6 +35,7 @@
149 public:
150 Qt::Key key() const { return m_key; }
151 Qt::KeyboardModifiers modifiers() const { return m_modifiers; }
152+ bool isX11Keysym() const { return m_isX11keysym; }
153
154 Q_SIGNALS:
155 void keyChanged(Qt::Key key);
156@@ -45,13 +48,14 @@
157 virtual void disconnectNotify(const char * signal);
158
159 private:
160- Hotkey(Qt::Key key, Qt::KeyboardModifiers modifiers, QObject *parent);
161+ Hotkey(Qt::Key key, Qt::KeyboardModifiers modifiers, QObject *parent, bool isX11keysym = false);
162 bool processNativeEvent(uint x11Keycode, uint x11Modifiers, bool isPressEvent);
163
164 private:
165 uint m_connections;
166 Qt::Key m_key;
167 Qt::KeyboardModifiers m_modifiers;
168+ bool m_isX11keysym;
169 uint m_x11key;
170 uint m_x11modifiers;
171 };
172
173=== modified file 'libunity-2d-private/src/hotkeymonitor.cpp'
174--- libunity-2d-private/src/hotkeymonitor.cpp 2011-10-14 07:07:09 +0000
175+++ libunity-2d-private/src/hotkeymonitor.cpp 2011-11-18 10:44:35 +0000
176@@ -64,7 +64,7 @@
177
178
179 Hotkey*
180-HotkeyMonitor::getHotkeyFor(Qt::Key key, Qt::KeyboardModifiers modifiers)
181+HotkeyMonitor::getHotkeyFor(Qt::Key key, Qt::KeyboardModifiers modifiers, bool isX11keysym)
182 {
183 Q_FOREACH(Hotkey* currentHotkey, m_hotkeys) {
184 if (currentHotkey->key() == key &&
185@@ -73,7 +73,7 @@
186 }
187 }
188
189- Hotkey *hotkey = new Hotkey(key, modifiers, this);
190+ Hotkey *hotkey = new Hotkey(key, modifiers, this, isX11keysym);
191 m_hotkeys.append(hotkey);
192 return hotkey;
193 }
194
195=== modified file 'libunity-2d-private/src/hotkeymonitor.h'
196--- libunity-2d-private/src/hotkeymonitor.h 2011-10-14 07:07:09 +0000
197+++ libunity-2d-private/src/hotkeymonitor.h 2011-11-18 10:44:35 +0000
198@@ -33,7 +33,7 @@
199 static HotkeyMonitor& instance();
200 ~HotkeyMonitor();
201
202- Hotkey* getHotkeyFor(Qt::Key key, Qt::KeyboardModifiers modifiers);
203+ Hotkey* getHotkeyFor(Qt::Key key, Qt::KeyboardModifiers modifiers, bool isX11keysym = false);
204
205 void disableModifiers(Qt::KeyboardModifiers modifiers);
206 void enableModifiers(Qt::KeyboardModifiers modifiers);

Subscribers

People subscribed via source and target branches