Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to wlr/workspaces to sort workspaces by number #1721

Merged
merged 5 commits into from
Oct 19, 2022
Merged
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
1 change: 1 addition & 0 deletions include/modules/wlr/workspace_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class WorkspaceManager : public AModule {

bool sort_by_name_ = true;
bool sort_by_coordinates_ = true;
bool sort_by_number_ = false;
bool all_outputs_ = false;
bool active_only_ = false;
bool creation_delayed_ = false;
Expand Down
8 changes: 7 additions & 1 deletion man/waybar-wlr-workspaces.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ Addressed by *wlr/workspaces*
Note that if both *sort-by-name* and *sort-by-coordinates* are true sort by name will be first.
If both are false - sort by id will be performed.

*sort-by-number*: ++
typeof: bool ++
default: false ++
If set to true, workspace names will be sorted numerically. Takes presedence over any other sort-by option.

*all-outputs*: ++
typeof: bool ++
default: false ++
Expand Down Expand Up @@ -75,7 +80,8 @@ Additional to workspace name matching, the following *format-icons* can be set.
"5": "",
"focused": "",
"default": ""
}
},
"sort-by-number": true
}
```

Expand Down
11 changes: 11 additions & 0 deletions src/modules/wlr/workspace_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ WorkspaceManager::WorkspaceManager(const std::string &id, const waybar::Bar &bar
sort_by_coordinates_ = config_sort_by_coordinates.asBool();
}

auto config_sort_by_number = config_["sort-by-number"];
if (config_sort_by_number.isBool()) {
sort_by_number_ = config_sort_by_number.asBool();
}

auto config_all_outputs = config_["all-outputs"];
if (config_all_outputs.isBool()) {
all_outputs_ = config_all_outputs.asBool();
Expand Down Expand Up @@ -61,6 +66,12 @@ auto WorkspaceManager::workspace_comparator() const
auto is_name_less = lhs->get_name() < rhs->get_name();
auto is_name_eq = lhs->get_name() == rhs->get_name();
auto is_coords_less = lhs->get_coords() < rhs->get_coords();
auto is_number_less = std::stoi(lhs->get_name()) < std::stoi(rhs->get_name());

if (sort_by_number_) {
return is_number_less;
}

if (sort_by_name_) {
if (sort_by_coordinates_) {
return is_name_eq ? is_coords_less : is_name_less;
Expand Down