minor changes
parent
c1f92d2a3c
commit
17b60bc737
|
@ -32,6 +32,8 @@ class Workspaces : public AModule, public sigc::trackable {
|
|||
|
||||
bool isNumber(const std::string&);
|
||||
|
||||
bool needReorder = false;
|
||||
|
||||
Gtk::Box box_;
|
||||
const Bar& bar_;
|
||||
std::deque<std::string> workspaces;
|
||||
|
|
|
@ -118,6 +118,9 @@ void Workspaces::updateButtons() {
|
|||
for (auto it = ws.begin(); it != ws.end(); ++it) {
|
||||
auto bit = buttons_.find(*it);
|
||||
|
||||
if (bit == buttons_.end())
|
||||
needReorder = true;
|
||||
|
||||
auto &button = bit == buttons_.end() ? addButton(*it) : bit->second;
|
||||
|
||||
if (focusedWorkspace == *it) {
|
||||
|
@ -132,6 +135,10 @@ void Workspaces::updateButtons() {
|
|||
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.show();
|
||||
|
@ -139,6 +146,8 @@ void Workspaces::updateButtons() {
|
|||
|
||||
AModule::update();
|
||||
|
||||
needReorder = false;
|
||||
|
||||
mutex_.unlock();
|
||||
}
|
||||
|
||||
|
@ -183,22 +192,28 @@ void Workspaces::onEvent(const std::string& ev) {
|
|||
focusedWorkspace = WORKSPACE;
|
||||
} else if (EVENT == "createworkspace") {
|
||||
workspaces.emplace_back(WORKSPACE);
|
||||
|
||||
// remove the buttons for reorder
|
||||
buttons_.clear();
|
||||
} else {
|
||||
const auto it = std::remove(workspaces.begin(), workspaces.end(), WORKSPACE);
|
||||
|
||||
if (it != workspaces.end())
|
||||
for (auto it = workspaces.begin(); it != workspaces.end(); it++) {
|
||||
if (*it == WORKSPACE) {
|
||||
workspaces.erase(it);
|
||||
|
||||
// also remove the buttons
|
||||
buttons_.clear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
dp.emit();
|
||||
// also remove the button
|
||||
for (auto it = buttons_.begin(); it != buttons_.end(); it++) {
|
||||
if (it->second.get_name() == WORKSPACE)
|
||||
it = buttons_.erase(it);
|
||||
|
||||
if (it == buttons_.end())
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mutex_.unlock();
|
||||
|
||||
dp.emit();
|
||||
}
|
||||
|
||||
bool Workspaces::handleScroll(GdkEventScroll *e) {
|
||||
|
|
Loading…
Reference in New Issue