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
=== modified file 'os/os-thumb.c'
--- os/os-thumb.c 2011-04-07 16:14:09 +0000
+++ os/os-thumb.c 2011-04-13 09:34:31 +0000
@@ -27,15 +27,18 @@
27#include "os-private.h"27#include "os-private.h"
28#include "math.h"28#include "math.h"
2929
30/* Rate of the fade-out */30/* Rate of the fade-out. */
31#define RATE_FADE_OUT 3031#define RATE_FADE_OUT 30
3232
33/* Duration of the fade-out */33/* Duration of the fade-out. */
34#define DURATION_FADE_OUT 200034#define DURATION_FADE_OUT 2000
3535
36/* Timeout before the fade-out */36/* Timeout before the fade-out. */
37#define TIMEOUT_FADE_OUT 25037#define TIMEOUT_FADE_OUT 250
3838
39/* Number of tolerance pixels. */
40#define TOLERANCE_PIXELS 3
41
39struct _OsThumbPrivate {42struct _OsThumbPrivate {
40 GtkOrientation orientation;43 GtkOrientation orientation;
41 GtkWidget *grabbed_widget;44 GtkWidget *grabbed_widget;
@@ -43,6 +46,7 @@
43 gboolean button_press_event;46 gboolean button_press_event;
44 gboolean motion_notify_event;47 gboolean motion_notify_event;
45 gboolean can_rgba;48 gboolean can_rgba;
49 gboolean use_tolerance;
46 gint pointer_x;50 gint pointer_x;
47 gint pointer_y;51 gint pointer_y;
48 guint32 source_id;52 guint32 source_id;
@@ -279,6 +283,8 @@
279 priv->button_press_event = TRUE;283 priv->button_press_event = TRUE;
280 priv->motion_notify_event = FALSE;284 priv->motion_notify_event = FALSE;
281285
286 priv->use_tolerance = TRUE;
287
282 gtk_widget_queue_draw (widget);288 gtk_widget_queue_draw (widget);
283 }289 }
284 }290 }
@@ -299,21 +305,6 @@
299305
300 gtk_widget_get_allocation (widget, &allocation);306 gtk_widget_get_allocation (widget, &allocation);
301307
302 if (priv->source_id != 0)
303 {
304 g_source_remove (priv->source_id);
305 priv->source_id = 0;
306 }
307
308 /* Add the fade-out timeout only
309 * if the pointer is inside the thumb.
310 * allocation.x and allocation.y are always 0. */
311 if ((event->x >= 0 && event->x <= allocation.width) &&
312 (event->y >= 0 && event->y <= allocation.height))
313 priv->source_id = g_timeout_add (TIMEOUT_FADE_OUT,
314 os_thumb_timeout_fade_out_cb,
315 thumb);
316
317 if (event->type == GDK_BUTTON_RELEASE)308 if (event->type == GDK_BUTTON_RELEASE)
318 {309 {
319 if (event->button == 1)310 if (event->button == 1)
@@ -588,6 +579,8 @@
588 }579 }
589 }580 }
590581
582 priv->use_tolerance = FALSE;
583
591 return FALSE;584 return FALSE;
592}585}
593586
@@ -637,13 +630,22 @@
637 gtk_window_set_opacity (GTK_WINDOW (widget), 1.0f);630 gtk_window_set_opacity (GTK_WINDOW (widget), 1.0f);
638 }631 }
639632
640 /* If you're not dragging, enable the fade-out.633 /* If you're not dragging, and you're outside
634 * the tolerance pixels, enable the fade-out.
641 * priv->motion_notify_event is TRUE only on dragging,635 * priv->motion_notify_event is TRUE only on dragging,
642 * see code few lines below. */636 * see code few lines below. */
643 if (!priv->motion_notify_event)637 if (!priv->motion_notify_event)
644 priv->source_id = g_timeout_add (TIMEOUT_FADE_OUT,638 {
645 os_thumb_timeout_fade_out_cb,639 if (!priv->use_tolerance ||
646 thumb);640 (abs (priv->pointer_x - event->x) > TOLERANCE_PIXELS ||
641 abs (priv->pointer_y - event->y) > TOLERANCE_PIXELS))
642 {
643 priv->use_tolerance = FALSE;
644 priv->source_id = g_timeout_add (TIMEOUT_FADE_OUT,
645 os_thumb_timeout_fade_out_cb,
646 thumb);
647 }
648 }
647649
648 if (priv->button_press_event)650 if (priv->button_press_event)
649 {651 {
@@ -709,6 +711,8 @@
709 priv->button_press_event = FALSE;711 priv->button_press_event = FALSE;
710 priv->motion_notify_event = FALSE;712 priv->motion_notify_event = FALSE;
711713
714 priv->use_tolerance = FALSE;
715
712 if (priv->grabbed_widget != NULL)716 if (priv->grabbed_widget != NULL)
713 gtk_grab_add (priv->grabbed_widget);717 gtk_grab_add (priv->grabbed_widget);
714718

Subscribers

People subscribed via source and target branches