From 4b0d3f44e1a4ec17d709f1604a1cdd98a8844236 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 31 Jul 2020 19:11:32 +0200 Subject: [PATCH] backends/native: Use viewport info to find out stage extents This information is equivalent to the stage extents, this just leaves meta_seat_native_get_stage() used for setting event->any.stage, which is a tiny lame excuse. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403 --- .../native/meta-input-device-native.c | 7 ++-- .../native/meta-input-device-native.h | 2 +- src/backends/native/meta-seat-native.c | 39 +++++++++---------- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/backends/native/meta-input-device-native.c b/src/backends/native/meta-input-device-native.c index ceef4a383..c8878337c 100644 --- a/src/backends/native/meta-input-device-native.c +++ b/src/backends/native/meta-input-device-native.c @@ -1437,17 +1437,16 @@ meta_input_device_native_get_libinput_device (ClutterInputDevice *device) void meta_input_device_native_translate_coordinates (ClutterInputDevice *device, - ClutterStage *stage, + MetaViewportInfo *viewports, float *x, float *y) { MetaInputDeviceNative *device_evdev = META_INPUT_DEVICE_NATIVE (device); double min_x = 0, min_y = 0, max_x = 1, max_y = 1; - double stage_width, stage_height; + float stage_width, stage_height; double x_d, y_d; - stage_width = clutter_actor_get_width (CLUTTER_ACTOR (stage)); - stage_height = clutter_actor_get_height (CLUTTER_ACTOR (stage)); + meta_viewport_info_get_extents (viewports, &stage_width, &stage_height); x_d = *x / stage_width; y_d = *y / stage_height; diff --git a/src/backends/native/meta-input-device-native.h b/src/backends/native/meta-input-device-native.h index fa5b3260e..25b50d105 100644 --- a/src/backends/native/meta-input-device-native.h +++ b/src/backends/native/meta-input-device-native.h @@ -126,7 +126,7 @@ ClutterInputDeviceType meta_input_device_native_determine_type (struct libin void meta_input_device_native_translate_coordinates (ClutterInputDevice *device, - ClutterStage *stage, + MetaViewportInfo *viewports, float *x, float *y); diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c index 26ce1ba70..317357df7 100644 --- a/src/backends/native/meta-seat-native.c +++ b/src/backends/native/meta-seat-native.c @@ -388,7 +388,6 @@ new_absolute_motion_event (MetaSeatNative *seat, float y, double *axes) { - ClutterStage *stage = meta_seat_native_get_stage (seat); ClutterEvent *event; event = clutter_event_new (CLUTTER_MOTION); @@ -408,9 +407,16 @@ new_absolute_motion_event (MetaSeatNative *seat, meta_xkb_translate_state (event, seat->xkb, seat->button_state); event->motion.x = x; event->motion.y = y; - meta_input_device_native_translate_coordinates (input_device, stage, - &event->motion.x, - &event->motion.y); + + /* This may happen early at startup */ + if (seat->viewports) + { + meta_input_device_native_translate_coordinates (input_device, + seat->viewports, + &event->motion.x, + &event->motion.y); + } + event->motion.axes = axes; clutter_event_set_device (event, seat->core_pointer); clutter_event_set_source_device (event, input_device); @@ -796,7 +802,6 @@ meta_seat_native_notify_touch_event (MetaSeatNative *seat, double x, double y) { - ClutterStage *stage = meta_seat_native_get_stage (seat); ClutterEvent *event = NULL; event = clutter_event_new (evtype); @@ -805,7 +810,8 @@ meta_seat_native_notify_touch_event (MetaSeatNative *seat, event->touch.time = us2ms (time_us); event->touch.x = x; event->touch.y = y; - meta_input_device_native_translate_coordinates (input_device, stage, + meta_input_device_native_translate_coordinates (input_device, + seat->viewports, &event->touch.x, &event->touch.y); @@ -1784,7 +1790,6 @@ 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; @@ -1801,8 +1806,7 @@ process_tablet_axis (MetaSeatNative *seat, if (!axes) return; - stage_width = clutter_actor_get_width (CLUTTER_ACTOR (stage)); - stage_height = clutter_actor_get_height (CLUTTER_ACTOR (stage)); + meta_viewport_info_get_extents (seat->viewports, &stage_width, &stage_height); time = libinput_event_tablet_tool_get_time_usec (tablet_event); @@ -1925,13 +1929,12 @@ process_device_event (MetaSeatNative *seat, uint64_t time_us; double x, y; float stage_width, stage_height; - 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_width = clutter_actor_get_width (CLUTTER_ACTOR (stage)); - stage_height = clutter_actor_get_height (CLUTTER_ACTOR (stage)); + meta_viewport_info_get_extents (seat->viewports, + &stage_width, &stage_height); time_us = libinput_event_pointer_get_time_usec (motion_event); x = libinput_event_pointer_get_absolute_x_transformed (motion_event, @@ -2026,7 +2029,6 @@ process_device_event (MetaSeatNative *seat, double x, y; float stage_width, stage_height; MetaSeatNative *seat; - ClutterStage *stage; MetaTouchState *touch_state; struct libinput_event_touch *touch_event = libinput_event_get_touch_event (event); @@ -2034,10 +2036,9 @@ 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 = meta_seat_native_get_stage (seat); - stage_width = clutter_actor_get_width (CLUTTER_ACTOR (stage)); - stage_height = clutter_actor_get_height (CLUTTER_ACTOR (stage)); + meta_viewport_info_get_extents (seat->viewports, + &stage_width, &stage_height); seat_slot = libinput_event_touch_get_seat_slot (touch_event); time_us = libinput_event_touch_get_time_usec (touch_event); @@ -2094,7 +2095,6 @@ process_device_event (MetaSeatNative *seat, double x, y; float stage_width, stage_height; MetaSeatNative *seat; - ClutterStage *stage; MetaTouchState *touch_state; struct libinput_event_touch *touch_event = libinput_event_get_touch_event (event); @@ -2102,10 +2102,9 @@ 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 = meta_seat_native_get_stage (seat); - stage_width = clutter_actor_get_width (CLUTTER_ACTOR (stage)); - stage_height = clutter_actor_get_height (CLUTTER_ACTOR (stage)); + meta_viewport_info_get_extents (seat->viewports, + &stage_width, &stage_height); seat_slot = libinput_event_touch_get_seat_slot (touch_event); time_us = libinput_event_touch_get_time_usec (touch_event);