Re-evaluate default_orientation auto when workspaces change outputs

Workspaces created with default_orientation auto now re-orient when
moved to a different output, evacuated on disconnect, restored on
reconnect, or when output mode/transform changes.
This commit is contained in:
Milad Alizadeh 2026-02-22 18:18:22 +00:00
parent fa497964fd
commit 19f9dbc49a
No known key found for this signature in database
5 changed files with 44 additions and 5 deletions

View file

@ -157,4 +157,6 @@ size_t workspace_num_sticky_containers(struct sway_workspace *ws);
*/
void workspace_squash(struct sway_workspace *workspace);
void workspace_reorient_auto(struct sway_workspace *ws);
#endif

View file

@ -641,6 +641,7 @@ static void workspace_move_to_output(struct sway_workspace *workspace,
}
output_add_workspace(output, workspace);
workspace_reorient_auto(workspace);
// If moving the last workspace from the old output, create a new workspace
// on the old output

View file

@ -21,6 +21,7 @@
#include "sway/server.h"
#include "sway/tree/arrange.h"
#include "sway/tree/root.h"
#include "sway/tree/workspace.h"
#include "log.h"
#include "util.h"
@ -1086,6 +1087,10 @@ static bool apply_resolved_output_configs(struct matched_output_config *configs,
struct matched_output_config *cfg = &configs[idx];
output_update_position(cfg->output);
arrange_layers(cfg->output);
for (int i = 0; i < cfg->output->workspaces->length; i++) {
struct sway_workspace *ws = cfg->output->workspaces->items[i];
workspace_reorient_auto(ws);
}
}
arrange_root();

View file

@ -41,6 +41,7 @@ static void restore_workspaces(struct sway_output *output) {
if (highest == output) {
workspace_detach(ws);
output_add_workspace(output, ws);
workspace_reorient_auto(ws);
ipc_event_workspace(NULL, ws, "move");
j--;
}
@ -59,6 +60,7 @@ static void restore_workspaces(struct sway_output *output) {
struct sway_workspace *ws = root->fallback_output->workspaces->items[0];
workspace_detach(ws);
output_add_workspace(output, ws);
workspace_reorient_auto(ws);
// If the floater was made floating while on the NOOP output, its width
// and height will be zero and it should be reinitialized as a floating
@ -172,11 +174,8 @@ void output_enable(struct sway_output *output) {
ipc_event_workspace(NULL, ws, "init");
}
if (ws && config->default_orientation == L_NONE) {
// Since the output transformation and resolution could have changed
// due to applying the output config, the previously set layout for the
// created workspace may not be correct for `default_orientation auto`
ws->layout = output_get_default_layout(output);
if (ws) {
workspace_reorient_auto(ws);
}
wl_signal_emit_mutable(&root->events.new_node, &output->node);
@ -241,6 +240,7 @@ static void output_evacuate(struct sway_output *output) {
workspace_output_add_priority(workspace, new_output);
output_add_workspace(new_output, workspace);
workspace_reorient_auto(workspace);
output_sort_workspaces(new_output);
ipc_event_workspace(NULL, workspace, "move");

View file

@ -979,3 +979,34 @@ void workspace_squash(struct sway_workspace *workspace) {
i += container_squash(child);
}
}
void workspace_reorient_auto(struct sway_workspace *ws) {
if (config->default_orientation != L_NONE) {
return;
}
if (!ws->output) {
return;
}
if (ws->tiling->length > 1) {
return;
}
if (ws->layout == L_TABBED || ws->layout == L_STACKED) {
return;
}
enum sway_container_layout new_layout = output_get_default_layout(ws->output);
if (ws->layout == new_layout) {
return;
}
ws->layout = new_layout;
workspace_update_representation(ws);
if (ws->tiling->length == 1) {
struct sway_container *child = ws->tiling->items[0];
if (!child->view &&
(child->pending.layout == L_HORIZ || child->pending.layout == L_VERT)) {
child->pending.layout = new_layout;
container_update_representation(child);
}
}
}