Merge lp:~aacid/unity-2d/unity-2d_hud_configuration_key into lp:unity-2d

Proposed by Albert Astals Cid
Status: Merged
Approved by: Michał Sawicz
Approved revision: 1035
Merged at revision: 1030
Proposed branch: lp:~aacid/unity-2d/unity-2d_hud_configuration_key
Merge into: lp:unity-2d
Diff against target: 605 lines (+302/-31)
15 files modified
libunity-2d-private/src/CMakeLists.txt (+1/-0)
libunity-2d-private/src/gkeysequenceparser.cpp (+73/-0)
libunity-2d-private/src/gkeysequenceparser.h (+28/-0)
libunity-2d-private/src/hotkey.cpp (+37/-15)
libunity-2d-private/src/hotkey.h (+7/-4)
libunity-2d-private/src/hotkeymonitor.cpp (+15/-0)
libunity-2d-private/src/hotkeymonitor.h (+1/-0)
libunity-2d-private/src/hotmodifier.cpp (+9/-5)
libunity-2d-private/src/hotmodifier.h (+1/-0)
libunity-2d-private/tests/CMakeLists.txt (+1/-0)
libunity-2d-private/tests/gkeysequenceparser.cpp (+66/-0)
libunity-2d-private/tests/hotkeytest.cpp (+1/-1)
shell/app/shellmanager.cpp (+50/-6)
shell/app/shellmanager.h (+2/-0)
tests/manual-tests/hud.txt (+10/-0)
To merge this branch: bzr merge lp:~aacid/unity-2d/unity-2d_hud_configuration_key
Reviewer Review Type Date Requested Status
Paweł Stołowski (community) Approve
Michał Sawicz Pending
Review via email: mp+100418@code.launchpad.net

Commit message

[HUD] Read the unity setting for hud toggling

For that we need to introduce a parser of the gsettings unity conf key and modify the hotmodifier so it supports multiple modifiers (like shift + alt)

Description of the change

[HUD] Read the unity setting for hud toggling

For that we need to introduce a parser of the gsettings unity conf key and modify the hotmodifier so it supports multiple modifiers (like shift + alt)

To post a comment you must log in.
Revision history for this message
Paweł Stołowski (stolowski) wrote :

Looks good!

review: Approve
Revision history for this message
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity-2d/233/console reported an error when processing this lp:~aacid/unity-2d/unity-2d_hud_configuration_key branch.
Not merging it.

1035. By Albert Astals Cid

Use a more usual letter that works with xvfb

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libunity-2d-private/src/CMakeLists.txt'
--- libunity-2d-private/src/CMakeLists.txt 2012-03-20 14:50:42 +0000
+++ libunity-2d-private/src/CMakeLists.txt 2012-04-02 16:31:23 +0000
@@ -87,6 +87,7 @@
87 pointerbarrier.cpp87 pointerbarrier.cpp
88 pointerbarriermanager.cpp88 pointerbarriermanager.cpp
89 decayedvalue.cpp89 decayedvalue.cpp
90 gkeysequenceparser.cpp
90 )91 )
9192
92# Build93# Build
9394
=== added file 'libunity-2d-private/src/gkeysequenceparser.cpp'
--- libunity-2d-private/src/gkeysequenceparser.cpp 1970-01-01 00:00:00 +0000
+++ libunity-2d-private/src/gkeysequenceparser.cpp 2012-04-02 16:31:23 +0000
@@ -0,0 +1,73 @@
1/*
2 * Copyright (C) 2012 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "gkeysequenceparser.h"
18
19#include <QDebug>
20#include <QString>
21#include <QX11Info>
22
23#include <X11/XKBlib.h>
24
25bool GKeySequenceParser::parse(const QString &keySequence, int *x11KeyCode, Qt::KeyboardModifiers *modifiers)
26{
27 // Parses a string in the form created by the gtk shortcut dialog into x11 keycode and qt modifiers
28 // The expected format is
29 // <Modifier>*Keyname?
30 // i.e. there can be none or multiple modifiers followed or not by the name of a key
31 bool success = true;
32 *x11KeyCode = 0;
33 *modifiers = Qt::NoModifier;
34 if (keySequence == "Disabled") {
35 return success;
36 }
37
38 QString aux = keySequence;
39 while (success && aux.startsWith('<')) {
40 const int closing = aux.indexOf('>');
41 if (closing > 0) {
42 const QString modifier = aux.mid(1, closing - 1);
43 if (modifier == "Control" || modifier == "Primary") {
44 *modifiers = *modifiers | Qt::ControlModifier;
45 } else if (modifier == "Shift") {
46 *modifiers = *modifiers | Qt::ShiftModifier;
47 } else if (modifier == "Alt") {
48 *modifiers = *modifiers | Qt::AltModifier;
49 } else if (modifier == "Super") {
50 *modifiers = *modifiers | Qt::MetaModifier;
51 } else {
52 qWarning() << "Could not parse modifier" << modifier << "in key sequence" << keySequence;
53 success = false;
54 }
55 aux = aux.mid(closing + 1);
56 } else {
57 qWarning() << "Could not find modifier end in key sequence" << keySequence;
58 success = false;
59 }
60 }
61
62 if (success && !aux.isEmpty()) {
63 KeySym keysym = XStringToKeysym(aux.toLatin1().constData());
64 if (keysym == NoSymbol) {
65 qWarning() << "Could not parse key" << aux << "in key sequence" << keySequence;
66 success = false;
67 } else {
68 *x11KeyCode = XKeysymToKeycode(QX11Info::display(), keysym);
69 }
70 }
71
72 return success;
73}
074
=== added file 'libunity-2d-private/src/gkeysequenceparser.h'
--- libunity-2d-private/src/gkeysequenceparser.h 1970-01-01 00:00:00 +0000
+++ libunity-2d-private/src/gkeysequenceparser.h 2012-04-02 16:31:23 +0000
@@ -0,0 +1,28 @@
1/*
2 * Copyright (C) 2012 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef GKEYSEQUENCEPARSER_H
18#define GKEYSEQUENCEPARSER_H
19
20#include <Qt>
21
22namespace GKeySequenceParser
23{
24 bool parse(const QString &keySequence, int *x11KeyCode, Qt::KeyboardModifiers *modifiers);
25}
26
27#endif // GKEYSEQUENCEPARSER_H
28
029
=== modified file 'libunity-2d-private/src/hotkey.cpp'
--- libunity-2d-private/src/hotkey.cpp 2012-03-16 16:48:19 +0000
+++ libunity-2d-private/src/hotkey.cpp 2012-04-02 16:31:23 +0000
@@ -54,20 +54,8 @@
54 m_key(key), m_modifiers(modifiers),54 m_key(key), m_modifiers(modifiers),
55 m_x11key(0), m_x11modifiers(0)55 m_x11key(0), m_x11modifiers(0)
56{56{
57 /* Translate the QT modifiers to X11 modifiers */57 translateModifiers(modifiers);
5858
59 if (modifiers.testFlag(Qt::ShiftModifier)) {
60 m_x11modifiers |= ShiftMask ;
61 }
62 if (modifiers.testFlag(Qt::ControlModifier)) {
63 m_x11modifiers |= ControlMask ;
64 }
65 if (modifiers.testFlag(Qt::AltModifier)) {
66 m_x11modifiers |= Mod1Mask;
67 }
68 if (modifiers.testFlag(Qt::MetaModifier)) {
69 m_x11modifiers |= Mod4Mask;
70 }
71 if (modifiers.testFlag(Qt::KeypadModifier)) {59 if (modifiers.testFlag(Qt::KeypadModifier)) {
72 /* Support 0..9 numpad keys only.60 /* Support 0..9 numpad keys only.
73 If we ever need to support additional numpad keys, then this logic should be extended61 If we ever need to support additional numpad keys, then this logic should be extended
@@ -102,12 +90,24 @@
102 }90 }
103}91}
10492
93Hotkey::Hotkey(uint x11key, Qt::KeyboardModifiers modifiers, QObject *parent)
94 : QObject(parent), m_connections(0),
95 m_key(0), m_modifiers(modifiers),
96 m_x11key(x11key), m_x11modifiers(0)
97{
98 translateModifiers(modifiers);
99}
100
105void101void
106Hotkey::connectNotify(const char * signal)102Hotkey::connectNotify(const char * signal)
107{103{
108 Q_UNUSED(signal);104 Q_UNUSED(signal);
109 if (m_connections == 0) {105 if (m_connections == 0) {
110 UQ_DEBUG << "Grabbing hotkey" << QKeySequence(m_key | m_modifiers).toString();106 if (m_key != 0) {
107 UQ_DEBUG << "Grabbing hotkey" << QKeySequence(m_key | m_modifiers).toString();
108 } else {
109 UQ_DEBUG.nospace() << "Grabbing hotkey" << QKeySequence(m_modifiers).toString() << XKeysymToString(XKeycodeToKeysym(QX11Info::display(), m_x11key, 0));
110 }
111 _x_old_errhandler = XSetErrorHandler(_x_grabkey_errhandler);111 _x_old_errhandler = XSetErrorHandler(_x_grabkey_errhandler);
112 XGrabKey(QX11Info::display(), m_x11key, m_x11modifiers,112 XGrabKey(QX11Info::display(), m_x11key, m_x11modifiers,
113 QX11Info::appRootWindow(), True, GrabModeAsync, GrabModeAsync);113 QX11Info::appRootWindow(), True, GrabModeAsync, GrabModeAsync);
@@ -122,7 +122,11 @@
122{122{
123 Q_UNUSED(signal);123 Q_UNUSED(signal);
124 if (m_connections == 1) {124 if (m_connections == 1) {
125 UQ_DEBUG << "Ungrabbing hotkey" << QKeySequence(m_key | m_modifiers).toString();125 if (m_key != 0) {
126 UQ_DEBUG << "Ungrabbing hotkey" << QKeySequence(m_key | m_modifiers).toString();
127 } else {
128 UQ_DEBUG.nospace() << "Ungrabbing hotkey" << QKeySequence(m_modifiers).toString() << XKeysymToString(XKeycodeToKeysym(QX11Info::display(), m_x11key, 0));
129 }
126 XUngrabKey(QX11Info::display(), m_x11key, m_x11modifiers,130 XUngrabKey(QX11Info::display(), m_x11key, m_x11modifiers,
127 QX11Info::appRootWindow());131 QX11Info::appRootWindow());
128 }132 }
@@ -139,4 +143,22 @@
139 return false;143 return false;
140}144}
141145
146void
147Hotkey::translateModifiers(Qt::KeyboardModifiers modifiers)
148{
149 /* Translate the QT modifiers to X11 modifiers */
150 if (modifiers.testFlag(Qt::ShiftModifier)) {
151 m_x11modifiers |= ShiftMask ;
152 }
153 if (modifiers.testFlag(Qt::ControlModifier)) {
154 m_x11modifiers |= ControlMask ;
155 }
156 if (modifiers.testFlag(Qt::AltModifier)) {
157 m_x11modifiers |= Mod1Mask;
158 }
159 if (modifiers.testFlag(Qt::MetaModifier)) {
160 m_x11modifiers |= Mod4Mask;
161 }
162}
163
142#include "hotkey.moc"164#include "hotkey.moc"
143165
=== modified file 'libunity-2d-private/src/hotkey.h'
--- libunity-2d-private/src/hotkey.h 2012-02-03 13:36:16 +0000
+++ libunity-2d-private/src/hotkey.h 2012-04-02 16:31:23 +0000
@@ -27,15 +27,16 @@
27 friend class HotkeyMonitor;27 friend class HotkeyMonitor;
2828
29 Q_OBJECT29 Q_OBJECT
30 Q_PROPERTY(Qt::Key key READ key NOTIFY keyChanged)30 Q_PROPERTY(int key READ key NOTIFY keyChanged)
31 Q_PROPERTY(Qt::KeyboardModifiers modifiers READ modifiers NOTIFY modifiersChanged)31 Q_PROPERTY(Qt::KeyboardModifiers modifiers READ modifiers NOTIFY modifiersChanged)
3232
33public:33public:
34 Qt::Key key() const { return m_key; }34 int key() const { return m_key; }
35 uint x11key() const { return m_x11key; }
35 Qt::KeyboardModifiers modifiers() const { return m_modifiers; }36 Qt::KeyboardModifiers modifiers() const { return m_modifiers; }
3637
37Q_SIGNALS:38Q_SIGNALS:
38 void keyChanged(Qt::Key key);39 void keyChanged(int key);
39 void modifiersChanged(Qt::KeyboardModifiers modifiers);40 void modifiersChanged(Qt::KeyboardModifiers modifiers);
40 void pressed();41 void pressed();
41 void released();42 void released();
@@ -46,11 +47,13 @@
4647
47private:48private:
48 Hotkey(Qt::Key key, Qt::KeyboardModifiers modifiers, QObject *parent);49 Hotkey(Qt::Key key, Qt::KeyboardModifiers modifiers, QObject *parent);
50 Hotkey(uint x11key, Qt::KeyboardModifiers modifiers, QObject *parent);
49 bool processNativeEvent(uint x11Keycode, uint x11Modifiers, bool isPressEvent);51 bool processNativeEvent(uint x11Keycode, uint x11Modifiers, bool isPressEvent);
52 void translateModifiers(Qt::KeyboardModifiers modifiers);
5053
51private:54private:
52 uint m_connections;55 uint m_connections;
53 Qt::Key m_key;56 int m_key;
54 Qt::KeyboardModifiers m_modifiers;57 Qt::KeyboardModifiers m_modifiers;
55 uint m_x11key;58 uint m_x11key;
56 uint m_x11modifiers;59 uint m_x11modifiers;
5760
=== modified file 'libunity-2d-private/src/hotkeymonitor.cpp'
--- libunity-2d-private/src/hotkeymonitor.cpp 2012-02-06 12:07:47 +0000
+++ libunity-2d-private/src/hotkeymonitor.cpp 2012-04-02 16:31:23 +0000
@@ -78,6 +78,21 @@
78 return hotkey;78 return hotkey;
79}79}
8080
81Hotkey*
82HotkeyMonitor::getHotkeyFor(uint x11Keycode, Qt::KeyboardModifiers modifiers)
83{
84 Q_FOREACH(Hotkey* currentHotkey, m_hotkeys) {
85 if (currentHotkey->x11key() == x11Keycode &&
86 currentHotkey->modifiers() == modifiers) {
87 return currentHotkey;
88 }
89 }
90
91 Hotkey *hotkey = new Hotkey(x11Keycode, modifiers, this);
92 m_hotkeys.append(hotkey);
93 return hotkey;
94}
95
81void HotkeyMonitor::disableModifiers(Qt::KeyboardModifiers modifiers)96void HotkeyMonitor::disableModifiers(Qt::KeyboardModifiers modifiers)
82{97{
83 m_disabledModifiers |= modifiers;98 m_disabledModifiers |= modifiers;
8499
=== modified file 'libunity-2d-private/src/hotkeymonitor.h'
--- libunity-2d-private/src/hotkeymonitor.h 2012-02-06 12:07:47 +0000
+++ libunity-2d-private/src/hotkeymonitor.h 2012-04-02 16:31:23 +0000
@@ -34,6 +34,7 @@
34 ~HotkeyMonitor();34 ~HotkeyMonitor();
3535
36 Hotkey* getHotkeyFor(Qt::Key key, Qt::KeyboardModifiers modifiers);36 Hotkey* getHotkeyFor(Qt::Key key, Qt::KeyboardModifiers modifiers);
37 Hotkey* getHotkeyFor(uint x11Keycode, Qt::KeyboardModifiers modifiers);
3738
38 void disableModifiers(Qt::KeyboardModifiers modifiers);39 void disableModifiers(Qt::KeyboardModifiers modifiers);
39 void enableModifiers(Qt::KeyboardModifiers modifiers);40 void enableModifiers(Qt::KeyboardModifiers modifiers);
4041
=== modified file 'libunity-2d-private/src/hotmodifier.cpp'
--- libunity-2d-private/src/hotmodifier.cpp 2012-02-20 16:51:19 +0000
+++ libunity-2d-private/src/hotmodifier.cpp 2012-04-02 16:31:23 +0000
@@ -29,6 +29,7 @@
29 QObject(parent)29 QObject(parent)
30, m_modifiers(modifiers)30, m_modifiers(modifiers)
31, m_pressed(false)31, m_pressed(false)
32, m_partiallyPressed(false)
32, m_held(false)33, m_held(false)
33, m_ignored(false)34, m_ignored(false)
34, m_otherModifierPressed(false)35, m_otherModifierPressed(false)
@@ -56,13 +57,14 @@
56void57void
57HotModifier::onModifiersChanged(Qt::KeyboardModifiers modifiers)58HotModifier::onModifiersChanged(Qt::KeyboardModifiers modifiers)
58{59{
59 bool pressed = m_modifiers & modifiers;60 const bool partiallyPressed = m_modifiers & modifiers;
60 bool otherModifierPressed = modifiers ^ m_modifiers;61 const bool pressed = m_modifiers == modifiers;
62 const bool otherModifierPressed = modifiers & ~m_modifiers;
6163
62 /* if a modifier other than m_modifier is pressed, we take note of it because when the64 /* if a modifier other than m_modifier is pressed, we take note of it because when the
63 other modifier is released, m_modifier is emitted again. If we don't ignore this65 other modifier is released, m_modifier is emitted again. If we don't ignore this
64 event, we generate a tap, which is wrong */66 event, we generate a tap, which is wrong */
65 if (otherModifierPressed && pressed) {67 if (otherModifierPressed && partiallyPressed) {
66 m_otherModifierPressed = true;68 m_otherModifierPressed = true;
67 }69 }
6870
@@ -72,17 +74,18 @@
72 m_held = false;74 m_held = false;
73 Q_EMIT heldChanged(m_held);75 Q_EMIT heldChanged(m_held);
74 }76 }
75 if (!m_pressed && pressed) {77 if (!m_partiallyPressed && partiallyPressed) {
76 m_ignored = false;78 m_ignored = false;
77 m_holdTimer.start();79 m_holdTimer.start();
78 }80 }
79 /* Case where "other modifier" is released while m_modifier still pressed. In this case81 /* Case where "other modifier" is released while m_modifier still pressed. In this case
80 we want to have the entire modifier press event ignored, to prevent generating a tap */82 we want to have the entire modifier press event ignored, to prevent generating a tap */
81 if (m_otherModifierPressed && otherModifierPressed && pressed) {83 if (m_otherModifierPressed && otherModifierPressed && partiallyPressed) {
82 m_otherModifierPressed = false;84 m_otherModifierPressed = false;
83 m_ignored = true;85 m_ignored = true;
84 }86 }
85 m_pressed = pressed;87 m_pressed = pressed;
88 m_partiallyPressed = partiallyPressed;
86}89}
8790
88void91void
@@ -109,6 +112,7 @@
109{112{
110 m_holdTimer.stop();113 m_holdTimer.stop();
111 m_pressed = false;114 m_pressed = false;
115 m_partiallyPressed = false;
112 m_ignored = false;116 m_ignored = false;
113 if (m_held) {117 if (m_held) {
114 m_held = false;118 m_held = false;
115119
=== modified file 'libunity-2d-private/src/hotmodifier.h'
--- libunity-2d-private/src/hotmodifier.h 2012-02-20 16:51:19 +0000
+++ libunity-2d-private/src/hotmodifier.h 2012-04-02 16:31:23 +0000
@@ -52,6 +52,7 @@
52 QTimer m_holdTimer;52 QTimer m_holdTimer;
53 Qt::KeyboardModifiers m_modifiers;53 Qt::KeyboardModifiers m_modifiers;
54 bool m_pressed;54 bool m_pressed;
55 bool m_partiallyPressed;
55 bool m_held;56 bool m_held;
56 bool m_ignored;57 bool m_ignored;
57 bool m_otherModifierPressed;58 bool m_otherModifierPressed;
5859
=== modified file 'libunity-2d-private/tests/CMakeLists.txt'
--- libunity-2d-private/tests/CMakeLists.txt 2012-03-20 14:50:42 +0000
+++ libunity-2d-private/tests/CMakeLists.txt 2012-04-02 16:31:23 +0000
@@ -41,6 +41,7 @@
41 imageutilitiestest41 imageutilitiestest
42 pointerbarriertest42 pointerbarriertest
43 hotkeytest43 hotkeytest
44 gkeysequenceparser
44 )45 )
4546
46target_link_libraries(pointerbarriertest ${X11_XTest_LIB})47target_link_libraries(pointerbarriertest ${X11_XTest_LIB})
4748
=== added file 'libunity-2d-private/tests/gkeysequenceparser.cpp'
--- libunity-2d-private/tests/gkeysequenceparser.cpp 1970-01-01 00:00:00 +0000
+++ libunity-2d-private/tests/gkeysequenceparser.cpp 2012-04-02 16:31:23 +0000
@@ -0,0 +1,66 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2012 Canonical Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <QObject>
20#include <unitytestmacro.h>
21
22#include "gkeysequenceparser.h"
23
24class GKeySequenceParserTest : public QObject
25{
26 Q_OBJECT
27private Q_SLOTS:
28 void testParsing()
29 {
30 int x11Code;
31 Qt::KeyboardModifiers modifiers;
32 bool success;
33
34 success = GKeySequenceParser::parse("<Alt>", &x11Code, &modifiers);
35 QVERIFY(success);
36 QCOMPARE(x11Code, 0);
37 QCOMPARE(modifiers, Qt::AltModifier);
38
39 success = GKeySequenceParser::parse("<Control><Shift><Alt><Super>k", &x11Code, &modifiers);
40 QVERIFY(success);
41 QCOMPARE(x11Code, 45);
42 QCOMPARE(modifiers, Qt::AltModifier | Qt::ShiftModifier | Qt::ControlModifier | Qt::MetaModifier);
43
44 success = GKeySequenceParser::parse("<Control><Shift><Alt><Super>ccedillaj", &x11Code, &modifiers);
45 QVERIFY(!success);
46
47 success = GKeySequenceParser::parse("<Controll><Shift><Alt><Super>ccedillaj", &x11Code, &modifiers);
48 QVERIFY(!success);
49
50 success = GKeySequenceParser::parse("<Control<Shift><Alt><Super>ccedillaj", &x11Code, &modifiers);
51 QVERIFY(!success);
52
53 success = GKeySequenceParser::parse("<Alt>+p", &x11Code, &modifiers);
54 QVERIFY(!success);
55
56 success = GKeySequenceParser::parse("<>", &x11Code, &modifiers);
57 QVERIFY(!success);
58
59 success = GKeySequenceParser::parse("><", &x11Code, &modifiers);
60 QVERIFY(!success);
61 }
62};
63
64QAPP_TEST_MAIN(GKeySequenceParserTest)
65
66#include "gkeysequenceparser.moc"
0\ No newline at end of file67\ No newline at end of file
168
=== modified file 'libunity-2d-private/tests/hotkeytest.cpp'
--- libunity-2d-private/tests/hotkeytest.cpp 2012-03-16 17:15:17 +0000
+++ libunity-2d-private/tests/hotkeytest.cpp 2012-04-02 16:31:23 +0000
@@ -51,7 +51,7 @@
51 void onKeyPressed() {51 void onKeyPressed() {
52 Hotkey* hotkey = qobject_cast<Hotkey*>(sender());52 Hotkey* hotkey = qobject_cast<Hotkey*>(sender());
5353
54 m_key = hotkey->key();54 m_key = (Qt::Key)hotkey->key();
55 m_modifiers = hotkey->modifiers();55 m_modifiers = hotkey->modifiers();
56 ++m_count;56 ++m_count;
57 }57 }
5858
=== modified file 'shell/app/shellmanager.cpp'
--- shell/app/shellmanager.cpp 2012-03-16 11:03:24 +0000
+++ shell/app/shellmanager.cpp 2012-04-02 16:31:23 +0000
@@ -27,6 +27,7 @@
2727
28// libunity-2d-private28// libunity-2d-private
29#include <debug_p.h>29#include <debug_p.h>
30#include <gkeysequenceparser.h>
30#include <hotmodifier.h>31#include <hotmodifier.h>
31#include <hotkeymonitor.h>32#include <hotkeymonitor.h>
32#include <hotkey.h>33#include <hotkey.h>
@@ -42,6 +43,9 @@
42#include <unity2ddebug.h>43#include <unity2ddebug.h>
43#include <gobjectcallback.h>44#include <gobjectcallback.h>
4445
46// libqtgconf
47#include <gconfitem-qml-wrapper.h>
48
45// bamf49// bamf
46#include "bamf-window.h"50#include "bamf-window.h"
47#include "bamf-matcher.h"51#include "bamf-matcher.h"
@@ -55,6 +59,7 @@
55static const char* COMMANDS_LENS_ID = "commands.lens";59static const char* COMMANDS_LENS_ID = "commands.lens";
56static const int DASH_MIN_SCREEN_WIDTH = 1280;60static const int DASH_MIN_SCREEN_WIDTH = 1280;
57static const int DASH_MIN_SCREEN_HEIGHT = 1084;61static const int DASH_MIN_SCREEN_HEIGHT = 1084;
62static const char* HUD_SHORTCUT_KEY = "/apps/compiz-1/plugins/unityshell/screen0/options/show_hud";
5863
59GOBJECT_CALLBACK1(activeWorkspaceChangedCB, "onActiveWorkspaceChanged");64GOBJECT_CALLBACK1(activeWorkspaceChangedCB, "onActiveWorkspaceChanged");
6065
@@ -96,9 +101,14 @@
96 QString m_dashActiveLens; /* Lens id of the active lens */101 QString m_dashActiveLens; /* Lens id of the active lens */
97102
98 HotModifier* m_superHotModifier;103 HotModifier* m_superHotModifier;
99 HotModifier* m_altHotModifier;104
105 // Only one of the two is non null at a time
106 HotModifier* m_hudHotModifier;
107 Hotkey* m_hudHotKey;
100108
101 WId m_last_focused_window;109 WId m_last_focused_window;
110
111 GConfItemQmlWrapper *m_gconfItem;
102};112};
103113
104114
@@ -270,6 +280,13 @@
270{280{
271 d->q = this;281 d->q = this;
272 d->m_sourceFileUrl = sourceFileUrl;282 d->m_sourceFileUrl = sourceFileUrl;
283 d->m_hudHotModifier = NULL;
284 d->m_hudHotKey = NULL;
285
286 d->m_gconfItem = new GConfItemQmlWrapper(this);
287 connect(d->m_gconfItem, SIGNAL(valueChanged()), this, SLOT(onHudActivationShortcutChanged()));
288 d->m_gconfItem->setKey(HUD_SHORTCUT_KEY);
289 onHudActivationShortcutChanged();
273290
274 qmlRegisterUncreatableType<ShellDeclarativeView>("Unity2d", 1, 0, "ShellDeclarativeView", "This can only be created from C++");291 qmlRegisterUncreatableType<ShellDeclarativeView>("Unity2d", 1, 0, "ShellDeclarativeView", "This can only be created from C++");
275 qmlRegisterUncreatableType<ShellManager>("Unity2d", 1, 0, "ShellManager", "This can only be created from C++");292 qmlRegisterUncreatableType<ShellManager>("Unity2d", 1, 0, "ShellManager", "This can only be created from C++");
@@ -288,10 +305,6 @@
288 connect(d->m_superHotModifier, SIGNAL(tapped()), SLOT(toggleDashRequested()));305 connect(d->m_superHotModifier, SIGNAL(tapped()), SLOT(toggleDashRequested()));
289 connect(d->m_superHotModifier, SIGNAL(heldChanged(bool)), SIGNAL(superKeyHeldChanged(bool)));306 connect(d->m_superHotModifier, SIGNAL(heldChanged(bool)), SIGNAL(superKeyHeldChanged(bool)));
290307
291 /* Alt tap shows the HUD */
292 d->m_altHotModifier = KeyboardModifiersMonitor::instance()->getHotModifierFor(Qt::AltModifier);
293 connect(d->m_altHotModifier, SIGNAL(tapped()), SLOT(toggleHudRequested()));
294
295 /* Alt+F1 reveals the launcher and gives the keyboard focus to the Dash Button. */308 /* Alt+F1 reveals the launcher and gives the keyboard focus to the Dash Button. */
296 Hotkey* altF1 = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_F1, Qt::AltModifier);309 Hotkey* altF1 = HotkeyMonitor::instance().getHotkeyFor(Qt::Key_F1, Qt::AltModifier);
297 connect(altF1, SIGNAL(pressed()), SLOT(onAltF1Pressed()));310 connect(altF1, SIGNAL(pressed()), SLOT(onAltF1Pressed()));
@@ -479,6 +492,37 @@
479 Q_EMIT lastFocusedWindowChanged(d->m_last_focused_window);492 Q_EMIT lastFocusedWindowChanged(d->m_last_focused_window);
480}493}
481494
495void ShellManager::onHudActivationShortcutChanged()
496{
497 // TODO It might make sense to abstract this logic
498 // of switching between hotkey and hotmodifier and put it
499 // in a class in libunity-2d-private
500 if (d->m_hudHotModifier) {
501 d->m_hudHotModifier->disconnect(this);
502 d->m_hudHotModifier = NULL;
503 }
504 if (d->m_hudHotKey) {
505 d->m_hudHotKey->disconnect(this);
506 d->m_hudHotKey = NULL;
507 }
508
509 int x11KeyCode;
510 Qt::KeyboardModifiers modifiers;
511 const QString shortcut = d->m_gconfItem->getValue().toString();
512 const bool success = GKeySequenceParser::parse(shortcut, &x11KeyCode, &modifiers);
513 if (success) {
514 if (x11KeyCode != 0) {
515 d->m_hudHotKey = HotkeyMonitor::instance().getHotkeyFor(x11KeyCode, modifiers);
516 connect(d->m_hudHotKey, SIGNAL(pressed()), SLOT(toggleHudRequested()));
517 } else if (modifiers != Qt::NoModifier) {
518 d->m_hudHotModifier = KeyboardModifiersMonitor::instance()->getHotModifierFor(modifiers);
519 connect(d->m_hudHotModifier, SIGNAL(tapped()), SLOT(toggleHudRequested()));
520 }
521 } else {
522 qWarning().nospace() << "Could not parse the key sequence " << shortcut << ". HUD won't be activated";
523 }
524}
525
482/* ----------------- super key handling ---------------- */526/* ----------------- super key handling ---------------- */
483527
484void528void
@@ -580,7 +624,7 @@
580 Shortcut for 0 should activate item with index 10.624 Shortcut for 0 should activate item with index 10.
581 In other words, the indexes are activated in the same order as625 In other words, the indexes are activated in the same order as
582 the keys appear on a standard keyboard. */626 the keys appear on a standard keyboard. */
583 Qt::Key key = hotkey->key();627 const int key = hotkey->key();
584 if (key >= Qt::Key_1 && key <= Qt::Key_9) {628 if (key >= Qt::Key_1 && key <= Qt::Key_9) {
585 int index = key - Qt::Key_0;629 int index = key - Qt::Key_0;
586 if (hotkey->modifiers() & Qt::ShiftModifier) {630 if (hotkey->modifiers() & Qt::ShiftModifier) {
587631
=== modified file 'shell/app/shellmanager.h'
--- shell/app/shellmanager.h 2012-03-14 08:29:06 +0000
+++ shell/app/shellmanager.h 2012-04-02 16:31:23 +0000
@@ -117,6 +117,8 @@
117117
118 void onActiveWorkspaceChanged();118 void onActiveWorkspaceChanged();
119119
120 void onHudActivationShortcutChanged();
121
120private:122private:
121 Q_DISABLE_COPY(ShellManager)123 Q_DISABLE_COPY(ShellManager)
122 ShellManagerPrivate * const d;124 ShellManagerPrivate * const d;
123125
=== modified file 'tests/manual-tests/hud.txt'
--- tests/manual-tests/hud.txt 2012-03-20 11:14:30 +0000
+++ tests/manual-tests/hud.txt 2012-04-02 16:31:23 +0000
@@ -15,3 +15,13 @@
15 * Use arrow keys to navigate up/down through the options returned15 * Use arrow keys to navigate up/down through the options returned
1616
17--> Check Orca speaks the contents of the results17--> Check Orca speaks the contents of the results
18
19----
20 * Go into ccsm
21 * Change Key to Show HUD to Super+Alt
22--> Verify Super+Alt shows the HUD
23
24----
25 * Go into ccsm
26 * Change Key to Show HUD to Super+Alt
27--> Verify Super+Alt shows the HUD
18\ No newline at end of file28\ No newline at end of file

Subscribers

People subscribed via source and target branches