]> git.mdlowis.com Git - proto/labwc.git/commitdiff
GrowToEdge, ShrinkToEdge: Implement actions
authorAxel Burri <axel@tty0.ch>
Sat, 5 Aug 2023 21:58:40 +0000 (23:58 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Thu, 19 Oct 2023 18:09:42 +0000 (19:09 +0100)
include/view.h
src/action.c
src/view.c

index 52bd6ed4fc29f0bec8c02ce2d6c726c19c52f5a0..471e52dd38ecf82990747ad07cad597bd8f4d008 100644 (file)
@@ -371,6 +371,8 @@ void view_set_decorations(struct view *view, bool decorations);
 void view_toggle_fullscreen(struct view *view);
 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_region(struct view *view, struct region *region, bool store_natural_geometry);
 
index 6402c4ec6b4df391757132f4e0397904628a8d4f..f9b15c386a80fef711d7bc9271ff7c45b7b5e29c 100644 (file)
@@ -66,6 +66,8 @@ enum action_type {
        ACTION_TYPE_EXIT,
        ACTION_TYPE_MOVE_TO_EDGE,
        ACTION_TYPE_SNAP_TO_EDGE,
+       ACTION_TYPE_GROW_TO_EDGE,
+       ACTION_TYPE_SHRINK_TO_EDGE,
        ACTION_TYPE_NEXT_WINDOW,
        ACTION_TYPE_PREVIOUS_WINDOW,
        ACTION_TYPE_RECONFIGURE,
@@ -105,6 +107,8 @@ const char *action_names[] = {
        "Exit",
        "MoveToEdge",
        "SnapToEdge",
+       "GrowToEdge",
+       "ShrinkToEdge",
        "NextWindow",
        "PreviousWindow",
        "Reconfigure",
@@ -272,6 +276,8 @@ action_arg_from_xml_node(struct action *action, const char *nodename, const char
                }
                /* Falls through */
        case ACTION_TYPE_SNAP_TO_EDGE:
+       case ACTION_TYPE_GROW_TO_EDGE:
+       case ACTION_TYPE_SHRINK_TO_EDGE:
                if (!strcmp(argument, "direction")) {
                        enum view_edge edge = view_edge_parse(content);
                        if ((edge == VIEW_EDGE_CENTER && action->type != ACTION_TYPE_SNAP_TO_EDGE)
@@ -411,6 +417,8 @@ action_is_valid(struct action *action)
                break;
        case ACTION_TYPE_MOVE_TO_EDGE:
        case ACTION_TYPE_SNAP_TO_EDGE:
+       case ACTION_TYPE_GROW_TO_EDGE:
+       case ACTION_TYPE_SHRINK_TO_EDGE:
                arg_name = "direction";
                arg_type = LAB_ACTION_ARG_INT;
                break;
@@ -654,6 +662,20 @@ actions_run(struct view *activator, struct server *server,
                                view_snap_to_edge(view, edge, /*store_natural_geometry*/ true);
                        }
                        break;
+               case ACTION_TYPE_GROW_TO_EDGE:
+                       if (view) {
+                               /* Config parsing makes sure that direction is a valid direction */
+                               enum view_edge edge = action_get_int(action, "direction", 0);
+                               view_grow_to_edge(view, edge);
+                       }
+                       break;
+               case ACTION_TYPE_SHRINK_TO_EDGE:
+                       if (view) {
+                               /* Config parsing makes sure that direction is a valid direction */
+                               enum view_edge edge = action_get_int(action, "direction", 0);
+                               view_shrink_to_edge(view, edge);
+                       }
+                       break;
                case ACTION_TYPE_NEXT_WINDOW:
                        server->osd_state.cycle_view = desktop_cycle_view(server,
                                server->osd_state.cycle_view, LAB_CYCLE_DIR_FORWARD);
index 3eaeebeed073aae35e2425845d4ffd076b1c2122..e85934bf38932d3624468771c04e1a8444de7c77 100644 (file)
@@ -1162,6 +1162,40 @@ view_move_to_edge(struct view *view, enum view_edge direction, bool snap_to_wind
        view_move(view, view->pending.x + dx, view->pending.y + dy);
 }
 
+void
+view_grow_to_edge(struct view *view, enum view_edge direction)
+{
+       assert(view);
+       if (view->fullscreen || view->maximized) {
+               return;
+       }
+       if (!output_is_usable(view->output)) {
+               wlr_log(WLR_ERROR, "view has no output, not growing view");
+               return;
+       }
+
+       struct wlr_box geo = view->pending;
+       snap_grow_to_next_edge(view, direction, &geo);
+       view_move_resize(view, geo);
+}
+
+void
+view_shrink_to_edge(struct view *view, enum view_edge direction)
+{
+       assert(view);
+       if (view->fullscreen || view->maximized) {
+               return;
+       }
+       if (!output_is_usable(view->output)) {
+               wlr_log(WLR_ERROR, "view has no output, not shrinking view");
+               return;
+       }
+
+       struct wlr_box geo = view->pending;
+       snap_shrink_to_next_edge(view, direction, &geo);
+       view_move_resize(view, geo);
+}
+
 enum view_edge
 view_edge_parse(const char *direction)
 {