fix(window): pick only con title

pull/31/head
Alexis 2018-08-19 20:37:33 +02:00
parent 969c1ceedd
commit 8ce33e0c64
9 changed files with 16 additions and 9 deletions

View File

@ -70,6 +70,13 @@ struct SleeperThread {
condvar_.notify_all(); condvar_.notify_all();
} }
void emit()
{
Glib::signal_idle().connect_once([this] {
sig_update.emit();
});
}
~SleeperThread() ~SleeperThread()
{ {
do_run_ = false; do_run_ = false;

View File

@ -33,7 +33,7 @@ waybar::modules::Battery::Battery(Json::Value config)
if (nbytes != sizeof(event)) { if (nbytes != sizeof(event)) {
return; return;
} }
thread_.sig_update.emit(); thread_.emit();
}; };
} }

View File

@ -8,7 +8,7 @@ waybar::modules::Clock::Clock(Json::Value config)
thread_.sig_update.connect(sigc::mem_fun(*this, &Clock::update)); thread_.sig_update.connect(sigc::mem_fun(*this, &Clock::update));
thread_ = [this, interval] { thread_ = [this, interval] {
auto now = waybar::chrono::clock::now(); auto now = waybar::chrono::clock::now();
thread_.sig_update.emit(); thread_.emit();
auto timeout = std::chrono::floor<std::chrono::seconds>(now auto timeout = std::chrono::floor<std::chrono::seconds>(now
+ std::chrono::seconds(interval)); + std::chrono::seconds(interval));
thread_.sleep_until(timeout); thread_.sleep_until(timeout);

View File

@ -7,7 +7,7 @@ waybar::modules::Cpu::Cpu(Json::Value config)
uint32_t interval = config_["interval"] ? config_["inveral"].asUInt() : 10; uint32_t interval = config_["interval"] ? config_["inveral"].asUInt() : 10;
thread_.sig_update.connect(sigc::mem_fun(*this, &Cpu::update)); thread_.sig_update.connect(sigc::mem_fun(*this, &Cpu::update));
thread_ = [this, interval] { thread_ = [this, interval] {
thread_.sig_update.emit(); thread_.emit();
thread_.sleep_for(chrono::seconds(interval)); thread_.sleep_for(chrono::seconds(interval));
}; };
} }

View File

@ -16,7 +16,7 @@ waybar::modules::Custom::Custom(std::string name, Json::Value config)
} }
} }
if (can_update) { if (can_update) {
thread_.sig_update.emit(); thread_.emit();
} }
thread_.sleep_for(chrono::seconds(interval)); thread_.sleep_for(chrono::seconds(interval));
}; };

View File

@ -7,7 +7,7 @@ waybar::modules::Memory::Memory(Json::Value config)
uint32_t interval = config_["interval"] ? config_["inveral"].asUInt() : 30; uint32_t interval = config_["interval"] ? config_["inveral"].asUInt() : 30;
thread_.sig_update.connect(sigc::mem_fun(*this, &Memory::update)); thread_.sig_update.connect(sigc::mem_fun(*this, &Memory::update));
thread_ = [this, interval] { thread_ = [this, interval] {
thread_.sig_update.emit(); thread_.emit();
thread_.sleep_for(chrono::seconds(interval)); thread_.sleep_for(chrono::seconds(interval));
}; };
} }

View File

@ -69,7 +69,7 @@ waybar::modules::Network::Network(Json::Value config)
} }
if (need_update) { if (need_update) {
getInfo(); getInfo();
thread_.sig_update.emit(); thread_.emit();
} }
}; };
} }

View File

@ -18,7 +18,7 @@ waybar::modules::sway::Window::Window(Bar &bar, Json::Value config)
if ((parsed["change"] == "focus" || parsed["change"] == "title") if ((parsed["change"] == "focus" || parsed["change"] == "title")
&& parsed["container"]["focused"].asBool()) { && parsed["container"]["focused"].asBool()) {
window_ = parsed["container"]["name"].asString(); window_ = parsed["container"]["name"].asString();
thread_.sig_update.emit(); thread_.emit();
} }
} catch (const std::exception& e) { } catch (const std::exception& e) {
std::cerr << e.what() << std::endl; 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) std::string waybar::modules::sway::Window::getFocusedNode(Json::Value nodes)
{ {
for (auto &node : nodes) { for (auto &node : nodes) {
if (node["focused"].asBool()) { if (node["focused"].asBool() && node["type"] == "con") {
return node["name"].asString(); return node["name"].asString();
} }
auto res = getFocusedNode(node["nodes"]); auto res = getFocusedNode(node["nodes"]);

View File

@ -20,7 +20,7 @@ waybar::modules::sway::Workspaces::Workspaces(Bar &bar, Json::Value config)
} else if (!workspaces_.empty()) { } else if (!workspaces_.empty()) {
ipcRecvResponse(ipc_eventfd_); ipcRecvResponse(ipc_eventfd_);
} }
thread_.sig_update.emit(); thread_.emit();
} catch (const std::exception& e) { } catch (const std::exception& e) {
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
} }