Merge lp:~dandrader/unity/lp969554 into lp:unity

Proposed by Daniel d'Andrada
Status: Merged
Approved by: Didier Roche-Tolomelli
Approved revision: no longer in the source branch.
Merged at revision: 2241
Proposed branch: lp:~dandrader/unity/lp969554
Merge into: lp:unity
Prerequisite: lp:~dandrader/unity/lp940612
Diff against target: 157 lines (+72/-9)
4 files modified
plugins/unityshell/src/GestureEngine.cpp (+2/-6)
plugins/unityshell/src/GestureEngine.h (+0/-1)
tests/test-gesture-engine/compiz_mock/core/window.h (+5/-2)
tests/test-gesture-engine/test_gesture_engine.cpp (+65/-0)
To merge this branch: bzr merge lp:~dandrader/unity/lp969554
Reviewer Review Type Date Requested Status
Thomi Richards (community) Approve
Review via email: mp+100833@code.launchpad.net

This proposal supersedes a proposal from 2012-03-30.

Commit message

Fix pinch gesture.

Description of the change

Fixes bug #969554

Now with unit tests.

To post a comment you must log in.
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote : Posted in a previous version of this proposal

Hi,

How can we test this? We need either a unit test, or an autopilot test, or, as a final resort, a manual test. From the looks of it, GestureEngine is going to be tricky to write a unit test for (it contains a lot of XLib calls, and is tightly coupled with CompScreen), but perhaps we can write an autopilot test? We'd need to work out how to simulate multi-touch using python & XLib.

...If that doesn't work, we need a manual test. Please consult the README and TEST_TEMPLATE files in manual-tests/ before writing one.

Thanks

review: Needs Fixing
Revision history for this message
Daniel d'Andrada (dandrader) wrote : Posted in a previous version of this proposal

> How can we test this? We need either a unit test, or an autopilot test, or, as
> a final resort, a manual test.[...]

It now has a unit test, but it's built on top of the commits from lp:~dandrader/unity/lp940612 (merge proposal https://code.launchpad.net/~dandrader/unity/lp940612/+merge/99956)

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Looks good to me.

review: Approve
Revision history for this message
Unity Merger (unity-merger) wrote :

The prerequisite lp:~dandrader/unity/lp940612 has not yet been merged into lp:unity.

Revision history for this message
Unity Merger (unity-merger) wrote :

No proposals found for merge of lp:~dandrader/unity/lp940612 into lp:unity.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/GestureEngine.cpp'
2--- plugins/unityshell/src/GestureEngine.cpp 2012-04-04 17:09:30 +0000
3+++ plugins/unityshell/src/GestureEngine.cpp 2012-04-04 17:09:31 +0000
4@@ -244,7 +244,6 @@
5 return;
6
7 _pinch_id = data->id;
8- _pinch_start_radius = data->radius;
9
10 if (_pinch_grab)
11 _screen->removeGrab(_pinch_grab, NULL);
12@@ -257,17 +256,14 @@
13 if (data->id != _pinch_id)
14 return;
15
16- float delta_radius = data->radius - _pinch_start_radius;
17- if (delta_radius > 110.0f)
18+ if (data->radius > 1.25)
19 {
20 _pinch_window->maximize(MAXIMIZE_STATE);
21- _pinch_start_radius = data->radius;
22 EndDrag();
23 }
24- else if (delta_radius < -110.0f)
25+ else if (data->radius < 0.8)
26 {
27 _pinch_window->maximize(0);
28- _pinch_start_radius = data->radius;
29 EndDrag();
30 }
31 }
32
33=== modified file 'plugins/unityshell/src/GestureEngine.h'
34--- plugins/unityshell/src/GestureEngine.h 2012-04-04 17:09:30 +0000
35+++ plugins/unityshell/src/GestureEngine.h 2012-04-04 17:09:31 +0000
36@@ -64,6 +64,5 @@
37 int _pinch_id;
38 int _touch_id;
39
40- float _pinch_start_radius;
41 Cursor _fleur_cursor;
42 };
43
44=== modified file 'tests/test-gesture-engine/compiz_mock/core/window.h'
45--- tests/test-gesture-engine/compiz_mock/core/window.h 2012-04-04 17:09:30 +0000
46+++ tests/test-gesture-engine/compiz_mock/core/window.h 2012-04-04 17:09:31 +0000
47@@ -26,7 +26,7 @@
48
49 class CompWindowMock {
50 public:
51- CompWindowMock() : _moved(false) {}
52+ CompWindowMock() : _moved(false), _maximize_count(0), _maximize_state(0) {}
53
54 int x() const {return _geometry.x();}
55 int y() const {return _geometry.y();}
56@@ -41,7 +41,7 @@
57
58 unsigned int actions () {return _actions;}
59
60- void maximize(int state) {}
61+ void maximize(int state) {++_maximize_count; _maximize_state = state;}
62
63 /* OBS: I wonder why it returns a reference */
64 unsigned int &state() {return _state;}
65@@ -61,6 +61,9 @@
66 bool _moved;
67 int _movement_x;
68 int _movement_y;
69+
70+ int _maximize_count;
71+ int _maximize_state;
72 };
73
74 #endif
75
76=== modified file 'tests/test-gesture-engine/test_gesture_engine.cpp'
77--- tests/test-gesture-engine/test_gesture_engine.cpp 2012-04-04 17:09:30 +0000
78+++ tests/test-gesture-engine/test_gesture_engine.cpp 2012-04-04 17:09:31 +0000
79@@ -36,6 +36,39 @@
80 GenerateWindows();
81 }
82
83+ void PerformPinch(GestureEngine &gesture_engine, float peak_radius) {
84+ CompWindowMock *middle_window = screen_mock->_client_list_stacking[1];
85+
86+ GeisAdapterMock::GeisTouchData touch_data;
87+ touch_data.id = 1;
88+ touch_data.touches = 3;
89+ touch_data.window = 123;
90+ touch_data.focus_x = 100; /* hits the middle window */
91+ touch_data.focus_y = 100;
92+ gesture_engine.OnTouchStart(&touch_data);
93+
94+ GeisAdapterMock::GeisPinchData pinch_data;
95+ pinch_data.id = 1;
96+ pinch_data.touches = 3;
97+ pinch_data.window = 123;
98+ pinch_data.focus_x = 100; /* hits the middle window */
99+ pinch_data.focus_y = 100;
100+ pinch_data.radius = 1.0;
101+ gesture_engine.OnPinchStart(&pinch_data);
102+
103+ touch_data.focus_x += 10;
104+ touch_data.focus_y += 20;
105+ gesture_engine.OnTouchUpdate(&touch_data);
106+
107+ pinch_data.focus_x += 10;
108+ pinch_data.focus_y += 20;
109+ pinch_data.radius = peak_radius;
110+ gesture_engine.OnPinchUpdate(&pinch_data);
111+
112+ gesture_engine.OnTouchFinish(&touch_data);
113+ gesture_engine.OnPinchFinish(&pinch_data);
114+ }
115+
116 private:
117 void GenerateWindows() {
118 /* remove windows from previous test */
119@@ -155,6 +188,38 @@
120 ASSERT_FALSE(middle_window->_moved);
121 }
122
123+TEST_F(GestureEngineTest, ThreeFingersPinchMaximizesWindow)
124+{
125+ GestureEngine gesture_engine(screen_mock);
126+ CompWindowMock *middle_window = screen_mock->_client_list_stacking[1];
127+
128+ PerformPinch(gesture_engine, 2.0);
129+
130+ ASSERT_EQ(1, middle_window->_maximize_count);
131+ ASSERT_EQ(MAXIMIZE_STATE, middle_window->_maximize_state);
132+}
133+
134+TEST_F(GestureEngineTest, ThreeFingersPinchRestoresWindow)
135+{
136+ GestureEngine gesture_engine(screen_mock);
137+ CompWindowMock *middle_window = screen_mock->_client_list_stacking[1];
138+
139+ PerformPinch(gesture_engine, 0.3);
140+
141+ ASSERT_EQ(1, middle_window->_maximize_count);
142+ ASSERT_EQ(0, middle_window->_maximize_state);
143+}
144+
145+TEST_F(GestureEngineTest, MinimalThreeFingersPinchDoesNothing)
146+{
147+ GestureEngine gesture_engine(screen_mock);
148+ CompWindowMock *middle_window = screen_mock->_client_list_stacking[1];
149+
150+ PerformPinch(gesture_engine, 1.1);
151+
152+ ASSERT_EQ(0, middle_window->_maximize_count);
153+}
154+
155 int main(int argc, char** argv)
156 {
157 ::testing::InitGoogleTest(&argc, argv);