hyprland workspaces: Add sorting Special Centered
Closes #4135
Doing the for loop you're moving the workspace you're iterating over. Wouldn't that cause problems?
Doring the for loop you're moving the workspace you're iterating over. Wouldn't that cause problems?
I think it's fine because:
- we have a mutex lock around
doUpdate(), which ensures m_workspaces isn't touched by another thread - we clear m_workspaces right after we made all workspaces nullptrs, so there's no risk of null ptr dereferencing
But I'm still not a big fan of that method, I'm trying to find a safer way to do it
EDIT: I came up with this but I feel like it isn't much better :laughing:
std::vector<size_t> normalIdx;
std::vector<size_t> specialIdx;
std::vector<size_t> hiddenIdx;
for (size_t i = 0; i < m_workspaces.size(); ++i) {
if (m_workspaces[i]->isSpecial()) {
specialIdx.push_back(i);
} else if (m_workspaces[i]->button().is_visible()) {
normalIdx.push_back(i);
} else {
hiddenIdx.push_back(i);
}
}
size_t center = normalIdx.size() / 2;
std::vector<std::unique_ptr<Workspace>> sorted;
sorted.reserve(m_workspaces.size());
auto move_by_indexes = [&](const std::vector<size_t>& idxs) {
for (size_t idx : idxs) {
sorted.push_back(std::move(m_workspaces[idx]));
}
};
move_by_indexes({normalIdx.begin(), normalIdx.begin() + center});
move_by_indexes(specialIdx);
move_by_indexes({normalIdx.begin() + center, normalIdx.end()});
move_by_indexes(hiddenIdx);
m_workspaces = std::move(sorted);
Can you update the docs?
I'll check if I can update the docs if I have some spare time during the weekend, but I don't promise anything
I also update wiki on github