From 0947bc37d3d92888a0fc8f9dfaf0d54aaa2a9bef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Sun, 14 Apr 2019 18:43:49 +0200 Subject: [PATCH] clutter/main: Move grabbing functions to clutter-input-device.c Thanks to the now removed global/context grabs, we can move pointer and keyboard grabs back home to where they belong. While at it, also add handling of CLUTTER_TABLET_DEVICE devices to `on_grab_actor_destroy` and `clutter_input_device_get_grabbed_actor`. https://gitlab.gnome.org/GNOME/mutter/merge_requests/536 --- clutter/clutter/clutter-input-device.c | 151 +++++++++++++++++++++++++ clutter/clutter/clutter-main.c | 149 ------------------------ 2 files changed, 151 insertions(+), 149 deletions(-) diff --git a/clutter/clutter/clutter-input-device.c b/clutter/clutter/clutter-input-device.c index c289f81b7..c664e83f1 100644 --- a/clutter/clutter/clutter-input-device.c +++ b/clutter/clutter/clutter-input-device.c @@ -1925,6 +1925,157 @@ _clutter_input_device_reset_scroll_info (ClutterInputDevice *device) } } +static void +on_grab_actor_destroy (ClutterActor *actor, + ClutterInputDevice *device) +{ + switch (device->device_type) + { + case CLUTTER_POINTER_DEVICE: + case CLUTTER_TABLET_DEVICE: + device->pointer_grab_actor = NULL; + break; + + case CLUTTER_KEYBOARD_DEVICE: + device->keyboard_grab_actor = NULL; + break; + + default: + g_assert_not_reached (); + } +} + +/** + * clutter_input_device_grab: + * @device: a #ClutterInputDevice + * @actor: a #ClutterActor + * + * Acquires a grab on @actor for the given @device. + * + * Any event coming from @device will be delivered to @actor, bypassing + * the usual event delivery mechanism, until the grab is released by + * calling clutter_input_device_ungrab(). + * + * The grab is client-side: even if the windowing system used by the Clutter + * backend has the concept of "device grabs", Clutter will not use them. + * + * Only #ClutterInputDevice of types %CLUTTER_POINTER_DEVICE, + * %CLUTTER_TABLET_DEVICE and %CLUTTER_KEYBOARD_DEVICE can hold a grab. + * + * Since: 1.10 + */ +void +clutter_input_device_grab (ClutterInputDevice *device, + ClutterActor *actor) +{ + ClutterActor **grab_actor; + + g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device)); + g_return_if_fail (CLUTTER_IS_ACTOR (actor)); + + switch (device->device_type) + { + case CLUTTER_POINTER_DEVICE: + case CLUTTER_TABLET_DEVICE: + grab_actor = &device->pointer_grab_actor; + break; + + case CLUTTER_KEYBOARD_DEVICE: + grab_actor = &device->keyboard_grab_actor; + break; + + default: + g_critical ("Only pointer and keyboard devices can grab an actor"); + return; + } + + if (*grab_actor != NULL) + { + g_signal_handlers_disconnect_by_func (*grab_actor, + G_CALLBACK (on_grab_actor_destroy), + device); + } + + *grab_actor = actor; + + g_signal_connect (*grab_actor, + "destroy", + G_CALLBACK (on_grab_actor_destroy), + device); +} + +/** + * clutter_input_device_ungrab: + * @device: a #ClutterInputDevice + * + * Releases the grab on the @device, if one is in place. + * + * Since: 1.10 + */ +void +clutter_input_device_ungrab (ClutterInputDevice *device) +{ + ClutterActor **grab_actor; + + g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device)); + + switch (device->device_type) + { + case CLUTTER_POINTER_DEVICE: + case CLUTTER_TABLET_DEVICE: + grab_actor = &device->pointer_grab_actor; + break; + + case CLUTTER_KEYBOARD_DEVICE: + grab_actor = &device->keyboard_grab_actor; + break; + + default: + return; + } + + if (*grab_actor == NULL) + return; + + g_signal_handlers_disconnect_by_func (*grab_actor, + G_CALLBACK (on_grab_actor_destroy), + device); + + *grab_actor = NULL; +} + +/** + * clutter_input_device_get_grabbed_actor: + * @device: a #ClutterInputDevice + * + * Retrieves a pointer to the #ClutterActor currently grabbing all + * the events coming from @device. + * + * Return value: (transfer none): a #ClutterActor, or %NULL + * + * Since: 1.10 + */ +ClutterActor * +clutter_input_device_get_grabbed_actor (ClutterInputDevice *device) +{ + g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL); + + switch (device->device_type) + { + case CLUTTER_POINTER_DEVICE: + case CLUTTER_TABLET_DEVICE: + return device->pointer_grab_actor; + + case CLUTTER_KEYBOARD_DEVICE: + return device->keyboard_grab_actor; + + default: + g_critical ("Only pointer and keyboard devices can grab an actor"); + } + + return NULL; +} + static void on_grab_sequence_actor_destroy (ClutterActor *actor, ClutterInputDevice *device) diff --git a/clutter/clutter/clutter-main.c b/clutter/clutter/clutter-main.c index 5de7602dd..899799e53 100644 --- a/clutter/clutter/clutter-main.c +++ b/clutter/clutter/clutter-main.c @@ -2335,155 +2335,6 @@ clutter_get_default_frame_rate (void) return context->frame_rate; } -static void -on_grab_actor_destroy (ClutterActor *actor, - ClutterInputDevice *device) -{ - switch (device->device_type) - { - case CLUTTER_POINTER_DEVICE: - device->pointer_grab_actor = NULL; - break; - - case CLUTTER_KEYBOARD_DEVICE: - device->keyboard_grab_actor = NULL; - break; - - default: - g_assert_not_reached (); - } -} - -/** - * clutter_input_device_grab: - * @device: a #ClutterInputDevice - * @actor: a #ClutterActor - * - * Acquires a grab on @actor for the given @device. - * - * Any event coming from @device will be delivered to @actor, bypassing - * the usual event delivery mechanism, until the grab is released by - * calling clutter_input_device_ungrab(). - * - * The grab is client-side: even if the windowing system used by the Clutter - * backend has the concept of "device grabs", Clutter will not use them. - * - * Only #ClutterInputDevice of types %CLUTTER_POINTER_DEVICE and - * %CLUTTER_KEYBOARD_DEVICE can hold a grab. - * - * Since: 1.10 - */ -void -clutter_input_device_grab (ClutterInputDevice *device, - ClutterActor *actor) -{ - ClutterActor **grab_actor; - - g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device)); - g_return_if_fail (CLUTTER_IS_ACTOR (actor)); - - switch (device->device_type) - { - case CLUTTER_POINTER_DEVICE: - case CLUTTER_TABLET_DEVICE: - grab_actor = &(device->pointer_grab_actor); - break; - - case CLUTTER_KEYBOARD_DEVICE: - grab_actor = &(device->keyboard_grab_actor); - break; - - default: - g_critical ("Only pointer and keyboard devices can grab an actor"); - return; - } - - if (*grab_actor != NULL) - { - g_signal_handlers_disconnect_by_func (*grab_actor, - G_CALLBACK (on_grab_actor_destroy), - device); - } - - *grab_actor = actor; - - g_signal_connect (*grab_actor, - "destroy", - G_CALLBACK (on_grab_actor_destroy), - device); -} - -/** - * clutter_input_device_ungrab: - * @device: a #ClutterInputDevice - * - * Releases the grab on the @device, if one is in place. - * - * Since: 1.10 - */ -void -clutter_input_device_ungrab (ClutterInputDevice *device) -{ - ClutterActor **grab_actor; - - g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device)); - - switch (device->device_type) - { - case CLUTTER_POINTER_DEVICE: - case CLUTTER_TABLET_DEVICE: - grab_actor = &(device->pointer_grab_actor); - break; - - case CLUTTER_KEYBOARD_DEVICE: - grab_actor = &(device->keyboard_grab_actor); - break; - - default: - return; - } - - if (*grab_actor == NULL) - return; - - g_signal_handlers_disconnect_by_func (*grab_actor, - G_CALLBACK (on_grab_actor_destroy), - device); - - *grab_actor = NULL; -} - -/** - * clutter_input_device_get_grabbed_actor: - * @device: a #ClutterInputDevice - * - * Retrieves a pointer to the #ClutterActor currently grabbing all - * the events coming from @device. - * - * Return value: (transfer none): a #ClutterActor, or %NULL - * - * Since: 1.10 - */ -ClutterActor * -clutter_input_device_get_grabbed_actor (ClutterInputDevice *device) -{ - g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL); - - switch (device->device_type) - { - case CLUTTER_POINTER_DEVICE: - return device->pointer_grab_actor; - - case CLUTTER_KEYBOARD_DEVICE: - return device->keyboard_grab_actor; - - default: - g_critical ("Only pointer and keyboard devices can grab an actor"); - } - - return NULL; -} - /** * clutter_get_font_map: *