minor changes

This commit is contained in:
vaxerski 2022-07-01 15:35:25 +02:00
parent c1f92d2a3c
commit 17b60bc737
2 changed files with 27 additions and 10 deletions

View File

@ -32,6 +32,8 @@ class Workspaces : public AModule, public sigc::trackable {
bool isNumber(const std::string&); bool isNumber(const std::string&);
bool needReorder = false;
Gtk::Box box_; Gtk::Box box_;
const Bar& bar_; const Bar& bar_;
std::deque<std::string> workspaces; std::deque<std::string> workspaces;

View File

@ -118,6 +118,9 @@ void Workspaces::updateButtons() {
for (auto it = ws.begin(); it != ws.end(); ++it) { for (auto it = ws.begin(); it != ws.end(); ++it) {
auto bit = buttons_.find(*it); auto bit = buttons_.find(*it);
if (bit == buttons_.end())
needReorder = true;
auto &button = bit == buttons_.end() ? addButton(*it) : bit->second; auto &button = bit == buttons_.end() ? addButton(*it) : bit->second;
if (focusedWorkspace == *it) { if (focusedWorkspace == *it) {
@ -132,6 +135,10 @@ void Workspaces::updateButtons() {
label = fmt::format(format, fmt::arg("icon", getIcon(*it)), fmt::arg("name", *it)); label = fmt::format(format, fmt::arg("icon", getIcon(*it)), fmt::arg("name", *it));
} }
if (needReorder) {
box_.reorder_child(button, it - workspaces.begin());
}
button.set_label(label); button.set_label(label);
button.show(); button.show();
@ -139,6 +146,8 @@ void Workspaces::updateButtons() {
AModule::update(); AModule::update();
needReorder = false;
mutex_.unlock(); mutex_.unlock();
} }
@ -183,22 +192,28 @@ void Workspaces::onEvent(const std::string& ev) {
focusedWorkspace = WORKSPACE; focusedWorkspace = WORKSPACE;
} else if (EVENT == "createworkspace") { } else if (EVENT == "createworkspace") {
workspaces.emplace_back(WORKSPACE); workspaces.emplace_back(WORKSPACE);
// remove the buttons for reorder
buttons_.clear();
} else { } else {
const auto it = std::remove(workspaces.begin(), workspaces.end(), WORKSPACE); for (auto it = workspaces.begin(); it != workspaces.end(); it++) {
if (*it == WORKSPACE) {
workspaces.erase(it);
break;
}
}
if (it != workspaces.end()) // also remove the button
workspaces.erase(it); for (auto it = buttons_.begin(); it != buttons_.end(); it++) {
if (it->second.get_name() == WORKSPACE)
it = buttons_.erase(it);
if (it == buttons_.end())
break;
}
// also remove the buttons
buttons_.clear();
} }
dp.emit();
mutex_.unlock(); mutex_.unlock();
dp.emit();
} }
bool Workspaces::handleScroll(GdkEventScroll *e) { bool Workspaces::handleScroll(GdkEventScroll *e) {