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

Proposed by Brandon Schaefer
Status: Merged
Approved by: Christopher Townsend
Approved revision: no longer in the source branch.
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
Christopher Townsend Approve
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.
Revision history for this message
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)
Revision history for this message
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)
Revision history for this message
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)
Revision history for this message
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)
Revision history for this message
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)
Revision history for this message
Christopher Townsend (townsend) wrote :

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

review: Approve
Revision history for this message
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
=== modified file 'launcher/CMakeLists.txt'
--- launcher/CMakeLists.txt 2013-03-21 16:22:34 +0000
+++ launcher/CMakeLists.txt 2013-09-19 20:08:39 +0000
@@ -81,6 +81,7 @@
81add_pch(pch/launcher_pch.hh launcher-lib)81add_pch(pch/launcher_pch.hh launcher-lib)
8282
83set (SWITCHER_SOURCES83set (SWITCHER_SOURCES
84 DeltaTracker.cpp
84 SwitcherController.cpp85 SwitcherController.cpp
85 SwitcherModel.cpp86 SwitcherModel.cpp
86 SwitcherView.cpp87 SwitcherView.cpp
8788
=== added file 'launcher/DeltaTracker.cpp'
--- launcher/DeltaTracker.cpp 1970-01-01 00:00:00 +0000
+++ launcher/DeltaTracker.cpp 2013-09-19 20:08:39 +0000
@@ -0,0 +1,80 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2011 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
18 */
19
20#include "DeltaTracker.h"
21
22namespace unity
23{
24
25DeltaTracker::DeltaTracker()
26 : delta_state_(DeltaState::NONE)
27{
28}
29
30void DeltaTracker::HandleNewMouseDelta(int dx, int dy)
31{
32 if (dx > 0)
33 {
34 delta_state_ |= DeltaState::RIGHT;
35 }
36 else if (dx < 0)
37 {
38 delta_state_ |= DeltaState::LEFT;
39 }
40
41 if (dy > 0)
42 {
43 delta_state_ |= DeltaState::DOWN;
44 }
45 else if (dy < 0)
46 {
47 delta_state_ |= DeltaState::UP;
48 }
49}
50
51void DeltaTracker::ResetState()
52{
53 delta_state_ = DeltaState::NONE;
54}
55
56unsigned int DeltaTracker::AmountOfDirectionsChanged() const
57{
58 unsigned int directions_changed = 0;
59
60 if (HasState(DeltaState::RIGHT))
61 directions_changed++;
62
63 if (HasState(DeltaState::LEFT))
64 directions_changed++;
65
66 if (HasState(DeltaState::UP))
67 directions_changed++;
68
69 if (HasState(DeltaState::DOWN))
70 directions_changed++;
71
72 return directions_changed;
73}
74
75bool DeltaTracker::HasState(DeltaState const& state) const
76{
77 return (delta_state_ & state);
78}
79
80}
081
=== added file 'launcher/DeltaTracker.h'
--- launcher/DeltaTracker.h 1970-01-01 00:00:00 +0000
+++ launcher/DeltaTracker.h 2013-09-19 20:08:39 +0000
@@ -0,0 +1,53 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2011 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
18 */
19
20#ifndef DELTA_TRACKER_H
21#define DELTA_TRACKER_H
22
23namespace unity
24{
25
26class DeltaTracker
27{
28public:
29 DeltaTracker();
30
31 void HandleNewMouseDelta(int dx, int dy);
32 void ResetState();
33
34 unsigned int AmountOfDirectionsChanged() const;
35
36private:
37 enum DeltaState
38 {
39 NONE = 1 << 0,
40 RIGHT = 1 << 1,
41 DOWN = 1 << 2,
42 LEFT = 1 << 3,
43 UP = 1 << 4
44 };
45
46 bool HasState(DeltaState const& state) const;
47
48 unsigned int delta_state_;
49};
50
51}
52
53#endif // DELTA_TRACKER_H
054
=== modified file 'launcher/SwitcherView.cpp'
--- launcher/SwitcherView.cpp 2013-09-09 23:19:45 +0000
+++ launcher/SwitcherView.cpp 2013-09-19 20:08:39 +0000
@@ -39,6 +39,7 @@
39 unsigned int const VERTICAL_PADDING = 45;39 unsigned int const VERTICAL_PADDING = 45;
40 unsigned int const SPREAD_OFFSET = 100;40 unsigned int const SPREAD_OFFSET = 100;
41 unsigned int const EXTRA_ICON_SPACE = 10;41 unsigned int const EXTRA_ICON_SPACE = 10;
42 unsigned int const MAX_DIRECTIONS_CHANGED = 3;
42}43}
4344
44NUX_IMPLEMENT_OBJECT_TYPE(SwitcherView);45NUX_IMPLEMENT_OBJECT_TYPE(SwitcherView);
@@ -206,6 +207,7 @@
206 text_view_->SetVisible(!detail);207 text_view_->SetVisible(!detail);
207208
208 last_detail_icon_selected_ = -1;209 last_detail_icon_selected_ = -1;
210 check_mouse_first_time_ = true;
209211
210 if (!detail)212 if (!detail)
211 {213 {
@@ -222,6 +224,8 @@
222 if (selection)224 if (selection)
223 text_view_->SetText(selection->tooltip_text());225 text_view_->SetText(selection->tooltip_text());
224226
227 delta_tracker_.ResetState();
228
225 SaveLast();229 SaveLast();
226 QueueDraw();230 QueueDraw();
227}231}
@@ -234,8 +238,33 @@
234 return {geo.x + x, geo.y + y};238 return {geo.x + x, geo.y + y};
235}239}
236240
237void SwitcherView::RecvMouseMove(int x, int y, int /*dx*/, int /*dy*/, unsigned long /*button_flags*/, unsigned long /*key_flags*/)241void SwitcherView::MouseHandlingBackToNormal()
238{242{
243 check_mouse_first_time_ = false;
244 last_icon_selected_ = -1;
245 last_detail_icon_selected_ = -1;
246}
247
248void SwitcherView::RecvMouseMove(int x, int y, int dx, int dy, unsigned long /*button_flags*/, unsigned long /*key_flags*/)
249{
250 // We just started, and want to check if we are a bump or not.
251 // Once we are no longer a bump, skip!!
252 if (check_mouse_first_time_)
253 {
254 if (CheckMouseInsideBackground(x,y))
255 {
256 delta_tracker_.HandleNewMouseDelta(dx, dy);
257 if (delta_tracker_.AmountOfDirectionsChanged() >= MAX_DIRECTIONS_CHANGED)
258 {
259 MouseHandlingBackToNormal();
260 }
261 }
262 else
263 {
264 MouseHandlingBackToNormal();
265 }
266 }
267
239 if (model_->detail_selection)268 if (model_->detail_selection)
240 {269 {
241 HandleDetailMouseMove(x, y);270 HandleDetailMouseMove(x, y);
@@ -254,7 +283,6 @@
254 if (check_mouse_first_time_)283 if (check_mouse_first_time_)
255 {284 {
256 last_detail_icon_selected_ = detail_icon_index;285 last_detail_icon_selected_ = detail_icon_index;
257 check_mouse_first_time_ = false;
258 return;286 return;
259 }287 }
260288
@@ -276,7 +304,6 @@
276 if (check_mouse_first_time_)304 if (check_mouse_first_time_)
277 {305 {
278 last_icon_selected_ = icon_index;306 last_icon_selected_ = icon_index;
279 check_mouse_first_time_ = false;
280 return;307 return;
281 }308 }
282309
@@ -364,6 +391,10 @@
364 model_->detail_selection_index = detail_icon_index;391 model_->detail_selection_index = detail_icon_index;
365 hide_request.emit(true);392 hide_request.emit(true);
366 }393 }
394 else if (detail_icon_index < 0)
395 {
396 model_->detail_selection = false;
397 }
367 }398 }
368 else if (button == 3)399 else if (button == 3)
369 {400 {
@@ -558,13 +589,13 @@
558 return result;589 return result;
559}590}
560591
561void SwitcherView::GetFlatIconPositions (int n_flat_icons,592void GetFlatIconPositions (int n_flat_icons,
562 int size,593 int size,
563 int selection,594 int selection,
564 int &first_flat,595 int &first_flat,
565 int &last_flat,596 int &last_flat,
566 int &half_fold_left,597 int &half_fold_left,
567 int &half_fold_right)598 int &half_fold_right)
568{599{
569 half_fold_left = -1;600 half_fold_left = -1;
570 half_fold_right = -1;601 half_fold_right = -1;
571602
=== modified file 'launcher/SwitcherView.h'
--- launcher/SwitcherView.h 2013-09-05 18:12:25 +0000
+++ launcher/SwitcherView.h 2013-09-19 20:08:39 +0000
@@ -20,6 +20,7 @@
20#ifndef SWITCHERVIEW_H20#ifndef SWITCHERVIEW_H
21#define SWITCHERVIEW_H21#define SWITCHERVIEW_H
2222
23#include "DeltaTracker.h"
23#include "SwitcherModel.h"24#include "SwitcherModel.h"
24#include "unity-shared/AbstractIconRenderer.h"25#include "unity-shared/AbstractIconRenderer.h"
25#include "unity-shared/StaticCairoText.h"26#include "unity-shared/StaticCairoText.h"
@@ -132,15 +133,13 @@
132 nux::Size SpreadSize();133 nux::Size SpreadSize();
133134
134 double GetCurrentProgress();135 double GetCurrentProgress();
135 void GetFlatIconPositions(int n_flat_icons, int size, int selection,
136 int &first_flat, int &last_flat,
137 int &half_fold_left, int &half_fold_right);
138136
139 void SaveTime();137 void SaveTime();
140 void ResetTimer();138 void ResetTimer();
141 void SaveLast();139 void SaveLast();
142140
143 bool CheckMouseInsideBackground(int x, int y) const;141 bool CheckMouseInsideBackground(int x, int y) const;
142 void MouseHandlingBackToNormal();
144143
145 SwitcherModel::Ptr model_;144 SwitcherModel::Ptr model_;
146 ui::LayoutSystem layout_system_;145 ui::LayoutSystem layout_system_;
@@ -152,6 +151,8 @@
152 bool target_sizes_set_;151 bool target_sizes_set_;
153 bool check_mouse_first_time_;152 bool check_mouse_first_time_;
154153
154 DeltaTracker delta_tracker_;
155
155 std::list<ui::RenderArg> last_args_;156 std::list<ui::RenderArg> last_args_;
156 std::list<ui::RenderArg> saved_args_;157 std::list<ui::RenderArg> saved_args_;
157158
158159
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2013-09-13 00:40:45 +0000
+++ tests/CMakeLists.txt 2013-09-19 20:08:39 +0000
@@ -134,6 +134,7 @@
134 test_abstract_interface_generator.cpp134 test_abstract_interface_generator.cpp
135 test_animation_utils.cpp135 test_animation_utils.cpp
136 test_connection_manager.cpp136 test_connection_manager.cpp
137 test_delta_tracker.cpp
137 test_glib_dbus_object.cpp138 test_glib_dbus_object.cpp
138 test_glib_cancellable.cpp139 test_glib_cancellable.cpp
139 test_glib_object.cpp140 test_glib_object.cpp
@@ -178,6 +179,7 @@
178 unity-shared179 unity-shared
179 unity-shared-standalone180 unity-shared-standalone
180 launcher-lib181 launcher-lib
182 switcher-lib
181 ${GMOCK_LIB}183 ${GMOCK_LIB}
182 ${GMOCK_MAIN_LIB}184 ${GMOCK_MAIN_LIB}
183 ${LIBS}185 ${LIBS}
184186
=== added file 'tests/test_delta_tracker.cpp'
--- tests/test_delta_tracker.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_delta_tracker.cpp 2013-09-19 20:08:39 +0000
@@ -0,0 +1,83 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2012 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
18 */
19
20#include <gmock/gmock.h>
21using namespace testing;
22
23#include "launcher/DeltaTracker.h"
24
25namespace unity
26{
27
28class TestDeltaTracker : public Test
29{
30public:
31 TestDeltaTracker()
32 {
33 }
34
35 DeltaTracker delta_tracker_;
36};
37
38
39TEST_F(TestDeltaTracker, TestDirectionEmptyOnStart)
40{
41 ASSERT_EQ(delta_tracker_.AmountOfDirectionsChanged(), 0);
42}
43
44TEST_F(TestDeltaTracker, TestCorrectDirections)
45{
46 delta_tracker_.HandleNewMouseDelta(0, -1);
47 delta_tracker_.HandleNewMouseDelta(1, 0);
48
49 ASSERT_EQ(delta_tracker_.AmountOfDirectionsChanged(), 2);
50}
51
52TEST_F(TestDeltaTracker, TestNoDuplicates)
53{
54 delta_tracker_.HandleNewMouseDelta(0, -1);
55 delta_tracker_.HandleNewMouseDelta(0, -1);
56
57 ASSERT_EQ(delta_tracker_.AmountOfDirectionsChanged(), 1);
58}
59
60TEST_F(TestDeltaTracker, TestAllDirections)
61{
62 delta_tracker_.HandleNewMouseDelta(0, -1);
63 delta_tracker_.HandleNewMouseDelta(0, 1);
64 delta_tracker_.HandleNewMouseDelta(-1, 0);
65 delta_tracker_.HandleNewMouseDelta(1, 0);
66
67 ASSERT_EQ(delta_tracker_.AmountOfDirectionsChanged(), 4);
68}
69
70TEST_F(TestDeltaTracker, TestResetStates)
71{
72 delta_tracker_.HandleNewMouseDelta(0, -1);
73 delta_tracker_.HandleNewMouseDelta(0, 1);
74 delta_tracker_.HandleNewMouseDelta(-1, 0);
75 delta_tracker_.HandleNewMouseDelta(1, 0);
76
77 ASSERT_EQ(delta_tracker_.AmountOfDirectionsChanged(), 4);
78
79 delta_tracker_.ResetState();
80 ASSERT_EQ(delta_tracker_.AmountOfDirectionsChanged(), 0);
81}
82
83}