gestures: Add remove() call to SugarGestureGrabber
Signed-off-by: Carlos Garnacho <carlos@lanedo.com> Acked-by: Simon Schampijer <simon@laptop.org>
This commit is contained in:
parent
31d6e6dd1e
commit
c546aaaf7c
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user