Merge lp:~cimi/overlay-scrollbar/fine-scroll into lp:overlay-scrollbar

Proposed by Andrea Cimitan
Status: Merged
Approved by: Ted Gould
Approved revision: 287
Merged at revision: 284
Proposed branch: lp:~cimi/overlay-scrollbar/fine-scroll
Merge into: lp:overlay-scrollbar
Diff against target: 479 lines (+188/-171)
2 files modified
os/os-private.h (+1/-1)
os/os-scrollbar.c (+187/-170)
To merge this branch: bzr merge lp:~cimi/overlay-scrollbar/fine-scroll
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+67079@code.launchpad.net
To post a comment you must log in.
286. By Andrea Cimitan

Readd tolerance on pageup/down

287. By Andrea Cimitan

whitespace

Revision history for this message
Ted Gould (ted) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'os/os-private.h'
--- os/os-private.h 2011-06-27 17:03:25 +0000
+++ os/os-private.h 2011-07-06 21:03:28 +0000
@@ -71,7 +71,7 @@
71 } \71 } \
72 } G_STMT_END72 } G_STMT_END
7373
74/* Macro loggging an error message to stderr and breaking the program execution74/* Macro logging an error message to stderr and breaking the program execution
75 * if the assertion fails. */75 * if the assertion fails. */
76#define OS_CHECK(cond) \76#define OS_CHECK(cond) \
77 G_STMT_START { \77 G_STMT_START { \
7878
=== modified file 'os/os-scrollbar.c'
--- os/os-scrollbar.c 2011-07-05 18:13:09 +0000
+++ os/os-scrollbar.c 2011-07-06 21:03:28 +0000
@@ -98,6 +98,7 @@
98 gboolean active_window;98 gboolean active_window;
99 gboolean can_deactivate_pager;99 gboolean can_deactivate_pager;
100 gboolean can_hide;100 gboolean can_hide;
101 gboolean detached_scroll;
101 gboolean filter;102 gboolean filter;
102 gboolean fullsize;103 gboolean fullsize;
103 gboolean internal;104 gboolean internal;
@@ -368,10 +369,7 @@
368 priv = scrollbar->priv;369 priv = scrollbar->priv;
369370
370 if (priv->can_hide)371 if (priv->can_hide)
371 {372 gtk_widget_hide (priv->thumb);
372 priv->value_changed_event = FALSE;
373 gtk_widget_hide (priv->thumb);
374 }
375}373}
376374
377/* timeout before hiding the thumb */375/* timeout before hiding the thumb */
@@ -773,19 +771,6 @@
773 gtk_adjustment_set_value (priv->adjustment, new_value);771 gtk_adjustment_set_value (priv->adjustment, new_value);
774}772}
775773
776/* stop_func called by the set-scroll animation */
777static void
778set_scroll_stop_cb (gpointer user_data)
779{
780 OsScrollbar *scrollbar;
781 OsScrollbarPrivate *priv;
782
783 scrollbar = OS_SCROLLBAR (user_data);
784 priv = scrollbar->priv;
785
786 priv->value = gtk_adjustment_get_value (priv->adjustment);
787}
788
789/* swap adjustment pointer */774/* swap adjustment pointer */
790static void775static void
791swap_adjustment (OsScrollbar *scrollbar,776swap_adjustment (OsScrollbar *scrollbar,
@@ -939,6 +924,91 @@
939 move_pager (scrollbar);924 move_pager (scrollbar);
940}925}
941926
927/* update the visual connection between pager and thumb. */
928static void
929update_visual_connection (OsScrollbar *scrollbar)
930{
931 OsScrollbarPrivate *priv;
932 gint x_pos, y_pos;
933
934 priv = scrollbar->priv;
935
936 gdk_window_get_origin (gtk_widget_get_window (priv->thumb), &x_pos, &y_pos);
937
938 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
939 {
940 if (priv->win_y + priv->overlay.y >= y_pos + priv->slider.height)
941 {
942 GdkRectangle mask;
943
944 mask.x = 0;
945 mask.y = y_pos + priv->slider.height / 2 - priv->win_y;
946 mask.width = priv->pager_all.width;
947 mask.height = priv->overlay.y - mask.y;
948
949 os_pager_connect (priv->pager, mask);
950 os_pager_set_detached (priv->pager, TRUE);
951
952 os_thumb_set_detached (OS_THUMB (priv->thumb), TRUE);
953 }
954 else if (priv->win_y + priv->overlay.y + priv->overlay.height <= y_pos)
955 {
956 GdkRectangle mask;
957
958 mask.x = 0;
959 mask.y = priv->overlay.y + priv->overlay.height;
960 mask.width = priv->pager_all.width;
961 mask.height = y_pos + priv->slider.height / 2 - priv->win_y - mask.y;
962
963 os_pager_connect (priv->pager, mask);
964 os_pager_set_detached (priv->pager, TRUE);
965
966 os_thumb_set_detached (OS_THUMB (priv->thumb), TRUE);
967 }
968 else
969 {
970 os_pager_set_detached (priv->pager, FALSE);
971 os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE);
972 }
973 }
974 else
975 {
976 if (priv->win_x + priv->overlay.x >= x_pos + priv->slider.width)
977 {
978 GdkRectangle mask;
979
980 mask.x = x_pos + priv->slider.width / 2 - priv->win_x;
981 mask.y = 0;
982 mask.width = priv->overlay.x - mask.x;
983 mask.height = priv->pager_all.height;
984
985 os_pager_connect (priv->pager, mask);
986 os_pager_set_detached (priv->pager, TRUE);
987
988 os_thumb_set_detached (OS_THUMB (priv->thumb), TRUE);
989 }
990 else if (priv->win_x + priv->overlay.x + priv->overlay.width <= x_pos)
991 {
992 GdkRectangle mask;
993
994 mask.x = priv->overlay.x + priv->overlay.width;
995 mask.y = 0;
996 mask.width = x_pos + priv->slider.width / 2 - priv->win_x - mask.x;
997 mask.height = priv->pager_all.height;
998
999 os_pager_connect (priv->pager, mask);
1000 os_pager_set_detached (priv->pager, TRUE);
1001
1002 os_thumb_set_detached (OS_THUMB (priv->thumb), TRUE);
1003 }
1004 else
1005 {
1006 os_pager_set_detached (priv->pager, FALSE);
1007 os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE);
1008 }
1009 }
1010}
1011
942static void1012static void
943adjustment_value_changed_cb (GtkAdjustment *adjustment,1013adjustment_value_changed_cb (GtkAdjustment *adjustment,
944 gpointer user_data)1014 gpointer user_data)
@@ -964,83 +1034,7 @@
964 os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE);1034 os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE);
965 }1035 }
966 else1036 else
967 {1037 update_visual_connection (scrollbar);
968 gint x_pos, y_pos;
969 gdk_window_get_origin (gtk_widget_get_window (priv->thumb), &x_pos, &y_pos);
970
971 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
972 {
973 if (priv->win_y + priv->overlay.y > y_pos + priv->slider.height)
974 {
975 GdkRectangle mask;
976
977 mask.x = 0;
978 mask.y = y_pos + priv->slider.height / 2 - priv->win_y;
979 mask.width = priv->pager_all.width;
980 mask.height = priv->overlay.y - mask.y;
981
982 os_pager_connect (priv->pager, mask);
983 os_pager_set_detached (priv->pager, TRUE);
984
985 os_thumb_set_detached (OS_THUMB (priv->thumb), TRUE);
986 }
987 else if (priv->win_y + priv->overlay.y + priv->overlay.height < y_pos)
988 {
989 GdkRectangle mask;
990
991 mask.x = 0;
992 mask.y = priv->overlay.y + priv->overlay.height;
993 mask.width = priv->pager_all.width;
994 mask.height = y_pos + priv->slider.height / 2 - priv->win_y - mask.y;
995
996 os_pager_connect (priv->pager, mask);
997 os_pager_set_detached (priv->pager, TRUE);
998
999 os_thumb_set_detached (OS_THUMB (priv->thumb), TRUE);
1000 }
1001 else
1002 {
1003 os_pager_set_detached (priv->pager, FALSE);
1004 os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE);
1005 }
1006 }
1007 else
1008 {
1009 if (priv->win_x + priv->overlay.x > x_pos + priv->slider.width)
1010 {
1011 GdkRectangle mask;
1012
1013 mask.x = x_pos + priv->slider.width / 2 - priv->win_x;
1014 mask.y = 0;
1015 mask.width = priv->overlay.x - mask.x;
1016 mask.height = priv->pager_all.height;
1017
1018 os_pager_connect (priv->pager, mask);
1019 os_pager_set_detached (priv->pager, TRUE);
1020
1021 os_thumb_set_detached (OS_THUMB (priv->thumb), TRUE);
1022 }
1023 else if (priv->win_x + priv->overlay.x + priv->overlay.width < x_pos)
1024 {
1025 GdkRectangle mask;
1026
1027 mask.x = priv->overlay.x + priv->overlay.width;
1028 mask.y = 0;
1029 mask.width = x_pos + priv->slider.width / 2 - priv->win_x - mask.x;
1030 mask.height = priv->pager_all.height;
1031
1032 os_pager_connect (priv->pager, mask);
1033 os_pager_set_detached (priv->pager, TRUE);
1034
1035 os_thumb_set_detached (OS_THUMB (priv->thumb), TRUE);
1036 }
1037 else
1038 {
1039 os_pager_set_detached (priv->pager, FALSE);
1040 os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE);
1041 }
1042 }
1043 }
1044 }1038 }
10451039
1046 move_pager (scrollbar);1040 move_pager (scrollbar);
@@ -1257,6 +1251,8 @@
1257 priv->present_time = g_get_monotonic_time ();1251 priv->present_time = g_get_monotonic_time ();
1258 present_gdk_window_with_timestamp (GTK_WIDGET (scrollbar), event->time);1252 present_gdk_window_with_timestamp (GTK_WIDGET (scrollbar), event->time);
12591253
1254 priv->detached_scroll = FALSE;
1255
1260 priv->button_press_event = TRUE;1256 priv->button_press_event = TRUE;
1261 priv->motion_notify_event = FALSE;1257 priv->motion_notify_event = FALSE;
12621258
@@ -1352,7 +1348,7 @@
13521348
1353 gtk_window_set_transient_for (GTK_WINDOW (widget), NULL);1349 gtk_window_set_transient_for (GTK_WINDOW (widget), NULL);
13541350
1355 if (!priv->motion_notify_event)1351 if (!priv->motion_notify_event && !priv->detached_scroll)
1356 {1352 {
1357 if (priv->orientation == GTK_ORIENTATION_VERTICAL)1353 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
1358 {1354 {
@@ -1586,46 +1582,6 @@
1586 gtk_adjustment_set_value (priv->adjustment, new_value);1582 gtk_adjustment_set_value (priv->adjustment, new_value);
1587}1583}
15881584
1589/* from pointer movement, store the right adjustment value */
1590static void
1591capture_movement_for_animation (OsScrollbar *scrollbar,
1592 gint mouse_x,
1593 gint mouse_y)
1594{
1595 OsScrollbarPrivate *priv;
1596 gint delta;
1597 gint c;
1598 gdouble current_value, old_value, new_value;
1599
1600 priv = scrollbar->priv;
1601
1602 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
1603 delta = mouse_y - priv->slide_initial_coordinate;
1604 else
1605 delta = mouse_x - priv->slide_initial_coordinate;
1606
1607 c = priv->slide_initial_slider_position + delta;
1608
1609 current_value = gtk_adjustment_get_value (priv->adjustment);
1610 old_value = priv->value;
1611 new_value = coord_to_value (scrollbar, c);
1612
1613 /* stop the animation if we are connecting. */
1614 if ((current_value > old_value &&
1615 new_value > current_value) ||
1616 (current_value < old_value &&
1617 new_value < current_value))
1618 {
1619 os_animation_stop (priv->animation, NULL);
1620
1621 gtk_adjustment_set_value (priv->adjustment, new_value);
1622 }
1623
1624 /* update the adjustment value for the reconnect animation:
1625 * set_scroll_cb could be running at that time. */
1626 priv->value = new_value;
1627}
1628
1629static gboolean1585static gboolean
1630thumb_motion_notify_event_cb (GtkWidget *widget,1586thumb_motion_notify_event_cb (GtkWidget *widget,
1631 GdkEventMotion *event,1587 GdkEventMotion *event,
@@ -1641,7 +1597,9 @@
1641 {1597 {
1642 gint x, y;1598 gint x, y;
16431599
1644 /* reconnect slider and overlay after key press */1600 /* thumb and pager are detached.
1601 * Detached scroll: keep the thumb detached during the scroll,
1602 * update the visual connection when reaching an edge. */
1645 if (priv->value_changed_event)1603 if (priv->value_changed_event)
1646 {1604 {
1647 /* return if the mouse movement is small. */1605 /* return if the mouse movement is small. */
@@ -1649,59 +1607,114 @@
1649 abs (priv->pointer_y - event->y) <= TOLERANCE_PIXELS)1607 abs (priv->pointer_y - event->y) <= TOLERANCE_PIXELS)
1650 return FALSE;1608 return FALSE;
16511609
1652 if (priv->orientation == GTK_ORIENTATION_VERTICAL)1610 priv->detached_scroll = TRUE;
1653 {
1654 priv->slide_initial_slider_position = event->y_root - priv->win_y - event->y;
1655 priv->slide_initial_coordinate = event->y_root;
1656 }
1657 else
1658 {
1659 priv->slide_initial_slider_position = event->x_root - priv->win_x - event->x;
1660 priv->slide_initial_coordinate = event->x_root;
1661 }
16621611
1663 /* stop the scroll animation if it's running. */1612 /* stop the scroll animation if it's running. */
1664 os_animation_stop (priv->animation, set_scroll_stop_cb);1613 os_animation_stop (priv->animation, NULL);
16651614
1666 /* set the initial adjustment value required for reconnect. */1615 /* limit x and y within the allocation. */
1667 capture_movement_for_animation (scrollbar, event->x_root, event->y_root);
1668
1669 /* animate the reconnect, using the same animation object. */
1670 os_animation_start (priv->animation);
1671
1672 priv->value_changed_event = FALSE;
1673 }
1674
1675 /* only the reconnect animation can be running at that time. */
1676 if (os_animation_is_running (priv->animation))
1677 {
1678 /* update the adjustment value. */
1679 capture_movement_for_animation (scrollbar, event->x_root, event->y_root);
1680
1681 /* limit x and y within the thumb allocation. */
1682 if (priv->orientation == GTK_ORIENTATION_VERTICAL)1616 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
1683 {1617 {
1684 x = priv->win_x;1618 x = priv->win_x;
1685 y = CLAMP (event->y_root - priv->pointer_y,1619 y = CLAMP (event->y_root - priv->pointer_y,
1686 priv->win_y,1620 priv->win_y,
1687 priv->win_y + priv->thumb_all.height);1621 priv->win_y + priv->thumb_all.height - priv->slider.height);
1688 }1622 }
1689 else1623 else
1690 {1624 {
1691 x = CLAMP (event->x_root - priv->pointer_x,1625 x = CLAMP (event->x_root - priv->pointer_x,
1692 priv->win_x,1626 priv->win_x,
1693 priv->win_x + priv->thumb_all.width);1627 priv->win_x + priv->thumb_all.width - priv->slider.width);
1694 y = priv->win_y;1628 y = priv->win_y;
1695 }1629 }
16961630
1631 /* fine scroll while detached,
1632 * do not scroll when hitting an edge. */
1633 if ((priv->orientation == GTK_ORIENTATION_VERTICAL &&
1634 y > priv->win_y &&
1635 y < priv->win_y + priv->thumb_all.height - priv->slider.height) ||
1636 (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1637 x > priv->win_x &&
1638 x < priv->win_x + priv->thumb_all.width - priv->slider.width))
1639 capture_movement (scrollbar, event->x_root, event->y_root);
1640
1697 move_thumb (scrollbar, x, y);1641 move_thumb (scrollbar, x, y);
16981642
1699 /* return if the reconnect animation is still running after1643 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
1700 * capture_movement_for_animation. */1644 {
1701 if (os_animation_is_running (priv->animation))1645 if (gtk_adjustment_get_value (priv->adjustment) == 0)
1702 return FALSE;1646 {
1647 update_visual_connection (scrollbar);
1648
1649 if (priv->overlay.height > priv->slider.height)
1650 {
1651 priv->slide_initial_slider_position = 0;
1652 priv->slide_initial_coordinate = MAX (event->y_root, priv->win_y + priv->pointer_y);
1653 }
1654 else
1655 {
1656 priv->slide_initial_slider_position = 0;
1657 priv->slide_initial_coordinate = event->y_root;
1658 }
1659 }
1660 else if (priv->overlay.y + priv->overlay.height >= priv->trough.height)
1661 {
1662 update_visual_connection (scrollbar);
1663
1664 if (priv->overlay.height > priv->slider.height)
1665 {
1666 priv->slide_initial_slider_position = priv->trough.height - priv->overlay.height;
1667 priv->slide_initial_coordinate = MAX (event->y_root, priv->win_y + priv->pointer_y);
1668 }
1669 else
1670 {
1671 priv->slide_initial_slider_position = priv->trough.height - priv->slider.height;
1672 priv->slide_initial_coordinate = event->y_root;
1673 }
1674 }
1675 }
1676 else
1677 {
1678 if (gtk_adjustment_get_value (priv->adjustment) == 0)
1679 {
1680 update_visual_connection (scrollbar);
1681
1682 if (priv->overlay.width > priv->slider.width)
1683 {
1684 priv->slide_initial_slider_position = 0;
1685 priv->slide_initial_coordinate = MAX (event->x_root, priv->win_x + priv->pointer_x);
1686 }
1687 else
1688 {
1689 priv->slide_initial_slider_position = 0;
1690 priv->slide_initial_coordinate = event->x_root;
1691 }
1692 }
1693 else if (priv->overlay.x + priv->overlay.width >= priv->trough.width)
1694 {
1695 update_visual_connection (scrollbar);
1696
1697 if (priv->overlay.width > priv->slider.width)
1698 {
1699 priv->slide_initial_slider_position = priv->trough.width - priv->overlay.width;
1700 priv->slide_initial_coordinate = MAX (event->x_root, priv->win_x + priv->pointer_x);
1701 }
1702 else
1703 {
1704 priv->slide_initial_slider_position = priv->trough.width - priv->slider.width;
1705 priv->slide_initial_coordinate = event->x_root;
1706 }
1707 }
1708 }
1709
1710 return FALSE;
1703 }1711 }
17041712
1713 OS_DCHECK (!priv->detached_scroll);
1714
1715 /* thumb and pager are connected.
1716 * Normal scroll: keep the thumb in sync with the pager,
1717 * do not update the visual connection. */
1705 priv->motion_notify_event = TRUE;1718 priv->motion_notify_event = TRUE;
17061719
1707 capture_movement (scrollbar, event->x_root, event->y_root);1720 capture_movement (scrollbar, event->x_root, event->y_root);
@@ -1821,9 +1834,12 @@
1821 scrollbar = OS_SCROLLBAR (user_data);1834 scrollbar = OS_SCROLLBAR (user_data);
1822 priv = scrollbar->priv;1835 priv = scrollbar->priv;
18231836
1837 priv->detached_scroll = FALSE;
1838
1824 priv->button_press_event = FALSE;1839 priv->button_press_event = FALSE;
1825 priv->motion_notify_event = FALSE;1840 priv->motion_notify_event = FALSE;
1826 priv->enter_notify_event = FALSE;1841 priv->enter_notify_event = FALSE;
1842 priv->value_changed_event = FALSE;
18271843
1828 os_pager_set_detached (priv->pager, FALSE);1844 os_pager_set_detached (priv->pager, FALSE);
1829}1845}
@@ -2563,6 +2579,7 @@
2563 priv->active_window = FALSE;2579 priv->active_window = FALSE;
2564 priv->can_deactivate_pager = TRUE;2580 priv->can_deactivate_pager = TRUE;
2565 priv->can_hide = TRUE;2581 priv->can_hide = TRUE;
2582 priv->detached_scroll = FALSE;
2566 priv->filter = FALSE;2583 priv->filter = FALSE;
2567 priv->fullsize = FALSE;2584 priv->fullsize = FALSE;
2568 priv->internal = FALSE;2585 priv->internal = FALSE;

Subscribers

People subscribed via source and target branches