]> git.mdlowis.com Git - proto/labwc.git/commitdiff
interactive: Make window snapping with mouse more intuitive
authortokyo4j <hrak1529@gmail.com>
Tue, 7 Nov 2023 05:43:53 +0000 (14:43 +0900)
committerJohan Malm <johanmalm@users.noreply.github.com>
Fri, 10 Nov 2023 19:41:36 +0000 (19:41 +0000)
1. Prevent window snapping triggered by mouse from moving the window
 into the adjacent output.
2. Make the coordinates used to check whether window snapping is
 triggered relative to the output the cursor is at, not the output the
 view is belonging to. This allows users to grab a tiled window and move
 it into another output or tile it again in another output in a single
 drag.

include/view.h
src/action.c
src/interactive.c
src/view.c

index c8640485430551a1d0b5bc1b49c7d8d9aff1bb19..d17ebad5885df9a70c1af53e93ef6c67e536deb3 100644 (file)
@@ -388,7 +388,8 @@ void view_adjust_for_layout_change(struct view *view);
 void view_move_to_edge(struct view *view, enum view_edge direction, bool snap_to_windows);
 void view_grow_to_edge(struct view *view, enum view_edge direction);
 void view_shrink_to_edge(struct view *view, enum view_edge direction);
-void view_snap_to_edge(struct view *view, enum view_edge direction, bool store_natural_geometry);
+void view_snap_to_edge(struct view *view, enum view_edge direction,
+       bool across_outputs, bool store_natural_geometry);
 void view_snap_to_region(struct view *view, struct region *region, bool store_natural_geometry);
 
 void view_move_to_front(struct view *view);
index 6cd809e4e4f132afbf86c9b8fb4aaba3543690af..bd0b7051985d172002b40d0fadaecc4d9b5e760c 100644 (file)
@@ -674,7 +674,9 @@ actions_run(struct view *activator, struct server *server,
                        if (view) {
                                /* Config parsing makes sure that direction is a valid direction */
                                enum view_edge edge = action_get_int(action, "direction", 0);
-                               view_snap_to_edge(view, edge, /*store_natural_geometry*/ true);
+                               view_snap_to_edge(view, edge,
+                                       /*across_outputs*/ true,
+                                       /*store_natural_geometry*/ true);
                        }
                        break;
                case ACTION_TYPE_GROW_TO_EDGE:
index d863f5698b108ff5dafa03532d0da378429b6ef9..25139e8bbe6f997845a1f64248fdffd07c3e1c4f 100644 (file)
@@ -114,39 +114,47 @@ snap_to_edge(struct view *view)
                return false;
        }
 
+       struct output *output = output_nearest_to_cursor(view->server);
+       if (!output_is_usable(output)) {
+               wlr_log(WLR_ERROR, "output at cursor is unusable");
+               return false;
+       }
+
        /* Translate into output local coordinates */
        double cursor_x = view->server->seat.cursor->x;
        double cursor_y = view->server->seat.cursor->y;
        wlr_output_layout_output_coords(view->server->output_layout,
-               view->output->wlr_output, &cursor_x, &cursor_y);
+               output->wlr_output, &cursor_x, &cursor_y);
 
-       /*
-        * Don't store natural geometry here (it was
-        * stored already in interactive_begin())
-        */
-       struct wlr_box *area = &view->output->usable_area;
+       struct wlr_box *area = &output->usable_area;
+       enum view_edge edge;
        if (cursor_x <= area->x + snap_range) {
-               view_snap_to_edge(view, VIEW_EDGE_LEFT,
-                       /*store_natural_geometry*/ false);
+               edge = VIEW_EDGE_LEFT;
        } else if (cursor_x >= area->x + area->width - snap_range) {
-               view_snap_to_edge(view, VIEW_EDGE_RIGHT,
-                       /*store_natural_geometry*/ false);
+               edge = VIEW_EDGE_RIGHT;
        } else if (cursor_y <= area->y + snap_range) {
-               if (rc.snap_top_maximize) {
-                       view_maximize(view, VIEW_AXIS_BOTH,
-                               /*store_natural_geometry*/ false);
-               } else {
-                       view_snap_to_edge(view, VIEW_EDGE_UP,
-                               /*store_natural_geometry*/ false);
-               }
+               edge = VIEW_EDGE_UP;
        } else if (cursor_y >= area->y + area->height - snap_range) {
-               view_snap_to_edge(view, VIEW_EDGE_DOWN,
-                       /*store_natural_geometry*/ false);
+               edge = VIEW_EDGE_DOWN;
        } else {
                /* Not close to any edge */
                return false;
        }
 
+       view_set_output(view, output);
+       /*
+        * Don't store natural geometry here (it was
+        * stored already in interactive_begin())
+        */
+       if (edge == VIEW_EDGE_UP && rc.snap_top_maximize) {
+               view_maximize(view, VIEW_AXIS_BOTH,
+                       /*store_natural_geometry*/ false);
+       } else {
+               view_snap_to_edge(view, edge,
+                       /*across_outputs*/ false,
+                       /*store_natural_geometry*/ false);
+       }
+
        return true;
 }
 
index b440fb6f64266f28c6aa7894436b5666ba10f3cd..e11c6c14c4f150fd0ed09290b61693181727687e 100644 (file)
@@ -1322,7 +1322,8 @@ view_edge_parse(const char *direction)
 }
 
 void
-view_snap_to_edge(struct view *view, enum view_edge edge, bool store_natural_geometry)
+view_snap_to_edge(struct view *view, enum view_edge edge,
+                       bool across_outputs, bool store_natural_geometry)
 {
        assert(view);
        if (view->fullscreen) {
@@ -1334,7 +1335,7 @@ view_snap_to_edge(struct view *view, enum view_edge edge, bool store_natural_geo
                return;
        }
 
-       if (view->tiled == edge && view->maximized == VIEW_AXIS_NONE) {
+       if (across_outputs && view->tiled == edge && view->maximized == VIEW_AXIS_NONE) {
                /* We are already tiled for this edge and thus should switch outputs */
                struct wlr_output *new_output = NULL;
                struct wlr_output *current_output = output->wlr_output;
@@ -1375,13 +1376,6 @@ view_snap_to_edge(struct view *view, enum view_edge edge, bool store_natural_geo
                         * state because the window might have been moved away
                         * (and thus got untiled) and then snapped back to the
                         * original edge.
-                        *
-                        * TODO: The described pattern will cause another bug
-                        *       in multi monitor setups: it will snap the
-                        *       window to the inverted edge of the nearest
-                        *       output. This is the desired behavior when
-                        *       caused by a keybind but doesn't make sense
-                        *       when caused by mouse movement.
                         */
                        view_apply_tiled_geometry(view);
                        return;