backends: Drop extra layer of touch info handling

We have a hashtable in the device that does not add much on top
to the seat handling. Make all the places rely on the seat accounting
instead.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403
This commit is contained in:
Carlos Garnacho 2020-05-06 14:12:55 +02:00
parent 908a331fa8
commit edc399e5cf
5 changed files with 31 additions and 84 deletions

View File

@ -67,10 +67,6 @@ meta_input_device_native_finalize (GObject *object)
if (device_evdev->libinput_device) if (device_evdev->libinput_device)
libinput_device_unref (device_evdev->libinput_device); libinput_device_unref (device_evdev->libinput_device);
meta_input_device_native_release_touch_slots (device_evdev,
g_get_monotonic_time ());
g_clear_pointer (&device_evdev->touches, g_hash_table_unref);
backend = clutter_get_default_backend (); backend = clutter_get_default_backend ();
seat = clutter_backend_get_default_seat (backend); seat = clutter_backend_get_default_seat (backend);
meta_seat_native_release_device_id (META_SEAT_NATIVE (seat), device); meta_seat_native_release_device_id (META_SEAT_NATIVE (seat), device);
@ -1228,44 +1224,6 @@ meta_input_device_native_a11y_maybe_notify_toggle_keys (MetaInputDeviceNative *d
meta_input_device_native_bell_notify (device); meta_input_device_native_bell_notify (device);
} }
static void
release_device_touch_slot (gpointer value)
{
MetaTouchState *touch_state = value;
meta_seat_native_release_touch_state (touch_state->seat, touch_state);
}
MetaTouchState *
meta_input_device_native_acquire_touch_state (MetaInputDeviceNative *device,
int device_slot)
{
MetaTouchState *touch_state;
touch_state = meta_seat_native_acquire_touch_state (device->seat,
device_slot);
g_hash_table_insert (device->touches,
GINT_TO_POINTER (device_slot),
touch_state);
return touch_state;
}
MetaTouchState *
meta_input_device_native_lookup_touch_state (MetaInputDeviceNative *device,
int device_slot)
{
return g_hash_table_lookup (device->touches, GINT_TO_POINTER (device_slot));
}
void
meta_input_device_native_release_touch_state (MetaInputDeviceNative *device,
MetaTouchState *touch_state)
{
g_hash_table_remove (device->touches,
GINT_TO_POINTER (touch_state->device_slot));
}
static void static void
meta_input_device_native_class_init (MetaInputDeviceNativeClass *klass) meta_input_device_native_class_init (MetaInputDeviceNativeClass *klass)
{ {
@ -1305,9 +1263,6 @@ meta_input_device_native_init (MetaInputDeviceNative *self)
cairo_matrix_init_identity (&self->device_matrix); cairo_matrix_init_identity (&self->device_matrix);
self->device_aspect_ratio = 0; self->device_aspect_ratio = 0;
self->output_ratio = 0; self->output_ratio = 0;
self->touches = g_hash_table_new_full (NULL, NULL,
NULL, release_device_touch_slot);
} }
/* /*

View File

@ -69,8 +69,6 @@ struct _MetaInputDeviceNative
double device_aspect_ratio; /* w:h */ double device_aspect_ratio; /* w:h */
double output_ratio; /* w:h */ double output_ratio; /* w:h */
GHashTable *touches;
/* Keyboard a11y */ /* Keyboard a11y */
ClutterKeyboardA11yFlags a11y_flags; ClutterKeyboardA11yFlags a11y_flags;
GList *slow_keys_list; GList *slow_keys_list;
@ -125,15 +123,6 @@ void meta_input_device_native_translate_coordinates (Clutte
void meta_input_device_native_apply_kbd_a11y_settings (MetaInputDeviceNative *device, void meta_input_device_native_apply_kbd_a11y_settings (MetaInputDeviceNative *device,
ClutterKbdA11ySettings *settings); ClutterKbdA11ySettings *settings);
MetaTouchState * meta_input_device_native_acquire_touch_state (MetaInputDeviceNative *device,
int device_slot);
MetaTouchState * meta_input_device_native_lookup_touch_state (MetaInputDeviceNative *device,
int device_slot);
void meta_input_device_native_release_touch_state (MetaInputDeviceNative *device,
MetaTouchState *touch_state);
void meta_input_device_native_a11y_maybe_notify_toggle_keys (MetaInputDeviceNative *device_evdev); void meta_input_device_native_a11y_maybe_notify_toggle_keys (MetaInputDeviceNative *device_evdev);
struct libinput_device * meta_input_device_native_get_libinput_device (ClutterInputDevice *device); struct libinput_device * meta_input_device_native_get_libinput_device (ClutterInputDevice *device);

View File

@ -170,6 +170,22 @@ ensure_seat_slot_allocated (MetaSeatNative *seat,
} }
} }
MetaTouchState *
meta_seat_native_lookup_touch_state (MetaSeatNative *seat,
int device_slot)
{
int seat_slot;
for (seat_slot = 0; seat_slot < seat->n_alloc_touch_states; seat_slot++)
{
if (seat->touch_states[seat_slot] &&
seat->touch_states[seat_slot]->device_slot == device_slot)
return seat->touch_states[seat_slot];
}
return NULL;
}
MetaTouchState * MetaTouchState *
meta_seat_native_acquire_touch_state (MetaSeatNative *seat, meta_seat_native_acquire_touch_state (MetaSeatNative *seat,
int device_slot) int device_slot)
@ -1974,9 +1990,7 @@ process_device_event (MetaSeatNative *seat,
y = libinput_event_touch_get_y_transformed (touch_event, y = libinput_event_touch_get_y_transformed (touch_event,
stage_height); stage_height);
touch_state = touch_state = meta_seat_native_acquire_touch_state (seat, device_slot);
meta_input_device_native_acquire_touch_state (device_evdev,
device_slot);
touch_state->coords.x = x; touch_state->coords.x = x;
touch_state->coords.y = y; touch_state->coords.y = y;
@ -2004,9 +2018,7 @@ process_device_event (MetaSeatNative *seat,
device_slot = libinput_event_touch_get_slot (touch_event); device_slot = libinput_event_touch_get_slot (touch_event);
time_us = libinput_event_touch_get_time_usec (touch_event); time_us = libinput_event_touch_get_time_usec (touch_event);
touch_state = touch_state = meta_seat_native_lookup_touch_state (seat, device_slot);
meta_input_device_native_lookup_touch_state (device_evdev,
device_slot);
if (!touch_state) if (!touch_state)
break; break;
@ -2015,8 +2027,7 @@ process_device_event (MetaSeatNative *seat,
touch_state->seat_slot, touch_state->seat_slot,
touch_state->coords.x, touch_state->coords.x,
touch_state->coords.y); touch_state->coords.y);
meta_input_device_native_release_touch_state (device_evdev, meta_seat_native_release_touch_state (seat, touch_state);
touch_state);
break; break;
} }
@ -2050,9 +2061,7 @@ process_device_event (MetaSeatNative *seat,
y = libinput_event_touch_get_y_transformed (touch_event, y = libinput_event_touch_get_y_transformed (touch_event,
stage_height); stage_height);
touch_state = touch_state = meta_seat_native_lookup_touch_state (seat, device_slot);
meta_input_device_native_lookup_touch_state (device_evdev,
device_slot);
if (!touch_state) if (!touch_state)
break; break;
@ -2082,9 +2091,7 @@ process_device_event (MetaSeatNative *seat,
time_us = libinput_event_touch_get_time_usec (touch_event); time_us = libinput_event_touch_get_time_usec (touch_event);
device_slot = libinput_event_touch_get_slot (touch_event); device_slot = libinput_event_touch_get_slot (touch_event);
touch_state = touch_state = meta_seat_native_lookup_touch_state (seat, device_slot);
meta_input_device_native_lookup_touch_state (device_evdev,
device_slot);
if (!touch_state) if (!touch_state)
break; break;
@ -2096,7 +2103,7 @@ process_device_event (MetaSeatNative *seat,
touch_state->coords.x, touch_state->coords.x,
touch_state->coords.y); touch_state->coords.y);
meta_input_device_native_release_touch_state (device_evdev, touch_state); meta_seat_native_release_touch_state (touch_state->seat, touch_state);
break; break;
} }
case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:

View File

@ -206,6 +206,8 @@ ClutterInputDevice * meta_seat_native_get_device (MetaSeatNative *seat,
MetaTouchState * meta_seat_native_acquire_touch_state (MetaSeatNative *seat, MetaTouchState * meta_seat_native_acquire_touch_state (MetaSeatNative *seat,
int device_slot); int device_slot);
MetaTouchState * meta_seat_native_lookup_touch_state (MetaSeatNative *seat,
int device_slot);
void meta_seat_native_release_touch_state (MetaSeatNative *seat, void meta_seat_native_release_touch_state (MetaSeatNative *seat,
MetaTouchState *touch_state); MetaTouchState *touch_state);

View File

@ -544,8 +544,6 @@ meta_virtual_input_device_native_notify_touch_down (ClutterVirtualInputDevice *v
{ {
MetaVirtualInputDeviceNative *virtual_evdev = MetaVirtualInputDeviceNative *virtual_evdev =
META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device); META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
MetaInputDeviceNative *device_evdev =
META_INPUT_DEVICE_NATIVE (virtual_evdev->device);
MetaTouchState *touch_state; MetaTouchState *touch_state;
g_return_if_fail (virtual_evdev->device != NULL); g_return_if_fail (virtual_evdev->device != NULL);
@ -553,8 +551,8 @@ meta_virtual_input_device_native_notify_touch_down (ClutterVirtualInputDevice *v
if (time_us == CLUTTER_CURRENT_TIME) if (time_us == CLUTTER_CURRENT_TIME)
time_us = g_get_monotonic_time (); time_us = g_get_monotonic_time ();
touch_state = meta_input_device_native_acquire_touch_state (device_evdev, touch_state = meta_seat_native_acquire_touch_state (virtual_evdev->seat,
device_slot); device_slot);
if (!touch_state) if (!touch_state)
return; return;
@ -579,8 +577,6 @@ meta_virtual_input_device_native_notify_touch_motion (ClutterVirtualInputDevice
{ {
MetaVirtualInputDeviceNative *virtual_evdev = MetaVirtualInputDeviceNative *virtual_evdev =
META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device); META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
MetaInputDeviceNative *device_evdev =
META_INPUT_DEVICE_NATIVE (virtual_evdev->device);
MetaTouchState *touch_state; MetaTouchState *touch_state;
g_return_if_fail (virtual_evdev->device != NULL); g_return_if_fail (virtual_evdev->device != NULL);
@ -588,8 +584,8 @@ meta_virtual_input_device_native_notify_touch_motion (ClutterVirtualInputDevice
if (time_us == CLUTTER_CURRENT_TIME) if (time_us == CLUTTER_CURRENT_TIME)
time_us = g_get_monotonic_time (); time_us = g_get_monotonic_time ();
touch_state = meta_input_device_native_lookup_touch_state (device_evdev, touch_state = meta_seat_native_lookup_touch_state (virtual_evdev->seat,
device_slot); device_slot);
if (!touch_state) if (!touch_state)
return; return;
@ -612,8 +608,6 @@ meta_virtual_input_device_native_notify_touch_up (ClutterVirtualInputDevice *vir
{ {
MetaVirtualInputDeviceNative *virtual_evdev = MetaVirtualInputDeviceNative *virtual_evdev =
META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device); META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
MetaInputDeviceNative *device_evdev =
META_INPUT_DEVICE_NATIVE (virtual_evdev->device);
MetaTouchState *touch_state; MetaTouchState *touch_state;
g_return_if_fail (virtual_evdev->device != NULL); g_return_if_fail (virtual_evdev->device != NULL);
@ -621,8 +615,8 @@ meta_virtual_input_device_native_notify_touch_up (ClutterVirtualInputDevice *vir
if (time_us == CLUTTER_CURRENT_TIME) if (time_us == CLUTTER_CURRENT_TIME)
time_us = g_get_monotonic_time (); time_us = g_get_monotonic_time ();
touch_state = meta_input_device_native_lookup_touch_state (device_evdev, touch_state = meta_seat_native_lookup_touch_state (virtual_evdev->seat,
device_slot); device_slot);
if (!touch_state) if (!touch_state)
return; return;
@ -634,7 +628,7 @@ meta_virtual_input_device_native_notify_touch_up (ClutterVirtualInputDevice *vir
touch_state->coords.x, touch_state->coords.x,
touch_state->coords.y); touch_state->coords.y);
meta_input_device_native_release_touch_state (device_evdev, touch_state); meta_seat_native_release_touch_state (virtual_evdev->seat, touch_state);
} }
static void static void