From a857cf56971b236331572da11d7e0424eee5c288 Mon Sep 17 00:00:00 2001 From: Nikita Zlobin Date: Thu, 12 May 2011 01:57:06 +0600 Subject: [PATCH] Limit redraw speed on module dragging --- src/gtkgraph-demo.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/gtkgraph-demo.c b/src/gtkgraph-demo.c index 68cdf99..8123858 100644 --- a/src/gtkgraph-demo.c +++ b/src/gtkgraph-demo.c @@ -285,6 +285,15 @@ static gboolean on_module_notify_height (GooCanvasItem * item, GParamSpec * even #define DRAG_HOLD_X( mod ) (G_MODULAR_GRAPH_MODULE( mod )->drag_hold_x) #define DRAG_HOLD_Y( mod ) (G_MODULAR_GRAPH_MODULE( mod )->drag_hold_y) +static gboolean drag_redraw = TRUE; +static unsigned drag_redraw_timeout_id = 0; + +static gboolean drag_redraw_timeout (gpointer data) +{ + drag_redraw = TRUE; + return TRUE; +} + static gboolean on_module_buttonPress_event (GooCanvasItem * item, GooCanvasItem * target, GdkEventButton * event, gpointer data) { @@ -295,12 +304,15 @@ gboolean on_module_buttonPress_event (GooCanvasItem * item, GooCanvasItem * targ DRAG_HOLD_Y (data) = event->y - DRAG_HOLD_Y (data); DRAG_CB (data) = g_signal_connect (G_OBJECT (root_item), "motion-notify-event", G_CALLBACK (on_module_dragged), data); + drag_redraw_timeout_id = g_timeout_add (20, drag_redraw_timeout, NULL); return FALSE; } static gboolean on_module_buttonRelease_event (GooCanvasItem * item, GooCanvasItem * target, GdkEventButton * event, gpointer data) { + g_source_remove (drag_redraw_timeout_id); + drag_redraw_timeout_id = 0; if (DRAG_CB (data)) g_signal_handler_disconnect (G_OBJECT (root_item), DRAG_CB (data)); return FALSE; @@ -309,9 +321,12 @@ gboolean on_module_buttonRelease_event (GooCanvasItem * item, GooCanvasItem * ta static gboolean on_module_dragged (GooCanvasItem * item, GooCanvasItem * target, GdkEventMotion * event, gpointer data) { - g_object_set (G_MODULAR_GRAPH_MODULE (data)->group, "x", event->x - DRAG_HOLD_X (data), NULL); - g_object_set (G_MODULAR_GRAPH_MODULE (data)->group, "y", event->y - DRAG_HOLD_Y (data), NULL); - + if (drag_redraw) + { + g_object_set (G_MODULAR_GRAPH_MODULE (data)->group, "x", event->x - DRAG_HOLD_X (data), NULL); + g_object_set (G_MODULAR_GRAPH_MODULE (data)->group, "y", event->y - DRAG_HOLD_Y (data), NULL); + drag_redraw = FALSE; + } return FALSE; } -- 2.11.4.GIT