1
0
Fork 0

wayland: Make MetaWaylandSeat in charge of its own tablet seat

The relation between seats and tablet seats is always 1:1, Make
the MetaWaylandSeat hold its own MetaWaylandTabletSeat, and
manipulate it directly.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3420>
This commit is contained in:
Carlos Garnacho 2023-11-02 14:35:23 +01:00
parent 5768caea81
commit a37fd34bbb
5 changed files with 41 additions and 141 deletions

View file

@ -226,6 +226,7 @@ meta_wayland_seat_new (MetaWaylandCompositor *compositor,
wl_global_create (display, &wl_seat_interface, META_WL_SEAT_VERSION, seat, bind_seat);
seat->tablet_seat =
meta_wayland_tablet_manager_ensure_seat (compositor->tablet_manager, seat);
return seat;
@ -305,10 +306,40 @@ out:
return hardware_device && supported_device;
}
static gboolean
is_tablet_event (MetaWaylandSeat *seat,
const ClutterEvent *event)
{
ClutterInputDevice *device;
ClutterInputCapabilities capabilities;
device = clutter_event_get_source_device (event);
capabilities = clutter_input_device_get_capabilities (device);
if (capabilities & CLUTTER_INPUT_CAPABILITY_TABLET_TOOL)
{
return meta_wayland_tablet_seat_lookup_tablet (seat->tablet_seat,
device) != NULL;
}
if (capabilities & CLUTTER_INPUT_CAPABILITY_TABLET_PAD)
{
return meta_wayland_tablet_seat_lookup_pad (seat->tablet_seat,
device) != NULL;
}
return FALSE;
}
void
meta_wayland_seat_update (MetaWaylandSeat *seat,
const ClutterEvent *event)
{
if (is_tablet_event (seat, event))
{
meta_wayland_tablet_seat_update (seat->tablet_seat, event);
return;
}
if (!(clutter_event_get_flags (event) & CLUTTER_EVENT_FLAG_INPUT_METHOD) &&
!event_from_supported_hardware_device (seat, event) &&
!event_is_synthesized_crossing (event))
@ -350,6 +381,9 @@ meta_wayland_seat_handle_event (MetaWaylandSeat *seat,
{
ClutterEventType event_type;
if (is_tablet_event (seat, event))
return meta_wayland_tablet_seat_handle_event (seat->tablet_seat, event);
if (!(clutter_event_get_flags (event) & CLUTTER_EVENT_FLAG_INPUT_METHOD) &&
!event_from_supported_hardware_device (seat, event))
return FALSE;
@ -413,9 +447,6 @@ void
meta_wayland_seat_set_input_focus (MetaWaylandSeat *seat,
MetaWaylandSurface *surface)
{
MetaWaylandCompositor *compositor = meta_wayland_seat_get_compositor (seat);
MetaWaylandTabletSeat *tablet_seat;
if (seat->input_focus == surface)
return;
@ -443,8 +474,7 @@ meta_wayland_seat_set_input_focus (MetaWaylandSeat *seat,
meta_wayland_data_device_primary_set_keyboard_focus (&seat->primary_data_device);
}
tablet_seat = meta_wayland_tablet_manager_ensure_seat (compositor->tablet_manager, seat);
meta_wayland_tablet_seat_set_pad_focus (tablet_seat, surface);
meta_wayland_tablet_seat_set_pad_focus (seat->tablet_seat, surface);
meta_wayland_text_input_set_focus (seat->text_input, surface);
}
@ -459,13 +489,9 @@ meta_wayland_seat_get_grab_info (MetaWaylandSeat *seat,
float *x,
float *y)
{
MetaWaylandCompositor *compositor;
MetaWaylandTabletSeat *tablet_seat;
GList *tools, *l;
compositor = meta_wayland_seat_get_compositor (seat);
tablet_seat = meta_wayland_tablet_manager_ensure_seat (compositor->tablet_manager, seat);
tools = g_hash_table_get_values (tablet_seat->tools);
tools = g_hash_table_get_values (seat->tablet_seat->tools);
if (meta_wayland_seat_has_touch (seat))
{
@ -536,17 +562,10 @@ gboolean
meta_wayland_seat_can_popup (MetaWaylandSeat *seat,
uint32_t serial)
{
MetaWaylandCompositor *compositor;
MetaWaylandTabletSeat *tablet_seat;
compositor = meta_wayland_seat_get_compositor (seat);
tablet_seat =
meta_wayland_tablet_manager_ensure_seat (compositor->tablet_manager, seat);
return (meta_wayland_pointer_can_popup (seat->pointer, serial) ||
meta_wayland_keyboard_can_popup (seat->keyboard, serial) ||
meta_wayland_touch_can_popup (seat->touch, serial) ||
meta_wayland_tablet_seat_can_popup (tablet_seat, serial));
meta_wayland_tablet_seat_can_popup (seat->tablet_seat, serial));
}
gboolean

View file

@ -42,6 +42,7 @@ struct _MetaWaylandSeat
MetaWaylandPointer *pointer;
MetaWaylandKeyboard *keyboard;
MetaWaylandTouch *touch;
MetaWaylandTabletSeat *tablet_seat;
MetaWaylandDataDevice data_device;
MetaWaylandDataDevicePrimary primary_data_device;

View file

@ -38,21 +38,6 @@ unbind_resource (struct wl_resource *resource)
wl_list_remove (wl_resource_get_link (resource));
}
static gboolean
is_tablet_device (ClutterInputDevice *device)
{
ClutterInputCapabilities capabilities;
if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_LOGICAL)
return FALSE;
capabilities = clutter_input_device_get_capabilities (device);
return (capabilities &
(CLUTTER_INPUT_CAPABILITY_TABLET_TOOL |
CLUTTER_INPUT_CAPABILITY_TABLET_PAD)) != 0;
}
static void
tablet_manager_get_tablet_seat (struct wl_client *client,
struct wl_resource *resource,
@ -131,97 +116,6 @@ meta_wayland_tablet_manager_finalize (MetaWaylandCompositor *compositor)
g_clear_pointer (&compositor->tablet_manager, g_free);
}
static MetaWaylandTabletSeat *
meta_wayland_tablet_manager_lookup_seat (MetaWaylandTabletManager *manager,
ClutterInputDevice *device)
{
MetaWaylandTabletSeat *tablet_seat;
MetaWaylandSeat *seat;
GHashTableIter iter;
if (!device || !is_tablet_device (device))
return NULL;
g_hash_table_iter_init (&iter, manager->seats);
while (g_hash_table_iter_next (&iter, (gpointer*) &seat, (gpointer*) &tablet_seat))
{
if (meta_wayland_tablet_seat_lookup_tablet (tablet_seat, device) ||
meta_wayland_tablet_seat_lookup_pad (tablet_seat, device))
return tablet_seat;
}
return NULL;
}
gboolean
meta_wayland_tablet_manager_consumes_event (MetaWaylandTabletManager *manager,
const ClutterEvent *event)
{
ClutterInputDevice *device = clutter_event_get_source_device (event);
return meta_wayland_tablet_manager_lookup_seat (manager, device) != NULL;
}
void
meta_wayland_tablet_manager_update (MetaWaylandTabletManager *manager,
const ClutterEvent *event)
{
ClutterInputDevice *device = clutter_event_get_source_device (event);
MetaWaylandTabletSeat *tablet_seat;
tablet_seat = meta_wayland_tablet_manager_lookup_seat (manager, device);
if (!tablet_seat)
return;
switch (clutter_event_type (event))
{
case CLUTTER_PROXIMITY_IN:
case CLUTTER_PROXIMITY_OUT:
case CLUTTER_BUTTON_PRESS:
case CLUTTER_BUTTON_RELEASE:
case CLUTTER_MOTION:
case CLUTTER_PAD_BUTTON_PRESS:
case CLUTTER_PAD_BUTTON_RELEASE:
case CLUTTER_PAD_RING:
case CLUTTER_PAD_STRIP:
meta_wayland_tablet_seat_update (tablet_seat, event);
break;
default:
break;
}
}
gboolean
meta_wayland_tablet_manager_handle_event (MetaWaylandTabletManager *manager,
const ClutterEvent *event)
{
ClutterInputDevice *device = clutter_event_get_source_device (event);
MetaWaylandTabletSeat *tablet_seat;
tablet_seat = meta_wayland_tablet_manager_lookup_seat (manager, device);
if (!tablet_seat)
return CLUTTER_EVENT_PROPAGATE;
switch (clutter_event_type (event))
{
case CLUTTER_PROXIMITY_IN:
case CLUTTER_PROXIMITY_OUT:
case CLUTTER_BUTTON_PRESS:
case CLUTTER_BUTTON_RELEASE:
case CLUTTER_MOTION:
case CLUTTER_PAD_BUTTON_PRESS:
case CLUTTER_PAD_BUTTON_RELEASE:
case CLUTTER_PAD_RING:
case CLUTTER_PAD_STRIP:
return meta_wayland_tablet_seat_handle_event (tablet_seat, event);
default:
return CLUTTER_EVENT_PROPAGATE;
}
}
MetaWaylandTabletSeat *
meta_wayland_tablet_manager_ensure_seat (MetaWaylandTabletManager *manager,
MetaWaylandSeat *seat)

View file

@ -38,13 +38,6 @@ struct _MetaWaylandTabletManager
void meta_wayland_tablet_manager_init (MetaWaylandCompositor *compositor);
void meta_wayland_tablet_manager_finalize (MetaWaylandCompositor *compositor);
gboolean meta_wayland_tablet_manager_consumes_event (MetaWaylandTabletManager *manager,
const ClutterEvent *event);
void meta_wayland_tablet_manager_update (MetaWaylandTabletManager *manager,
const ClutterEvent *event);
gboolean meta_wayland_tablet_manager_handle_event (MetaWaylandTabletManager *manager,
const ClutterEvent *event);
MetaWaylandTabletSeat *
meta_wayland_tablet_manager_ensure_seat (MetaWaylandTabletManager *manager,
MetaWaylandSeat *seat);

View file

@ -396,9 +396,6 @@ void
meta_wayland_compositor_update (MetaWaylandCompositor *compositor,
const ClutterEvent *event)
{
if (meta_wayland_tablet_manager_consumes_event (compositor->tablet_manager, event))
meta_wayland_tablet_manager_update (compositor->tablet_manager, event);
else
meta_wayland_seat_update (compositor->seat, event);
}
@ -472,10 +469,6 @@ gboolean
meta_wayland_compositor_handle_event (MetaWaylandCompositor *compositor,
const ClutterEvent *event)
{
if (meta_wayland_tablet_manager_handle_event (compositor->tablet_manager,
event))
return TRUE;
return meta_wayland_seat_handle_event (compositor->seat, event);
}
@ -618,7 +611,6 @@ meta_wayland_compositor_finalize (GObject *object)
meta_wayland_activation_finalize (compositor);
meta_wayland_outputs_finalize (compositor);
meta_wayland_presentation_time_finalize (compositor);
meta_wayland_tablet_manager_finalize (compositor);
g_hash_table_destroy (compositor->scheduled_surface_associations);
@ -630,6 +622,7 @@ meta_wayland_compositor_finalize (GObject *object)
g_clear_object (&compositor->dma_buf_manager);
g_clear_pointer (&compositor->seat, meta_wayland_seat_free);
meta_wayland_tablet_manager_finalize (compositor);
g_clear_pointer (&priv->filter_manager, meta_wayland_filter_manager_free);
g_clear_pointer (&priv->frame_callback_sources, g_hash_table_destroy);