SnapToRegion: Add SnapToRegion action

This commit is contained in:
Consolatis 2022-07-06 08:06:48 +02:00
parent 9d3e309a22
commit 96a591297d
3 changed files with 43 additions and 0 deletions

View file

@ -30,4 +30,6 @@ void regions_init(struct server *server, struct seat *seat);
void regions_update(struct output *output); void regions_update(struct output *output);
void regions_destroy(struct wl_list *regions); void regions_destroy(struct wl_list *regions);
struct region *regions_from_name(const char *region_name, struct output *output);
#endif /* __LABWC_REGIONS_H */ #endif /* __LABWC_REGIONS_H */

View file

@ -13,6 +13,7 @@
#include "debug.h" #include "debug.h"
#include "labwc.h" #include "labwc.h"
#include "menu/menu.h" #include "menu/menu.h"
#include "regions.h"
#include "ssd.h" #include "ssd.h"
#include "view.h" #include "view.h"
#include "workspaces.h" #include "workspaces.h"
@ -58,6 +59,7 @@ enum action_type {
ACTION_TYPE_RESIZE, ACTION_TYPE_RESIZE,
ACTION_TYPE_GO_TO_DESKTOP, ACTION_TYPE_GO_TO_DESKTOP,
ACTION_TYPE_SEND_TO_DESKTOP, ACTION_TYPE_SEND_TO_DESKTOP,
ACTION_TYPE_SNAP_TO_REGION
}; };
const char *action_names[] = { const char *action_names[] = {
@ -85,6 +87,7 @@ const char *action_names[] = {
"Resize", "Resize",
"GoToDesktop", "GoToDesktop",
"SendToDesktop", "SendToDesktop",
"SnapToRegion",
NULL NULL
}; };
@ -111,6 +114,9 @@ action_arg_from_xml_node(struct action *action, char *nodename, char *content)
} else if (!strcmp(nodename, "to.action")) { } else if (!strcmp(nodename, "to.action")) {
/* GoToDesktop, SendToDesktop */ /* GoToDesktop, SendToDesktop */
action_arg_add_str(action, NULL, content); action_arg_add_str(action, NULL, content);
} else if (!strcmp(nodename, "region.action")) {
/* SnapToRegion */
action_arg_add_str(action, NULL, content);
} }
} }
@ -418,6 +424,27 @@ actions_run(struct view *activator, struct server *server,
} }
} }
break; break;
case ACTION_TYPE_SNAP_TO_REGION:
if (!arg) {
wlr_log(WLR_ERROR, "Missing argument for SnapToRegion");
break;
}
if (!view) {
break;
}
struct output *output = view->output;
if (!output) {
break;
}
const char *region_name = action_str_from_arg(arg);
struct region *region = regions_from_name(region_name, output);
if (region) {
view_snap_to_region(view, region,
/*store_natural_geometry*/ true);
} else {
wlr_log(WLR_ERROR, "Invalid SnapToRegion id: '%s'", region_name);
}
break;
case ACTION_TYPE_NONE: case ACTION_TYPE_NONE:
break; break;
case ACTION_TYPE_INVALID: case ACTION_TYPE_INVALID:

View file

@ -25,6 +25,20 @@ regions_init(struct server *server, struct seat *seat)
/* To be filled later */ /* To be filled later */
} }
struct region *
regions_from_name(const char *region_name, struct output *output)
{
assert(region_name);
assert(output);
struct region *region;
wl_list_for_each(region, &output->regions, link) {
if (!strcmp(region->name, region_name)) {
return region;
}
}
return NULL;
}
void void
regions_update(struct output *output) regions_update(struct output *output)
{ {