From 7979f5b3d44f244adcd98eeb60f60492fe7bddaf Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Wed, 21 Dec 2016 08:38:44 +0100 Subject: [PATCH] refactor(modules): Handle events using signal_receiver --- include/modules/backlight.hpp | 17 ++++--- include/modules/battery.hpp | 39 ++++++++------- include/modules/bspwm.hpp | 10 ++-- include/modules/date.hpp | 10 ++-- include/modules/i3.hpp | 10 ++-- include/modules/menu.hpp | 8 +-- include/modules/meta/base.hpp | 5 -- include/modules/meta/base.inl | 12 +---- include/modules/meta/input_handler.hpp | 17 +++++++ include/modules/mpd.hpp | 8 +-- include/modules/volume.hpp | 8 +-- include/modules/xbacklight.hpp | 12 +++-- include/modules/xkeyboard.hpp | 13 ++--- include/modules/xworkspaces.hpp | 10 ++-- src/components/controller.cpp | 21 ++++---- src/modules/backlight.cpp | 22 ++++----- src/modules/battery.cpp | 68 +++++++++++++------------- src/modules/bspwm.cpp | 4 +- src/modules/date.cpp | 4 +- src/modules/i3.cpp | 4 +- src/modules/menu.cpp | 8 ++- src/modules/mpd.cpp | 8 ++- src/modules/volume.cpp | 8 ++- src/modules/xbacklight.cpp | 4 +- src/modules/xkeyboard.cpp | 4 +- src/modules/xworkspaces.cpp | 3 +- 26 files changed, 176 insertions(+), 161 deletions(-) create mode 100644 include/modules/meta/input_handler.hpp diff --git a/include/modules/backlight.hpp b/include/modules/backlight.hpp index e998145b..22df3e9d 100644 --- a/include/modules/backlight.hpp +++ b/include/modules/backlight.hpp @@ -7,15 +7,16 @@ POLYBAR_NS namespace modules { - struct brightness_handle { - void filepath(const string& path); - float read() const; - - private: - string m_path; - }; - class backlight_module : public inotify_module { + public: + struct brightness_handle { + void filepath(const string& path); + float read() const; + + private: + string m_path; + }; + public: explicit backlight_module(const bar_settings&, string); diff --git a/include/modules/battery.hpp b/include/modules/battery.hpp index 770d5894..f6b473bd 100644 --- a/include/modules/battery.hpp +++ b/include/modules/battery.hpp @@ -7,23 +7,24 @@ POLYBAR_NS namespace modules { - enum class battery_state { - NONE = 0, - CHARGING, - DISCHARGING, - FULL, - }; - - enum class battery_value { - NONE = 0, - ADAPTER, - CAPACITY, - CAPACITY_MAX, - VOLTAGE, - RATE, - }; - class battery_module : public inotify_module { + public: + enum class state { + NONE = 0, + CHARGING, + DISCHARGING, + FULL, + }; + + enum class value { + NONE = 0, + ADAPTER, + CAPACITY, + CAPACITY_MAX, + VOLTAGE, + RATE, + }; + public: explicit battery_module(const bar_settings&, string); @@ -36,7 +37,7 @@ namespace modules { protected: int current_percentage(); - battery_state current_state(); + battery_module::state current_state(); string current_time(); void subthread(); @@ -61,8 +62,8 @@ namespace modules { label_t m_label_discharging; label_t m_label_full; - battery_state m_state{battery_state::DISCHARGING}; - map m_valuepath; + battery_module::state m_state{battery_module::state::DISCHARGING}; + map m_valuepath; std::atomic m_percentage{0}; int m_fullat{100}; chrono::duration m_interval{}; diff --git a/include/modules/bspwm.hpp b/include/modules/bspwm.hpp index cb8bb4b1..b0177b9b 100644 --- a/include/modules/bspwm.hpp +++ b/include/modules/bspwm.hpp @@ -1,12 +1,13 @@ #pragma once #include "modules/meta/event_module.hpp" +#include "modules/meta/input_handler.hpp" #include "utils/bspwm.hpp" POLYBAR_NS namespace modules { - class bspwm_module : public event_module { + class bspwm_module : public event_module, public input_handler { public: enum class state { NONE = 0U, @@ -44,10 +45,9 @@ namespace modules { bool update(); string get_output(); bool build(builder* builder, const string& tag) const; - bool handle_event(string cmd); - bool receive_events() const { - return true; - } + + protected: + bool on(const input_event_t& evt); private: static constexpr auto DEFAULT_ICON = "ws-icon-default"; diff --git a/include/modules/date.hpp b/include/modules/date.hpp index 7dff536b..3dc6583d 100644 --- a/include/modules/date.hpp +++ b/include/modules/date.hpp @@ -1,20 +1,20 @@ #pragma once +#include "modules/meta/input_handler.hpp" #include "modules/meta/timer_module.hpp" POLYBAR_NS namespace modules { - class date_module : public timer_module { + class date_module : public timer_module, public input_handler { public: explicit date_module(const bar_settings&, string); bool update(); bool build(builder* builder, const string& tag) const; - bool handle_event(string cmd); - bool receive_events() const { - return true; - } + + protected: + bool on(const input_event_t& evt); private: static constexpr auto TAG_LABEL = "