From f76952e83fcb1afaab2751a38e6a6ac3cc631ce2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 20 Nov 2023 14:28:16 +1000 Subject: [PATCH] backends/native: If the tablet tool is relative, constrain it normally If we're moving our tool like a relative pointer, constrain to our viewports, if any. This fixes the cursor moving off the screen in relative mode. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3168 Part-of: --- src/backends/native/meta-seat-impl.c | 63 +++++++++++++++++++--------- 1 file changed, 44 insertions(+), 19 deletions(-) diff --git a/src/backends/native/meta-seat-impl.c b/src/backends/native/meta-seat-impl.c index 14257f4e0..835c5a47d 100644 --- a/src/backends/native/meta-seat-impl.c +++ b/src/backends/native/meta-seat-impl.c @@ -574,6 +574,26 @@ constrain_all_screen_monitors (ClutterInputDevice *device, } } +static void +constrain_to_viewports (MetaSeatImpl *seat_impl, + ClutterInputDevice *device, + uint64_t time_us, + float *x_inout, + float *y_inout) +{ + if (seat_impl->viewports) + { + /* if we're moving inside a monitor, we're fine */ + if (meta_viewport_info_get_view_at (seat_impl->viewports, + *x_inout, *y_inout) >= 0) + return; + + /* if we're trying to escape, clamp to the CRTC we're coming from */ + constrain_all_screen_monitors (device, seat_impl->viewports, + x_inout, y_inout); + } +} + static void constrain_coordinates (MetaSeatImpl *seat_impl, ClutterInputDevice *input_device, @@ -583,16 +603,31 @@ constrain_coordinates (MetaSeatImpl *seat_impl, float *x_out, float *y_out) { + MetaInputDeviceNative *device_evdev = META_INPUT_DEVICE_NATIVE (input_device); + if (clutter_input_device_get_device_type (input_device) == CLUTTER_TABLET_DEVICE) { - /* Viewport may be unset during startup */ - if (seat_impl->viewports) - { - meta_input_device_native_translate_coordinates_in_impl (input_device, - seat_impl->viewports, - &x, - &y); - } + if (device_evdev->mapping_mode == META_INPUT_DEVICE_MAPPING_RELATIVE) + { + constrain_to_barriers (seat_impl, input_device, + us2ms (time_us), + &x, &y); + constrain_to_viewports (seat_impl, + input_device, + time_us, + &x, &y); + } + else + { + /* Viewport may be unset during startup */ + if (seat_impl->viewports) + { + meta_input_device_native_translate_coordinates_in_impl (input_device, + seat_impl->viewports, + &x, + &y); + } + } } else { @@ -1186,17 +1221,7 @@ meta_seat_impl_constrain_pointer (MetaSeatImpl *seat_impl, new_x, new_y); } - if (seat_impl->viewports) - { - /* if we're moving inside a monitor, we're fine */ - if (meta_viewport_info_get_view_at (seat_impl->viewports, - *new_x, *new_y) >= 0) - return; - - /* if we're trying to escape, clamp to the CRTC we're coming from */ - constrain_all_screen_monitors (core_pointer, seat_impl->viewports, - new_x, new_y); - } + constrain_to_viewports (seat_impl, core_pointer, time_us, new_x, new_y); } static void