stabilize window module

This commit is contained in:
vaxerski 2022-08-17 21:54:23 +02:00
parent 17b60bc737
commit c64058c947
2 changed files with 19 additions and 9 deletions

View File

@ -14,9 +14,12 @@ public:
Window(const std::string&, const waybar::Bar&, const Json::Value&); Window(const std::string&, const waybar::Bar&, const Json::Value&);
~Window() = default; ~Window() = default;
auto update() -> void;
private: private:
void onEvent(const std::string&); void onEvent(const std::string&);
std::mutex mutex_;
const Bar& bar_; const Bar& bar_;
util::JsonParser parser_; util::JsonParser parser_;
std::string lastView; std::string lastView;

View File

@ -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); }); 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) { 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); auto windowName = ev.substr(ev.find_first_of(',') + 1).substr(0, 256);
// fix ampersands
auto replaceAll = [](std::string str, const std::string& from, auto replaceAll = [](std::string str, const std::string& from,
const std::string& to) -> std::string { const std::string& to) -> std::string {
size_t start_pos = 0; size_t start_pos = 0;
@ -42,13 +56,6 @@ void Window::onEvent(const std::string& ev) {
spdlog::debug("hyprland window onevent with {}", windowName); spdlog::debug("hyprland window onevent with {}", windowName);
if (!format_.empty()) { dp.emit();
label_.show();
label_.set_markup(fmt::format(format_, windowName));
} else {
label_.hide();
}
ALabel::update();
} }
} }