diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2020-06-05 12:54:51 +0200 |
---|---|---|
committer | Jonas Ã…dahl <jadahl@gmail.com> | 2020-10-23 18:48:18 +0000 |
commit | 3c8376ad91d329ba08b4863444b79fd8a205dcf0 (patch) | |
tree | 01ddbdc17578953d9f4e2862be8d8f773a8cdc35 | |
parent | 90df3c6fa32f96af16c4b6a3d2bf5b956df91de2 (diff) | |
download | mutter-3c8376ad91d329ba08b4863444b79fd8a205dcf0.tar.gz |
backends/native: Move relative motion filter to MetaSeatNative altogether
And drop the relative motion filter API. The seat will handle relative motion
across outputs with different scales. This accesses the MetaMonitorManager
ATM.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1486
-rw-r--r-- | src/backends/native/meta-backend-native.c | 117 | ||||
-rw-r--r-- | src/backends/native/meta-seat-native.c | 118 | ||||
-rw-r--r-- | src/backends/native/meta-seat-native.h | 13 |
3 files changed, 104 insertions, 144 deletions
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c index 306cc0495..8002e4051 100644 --- a/src/backends/native/meta-backend-native.c +++ b/src/backends/native/meta-backend-native.c @@ -137,120 +137,6 @@ pointer_constrain_callback (ClutterInputDevice *device, constrain_to_client_constraint (device, time, prev_x, prev_y, new_x, new_y); } -static void -relative_motion_across_outputs (MetaMonitorManager *monitor_manager, - MetaLogicalMonitor *current, - float cur_x, - float cur_y, - float *dx_inout, - float *dy_inout) -{ - MetaLogicalMonitor *cur = current; - float x = cur_x, y = cur_y; - float target_x = cur_x, target_y = cur_y; - float dx = *dx_inout, dy = *dy_inout; - MetaDisplayDirection direction = -1; - - while (cur) - { - MetaLine2 left, right, top, bottom, motion; - MetaVector2 intersection; - - motion = (MetaLine2) { - .a = { x, y }, - .b = { x + (dx * cur->scale), y + (dy * cur->scale) } - }; - left = (MetaLine2) { - { cur->rect.x, cur->rect.y }, - { cur->rect.x, cur->rect.y + cur->rect.height } - }; - right = (MetaLine2) { - { cur->rect.x + cur->rect.width, cur->rect.y }, - { cur->rect.x + cur->rect.width, cur->rect.y + cur->rect.height } - }; - top = (MetaLine2) { - { cur->rect.x, cur->rect.y }, - { cur->rect.x + cur->rect.width, cur->rect.y } - }; - bottom = (MetaLine2) { - { cur->rect.x, cur->rect.y + cur->rect.height }, - { cur->rect.x + cur->rect.width, cur->rect.y + cur->rect.height } - }; - - target_x = motion.b.x; - target_y = motion.b.y; - - if (direction != META_DISPLAY_RIGHT && - meta_line2_intersects_with (&motion, &left, &intersection)) - direction = META_DISPLAY_LEFT; - else if (direction != META_DISPLAY_LEFT && - meta_line2_intersects_with (&motion, &right, &intersection)) - direction = META_DISPLAY_RIGHT; - else if (direction != META_DISPLAY_DOWN && - meta_line2_intersects_with (&motion, &top, &intersection)) - direction = META_DISPLAY_UP; - else if (direction != META_DISPLAY_UP && - meta_line2_intersects_with (&motion, &bottom, &intersection)) - direction = META_DISPLAY_DOWN; - else - /* We reached the dest logical monitor */ - break; - - x = intersection.x; - y = intersection.y; - dx -= intersection.x - motion.a.x; - dy -= intersection.y - motion.a.y; - - cur = meta_monitor_manager_get_logical_monitor_neighbor (monitor_manager, - cur, direction); - } - - *dx_inout = target_x - cur_x; - *dy_inout = target_y - cur_y; -} - -static void -relative_motion_filter (ClutterInputDevice *device, - float x, - float y, - float *dx, - float *dy, - gpointer user_data) -{ - MetaMonitorManager *monitor_manager = user_data; - MetaLogicalMonitor *logical_monitor, *dest_logical_monitor; - float new_dx, new_dy; - - if (meta_is_stage_views_scaled ()) - return; - - logical_monitor = meta_monitor_manager_get_logical_monitor_at (monitor_manager, - x, y); - if (!logical_monitor) - return; - - new_dx = (*dx) * logical_monitor->scale; - new_dy = (*dy) * logical_monitor->scale; - - dest_logical_monitor = meta_monitor_manager_get_logical_monitor_at (monitor_manager, - x + new_dx, - y + new_dy); - if (dest_logical_monitor && - dest_logical_monitor != logical_monitor) - { - /* If we are crossing monitors, attempt to bisect the distance on each - * axis and apply the relative scale for each of them. - */ - new_dx = *dx; - new_dy = *dy; - relative_motion_across_outputs (monitor_manager, logical_monitor, - x, y, &new_dx, &new_dy); - } - - *dx = new_dx; - *dy = new_dy; -} - static ClutterBackend * meta_backend_native_create_clutter_backend (MetaBackend *backend) { @@ -302,9 +188,6 @@ meta_backend_native_post_init (MetaBackend *backend) meta_seat_native_set_pointer_constrain_callback (META_SEAT_NATIVE (seat), pointer_constrain_callback, NULL, NULL); - meta_seat_native_set_relative_motion_filter (META_SEAT_NATIVE (seat), - relative_motion_filter, - meta_backend_get_monitor_manager (backend)); META_BACKEND_CLASS (meta_backend_native_parent_class)->post_init (backend); diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c index 01f2e3a10..cd5dfef25 100644 --- a/src/backends/native/meta-seat-native.c +++ b/src/backends/native/meta-seat-native.c @@ -993,6 +993,78 @@ meta_seat_native_constrain_pointer (MetaSeatNative *seat, constrain_all_screen_monitors (core_pointer, monitor_manager, new_x, new_y); } +static void +relative_motion_across_outputs (MetaMonitorManager *monitor_manager, + MetaLogicalMonitor *current, + float cur_x, + float cur_y, + float *dx_inout, + float *dy_inout) +{ + MetaLogicalMonitor *cur = current; + float x = cur_x, y = cur_y; + float target_x = cur_x, target_y = cur_y; + float dx = *dx_inout, dy = *dy_inout; + MetaDisplayDirection direction = -1; + + while (cur) + { + MetaLine2 left, right, top, bottom, motion; + MetaVector2 intersection; + + motion = (MetaLine2) { + .a = { x, y }, + .b = { x + (dx * cur->scale), y + (dy * cur->scale) } + }; + left = (MetaLine2) { + { cur->rect.x, cur->rect.y }, + { cur->rect.x, cur->rect.y + cur->rect.height } + }; + right = (MetaLine2) { + { cur->rect.x + cur->rect.width, cur->rect.y }, + { cur->rect.x + cur->rect.width, cur->rect.y + cur->rect.height } + }; + top = (MetaLine2) { + { cur->rect.x, cur->rect.y }, + { cur->rect.x + cur->rect.width, cur->rect.y } + }; + bottom = (MetaLine2) { + { cur->rect.x, cur->rect.y + cur->rect.height }, + { cur->rect.x + cur->rect.width, cur->rect.y + cur->rect.height } + }; + + target_x = motion.b.x; + target_y = motion.b.y; + + if (direction != META_DISPLAY_RIGHT && + meta_line2_intersects_with (&motion, &left, &intersection)) + direction = META_DISPLAY_LEFT; + else if (direction != META_DISPLAY_LEFT && + meta_line2_intersects_with (&motion, &right, &intersection)) + direction = META_DISPLAY_RIGHT; + else if (direction != META_DISPLAY_DOWN && + meta_line2_intersects_with (&motion, &top, &intersection)) + direction = META_DISPLAY_UP; + else if (direction != META_DISPLAY_UP && + meta_line2_intersects_with (&motion, &bottom, &intersection)) + direction = META_DISPLAY_DOWN; + else + /* We reached the dest logical monitor */ + break; + + x = intersection.x; + y = intersection.y; + dx -= intersection.x - motion.a.x; + dy -= intersection.y - motion.a.y; + + cur = meta_monitor_manager_get_logical_monitor_neighbor (monitor_manager, + cur, direction); + } + + *dx_inout = target_x - cur_x; + *dy_inout = target_y - cur_y; +} + void meta_seat_native_filter_relative_motion (MetaSeatNative *seat, ClutterInputDevice *device, @@ -1001,11 +1073,40 @@ meta_seat_native_filter_relative_motion (MetaSeatNative *seat, float *dx, float *dy) { - if (!seat->relative_motion_filter) + MetaBackend *backend = meta_get_backend (); + MetaMonitorManager *monitor_manager = + meta_backend_get_monitor_manager (backend); + MetaLogicalMonitor *logical_monitor, *dest_logical_monitor; + float new_dx, new_dy; + + if (meta_is_stage_views_scaled ()) return; - seat->relative_motion_filter (device, x, y, dx, dy, - seat->relative_motion_filter_user_data); + logical_monitor = meta_monitor_manager_get_logical_monitor_at (monitor_manager, + x, y); + if (!logical_monitor) + return; + + new_dx = (*dx) * logical_monitor->scale; + new_dy = (*dy) * logical_monitor->scale; + + dest_logical_monitor = meta_monitor_manager_get_logical_monitor_at (monitor_manager, + x + new_dx, + y + new_dy); + if (dest_logical_monitor && + dest_logical_monitor != logical_monitor) + { + /* If we are crossing monitors, attempt to bisect the distance on each + * axis and apply the relative scale for each of them. + */ + new_dx = *dx; + new_dy = *dy; + relative_motion_across_outputs (monitor_manager, logical_monitor, + x, y, &new_dx, &new_dy); + } + + *dx = new_dx; + *dy = new_dy; } static void @@ -3051,17 +3152,6 @@ meta_seat_native_set_pointer_constrain_callback (MetaSeatNative *s } void -meta_seat_native_set_relative_motion_filter (MetaSeatNative *seat, - MetaRelativeMotionFilter filter, - gpointer user_data) -{ - g_return_if_fail (META_IS_SEAT_NATIVE (seat)); - - seat->relative_motion_filter = filter; - seat->relative_motion_filter_user_data = user_data; -} - -void meta_seat_native_update_xkb_state (MetaSeatNative *seat) { xkb_mod_mask_t latched_mods; diff --git a/src/backends/native/meta-seat-native.h b/src/backends/native/meta-seat-native.h index dbb9933d9..0cc353e7d 100644 --- a/src/backends/native/meta-seat-native.h +++ b/src/backends/native/meta-seat-native.h @@ -59,12 +59,6 @@ typedef void (* MetaPointerConstrainCallback) (ClutterInputDevice *device, float *x, float *y, gpointer user_data); -typedef void (* MetaRelativeMotionFilter) (ClutterInputDevice *device, - float x, - float y, - float *dx, - float *dy, - gpointer user_data); struct _MetaTouchState { @@ -115,9 +109,6 @@ struct _MetaSeatNative gpointer constrain_data; GDestroyNotify constrain_data_notify; - MetaRelativeMotionFilter relative_motion_filter; - gpointer relative_motion_filter_user_data; - MetaKeymapNative *keymap; GUdevClient *udev_client; @@ -270,10 +261,6 @@ void meta_seat_native_set_pointer_constrain_callback (MetaSeatNative gpointer user_data, GDestroyNotify user_data_notify); -void meta_seat_native_set_relative_motion_filter (MetaSeatNative *seat, - MetaRelativeMotionFilter filter, - gpointer user_data); - struct xkb_state * meta_seat_native_get_xkb_state (MetaSeatNative *seat); void meta_seat_native_set_keyboard_map (MetaSeatNative *seat, |