Merge pull request #4136 from Roc25/special-centered
hyprland workspaces: Add sorting Special Centered
This commit is contained in:
@ -51,6 +51,7 @@ class Workspaces : public AModule, public EventHandler {
|
||||
private:
|
||||
void onEvent(const std::string& e) override;
|
||||
void updateWindowCount();
|
||||
void sortSpecialCentered();
|
||||
void sortWorkspaces();
|
||||
void createWorkspace(Json::Value const& workspace_data,
|
||||
Json::Value const& clients_data = Json::Value::nullRef);
|
||||
@ -132,12 +133,13 @@ class Workspaces : public AModule, public EventHandler {
|
||||
// and doesn't share windows across bars (a.k.a `all-outputs` = false)
|
||||
std::map<WindowAddress, std::string> m_orphanWindowMap;
|
||||
|
||||
enum class SortMethod { ID, NAME, NUMBER, DEFAULT };
|
||||
enum class SortMethod { ID, NAME, NUMBER, SPECIAL_CENTERED, DEFAULT };
|
||||
util::EnumParser<SortMethod> m_enumParser;
|
||||
SortMethod m_sortBy = SortMethod::DEFAULT;
|
||||
std::map<std::string, SortMethod> m_sortMap = {{"ID", SortMethod::ID},
|
||||
{"NAME", SortMethod::NAME},
|
||||
{"NUMBER", SortMethod::NUMBER},
|
||||
{"SPECIAL-CENTERED", SortMethod::SPECIAL_CENTERED},
|
||||
{"DEFAULT", SortMethod::DEFAULT}};
|
||||
|
||||
std::string m_format;
|
||||
|
@ -81,6 +81,7 @@ Addressed by *hyprland/workspaces*
|
||||
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 set to special-centered, workspaces will sort by default with special workspaces in the center.
|
||||
If none of those, workspaces will sort with default behavior.
|
||||
|
||||
*expand*: ++
|
||||
|
@ -771,7 +771,45 @@ void Workspaces::setCurrentMonitorId() {
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::sortSpecialCentered() {
|
||||
std::vector<std::unique_ptr<Workspace>> specialWorkspaces;
|
||||
std::vector<std::unique_ptr<Workspace>> hiddenWorkspaces;
|
||||
std::vector<std::unique_ptr<Workspace>> normalWorkspaces;
|
||||
|
||||
for (auto &workspace : m_workspaces) {
|
||||
if (workspace->isSpecial()) {
|
||||
specialWorkspaces.push_back(std::move(workspace));
|
||||
} else {
|
||||
if (workspace->button().is_visible()) {
|
||||
normalWorkspaces.push_back(std::move(workspace));
|
||||
} else {
|
||||
hiddenWorkspaces.push_back(std::move(workspace));
|
||||
}
|
||||
}
|
||||
}
|
||||
m_workspaces.clear();
|
||||
|
||||
size_t center = normalWorkspaces.size() / 2;
|
||||
|
||||
m_workspaces.insert(m_workspaces.end(),
|
||||
std::make_move_iterator(normalWorkspaces.begin()),
|
||||
std::make_move_iterator(normalWorkspaces.begin() + center));
|
||||
|
||||
m_workspaces.insert(m_workspaces.end(),
|
||||
std::make_move_iterator(specialWorkspaces.begin()),
|
||||
std::make_move_iterator(specialWorkspaces.end()));
|
||||
|
||||
m_workspaces.insert(m_workspaces.end(),
|
||||
std::make_move_iterator(normalWorkspaces.begin() + center),
|
||||
std::make_move_iterator(normalWorkspaces.end()));
|
||||
|
||||
m_workspaces.insert(m_workspaces.end(),
|
||||
std::make_move_iterator(hiddenWorkspaces.begin()),
|
||||
std::make_move_iterator(hiddenWorkspaces.end()));
|
||||
}
|
||||
|
||||
void Workspaces::sortWorkspaces() {
|
||||
|
||||
std::ranges::sort( //
|
||||
m_workspaces, [&](std::unique_ptr<Workspace> &a, std::unique_ptr<Workspace> &b) {
|
||||
// Helper comparisons
|
||||
@ -829,6 +867,9 @@ void Workspaces::sortWorkspaces() {
|
||||
// Return a default value if none of the cases match.
|
||||
return isNameLess; // You can adjust this to your specific needs.
|
||||
});
|
||||
if (m_sortBy == SortMethod::SPECIAL_CENTERED) {
|
||||
this->sortSpecialCentered();
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m_workspaces.size(); ++i) {
|
||||
m_box.reorder_child(m_workspaces[i]->button(), i);
|
||||
|
Reference in New Issue
Block a user