Merge lp:~cimi/overlay-scrollbar/fix-758046 into lp:overlay-scrollbar

Proposed by Andrea Cimitan
Status: Merged
Approved by: Ted Gould
Approved revision: 207
Merged at revision: 207
Proposed branch: lp:~cimi/overlay-scrollbar/fix-758046
Merge into: lp:overlay-scrollbar
Diff against target: 108 lines (+26/-22)
1 file modified
os/os-thumb.c (+26/-22)
To merge this branch: bzr merge lp:~cimi/overlay-scrollbar/fix-758046
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+57364@code.launchpad.net

Description of the change

Implement tolerance

To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote :

You shouldn't need to use the floating point absolute value here. (fabs). Other than that it seems good.

review: Approve
208. By Andrea Cimitan

use abs instead fabs

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'os/os-thumb.c'
2--- os/os-thumb.c 2011-04-07 16:14:09 +0000
3+++ os/os-thumb.c 2011-04-13 09:34:31 +0000
4@@ -27,15 +27,18 @@
5 #include "os-private.h"
6 #include "math.h"
7
8-/* Rate of the fade-out */
9+/* Rate of the fade-out. */
10 #define RATE_FADE_OUT 30
11
12-/* Duration of the fade-out */
13+/* Duration of the fade-out. */
14 #define DURATION_FADE_OUT 2000
15
16-/* Timeout before the fade-out */
17+/* Timeout before the fade-out. */
18 #define TIMEOUT_FADE_OUT 250
19
20+/* Number of tolerance pixels. */
21+#define TOLERANCE_PIXELS 3
22+
23 struct _OsThumbPrivate {
24 GtkOrientation orientation;
25 GtkWidget *grabbed_widget;
26@@ -43,6 +46,7 @@
27 gboolean button_press_event;
28 gboolean motion_notify_event;
29 gboolean can_rgba;
30+ gboolean use_tolerance;
31 gint pointer_x;
32 gint pointer_y;
33 guint32 source_id;
34@@ -279,6 +283,8 @@
35 priv->button_press_event = TRUE;
36 priv->motion_notify_event = FALSE;
37
38+ priv->use_tolerance = TRUE;
39+
40 gtk_widget_queue_draw (widget);
41 }
42 }
43@@ -299,21 +305,6 @@
44
45 gtk_widget_get_allocation (widget, &allocation);
46
47- if (priv->source_id != 0)
48- {
49- g_source_remove (priv->source_id);
50- priv->source_id = 0;
51- }
52-
53- /* Add the fade-out timeout only
54- * if the pointer is inside the thumb.
55- * allocation.x and allocation.y are always 0. */
56- if ((event->x >= 0 && event->x <= allocation.width) &&
57- (event->y >= 0 && event->y <= allocation.height))
58- priv->source_id = g_timeout_add (TIMEOUT_FADE_OUT,
59- os_thumb_timeout_fade_out_cb,
60- thumb);
61-
62 if (event->type == GDK_BUTTON_RELEASE)
63 {
64 if (event->button == 1)
65@@ -588,6 +579,8 @@
66 }
67 }
68
69+ priv->use_tolerance = FALSE;
70+
71 return FALSE;
72 }
73
74@@ -637,13 +630,22 @@
75 gtk_window_set_opacity (GTK_WINDOW (widget), 1.0f);
76 }
77
78- /* If you're not dragging, enable the fade-out.
79+ /* If you're not dragging, and you're outside
80+ * the tolerance pixels, enable the fade-out.
81 * priv->motion_notify_event is TRUE only on dragging,
82 * see code few lines below. */
83 if (!priv->motion_notify_event)
84- priv->source_id = g_timeout_add (TIMEOUT_FADE_OUT,
85- os_thumb_timeout_fade_out_cb,
86- thumb);
87+ {
88+ if (!priv->use_tolerance ||
89+ (abs (priv->pointer_x - event->x) > TOLERANCE_PIXELS ||
90+ abs (priv->pointer_y - event->y) > TOLERANCE_PIXELS))
91+ {
92+ priv->use_tolerance = FALSE;
93+ priv->source_id = g_timeout_add (TIMEOUT_FADE_OUT,
94+ os_thumb_timeout_fade_out_cb,
95+ thumb);
96+ }
97+ }
98
99 if (priv->button_press_event)
100 {
101@@ -709,6 +711,8 @@
102 priv->button_press_event = FALSE;
103 priv->motion_notify_event = FALSE;
104
105+ priv->use_tolerance = FALSE;
106+
107 if (priv->grabbed_widget != NULL)
108 gtk_grab_add (priv->grabbed_widget);
109

Subscribers

People subscribed via source and target branches