From 692541550123e7e4bf9d6028726b3e01223a76db Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Mon, 9 Jan 2017 14:27:55 +0100 Subject: [PATCH] fix(tray): Force bar update on change Refs #295 --- include/components/bar.hpp | 5 +++-- include/components/controller.hpp | 9 +++++---- include/events/signal.hpp | 4 ++-- include/events/signal_fwd.hpp | 2 +- src/components/bar.cpp | 10 +++++----- src/components/controller.cpp | 28 +++++++++++++++++----------- src/x11/tray_manager.cpp | 4 ++-- 7 files changed, 35 insertions(+), 27 deletions(-) diff --git a/include/components/bar.hpp b/include/components/bar.hpp index 5ed59397..d925345c 100644 --- a/include/components/bar.hpp +++ b/include/components/bar.hpp @@ -33,7 +33,8 @@ namespace sig_ev = signals::eventqueue; class bar : public xpp::event::sink, - public signal_receiver { + public signal_receiver { public: using make_type = unique_ptr; static make_type make(bool only_initialize_values = false); @@ -44,7 +45,7 @@ class bar : public xpp::event::sink { + sig_ev::notify_change, sig_ev::notify_forcechange, sig_ev::check_state, sig_ipc::action, + sig_ipc::command, sig_ipc::hook, sig_ui::button_press> { public: using make_type = unique_ptr; static make_type make(unique_ptr&& ipc, unique_ptr&& config_watch); @@ -63,9 +63,10 @@ class controller : public signal_receiver { using base_type::base_type; }; - struct check_state : public detail::base_signal { + struct notify_forcechange : public detail::base_signal { using base_type::base_type; }; - struct update : public detail::base_signal { + struct check_state : public detail::base_signal { using base_type::base_type; }; } diff --git a/include/events/signal_fwd.hpp b/include/events/signal_fwd.hpp index 2b331eea..69969298 100644 --- a/include/events/signal_fwd.hpp +++ b/include/events/signal_fwd.hpp @@ -18,8 +18,8 @@ namespace signals { struct exit_terminate; struct exit_reload; struct notify_change; + struct notify_forcechange; struct check_state; - struct update; } namespace ipc { struct command; diff --git a/src/components/bar.cpp b/src/components/bar.cpp index 96651f95..a323e88e 100644 --- a/src/components/bar.cpp +++ b/src/components/bar.cpp @@ -311,18 +311,18 @@ const bar_settings bar::settings() const { * @param data Input string * @param force Unless true, do not parse unchanged data */ -void bar::parse(string&& data) { +void bar::parse(string&& data, bool force) { if (!m_mutex.try_lock()) { return; } std::lock_guard guard(m_mutex, std::adopt_lock); - if (m_opts.shaded) { + if (force) { + m_log.trace("bar: Force update"); + } else if (m_opts.shaded) { return m_log.trace("bar: Ignoring update (shaded)"); - } - - if (data == m_lastinput) { + } else if (data == m_lastinput) { return; } diff --git a/src/components/controller.cpp b/src/components/controller.cpp index b408f79e..3905f3c7 100644 --- a/src/components/controller.cpp +++ b/src/components/controller.cpp @@ -350,7 +350,7 @@ void controller::process_eventqueue() { } if (evt.type == event_type::UPDATE) { - on(sig_ev::update{}); + process_update(evt.flag); } else if (evt.type == event_type::INPUT) { process_inputdata(); } else if (evt.type == event_type::QUIT) { @@ -401,18 +401,10 @@ void controller::process_inputdata() { } } -/** - * Process broadcast events - */ -bool controller::on(const sig_ev::notify_change&) { - enqueue(make_update_evt(false)); - return true; -} - /** * Process eventqueue update event */ -bool controller::on(const sig_ev::update&) { +bool controller::process_update(bool force) { const bar_settings& bar{m_bar->settings()}; string contents; string separator{bar.separator}; @@ -484,7 +476,7 @@ bool controller::on(const sig_ev::update&) { try { if (!m_writeback) { - m_bar->parse(move(contents)); + m_bar->parse(move(contents), force); } else { std::cout << contents << std::endl; } @@ -495,6 +487,20 @@ bool controller::on(const sig_ev::update&) { return true; } +/** + * Process broadcast events + */ +bool controller::on(const sig_ev::notify_change&) { + return enqueue(make_update_evt(false)); +} + +/** + * Process forced broadcast events + */ +bool controller::on(const sig_ev::notify_forcechange&) { + return enqueue(make_update_evt(true)); +} + /** * Process eventqueue terminate event */ diff --git a/src/x11/tray_manager.cpp b/src/x11/tray_manager.cpp index f39bd5e4..277d91b3 100644 --- a/src/x11/tray_manager.cpp +++ b/src/x11/tray_manager.cpp @@ -286,7 +286,7 @@ void tray_manager::deactivate(bool clear_selection) { m_connection.flush(); - m_sig.emit(notify_change{}); + m_sig.emit(notify_forcechange{}); } /** @@ -325,7 +325,7 @@ void tray_manager::reconfigure() { m_connection.flush(); - m_sig.emit(notify_change{}); + m_sig.emit(notify_forcechange{}); } /**