stabilize window module
parent
17b60bc737
commit
c64058c947
|
@ -14,9 +14,12 @@ public:
|
|||
Window(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
~Window() = default;
|
||||
|
||||
auto update() -> void;
|
||||
|
||||
private:
|
||||
void onEvent(const std::string&);
|
||||
|
||||
std::mutex mutex_;
|
||||
const Bar& bar_;
|
||||
util::JsonParser parser_;
|
||||
std::string lastView;
|
||||
|
|
|
@ -20,10 +20,24 @@ Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
|
|||
gIPC->registerForIPC("activewindow", [&](const std::string& ev) { this->onEvent(ev); });
|
||||
}
|
||||
|
||||
auto Window::update() -> void {
|
||||
// fix ampersands
|
||||
std::lock_guard<std::mutex> lg(mutex_);
|
||||
|
||||
if (!format_.empty()) {
|
||||
label_.show();
|
||||
label_.set_markup(fmt::format(format_, lastView));
|
||||
} else {
|
||||
label_.hide();
|
||||
}
|
||||
|
||||
ALabel::update();
|
||||
}
|
||||
|
||||
void Window::onEvent(const std::string& ev) {
|
||||
std::lock_guard<std::mutex> lg(mutex_);
|
||||
auto windowName = ev.substr(ev.find_first_of(',') + 1).substr(0, 256);
|
||||
|
||||
// fix ampersands
|
||||
auto replaceAll = [](std::string str, const std::string& from,
|
||||
const std::string& to) -> std::string {
|
||||
size_t start_pos = 0;
|
||||
|
@ -42,13 +56,6 @@ void Window::onEvent(const std::string& ev) {
|
|||
|
||||
spdlog::debug("hyprland window onevent with {}", windowName);
|
||||
|
||||
if (!format_.empty()) {
|
||||
label_.show();
|
||||
label_.set_markup(fmt::format(format_, windowName));
|
||||
} else {
|
||||
label_.hide();
|
||||
}
|
||||
|
||||
ALabel::update();
|
||||
dp.emit();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue