Add sorting with centered special workspaces
This commit is contained in:
@ -50,6 +50,7 @@ class Workspaces : public AModule, public EventHandler {
|
|||||||
private:
|
private:
|
||||||
void onEvent(const std::string& e) override;
|
void onEvent(const std::string& e) override;
|
||||||
void updateWindowCount();
|
void updateWindowCount();
|
||||||
|
void sortSpecialCentered();
|
||||||
void sortWorkspaces();
|
void sortWorkspaces();
|
||||||
void createWorkspace(Json::Value const& workspace_data,
|
void createWorkspace(Json::Value const& workspace_data,
|
||||||
Json::Value const& clients_data = Json::Value::nullRef);
|
Json::Value const& clients_data = Json::Value::nullRef);
|
||||||
@ -130,12 +131,13 @@ class Workspaces : public AModule, public EventHandler {
|
|||||||
// and doesn't share windows accross bars (a.k.a `all-outputs` = false)
|
// and doesn't share windows accross bars (a.k.a `all-outputs` = false)
|
||||||
std::map<WindowAddress, std::string> m_orphanWindowMap;
|
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;
|
util::EnumParser<SortMethod> m_enumParser;
|
||||||
SortMethod m_sortBy = SortMethod::DEFAULT;
|
SortMethod m_sortBy = SortMethod::DEFAULT;
|
||||||
std::map<std::string, SortMethod> m_sortMap = {{"ID", SortMethod::ID},
|
std::map<std::string, SortMethod> m_sortMap = {{"ID", SortMethod::ID},
|
||||||
{"NAME", SortMethod::NAME},
|
{"NAME", SortMethod::NAME},
|
||||||
{"NUMBER", SortMethod::NUMBER},
|
{"NUMBER", SortMethod::NUMBER},
|
||||||
|
{"SPECIAL-CENTERED", SortMethod::SPECIAL_CENTERED},
|
||||||
{"DEFAULT", SortMethod::DEFAULT}};
|
{"DEFAULT", SortMethod::DEFAULT}};
|
||||||
|
|
||||||
std::string m_format;
|
std::string m_format;
|
||||||
|
@ -770,7 +770,36 @@ void Workspaces::setCurrentMonitorId() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Workspaces::sortSpecialCentered() {
|
||||||
|
std::vector<std::unique_ptr<Workspace>> specialWorkspaces;
|
||||||
|
std::vector<std::unique_ptr<Workspace>> normalWorkspaces;
|
||||||
|
|
||||||
|
for (auto &workspace : m_workspaces) {
|
||||||
|
if (workspace->isSpecial()) {
|
||||||
|
specialWorkspaces.push_back(std::move(workspace));
|
||||||
|
} else {
|
||||||
|
normalWorkspaces.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()));
|
||||||
|
}
|
||||||
|
|
||||||
void Workspaces::sortWorkspaces() {
|
void Workspaces::sortWorkspaces() {
|
||||||
|
|
||||||
std::ranges::sort( //
|
std::ranges::sort( //
|
||||||
m_workspaces, [&](std::unique_ptr<Workspace> &a, std::unique_ptr<Workspace> &b) {
|
m_workspaces, [&](std::unique_ptr<Workspace> &a, std::unique_ptr<Workspace> &b) {
|
||||||
// Helper comparisons
|
// Helper comparisons
|
||||||
@ -828,6 +857,9 @@ void Workspaces::sortWorkspaces() {
|
|||||||
// Return a default value if none of the cases match.
|
// Return a default value if none of the cases match.
|
||||||
return isNameLess; // You can adjust this to your specific needs.
|
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) {
|
for (size_t i = 0; i < m_workspaces.size(); ++i) {
|
||||||
m_box.reorder_child(m_workspaces[i]->button(), i);
|
m_box.reorder_child(m_workspaces[i]->button(), i);
|
||||||
|
Reference in New Issue
Block a user