From c546aaaf7cab3a912c5245e024356a8d789feaa2 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 8 Oct 2012 12:09:20 +0200 Subject: [PATCH 1/2] gestures: Add remove() call to SugarGestureGrabber Signed-off-by: Carlos Garnacho Acked-by: Simon Schampijer --- src/sugar3/sugar-gesture-grabber.c | 53 ++++++++++++++++++++++++++++++ src/sugar3/sugar-gesture-grabber.h | 2 ++ 2 files changed, 55 insertions(+) diff --git a/src/sugar3/sugar-gesture-grabber.c b/src/sugar3/sugar-gesture-grabber.c index b1d28db8..211e637a 100644 --- a/src/sugar3/sugar-gesture-grabber.c +++ b/src/sugar3/sugar-gesture-grabber.c @@ -366,6 +366,32 @@ sugar_gesture_grabber_new (void) return g_object_new (SUGAR_TYPE_GESTURE_GRABBER, NULL); } +static ControllerData * +_sugar_gesture_grabber_find_controller (SugarGestureGrabber *grabber, + SugarEventController *controller, + gint *pos) +{ + SugarGestureGrabberPriv *priv; + guint i; + + priv = grabber->_priv; + + for (i = 0; i < priv->controllers->len; i++) { + ControllerData *data; + + data = &g_array_index (priv->controllers, ControllerData, i); + + if (data->controller == controller) { + if (pos) + *pos = i; + + return data; + } + } + + return NULL; +} + void sugar_gesture_grabber_add (SugarGestureGrabber *grabber, SugarEventController *controller, @@ -377,9 +403,36 @@ sugar_gesture_grabber_add (SugarGestureGrabber *grabber, g_return_if_fail (SUGAR_IS_GESTURE_GRABBER (grabber)); g_return_if_fail (SUGAR_IS_EVENT_CONTROLLER (controller)); + if (_sugar_gesture_grabber_find_controller (grabber, controller, NULL)) { + g_warning ("Controller is already on the gesture grabber" + " list. Controllers can only be added once."); + return; + } + priv = grabber->_priv; data.controller = g_object_ref (controller); data.rect = *rect; g_array_append_val (priv->controllers, data); } + +void +sugar_gesture_grabber_remove (SugarGestureGrabber *grabber, + SugarEventController *controller) +{ + SugarGestureGrabberPriv *priv; + ControllerData *data; + gint pos; + + g_return_if_fail (SUGAR_IS_GESTURE_GRABBER (grabber)); + g_return_if_fail (SUGAR_IS_EVENT_CONTROLLER (controller)); + + priv = grabber->_priv; + data = _sugar_gesture_grabber_find_controller (grabber, controller, &pos); + + if (data) { + g_array_remove_index_fast (priv->controllers, pos); + sugar_event_controller_reset (data->controller); + g_object_unref (data->controller); + } +} diff --git a/src/sugar3/sugar-gesture-grabber.h b/src/sugar3/sugar-gesture-grabber.h index 2d956a33..d6c8c4b5 100644 --- a/src/sugar3/sugar-gesture-grabber.h +++ b/src/sugar3/sugar-gesture-grabber.h @@ -51,6 +51,8 @@ SugarGestureGrabber * sugar_gesture_grabber_new (void); void sugar_gesture_grabber_add (SugarGestureGrabber *grabber, SugarEventController *controller, const GdkRectangle *rect); +void sugar_gesture_grabber_remove (SugarGestureGrabber *grabber, + SugarEventController *controller); G_END_DECLS From f569e7ef981a9c8447ff304eb8d040676390ef7b Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Mon, 8 Oct 2012 13:03:43 +0200 Subject: [PATCH 2/2] Cleanup: remove unused variable --- src/sugar3/sugar-gesture-grabber.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sugar3/sugar-gesture-grabber.c b/src/sugar3/sugar-gesture-grabber.c index 211e637a..186d8ac7 100644 --- a/src/sugar3/sugar-gesture-grabber.c +++ b/src/sugar3/sugar-gesture-grabber.c @@ -258,7 +258,6 @@ filter_function (GdkXEvent *xevent, SugarGestureGrabber *grabber; SugarGestureGrabberPriv *priv; gboolean handled = FALSE; - Window event_window; GdkDevice *device; XIDeviceEvent *ev; GdkDisplay *display;