feat: hyprland workspaces add sort-by
parent
587bd0cd62
commit
cbc12e5443
|
@ -86,6 +86,7 @@ class Workspaces : public AModule, public EventHandler {
|
||||||
bool all_outputs_ = false;
|
bool all_outputs_ = false;
|
||||||
bool show_special_ = false;
|
bool show_special_ = false;
|
||||||
bool active_only_ = false;
|
bool active_only_ = false;
|
||||||
|
std::string sort_by = "default";
|
||||||
|
|
||||||
void fill_persistent_workspaces();
|
void fill_persistent_workspaces();
|
||||||
void create_persistent_workspaces();
|
void create_persistent_workspaces();
|
||||||
|
|
|
@ -36,6 +36,14 @@ Addressed by *hyprland/workspaces*
|
||||||
default: false ++
|
default: false ++
|
||||||
If set to true, only the active workspace will be shown.
|
If set to true, only the active workspace will be shown.
|
||||||
|
|
||||||
|
*sort-by*: ++
|
||||||
|
typeof: string ++
|
||||||
|
default: "default" ++
|
||||||
|
If set to number, workspaces will sort by number.
|
||||||
|
If set to name, workspaces will sort by name.
|
||||||
|
If set to id, workspaces will sort by id.
|
||||||
|
If none of those, workspaces will sort with default behavior.
|
||||||
|
|
||||||
# FORMAT REPLACEMENTS
|
# FORMAT REPLACEMENTS
|
||||||
|
|
||||||
*{id}*: id of workspace assigned by compositor
|
*{id}*: id of workspace assigned by compositor
|
||||||
|
|
|
@ -421,12 +421,27 @@ void Workspace::update(const std::string &format, const std::string &icon) {
|
||||||
|
|
||||||
void Workspaces::sort_workspaces() {
|
void Workspaces::sort_workspaces() {
|
||||||
std::sort(workspaces_.begin(), workspaces_.end(),
|
std::sort(workspaces_.begin(), workspaces_.end(),
|
||||||
[](std::unique_ptr<Workspace> &a, std::unique_ptr<Workspace> &b) {
|
[&](std::unique_ptr<Workspace> &a, std::unique_ptr<Workspace> &b) {
|
||||||
|
// Helper comparisons
|
||||||
|
auto is_id_less = a->id() < b->id();
|
||||||
|
auto is_name_less = a->name() < b->name();
|
||||||
|
auto is_number_less = std::stoi(a->name()) < std::stoi(b->name());
|
||||||
|
|
||||||
|
if (sort_by == "number") {
|
||||||
|
try {
|
||||||
|
return is_number_less;
|
||||||
|
} catch (const std::invalid_argument &) {
|
||||||
|
}
|
||||||
|
} else if (sort_by == "name") {
|
||||||
|
return is_name_less;
|
||||||
|
} else if (sort_by == "id") {
|
||||||
|
return is_id_less;
|
||||||
|
} else {
|
||||||
// normal -> named persistent -> named -> special -> named special
|
// normal -> named persistent -> named -> special -> named special
|
||||||
|
|
||||||
// both normal (includes numbered persistent) => sort by ID
|
// both normal (includes numbered persistent) => sort by ID
|
||||||
if (a->id() > 0 && b->id() > 0) {
|
if (a->id() > 0 && b->id() > 0) {
|
||||||
return a->id() < b->id();
|
return is_id_less;
|
||||||
}
|
}
|
||||||
|
|
||||||
// one normal, one special => normal first
|
// one normal, one special => normal first
|
||||||
|
@ -445,12 +460,14 @@ void Workspaces::sort_workspaces() {
|
||||||
if (a->id() == -99 || b->id() == -99) {
|
if (a->id() == -99 || b->id() == -99) {
|
||||||
return b->id() == -99;
|
return b->id() == -99;
|
||||||
}
|
}
|
||||||
// both are 0 (not yet named persistents) / both are named specials (-98 <= ID <=-1)
|
// both are 0 (not yet named persistents) / both are named specials (-98 <= ID
|
||||||
return a->name() < b->name();
|
// <=-1)
|
||||||
|
return is_name_less;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort non-special named workspaces by name (ID <= -1377)
|
// sort non-special named workspaces by name (ID <= -1377)
|
||||||
return a->name() < b->name();
|
return is_name_less;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (size_t i = 0; i < workspaces_.size(); ++i) {
|
for (size_t i = 0; i < workspaces_.size(); ++i) {
|
||||||
|
|
Loading…
Reference in New Issue