Merge pull request #4685 from AckslD/no-switch-output

feat: allow not switching output when clicking sway/workspace
This commit is contained in:
Alexis Rouillard
2026-07-04 00:53:26 +02:00
committed by GitHub
2 changed files with 17 additions and 7 deletions
+4
View File
@@ -88,6 +88,10 @@ Addressed by *sway/workspaces*
typeof: bool ++ typeof: bool ++
Whether to disable *workspace_auto_back_and_forth* when clicking on workspaces. If this is set to *true*, clicking on a workspace you are already on won't do anything, even if *workspace_auto_back_and_forth* is enabled in the Sway configuration. Whether to disable *workspace_auto_back_and_forth* when clicking on workspaces. If this is set to *true*, clicking on a workspace you are already on won't do anything, even if *workspace_auto_back_and_forth* is enabled in the Sway configuration.
*no-switch-output*: ++
typeof: bool ++
Whether to disable switching output when clicking on workspaces. If this is set to *true*, then clicking on a workspace on a different output will bring it to the current output instead of switching to that output.
*alphabetical_sort*: ++ *alphabetical_sort*: ++
typeof: bool ++ typeof: bool ++
Whether to sort workspaces alphabetically. Please note this can make "swaymsg workspace prev/next" move to workspaces inconsistent with the ordering shown in Waybar. Whether to sort workspaces alphabetically. Please note this can make "swaymsg workspace prev/next" move to workspaces inconsistent with the ordering shown in Waybar.
+13 -7
View File
@@ -359,7 +359,7 @@ auto Workspaces::update() -> void {
if ((*it)["output"].isString()) { if ((*it)["output"].isString()) {
// Simply attempt to remove all output classes every time to reset output classes. This works // Simply attempt to remove all output classes every time to reset output classes. This works
// even if a class has not been previously added to the style context. // even if a class has not been previously added to the style context.
for (const auto &oclass : config_["output-classes"]) { for (const auto& oclass : config_["output-classes"]) {
button.get_style_context()->remove_class(oclass.asString()); button.get_style_context()->remove_class(oclass.asString());
} }
// If output-classes contains a class for output associated with current workspace button, add // If output-classes contains a class for output associated with current workspace button, add
@@ -437,13 +437,19 @@ Gtk::Button& Workspaces::addButton(const Json::Value& node) {
node["name"].asString(), node["target_output"].asString(), node["name"].asString(), node["target_output"].asString(),
"--no-auto-back-and-forth", node["name"].asString())); "--no-auto-back-and-forth", node["name"].asString()));
} else { } else {
std::string flag = config_["disable-auto-back-and-forth"].asBool() std::string flag =
? "--no-auto-back-and-forth" config_["disable-auto-back-and-forth"].asBool() ? "--no-auto-back-and-forth" : "";
: ""; if (config_["no-switch-output"].asBool()) {
if (node["num"].asInt() >= 0) { ipc_.sendCmd(IPC_COMMAND,
ipc_.sendCmd(IPC_COMMAND, fmt::format(workspace_switch_number_cmd_, flag, node["num"].asInt())); fmt::format("[workspace=\"^{}$\"] move workspace to output current; "
"workspace number {} \"{}\"",
node["name"].asString(), flag, node["name"].asString()));
} else if (node["num"].asInt() >= 0) {
ipc_.sendCmd(IPC_COMMAND,
fmt::format(workspace_switch_number_cmd_, flag, node["num"].asInt()));
} else { } else {
ipc_.sendCmd(IPC_COMMAND, fmt::format(workspace_switch_cmd_, flag, node["name"].asString())); ipc_.sendCmd(IPC_COMMAND,
fmt::format(workspace_switch_cmd_, flag, node["name"].asString()));
} }
} }
} catch (const std::exception& e) { } catch (const std::exception& e) {