Merge lp:~brandontschaefer/unity/lp.1215630 into lp:unity

Proposed by Brandon Schaefer
Status: Rejected
Rejected by: Brandon Schaefer
Proposed branch: lp:~brandontschaefer/unity/lp.1215630
Merge into: lp:unity
Diff against target: 213 lines (+86/-23)
4 files modified
launcher/SwitcherView.cpp (+23/-4)
launcher/SwitcherView.h (+2/-0)
tests/autopilot/unity/emulators/switcher.py (+19/-0)
tests/autopilot/unity/tests/test_switcher.py (+42/-19)
To merge this branch: bzr merge lp:~brandontschaefer/unity/lp.1215630
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Christopher Townsend Needs Information
Review via email: mp+181925@code.launchpad.net

Commit message

Only change the selection of the icon if the delta x/y is greater then 3 (either direction).

Description of the change

Only change the selection of the icon if the delta x/y is greater then 3 (either direction).

This does mean you could slowly move across an icon without it changing.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Christopher Townsend (townsend) wrote :

Works as intended, but a couple of things.

- I'm wondering why you switched the const and var type in the constant variable declarations. Seems easier to read with const placed first.
- Also, is it possible to have an AP test for testing a slight mouse bump (not sure if it is)?

review: Needs Information
3479. By Brandon Schaefer

* On the first time the switcher view is opened, check if the mouse is over an icon.
  if so ignore it until it enters a new icon.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
3480. By Brandon Schaefer

* Clean up switcher mouse ap test
* Add new AP test

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

The approach seems fine to me, but this would lead to checking the mouse pointer on start whether there's a mouse movement or not, and it does that in sync way (blame Xorg!)... So why not just using something like this instead: http://pastebin.ubuntu.com/6055505/ ?

Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Thats a way better solution... Ill get to this tomorrow (as I shouldn't be checking my email ;).

Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Unmerged revisions

3480. By Brandon Schaefer

* Clean up switcher mouse ap test
* Add new AP test

3479. By Brandon Schaefer

* On the first time the switcher view is opened, check if the mouse is over an icon.
  if so ignore it until it enters a new icon.

3478. By Brandon Schaefer

* If the mouse move delta x/y is to small, ignore that event. Dont
  want accidental bumping to cause unwanted selection changes.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/SwitcherView.cpp'
2--- launcher/SwitcherView.cpp 2013-08-09 17:51:06 +0000
3+++ launcher/SwitcherView.cpp 2013-08-31 01:29:50 +0000
4@@ -36,9 +36,9 @@
5
6 namespace
7 {
8- const unsigned int VERTICAL_PADDING = 45;
9- const unsigned int SPREAD_OFFSET = 100;
10- const unsigned int EXTRA_ICON_SPACE = 10;
11+ unsigned int const VERTICAL_PADDING = 45;
12+ unsigned int const SPREAD_OFFSET = 100;
13+ unsigned int const EXTRA_ICON_SPACE = 10;
14 }
15
16 NUX_IMPLEMENT_OBJECT_TYPE(SwitcherView);
17@@ -61,6 +61,7 @@
18 , last_icon_selected_(-1)
19 , last_detail_icon_selected_(-1)
20 , target_sizes_set_(false)
21+ , check_mouse_first_time_(true)
22 {
23 icon_renderer_->pip_style = OVER_TILE;
24 icon_renderer_->monitor = monitors::MAX;
25@@ -114,6 +115,7 @@
26 .add("animation-length", animation_length)
27 .add("spread-size", (float)spread_size)
28 .add("label", text_view_->GetText())
29+ .add("last_icon_selected", last_icon_selected_)
30 .add("spread_offset", SPREAD_OFFSET)
31 .add("label_visible", text_view_->IsVisible());
32 }
33@@ -232,7 +234,7 @@
34 return {geo.x + x, geo.y + y};
35 }
36
37-void SwitcherView::RecvMouseMove(int x, int y, int /*dx*/, int /*dy*/, unsigned long /*button_flags*/, unsigned long /*key_flags*/)
38+void SwitcherView::RecvMouseMove(int x, int y, int dx, int dy, unsigned long /*button_flags*/, unsigned long /*key_flags*/)
39 {
40 if (model_->detail_selection)
41 {
42@@ -773,6 +775,23 @@
43 last_background_ = background_geo;
44
45 icon_renderer_->PreprocessIcons(last_args_, GetGeometry());
46+
47+ if (check_mouse_first_time_)
48+ {
49+ CheckMouseInsideIconOnStart();
50+ }
51+}
52+
53+void SwitcherView::CheckMouseInsideIconOnStart()
54+{
55+ int monitor = unity::UScreen::GetDefault()->GetMonitorWithMouse();
56+ nux::Geometry const& geo = unity::UScreen::GetDefault()->GetMonitorGeometry(monitor);
57+
58+ nux::Point const& screen_pt = nux::GetGraphicsDisplay()->GetMouseScreenCoord();
59+ nux::Point const& pt = {screen_pt.x - geo.x, screen_pt.y - geo.y};
60+
61+ last_icon_selected_ = IconIndexAt(pt.x - SPREAD_OFFSET, pt.y - SPREAD_OFFSET);
62+ check_mouse_first_time_ = false;
63 }
64
65 nux::Geometry SwitcherView::GetBackgroundGeometry()
66
67=== modified file 'launcher/SwitcherView.h'
68--- launcher/SwitcherView.h 2013-08-09 17:51:06 +0000
69+++ launcher/SwitcherView.h 2013-08-31 01:29:50 +0000
70@@ -141,6 +141,7 @@
71 void SaveLast();
72
73 bool CheckMouseInsideBackground(int x, int y) const;
74+ void CheckMouseInsideIconOnStart();
75
76 SwitcherModel::Ptr model_;
77 ui::LayoutSystem layout_system_;
78@@ -150,6 +151,7 @@
79 int last_icon_selected_;
80 int last_detail_icon_selected_;
81 bool target_sizes_set_;
82+ bool check_mouse_first_time_;
83
84 std::list<ui::RenderArg> last_args_;
85 std::list<ui::RenderArg> saved_args_;
86
87=== modified file 'tests/autopilot/unity/emulators/switcher.py'
88--- tests/autopilot/unity/emulators/switcher.py 2013-07-17 21:54:34 +0000
89+++ tests/autopilot/unity/emulators/switcher.py 2013-08-31 01:29:50 +0000
90@@ -234,6 +234,10 @@
91 class SwitcherView(UnityIntrospectionObject):
92 """An emulator class for interacting with with SwitcherView."""
93
94+ def __init__(self, *args, **kwargs):
95+ super(SwitcherView, self).__init__(*args, **kwargs)
96+ self._mouse = Mouse.create()
97+
98 @property
99 def icon_args(self):
100 return self.get_children_by_type(RenderArgs);
101@@ -242,6 +246,21 @@
102 def detail_icons(self):
103 return self.get_children_by_type(LayoutWindow);
104
105+ def move_over_icon(self, index):
106+ offset = self.spread_offset
107+ icon_arg = self.icon_args[index]
108+
109+ x = icon_arg.logical_center_x + offset
110+ y = icon_arg.logical_center_y + offset
111+
112+ self._mouse.move(x,y)
113+
114+ def move_over_detail_icon(self, index):
115+ offset = self.spread_offset
116+ x = self.detail_icons[index].x + offset
117+ y = self.detail_icons[index].y + offset
118+
119+ self._mouse.move(x,y)
120
121 class RenderArgs(UnityIntrospectionObject):
122 """An emulator class for interacting with the RenderArgs class."""
123
124=== modified file 'tests/autopilot/unity/tests/test_switcher.py'
125--- tests/autopilot/unity/tests/test_switcher.py 2013-08-27 21:43:12 +0000
126+++ tests/autopilot/unity/tests/test_switcher.py 2013-08-31 01:29:50 +0000
127@@ -576,16 +576,49 @@
128 self.addCleanup(self.unity.switcher.terminate)
129
130 index = self.unity.switcher.selection_index
131- offset = self.unity.switcher.view.spread_offset
132-
133- icon_arg = self.unity.switcher.view.icon_args[index]
134- x = icon_arg.logical_center_x + offset
135- y = icon_arg.logical_center_y + offset
136- self.mouse.move(x, y)
137+ self.unity.switcher.view.move_over_icon(index);
138 self.mouse.click()
139
140 self.assertProperty(char_win1, is_focused=True)
141
142+ def test_mouse_doesnt_hightlight_icon_if_over_on_start(self):
143+ """
144+ First start the launcher and move the mosue over position of Text Editor icon,
145+ then close the switcher and open it again while moving the mouse a bit.
146+ Asserting that the icon does lose focus from Character Map.
147+ """
148+
149+ char_win1, char_win2 = self.start_applications("Character Map", "Text Editor")
150+ self.assertVisibleWindowStack([char_win2, char_win1])
151+ self.assertProperty(char_win1, is_focused=False)
152+
153+ self.unity.switcher.initiate()
154+ self.addCleanup(self.unity.switcher.terminate)
155+
156+ mouse_index = self.unity.switcher.selection_index - 1
157+
158+ self.unity.switcher.view.move_over_icon(mouse_index);
159+ # Assert we are over the icon we want to hover over.
160+ self.assertThat(self.unity.switcher.view.last_icon_selected, Eventually(Equals(mouse_index)))
161+
162+ self.addCleanup(self.keybinding, "switcher/cancel")
163+
164+ self.unity.switcher.terminate()
165+ self.unity.switcher.initiate()
166+
167+ index = self.unity.switcher.selection_index
168+
169+ pos = self.mouse.position()
170+ self.mouse.move(pos[0] + 5, pos[1] + 5)
171+
172+ # Assert moving the mouse does not change the selection
173+ self.assertThat(self.unity.switcher.selection_index, Eventually(Equals(index)))
174+
175+ # Also nice to know clicking still works, even without selection
176+ self.mouse.click()
177+
178+ self.assertProperty(char_win2, is_focused=True)
179+
180 def test_mouse_highlights_switcher_deatil_icons_motion(self):
181 """
182 Gather the cords of all the detail icons, move the mouse through each
183@@ -597,15 +630,9 @@
184 self.unity.switcher.initiate(SwitcherMode.DETAIL)
185 self.addCleanup(self.unity.switcher.terminate)
186
187- offset = self.unity.switcher.view.spread_offset
188- cords = []
189-
190+ index = 0;
191 for icon in self.unity.switcher.view.detail_icons:
192- cords.append((icon.x + offset, icon.y + offset))
193-
194- index = 0;
195- for cord in cords:
196- self.mouse.move(cord[0], cord[1])
197+ self.unity.switcher.view.move_over_detail_icon(index)
198 self.assertThat(index, Equals(self.unity.switcher.detail_selection_index))
199 index += 1
200
201@@ -621,11 +648,7 @@
202 self.unity.switcher.initiate(SwitcherMode.DETAIL)
203 self.addCleanup(self.unity.switcher.terminate)
204
205- offset = self.unity.switcher.view.spread_offset
206- x = self.unity.switcher.view.detail_icons[0].x + offset
207- y = self.unity.switcher.view.detail_icons[0].y + offset
208-
209- self.mouse.move(x,y)
210+ self.unity.switcher.view.move_over_detail_icon(0);
211 self.mouse.click()
212
213 self.assertProperty(char_win1, is_focused=True)