]> git.mdlowis.com Git - proto/labwc.git/commitdiff
action: add MoveToOutput
authorJens Peters <jp7677@gmail.com>
Sun, 21 Jan 2024 22:45:47 +0000 (23:45 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Mon, 22 Jan 2024 22:27:08 +0000 (22:27 +0000)
src/action.c

index d9b46866ec36cfae489a1c1bcbdad81f9f265eb3..8e12eeb6388b6006aece0b14d70d49512a7c23c1 100644 (file)
@@ -97,6 +97,7 @@ enum action_type {
        ACTION_TYPE_SNAP_TO_REGION,
        ACTION_TYPE_TOGGLE_KEYBINDS,
        ACTION_TYPE_FOCUS_OUTPUT,
+       ACTION_TYPE_MOVE_TO_OUTPUT,
        ACTION_TYPE_IF,
        ACTION_TYPE_FOR_EACH,
        ACTION_TYPE_VIRTUAL_OUTPUT_ADD,
@@ -148,6 +149,7 @@ const char *action_names[] = {
        "SnapToRegion",
        "ToggleKeybinds",
        "FocusOutput",
+       "MoveToOutput",
        "If",
        "ForEach",
        "VirtualOutputAdd",
@@ -378,6 +380,22 @@ action_arg_from_xml_node(struct action *action, const char *nodename, const char
                        goto cleanup;
                }
                break;
+       case ACTION_TYPE_MOVE_TO_OUTPUT:
+               if (!strcmp(argument, "name")) {
+                       action_arg_add_str(action, argument, content);
+                       goto cleanup;
+               }
+               if (!strcmp(argument, "direction")) {
+                       enum view_edge edge = view_edge_parse(content);
+                       if (edge == VIEW_EDGE_CENTER) {
+                               wlr_log(WLR_ERROR, "Invalid argument for action %s: '%s' (%s)",
+                                       action_names[action->type], argument, content);
+                       } else {
+                               action_arg_add_int(action, argument, edge);
+                       }
+                       goto cleanup;
+               }
+               break;
        case ACTION_TYPE_VIRTUAL_OUTPUT_ADD:
        case ACTION_TYPE_VIRTUAL_OUTPUT_REMOVE:
                if (!strcmp(argument, "output_name")) {
@@ -893,6 +911,25 @@ actions_run(struct view *activator, struct server *server,
                                }
                        }
                        break;
+               case ACTION_TYPE_MOVE_TO_OUTPUT:
+                       if (!view) {
+                               break;
+                       }
+                       const char *name = action_get_str(action, "name", NULL);
+                       struct output *target = NULL;
+                       if (name) {
+                               target = output_from_name(view->server, name);
+                       } else {
+                               /* Config parsing makes sure that direction is a valid direction */
+                               enum view_edge edge = action_get_int(action, "direction", 0);
+                               target = view_get_adjacent_output(view, edge);
+                       }
+                       if (!target) {
+                               wlr_log(WLR_ERROR, "Invalid output.");
+                               break;
+                       }
+                       view_move_to_output(view, target);
+                       break;
                case ACTION_TYPE_SNAP_TO_REGION:
                        if (!view) {
                                break;