From d592eea96648a0f45a6888c81e490fe8555f9777 Mon Sep 17 00:00:00 2001 From: patrick96 Date: Fri, 15 May 2020 19:59:08 +0200 Subject: [PATCH] refactor: Move module type string into modules This allows us to identify module by their type and it is also better to store the module type as part of the module instead of having it hardcoded in factory.hpp --- include/modules/alsa.hpp | 8 +++-- include/modules/backlight.hpp | 5 +-- include/modules/battery.hpp | 4 ++- include/modules/bspwm.hpp | 4 ++- include/modules/counter.hpp | 4 ++- include/modules/cpu.hpp | 6 ++-- include/modules/date.hpp | 12 ++++--- include/modules/fs.hpp | 6 ++-- include/modules/github.hpp | 2 ++ include/modules/i3.hpp | 2 ++ include/modules/ipc.hpp | 4 ++- include/modules/memory.hpp | 4 ++- include/modules/menu.hpp | 4 ++- include/modules/meta/base.hpp | 14 ++++++-- include/modules/meta/base.inl | 5 +++ include/modules/meta/factory.hpp | 55 +++++++++++++++----------------- include/modules/mpd.hpp | 6 ++-- include/modules/network.hpp | 4 ++- include/modules/pulseaudio.hpp | 6 ++-- include/modules/script.hpp | 4 ++- include/modules/systray.hpp | 4 ++- include/modules/temperature.hpp | 6 ++-- include/modules/text.hpp | 4 ++- include/modules/unsupported.hpp | 8 ++--- include/modules/xbacklight.hpp | 11 +++---- include/modules/xkeyboard.hpp | 6 ++-- include/modules/xwindow.hpp | 10 +++--- include/modules/xworkspaces.hpp | 5 +-- src/components/controller.cpp | 9 +++--- src/modules/date.cpp | 4 +-- 30 files changed, 137 insertions(+), 89 deletions(-) diff --git a/include/modules/alsa.hpp b/include/modules/alsa.hpp index eae9cefb..2b3f52ca 100644 --- a/include/modules/alsa.hpp +++ b/include/modules/alsa.hpp @@ -1,7 +1,7 @@ #pragma once -#include "settings.hpp" #include "modules/meta/event_module.hpp" +#include "settings.hpp" POLYBAR_NS @@ -9,7 +9,7 @@ POLYBAR_NS namespace alsa { class mixer; class control; -} +} // namespace alsa namespace modules { enum class mixer { NONE = 0, MASTER, SPEAKER, HEADPHONE }; @@ -29,6 +29,8 @@ namespace modules { string get_output(); bool build(builder* builder, const string& tag) const; + static constexpr auto TYPE = "internal/alsa"; + protected: bool input(string&& cmd); @@ -62,6 +64,6 @@ namespace modules { atomic m_headphones{false}; atomic m_volume{0}; }; -} +} // namespace modules POLYBAR_NS_END diff --git a/include/modules/backlight.hpp b/include/modules/backlight.hpp index b62220df..751735c8 100644 --- a/include/modules/backlight.hpp +++ b/include/modules/backlight.hpp @@ -2,13 +2,12 @@ #include "components/config.hpp" #include "modules/meta/inotify_module.hpp" -#include "modules/meta/input_handler.hpp" #include "settings.hpp" POLYBAR_NS namespace modules { - class backlight_module : public inotify_module, public input_handler { + class backlight_module : public inotify_module { public: struct brightness_handle { void filepath(const string& path); @@ -27,6 +26,8 @@ namespace modules { bool on_event(inotify_event* event); bool build(builder* builder, const string& tag) const; + static constexpr auto TYPE = "internal/backlight"; + protected: bool input(string&& cmd); diff --git a/include/modules/battery.hpp b/include/modules/battery.hpp index 1fc11b47..07fba087 100644 --- a/include/modules/battery.hpp +++ b/include/modules/battery.hpp @@ -54,6 +54,8 @@ namespace modules { string get_format() const; bool build(builder* builder, const string& tag) const; + static constexpr auto TYPE = "internal/battery"; + protected: state current_state(); int current_percentage(); @@ -106,6 +108,6 @@ namespace modules { chrono::system_clock::time_point m_lastpoll; thread m_subthread; }; -} +} // namespace modules POLYBAR_NS_END diff --git a/include/modules/bspwm.hpp b/include/modules/bspwm.hpp index 2f739088..be97cf8b 100644 --- a/include/modules/bspwm.hpp +++ b/include/modules/bspwm.hpp @@ -47,6 +47,8 @@ namespace modules { string get_output(); bool build(builder* builder, const string& tag) const; + static constexpr auto TYPE = "internal/bspwm"; + protected: bool input(string&& cmd); @@ -91,6 +93,6 @@ namespace modules { // used while formatting output size_t m_index{0U}; }; -} +} // namespace modules POLYBAR_NS_END diff --git a/include/modules/counter.hpp b/include/modules/counter.hpp index 4c498e93..a386185d 100644 --- a/include/modules/counter.hpp +++ b/include/modules/counter.hpp @@ -12,11 +12,13 @@ namespace modules { bool update(); bool build(builder* builder, const string& tag) const; + static constexpr auto TYPE = "internal/counter"; + private: static constexpr auto TAG_COUNTER = ""; int m_counter{0}; }; -} +} // namespace modules POLYBAR_NS_END diff --git a/include/modules/cpu.hpp b/include/modules/cpu.hpp index 40e9c87d..003c9fb2 100644 --- a/include/modules/cpu.hpp +++ b/include/modules/cpu.hpp @@ -1,7 +1,7 @@ #pragma once -#include "settings.hpp" #include "modules/meta/timer_module.hpp" +#include "settings.hpp" POLYBAR_NS @@ -24,6 +24,8 @@ namespace modules { bool update(); bool build(builder* builder, const string& tag) const; + static constexpr auto TYPE = "internal/cpu"; + protected: bool read_values(); float get_load(size_t core) const; @@ -46,6 +48,6 @@ namespace modules { float m_total = 0; vector m_load; }; -} +} // namespace modules POLYBAR_NS_END diff --git a/include/modules/date.hpp b/include/modules/date.hpp index 3e42fb8d..6639b759 100644 --- a/include/modules/date.hpp +++ b/include/modules/date.hpp @@ -1,10 +1,10 @@ #pragma once -#include "modules/meta/timer_module.hpp" - -#include -#include #include +#include +#include + +#include "modules/meta/timer_module.hpp" POLYBAR_NS @@ -16,6 +16,8 @@ namespace modules { bool update(); bool build(builder* builder, const string& tag) const; + static constexpr auto TYPE = "internal/date"; + protected: bool input(string&& cmd); @@ -41,6 +43,6 @@ namespace modules { std::atomic m_toggled{false}; }; -} +} // namespace modules POLYBAR_NS_END diff --git a/include/modules/fs.hpp b/include/modules/fs.hpp index 0ee56721..115dddcd 100644 --- a/include/modules/fs.hpp +++ b/include/modules/fs.hpp @@ -1,8 +1,8 @@ #pragma once #include "components/config.hpp" -#include "settings.hpp" #include "modules/meta/timer_module.hpp" +#include "settings.hpp" POLYBAR_NS @@ -42,6 +42,8 @@ namespace modules { string get_output(); bool build(builder* builder, const string& tag) const; + static constexpr auto TYPE = "internal/fs"; + private: static constexpr auto FORMAT_MOUNTED = "format-mounted"; static constexpr auto FORMAT_UNMOUNTED = "format-unmounted"; @@ -66,6 +68,6 @@ namespace modules { // used while formatting output size_t m_index{0_z}; }; -} +} // namespace modules POLYBAR_NS_END diff --git a/include/modules/github.hpp b/include/modules/github.hpp index 0eab224e..a45701f5 100644 --- a/include/modules/github.hpp +++ b/include/modules/github.hpp @@ -18,6 +18,8 @@ namespace modules { bool build(builder* builder, const string& tag) const; string get_format() const; + static constexpr auto TYPE = "internal/github"; + private: void update_label(int); int get_number_of_notification(); diff --git a/include/modules/i3.hpp b/include/modules/i3.hpp index 1559377a..8139cf12 100644 --- a/include/modules/i3.hpp +++ b/include/modules/i3.hpp @@ -51,6 +51,8 @@ namespace modules { bool update(); bool build(builder* builder, const string& tag) const; + static constexpr auto TYPE = "internal/i3"; + protected: bool input(string&& cmd); diff --git a/include/modules/ipc.hpp b/include/modules/ipc.hpp index bb681a62..63e4fe70 100644 --- a/include/modules/ipc.hpp +++ b/include/modules/ipc.hpp @@ -32,6 +32,8 @@ namespace modules { bool build(builder* builder, const string& tag) const; void on_message(const string& message); + static constexpr auto TYPE = "custom/ipc"; + private: static constexpr const char* TAG_OUTPUT{""}; vector> m_hooks; @@ -39,6 +41,6 @@ namespace modules { string m_output; size_t m_initial; }; -} +} // namespace modules POLYBAR_NS_END diff --git a/include/modules/memory.hpp b/include/modules/memory.hpp index 5f06d0ab..e85624a1 100644 --- a/include/modules/memory.hpp +++ b/include/modules/memory.hpp @@ -15,6 +15,8 @@ namespace modules { bool update(); bool build(builder* builder, const string& tag) const; + static constexpr auto TYPE = "internal/memory"; + private: static constexpr const char* TAG_LABEL{"