fix(tray): Force bar update on change

Refs #295
This commit is contained in:
Michael Carlberg 2017-01-09 14:27:55 +01:00
parent 5458c433b6
commit 6925415501
7 changed files with 35 additions and 27 deletions

View File

@ -33,7 +33,8 @@ namespace sig_ev = signals::eventqueue;
class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::property_notify, evt::enter_notify, class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::property_notify, evt::enter_notify,
evt::leave_notify, evt::destroy_notify, evt::client_message>, evt::leave_notify, evt::destroy_notify, evt::client_message>,
public signal_receiver<SIGN_PRIORITY_BAR, sig_ui::tick, sig_ui::shade_window, sig_ui::unshade_window, sig_ui::dim_window> { public signal_receiver<SIGN_PRIORITY_BAR, sig_ui::tick, sig_ui::shade_window, sig_ui::unshade_window,
sig_ui::dim_window> {
public: public:
using make_type = unique_ptr<bar>; using make_type = unique_ptr<bar>;
static make_type make(bool only_initialize_values = false); static make_type make(bool only_initialize_values = false);
@ -44,7 +45,7 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::propert
const bar_settings settings() const; const bar_settings settings() const;
void parse(string&& data); void parse(string&& data, bool force = false);
protected: protected:
void restack_window(); void restack_window();

View File

@ -8,8 +8,8 @@
#include "events/signal_receiver.hpp" #include "events/signal_receiver.hpp"
#include "events/types.hpp" #include "events/types.hpp"
#include "utils/file.hpp" #include "utils/file.hpp"
#include "x11/types.hpp"
#include "x11/events.hpp" #include "x11/events.hpp"
#include "x11/types.hpp"
POLYBAR_NS POLYBAR_NS
@ -44,8 +44,8 @@ namespace sig_ui = signals::ui;
namespace sig_ipc = signals::ipc; namespace sig_ipc = signals::ipc;
class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::exit_terminate, sig_ev::exit_reload, class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::exit_terminate, sig_ev::exit_reload,
sig_ev::update, sig_ev::notify_change, sig_ev::check_state, sig_ipc::action, sig_ipc::command, sig_ev::notify_change, sig_ev::notify_forcechange, sig_ev::check_state, sig_ipc::action,
sig_ipc::hook, sig_ui::button_press> { sig_ipc::command, sig_ipc::hook, sig_ui::button_press> {
public: public:
using make_type = unique_ptr<controller>; using make_type = unique_ptr<controller>;
static make_type make(unique_ptr<ipc>&& ipc, unique_ptr<inotify_watch>&& config_watch); static make_type make(unique_ptr<ipc>&& ipc, unique_ptr<inotify_watch>&& config_watch);
@ -63,9 +63,10 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::exit
void read_events(); void read_events();
void process_eventqueue(); void process_eventqueue();
void process_inputdata(); void process_inputdata();
bool process_update(bool force);
bool on(const sig_ev::notify_change& evt); bool on(const sig_ev::notify_change& evt);
bool on(const sig_ev::update& evt); bool on(const sig_ev::notify_forcechange& evt);
bool on(const sig_ev::exit_terminate& evt); bool on(const sig_ev::exit_terminate& evt);
bool on(const sig_ev::exit_reload& evt); bool on(const sig_ev::exit_reload& evt);
bool on(const sig_ev::check_state& evt); bool on(const sig_ev::check_state& evt);

View File

@ -86,10 +86,10 @@ namespace signals {
struct notify_change : public detail::base_signal<notify_change> { struct notify_change : public detail::base_signal<notify_change> {
using base_type::base_type; using base_type::base_type;
}; };
struct check_state : public detail::base_signal<check_state> { struct notify_forcechange : public detail::base_signal<notify_forcechange> {
using base_type::base_type; using base_type::base_type;
}; };
struct update : public detail::base_signal<update> { struct check_state : public detail::base_signal<check_state> {
using base_type::base_type; using base_type::base_type;
}; };
} }

View File

@ -18,8 +18,8 @@ namespace signals {
struct exit_terminate; struct exit_terminate;
struct exit_reload; struct exit_reload;
struct notify_change; struct notify_change;
struct notify_forcechange;
struct check_state; struct check_state;
struct update;
} }
namespace ipc { namespace ipc {
struct command; struct command;

View File

@ -311,18 +311,18 @@ const bar_settings bar::settings() const {
* @param data Input string * @param data Input string
* @param force Unless true, do not parse unchanged data * @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()) { if (!m_mutex.try_lock()) {
return; return;
} }
std::lock_guard<std::mutex> guard(m_mutex, std::adopt_lock); std::lock_guard<std::mutex> 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)"); return m_log.trace("bar: Ignoring update (shaded)");
} } else if (data == m_lastinput) {
if (data == m_lastinput) {
return; return;
} }

View File

@ -350,7 +350,7 @@ void controller::process_eventqueue() {
} }
if (evt.type == event_type::UPDATE) { if (evt.type == event_type::UPDATE) {
on(sig_ev::update{}); process_update(evt.flag);
} else if (evt.type == event_type::INPUT) { } else if (evt.type == event_type::INPUT) {
process_inputdata(); process_inputdata();
} else if (evt.type == event_type::QUIT) { } 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 * Process eventqueue update event
*/ */
bool controller::on(const sig_ev::update&) { bool controller::process_update(bool force) {
const bar_settings& bar{m_bar->settings()}; const bar_settings& bar{m_bar->settings()};
string contents; string contents;
string separator{bar.separator}; string separator{bar.separator};
@ -484,7 +476,7 @@ bool controller::on(const sig_ev::update&) {
try { try {
if (!m_writeback) { if (!m_writeback) {
m_bar->parse(move(contents)); m_bar->parse(move(contents), force);
} else { } else {
std::cout << contents << std::endl; std::cout << contents << std::endl;
} }
@ -495,6 +487,20 @@ bool controller::on(const sig_ev::update&) {
return true; 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 * Process eventqueue terminate event
*/ */

View File

@ -286,7 +286,7 @@ void tray_manager::deactivate(bool clear_selection) {
m_connection.flush(); 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_connection.flush();
m_sig.emit(notify_change{}); m_sig.emit(notify_forcechange{});
} }
/** /**