Add ResizeTo action

Fixes: #1261
This commit is contained in:
Johan Malm 2023-12-01 17:03:58 +00:00 committed by Johan Malm
parent 590ec0c77d
commit 9c1c96f993
2 changed files with 34 additions and 0 deletions

View 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.

View 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);