]> git.mdlowis.com Git - proto/labwc.git/commitdiff
src/cursor.c: handle pointer constraint position hint
authorJean-Luc Mackail <fuzzyquils@scrapyard.link>
Wed, 12 Apr 2023 06:42:32 +0000 (16:42 +1000)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Thu, 13 Apr 2023 04:01:42 +0000 (06:01 +0200)
Now cursor hints are respected once cursor movement occurs
after unlocking the pointer.

Fixes Overwatch 2 failing to center the mouse pointer when
opening the communication wheel in-game.

Fixes #872

src/cursor.c

index 1a2b031376d81e508e0101750774ac859e30bbde..583dde3c266a0bd06aa81af8a6f50a595e4a7d47 100644 (file)
@@ -543,6 +543,27 @@ cursor_update_focus(struct server *server)
        }
 }
 
+static void
+warp_cursor_to_constraint_hint(struct seat *seat,
+               struct wlr_pointer_constraint_v1 *constraint)
+{
+       if (!seat->server->focused_view) {
+               return;
+       }
+
+       if (constraint->current.committed
+                       & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT) {
+               double sx = constraint->current.cursor_hint.x;
+               double sy = constraint->current.cursor_hint.y;
+               wlr_cursor_warp(seat->cursor, NULL,
+                       seat->server->focused_view->current.x + sx,
+                       seat->server->focused_view->current.y + sy);
+
+               /* Make sure we are not sending unnecessary surface movements */
+               wlr_seat_pointer_warp(seat->seat, sx, sy);
+       }
+}
+
 static void
 handle_constraint_commit(struct wl_listener *listener, void *data)
 {
@@ -561,6 +582,8 @@ destroy_constraint(struct wl_listener *listener, void *data)
 
        wl_list_remove(&constraint->destroy.link);
        if (seat->current_constraint == wlr_constraint) {
+               warp_cursor_to_constraint_hint(seat, wlr_constraint);
+
                if (seat->constraint_commit.link.next) {
                        wl_list_remove(&seat->constraint_commit.link);
                }
@@ -600,6 +623,10 @@ constrain_cursor(struct server *server, struct wlr_pointer_constraint_v1
        }
        wl_list_remove(&seat->constraint_commit.link);
        if (seat->current_constraint) {
+               if (!constraint) {
+                       warp_cursor_to_constraint_hint(seat, seat->current_constraint);
+               }
+
                wlr_pointer_constraint_v1_send_deactivated(
                        seat->current_constraint);
        }