clutter/main: Remove global/context grabs

Those are deprecated in favour of per device grabs.

Also switch to ClutterInputDevice grabs for the grab test.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/536
This commit is contained in:
Jonas Dreßler 2019-04-14 18:30:31 +02:00
parent 32dcf77a8f
commit 959eb98090
4 changed files with 28 additions and 255 deletions

View File

@ -1701,37 +1701,19 @@ static inline void
emit_pointer_event (ClutterEvent *event,
ClutterInputDevice *device)
{
ClutterMainContext *context = _clutter_context_get_default ();
if (_clutter_event_process_filters (event))
return;
if (context->pointer_grab_actor == NULL &&
(device == NULL || device->pointer_grab_actor == NULL))
{
/* no grab, time to capture and bubble */
emit_event_chain (event);
}
if (device != NULL && device->pointer_grab_actor != NULL)
clutter_actor_event (device->pointer_grab_actor, event, FALSE);
else
{
if (context->pointer_grab_actor != NULL)
{
/* global grab */
clutter_actor_event (context->pointer_grab_actor, event, FALSE);
}
else if (device != NULL && device->pointer_grab_actor != NULL)
{
/* per device grab */
clutter_actor_event (device->pointer_grab_actor, event, FALSE);
}
}
emit_event_chain (event);
}
static inline void
emit_crossing_event (ClutterEvent *event,
ClutterInputDevice *device)
{
ClutterMainContext *context = _clutter_context_get_default ();
ClutterEventSequence *sequence = clutter_event_get_event_sequence (event);
ClutterActor *grab_actor = NULL;
@ -1745,9 +1727,7 @@ emit_crossing_event (ClutterEvent *event,
}
else
{
if (context->pointer_grab_actor != NULL)
grab_actor = context->pointer_grab_actor;
else if (device != NULL && device->pointer_grab_actor != NULL)
if (device != NULL && device->pointer_grab_actor != NULL)
grab_actor = device->pointer_grab_actor;
}
@ -1788,30 +1768,13 @@ static inline void
emit_keyboard_event (ClutterEvent *event,
ClutterInputDevice *device)
{
ClutterMainContext *context = _clutter_context_get_default ();
if (_clutter_event_process_filters (event))
return;
if (context->keyboard_grab_actor == NULL &&
(device == NULL || device->keyboard_grab_actor == NULL))
{
/* no grab, time to capture and bubble */
emit_event_chain (event);
}
if (device != NULL && device->keyboard_grab_actor != NULL)
clutter_actor_event (device->keyboard_grab_actor, event, FALSE);
else
{
if (context->keyboard_grab_actor != NULL)
{
/* global key grab */
clutter_actor_event (context->keyboard_grab_actor, event, FALSE);
}
else if (device != NULL && device->keyboard_grab_actor != NULL)
{
/* per-device key grab */
clutter_actor_event (context->keyboard_grab_actor, event, FALSE);
}
}
emit_event_chain (event);
}
static inline void
@ -2009,15 +1972,7 @@ _clutter_process_event_details (ClutterActor *stage,
if (_clutter_event_process_filters (event))
break;
/* global grabs */
if (context->pointer_grab_actor != NULL)
{
clutter_actor_event (context->pointer_grab_actor,
event,
FALSE);
break;
}
else if (device != NULL && device->pointer_grab_actor != NULL)
if (device != NULL && device->pointer_grab_actor != NULL)
{
clutter_actor_event (device->pointer_grab_actor,
event,
@ -2384,19 +2339,6 @@ static void
on_grab_actor_destroy (ClutterActor *actor,
ClutterInputDevice *device)
{
if (device == NULL)
{
ClutterMainContext *context = _clutter_context_get_default ();
if (context->pointer_grab_actor == actor)
clutter_ungrab_pointer ();
if (context->keyboard_grab_actor == actor)
clutter_ungrab_keyboard ();
return;
}
switch (device->device_type)
{
case CLUTTER_POINTER_DEVICE:
@ -2412,58 +2354,6 @@ on_grab_actor_destroy (ClutterActor *actor,
}
}
/**
* clutter_grab_pointer:
* @actor: a #ClutterActor
*
* Grabs pointer events, after the grab is done all pointer related events
* (press, motion, release, enter, leave and scroll) are delivered to this
* actor directly without passing through both capture and bubble phases of
* the event delivery chain. The source set in the event will be the actor
* that would have received the event if the pointer grab was not in effect.
*
* Grabs completely override the entire event delivery chain
* done by Clutter. Pointer grabs should only be used as a last resource;
* using the #ClutterActor::captured-event signal should always be the
* preferred way to intercept event delivery to reactive actors.
*
* This function should rarely be used.
*
* If a grab is required, you are strongly encouraged to use a specific
* input device by calling clutter_input_device_grab().
*
* Since: 0.6
*/
void
clutter_grab_pointer (ClutterActor *actor)
{
ClutterMainContext *context;
g_return_if_fail (actor == NULL || CLUTTER_IS_ACTOR (actor));
context = _clutter_context_get_default ();
if (context->pointer_grab_actor == actor)
return;
if (context->pointer_grab_actor != NULL)
{
g_signal_handlers_disconnect_by_func (context->pointer_grab_actor,
G_CALLBACK (on_grab_actor_destroy),
NULL);
context->pointer_grab_actor = NULL;
}
if (actor != NULL)
{
context->pointer_grab_actor = actor;
g_signal_connect (context->pointer_grab_actor, "destroy",
G_CALLBACK (on_grab_actor_destroy),
NULL);
}
}
/**
* clutter_input_device_grab:
* @device: a #ClutterInputDevice
@ -2594,118 +2484,6 @@ clutter_input_device_get_grabbed_actor (ClutterInputDevice *device)
return NULL;
}
/**
* clutter_ungrab_pointer:
*
* Removes an existing grab of the pointer.
*
* Since: 0.6
*/
void
clutter_ungrab_pointer (void)
{
clutter_grab_pointer (NULL);
}
/**
* clutter_get_pointer_grab:
*
* Queries the current pointer grab of clutter.
*
* Return value: (transfer none): the actor currently holding the pointer grab, or NULL if there is no grab.
*
* Since: 0.6
*/
ClutterActor *
clutter_get_pointer_grab (void)
{
ClutterMainContext *context;
context = _clutter_context_get_default ();
return context->pointer_grab_actor;
}
/**
* clutter_grab_keyboard:
* @actor: a #ClutterActor
*
* Grabs keyboard events, after the grab is done keyboard
* events (#ClutterActor::key-press-event and #ClutterActor::key-release-event)
* are delivered to this actor directly. The source set in the event will be
* the actor that would have received the event if the keyboard grab was not
* in effect.
*
* Like pointer grabs, keyboard grabs should only be used as a last
* resource.
*
* See also clutter_stage_set_key_focus() and clutter_actor_grab_key_focus()
* to perform a "soft" key grab and assign key focus to a specific actor.
*
* Since: 0.6
*/
void
clutter_grab_keyboard (ClutterActor *actor)
{
ClutterMainContext *context;
g_return_if_fail (actor == NULL || CLUTTER_IS_ACTOR (actor));
context = _clutter_context_get_default ();
if (context->keyboard_grab_actor == actor)
return;
if (context->keyboard_grab_actor != NULL)
{
g_signal_handlers_disconnect_by_func (context->keyboard_grab_actor,
G_CALLBACK (on_grab_actor_destroy),
NULL);
context->keyboard_grab_actor = NULL;
}
if (actor != NULL)
{
context->keyboard_grab_actor = actor;
g_signal_connect (context->keyboard_grab_actor, "destroy",
G_CALLBACK (on_grab_actor_destroy),
NULL);
}
}
/**
* clutter_ungrab_keyboard:
*
* Removes an existing grab of the keyboard.
*
* Since: 0.6
*/
void
clutter_ungrab_keyboard (void)
{
clutter_grab_keyboard (NULL);
}
/**
* clutter_get_keyboard_grab:
*
* Queries the current keyboard grab of clutter.
*
* Return value: (transfer none): the actor currently holding the keyboard grab, or NULL if there is no grab.
*
* Since: 0.6
*/
ClutterActor *
clutter_get_keyboard_grab (void)
{
ClutterMainContext *context;
context = _clutter_context_get_default ();
return context->keyboard_grab_actor;
}
/**
* clutter_get_font_map:
*

View File

@ -146,19 +146,6 @@ guint clutter_threads_add_repaint_func_full (ClutterRepaintF
CLUTTER_EXPORT
void clutter_threads_remove_repaint_func (guint handle_id);
CLUTTER_EXPORT
void clutter_grab_pointer (ClutterActor *actor);
CLUTTER_EXPORT
void clutter_ungrab_pointer (void);
CLUTTER_EXPORT
ClutterActor * clutter_get_pointer_grab (void);
CLUTTER_EXPORT
void clutter_grab_keyboard (ClutterActor *actor);
CLUTTER_EXPORT
void clutter_ungrab_keyboard (void);
CLUTTER_EXPORT
ClutterActor * clutter_get_keyboard_grab (void);
CLUTTER_EXPORT
PangoFontMap * clutter_get_font_map (void);

View File

@ -142,10 +142,6 @@ struct _ClutterMainContext
/* default FPS; this is only used if we cannot sync to vblank */
guint frame_rate;
/* actors with a grab on all devices */
ClutterActor *pointer_grab_actor;
ClutterActor *keyboard_grab_actor;
/* fb bit masks for col<->id mapping in picking */
gint fb_r_mask;
gint fb_g_mask;

View File

@ -123,7 +123,9 @@ grab_pointer_cb (ClutterActor *actor,
ClutterEvent *event,
gpointer data)
{
clutter_grab_pointer (actor);
ClutterInputDevice *device = clutter_event_get_device (event);
clutter_input_device_grab (device, actor);
return FALSE;
}
@ -132,7 +134,9 @@ red_release_cb (ClutterActor *actor,
ClutterEvent *event,
gpointer data)
{
clutter_ungrab_pointer ();
ClutterInputDevice *device = clutter_event_get_device (event);
clutter_input_device_ungrab (device);
return FALSE;
}
@ -169,14 +173,17 @@ toggle_grab_pointer_cb (ClutterActor *actor,
ClutterEvent *event,
gpointer data)
{
ClutterInputDevice *device = clutter_event_get_device (event);
/* we only deal with the event if the source is ourself */
if (event->button.source == actor)
{
if (clutter_get_pointer_grab () != NULL)
clutter_ungrab_pointer ();
if (clutter_input_device_get_grabbed_actor (device) != NULL)
clutter_input_device_ungrab (device);
else
clutter_grab_pointer (actor);
clutter_input_device_grab (device, actor);
}
return FALSE;
}
@ -185,10 +192,15 @@ cyan_press_cb (ClutterActor *actor,
ClutterEvent *event,
gpointer data)
{
if (clutter_get_keyboard_grab () != NULL)
clutter_ungrab_keyboard ();
ClutterDeviceManager *dm = clutter_device_manager_get_default ();
ClutterInputDevice *device =
clutter_device_manager_get_core_device (dm, CLUTTER_KEYBOARD_DEVICE);
if (clutter_input_device_get_grabbed_actor (device) != NULL)
clutter_input_device_ungrab (device);
else
clutter_grab_keyboard (actor);
clutter_input_device_grab (device, actor);
return FALSE;
}