mirror of
https://github.com/brl/mutter.git
synced 2024-11-12 17:27:03 -05:00
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
This commit is contained in:
parent
959eb98090
commit
0947bc37d3
@ -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)
|
||||
|
@ -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:
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user