Merge lp:~thumper/unity/non-modifier-hud into lp:unity

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 2223
Proposed branch: lp:~thumper/unity/non-modifier-hud
Merge into: lp:unity
Diff against target: 166 lines (+75/-26)
4 files modified
plugins/unityshell/src/unityshell.cpp (+47/-25)
plugins/unityshell/src/unityshell.h (+1/-0)
tests/autopilot/autopilot/tests/__init__.py (+2/-0)
tests/autopilot/autopilot/tests/test_hud.py (+25/-1)
To merge this branch: bzr merge lp:~thumper/unity/non-modifier-hud
Reviewer Review Type Date Requested Status
Daniel van Vugt Approve
Thomi Richards (community) Approve
Review via email: mp+100906@code.launchpad.net

Commit message

Allow Unity to correctly respond to a non-modifier key-binding for "show hud".

Description of the change

= Problem =

Due to the way the HUD was initially designed to work, there was assumed behaviour in the handlers for the key-bindings that caused non-modifier key-bindings for the HUD reveal to not work very well.

= Solution =

When there is an initiate event from compiz, if the key-binding is modifier only, then the keycode is unset (or zero in the future). If we have a key-code, then the show_hud key-binding has been remapped, and we should show the hud on the initiate (key down), rather than waiting for a key-release to determine a tap.

= Tests =

Autopilot tests included working with <Super>h and <Ctrl><Alt>h.

To post a comment you must log in.
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) :
review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) :
review: Approve
Revision history for this message
Unity Merger (unity-merger) wrote :

No commit message specified.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/unityshell.cpp'
2--- plugins/unityshell/src/unityshell.cpp 2012-04-04 00:28:31 +0000
3+++ plugins/unityshell/src/unityshell.cpp 2012-04-05 03:33:18 +0000
4@@ -1942,10 +1942,55 @@
5 PluginAdapter::Default ()->restoreInputFocus ();
6 }
7
8+bool UnityScreen::ShowHud()
9+{
10+ if (switcher_controller_->Visible())
11+ {
12+ LOG_ERROR(logger) << "this should never happen";
13+ return false; // early exit if the switcher is open
14+ }
15+
16+ if (hud_controller_->IsVisible())
17+ {
18+ ubus_manager_.SendMessage(UBUS_HUD_CLOSE_REQUEST);
19+ }
20+ else
21+ {
22+ // Handles closing KeyNav (Alt+F1) if the hud is about to show
23+ if (launcher_controller_->KeyNavIsActive())
24+ launcher_controller_->KeyNavTerminate(false);
25+
26+ // If an overlay is open, it must be the dash! Close it!
27+ if (launcher_controller_->IsOverlayOpen())
28+ dash_controller_->HideDash();
29+
30+ hud_controller_->ShowHud();
31+ }
32+
33+ // Consume the event.
34+ return true;
35+}
36+
37 bool UnityScreen::ShowHudInitiate(CompAction* action,
38 CompAction::State state,
39 CompOption::Vector& options)
40 {
41+ // Look to see if there is a keycode. If there is, then this isn't a
42+ // modifier only keybinding.
43+ int key_code = 0;
44+ if (options[6].type() != CompOption::TypeUnset)
45+ {
46+ key_code = options[6].value().i();
47+ LOG_DEBUG(logger) << "HUD initiate key code: " << key_code;
48+ // show it now, no timings or terminate needed.
49+ return ShowHud();
50+ }
51+ else
52+ {
53+ LOG_DEBUG(logger) << "HUD initiate key code option not set, modifier only keypress.";
54+ }
55+
56+
57 // to receive the Terminate event
58 if (state & CompAction::StateInitKey)
59 action->setState(action->state() | CompAction::StateTermKey);
60@@ -1966,7 +2011,7 @@
61
62 action->setState(action->state() & ~CompAction::StateTermKey);
63
64- // And only respond to key taps
65+ // If we have a modifier only keypress, check for tap and timing.
66 if (!(state & CompAction::StateTermTapped))
67 return false;
68
69@@ -1978,30 +2023,7 @@
70 return false;
71 }
72
73- if (switcher_controller_->Visible())
74- {
75- LOG_ERROR(logger) << "this should never happen";
76- return false; // early exit if the switcher is open
77- }
78-
79- if (hud_controller_->IsVisible())
80- {
81- ubus_manager_.SendMessage(UBUS_HUD_CLOSE_REQUEST);
82- }
83- else
84- {
85- // Handles closing KeyNav (Alt+F1) if the hud is about to show
86- if (launcher_controller_->KeyNavIsActive())
87- launcher_controller_->KeyNavTerminate(false);
88-
89- // If an overlay is open, it must be the dash! Close it!
90- if (launcher_controller_->IsOverlayOpen())
91- dash_controller_->HideDash();
92-
93- hud_controller_->ShowHud();
94- }
95-
96- return true;
97+ return ShowHud();
98 }
99
100 gboolean UnityScreen::initPluginActions(gpointer data)
101
102=== modified file 'plugins/unityshell/src/unityshell.h'
103--- plugins/unityshell/src/unityshell.h 2012-03-30 04:00:05 +0000
104+++ plugins/unityshell/src/unityshell.h 2012-04-05 03:33:18 +0000
105@@ -206,6 +206,7 @@
106 bool altTabNextWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
107 bool altTabPrevWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
108
109+ bool ShowHud();
110 /* handle hud key activations */
111 bool ShowHudInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
112 bool ShowHudTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options);
113
114=== modified file 'tests/autopilot/autopilot/tests/__init__.py'
115--- tests/autopilot/autopilot/tests/__init__.py 2012-04-03 13:48:07 +0000
116+++ tests/autopilot/autopilot/tests/__init__.py 2012-04-05 03:33:18 +0000
117@@ -290,6 +290,8 @@
118 """
119 old_value = self._set_compiz_option(plugin_name, setting_name, setting_value)
120 self.addCleanup(self._set_compiz_option, plugin_name, setting_name, old_value)
121+ # Allow unity time to respond to the new setting.
122+ time.sleep(0.5)
123
124 def _set_compiz_option(self, plugin_name, option_name, option_value):
125 logger.info("Setting compiz option '%s' in plugin '%s' to %r",
126
127=== modified file 'tests/autopilot/autopilot/tests/test_hud.py'
128--- tests/autopilot/autopilot/tests/test_hud.py 2012-04-04 00:28:31 +0000
129+++ tests/autopilot/autopilot/tests/test_hud.py 2012-04-05 03:33:18 +0000
130@@ -401,7 +401,6 @@
131 def test_hud_icon_is_shown(self):
132 """Tests that the correct HUD icon is shown"""
133 self.reveal_hud()
134- self.hud.visible
135 sleep(.5)
136
137 hud_launcher_icon = self.hud.get_launcher_icon()
138@@ -463,3 +462,28 @@
139 sleep(.5)
140
141 self.assertThat(self.hud.icon.icon_name, Equals(calc.icon))
142+
143+
144+class HudAlternativeKeybindingTests(HudTestsBase):
145+
146+ def test_super_h(self):
147+ """Test hud reveal on <Super>h."""
148+ self.set_unity_option("show_hud", "<Super>h")
149+ # Don't use reveal_hud, but be explicit in the keybindings.
150+ self.keyboard.press_and_release("Super+h")
151+ for counter in range(10):
152+ sleep(1)
153+ if self.hud.visible:
154+ break
155+ self.assertTrue(self.hud.visible, "HUD did not appear.")
156+
157+ def test_ctrl_alt_h(self):
158+ """Test hud reveal on <Contrl><Alt>h."""
159+ self.set_unity_option("show_hud", "<Control><Alt>h")
160+ # Don't use reveal_hud, but be explicit in the keybindings.
161+ self.keyboard.press_and_release("Ctrl+Alt+h")
162+ for counter in range(10):
163+ sleep(1)
164+ if self.hud.visible:
165+ break
166+ self.assertTrue(self.hud.visible, "HUD did not appear.")