Merge lp:~uriboni/unity-2d/launcher-keyboard-shortcuts into lp:unity-2d/3.0
- launcher-keyboard-shortcuts
- Merge into natty
Proposed by
Ugo Riboni
Status: | Merged |
---|---|
Merged at revision: | 407 |
Proposed branch: | lp:~uriboni/unity-2d/launcher-keyboard-shortcuts |
Merge into: | lp:unity-2d/3.0 |
Diff against target: |
975 lines (+458/-279) 18 files modified
launcher/LauncherItem.qml (+18/-0) launcher/LauncherList.qml (+15/-0) launcher/app/CMakeLists.txt (+3/-0) launcher/app/launcher.cpp (+3/-1) launcher/app/launcherview.cpp (+83/-1) launcher/app/launcherview.h (+17/-1) launcher/tests/CMakeLists.txt (+1/-0) libunity-2d-private/src/CMakeLists.txt (+2/-0) libunity-2d-private/src/hotkey.cpp (+101/-0) libunity-2d-private/src/hotkey.h (+59/-0) libunity-2d-private/src/hotkeymonitor.cpp (+105/-0) libunity-2d-private/src/hotkeymonitor.h (+50/-0) places/app/CMakeLists.txt (+0/-4) places/app/keymonitor.cpp (+0/-62) places/app/keymonitor.h (+0/-42) places/app/places.cpp (+1/-34) places/app/superkeymonitor.cpp (+0/-79) places/app/superkeymonitor.h (+0/-55) |
To merge this branch: | bzr merge lp:~uriboni/unity-2d/launcher-keyboard-shortcuts |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Florian Boucault | Pending | ||
Review via email: mp+51046@code.launchpad.net |
Commit message
[launcher] Make the first 10 items in the launcher able to be activated via Super+n, and show the launcher when Super is pressed if hidden.
Description of the change
Make the first 10 items in the launcher able to be activated via Super+n, and show the launcher when Super is pressed if hidden.
Please note that this branch has already merged into it the following branches:
lp:~fboucault/unity-2d/more_robust_intellihide and
lp:~fboucault/unity-2d/launcher_four_fingers_drag
To post a comment you must log in.
Revision history for this message
Florian Boucault (fboucault) wrote : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'launcher/LauncherItem.qml' | |||
2 | --- launcher/LauncherItem.qml 2011-02-18 14:02:46 +0000 | |||
3 | +++ launcher/LauncherItem.qml 2011-02-24 00:23:17 +0000 | |||
4 | @@ -53,6 +53,9 @@ | |||
5 | 53 | property bool backgroundFromIcon | 53 | property bool backgroundFromIcon |
6 | 54 | property color defaultBackgroundColor: "#333333" | 54 | property color defaultBackgroundColor: "#333333" |
7 | 55 | 55 | ||
8 | 56 | property alias shortcutVisible: shortcut.visible | ||
9 | 57 | property alias shortcutText: shortcutText.text | ||
10 | 58 | |||
11 | 56 | property int pips: 0 | 59 | property int pips: 0 |
12 | 57 | property string pipSource: engineBaseUrl + "artwork/launcher_" + | 60 | property string pipSource: engineBaseUrl + "artwork/launcher_" + |
13 | 58 | ((pips <= 1) ? "arrow" : "pip") + "_ltr.png" | 61 | ((pips <= 1) ? "arrow" : "pip") + "_ltr.png" |
14 | @@ -263,6 +266,21 @@ | |||
15 | 263 | } | 266 | } |
16 | 264 | } | 267 | } |
17 | 265 | 268 | ||
18 | 269 | Rectangle { | ||
19 | 270 | id: shortcut | ||
20 | 271 | anchors.centerIn: parent | ||
21 | 272 | color: "#B3000000" // 0.7 opacity on black | ||
22 | 273 | radius: 2 | ||
23 | 274 | width: 22 | ||
24 | 275 | height: 22 | ||
25 | 276 | |||
26 | 277 | Text { | ||
27 | 278 | id: shortcutText | ||
28 | 279 | anchors.centerIn: parent | ||
29 | 280 | color: "white" | ||
30 | 281 | } | ||
31 | 282 | } | ||
32 | 283 | |||
33 | 266 | Image { | 284 | Image { |
34 | 267 | id: emblemIcon | 285 | id: emblemIcon |
35 | 268 | anchors.left: parent.left | 286 | anchors.left: parent.left |
36 | 269 | 287 | ||
37 | === modified file 'launcher/LauncherList.qml' | |||
38 | --- launcher/LauncherList.qml 2011-02-21 10:23:45 +0000 | |||
39 | +++ launcher/LauncherList.qml 2011-02-24 00:23:17 +0000 | |||
40 | @@ -31,6 +31,10 @@ | |||
41 | 31 | emblem: (noOverlays && item.emblem) ? "image://icons/" + item.emblem : "" | 31 | emblem: (noOverlays && item.emblem) ? "image://icons/" + item.emblem : "" |
42 | 32 | emblemVisible: (noOverlays) ? false : item.emblemVisible | 32 | emblemVisible: (noOverlays) ? false : item.emblemVisible |
43 | 33 | 33 | ||
44 | 34 | shortcutVisible: item.toString().indexOf("LauncherApplication") == 0 && | ||
45 | 35 | index <= 9 && launcherView.superKeyPressed | ||
46 | 36 | shortcutText: index + 1 | ||
47 | 37 | |||
48 | 34 | /* Best way I could find to check if the item is an application or the | 38 | /* Best way I could find to check if the item is an application or the |
49 | 35 | workspaces switcher. There may be something cleaner and better. */ | 39 | workspaces switcher. There may be something cleaner and better. */ |
50 | 36 | backgroundFromIcon: item.toString().indexOf("LauncherApplication") == 0 || | 40 | backgroundFromIcon: item.toString().indexOf("LauncherApplication") == 0 || |
51 | @@ -121,5 +125,16 @@ | |||
52 | 121 | /* Not all items are applications. */ | 125 | /* Not all items are applications. */ |
53 | 122 | ignoreUnknownSignals: true | 126 | ignoreUnknownSignals: true |
54 | 123 | } | 127 | } |
55 | 128 | |||
56 | 129 | Connections { | ||
57 | 130 | target: launcherView | ||
58 | 131 | onKeyboardShortcutPressed: { | ||
59 | 132 | /* Only applications can be launched by keyboard shortcuts */ | ||
60 | 133 | if (item.toString().indexOf("LauncherApplication") == 0 && index == itemIndex) { | ||
61 | 134 | item.menu.hide() | ||
62 | 135 | item.activate() | ||
63 | 136 | } | ||
64 | 137 | } | ||
65 | 138 | } | ||
66 | 124 | } | 139 | } |
67 | 125 | } | 140 | } |
68 | 126 | 141 | ||
69 | === modified file 'launcher/app/CMakeLists.txt' | |||
70 | --- launcher/app/CMakeLists.txt 2011-02-16 02:21:24 +0000 | |||
71 | +++ launcher/app/CMakeLists.txt 2011-02-24 00:23:17 +0000 | |||
72 | @@ -2,6 +2,7 @@ | |||
73 | 2 | pkg_check_modules(GTK REQUIRED gtk+-2.0) | 2 | pkg_check_modules(GTK REQUIRED gtk+-2.0) |
74 | 3 | pkg_check_modules(X11 REQUIRED x11) | 3 | pkg_check_modules(X11 REQUIRED x11) |
75 | 4 | pkg_check_modules(GEIS REQUIRED libutouch-geis) | 4 | pkg_check_modules(GEIS REQUIRED libutouch-geis) |
76 | 5 | pkg_check_modules(QTGCONF REQUIRED libqtgconf) | ||
77 | 5 | 6 | ||
78 | 6 | # Sources | 7 | # Sources |
79 | 7 | set(launcher_SRCS | 8 | set(launcher_SRCS |
80 | @@ -34,6 +35,7 @@ | |||
81 | 34 | ${GTK_INCLUDE_DIRS} | 35 | ${GTK_INCLUDE_DIRS} |
82 | 35 | ${X11_INCLUDE_DIRS} | 36 | ${X11_INCLUDE_DIRS} |
83 | 36 | ${GEIS_INCLUDE_DIRS} | 37 | ${GEIS_INCLUDE_DIRS} |
84 | 38 | ${QTGCONF_INCLUDE_DIRS} | ||
85 | 37 | ${libunity-2d-private_SOURCE_DIR}/src | 39 | ${libunity-2d-private_SOURCE_DIR}/src |
86 | 38 | ) | 40 | ) |
87 | 39 | 41 | ||
88 | @@ -45,6 +47,7 @@ | |||
89 | 45 | ${GTK_LDFLAGS} | 47 | ${GTK_LDFLAGS} |
90 | 46 | ${X11_LDFLAGS} | 48 | ${X11_LDFLAGS} |
91 | 47 | ${GEIS_LDFLAGS} | 49 | ${GEIS_LDFLAGS} |
92 | 50 | ${QTGCONF_LDFLAGS} | ||
93 | 48 | unity-2d-private | 51 | unity-2d-private |
94 | 49 | ) | 52 | ) |
95 | 50 | 53 | ||
96 | 51 | 54 | ||
97 | === modified file 'launcher/app/launcher.cpp' | |||
98 | --- launcher/app/launcher.cpp 2011-02-22 16:54:40 +0000 | |||
99 | +++ launcher/app/launcher.cpp 2011-02-24 00:23:17 +0000 | |||
100 | @@ -29,6 +29,8 @@ | |||
101 | 29 | #include <QDeclarativeContext> | 29 | #include <QDeclarativeContext> |
102 | 30 | #include <QDir> | 30 | #include <QDir> |
103 | 31 | 31 | ||
104 | 32 | #include <unity2dapplication.h> | ||
105 | 33 | |||
106 | 32 | #include "config.h" | 34 | #include "config.h" |
107 | 33 | #include "launcherview.h" | 35 | #include "launcherview.h" |
108 | 34 | #include "launchercontrol.h" | 36 | #include "launchercontrol.h" |
109 | @@ -53,7 +55,7 @@ | |||
110 | 53 | */ | 55 | */ |
111 | 54 | QApplication::setGraphicsSystem("raster"); | 56 | QApplication::setGraphicsSystem("raster"); |
112 | 55 | QApplication::setColorSpec(QApplication::ManyColor); | 57 | QApplication::setColorSpec(QApplication::ManyColor); |
114 | 56 | QApplication application(argc, argv); | 58 | Unity2dApplication application(argc, argv); |
115 | 57 | 59 | ||
116 | 58 | GnomeSessionClient client(INSTALL_PREFIX "/share/applications/unity-2d-launcher.desktop"); | 60 | GnomeSessionClient client(INSTALL_PREFIX "/share/applications/unity-2d-launcher.desktop"); |
117 | 59 | client.connectToSessionManager(); | 61 | client.connectToSessionManager(); |
118 | 60 | 62 | ||
119 | === modified file 'launcher/app/launcherview.cpp' | |||
120 | --- launcher/app/launcherview.cpp 2011-02-16 11:11:46 +0000 | |||
121 | +++ launcher/app/launcherview.cpp 2011-02-24 00:23:17 +0000 | |||
122 | @@ -35,13 +35,95 @@ | |||
123 | 35 | #include <X11/Xatom.h> | 35 | #include <X11/Xatom.h> |
124 | 36 | 36 | ||
125 | 37 | #include "dragdropevent.h" | 37 | #include "dragdropevent.h" |
126 | 38 | #include <keyboardmodifiersmonitor.h> | ||
127 | 39 | #include <hotkey.h> | ||
128 | 40 | #include <hotkeymonitor.h> | ||
129 | 38 | 41 | ||
130 | 39 | LauncherView::LauncherView() : | 42 | LauncherView::LauncherView() : |
131 | 40 | QDeclarativeView(), m_resizing(false), m_reserved(false), | 43 | QDeclarativeView(), m_resizing(false), m_reserved(false), |
132 | 41 | m_dndCurrentLauncherItem(NULL), m_dndCurrentLauncherItemAccepted(false), | 44 | m_dndCurrentLauncherItem(NULL), m_dndCurrentLauncherItemAccepted(false), |
134 | 42 | m_dndAccepted(false) | 45 | m_dndAccepted(false), m_superKeyPressed(false) |
135 | 43 | { | 46 | { |
136 | 44 | setAcceptDrops(true); | 47 | setAcceptDrops(true); |
137 | 48 | |||
138 | 49 | m_enableSuperKey.setKey("/desktop/unity/launcher/super_key_enable"); | ||
139 | 50 | QObject::connect(&m_enableSuperKey, SIGNAL(valueChanged()), | ||
140 | 51 | this, SLOT(updateSuperKeyMonitoring())); | ||
141 | 52 | updateSuperKeyMonitoring(); | ||
142 | 53 | } | ||
143 | 54 | |||
144 | 55 | void | ||
145 | 56 | LauncherView::updateSuperKeyMonitoring() | ||
146 | 57 | { | ||
147 | 58 | KeyboardModifiersMonitor *modifiersMonitor = KeyboardModifiersMonitor::instance(); | ||
148 | 59 | |||
149 | 60 | QVariant value = m_enableSuperKey.getValue(); | ||
150 | 61 | if (!value.isValid() || value.toBool() == true) { | ||
151 | 62 | QObject::connect(modifiersMonitor, | ||
152 | 63 | SIGNAL(keyboardModifiersChanged(Qt::KeyboardModifiers)), | ||
153 | 64 | this, SLOT(setHotkeysForModifiers(Qt::KeyboardModifiers))); | ||
154 | 65 | setHotkeysForModifiers(modifiersMonitor->keyboardModifiers()); | ||
155 | 66 | } else { | ||
156 | 67 | QObject::disconnect(modifiersMonitor, | ||
157 | 68 | SIGNAL(keyboardModifiersChanged(Qt::KeyboardModifiers)), | ||
158 | 69 | this, SLOT(setHotkeysForModifiers(Qt::KeyboardModifiers))); | ||
159 | 70 | m_superKeyPressed = false; | ||
160 | 71 | Q_EMIT superKeyPressedChanged(false); | ||
161 | 72 | changeKeyboardShortcutsState(false); | ||
162 | 73 | } | ||
163 | 74 | } | ||
164 | 75 | |||
165 | 76 | void | ||
166 | 77 | LauncherView::setHotkeysForModifiers(Qt::KeyboardModifiers modifiers) | ||
167 | 78 | { | ||
168 | 79 | /* This is the new new state of the Super key (AKA Meta key), while | ||
169 | 80 | m_superKeyPressed is the previous state of the key at the last modifiers change. */ | ||
170 | 81 | bool superKeyPressed = modifiers.testFlag(Qt::MetaModifier); | ||
171 | 82 | |||
172 | 83 | if (m_superKeyPressed != superKeyPressed) { | ||
173 | 84 | m_superKeyPressed = superKeyPressed; | ||
174 | 85 | Q_EMIT superKeyPressedChanged(m_superKeyPressed); | ||
175 | 86 | changeKeyboardShortcutsState(m_superKeyPressed); | ||
176 | 87 | } | ||
177 | 88 | } | ||
178 | 89 | |||
179 | 90 | void | ||
180 | 91 | LauncherView::changeKeyboardShortcutsState(bool enabled) | ||
181 | 92 | { | ||
182 | 93 | /* We are going to connect 10 Hotkeys, but to make things simpler on the QML | ||
183 | 94 | side we want to have only one signal with the number of the item that needs to | ||
184 | 95 | be activated in response to the hotkey press. | ||
185 | 96 | So we connect all of them to a single slot where we emit a single signal with | ||
186 | 97 | an index based on which Hotkey was the sender. */ | ||
187 | 98 | Qt::Key key = Qt::Key_0; | ||
188 | 99 | while (key <= Qt::Key_9) { | ||
189 | 100 | Hotkey *hotkey = HotkeyMonitor::instance().getHotkeyFor(key, Qt::MetaModifier); | ||
190 | 101 | |||
191 | 102 | if (enabled) { | ||
192 | 103 | QObject::connect(hotkey, SIGNAL(pressed()), this, SLOT(forwardHotkey())); | ||
193 | 104 | } else { | ||
194 | 105 | QObject::disconnect(hotkey, SIGNAL(pressed()), this, SLOT(forwardHotkey())); | ||
195 | 106 | } | ||
196 | 107 | key = (Qt::Key) (key + 1); | ||
197 | 108 | } | ||
198 | 109 | } | ||
199 | 110 | |||
200 | 111 | void | ||
201 | 112 | LauncherView::forwardHotkey() | ||
202 | 113 | { | ||
203 | 114 | Hotkey *hotkey = qobject_cast<Hotkey*>(sender()); | ||
204 | 115 | if (hotkey != NULL) { | ||
205 | 116 | /* Shortcuts from 1 to 9 should activate the items with index | ||
206 | 117 | from 0 to 8. Shortcut for 0 should activate item with index 10. | ||
207 | 118 | In other words, the indexes are activated in the same order as | ||
208 | 119 | the keys appear on a standard keyboard. */ | ||
209 | 120 | int itemIndex = hotkey->key() - Qt::Key_0; | ||
210 | 121 | itemIndex = (itemIndex == 0) ? 9 : itemIndex - 1; | ||
211 | 122 | |||
212 | 123 | if (itemIndex >= 0 && itemIndex <= 10) { | ||
213 | 124 | Q_EMIT keyboardShortcutPressed(itemIndex); | ||
214 | 125 | } | ||
215 | 126 | } | ||
216 | 45 | } | 127 | } |
217 | 46 | 128 | ||
218 | 47 | QGraphicsObject* | 129 | QGraphicsObject* |
219 | 48 | 130 | ||
220 | === modified file 'launcher/app/launcherview.h' | |||
221 | --- launcher/app/launcherview.h 2011-02-16 11:11:46 +0000 | |||
222 | +++ launcher/app/launcherview.h 2011-02-24 00:23:17 +0000 | |||
223 | @@ -24,23 +24,36 @@ | |||
224 | 24 | #include <QUrl> | 24 | #include <QUrl> |
225 | 25 | #include <QList> | 25 | #include <QList> |
226 | 26 | #include <QDragEnterEvent> | 26 | #include <QDragEnterEvent> |
227 | 27 | #include "gconfitem-qml-wrapper.h" | ||
228 | 27 | 28 | ||
229 | 28 | class QGraphicsObject; | 29 | class QGraphicsObject; |
230 | 29 | 30 | ||
231 | 30 | class LauncherView : public QDeclarativeView | 31 | class LauncherView : public QDeclarativeView |
232 | 31 | { | 32 | { |
233 | 32 | Q_OBJECT | 33 | Q_OBJECT |
234 | 34 | Q_PROPERTY(bool superKeyPressed READ superKeyPressed | ||
235 | 35 | NOTIFY superKeyPressedChanged) | ||
236 | 33 | 36 | ||
237 | 34 | public: | 37 | public: |
238 | 35 | explicit LauncherView(); | 38 | explicit LauncherView(); |
239 | 36 | Q_INVOKABLE QList<QVariant> getColorsFromIcon(QUrl source, QSize size) const; | 39 | Q_INVOKABLE QList<QVariant> getColorsFromIcon(QUrl source, QSize size) const; |
240 | 37 | 40 | ||
242 | 38 | signals: | 41 | bool superKeyPressed() const { return m_superKeyPressed; } |
243 | 42 | |||
244 | 43 | Q_SIGNALS: | ||
245 | 39 | void desktopFileDropped(QString path); | 44 | void desktopFileDropped(QString path); |
246 | 40 | void webpageUrlDropped(const QUrl& url); | 45 | void webpageUrlDropped(const QUrl& url); |
247 | 46 | void keyboardShortcutPressed(int itemIndex); | ||
248 | 47 | void superKeyPressedChanged(bool superKeyPressed); | ||
249 | 48 | |||
250 | 49 | private Q_SLOTS: | ||
251 | 50 | void setHotkeysForModifiers(Qt::KeyboardModifiers modifiers); | ||
252 | 51 | void forwardHotkey(); | ||
253 | 52 | void updateSuperKeyMonitoring(); | ||
254 | 41 | 53 | ||
255 | 42 | private: | 54 | private: |
256 | 43 | QList<QUrl> getEventUrls(QDropEvent*); | 55 | QList<QUrl> getEventUrls(QDropEvent*); |
257 | 56 | void changeKeyboardShortcutsState(bool enabled); | ||
258 | 44 | 57 | ||
259 | 45 | /* Whether the launcher is already being resized */ | 58 | /* Whether the launcher is already being resized */ |
260 | 46 | bool m_resizing; | 59 | bool m_resizing; |
261 | @@ -63,6 +76,9 @@ | |||
262 | 63 | bool m_dndCurrentLauncherItemAccepted; | 76 | bool m_dndCurrentLauncherItemAccepted; |
263 | 64 | /* Whether the launcher itself handles the current dnd event */ | 77 | /* Whether the launcher itself handles the current dnd event */ |
264 | 65 | bool m_dndAccepted; | 78 | bool m_dndAccepted; |
265 | 79 | |||
266 | 80 | GConfItemQmlWrapper m_enableSuperKey; | ||
267 | 81 | bool m_superKeyPressed; | ||
268 | 66 | }; | 82 | }; |
269 | 67 | 83 | ||
270 | 68 | #endif // LAUNCHERVIEW | 84 | #endif // LAUNCHERVIEW |
271 | 69 | 85 | ||
272 | === modified file 'launcher/tests/CMakeLists.txt' | |||
273 | --- launcher/tests/CMakeLists.txt 2011-01-27 16:23:33 +0000 | |||
274 | +++ launcher/tests/CMakeLists.txt 2011-02-24 00:23:17 +0000 | |||
275 | @@ -22,6 +22,7 @@ | |||
276 | 22 | ${CMAKE_CURRENT_SOURCE_DIR}/../UnityApplications | 22 | ${CMAKE_CURRENT_SOURCE_DIR}/../UnityApplications |
277 | 23 | ${CMAKE_CURRENT_BINARY_DIR} | 23 | ${CMAKE_CURRENT_BINARY_DIR} |
278 | 24 | ${QT_QTTEST_INCLUDE_DIR} | 24 | ${QT_QTTEST_INCLUDE_DIR} |
279 | 25 | ${QTGCONF_INCLUDE_DIRS} | ||
280 | 25 | ) | 26 | ) |
281 | 26 | 27 | ||
282 | 27 | enable_testing() | 28 | enable_testing() |
283 | 28 | 29 | ||
284 | === modified file 'libunity-2d-private/src/CMakeLists.txt' | |||
285 | --- libunity-2d-private/src/CMakeLists.txt 2011-02-11 11:37:55 +0000 | |||
286 | +++ libunity-2d-private/src/CMakeLists.txt 2011-02-24 00:23:17 +0000 | |||
287 | @@ -2,6 +2,8 @@ | |||
288 | 2 | set(libunity-2d-private_SRCS | 2 | set(libunity-2d-private_SRCS |
289 | 3 | gnomesessionclient.cpp | 3 | gnomesessionclient.cpp |
290 | 4 | keyboardmodifiersmonitor.cpp | 4 | keyboardmodifiersmonitor.cpp |
291 | 5 | hotkeymonitor.cpp | ||
292 | 6 | hotkey.cpp | ||
293 | 5 | unity2dapplication.cpp | 7 | unity2dapplication.cpp |
294 | 6 | unity2dpanel.cpp | 8 | unity2dpanel.cpp |
295 | 7 | mimedata.cpp | 9 | mimedata.cpp |
296 | 8 | 10 | ||
297 | === added file 'libunity-2d-private/src/hotkey.cpp' | |||
298 | --- libunity-2d-private/src/hotkey.cpp 1970-01-01 00:00:00 +0000 | |||
299 | +++ libunity-2d-private/src/hotkey.cpp 2011-02-24 00:23:17 +0000 | |||
300 | @@ -0,0 +1,101 @@ | |||
301 | 1 | /* | ||
302 | 2 | * Copyright (C) 2011 Canonical, Ltd. | ||
303 | 3 | * | ||
304 | 4 | * Authors: | ||
305 | 5 | * Ugo Riboni <ugo.riboni@canonical.com> | ||
306 | 6 | * | ||
307 | 7 | * This program is free software; you can redistribute it and/or modify | ||
308 | 8 | * it under the terms of the GNU General Public License as published by | ||
309 | 9 | * the Free Software Foundation; version 3. | ||
310 | 10 | * | ||
311 | 11 | * This program is distributed in the hope that it will be useful, | ||
312 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
313 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
314 | 14 | * GNU General Public License for more details. | ||
315 | 15 | * | ||
316 | 16 | * You should have received a copy of the GNU General Public License | ||
317 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
318 | 18 | */ | ||
319 | 19 | |||
320 | 20 | #include "hotkey.h" | ||
321 | 21 | |||
322 | 22 | #include <QX11Info> | ||
323 | 23 | #include <QDebug> | ||
324 | 24 | #include <QKeySequence> | ||
325 | 25 | |||
326 | 26 | #include <X11/Xlib.h> | ||
327 | 27 | #include <X11/XKBlib.h> | ||
328 | 28 | #include <X11/extensions/XKB.h> | ||
329 | 29 | |||
330 | 30 | Hotkey::Hotkey(Qt::Key key, Qt::KeyboardModifiers modifiers, QObject *parent) : | ||
331 | 31 | QObject(parent), m_connections(0), | ||
332 | 32 | m_key(key), m_modifiers(modifiers), | ||
333 | 33 | m_x11key(0), m_x11modifiers(0) | ||
334 | 34 | { | ||
335 | 35 | /* Translate the QT modifiers to X11 modifiers */ | ||
336 | 36 | |||
337 | 37 | if (modifiers.testFlag(Qt::ShiftModifier)) { | ||
338 | 38 | m_x11modifiers |= ShiftMask ; | ||
339 | 39 | } | ||
340 | 40 | if (modifiers.testFlag(Qt::ControlModifier)) { | ||
341 | 41 | m_x11modifiers |= ControlMask ; | ||
342 | 42 | } | ||
343 | 43 | if (modifiers.testFlag(Qt::AltModifier)) { | ||
344 | 44 | m_x11modifiers |= Mod1Mask; | ||
345 | 45 | } | ||
346 | 46 | if (modifiers.testFlag(Qt::MetaModifier)) { | ||
347 | 47 | m_x11modifiers |= Mod4Mask; | ||
348 | 48 | } | ||
349 | 49 | |||
350 | 50 | /* Translate the QT key to X11 keycode */ | ||
351 | 51 | |||
352 | 52 | /* QKeySequence can be used to translate a Qt::Key in a format that is | ||
353 | 53 | understood by XStringToKeysym if the sequence is composed only by the key */ | ||
354 | 54 | QString keyString = QKeySequence(key).toString(); | ||
355 | 55 | KeySym keysym = XStringToKeysym(keyString.toLatin1().data()); | ||
356 | 56 | if (keysym == NoSymbol) { | ||
357 | 57 | qWarning() << "Could not convert" << keyString << "to an x11 keysym"; | ||
358 | 58 | } else { | ||
359 | 59 | m_x11key = XKeysymToKeycode(QX11Info::display(), keysym); | ||
360 | 60 | if (m_x11key == 0) { | ||
361 | 61 | qWarning() << "Could not get keycode for keysym" << keysym | ||
362 | 62 | << "(" << keyString << ")"; | ||
363 | 63 | } | ||
364 | 64 | } | ||
365 | 65 | } | ||
366 | 66 | |||
367 | 67 | void | ||
368 | 68 | Hotkey::connectNotify(const char * signal) | ||
369 | 69 | { | ||
370 | 70 | Q_UNUSED(signal); | ||
371 | 71 | if (m_connections == 0) { | ||
372 | 72 | qDebug() << "Grabbing hotkey" << QKeySequence(m_key | m_modifiers).toString(); | ||
373 | 73 | XGrabKey(QX11Info::display(), m_x11key, m_x11modifiers, | ||
374 | 74 | QX11Info::appRootWindow(), True, GrabModeAsync, GrabModeAsync); | ||
375 | 75 | } | ||
376 | 76 | m_connections++; | ||
377 | 77 | } | ||
378 | 78 | |||
379 | 79 | void | ||
380 | 80 | Hotkey::disconnectNotify(const char * signal) | ||
381 | 81 | { | ||
382 | 82 | Q_UNUSED(signal); | ||
383 | 83 | if (m_connections == 1) { | ||
384 | 84 | qDebug() << "Ungrabbing hotkey" << QKeySequence(m_key | m_modifiers).toString(); | ||
385 | 85 | XUngrabKey(QX11Info::display(), m_x11key, m_x11modifiers, | ||
386 | 86 | QX11Info::appRootWindow()); | ||
387 | 87 | } | ||
388 | 88 | m_connections--; | ||
389 | 89 | } | ||
390 | 90 | |||
391 | 91 | bool | ||
392 | 92 | Hotkey::processNativeEvent(uint x11Keycode, uint x11Modifiers, bool isPressEvent) | ||
393 | 93 | { | ||
394 | 94 | if (x11Keycode == m_x11key && x11Modifiers == m_x11modifiers) { | ||
395 | 95 | Q_EMIT (isPressEvent) ? pressed() : released(); | ||
396 | 96 | return true; | ||
397 | 97 | } | ||
398 | 98 | return false; | ||
399 | 99 | } | ||
400 | 100 | |||
401 | 101 | #include "hotkey.moc" | ||
402 | 0 | 102 | ||
403 | === added file 'libunity-2d-private/src/hotkey.h' | |||
404 | --- libunity-2d-private/src/hotkey.h 1970-01-01 00:00:00 +0000 | |||
405 | +++ libunity-2d-private/src/hotkey.h 2011-02-24 00:23:17 +0000 | |||
406 | @@ -0,0 +1,59 @@ | |||
407 | 1 | /* | ||
408 | 2 | * Copyright (C) 2011 Canonical, Ltd. | ||
409 | 3 | * | ||
410 | 4 | * Authors: | ||
411 | 5 | * Ugo Riboni <ugo.riboni@canonical.com> | ||
412 | 6 | * | ||
413 | 7 | * This program is free software; you can redistribute it and/or modify | ||
414 | 8 | * it under the terms of the GNU General Public License as published by | ||
415 | 9 | * the Free Software Foundation; version 3. | ||
416 | 10 | * | ||
417 | 11 | * This program is distributed in the hope that it will be useful, | ||
418 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
419 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
420 | 14 | * GNU General Public License for more details. | ||
421 | 15 | * | ||
422 | 16 | * You should have received a copy of the GNU General Public License | ||
423 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
424 | 18 | */ | ||
425 | 19 | |||
426 | 20 | #ifndef Hotkey_H | ||
427 | 21 | #define Hotkey_H | ||
428 | 22 | |||
429 | 23 | #include <QObject> | ||
430 | 24 | |||
431 | 25 | class Hotkey : public QObject | ||
432 | 26 | { | ||
433 | 27 | friend class HotkeyMonitor; | ||
434 | 28 | |||
435 | 29 | Q_OBJECT | ||
436 | 30 | Q_PROPERTY(Qt::Key key READ key NOTIFY keyChanged) | ||
437 | 31 | Q_PROPERTY(Qt::KeyboardModifiers modifiers READ modifiers NOTIFY modifiersChanged) | ||
438 | 32 | |||
439 | 33 | public: | ||
440 | 34 | Qt::Key key() const { return m_key; } | ||
441 | 35 | Qt::KeyboardModifiers modifiers() const { return m_modifiers; } | ||
442 | 36 | |||
443 | 37 | Q_SIGNALS: | ||
444 | 38 | void keyChanged(Qt::Key key); | ||
445 | 39 | void modifiersChanged(Qt::KeyboardModifiers modifiers); | ||
446 | 40 | void pressed(); | ||
447 | 41 | void released(); | ||
448 | 42 | |||
449 | 43 | protected: | ||
450 | 44 | virtual void connectNotify(const char * signal); | ||
451 | 45 | virtual void disconnectNotify(const char * signal); | ||
452 | 46 | |||
453 | 47 | private: | ||
454 | 48 | Hotkey(Qt::Key key, Qt::KeyboardModifiers modifiers, QObject *parent); | ||
455 | 49 | bool processNativeEvent(uint x11Keycode, uint x11Modifiers, bool isPressEvent); | ||
456 | 50 | |||
457 | 51 | private: | ||
458 | 52 | uint m_connections; | ||
459 | 53 | Qt::Key m_key; | ||
460 | 54 | Qt::KeyboardModifiers m_modifiers; | ||
461 | 55 | uint m_x11key; | ||
462 | 56 | uint m_x11modifiers; | ||
463 | 57 | }; | ||
464 | 58 | |||
465 | 59 | #endif // Hotkey_H | ||
466 | 0 | 60 | ||
467 | === added file 'libunity-2d-private/src/hotkeymonitor.cpp' | |||
468 | --- libunity-2d-private/src/hotkeymonitor.cpp 1970-01-01 00:00:00 +0000 | |||
469 | +++ libunity-2d-private/src/hotkeymonitor.cpp 2011-02-24 00:23:17 +0000 | |||
470 | @@ -0,0 +1,105 @@ | |||
471 | 1 | /* | ||
472 | 2 | * Copyright (C) 2011 Canonical, Ltd. | ||
473 | 3 | * | ||
474 | 4 | * Authors: | ||
475 | 5 | * Ugo Riboni <ugo.riboni@canonical.com> | ||
476 | 6 | * | ||
477 | 7 | * This program is free software; you can redistribute it and/or modify | ||
478 | 8 | * it under the terms of the GNU General Public License as published by | ||
479 | 9 | * the Free Software Foundation; version 3. | ||
480 | 10 | * | ||
481 | 11 | * This program is distributed in the hope that it will be useful, | ||
482 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
483 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
484 | 14 | * GNU General Public License for more details. | ||
485 | 15 | * | ||
486 | 16 | * You should have received a copy of the GNU General Public License | ||
487 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
488 | 18 | */ | ||
489 | 19 | |||
490 | 20 | #include "hotkeymonitor.h" | ||
491 | 21 | #include "hotkey.h" | ||
492 | 22 | |||
493 | 23 | #include <QDebug> | ||
494 | 24 | |||
495 | 25 | #include <X11/X.h> | ||
496 | 26 | #include <X11/Xlib.h> | ||
497 | 27 | #include <X11/XKBlib.h> | ||
498 | 28 | #include <X11/extensions/XKB.h> | ||
499 | 29 | |||
500 | 30 | #include <QX11Info> | ||
501 | 31 | #include <QAbstractEventDispatcher> | ||
502 | 32 | |||
503 | 33 | HotkeyMonitor::HotkeyMonitor(QObject* parent) | ||
504 | 34 | : QObject(parent) | ||
505 | 35 | { | ||
506 | 36 | int opcode, baseError, baseEvent; | ||
507 | 37 | if (XkbQueryExtension(QX11Info::display(), &opcode, &baseEvent, | ||
508 | 38 | &baseError, NULL, NULL) == False) { | ||
509 | 39 | qWarning() << "Failed to initialize Xkb extension. CapsLock and NumLock" | ||
510 | 40 | "active will prevent shortcuts from working."; | ||
511 | 41 | } else { | ||
512 | 42 | /* With this call we ignore CapsLock and NumLock when grabbing keys. */ | ||
513 | 43 | XkbSetIgnoreLockMods(QX11Info::display(), XkbUseCoreKbd, | ||
514 | 44 | Mod2Mask | LockMask, Mod2Mask | LockMask, | ||
515 | 45 | 0, 0); | ||
516 | 46 | } | ||
517 | 47 | |||
518 | 48 | QAbstractEventDispatcher::instance()->setEventFilter(HotkeyMonitor::keyEventFilter); | ||
519 | 49 | } | ||
520 | 50 | |||
521 | 51 | HotkeyMonitor& | ||
522 | 52 | HotkeyMonitor::instance() | ||
523 | 53 | { | ||
524 | 54 | static HotkeyMonitor monitor; | ||
525 | 55 | return monitor; | ||
526 | 56 | } | ||
527 | 57 | |||
528 | 58 | HotkeyMonitor::~HotkeyMonitor() | ||
529 | 59 | { | ||
530 | 60 | qDeleteAll(m_hotkeys); | ||
531 | 61 | } | ||
532 | 62 | |||
533 | 63 | |||
534 | 64 | Hotkey* | ||
535 | 65 | HotkeyMonitor::getHotkeyFor(Qt::Key key, Qt::KeyboardModifiers modifiers) | ||
536 | 66 | { | ||
537 | 67 | Q_FOREACH(Hotkey* currentHotkey, m_hotkeys) { | ||
538 | 68 | if (currentHotkey->key() == key && | ||
539 | 69 | currentHotkey->modifiers() == modifiers) { | ||
540 | 70 | return currentHotkey; | ||
541 | 71 | } | ||
542 | 72 | } | ||
543 | 73 | |||
544 | 74 | Hotkey *hotkey = new Hotkey(key, modifiers, this); | ||
545 | 75 | m_hotkeys.append(hotkey); | ||
546 | 76 | return hotkey; | ||
547 | 77 | } | ||
548 | 78 | |||
549 | 79 | bool | ||
550 | 80 | HotkeyMonitor::keyEventFilter(void* message) | ||
551 | 81 | { | ||
552 | 82 | XEvent* event = static_cast<XEvent*>(message); | ||
553 | 83 | if (event->type == KeyRelease || event->type == KeyPress) | ||
554 | 84 | { | ||
555 | 85 | XKeyEvent* key = (XKeyEvent*) event; | ||
556 | 86 | HotkeyMonitor::instance().processKeyEvent(key->keycode, key->state, | ||
557 | 87 | event->type == KeyPress); | ||
558 | 88 | } | ||
559 | 89 | return false; | ||
560 | 90 | } | ||
561 | 91 | |||
562 | 92 | void | ||
563 | 93 | HotkeyMonitor::processKeyEvent(uint x11Keycode, uint x11Modifiers, | ||
564 | 94 | bool isPressEvent) | ||
565 | 95 | { | ||
566 | 96 | Q_FOREACH(Hotkey* hotkey, m_hotkeys) { | ||
567 | 97 | if (hotkey->processNativeEvent(x11Keycode, x11Modifiers, isPressEvent)) { | ||
568 | 98 | return; | ||
569 | 99 | } | ||
570 | 100 | } | ||
571 | 101 | qWarning() << "Received x11 key event that wasn't processed by any hotkey:" | ||
572 | 102 | << x11Keycode << x11Modifiers << ((isPressEvent) ? "Press" : "Release"); | ||
573 | 103 | } | ||
574 | 104 | |||
575 | 105 | #include "hotkeymonitor.moc" | ||
576 | 0 | 106 | ||
577 | === added file 'libunity-2d-private/src/hotkeymonitor.h' | |||
578 | --- libunity-2d-private/src/hotkeymonitor.h 1970-01-01 00:00:00 +0000 | |||
579 | +++ libunity-2d-private/src/hotkeymonitor.h 2011-02-24 00:23:17 +0000 | |||
580 | @@ -0,0 +1,50 @@ | |||
581 | 1 | /* | ||
582 | 2 | * Copyright (C) 2011 Canonical, Ltd. | ||
583 | 3 | * | ||
584 | 4 | * Authors: | ||
585 | 5 | * Ugo Riboni <ugo.riboni@canonical.com> | ||
586 | 6 | * | ||
587 | 7 | * This program is free software; you can redistribute it and/or modify | ||
588 | 8 | * it under the terms of the GNU General Public License as published by | ||
589 | 9 | * the Free Software Foundation; version 3. | ||
590 | 10 | * | ||
591 | 11 | * This program is distributed in the hope that it will be useful, | ||
592 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
593 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
594 | 14 | * GNU General Public License for more details. | ||
595 | 15 | * | ||
596 | 16 | * You should have received a copy of the GNU General Public License | ||
597 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
598 | 18 | */ | ||
599 | 19 | |||
600 | 20 | #ifndef HotkeyMonitor_H | ||
601 | 21 | #define HotkeyMonitor_H | ||
602 | 22 | |||
603 | 23 | #include <QObject> | ||
604 | 24 | #include <QList> | ||
605 | 25 | |||
606 | 26 | class Hotkey; | ||
607 | 27 | |||
608 | 28 | class HotkeyMonitor : public QObject | ||
609 | 29 | { | ||
610 | 30 | Q_OBJECT | ||
611 | 31 | |||
612 | 32 | public: | ||
613 | 33 | static HotkeyMonitor& instance(); | ||
614 | 34 | ~HotkeyMonitor(); | ||
615 | 35 | |||
616 | 36 | Hotkey* getHotkeyFor(Qt::Key key, Qt::KeyboardModifiers modifiers); | ||
617 | 37 | |||
618 | 38 | private: | ||
619 | 39 | HotkeyMonitor(QObject* parent=0); | ||
620 | 40 | |||
621 | 41 | static bool keyEventFilter(void* message); | ||
622 | 42 | void processKeyEvent(uint x11Keycode, uint x11Modifiers, | ||
623 | 43 | bool isPressEvent); | ||
624 | 44 | |||
625 | 45 | QList<Hotkey*> m_hotkeys; | ||
626 | 46 | }; | ||
627 | 47 | |||
628 | 48 | |||
629 | 49 | #endif // HotkeyMonitor_H | ||
630 | 50 | |||
631 | 0 | 51 | ||
632 | === modified file 'places/app/CMakeLists.txt' | |||
633 | --- places/app/CMakeLists.txt 2011-01-10 18:25:49 +0000 | |||
634 | +++ places/app/CMakeLists.txt 2011-02-24 00:23:17 +0000 | |||
635 | @@ -4,15 +4,11 @@ | |||
636 | 4 | 4 | ||
637 | 5 | # Sources | 5 | # Sources |
638 | 6 | set(places_SRCS | 6 | set(places_SRCS |
639 | 7 | keymonitor.cpp | ||
640 | 8 | superkeymonitor.cpp | ||
641 | 9 | places.cpp | 7 | places.cpp |
642 | 10 | dashdeclarativeview.cpp | 8 | dashdeclarativeview.cpp |
643 | 11 | ) | 9 | ) |
644 | 12 | 10 | ||
645 | 13 | set(places_MOC_HDRS | 11 | set(places_MOC_HDRS |
646 | 14 | keymonitor.h | ||
647 | 15 | superkeymonitor.h | ||
648 | 16 | dashdeclarativeview.h | 12 | dashdeclarativeview.h |
649 | 17 | ) | 13 | ) |
650 | 18 | 14 | ||
651 | 19 | 15 | ||
652 | === removed file 'places/app/keymonitor.cpp' | |||
653 | --- places/app/keymonitor.cpp 2011-01-12 09:17:58 +0000 | |||
654 | +++ places/app/keymonitor.cpp 1970-01-01 00:00:00 +0000 | |||
655 | @@ -1,62 +0,0 @@ | |||
656 | 1 | /* | ||
657 | 2 | * Copyright (C) 2011 Canonical, Ltd. | ||
658 | 3 | * | ||
659 | 4 | * Authors: | ||
660 | 5 | * Olivier Tilloy <olivier.tilloy@canonical.com> | ||
661 | 6 | * | ||
662 | 7 | * This program is free software; you can redistribute it and/or modify | ||
663 | 8 | * it under the terms of the GNU General Public License as published by | ||
664 | 9 | * the Free Software Foundation; version 3. | ||
665 | 10 | * | ||
666 | 11 | * This program is distributed in the hope that it will be useful, | ||
667 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
668 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
669 | 14 | * GNU General Public License for more details. | ||
670 | 15 | * | ||
671 | 16 | * You should have received a copy of the GNU General Public License | ||
672 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
673 | 18 | */ | ||
674 | 19 | |||
675 | 20 | #include "keymonitor.h" | ||
676 | 21 | |||
677 | 22 | #include <X11/Xlib.h> | ||
678 | 23 | |||
679 | 24 | #include <QX11Info> | ||
680 | 25 | |||
681 | 26 | KeyMonitor::KeyMonitor(int keycode, QObject* parent) | ||
682 | 27 | : QObject(parent) | ||
683 | 28 | , m_keycode(keycode) | ||
684 | 29 | , m_grabbed(false) | ||
685 | 30 | { | ||
686 | 31 | } | ||
687 | 32 | |||
688 | 33 | KeyMonitor::~KeyMonitor() | ||
689 | 34 | { | ||
690 | 35 | if (m_grabbed) { | ||
691 | 36 | ungrabKey(); | ||
692 | 37 | } | ||
693 | 38 | } | ||
694 | 39 | |||
695 | 40 | void | ||
696 | 41 | KeyMonitor::grabKey() | ||
697 | 42 | { | ||
698 | 43 | Display* display = QX11Info::display(); | ||
699 | 44 | Window window = QX11Info::appRootWindow(); | ||
700 | 45 | Bool owner = True; | ||
701 | 46 | int pointer = GrabModeAsync; | ||
702 | 47 | int keyboard = GrabModeAsync; | ||
703 | 48 | XGrabKey(display, m_keycode, 0, window, owner, pointer, keyboard); | ||
704 | 49 | /* Assume no X error. */ | ||
705 | 50 | m_grabbed = true; | ||
706 | 51 | } | ||
707 | 52 | |||
708 | 53 | void | ||
709 | 54 | KeyMonitor::ungrabKey() | ||
710 | 55 | { | ||
711 | 56 | Display* display = QX11Info::display(); | ||
712 | 57 | Window window = QX11Info::appRootWindow(); | ||
713 | 58 | XUngrabKey(display, m_keycode, 0, window); | ||
714 | 59 | /* Assume no X error. */ | ||
715 | 60 | m_grabbed = false; | ||
716 | 61 | } | ||
717 | 62 | |||
718 | 63 | 0 | ||
719 | === removed file 'places/app/keymonitor.h' | |||
720 | --- places/app/keymonitor.h 2011-01-11 12:37:45 +0000 | |||
721 | +++ places/app/keymonitor.h 1970-01-01 00:00:00 +0000 | |||
722 | @@ -1,42 +0,0 @@ | |||
723 | 1 | /* | ||
724 | 2 | * Copyright (C) 2011 Canonical, Ltd. | ||
725 | 3 | * | ||
726 | 4 | * Authors: | ||
727 | 5 | * Olivier Tilloy <olivier.tilloy@canonical.com> | ||
728 | 6 | * | ||
729 | 7 | * This program is free software; you can redistribute it and/or modify | ||
730 | 8 | * it under the terms of the GNU General Public License as published by | ||
731 | 9 | * the Free Software Foundation; version 3. | ||
732 | 10 | * | ||
733 | 11 | * This program is distributed in the hope that it will be useful, | ||
734 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
735 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
736 | 14 | * GNU General Public License for more details. | ||
737 | 15 | * | ||
738 | 16 | * You should have received a copy of the GNU General Public License | ||
739 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
740 | 18 | */ | ||
741 | 19 | |||
742 | 20 | #ifndef KeyMonitor_H | ||
743 | 21 | #define KeyMonitor_H | ||
744 | 22 | |||
745 | 23 | #include <QObject> | ||
746 | 24 | |||
747 | 25 | class KeyMonitor : public QObject | ||
748 | 26 | { | ||
749 | 27 | Q_OBJECT | ||
750 | 28 | |||
751 | 29 | public: | ||
752 | 30 | KeyMonitor(int keycode, QObject* parent=0); | ||
753 | 31 | ~KeyMonitor(); | ||
754 | 32 | |||
755 | 33 | void grabKey(); | ||
756 | 34 | void ungrabKey(); | ||
757 | 35 | |||
758 | 36 | private: | ||
759 | 37 | int m_keycode; | ||
760 | 38 | bool m_grabbed; | ||
761 | 39 | }; | ||
762 | 40 | |||
763 | 41 | #endif // KeyMonitor_H | ||
764 | 42 | |||
765 | 43 | 0 | ||
766 | === modified file 'places/app/places.cpp' | |||
767 | --- places/app/places.cpp 2011-02-02 16:57:00 +0000 | |||
768 | +++ places/app/places.cpp 2011-02-24 00:23:17 +0000 | |||
769 | @@ -30,8 +30,6 @@ | |||
770 | 30 | #include <X11/Xlib.h> | 30 | #include <X11/Xlib.h> |
771 | 31 | 31 | ||
772 | 32 | #include "dashdeclarativeview.h" | 32 | #include "dashdeclarativeview.h" |
773 | 33 | #include "superkeymonitor.h" | ||
774 | 34 | |||
775 | 35 | #include "config.h" | 33 | #include "config.h" |
776 | 36 | 34 | ||
777 | 37 | /* Register a D-Bus service for activation and deactivation of the dash */ | 35 | /* Register a D-Bus service for activation and deactivation of the dash */ |
778 | @@ -43,7 +41,7 @@ | |||
779 | 43 | return false; | 41 | return false; |
780 | 44 | } | 42 | } |
781 | 45 | /* FIXME: use an adaptor class in order not to expose all of the view's | 43 | /* FIXME: use an adaptor class in order not to expose all of the view's |
783 | 46 | properties and methods. */ | 44 | properties and methods. */\ |
784 | 47 | if (!bus.registerObject("/Dash", view, QDBusConnection::ExportAllContents)) { | 45 | if (!bus.registerObject("/Dash", view, QDBusConnection::ExportAllContents)) { |
785 | 48 | qCritical() << "Failed to register /Dash, this should not happen!"; | 46 | qCritical() << "Failed to register /Dash, this should not happen!"; |
786 | 49 | return false; | 47 | return false; |
787 | @@ -61,33 +59,6 @@ | |||
788 | 61 | return true; | 59 | return true; |
789 | 62 | } | 60 | } |
790 | 63 | 61 | ||
791 | 64 | static DashDeclarativeView* getView() | ||
792 | 65 | { | ||
793 | 66 | QVariant viewProperty = QApplication::instance()->property("view"); | ||
794 | 67 | return viewProperty.value<DashDeclarativeView*>(); | ||
795 | 68 | } | ||
796 | 69 | |||
797 | 70 | static bool eventFilter(void* message) | ||
798 | 71 | { | ||
799 | 72 | XEvent* event = static_cast<XEvent*>(message); | ||
800 | 73 | if (event->type == KeyRelease) | ||
801 | 74 | { | ||
802 | 75 | XKeyEvent* key = (XKeyEvent*) event; | ||
803 | 76 | uint code = key->keycode; | ||
804 | 77 | if (code == SuperKeyMonitor::SUPER_L || code == SuperKeyMonitor::SUPER_R) { | ||
805 | 78 | /* Super (aka the "windows" key) shows/hides the dash. */ | ||
806 | 79 | DashDeclarativeView* view = getView(); | ||
807 | 80 | if (view->active()) { | ||
808 | 81 | view->setActive(false); | ||
809 | 82 | } | ||
810 | 83 | else { | ||
811 | 84 | view->activateHome(); | ||
812 | 85 | } | ||
813 | 86 | } | ||
814 | 87 | } | ||
815 | 88 | return false; | ||
816 | 89 | } | ||
817 | 90 | |||
818 | 91 | int main(int argc, char *argv[]) | 62 | int main(int argc, char *argv[]) |
819 | 92 | { | 63 | { |
820 | 93 | QApplication::setApplicationName("Unity 2D Dash"); | 64 | QApplication::setApplicationName("Unity 2D Dash"); |
821 | @@ -142,10 +113,6 @@ | |||
822 | 142 | view.fitToAvailableSpace(current_screen); | 113 | view.fitToAvailableSpace(current_screen); |
823 | 143 | QObject::connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), &view, SLOT(fitToAvailableSpace(int))); | 114 | QObject::connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), &view, SLOT(fitToAvailableSpace(int))); |
824 | 144 | 115 | ||
825 | 145 | /* Grab the "super" keys */ | ||
826 | 146 | SuperKeyMonitor superKeys; /* Just needs to be instantiated to work. */ | ||
827 | 147 | QAbstractEventDispatcher::instance()->setEventFilter(eventFilter); | ||
828 | 148 | |||
829 | 149 | application.setProperty("view", QVariant::fromValue(&view)); | 116 | application.setProperty("view", QVariant::fromValue(&view)); |
830 | 150 | return application.exec(); | 117 | return application.exec(); |
831 | 151 | } | 118 | } |
832 | 152 | 119 | ||
833 | === removed file 'places/app/superkeymonitor.cpp' | |||
834 | --- places/app/superkeymonitor.cpp 2011-01-11 12:47:22 +0000 | |||
835 | +++ places/app/superkeymonitor.cpp 1970-01-01 00:00:00 +0000 | |||
836 | @@ -1,79 +0,0 @@ | |||
837 | 1 | /* | ||
838 | 2 | * Copyright (C) 2011 Canonical, Ltd. | ||
839 | 3 | * | ||
840 | 4 | * Authors: | ||
841 | 5 | * Olivier Tilloy <olivier.tilloy@canonical.com> | ||
842 | 6 | * | ||
843 | 7 | * This program is free software; you can redistribute it and/or modify | ||
844 | 8 | * it under the terms of the GNU General Public License as published by | ||
845 | 9 | * the Free Software Foundation; version 3. | ||
846 | 10 | * | ||
847 | 11 | * This program is distributed in the hope that it will be useful, | ||
848 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
849 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
850 | 14 | * GNU General Public License for more details. | ||
851 | 15 | * | ||
852 | 16 | * You should have received a copy of the GNU General Public License | ||
853 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
854 | 18 | */ | ||
855 | 19 | |||
856 | 20 | #include "superkeymonitor.h" | ||
857 | 21 | #include "keymonitor.h" | ||
858 | 22 | |||
859 | 23 | #include "gconfitem-qml-wrapper.h" | ||
860 | 24 | |||
861 | 25 | SuperKeyMonitor::SuperKeyMonitor() | ||
862 | 26 | { | ||
863 | 27 | m_left = new KeyMonitor(SUPER_L, this); | ||
864 | 28 | m_right = new KeyMonitor(SUPER_R, this); | ||
865 | 29 | |||
866 | 30 | m_enable_setting = new GConfItemQmlWrapper(this); | ||
867 | 31 | m_enable_setting->setKey("/desktop/unity/launcher/super_key_enable"); | ||
868 | 32 | if (getEnableSettingValue()) { | ||
869 | 33 | startMonitoring(); | ||
870 | 34 | } | ||
871 | 35 | connect(m_enable_setting, SIGNAL(valueChanged()), SLOT(slotEnableSettingChanged())); | ||
872 | 36 | } | ||
873 | 37 | |||
874 | 38 | SuperKeyMonitor::~SuperKeyMonitor() | ||
875 | 39 | { | ||
876 | 40 | } | ||
877 | 41 | |||
878 | 42 | bool | ||
879 | 43 | SuperKeyMonitor::getEnableSettingValue() const | ||
880 | 44 | { | ||
881 | 45 | QVariant value = m_enable_setting->getValue(); | ||
882 | 46 | if (value.isValid()) { | ||
883 | 47 | return value.toBool(); | ||
884 | 48 | } | ||
885 | 49 | else { | ||
886 | 50 | /* The key is not set, assume true. */ | ||
887 | 51 | return true; | ||
888 | 52 | } | ||
889 | 53 | } | ||
890 | 54 | |||
891 | 55 | void | ||
892 | 56 | SuperKeyMonitor::slotEnableSettingChanged() | ||
893 | 57 | { | ||
894 | 58 | if (getEnableSettingValue()) { | ||
895 | 59 | startMonitoring(); | ||
896 | 60 | } | ||
897 | 61 | else { | ||
898 | 62 | stopMonitoring(); | ||
899 | 63 | } | ||
900 | 64 | } | ||
901 | 65 | |||
902 | 66 | void | ||
903 | 67 | SuperKeyMonitor::startMonitoring() | ||
904 | 68 | { | ||
905 | 69 | m_left->grabKey(); | ||
906 | 70 | m_right->grabKey(); | ||
907 | 71 | } | ||
908 | 72 | |||
909 | 73 | void | ||
910 | 74 | SuperKeyMonitor::stopMonitoring() | ||
911 | 75 | { | ||
912 | 76 | m_left->ungrabKey(); | ||
913 | 77 | m_right->ungrabKey(); | ||
914 | 78 | } | ||
915 | 79 | |||
916 | 80 | 0 | ||
917 | === removed file 'places/app/superkeymonitor.h' | |||
918 | --- places/app/superkeymonitor.h 2011-01-11 12:35:07 +0000 | |||
919 | +++ places/app/superkeymonitor.h 1970-01-01 00:00:00 +0000 | |||
920 | @@ -1,55 +0,0 @@ | |||
921 | 1 | /* | ||
922 | 2 | * Copyright (C) 2011 Canonical, Ltd. | ||
923 | 3 | * | ||
924 | 4 | * Authors: | ||
925 | 5 | * Olivier Tilloy <olivier.tilloy@canonical.com> | ||
926 | 6 | * | ||
927 | 7 | * This program is free software; you can redistribute it and/or modify | ||
928 | 8 | * it under the terms of the GNU General Public License as published by | ||
929 | 9 | * the Free Software Foundation; version 3. | ||
930 | 10 | * | ||
931 | 11 | * This program is distributed in the hope that it will be useful, | ||
932 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
933 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
934 | 14 | * GNU General Public License for more details. | ||
935 | 15 | * | ||
936 | 16 | * You should have received a copy of the GNU General Public License | ||
937 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
938 | 18 | */ | ||
939 | 19 | |||
940 | 20 | #ifndef SuperKeyMonitor_H | ||
941 | 21 | #define SuperKeyMonitor_H | ||
942 | 22 | |||
943 | 23 | #include <QObject> | ||
944 | 24 | |||
945 | 25 | class KeyMonitor; | ||
946 | 26 | class GConfItemQmlWrapper; | ||
947 | 27 | |||
948 | 28 | class SuperKeyMonitor : public QObject | ||
949 | 29 | { | ||
950 | 30 | Q_OBJECT | ||
951 | 31 | |||
952 | 32 | public: | ||
953 | 33 | SuperKeyMonitor(); | ||
954 | 34 | ~SuperKeyMonitor(); | ||
955 | 35 | |||
956 | 36 | static const uint SUPER_L = 133; | ||
957 | 37 | static const uint SUPER_R = 134; | ||
958 | 38 | |||
959 | 39 | private: | ||
960 | 40 | KeyMonitor* m_left; | ||
961 | 41 | KeyMonitor* m_right; | ||
962 | 42 | |||
963 | 43 | GConfItemQmlWrapper* m_enable_setting; | ||
964 | 44 | |||
965 | 45 | bool getEnableSettingValue() const; | ||
966 | 46 | |||
967 | 47 | void startMonitoring(); | ||
968 | 48 | void stopMonitoring(); | ||
969 | 49 | |||
970 | 50 | private Q_SLOTS: | ||
971 | 51 | void slotEnableSettingChanged(); | ||
972 | 52 | }; | ||
973 | 53 | |||
974 | 54 | #endif // SuperKeyMonitor_H | ||
975 | 55 |
Attempt to merge into lp:unity-2d failed due to conflicts:
text conflict in launcher/ LauncherItem. qml app/CMakeLists. txt 2d-private/ src/CMakeLists. txt app/places. cpp
text conflict in launcher/
text conflict in libunity-
text conflict in places/