From 8ce33e0c64f610209dd7ecd1b7fa9b7d65068c8c Mon Sep 17 00:00:00 2001 From: Alexis Date: Sun, 19 Aug 2018 20:37:33 +0200 Subject: [PATCH] fix(window): pick only con title --- include/util/chrono.hpp | 7 +++++++ src/modules/battery.cpp | 2 +- src/modules/clock.cpp | 2 +- src/modules/cpu.cpp | 2 +- src/modules/custom.cpp | 2 +- src/modules/memory.cpp | 2 +- src/modules/network.cpp | 2 +- src/modules/sway/window.cpp | 4 ++-- src/modules/sway/workspaces.cpp | 2 +- 9 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/util/chrono.hpp b/include/util/chrono.hpp index a361d64c..e12a9a86 100644 --- a/include/util/chrono.hpp +++ b/include/util/chrono.hpp @@ -70,6 +70,13 @@ struct SleeperThread { condvar_.notify_all(); } + void emit() + { + Glib::signal_idle().connect_once([this] { + sig_update.emit(); + }); + } + ~SleeperThread() { do_run_ = false; diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index ea9d02d2..715af3fd 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -33,7 +33,7 @@ waybar::modules::Battery::Battery(Json::Value config) if (nbytes != sizeof(event)) { return; } - thread_.sig_update.emit(); + thread_.emit(); }; } diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 190df873..3fd3b58d 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -8,7 +8,7 @@ waybar::modules::Clock::Clock(Json::Value config) thread_.sig_update.connect(sigc::mem_fun(*this, &Clock::update)); thread_ = [this, interval] { auto now = waybar::chrono::clock::now(); - thread_.sig_update.emit(); + thread_.emit(); auto timeout = std::chrono::floor(now + std::chrono::seconds(interval)); thread_.sleep_until(timeout); diff --git a/src/modules/cpu.cpp b/src/modules/cpu.cpp index 6ff37364..6c9e4858 100644 --- a/src/modules/cpu.cpp +++ b/src/modules/cpu.cpp @@ -7,7 +7,7 @@ waybar::modules::Cpu::Cpu(Json::Value config) uint32_t interval = config_["interval"] ? config_["inveral"].asUInt() : 10; thread_.sig_update.connect(sigc::mem_fun(*this, &Cpu::update)); thread_ = [this, interval] { - thread_.sig_update.emit(); + thread_.emit(); thread_.sleep_for(chrono::seconds(interval)); }; } diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index a1061f54..19c6bea7 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -16,7 +16,7 @@ waybar::modules::Custom::Custom(std::string name, Json::Value config) } } if (can_update) { - thread_.sig_update.emit(); + thread_.emit(); } thread_.sleep_for(chrono::seconds(interval)); }; diff --git a/src/modules/memory.cpp b/src/modules/memory.cpp index 39d23700..668ebf48 100644 --- a/src/modules/memory.cpp +++ b/src/modules/memory.cpp @@ -7,7 +7,7 @@ waybar::modules::Memory::Memory(Json::Value config) uint32_t interval = config_["interval"] ? config_["inveral"].asUInt() : 30; thread_.sig_update.connect(sigc::mem_fun(*this, &Memory::update)); thread_ = [this, interval] { - thread_.sig_update.emit(); + thread_.emit(); thread_.sleep_for(chrono::seconds(interval)); }; } diff --git a/src/modules/network.cpp b/src/modules/network.cpp index 28effcaf..b37ec29f 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -69,7 +69,7 @@ waybar::modules::Network::Network(Json::Value config) } if (need_update) { getInfo(); - thread_.sig_update.emit(); + thread_.emit(); } }; } diff --git a/src/modules/sway/window.cpp b/src/modules/sway/window.cpp index aba6e24b..a2e3e4a7 100644 --- a/src/modules/sway/window.cpp +++ b/src/modules/sway/window.cpp @@ -18,7 +18,7 @@ waybar::modules::sway::Window::Window(Bar &bar, Json::Value config) if ((parsed["change"] == "focus" || parsed["change"] == "title") && parsed["container"]["focused"].asBool()) { window_ = parsed["container"]["name"].asString(); - thread_.sig_update.emit(); + thread_.emit(); } } catch (const std::exception& e) { std::cerr << e.what() << std::endl; @@ -41,7 +41,7 @@ auto waybar::modules::sway::Window::update() -> void std::string waybar::modules::sway::Window::getFocusedNode(Json::Value nodes) { for (auto &node : nodes) { - if (node["focused"].asBool()) { + if (node["focused"].asBool() && node["type"] == "con") { return node["name"].asString(); } auto res = getFocusedNode(node["nodes"]); diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index 3b702bcb..e65e8862 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -20,7 +20,7 @@ waybar::modules::sway::Workspaces::Workspaces(Bar &bar, Json::Value config) } else if (!workspaces_.empty()) { ipcRecvResponse(ipc_eventfd_); } - thread_.sig_update.emit(); + thread_.emit(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; }