[mutter/wip/carlosg/input-refactors-pt1: 23/44] backends/native: Use libinput seat slot API
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/carlosg/input-refactors-pt1: 23/44] backends/native: Use libinput seat slot API
- Date: Thu, 15 Oct 2020 23:25:52 +0000 (UTC)
commit f1e2068b70931c7ad00086504c61713493c1b324
Author: Carlos Garnacho <carlosg gnome org>
Date: Thu May 7 12:41:32 2020 +0200
backends/native: Use libinput seat slot API
Instead of creating a seat-wide touch slot ID ourselves, rely on libinput
API doing this for us.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1486
src/backends/native/meta-input-device-native.c | 3 +-
src/backends/native/meta-seat-native.c | 92 ++++++++++------------
src/backends/native/meta-seat-native.h | 9 ++-
.../native/meta-virtual-input-device-native.c | 3 +-
4 files changed, 49 insertions(+), 58 deletions(-)
---
diff --git a/src/backends/native/meta-input-device-native.c b/src/backends/native/meta-input-device-native.c
index 25360e6f51..fef496a761 100644
--- a/src/backends/native/meta-input-device-native.c
+++ b/src/backends/native/meta-input-device-native.c
@@ -1233,7 +1233,8 @@ release_device_touch_slot (gpointer value)
{
MetaTouchState *touch_state = value;
- meta_seat_native_release_touch_state (touch_state->seat, touch_state);
+ meta_seat_native_release_touch_state (touch_state->seat,
+ touch_state->seat_slot);
}
MetaTouchState *
diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c
index 9e2c2d768f..6594437964 100644
--- a/src/backends/native/meta-seat-native.c
+++ b/src/backends/native/meta-seat-native.c
@@ -146,63 +146,58 @@ meta_seat_native_sync_leds (MetaSeatNative *seat)
}
}
-static void
-clutter_touch_state_free (MetaTouchState *touch_state)
+MetaTouchState *
+meta_seat_native_lookup_touch_state (MetaSeatNative *seat,
+ int seat_slot)
{
- g_slice_free (MetaTouchState, touch_state);
+ if (!seat->touch_states)
+ return NULL;
+
+ return g_hash_table_lookup (seat->touch_states, GINT_TO_POINTER (seat_slot));
}
static void
-ensure_seat_slot_allocated (MetaSeatNative *seat,
- int seat_slot)
+meta_touch_state_free (MetaTouchState *state)
{
- if (seat_slot >= seat->n_alloc_touch_states)
- {
- const int size_increase = 5;
- int i;
-
- seat->n_alloc_touch_states += size_increase;
- seat->touch_states = g_realloc_n (seat->touch_states,
- seat->n_alloc_touch_states,
- sizeof (MetaTouchState *));
- for (i = 0; i < size_increase; i++)
- seat->touch_states[seat->n_alloc_touch_states - (i + 1)] = NULL;
- }
+ g_slice_free (MetaTouchState, state);
}
MetaTouchState *
meta_seat_native_acquire_touch_state (MetaSeatNative *seat,
- int device_slot)
+ int seat_slot)
{
MetaTouchState *touch_state;
- int seat_slot;
- for (seat_slot = 0; seat_slot < seat->n_alloc_touch_states; seat_slot++)
+ if (!seat->touch_states)
{
- if (!seat->touch_states[seat_slot])
- break;
+ seat->touch_states =
+ g_hash_table_new_full (NULL, NULL, NULL,
+ (GDestroyNotify) meta_touch_state_free);
}
- ensure_seat_slot_allocated (seat, seat_slot);
+ g_assert (!g_hash_table_contains (seat->touch_states,
+ GINT_TO_POINTER (seat_slot)));
touch_state = g_slice_new0 (MetaTouchState);
*touch_state = (MetaTouchState) {
.seat = seat,
.seat_slot = seat_slot,
- .device_slot = device_slot,
};
- seat->touch_states[seat_slot] = touch_state;
+ g_hash_table_insert (seat->touch_states, GINT_TO_POINTER (seat_slot),
+ touch_state);
return touch_state;
}
void
meta_seat_native_release_touch_state (MetaSeatNative *seat,
- MetaTouchState *touch_state)
+ int seat_slot)
{
- g_clear_pointer (&seat->touch_states[touch_state->seat_slot],
- clutter_touch_state_free);
+ if (!seat->touch_states)
+ return;
+
+ g_hash_table_remove (seat->touch_states, GINT_TO_POINTER (seat_slot));
}
void
@@ -1958,7 +1953,7 @@ process_device_event (MetaSeatNative *seat,
case LIBINPUT_EVENT_TOUCH_DOWN:
{
- int device_slot;
+ int seat_slot;
uint64_t time_us;
double x, y;
float stage_width, stage_height;
@@ -1979,16 +1974,14 @@ process_device_event (MetaSeatNative *seat,
stage_width = clutter_actor_get_width (CLUTTER_ACTOR (stage));
stage_height = clutter_actor_get_height (CLUTTER_ACTOR (stage));
- device_slot = libinput_event_touch_get_slot (touch_event);
+ seat_slot = libinput_event_touch_get_seat_slot (touch_event);
time_us = libinput_event_touch_get_time_usec (touch_event);
x = libinput_event_touch_get_x_transformed (touch_event,
stage_width);
y = libinput_event_touch_get_y_transformed (touch_event,
stage_height);
- touch_state =
- meta_input_device_native_acquire_touch_state (device_evdev,
- device_slot);
+ touch_state = meta_seat_native_acquire_touch_state (seat, seat_slot);
touch_state->coords.x = x;
touch_state->coords.y = y;
@@ -2003,7 +1996,7 @@ process_device_event (MetaSeatNative *seat,
case LIBINPUT_EVENT_TOUCH_UP:
{
- int device_slot;
+ int seat_slot;
uint64_t time_us;
MetaSeatNative *seat;
MetaTouchState *touch_state;
@@ -2014,11 +2007,9 @@ process_device_event (MetaSeatNative *seat,
device_evdev = META_INPUT_DEVICE_NATIVE (device);
seat = meta_input_device_native_get_seat (device_evdev);
- device_slot = libinput_event_touch_get_slot (touch_event);
+ seat_slot = libinput_event_touch_get_seat_slot (touch_event);
time_us = libinput_event_touch_get_time_usec (touch_event);
- touch_state =
- meta_input_device_native_lookup_touch_state (device_evdev,
- device_slot);
+ touch_state = meta_seat_native_lookup_touch_state (seat, seat_slot);
if (!touch_state)
break;
@@ -2027,14 +2018,13 @@ process_device_event (MetaSeatNative *seat,
touch_state->seat_slot,
touch_state->coords.x,
touch_state->coords.y);
- meta_input_device_native_release_touch_state (device_evdev,
- touch_state);
+ meta_seat_native_release_touch_state (seat, seat_slot);
break;
}
case LIBINPUT_EVENT_TOUCH_MOTION:
{
- int device_slot;
+ int seat_slot;
uint64_t time_us;
double x, y;
float stage_width, stage_height;
@@ -2055,16 +2045,14 @@ process_device_event (MetaSeatNative *seat,
stage_width = clutter_actor_get_width (CLUTTER_ACTOR (stage));
stage_height = clutter_actor_get_height (CLUTTER_ACTOR (stage));
- device_slot = libinput_event_touch_get_slot (touch_event);
+ seat_slot = libinput_event_touch_get_seat_slot (touch_event);
time_us = libinput_event_touch_get_time_usec (touch_event);
x = libinput_event_touch_get_x_transformed (touch_event,
stage_width);
y = libinput_event_touch_get_y_transformed (touch_event,
stage_height);
- touch_state =
- meta_input_device_native_lookup_touch_state (device_evdev,
- device_slot);
+ touch_state = meta_seat_native_lookup_touch_state (seat, seat_slot);
if (!touch_state)
break;
@@ -2081,7 +2069,7 @@ process_device_event (MetaSeatNative *seat,
}
case LIBINPUT_EVENT_TOUCH_CANCEL:
{
- int device_slot;
+ int seat_slot;
MetaTouchState *touch_state;
uint64_t time_us;
MetaSeatNative *seat;
@@ -2093,10 +2081,8 @@ process_device_event (MetaSeatNative *seat,
seat = meta_input_device_native_get_seat (device_evdev);
time_us = libinput_event_touch_get_time_usec (touch_event);
- device_slot = libinput_event_touch_get_slot (touch_event);
- touch_state =
- meta_input_device_native_lookup_touch_state (device_evdev,
- device_slot);
+ seat_slot = libinput_event_touch_get_seat_slot (touch_event);
+ touch_state = meta_seat_native_lookup_touch_state (seat, seat_slot);
if (!touch_state)
break;
@@ -2108,7 +2094,7 @@ process_device_event (MetaSeatNative *seat,
touch_state->coords.x,
touch_state->coords.y);
- meta_input_device_native_release_touch_state (device_evdev, touch_state);
+ meta_seat_native_release_touch_state (seat, seat_slot);
break;
}
case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:
@@ -2579,7 +2565,9 @@ meta_seat_native_finalize (GObject *object)
g_object_unref (device);
}
g_slist_free (seat->devices);
- g_free (seat->touch_states);
+
+ if (seat->touch_states)
+ g_hash_table_destroy (seat->touch_states);
g_object_unref (seat->udev_client);
diff --git a/src/backends/native/meta-seat-native.h b/src/backends/native/meta-seat-native.h
index 7945603758..1c4ee182c3 100644
--- a/src/backends/native/meta-seat-native.h
+++ b/src/backends/native/meta-seat-native.h
@@ -88,8 +88,7 @@ struct _MetaSeatNative
ClutterInputDevice *core_pointer;
ClutterInputDevice *core_keyboard;
- MetaTouchState **touch_states;
- int n_alloc_touch_states;
+ GHashTable *touch_states;
struct xkb_state *xkb;
xkb_led_index_t caps_lock_led;
@@ -202,10 +201,12 @@ void meta_seat_native_set_libinput_seat (MetaSeatNative *seat,
void meta_seat_native_sync_leds (MetaSeatNative *seat);
MetaTouchState * meta_seat_native_acquire_touch_state (MetaSeatNative *seat,
- int device_slot);
+ int seat_slot);
+MetaTouchState * meta_seat_native_lookup_touch_state (MetaSeatNative *seat,
+ int seat_slot);
void meta_seat_native_release_touch_state (MetaSeatNative *seat,
- MetaTouchState *touch_state);
+ int seat_slot);
void meta_seat_native_set_stage (MetaSeatNative *seat,
ClutterStage *stage);
diff --git a/src/backends/native/meta-virtual-input-device-native.c
b/src/backends/native/meta-virtual-input-device-native.c
index 510414bde8..f1fc538989 100644
--- a/src/backends/native/meta-virtual-input-device-native.c
+++ b/src/backends/native/meta-virtual-input-device-native.c
@@ -634,7 +634,8 @@ meta_virtual_input_device_native_notify_touch_up (ClutterVirtualInputDevice *vir
touch_state->coords.x,
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->seat_slot);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]