]> git.mdlowis.com Git - proto/labwc.git/commitdiff
SnapToRegion: Add SnapToRegion action
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Wed, 6 Jul 2022 06:06:48 +0000 (08:06 +0200)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Wed, 11 Jan 2023 17:52:24 +0000 (18:52 +0100)
include/regions.h
src/action.c
src/regions.c

index 86bd570e5a53f81db18e653a0bdd146597b90ef6..7b9b224153719a0bc195233b99b23a2c9f3639e7 100644 (file)
@@ -30,4 +30,6 @@ void regions_init(struct server *server, struct seat *seat);
 void regions_update(struct output *output);
 void regions_destroy(struct wl_list *regions);
 
+struct region *regions_from_name(const char *region_name, struct output *output);
+
 #endif /* __LABWC_REGIONS_H */
index c191bdbd49336946b4ab1558ae08b845ecbaabbd..09992ef15de7cc73078f3fc741fd6bcb8c3930ba 100644 (file)
@@ -13,6 +13,7 @@
 #include "debug.h"
 #include "labwc.h"
 #include "menu/menu.h"
+#include "regions.h"
 #include "ssd.h"
 #include "view.h"
 #include "workspaces.h"
@@ -58,6 +59,7 @@ enum action_type {
        ACTION_TYPE_RESIZE,
        ACTION_TYPE_GO_TO_DESKTOP,
        ACTION_TYPE_SEND_TO_DESKTOP,
+       ACTION_TYPE_SNAP_TO_REGION
 };
 
 const char *action_names[] = {
@@ -85,6 +87,7 @@ const char *action_names[] = {
        "Resize",
        "GoToDesktop",
        "SendToDesktop",
+       "SnapToRegion",
        NULL
 };
 
@@ -111,6 +114,9 @@ action_arg_from_xml_node(struct action *action, char *nodename, char *content)
        } else if (!strcmp(nodename, "to.action")) {
                /* GoToDesktop, SendToDesktop */
                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;
+               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:
                        break;
                case ACTION_TYPE_INVALID:
index 52d2c5d3e9ec1dcab243ecc262f25b21a01c6d2a..4b299730bdecaf3828c09339457a1ea0da0f497e 100644 (file)
@@ -25,6 +25,20 @@ regions_init(struct server *server, struct seat *seat)
        /* 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
 regions_update(struct output *output)
 {