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

Proposed by Brandon Schaefer on 2013-09-18
Status: Merged
Approved by: Christopher Townsend on 2013-09-19
Approved revision: 3504
Merged at revision: 3522
Proposed branch: lp:~brandontschaefer/unity/lp.1223630-fix
Merge into: lp:unity
Diff against target: 413 lines (+265/-14)
7 files modified
launcher/CMakeLists.txt (+1/-0)
launcher/DeltaTracker.cpp (+80/-0)
launcher/DeltaTracker.h (+53/-0)
launcher/SwitcherView.cpp (+42/-11)
launcher/SwitcherView.h (+4/-3)
tests/CMakeLists.txt (+2/-0)
tests/test_delta_tracker.cpp (+83/-0)
To merge this branch: bzr merge lp:~brandontschaefer/unity/lp.1223630-fix
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve on 2013-09-19
Christopher Townsend 2013-09-18 Approve on 2013-09-19
Review via email: mp+186417@code.launchpad.net

Commit message

Only accept focus if the mouse moves in 3 directions on switcher start up if the mouse starts over the switcher window. This is an attempt to tell the difference between a bump and intentional movement.

Description of the change

Only accept focus if the mouse moves in 3 directions on switcher start up if the mouse starts over the switcher window. This is an attempt to tell the difference between a bump and intentional movement.

To post a comment you must log in.
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:3496
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~brandontschaefer/unity/lp.1223630-fix/+merge/186417/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/unity-ci/370/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-saucy-amd64-ci/259
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-saucy-armhf-ci/257
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-saucy-i386-ci/258

Click here to trigger a rebuild:
http://s-jenkins:8080/job/unity-ci/370/rebuild

review: Needs Fixing (continuous-integration)
3497. By Brandon Schaefer on 2013-09-18

* Use the SwitcherWindow as boarder instead of keeping track of which icon we are over.

3498. By Brandon Schaefer on 2013-09-18

* GetFlatIcons does not need to part of the SwitcherView class. Its completly independent of the class, and is a untility function.

3499. By Brandon Schaefer on 2013-09-18

* Make sure we do the same for detail mode on start up.
* Remove old function that is not used anymore

PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:3497
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~brandontschaefer/unity/lp.1223630-fix/+merge/186417/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/unity-ci/372/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-saucy-amd64-ci/261
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-saucy-armhf-ci/259
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-saucy-i386-ci/260

Click here to trigger a rebuild:
http://s-jenkins:8080/job/unity-ci/372/rebuild

review: Needs Fixing (continuous-integration)
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:3499
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~brandontschaefer/unity/lp.1223630-fix/+merge/186417/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/unity-ci/373/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/unity-saucy-amd64-ci/262/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/unity-saucy-armhf-ci/260/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/unity-saucy-i386-ci/261/console

Click here to trigger a rebuild:
http://s-jenkins:8080/job/unity-ci/373/rebuild

review: Needs Fixing (continuous-integration)
3500. By Brandon Schaefer on 2013-09-18

* Merge trunk

3501. By Brandon Schaefer on 2013-09-19

* Add gtest for delta tracker

PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:3500
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~brandontschaefer/unity/lp.1223630-fix/+merge/186417/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/unity-ci/374/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-saucy-amd64-ci/263
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-saucy-armhf-ci/261
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-saucy-i386-ci/262

Click here to trigger a rebuild:
http://s-jenkins:8080/job/unity-ci/374/rebuild

review: Needs Fixing (continuous-integration)
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:3501
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~brandontschaefer/unity/lp.1223630-fix/+merge/186417/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/unity-ci/376/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-saucy-amd64-ci/265
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-saucy-armhf-ci/263
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-saucy-i386-ci/264

Click here to trigger a rebuild:
http://s-jenkins:8080/job/unity-ci/376/rebuild

review: Needs Fixing (continuous-integration)
3502. By Brandon Schaefer on 2013-09-19

* Don't set check_mouse_first_time_ while handling detail mouse events

3503. By Brandon Schaefer on 2013-09-19

* Left click in detail mode that is not over an icon should exit detail mode

3504. By Brandon Schaefer on 2013-09-19

* Restart bump handling each time we go in/out of detail mode

Christopher Townsend (townsend) wrote :

This looks good! Hopefully, the bugs will be slow to come in;)

review: Approve
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/CMakeLists.txt'
2--- launcher/CMakeLists.txt 2013-03-21 16:22:34 +0000
3+++ launcher/CMakeLists.txt 2013-09-19 20:08:39 +0000
4@@ -81,6 +81,7 @@
5 add_pch(pch/launcher_pch.hh launcher-lib)
6
7 set (SWITCHER_SOURCES
8+ DeltaTracker.cpp
9 SwitcherController.cpp
10 SwitcherModel.cpp
11 SwitcherView.cpp
12
13=== added file 'launcher/DeltaTracker.cpp'
14--- launcher/DeltaTracker.cpp 1970-01-01 00:00:00 +0000
15+++ launcher/DeltaTracker.cpp 2013-09-19 20:08:39 +0000
16@@ -0,0 +1,80 @@
17+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
18+/*
19+ * Copyright (C) 2011 Canonical Ltd
20+ *
21+ * This program is free software: you can redistribute it and/or modify
22+ * it under the terms of the GNU General Public License version 3 as
23+ * published by the Free Software Foundation.
24+ *
25+ * This program is distributed in the hope that it will be useful,
26+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
27+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+ * GNU General Public License for more details.
29+ *
30+ * You should have received a copy of the GNU General Public License
31+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
32+ *
33+ * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
34+ */
35+
36+#include "DeltaTracker.h"
37+
38+namespace unity
39+{
40+
41+DeltaTracker::DeltaTracker()
42+ : delta_state_(DeltaState::NONE)
43+{
44+}
45+
46+void DeltaTracker::HandleNewMouseDelta(int dx, int dy)
47+{
48+ if (dx > 0)
49+ {
50+ delta_state_ |= DeltaState::RIGHT;
51+ }
52+ else if (dx < 0)
53+ {
54+ delta_state_ |= DeltaState::LEFT;
55+ }
56+
57+ if (dy > 0)
58+ {
59+ delta_state_ |= DeltaState::DOWN;
60+ }
61+ else if (dy < 0)
62+ {
63+ delta_state_ |= DeltaState::UP;
64+ }
65+}
66+
67+void DeltaTracker::ResetState()
68+{
69+ delta_state_ = DeltaState::NONE;
70+}
71+
72+unsigned int DeltaTracker::AmountOfDirectionsChanged() const
73+{
74+ unsigned int directions_changed = 0;
75+
76+ if (HasState(DeltaState::RIGHT))
77+ directions_changed++;
78+
79+ if (HasState(DeltaState::LEFT))
80+ directions_changed++;
81+
82+ if (HasState(DeltaState::UP))
83+ directions_changed++;
84+
85+ if (HasState(DeltaState::DOWN))
86+ directions_changed++;
87+
88+ return directions_changed;
89+}
90+
91+bool DeltaTracker::HasState(DeltaState const& state) const
92+{
93+ return (delta_state_ & state);
94+}
95+
96+}
97
98=== added file 'launcher/DeltaTracker.h'
99--- launcher/DeltaTracker.h 1970-01-01 00:00:00 +0000
100+++ launcher/DeltaTracker.h 2013-09-19 20:08:39 +0000
101@@ -0,0 +1,53 @@
102+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
103+/*
104+ * Copyright (C) 2011 Canonical Ltd
105+ *
106+ * This program is free software: you can redistribute it and/or modify
107+ * it under the terms of the GNU General Public License version 3 as
108+ * published by the Free Software Foundation.
109+ *
110+ * This program is distributed in the hope that it will be useful,
111+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
112+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
113+ * GNU General Public License for more details.
114+ *
115+ * You should have received a copy of the GNU General Public License
116+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
117+ *
118+ * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
119+ */
120+
121+#ifndef DELTA_TRACKER_H
122+#define DELTA_TRACKER_H
123+
124+namespace unity
125+{
126+
127+class DeltaTracker
128+{
129+public:
130+ DeltaTracker();
131+
132+ void HandleNewMouseDelta(int dx, int dy);
133+ void ResetState();
134+
135+ unsigned int AmountOfDirectionsChanged() const;
136+
137+private:
138+ enum DeltaState
139+ {
140+ NONE = 1 << 0,
141+ RIGHT = 1 << 1,
142+ DOWN = 1 << 2,
143+ LEFT = 1 << 3,
144+ UP = 1 << 4
145+ };
146+
147+ bool HasState(DeltaState const& state) const;
148+
149+ unsigned int delta_state_;
150+};
151+
152+}
153+
154+#endif // DELTA_TRACKER_H
155
156=== modified file 'launcher/SwitcherView.cpp'
157--- launcher/SwitcherView.cpp 2013-09-09 23:19:45 +0000
158+++ launcher/SwitcherView.cpp 2013-09-19 20:08:39 +0000
159@@ -39,6 +39,7 @@
160 unsigned int const VERTICAL_PADDING = 45;
161 unsigned int const SPREAD_OFFSET = 100;
162 unsigned int const EXTRA_ICON_SPACE = 10;
163+ unsigned int const MAX_DIRECTIONS_CHANGED = 3;
164 }
165
166 NUX_IMPLEMENT_OBJECT_TYPE(SwitcherView);
167@@ -206,6 +207,7 @@
168 text_view_->SetVisible(!detail);
169
170 last_detail_icon_selected_ = -1;
171+ check_mouse_first_time_ = true;
172
173 if (!detail)
174 {
175@@ -222,6 +224,8 @@
176 if (selection)
177 text_view_->SetText(selection->tooltip_text());
178
179+ delta_tracker_.ResetState();
180+
181 SaveLast();
182 QueueDraw();
183 }
184@@ -234,8 +238,33 @@
185 return {geo.x + x, geo.y + y};
186 }
187
188-void SwitcherView::RecvMouseMove(int x, int y, int /*dx*/, int /*dy*/, unsigned long /*button_flags*/, unsigned long /*key_flags*/)
189-{
190+void SwitcherView::MouseHandlingBackToNormal()
191+{
192+ check_mouse_first_time_ = false;
193+ last_icon_selected_ = -1;
194+ last_detail_icon_selected_ = -1;
195+}
196+
197+void SwitcherView::RecvMouseMove(int x, int y, int dx, int dy, unsigned long /*button_flags*/, unsigned long /*key_flags*/)
198+{
199+ // We just started, and want to check if we are a bump or not.
200+ // Once we are no longer a bump, skip!!
201+ if (check_mouse_first_time_)
202+ {
203+ if (CheckMouseInsideBackground(x,y))
204+ {
205+ delta_tracker_.HandleNewMouseDelta(dx, dy);
206+ if (delta_tracker_.AmountOfDirectionsChanged() >= MAX_DIRECTIONS_CHANGED)
207+ {
208+ MouseHandlingBackToNormal();
209+ }
210+ }
211+ else
212+ {
213+ MouseHandlingBackToNormal();
214+ }
215+ }
216+
217 if (model_->detail_selection)
218 {
219 HandleDetailMouseMove(x, y);
220@@ -254,7 +283,6 @@
221 if (check_mouse_first_time_)
222 {
223 last_detail_icon_selected_ = detail_icon_index;
224- check_mouse_first_time_ = false;
225 return;
226 }
227
228@@ -276,7 +304,6 @@
229 if (check_mouse_first_time_)
230 {
231 last_icon_selected_ = icon_index;
232- check_mouse_first_time_ = false;
233 return;
234 }
235
236@@ -364,6 +391,10 @@
237 model_->detail_selection_index = detail_icon_index;
238 hide_request.emit(true);
239 }
240+ else if (detail_icon_index < 0)
241+ {
242+ model_->detail_selection = false;
243+ }
244 }
245 else if (button == 3)
246 {
247@@ -558,13 +589,13 @@
248 return result;
249 }
250
251-void SwitcherView::GetFlatIconPositions (int n_flat_icons,
252- int size,
253- int selection,
254- int &first_flat,
255- int &last_flat,
256- int &half_fold_left,
257- int &half_fold_right)
258+void GetFlatIconPositions (int n_flat_icons,
259+ int size,
260+ int selection,
261+ int &first_flat,
262+ int &last_flat,
263+ int &half_fold_left,
264+ int &half_fold_right)
265 {
266 half_fold_left = -1;
267 half_fold_right = -1;
268
269=== modified file 'launcher/SwitcherView.h'
270--- launcher/SwitcherView.h 2013-09-05 18:12:25 +0000
271+++ launcher/SwitcherView.h 2013-09-19 20:08:39 +0000
272@@ -20,6 +20,7 @@
273 #ifndef SWITCHERVIEW_H
274 #define SWITCHERVIEW_H
275
276+#include "DeltaTracker.h"
277 #include "SwitcherModel.h"
278 #include "unity-shared/AbstractIconRenderer.h"
279 #include "unity-shared/StaticCairoText.h"
280@@ -132,15 +133,13 @@
281 nux::Size SpreadSize();
282
283 double GetCurrentProgress();
284- void GetFlatIconPositions(int n_flat_icons, int size, int selection,
285- int &first_flat, int &last_flat,
286- int &half_fold_left, int &half_fold_right);
287
288 void SaveTime();
289 void ResetTimer();
290 void SaveLast();
291
292 bool CheckMouseInsideBackground(int x, int y) const;
293+ void MouseHandlingBackToNormal();
294
295 SwitcherModel::Ptr model_;
296 ui::LayoutSystem layout_system_;
297@@ -152,6 +151,8 @@
298 bool target_sizes_set_;
299 bool check_mouse_first_time_;
300
301+ DeltaTracker delta_tracker_;
302+
303 std::list<ui::RenderArg> last_args_;
304 std::list<ui::RenderArg> saved_args_;
305
306
307=== modified file 'tests/CMakeLists.txt'
308--- tests/CMakeLists.txt 2013-09-13 00:40:45 +0000
309+++ tests/CMakeLists.txt 2013-09-19 20:08:39 +0000
310@@ -134,6 +134,7 @@
311 test_abstract_interface_generator.cpp
312 test_animation_utils.cpp
313 test_connection_manager.cpp
314+ test_delta_tracker.cpp
315 test_glib_dbus_object.cpp
316 test_glib_cancellable.cpp
317 test_glib_object.cpp
318@@ -178,6 +179,7 @@
319 unity-shared
320 unity-shared-standalone
321 launcher-lib
322+ switcher-lib
323 ${GMOCK_LIB}
324 ${GMOCK_MAIN_LIB}
325 ${LIBS}
326
327=== added file 'tests/test_delta_tracker.cpp'
328--- tests/test_delta_tracker.cpp 1970-01-01 00:00:00 +0000
329+++ tests/test_delta_tracker.cpp 2013-09-19 20:08:39 +0000
330@@ -0,0 +1,83 @@
331+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
332+/*
333+ * Copyright (C) 2012 Canonical Ltd
334+ *
335+ * This program is free software: you can redistribute it and/or modify
336+ * it under the terms of the GNU General Public License version 3 as
337+ * published by the Free Software Foundation.
338+ *
339+ * This program is distributed in the hope that it will be useful,
340+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
341+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
342+ * GNU General Public License for more details.
343+ *
344+ * You should have received a copy of the GNU General Public License
345+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
346+ *
347+ * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
348+ */
349+
350+#include <gmock/gmock.h>
351+using namespace testing;
352+
353+#include "launcher/DeltaTracker.h"
354+
355+namespace unity
356+{
357+
358+class TestDeltaTracker : public Test
359+{
360+public:
361+ TestDeltaTracker()
362+ {
363+ }
364+
365+ DeltaTracker delta_tracker_;
366+};
367+
368+
369+TEST_F(TestDeltaTracker, TestDirectionEmptyOnStart)
370+{
371+ ASSERT_EQ(delta_tracker_.AmountOfDirectionsChanged(), 0);
372+}
373+
374+TEST_F(TestDeltaTracker, TestCorrectDirections)
375+{
376+ delta_tracker_.HandleNewMouseDelta(0, -1);
377+ delta_tracker_.HandleNewMouseDelta(1, 0);
378+
379+ ASSERT_EQ(delta_tracker_.AmountOfDirectionsChanged(), 2);
380+}
381+
382+TEST_F(TestDeltaTracker, TestNoDuplicates)
383+{
384+ delta_tracker_.HandleNewMouseDelta(0, -1);
385+ delta_tracker_.HandleNewMouseDelta(0, -1);
386+
387+ ASSERT_EQ(delta_tracker_.AmountOfDirectionsChanged(), 1);
388+}
389+
390+TEST_F(TestDeltaTracker, TestAllDirections)
391+{
392+ delta_tracker_.HandleNewMouseDelta(0, -1);
393+ delta_tracker_.HandleNewMouseDelta(0, 1);
394+ delta_tracker_.HandleNewMouseDelta(-1, 0);
395+ delta_tracker_.HandleNewMouseDelta(1, 0);
396+
397+ ASSERT_EQ(delta_tracker_.AmountOfDirectionsChanged(), 4);
398+}
399+
400+TEST_F(TestDeltaTracker, TestResetStates)
401+{
402+ delta_tracker_.HandleNewMouseDelta(0, -1);
403+ delta_tracker_.HandleNewMouseDelta(0, 1);
404+ delta_tracker_.HandleNewMouseDelta(-1, 0);
405+ delta_tracker_.HandleNewMouseDelta(1, 0);
406+
407+ ASSERT_EQ(delta_tracker_.AmountOfDirectionsChanged(), 4);
408+
409+ delta_tracker_.ResetState();
410+ ASSERT_EQ(delta_tracker_.AmountOfDirectionsChanged(), 0);
411+}
412+
413+}