Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/sway/tree/workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions sway/commands/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions sway/config/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -1088,6 +1089,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();
Expand Down
10 changes: 5 additions & 5 deletions sway/tree/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
}
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");

Expand Down
31 changes: 31 additions & 0 deletions sway/tree/workspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -985,3 +985,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);
}
}
}