From 99e17d5efb28cf1017743a709aa28f2e0177f43f Mon Sep 17 00:00:00 2001 From: Milad Alizadeh Date: Wed, 18 Feb 2026 16:32:11 +0000 Subject: [PATCH 1/2] tree/workspace: fix output priority in workspace assignment workspace_valid_on_output() and workspace_next_name() check whether an output appears anywhere in a workspace's output list, ignoring priority order. This allows a lower-priority output to claim a workspace even when a higher-priority output is available. Fix by stopping early when iterating the output list: if a different available output is found before the current one, the workspace belongs to that higher-priority output. --- sway/tree/workspace.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 733a002b4..9a8e53d25 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -205,6 +205,9 @@ static bool workspace_valid_on_output(const char *output_name, if (output_match_name_or_id(output, wsc->outputs->items[i])) { return true; } + if (output_by_name_or_id(wsc->outputs->items[i])) { + return false; // a higher-priority output is available + } } return false; @@ -326,6 +329,9 @@ char *workspace_next_name(const char *output_name) { target = strdup(wsc->workspace); break; } + if (output_by_name_or_id(wsc->outputs->items[j])) { + break; // a higher-priority output is available + } } if (found) { break; From f66b69762d6844cee473c591dbf3789800ecb785 Mon Sep 17 00:00:00 2001 From: Milad Alizadeh Date: Fri, 20 Feb 2026 21:49:14 +0000 Subject: [PATCH 2/2] simplify output priority check --- sway/tree/workspace.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 9a8e53d25..49a830e7f 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -202,11 +202,10 @@ static bool workspace_valid_on_output(const char *output_name, } for (int i = 0; i < wsc->outputs->length; i++) { - if (output_match_name_or_id(output, wsc->outputs->items[i])) { - return true; - } - if (output_by_name_or_id(wsc->outputs->items[i])) { - return false; // a higher-priority output is available + struct sway_output *ws_output = + output_by_name_or_id(wsc->outputs->items[i]); + if (ws_output) { + return ws_output == output; } } @@ -323,15 +322,16 @@ char *workspace_next_name(const char *output_name) { } bool found = false; for (int j = 0; j < wsc->outputs->length; ++j) { - if (output_match_name_or_id(output, wsc->outputs->items[j])) { - found = true; - free(target); - target = strdup(wsc->workspace); + struct sway_output *ws_output = + output_by_name_or_id(wsc->outputs->items[j]); + if (ws_output) { + if (ws_output == output) { + found = true; + free(target); + target = strdup(wsc->workspace); + } break; } - if (output_by_name_or_id(wsc->outputs->items[j])) { - break; // a higher-priority output is available - } } if (found) { break;