action: add MoveToOutput

This commit is contained in:
Jens Peters 2024-01-21 23:45:47 +01:00 committed by Johan Malm
parent b1d626fbfd
commit aa0e7523c3

View file

@ -97,6 +97,7 @@ enum action_type {
ACTION_TYPE_SNAP_TO_REGION, ACTION_TYPE_SNAP_TO_REGION,
ACTION_TYPE_TOGGLE_KEYBINDS, ACTION_TYPE_TOGGLE_KEYBINDS,
ACTION_TYPE_FOCUS_OUTPUT, ACTION_TYPE_FOCUS_OUTPUT,
ACTION_TYPE_MOVE_TO_OUTPUT,
ACTION_TYPE_IF, ACTION_TYPE_IF,
ACTION_TYPE_FOR_EACH, ACTION_TYPE_FOR_EACH,
ACTION_TYPE_VIRTUAL_OUTPUT_ADD, ACTION_TYPE_VIRTUAL_OUTPUT_ADD,
@ -148,6 +149,7 @@ const char *action_names[] = {
"SnapToRegion", "SnapToRegion",
"ToggleKeybinds", "ToggleKeybinds",
"FocusOutput", "FocusOutput",
"MoveToOutput",
"If", "If",
"ForEach", "ForEach",
"VirtualOutputAdd", "VirtualOutputAdd",
@ -378,6 +380,22 @@ action_arg_from_xml_node(struct action *action, const char *nodename, const char
goto cleanup; goto cleanup;
} }
break; 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_ADD:
case ACTION_TYPE_VIRTUAL_OUTPUT_REMOVE: case ACTION_TYPE_VIRTUAL_OUTPUT_REMOVE:
if (!strcmp(argument, "output_name")) { if (!strcmp(argument, "output_name")) {
@ -893,6 +911,25 @@ actions_run(struct view *activator, struct server *server,
} }
} }
break; 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: case ACTION_TYPE_SNAP_TO_REGION:
if (!view) { if (!view) {
break; break;