]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Add ResizeTo action
authorJohan Malm <jgm323@gmail.com>
Fri, 1 Dec 2023 17:03:58 +0000 (17:03 +0000)
committerJohan Malm <johanmalm@users.noreply.github.com>
Fri, 1 Dec 2023 21:23:42 +0000 (21:23 +0000)
Fixes: #1261
docs/labwc-actions.5.scd
src/action.c

index 2af1f0bc499e88bac84d3514d9a6f00a59ced1f2..984f35f0feafdaab91ca3937680697222304239f 100644 (file)
@@ -73,6 +73,13 @@ Actions are used in menus and keyboard/mouse bindings.
 *<action name="MoveTo" x="" y="" />*
        Move to position (x, y)
 
+*<action name="ResizeTo" width="" height="" />*
+       Resize window
+
+       *width* The width to resize the window to in pixels.
+
+       *height* The height to resize the window to in pixels.
+
 *<action name="MoveToCursor" />*
        Move to be centered on cursor.
        Tries to prevent any part of the window from going off-screen.
index 07a52dd2b45cdd6c25dec7aefddc3cb581e06517..3a97efe48b36022e0e6d7dbb3cea22cfbdac4af5 100644 (file)
@@ -88,6 +88,7 @@ enum action_type {
        ACTION_TYPE_RESIZE,
        ACTION_TYPE_RESIZE_RELATIVE,
        ACTION_TYPE_MOVETO,
+       ACTION_TYPE_RESIZETO,
        ACTION_TYPE_MOVETO_CURSOR,
        ACTION_TYPE_MOVE_RELATIVE,
        ACTION_TYPE_SEND_TO_DESKTOP,
@@ -131,6 +132,7 @@ const char *action_names[] = {
        "Resize",
        "ResizeRelative",
        "MoveTo",
+       "ResizeTo",
        "MoveToCursor",
        "MoveRelative",
        "SendToDesktop",
@@ -327,6 +329,12 @@ action_arg_from_xml_node(struct action *action, const char *nodename, const char
                        goto cleanup;
                }
                break;
+       case ACTION_TYPE_RESIZETO:
+               if (!strcmp(argument, "width") || !strcmp(argument, "height")) {
+                       action_arg_add_int(action, argument, atoi(content));
+                       goto cleanup;
+               }
+               break;
        case ACTION_TYPE_SEND_TO_DESKTOP:
                if (!strcmp(argument, "follow")) {
                        action_arg_add_bool(action, argument, parse_bool(content, true));
@@ -801,6 +809,25 @@ actions_run(struct view *activator, struct server *server,
                                view_move(view, x, y);
                        }
                        break;
+               case ACTION_TYPE_RESIZETO:
+                       if (view) {
+                               int width = action_get_int(action, "width", 0);
+                               int height = action_get_int(action, "height", 0);
+
+                               /*
+                                * To support only setting one of width/height
+                                * in <action name="ResizeTo" width="" height=""/>
+                                * we fall back to current dimension when unset.
+                                */
+                               struct wlr_box box = {
+                                       .x = view->pending.x,
+                                       .y = view->pending.y,
+                                       .width = width ? : view->pending.width,
+                                       .height = height ? : view->pending.height,
+                               };
+                               view_move_resize(view, box);
+                       }
+                       break;
                case ACTION_TYPE_MOVE_RELATIVE:
                        if (view) {
                                int x = action_get_int(action, "x", 0);