summaryrefslogtreecommitdiff
path: root/unity-private
diff options
authorGord Allott <gord.allott@canonical.com>2010-08-26 11:27:34 +0100
committerGord Allott <gord.allott@canonical.com>2010-08-26 11:27:34 +0100
commitdcd1b6d24df8c92d3f6ddd89c8f8e203f0f06fe2 (patch)
tree1ca4afcf1db82d2ede324e4f0cfde789dd22e71d /unity-private
parent1afd60789da1d777f75286a9f956af19db86d2d3 (diff)
enables scroll wheel events
(bzr r433.6.12)
Diffstat (limited to 'unity-private')
-rw-r--r--unity-private/launcher/scroller-view.vala64
1 files changed, 38 insertions, 26 deletions
diff --git a/unity-private/launcher/scroller-view.vala b/unity-private/launcher/scroller-view.vala
index 85c25bc6b..1ae1f4d43 100644
--- a/unity-private/launcher/scroller-view.vala
+++ b/unity-private/launcher/scroller-view.vala
@@ -167,6 +167,7 @@ namespace Unity.Launcher
button_release_event.connect (on_button_release_event);
motion_event.connect (on_motion_event);
enter_event.connect (on_enter_event);
+ scroll_event.connect (on_scroll_event);
leave_event.connect (on_leave_event);
notify["is-autoscrolling"].connect (on_auto_scrolling_state_change);
@@ -665,7 +666,7 @@ namespace Unity.Launcher
}
// will move the scroller by the given pixels
- private void move_scroll_position (float pixels, bool check_bounds=false)
+ private void move_scroll_position (float pixels, bool check_bounds=false, float limit = 160.0f)
{
scroll_position += pixels;
float old_scroll_position = scroll_position;
@@ -676,14 +677,12 @@ namespace Unity.Launcher
}
else if (scroll_position > 0)
{
- float limit = 160.0f;
float new_scroll_position = scroll_position;
new_scroll_position = limit * ( 1 - Math.powf ((limit - 1) / limit, new_scroll_position));
scroll_position = new_scroll_position;
}
else if (scroll_position < -(get_total_children_height () - get_available_height ()))
{
- float limit = 160.0f;
float diff = scroll_position + (get_total_children_height () - get_available_height ());
float new_scroll_position = limit * ( 1 - Math.powf ((limit - 1) / limit, Math.fabsf (diff)));
new_scroll_position = -(get_total_children_height () - get_available_height ()) - new_scroll_position;
@@ -1032,31 +1031,30 @@ namespace Unity.Launcher
previous_y_position = event.motion.y;
previous_y_time = event.motion.time;
+ // move the scroller by how far we dragged
+ move_scroll_position (pixel_diff);
-/*
- if (scroll_position > 0)
- {
- float limit = 160.0f * 8;
- //float new_scroll_position = limit * ( 1 - Math.powf((limit-1)/limit, scroll_position) );
- float new_scroll_position = (scroll_position + pixel_diff);// * 0.95f;
- new_scroll_position = limit * ( 1 - Math.powf ((limit - 1) / limit, new_scroll_position));
- float diff = Math.fmaxf (new_scroll_position - scroll_position, 0);
- move_scroll_position (diff);
- }
- else if (scroll_position < -(get_total_children_height () - get_available_height ()))
- {
+ return true;
+ }
- }
- else
- {
-*/
- // move the scroller by how far we dragged
- move_scroll_position (pixel_diff);
-/*
- }
-*/
+ return false;
+ }
- return true;
+ private bool on_scroll_event (Clutter.Event event)
+ {
+ // got a mouse wheel scroll
+ float modifier = 0.0f;
+ if (event.scroll.direction == Clutter.ScrollDirection.UP)
+ modifier = 1.0f;
+ else if (event.scroll.direction == Clutter.ScrollDirection.DOWN)
+ modifier = -1.0f;
+
+ if (modifier != 0.0f)
+ {
+ float speed = ((48 + spacing) * 3) * 6.0f;
+ scroll_speed += speed * modifier;
+ current_phase = ScrollerPhase.FLUNG;
+ fling_timeline.start ();
}
return false;
@@ -1084,6 +1082,9 @@ namespace Unity.Launcher
{
is_animating = true;
delta -= 16;
+ if (fling_timeout_source != 0 && current_phase != ScrollerPhase.NONE)
+ Source.remove (fling_timeout_source);
+
switch (current_phase) {
case (ScrollerPhase.SETTLING):
do_anim_settle (timeline, msecs);
@@ -1126,13 +1127,14 @@ namespace Unity.Launcher
}
+ uint fling_timeout_source = 0;
private void do_anim_fling (Clutter.Timeline timeline, int msecs)
{
scroll_speed *= friction; // slow our speed
// we devide by 60 because get 60 ticks a second
float scroll_move_amount = scroll_speed / 60.0f;
- move_scroll_position (scroll_move_amount, true);
+ move_scroll_position (scroll_move_amount, false, 60.0f);
//after a fling, we have to figure out if we want to change our
// scroller phase or not
@@ -1141,6 +1143,16 @@ namespace Unity.Launcher
if (Math.fabsf (scroll_move_amount) < 1.0)
{
current_phase = ScrollerPhase.NONE;
+ fling_timeout_source = GLib.Timeout.add (300, () =>
+ {
+ current_phase = ScrollerPhase.SETTLING;
+ if (scroll_position > 0)
+ settle_position = 0;
+ else
+ settle_position = -(get_total_children_height () - get_available_height ());
+ fling_timeline.start ();
+ return false;
+ });
}
}