From 60b3f628a6213942d90007d14829a005aaf520cf Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 5 Jun 2020 16:52:10 +0200 Subject: [PATCH] backends/native: Drop all uses of clutter_input_device_get_stage() Rely on the seat stage, or other ways to fetch it. Also rely that there is actually a single stage, so that we assign the right stage to all events going out of the seat, in a single place. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403 --- src/backends/native/meta-seat-native.c | 198 +++++-------------------- src/backends/native/meta-xkb-utils.c | 3 - src/backends/native/meta-xkb-utils.h | 1 - 3 files changed, 41 insertions(+), 161 deletions(-) diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c index 9391692ac..9f97b51c0 100644 --- a/src/backends/native/meta-seat-native.c +++ b/src/backends/native/meta-seat-native.c @@ -243,8 +243,18 @@ keyboard_repeat (gpointer data) } static void -queue_event (ClutterEvent *event) +queue_event (MetaSeatNative *seat, + ClutterEvent *event) { + ClutterStage *stage = meta_seat_native_get_stage (seat); + + if (!stage) + { + /* No stage yet, drop this event on the floor */ + return; + } + + event->any.stage = stage; _clutter_event_push (event, FALSE); } @@ -280,7 +290,6 @@ meta_seat_native_notify_key (MetaSeatNative *seat, uint32_t state, gboolean update_keys) { - ClutterStage *stage; ClutterEvent *event = NULL; enum xkb_state_component changed_state; @@ -298,18 +307,8 @@ meta_seat_native_notify_key (MetaSeatNative *seat, } } - /* We can drop the event on the floor if no stage has been - * associated with the device yet. */ - stage = _clutter_input_device_get_stage (device); - if (stage == NULL) - { - meta_seat_native_clear_repeat_timer (seat); - return; - } - event = meta_key_event_new_from_evdev (device, seat->core_keyboard, - stage, seat->xkb, seat->button_state, us2ms (time_us), key, state); @@ -329,7 +328,7 @@ meta_seat_native_notify_key (MetaSeatNative *seat, clutter_event_set_flags (event, CLUTTER_EVENT_FLAG_REPEATED); } - queue_event (event); + queue_event (seat, event); if (update_keys && (changed_state & XKB_STATE_LEDS)) { @@ -389,7 +388,7 @@ new_absolute_motion_event (MetaSeatNative *seat, float y, double *axes) { - ClutterStage *stage = _clutter_input_device_get_stage (input_device); + ClutterStage *stage = meta_seat_native_get_stage (seat); ClutterEvent *event; event = clutter_event_new (CLUTTER_MOTION); @@ -406,7 +405,6 @@ new_absolute_motion_event (MetaSeatNative *seat, meta_event_native_set_time_usec (event, time_us); event->motion.time = us2ms (time_us); - event->motion.stage = stage; meta_xkb_translate_state (event, seat->xkb, seat->button_state); event->motion.x = x; event->motion.y = y; @@ -430,8 +428,6 @@ new_absolute_motion_event (MetaSeatNative *seat, clutter_event_set_device (event, seat->core_pointer); } - _clutter_input_device_set_stage (seat->core_pointer, stage); - if (clutter_input_device_get_device_type (input_device) != CLUTTER_TABLET_DEVICE) { seat->pointer_x = x; @@ -453,11 +449,6 @@ meta_seat_native_notify_relative_motion (MetaSeatNative *seat, float new_x, new_y; ClutterEvent *event; - /* We can drop the event on the floor if no stage has been - * associated with the device yet. */ - if (!_clutter_input_device_get_stage (input_device)) - return; - meta_seat_native_filter_relative_motion (seat, input_device, seat->pointer_x, @@ -474,7 +465,7 @@ meta_seat_native_notify_relative_motion (MetaSeatNative *seat, dx, dy, dx_unaccel, dy_unaccel); - queue_event (event); + queue_event (seat, event); } void @@ -489,7 +480,7 @@ meta_seat_native_notify_absolute_motion (MetaSeatNative *seat, event = new_absolute_motion_event (seat, input_device, time_us, x, y, axes); - queue_event (event); + queue_event (seat, event); } void @@ -500,7 +491,6 @@ meta_seat_native_notify_button (MetaSeatNative *seat, uint32_t state) { MetaInputDeviceNative *device_evdev = (MetaInputDeviceNative *) input_device; - ClutterStage *stage; ClutterEvent *event = NULL; int button_nr; static int maskmap[8] = @@ -521,12 +511,6 @@ meta_seat_native_notify_button (MetaSeatNative *seat, return; } - /* We can drop the event on the floor if no stage has been - * associated with the device yet. */ - stage = _clutter_input_device_get_stage (input_device); - if (stage == NULL) - return; - /* The evdev button numbers don't map sequentially to clutter button * numbers (the right and middle mouse buttons are in the opposite * order) so we'll map them directly with a switch statement */ @@ -582,7 +566,6 @@ meta_seat_native_notify_button (MetaSeatNative *seat, meta_event_native_set_time_usec (event, time_us); event->button.time = us2ms (time_us); - event->button.stage = CLUTTER_STAGE (stage); meta_xkb_translate_state (event, seat->xkb, seat->button_state); event->button.button = button_nr; @@ -626,9 +609,7 @@ meta_seat_native_notify_button (MetaSeatNative *seat, clutter_event_set_device (event, seat->core_pointer); } - _clutter_input_device_set_stage (seat->core_pointer, stage); - - queue_event (event); + queue_event (seat, event); } static void @@ -642,16 +623,9 @@ notify_scroll (ClutterInputDevice *input_device, { MetaInputDeviceNative *device_evdev; MetaSeatNative *seat; - ClutterStage *stage; ClutterEvent *event = NULL; double scroll_factor; - /* We can drop the event on the floor if no stage has been - * associated with the device yet. */ - stage = _clutter_input_device_get_stage (input_device); - if (stage == NULL) - return; - device_evdev = META_INPUT_DEVICE_NATIVE (input_device); seat = meta_input_device_native_get_seat (device_evdev); @@ -659,7 +633,6 @@ notify_scroll (ClutterInputDevice *input_device, meta_event_native_set_time_usec (event, time_us); event->scroll.time = us2ms (time_us); - event->scroll.stage = CLUTTER_STAGE (stage); meta_xkb_translate_state (event, seat->xkb, seat->button_state); /* libinput pointer axis events are in pointer motion coordinate space. @@ -680,7 +653,7 @@ notify_scroll (ClutterInputDevice *input_device, _clutter_event_set_pointer_emulated (event, emulated); - queue_event (event); + queue_event (seat, event); } static void @@ -692,18 +665,11 @@ notify_discrete_scroll (ClutterInputDevice *input_device, { MetaInputDeviceNative *device_evdev; MetaSeatNative *seat; - ClutterStage *stage; ClutterEvent *event = NULL; if (direction == CLUTTER_SCROLL_SMOOTH) return; - /* We can drop the event on the floor if no stage has been - * associated with the device yet. */ - stage = _clutter_input_device_get_stage (input_device); - if (stage == NULL) - return; - device_evdev = META_INPUT_DEVICE_NATIVE (input_device); seat = meta_input_device_native_get_seat (device_evdev); @@ -711,7 +677,6 @@ notify_discrete_scroll (ClutterInputDevice *input_device, meta_event_native_set_time_usec (event, time_us); event->scroll.time = us2ms (time_us); - event->scroll.stage = CLUTTER_STAGE (stage); meta_xkb_translate_state (event, seat->xkb, seat->button_state); event->scroll.direction = direction; @@ -724,7 +689,7 @@ notify_discrete_scroll (ClutterInputDevice *input_device, _clutter_event_set_pointer_emulated (event, emulated); - queue_event (event); + queue_event (seat, event); } static void @@ -827,20 +792,13 @@ meta_seat_native_notify_touch_event (MetaSeatNative *seat, double x, double y) { - ClutterStage *stage; + ClutterStage *stage = meta_seat_native_get_stage (seat); ClutterEvent *event = NULL; - /* We can drop the event on the floor if no stage has been - * associated with the device yet. */ - stage = _clutter_input_device_get_stage (input_device); - if (stage == NULL) - return; - event = clutter_event_new (evtype); meta_event_native_set_time_usec (event, time_us); event->touch.time = us2ms (time_us); - event->touch.stage = CLUTTER_STAGE (stage); event->touch.x = x; event->touch.y = y; meta_input_device_native_translate_coordinates (input_device, stage, @@ -858,7 +816,7 @@ meta_seat_native_notify_touch_event (MetaSeatNative *seat, clutter_event_set_device (event, seat->core_pointer); clutter_event_set_source_device (event, input_device); - queue_event (event); + queue_event (seat, event); } @@ -1121,7 +1079,7 @@ notify_absolute_motion (ClutterInputDevice *input_device, seat = meta_input_device_native_get_seat (META_INPUT_DEVICE_NATIVE (input_device)); event = new_absolute_motion_event (seat, input_device, time_us, x, y, axes); - queue_event (event); + queue_event (seat, event); } static void @@ -1151,7 +1109,7 @@ notify_relative_tool_motion (ClutterInputDevice *input_device, event = new_absolute_motion_event (seat, input_device, time_us, x, y, axes); meta_event_native_set_relative_motion (event, dx, dy, 0, 0); - queue_event (event); + queue_event (seat, event); } static void @@ -1166,16 +1124,9 @@ notify_pinch_gesture_event (ClutterInputDevice *input_device, { MetaInputDeviceNative *device_evdev; MetaSeatNative *seat; - ClutterStage *stage; ClutterEvent *event = NULL; graphene_point_t pos; - /* We can drop the event on the floor if no stage has been - * associated with the device yet. */ - stage = _clutter_input_device_get_stage (input_device); - if (stage == NULL) - return; - device_evdev = META_INPUT_DEVICE_NATIVE (input_device); seat = meta_input_device_native_get_seat (device_evdev); @@ -1186,7 +1137,6 @@ notify_pinch_gesture_event (ClutterInputDevice *input_device, meta_event_native_set_time_usec (event, time_us); event->touchpad_pinch.phase = phase; event->touchpad_pinch.time = us2ms (time_us); - event->touchpad_pinch.stage = CLUTTER_STAGE (stage); event->touchpad_pinch.x = pos.x; event->touchpad_pinch.y = pos.y; event->touchpad_pinch.dx = dx; @@ -1200,7 +1150,7 @@ notify_pinch_gesture_event (ClutterInputDevice *input_device, clutter_event_set_device (event, seat->core_pointer); clutter_event_set_source_device (event, input_device); - queue_event (event); + queue_event (seat, event); } static void @@ -1213,16 +1163,9 @@ notify_swipe_gesture_event (ClutterInputDevice *input_device, { MetaInputDeviceNative *device_evdev; MetaSeatNative *seat; - ClutterStage *stage; ClutterEvent *event = NULL; graphene_point_t pos; - /* We can drop the event on the floor if no stage has been - * associated with the device yet. */ - stage = _clutter_input_device_get_stage (input_device); - if (stage == NULL) - return; - device_evdev = META_INPUT_DEVICE_NATIVE (input_device); seat = meta_input_device_native_get_seat (device_evdev); @@ -1231,7 +1174,6 @@ notify_swipe_gesture_event (ClutterInputDevice *input_device, meta_event_native_set_time_usec (event, time_us); event->touchpad_swipe.phase = phase; event->touchpad_swipe.time = us2ms (time_us); - event->touchpad_swipe.stage = CLUTTER_STAGE (stage); clutter_input_device_get_coords (seat->core_pointer, NULL, &pos); event->touchpad_swipe.x = pos.x; @@ -1245,7 +1187,7 @@ notify_swipe_gesture_event (ClutterInputDevice *input_device, clutter_event_set_device (event, seat->core_pointer); clutter_event_set_source_device (event, input_device); - queue_event (event); + queue_event (seat, event); } static void @@ -1255,15 +1197,8 @@ notify_proximity (ClutterInputDevice *input_device, { MetaInputDeviceNative *device_evdev; MetaSeatNative *seat; - ClutterStage *stage; ClutterEvent *event = NULL; - /* We can drop the event on the floor if no stage has been - * associated with the device yet. */ - stage = _clutter_input_device_get_stage (input_device); - if (stage == NULL) - return; - device_evdev = META_INPUT_DEVICE_NATIVE (input_device); seat = meta_input_device_native_get_seat (device_evdev); @@ -1275,14 +1210,11 @@ notify_proximity (ClutterInputDevice *input_device, meta_event_native_set_time_usec (event, time_us); event->proximity.time = us2ms (time_us); - event->proximity.stage = CLUTTER_STAGE (stage); clutter_event_set_device_tool (event, device_evdev->last_tool); clutter_event_set_device (event, seat->core_pointer); clutter_event_set_source_device (event, input_device); - _clutter_input_device_set_stage (seat->core_pointer, stage); - - queue_event (event); + queue_event (seat, event); } static void @@ -1295,25 +1227,17 @@ notify_pad_button (ClutterInputDevice *input_device, { MetaInputDeviceNative *device_evdev; MetaSeatNative *seat; - ClutterStage *stage; ClutterEvent *event; - /* We can drop the event on the floor if no stage has been - * associated with the device yet. */ - stage = _clutter_input_device_get_stage (input_device); - if (stage == NULL) - return; + device_evdev = META_INPUT_DEVICE_NATIVE (input_device); + seat = meta_input_device_native_get_seat (device_evdev); if (pressed) event = clutter_event_new (CLUTTER_PAD_BUTTON_PRESS); else event = clutter_event_new (CLUTTER_PAD_BUTTON_RELEASE); - device_evdev = META_INPUT_DEVICE_NATIVE (input_device); - seat = meta_input_device_native_get_seat (device_evdev); - meta_event_native_set_time_usec (event, time_us); - event->pad_button.stage = stage; event->pad_button.button = button; event->pad_button.group = mode_group; event->pad_button.mode = mode; @@ -1321,9 +1245,7 @@ notify_pad_button (ClutterInputDevice *input_device, clutter_event_set_source_device (event, input_device); clutter_event_set_time (event, us2ms (time_us)); - _clutter_input_device_set_stage (seat->core_pointer, stage); - - queue_event (event); + queue_event (seat, event); } static void @@ -1335,30 +1257,22 @@ notify_pad_strip (ClutterInputDevice *input_device, uint32_t mode, double value) { - MetaInputDeviceNative *device_evdev; ClutterInputDevicePadSource source; + MetaInputDeviceNative *device_evdev; MetaSeatNative *seat; - ClutterStage *stage; ClutterEvent *event; - /* We can drop the event on the floor if no stage has been - * associated with the device yet. */ - stage = _clutter_input_device_get_stage (input_device); - if (stage == NULL) - return; + device_evdev = META_INPUT_DEVICE_NATIVE (input_device); + seat = meta_input_device_native_get_seat (device_evdev); if (strip_source == LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER) source = CLUTTER_INPUT_DEVICE_PAD_SOURCE_FINGER; else source = CLUTTER_INPUT_DEVICE_PAD_SOURCE_UNKNOWN; - device_evdev = META_INPUT_DEVICE_NATIVE (input_device); - seat = meta_input_device_native_get_seat (device_evdev); - event = clutter_event_new (CLUTTER_PAD_STRIP); meta_event_native_set_time_usec (event, time_us); event->pad_strip.strip_source = source; - event->pad_strip.stage = stage; event->pad_strip.strip_number = strip_number; event->pad_strip.value = value; event->pad_strip.group = mode_group; @@ -1367,9 +1281,7 @@ notify_pad_strip (ClutterInputDevice *input_device, clutter_event_set_source_device (event, input_device); clutter_event_set_time (event, us2ms (time_us)); - _clutter_input_device_set_stage (seat->core_pointer, stage); - - queue_event (event); + queue_event (seat, event); } static void @@ -1381,30 +1293,22 @@ notify_pad_ring (ClutterInputDevice *input_device, uint32_t mode, double angle) { - MetaInputDeviceNative *device_evdev; ClutterInputDevicePadSource source; + MetaInputDeviceNative *device_evdev; MetaSeatNative *seat; - ClutterStage *stage; ClutterEvent *event; - /* We can drop the event on the floor if no stage has been - * associated with the device yet. */ - stage = _clutter_input_device_get_stage (input_device); - if (stage == NULL) - return; + device_evdev = META_INPUT_DEVICE_NATIVE (input_device); + seat = meta_input_device_native_get_seat (device_evdev); if (ring_source == LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER) source = CLUTTER_INPUT_DEVICE_PAD_SOURCE_FINGER; else source = CLUTTER_INPUT_DEVICE_PAD_SOURCE_UNKNOWN; - device_evdev = META_INPUT_DEVICE_NATIVE (input_device); - seat = meta_input_device_native_get_seat (device_evdev); - event = clutter_event_new (CLUTTER_PAD_RING); meta_event_native_set_time_usec (event, time_us); event->pad_ring.ring_source = source; - event->pad_ring.stage = stage; event->pad_ring.ring_number = ring_number; event->pad_ring.angle = angle; event->pad_ring.group = mode_group; @@ -1413,9 +1317,7 @@ notify_pad_ring (ClutterInputDevice *input_device, clutter_event_set_source_device (event, input_device); clutter_event_set_time (event, us2ms (time_us)); - _clutter_input_device_set_stage (seat->core_pointer, stage); - - queue_event (event); + queue_event (seat, event); } static gboolean @@ -1449,10 +1351,6 @@ meta_event_dispatch (GSource *g_source, MetaSeatNative *seat = meta_input_device_native_get_seat (device_evdev); - /* Drop events if we don't have any stage to forward them to */ - if (!_clutter_input_device_get_stage (input_device)) - return TRUE; - /* update the device states *before* the event */ event_state = seat->button_state | xkb_state_serialize_mods (seat->xkb, XKB_STATE_MODS_EFFECTIVE); @@ -1676,7 +1574,7 @@ process_base_event (MetaSeatNative *seat, if (device_event) { - queue_event (device_event); + queue_event (seat, device_event); return TRUE; } @@ -1897,10 +1795,10 @@ process_tablet_axis (MetaSeatNative *seat, struct libinput_event *event) { struct libinput_device *libinput_device = libinput_event_get_device (event); + ClutterStage *stage = meta_seat_native_get_stage (seat); uint64_t time; double x, y, dx, dy, *axes; float stage_width, stage_height; - ClutterStage *stage; ClutterInputDevice *device; struct libinput_event_tablet_tool *tablet_event = libinput_event_get_tablet_tool_event (event); @@ -1909,10 +1807,6 @@ process_tablet_axis (MetaSeatNative *seat, device = libinput_device_get_user_data (libinput_device); evdev_device = META_INPUT_DEVICE_NATIVE (device); - stage = _clutter_input_device_get_stage (device); - if (!stage) - return; - axes = translate_tablet_axes (tablet_event, evdev_device->last_tool); if (!axes) @@ -2017,15 +1911,11 @@ process_device_event (MetaSeatNative *seat, uint64_t time_us; double x, y; float stage_width, stage_height; - ClutterStage *stage; + ClutterStage *stage = meta_seat_native_get_stage (seat); struct libinput_event_pointer *motion_event = libinput_event_get_pointer_event (event); device = libinput_device_get_user_data (libinput_device); - stage = _clutter_input_device_get_stage (device); - if (stage == NULL) - break; - stage_width = clutter_actor_get_width (CLUTTER_ACTOR (stage)); stage_height = clutter_actor_get_height (CLUTTER_ACTOR (stage)); @@ -2130,10 +2020,7 @@ process_device_event (MetaSeatNative *seat, device = libinput_device_get_user_data (libinput_device); device_evdev = META_INPUT_DEVICE_NATIVE (device); seat = meta_input_device_native_get_seat (device_evdev); - - stage = _clutter_input_device_get_stage (device); - if (stage == NULL) - break; + stage = meta_seat_native_get_stage (seat); stage_width = clutter_actor_get_width (CLUTTER_ACTOR (stage)); stage_height = clutter_actor_get_height (CLUTTER_ACTOR (stage)); @@ -2201,10 +2088,7 @@ process_device_event (MetaSeatNative *seat, device = libinput_device_get_user_data (libinput_device); device_evdev = META_INPUT_DEVICE_NATIVE (device); seat = meta_input_device_native_get_seat (device_evdev); - - stage = _clutter_input_device_get_stage (device); - if (stage == NULL) - break; + stage = meta_seat_native_get_stage (seat); stage_width = clutter_actor_get_width (CLUTTER_ACTOR (stage)); stage_height = clutter_actor_get_height (CLUTTER_ACTOR (stage)); diff --git a/src/backends/native/meta-xkb-utils.c b/src/backends/native/meta-xkb-utils.c index 2fcdcf37f..6470e520e 100644 --- a/src/backends/native/meta-xkb-utils.c +++ b/src/backends/native/meta-xkb-utils.c @@ -28,7 +28,6 @@ /* * _clutter_event_new_from_evdev: Create a new Clutter ClutterKeyEvent * @device: a ClutterInputDevice - * @stage: the stage the event should be delivered to * @xkb: XKB rules to translate the event * @_time: timestamp of the event * @key: a key code coming from a Linux input device @@ -42,7 +41,6 @@ ClutterEvent * meta_key_event_new_from_evdev (ClutterInputDevice *device, ClutterInputDevice *core_device, - ClutterStage *stage, struct xkb_state *xkb_state, uint32_t button_state, uint32_t _time, @@ -72,7 +70,6 @@ meta_key_event_new_from_evdev (ClutterInputDevice *device, else sym = XKB_KEY_NoSymbol; - event->key.stage = stage; event->key.time = _time; meta_xkb_translate_state (event, xkb_state, button_state); event->key.hardware_keycode = key; diff --git a/src/backends/native/meta-xkb-utils.h b/src/backends/native/meta-xkb-utils.h index a4c2de7dc..5121d08d6 100644 --- a/src/backends/native/meta-xkb-utils.h +++ b/src/backends/native/meta-xkb-utils.h @@ -27,7 +27,6 @@ ClutterEvent * meta_key_event_new_from_evdev (ClutterInputDevice *device, ClutterInputDevice *core_keyboard, - ClutterStage *stage, struct xkb_state *xkb_state, uint32_t button_state, uint32_t _time,