From e3cd18976935d5229d48c16996842311a1b1f81f Mon Sep 17 00:00:00 2001 From: "Andrew J. Hesford" Date: Thu, 28 Dec 2023 16:47:21 -0500 Subject: [PATCH] feat: add "AutoPlace" action The AutoPlace action will apply placement_find_best() to an active view, moving it to a position on its output that will minimize overlap with other views. --- docs/labwc-actions.5.scd | 4 ++++ docs/rc.xml.all | 6 +++++- src/action.c | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/labwc-actions.5.scd b/docs/labwc-actions.5.scd index f639c490..6558d0fc 100644 --- a/docs/labwc-actions.5.scd +++ b/docs/labwc-actions.5.scd @@ -219,6 +219,10 @@ Actions are used in menus and keyboard/mouse bindings. *output_name* The name of virtual output. If not supplied, will remove the last virtual output added. +** + Use the automatic placement policy to move the active window to a + position on its output that will minimize overlap with other windows. + ** If used as the only action for a binding: clear an earlier defined binding. diff --git a/docs/rc.xml.all b/docs/rc.xml.all index c5ef69cf..316586d9 100644 --- a/docs/rc.xml.all +++ b/docs/rc.xml.all @@ -453,10 +453,14 @@ yes yes - yes + yes + + + + --> diff --git a/src/action.c b/src/action.c index fb442ac6..2259ba7d 100644 --- a/src/action.c +++ b/src/action.c @@ -16,6 +16,7 @@ #include "debug.h" #include "labwc.h" #include "menu/menu.h" +#include "placement.h" #include "regions.h" #include "ssd.h" #include "view.h" @@ -100,6 +101,7 @@ enum action_type { ACTION_TYPE_FOR_EACH, ACTION_TYPE_VIRTUAL_OUTPUT_ADD, ACTION_TYPE_VIRTUAL_OUTPUT_REMOVE, + ACTION_TYPE_AUTO_PLACE, }; const char *action_names[] = { @@ -146,6 +148,7 @@ const char *action_names[] = { "ForEach", "VirtualOutputAdd", "VirtualOutputRemove", + "AutoPlace", NULL }; @@ -940,6 +943,14 @@ actions_run(struct view *activator, struct server *server, output_remove_virtual(server, output_name); } break; + case ACTION_TYPE_AUTO_PLACE: + if (view) { + int x = 0, y = 0; + if (placement_find_best(view, &x, &y)) { + view_move(view, x, y); + } + } + break; case ACTION_TYPE_INVALID: wlr_log(WLR_ERROR, "Not executing unknown action"); break;