Skip to content

Commit 1b2d552

Browse files
committed
hyprland/workspaces: allow sorting by 'output'
1 parent 559079e commit 1b2d552

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

include/modules/hyprland/workspaces.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,14 @@ class Workspaces : public AModule, public EventHandler {
152152
// and doesn't share windows across bars (a.k.a `all-outputs` = false)
153153
std::map<WindowAddress, WindowRepr, std::less<>> m_orphanWindowMap;
154154

155-
enum class SortMethod { ID, NAME, NUMBER, SPECIAL_CENTERED, DEFAULT };
155+
enum class SortMethod { ID, NAME, NUMBER, SPECIAL_CENTERED, OUTPUT, DEFAULT };
156156
util::EnumParser<SortMethod> m_enumParser;
157157
SortMethod m_sortBy = SortMethod::DEFAULT;
158158
std::map<std::string, SortMethod> m_sortMap = {{"ID", SortMethod::ID},
159159
{"NAME", SortMethod::NAME},
160160
{"NUMBER", SortMethod::NUMBER},
161161
{"SPECIAL-CENTERED", SortMethod::SPECIAL_CENTERED},
162+
{"OUTPUT", SortMethod::OUTPUT},
162163
{"DEFAULT", SortMethod::DEFAULT}};
163164

164165
std::string m_formatBefore;

man/waybar-hyprland-workspaces.5.scd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ This setting is ignored if *workspace-taskbar.enable* is set to true.
142142
If set to name, workspaces will sort by name.
143143
If set to id, workspaces will sort by id.
144144
If set to special-centered, workspaces will sort by default with special workspaces in the center.
145+
If set to output, workspaces will sort by the output (monitor) name.
145146
If none of those, workspaces will sort with default behavior.
146147

147148
*expand*: ++

src/modules/hyprland/workspaces.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,12 +925,15 @@ void Workspaces::sortWorkspaces() {
925925
// Helper comparisons
926926
auto isIdLess = a->id() < b->id();
927927
auto isNameLess = a->name() < b->name();
928+
auto isOutputLess = a->output() < b->output();
928929

929930
switch (m_sortBy) {
930931
case SortMethod::ID:
931932
return isIdLess;
932933
case SortMethod::NAME:
933934
return isNameLess;
935+
case SortMethod::OUTPUT:
936+
return isOutputLess;
934937
case SortMethod::NUMBER:
935938
try {
936939
return std::stoi(a->name()) < std::stoi(b->name());
@@ -1146,4 +1149,4 @@ std::optional<int> Workspaces::parseWorkspaceId(std::string const &workspaceIdSt
11461149
}
11471150
}
11481151

1149-
} // namespace waybar::modules::hyprland
1152+
} // namespace waybar::modules::hyprland

0 commit comments

Comments
 (0)