Merge lp:~brandontschaefer/unity/lp.1066442-fix into lp:unity

Proposed by Brandon Schaefer
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 3235
Proposed branch: lp:~brandontschaefer/unity/lp.1066442-fix
Merge into: lp:unity
Diff against target: 95 lines (+22/-8)
2 files modified
hud/HudView.cpp (+11/-8)
tests/autopilot/unity/tests/test_hud.py (+11/-0)
To merge this branch: bzr merge lp:~brandontschaefer/unity/lp.1066442-fix
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Marco Trevisan (Treviño) Approve
Review via email: mp+153924@code.launchpad.net

This proposal supersedes a proposal from 2013-03-15.

Commit message

The HudButtons no longer receive mouse events until the mouse is being moved over the HudView. It resets when any typing happens, so the mouse can no longer steal button focus with out moving it (which in that case you want the button to focus :)

Description of the change

=== Problem ===
When items for the hud appear, and the mouse was over where it appeared at, it would steal button focus.

=== Fix ===
The buttons no longer receives mouse events until the mouse is being moved over the HudView. It resets when any typing happens, so the mouse can no longer steal button focus with out moving it (which in that case you want the button to focus :)

=== Test ===
AP Test

To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

It works well here, thanks.

review: Approve
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Confirming again to work...

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hud/HudView.cpp'
2--- hud/HudView.cpp 2013-02-26 12:57:59 +0000
3+++ hud/HudView.cpp 2013-03-18 20:02:24 +0000
4@@ -114,6 +114,11 @@
5 }
6 });
7
8+ mouse_move.connect([this] (int x, int y, int dx, int dy, unsigned long mouse_button, unsigned long special_key) {
9+ for (auto button : buttons_)
10+ button->SetInputEventSensitivity(true);
11+ });
12+
13 mouse_down.connect(sigc::mem_fun(this, &View::OnMouseButtonDown));
14
15 Relayout();
16@@ -182,7 +187,6 @@
17 }
18 }
19
20-
21 void View::ResetToDefault()
22 {
23 SetQueries(Hud::Queries());
24@@ -238,6 +242,7 @@
25
26 HudButton::Ptr button(new HudButton());
27 buttons_.push_front(button);
28+ button->SetInputEventSensitivity(false);
29 button->SetMinimumWidth(content_width);
30 button->SetMaximumWidth(content_width);
31 button->SetQuery(query);
32@@ -248,7 +253,7 @@
33 query_activated.emit(dynamic_cast<HudButton*>(view)->GetQuery());
34 });
35
36- button->mouse_move.connect([&](int x, int y, int dx, int dy, unsigned long mouse_button, unsigned long special_key) {
37+ button->mouse_move.connect([this](int x, int y, int dx, int dy, unsigned long mouse_button, unsigned long special_key) {
38 if (keyboard_stole_focus_)
39 {
40 MouseStealsHudButtonFocus();
41@@ -256,19 +261,19 @@
42 }
43 });
44
45- button->mouse_enter.connect([&](int x, int y, unsigned long mouse_button, unsigned long special_key) {
46+ button->mouse_enter.connect([this](int x, int y, unsigned long mouse_button, unsigned long special_key) {
47 MouseStealsHudButtonFocus();
48 });
49
50- button->mouse_leave.connect([&](int x, int y, unsigned long mouse_button, unsigned long special_key) {
51+ button->mouse_leave.connect([this](int x, int y, unsigned long mouse_button, unsigned long special_key) {
52 SelectLastFocusedButton();
53 });
54
55- button->key_nav_focus_activate.connect([&](nux::Area* area) {
56+ button->key_nav_focus_activate.connect([this](nux::Area* area) {
57 query_activated.emit(dynamic_cast<HudButton*>(area)->GetQuery());
58 });
59
60- button->key_nav_focus_change.connect([&](nux::Area* area, bool recieving, nux::KeyNavDirection direction){
61+ button->key_nav_focus_change.connect([this](nux::Area* area, bool recieving, nux::KeyNavDirection direction){
62 if (recieving)
63 query_selected.emit(dynamic_cast<HudButton*>(area)->GetQuery());
64 });
65@@ -418,9 +423,7 @@
66 search_changed.emit(search_string);
67
68 for(auto button : buttons_)
69- {
70 button->fake_focused = false;
71- }
72
73 if (!buttons_.empty())
74 buttons_.back()->fake_focused = true;
75
76=== modified file 'tests/autopilot/unity/tests/test_hud.py'
77--- tests/autopilot/unity/tests/test_hud.py 2013-02-04 19:54:47 +0000
78+++ tests/autopilot/unity/tests/test_hud.py 2013-03-18 20:02:24 +0000
79@@ -459,6 +459,17 @@
80
81 self.assertProperty(char_win, is_active=True)
82
83+ def test_mouse_does_not_steal_button_focus(self):
84+ """When typing in the hud the mouse must not steal button focus."""
85+
86+ self.unity.hud.ensure_visible()
87+
88+ (x,y,w,h) = self.unity.hud.view.geometry
89+ self.mouse.move(w/4, h/4)
90+
91+ self.keyboard.type("a")
92+ self.assertThat(self.unity.hud.view.selected_button, Eventually(Equals(1)))
93+
94
95 class HudLauncherInteractionsTests(HudTestsBase):
96