Merge lp:~unity-team/unity/unity.scrolling-update into lp:unity

Proposed by Gord Allott
Status: Merged
Approved by: Mirco Müller
Approved revision: no longer in the source branch.
Merged at revision: 463
Proposed branch: lp:~unity-team/unity/unity.scrolling-update
Merge into: lp:unity
Prerequisite: lp:~unity-team/unity/unity.newdnd
Diff against target: 300 lines (+102/-24)
3 files modified
unity-private/launcher/quicklist-controller.vala (+1/-0)
unity-private/launcher/scroller-view.vala (+72/-21)
unity-private/launcher/scrollerchild-controller.vala (+29/-3)
To merge this branch: bzr merge lp:~unity-team/unity/unity.scrolling-update
Reviewer Review Type Date Requested Status
Mirco Müller (community) Approve
Review via email: mp+33758@code.launchpad.net

Description of the change

updates the scroller animations, implements scroll wheel scrolling

To post a comment you must log in.
Revision history for this message
Mirco Müller (macslow) wrote :

Approved with promised fix :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'unity-private/launcher/quicklist-controller.vala'
2--- unity-private/launcher/quicklist-controller.vala 2010-08-05 14:52:07 +0000
3+++ unity-private/launcher/quicklist-controller.vala 2010-08-26 12:55:46 +0000
4@@ -20,6 +20,7 @@
5 namespace Unity.Launcher
6 {
7 public static QuicklistController? ql_controller_singleton;
8+ public static bool disable_quicklists = false;
9
10 public enum QuicklistControllerState {
11 LABEL,
12
13=== modified file 'unity-private/launcher/scroller-view.vala'
14--- unity-private/launcher/scroller-view.vala 2010-08-25 10:08:29 +0000
15+++ unity-private/launcher/scroller-view.vala 2010-08-26 12:55:46 +0000
16@@ -167,6 +167,7 @@
17 button_release_event.connect (on_button_release_event);
18 motion_event.connect (on_motion_event);
19 enter_event.connect (on_enter_event);
20+ scroll_event.connect (on_scroll_event);
21
22 leave_event.connect (on_leave_event);
23 notify["is-autoscrolling"].connect (on_auto_scrolling_state_change);
24@@ -191,7 +192,7 @@
25 drag_controller.drag_start.connect (() => {
26 is_scrolling = false;
27 button_down = false;
28- is_scrolling = false;
29+ Unity.Launcher.disable_quicklists = true;
30 Clutter.ungrab_pointer ();
31 get_stage ().motion_event.disconnect (on_motion_event);
32 current_phase = ScrollerPhase.FLUNG;
33@@ -202,6 +203,7 @@
34 });
35
36 drag_controller.drag_drop.connect ((drag_model, x, y) => {
37+ Unity.Launcher.disable_quicklists = false;
38 foreach (Clutter.Actor child in model)
39 {
40 child.set_reactive (false);
41@@ -664,17 +666,32 @@
42 }
43
44 // will move the scroller by the given pixels
45- private void move_scroll_position (float pixels, bool check_bounds=false)
46+ private void move_scroll_position (float pixels, bool check_bounds=false, float limit = 160.0f)
47 {
48 scroll_position += pixels;
49-
50+ float old_scroll_position = scroll_position;
51 if (check_bounds)
52 {
53 scroll_position = Math.fminf (scroll_position, 0);
54 scroll_position = Math.fmaxf (scroll_position, - (get_total_children_height () - get_available_height ()));
55 }
56+ else if (scroll_position > 0)
57+ {
58+ float new_scroll_position = scroll_position;
59+ new_scroll_position = limit * ( 1 - Math.powf ((limit - 1) / limit, new_scroll_position));
60+ scroll_position = new_scroll_position;
61+ }
62+ else if (scroll_position < -(get_total_children_height () - get_available_height ()))
63+ {
64+ float diff = scroll_position + (get_total_children_height () - get_available_height ());
65+ float new_scroll_position = limit * ( 1 - Math.powf ((limit - 1) / limit, Math.fabsf (diff)));
66+ new_scroll_position = -(get_total_children_height () - get_available_height ()) - new_scroll_position;
67+ scroll_position = new_scroll_position;
68+ }
69 order_children (true);
70 queue_relayout ();
71+
72+ scroll_position = old_scroll_position;
73 }
74
75 /* disables animations and events on children so that they don't
76@@ -853,14 +870,22 @@
77
78 if (is_scrolling)
79 {
80- passthrough_button_release_event (event);
81+ //passthrough_button_release_event (event);
82+ foreach (ScrollerChild child in model)
83+ {
84+ child.grabbed_push = 0;
85+ }
86 is_scrolling = false;
87+ Unity.Launcher.disable_quicklists = false;
88 Clutter.ungrab_pointer ();
89 get_stage ().motion_event.disconnect (on_motion_event);
90- if ((event.button.time - last_motion_event_time) > 120)
91+ if (scroll_position > 0 || scroll_position < -(get_total_children_height () - get_available_height ()))
92 {
93 current_phase = ScrollerPhase.SETTLING;
94- settle_position = get_aligned_settle_position ();
95+ if (scroll_position > 0)
96+ settle_position = 0;
97+ else
98+ settle_position = -(get_total_children_height () - get_available_height ());
99 }
100 else
101 {
102@@ -894,7 +919,10 @@
103 private bool on_queue_contract_launcher ()
104 {
105 if (queue_contract_launcher != 0)
106- contract_launcher ();
107+ {
108+ current_phase = ScrollerPhase.NONE;
109+ contract_launcher ();
110+ }
111 queue_contract_launcher = 0;
112 return false;
113 }
114@@ -961,7 +989,6 @@
115
116 private bool on_motion_event (Clutter.Event event)
117 {
118-
119 on_autoscroll_motion_check (event.motion.y);
120
121 var drag_controller = Drag.Controller.get_default ();
122@@ -980,6 +1007,7 @@
123 */
124 //var diff = event.motion.y - previous_y_position;
125 is_scrolling = true;
126+ Unity.Launcher.disable_quicklists = true;
127 Unity.global_shell.add_fullscreen_request (this);
128 Clutter.grab_pointer (this);
129 get_stage ().motion_event.connect (on_motion_event);
130@@ -1012,6 +1040,26 @@
131 return false;
132 }
133
134+ private bool on_scroll_event (Clutter.Event event)
135+ {
136+ // got a mouse wheel scroll
137+ float modifier = 0.0f;
138+ if (event.scroll.direction == Clutter.ScrollDirection.UP)
139+ modifier = 1.0f;
140+ else if (event.scroll.direction == Clutter.ScrollDirection.DOWN)
141+ modifier = -1.0f;
142+
143+ if (modifier != 0.0f)
144+ {
145+ float speed = ((48 + spacing) * 3) * 6.0f;
146+ scroll_speed += speed * modifier;
147+ current_phase = ScrollerPhase.FLUNG;
148+ fling_timeline.start ();
149+ }
150+
151+ return false;
152+ }
153+
154 /*
155 * Methods to handle our scroller animation, generally todo with the scrolling
156 */
157@@ -1034,6 +1082,9 @@
158 {
159 is_animating = true;
160 delta -= 16;
161+ if (fling_timeout_source != 0 && current_phase != ScrollerPhase.NONE)
162+ Source.remove (fling_timeout_source);
163+
164 switch (current_phase) {
165 case (ScrollerPhase.SETTLING):
166 do_anim_settle (timeline, msecs);
167@@ -1076,32 +1127,32 @@
168
169 }
170
171+ uint fling_timeout_source = 0;
172 private void do_anim_fling (Clutter.Timeline timeline, int msecs)
173 {
174 scroll_speed *= friction; // slow our speed
175
176 // we devide by 60 because get 60 ticks a second
177 float scroll_move_amount = scroll_speed / 60.0f;
178- move_scroll_position (scroll_move_amount);
179+ move_scroll_position (scroll_move_amount, false, 60.0f);
180
181 //after a fling, we have to figure out if we want to change our
182 // scroller phase or not
183
184- if(scroll_move_amount <= -1.0 && -scroll_position > total_child_height - height ||
185- scroll_move_amount >= 1.0 && scroll_position > 0)
186- {
187- current_phase = ScrollerPhase.BOUNCE;
188- }
189
190- if (Math.fabsf (scroll_move_amount) < 1.0 &&
191- (scroll_position > 0 || -scroll_position > total_child_height - height))
192- {
193- settle_position = get_aligned_settle_position ();
194- current_phase = ScrollerPhase.SETTLING;
195- }
196- else if (Math.fabsf (scroll_move_amount) < 1.0)
197+ if (Math.fabsf (scroll_move_amount) < 1.0)
198 {
199 current_phase = ScrollerPhase.NONE;
200+ fling_timeout_source = GLib.Timeout.add (300, () =>
201+ {
202+ current_phase = ScrollerPhase.SETTLING;
203+ if (scroll_position > 0)
204+ settle_position = 0;
205+ else
206+ settle_position = -(get_total_children_height () - get_available_height ());
207+ fling_timeline.start ();
208+ return false;
209+ });
210 }
211 }
212
213
214=== modified file 'unity-private/launcher/scrollerchild-controller.vala'
215--- unity-private/launcher/scrollerchild-controller.vala 2010-08-25 10:03:36 +0000
216+++ unity-private/launcher/scrollerchild-controller.vala 2010-08-26 12:55:46 +0000
217@@ -115,7 +115,7 @@
218 ensure_menu_state ();
219 return false;
220 }
221-
222+ private bool no_activate = false;
223 private bool on_press_event (Clutter.Event event)
224 {
225 switch (event.button.button)
226@@ -124,6 +124,7 @@
227 {
228 last_press_time = event.button.time;
229 button_down = true;
230+ no_activate = false;
231 click_start_pos_x = event.button.x;
232 click_start_pos_y = event.button.y;
233 } break;
234@@ -142,7 +143,8 @@
235 child.grabbed_push = 0;
236 if (event.button.button == 1 &&
237 button_down == true &&
238- event.button.time - last_press_time < 500)
239+ event.button.time - last_press_time < 500 &&
240+ no_activate == false)
241 {
242 if (menu is QuicklistController)
243 {
244@@ -155,6 +157,12 @@
245
246 activate ();
247 }
248+ else
249+ {
250+ menu.state = QuicklistControllerState.LABEL;
251+ ensure_menu_state ();
252+ }
253+
254 button_down = false;
255 return false;
256 }
257@@ -178,6 +186,11 @@
258 if (menu is QuicklistController == false)
259 return;
260 }
261+ if (Unity.Launcher.disable_quicklists)
262+ {
263+ menu.state = QuicklistControllerState.CLOSED;
264+ return;
265+ }
266
267 if (menu.state == QuicklistControllerState.MENU
268 && QuicklistController.is_menu_open ()
269@@ -203,7 +216,6 @@
270 {
271 Idle.add (() =>
272 {
273- debug ("setting menu to menu");
274 menu.state = QuicklistControllerState.MENU;
275 menu_state = ScrollerChildControllerMenuState.NO_MENU;
276 return false;
277@@ -225,9 +237,23 @@
278 private bool on_motion_event (Clutter.Event event)
279 {
280 var drag_controller = Unity.Drag.Controller.get_default ();
281+ if (!Unity.Launcher.disable_quicklists)
282+ {
283+ button_down = false;
284+ return false;
285+ }
286+
287 if (button_down && drag_controller.is_dragging == false && can_drag ())
288 {
289+ menu_state = ScrollerChildControllerMenuState.NO_MENU;
290+ ensure_menu_state ();
291 float diff = Math.fabsf (event.motion.x - click_start_pos_x);
292+ float diff_y = Math.fabsf (event.motion.y - click_start_pos_y);
293+ if (diff_y > 5)
294+ {
295+ no_activate = true;
296+ }
297+
298 if (event.motion.x - click_start_pos_x > 0)
299 {
300 child.grabbed_push = Math.powf (diff, 0.5f);