From e4542a6495681ef6e29d348ac70108f98bfd1c62 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Thu, 25 Jan 2024 12:38:01 +0100 Subject: [PATCH] compositor: Add MetaWindowDrag API to add a hint on the grab coordinates This is added as a hint so that the caller can optionally use it, e.g. in the case that a window drag is driven by the mouse. This will be used to more accurately follow the drag position, other than starting at the current pointer position. Part-of: --- src/compositor/meta-window-drag.c | 17 +++++++++++++++++ src/compositor/meta-window-drag.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/src/compositor/meta-window-drag.c b/src/compositor/meta-window-drag.c index 53b81c348..576bfb37c 100644 --- a/src/compositor/meta-window-drag.c +++ b/src/compositor/meta-window-drag.c @@ -56,6 +56,8 @@ struct _MetaWindowDrag { MetaGrabOp grab_op; ClutterGrab *grab; + graphene_point_t pos_hint; + ClutterInputDevice *leading_device; ClutterEventSequence *leading_touch_sequence; double anchor_rel_x; @@ -79,6 +81,7 @@ struct _MetaWindowDrag { guint tile_preview_timeout_id; guint preview_tile_mode : 2; + guint pos_hint_set : 1; }; G_DEFINE_FINAL_TYPE (MetaWindowDrag, meta_window_drag, G_TYPE_OBJECT) @@ -1781,6 +1784,11 @@ meta_window_drag_begin (MetaWindowDrag *window_drag, { warp_grab_pointer (window_drag, window, grab_op, &root_x, &root_y); } + else if (window_drag->pos_hint_set) + { + root_x = window_drag->pos_hint.x; + root_y = window_drag->pos_hint.y; + } else { ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); @@ -1917,3 +1925,12 @@ meta_window_drag_update_edges (MetaWindowDrag *window_drag) { meta_window_drag_edge_resistance_cleanup (window_drag); } + +void +meta_window_drag_set_position_hint (MetaWindowDrag *window_drag, + graphene_point_t *pos_hint) +{ + window_drag->pos_hint_set = pos_hint != NULL; + if (pos_hint) + window_drag->pos_hint = *pos_hint; +} diff --git a/src/compositor/meta-window-drag.h b/src/compositor/meta-window-drag.h index 3f48dcc09..5fac435b7 100644 --- a/src/compositor/meta-window-drag.h +++ b/src/compositor/meta-window-drag.h @@ -43,3 +43,6 @@ MetaWindow * meta_window_drag_get_window (MetaWindowDrag *window_drag); MetaGrabOp meta_window_drag_get_grab_op (MetaWindowDrag *window_drag); void meta_window_drag_update_edges (MetaWindowDrag *window_drag); + +void meta_window_drag_set_position_hint (MetaWindowDrag *window_drag, + graphene_point_t *pos_hint);