]> git.mdlowis.com Git - proto/labwc.git/commitdiff
xdg: account for drag resistance in do_late_positioning()
authorJohn Lindgren <john@jlindgren.net>
Sat, 3 Aug 2024 00:18:21 +0000 (20:18 -0400)
committerHiroaki Yamamoto <hrak1529@gmail.com>
Tue, 6 Aug 2024 04:51:35 +0000 (13:51 +0900)
The position where the view should be anchored can now be slightly
different from the current cursor position.

Addresses a TODO from #2009.

include/labwc.h
src/interactive.c
src/xdg.c

index 564f668c736ca2e1303c490208d34fa4bec05387..28aeebca2b4e2eba69d8b101d56e952b789e535e 100644 (file)
@@ -503,8 +503,12 @@ void seat_output_layout_changed(struct seat *seat);
  *
  * geometry->{width,height} are provided by the caller.
  * geometry->{x,y} are computed by this function.
+ *
+ * @note When drag-resistance is used, cursor_x/y should be the original
+ *       cursor position when the button was pressed.
  */
-void interactive_anchor_to_cursor(struct view *view, struct wlr_box *geometry);
+void interactive_anchor_to_cursor(struct view *view, struct wlr_box *geometry,
+       int cursor_x, int cursor_y);
 
 /**
  * interactive_move_tiled_view_to() - Un-tile the tiled/maximized view at the
index bd9745a03fe548d165cd659a4476968455ed2bbb..d8c2f342ec359d384e97b785fd0cd49e3cba65dc 100644 (file)
@@ -23,12 +23,12 @@ max_move_scale(double pos_cursor, double pos_current,
 }
 
 void
-interactive_anchor_to_cursor(struct view *view, struct wlr_box *geometry)
+interactive_anchor_to_cursor(struct view *view, struct wlr_box *geometry,
+               int cursor_x, int cursor_y)
 {
-       struct wlr_cursor *cursor = view->server->seat.cursor;
-       geometry->x = max_move_scale(cursor->x, view->current.x,
+       geometry->x = max_move_scale(cursor_x, view->current.x,
                view->current.width, geometry->width);
-       geometry->y = max_move_scale(cursor->y, view->current.y,
+       geometry->y = max_move_scale(cursor_y, view->current.y,
                view->current.height, geometry->height);
 }
 
@@ -113,7 +113,8 @@ interactive_begin(struct view *view, enum input_mode mode, uint32_t edges)
                        geometry.width = view->natural_geometry.width;
                        geometry.height = view->natural_geometry.height;
                        if (!wlr_box_empty(&geometry)) {
-                               interactive_anchor_to_cursor(view, &geometry);
+                               interactive_anchor_to_cursor(view, &geometry,
+                                       seat->cursor->x, seat->cursor->y);
                        }
 
                        /*
index 33d26645df5ca19366e773385a20e391b2f6580b..ad0e19c158a95d80d1976bd83dc79fef0a793477 100644 (file)
--- a/src/xdg.c
+++ b/src/xdg.c
@@ -93,13 +93,14 @@ do_late_positioning(struct view *view)
        struct server *server = view->server;
        if (server->input_mode == LAB_INPUT_STATE_MOVE
                        && view == server->grabbed_view) {
-               /* Keep view underneath cursor */
-               /* TODO: resistance is not considered */
-               interactive_anchor_to_cursor(view, &view->pending);
-               /* Update grab offsets */
-               server->grab_x = server->seat.cursor->x;
-               server->grab_y = server->seat.cursor->y;
+               /* Anchor view to original grab position */
+               interactive_anchor_to_cursor(view, &view->pending,
+                       server->grab_x, server->grab_y);
+               /* Next update grab offsets */
                server->grab_box = view->pending;
+               /* Finally, move by same distance cursor has moved */
+               view->pending.x += server->seat.cursor->x - server->grab_x;
+               view->pending.y += server->seat.cursor->y - server->grab_y;
        } else {
                /* TODO: smart placement? */
                view_compute_centered_position(view, NULL,