Make workspace_move_to_output reusable

Move workspace_move_to_output out of the command handler, so it can be
re-used for ext_workspace_handle_v1::assign.

(cherry picked from commit 7ba11d6dee)
This commit is contained in:
Hugo Osvaldo Barrera 2026-03-12 06:02:42 +01:00 committed by Simon Ser
parent fa889d020b
commit 3aa4c46c13
3 changed files with 37 additions and 34 deletions

View file

@ -985,3 +985,35 @@ void workspace_squash(struct sway_workspace *workspace) {
i += container_squash(child);
}
}
void workspace_move_to_output(struct sway_workspace *workspace,
struct sway_output *output) {
if (workspace->output == output) {
return;
}
struct sway_output *old_output = workspace->output;
workspace_detach(workspace);
struct sway_workspace *new_output_old_ws =
output_get_active_workspace(output);
if (!sway_assert(new_output_old_ws, "Expected output to have a workspace")) {
return;
}
output_add_workspace(output, workspace);
// If moving the last workspace from the old output, create a new workspace
// on the old output
if (old_output->workspaces->length == 0) {
char *ws_name = workspace_next_name(old_output->wlr_output->name);
struct sway_workspace *ws = workspace_create(old_output, ws_name);
free(ws_name);
struct sway_seat *seat = input_manager_current_seat();
seat_set_raw_focus(seat, &ws->node);
}
workspace_consider_destroy(new_output_old_ws);
output_sort_workspaces(output);
workspace_output_raise_priority(workspace, old_output, output);
ipc_event_workspace(NULL, workspace, "move");
}