mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
minor changes
This commit is contained in:
parent
c1f92d2a3c
commit
17b60bc737
@ -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;
|
||||||
|
@ -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) {
|
||||||
if (it != workspaces.end())
|
|
||||||
workspaces.erase(it);
|
workspaces.erase(it);
|
||||||
|
break;
|
||||||
// also remove the buttons
|
}
|
||||||
buttons_.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
mutex_.unlock();
|
||||||
|
|
||||||
|
dp.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Workspaces::handleScroll(GdkEventScroll *e) {
|
bool Workspaces::handleScroll(GdkEventScroll *e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user