From 4b5007294bb6bf7e64af8aa65f01424d17c9018f Mon Sep 17 00:00:00 2001
From: patrick96
Date: Mon, 2 Dec 2019 19:14:26 +0100
Subject: [PATCH] refactor(modules): Make all modules input handlers
By default they will return false for calls to `input`
---
include/modules/alsa.hpp | 3 +--
include/modules/bspwm.hpp | 3 +--
include/modules/date.hpp | 3 +--
include/modules/i3.hpp | 3 +--
include/modules/menu.hpp | 3 +--
include/modules/meta/base.hpp | 7 +++++--
include/modules/meta/base.inl | 11 +++++++++++
include/modules/meta/input_handler.hpp | 7 +++++++
include/modules/mpd.hpp | 3 +--
include/modules/pulseaudio.hpp | 3 +--
include/modules/systray.hpp | 3 +--
include/modules/unsupported.hpp | 8 +++++++-
include/modules/xbacklight.hpp | 4 +---
include/modules/xkeyboard.hpp | 4 +---
include/modules/xworkspaces.hpp | 4 +---
15 files changed, 41 insertions(+), 28 deletions(-)
diff --git a/include/modules/alsa.hpp b/include/modules/alsa.hpp
index b9dac597..eae9cefb 100644
--- a/include/modules/alsa.hpp
+++ b/include/modules/alsa.hpp
@@ -2,7 +2,6 @@
#include "settings.hpp"
#include "modules/meta/event_module.hpp"
-#include "modules/meta/input_handler.hpp"
POLYBAR_NS
@@ -19,7 +18,7 @@ namespace modules {
using mixer_t = shared_ptr;
using control_t = shared_ptr;
- class alsa_module : public event_module, public input_handler {
+ class alsa_module : public event_module {
public:
explicit alsa_module(const bar_settings&, string);
diff --git a/include/modules/bspwm.hpp b/include/modules/bspwm.hpp
index 5f3248c7..2f739088 100644
--- a/include/modules/bspwm.hpp
+++ b/include/modules/bspwm.hpp
@@ -1,13 +1,12 @@
#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, public input_handler {
+ class bspwm_module : public event_module {
public:
enum class state {
NONE = 0U,
diff --git a/include/modules/date.hpp b/include/modules/date.hpp
index b0bf29aa..3e42fb8d 100644
--- a/include/modules/date.hpp
+++ b/include/modules/date.hpp
@@ -1,6 +1,5 @@
#pragma once
-#include "modules/meta/input_handler.hpp"
#include "modules/meta/timer_module.hpp"
#include
@@ -10,7 +9,7 @@
POLYBAR_NS
namespace modules {
- class date_module : public timer_module, public input_handler {
+ class date_module : public timer_module {
public:
explicit date_module(const bar_settings&, string);
diff --git a/include/modules/i3.hpp b/include/modules/i3.hpp
index 95a5c131..1559377a 100644
--- a/include/modules/i3.hpp
+++ b/include/modules/i3.hpp
@@ -4,14 +4,13 @@
#include "components/config.hpp"
#include "modules/meta/event_module.hpp"
-#include "modules/meta/input_handler.hpp"
#include "utils/i3.hpp"
#include "utils/io.hpp"
POLYBAR_NS
namespace modules {
- class i3_module : public event_module, public input_handler {
+ class i3_module : public event_module {
public:
enum class state {
NONE,
diff --git a/include/modules/menu.hpp b/include/modules/menu.hpp
index a0e1fa3d..2706c8d5 100644
--- a/include/modules/menu.hpp
+++ b/include/modules/menu.hpp
@@ -1,12 +1,11 @@
#pragma once
-#include "modules/meta/input_handler.hpp"
#include "modules/meta/static_module.hpp"
POLYBAR_NS
namespace modules {
- class menu_module : public static_module, public input_handler {
+ class menu_module : public static_module {
public:
struct menu_tree_item {
string exec;
diff --git a/include/modules/meta/base.hpp b/include/modules/meta/base.hpp
index 558f5b90..05e40a48 100644
--- a/include/modules/meta/base.hpp
+++ b/include/modules/meta/base.hpp
@@ -9,11 +9,11 @@
#include "common.hpp"
#include "components/types.hpp"
#include "errors.hpp"
+#include "modules/meta/input_handler.hpp"
#include "utils/concurrency.hpp"
#include "utils/functional.hpp"
#include "utils/inotify.hpp"
#include "utils/string.hpp"
-
POLYBAR_NS
namespace chrono = std::chrono;
@@ -118,7 +118,7 @@ namespace modules {
// class definition : module {{{
template
- class module : public module_interface {
+ class module : public module_interface, public input_handler {
public:
module(const bar_settings bar, string name);
~module() noexcept;
@@ -131,6 +131,9 @@ namespace modules {
void teardown();
string contents();
+ bool input(string&& cmd);
+ string input_handler_name() const;
+
protected:
void broadcast();
void idle();
diff --git a/include/modules/meta/base.inl b/include/modules/meta/base.inl
index f201c9cf..3213fac7 100644
--- a/include/modules/meta/base.inl
+++ b/include/modules/meta/base.inl
@@ -98,6 +98,17 @@ namespace modules {
return m_cache;
}
+ template
+ bool module::input(string&&) {
+ // By default a module doesn't support inputs
+ return false;
+ }
+
+ template
+ string module::input_handler_name() const {
+ return m_name_raw;
+ }
+
// }}}
// module protected {{{
diff --git a/include/modules/meta/input_handler.hpp b/include/modules/meta/input_handler.hpp
index b3362cc3..0d740322 100644
--- a/include/modules/meta/input_handler.hpp
+++ b/include/modules/meta/input_handler.hpp
@@ -14,6 +14,13 @@ namespace modules {
* \returns true if the command is supported and false otherwise
*/
virtual bool input(string&& cmd) = 0;
+
+ /**
+ * The name of this input handler
+ *
+ * Actions of the form '#NAME#ACTION' can be sent to this handler if NAME is the name of this input handler.
+ */
+ virtual string input_handler_name() const = 0;
};
}
diff --git a/include/modules/mpd.hpp b/include/modules/mpd.hpp
index c9e07257..2979c628 100644
--- a/include/modules/mpd.hpp
+++ b/include/modules/mpd.hpp
@@ -5,14 +5,13 @@
#include "utils/env.hpp"
#include "adapters/mpd.hpp"
#include "modules/meta/event_module.hpp"
-#include "modules/meta/input_handler.hpp"
POLYBAR_NS
using namespace mpd;
namespace modules {
- class mpd_module : public event_module, public input_handler {
+ class mpd_module : public event_module {
public:
explicit mpd_module(const bar_settings&, string);
diff --git a/include/modules/pulseaudio.hpp b/include/modules/pulseaudio.hpp
index 48c381c5..083e11a0 100644
--- a/include/modules/pulseaudio.hpp
+++ b/include/modules/pulseaudio.hpp
@@ -2,7 +2,6 @@
#include "settings.hpp"
#include "modules/meta/event_module.hpp"
-#include "modules/meta/input_handler.hpp"
POLYBAR_NS
@@ -12,7 +11,7 @@ class pulseaudio;
namespace modules {
using pulseaudio_t = shared_ptr;
- class pulseaudio_module : public event_module, public input_handler {
+ class pulseaudio_module : public event_module {
public:
explicit pulseaudio_module(const bar_settings&, string);
diff --git a/include/modules/systray.hpp b/include/modules/systray.hpp
index b7e0cf3f..a1ff57ed 100644
--- a/include/modules/systray.hpp
+++ b/include/modules/systray.hpp
@@ -2,7 +2,6 @@
#pragma once
#include "modules/meta/static_module.hpp"
-#include "modules/meta/input_handler.hpp"
POLYBAR_NS
@@ -13,7 +12,7 @@ namespace modules {
* Module used to display information about the
* currently active X window.
*/
- class systray_module : public static_module, public input_handler {
+ class systray_module : public static_module {
public:
explicit systray_module(const bar_settings&, string);
diff --git a/include/modules/unsupported.hpp b/include/modules/unsupported.hpp
index 8d9dd959..5fc75ca1 100644
--- a/include/modules/unsupported.hpp
+++ b/include/modules/unsupported.hpp
@@ -12,7 +12,7 @@ namespace modules {
struct module_interface;
#define DEFINE_UNSUPPORTED_MODULE(MODULE_NAME, MODULE_TYPE) \
- class MODULE_NAME : public module_interface { \
+ class MODULE_NAME : public module_interface, public input_handler { \
public: \
MODULE_NAME(const bar_settings, string) { \
throw application_error("No built-in support for '" + string{MODULE_TYPE} + "'"); \
@@ -32,6 +32,12 @@ namespace modules {
string contents() { \
return ""; \
} \
+ string input_handler_name() const { \
+ return ""; \
+ } \
+ bool input(string&&) { \
+ return false; \
+ } \
}
#if not ENABLE_I3
diff --git a/include/modules/xbacklight.hpp b/include/modules/xbacklight.hpp
index 4940c4a9..9f393a01 100644
--- a/include/modules/xbacklight.hpp
+++ b/include/modules/xbacklight.hpp
@@ -3,7 +3,6 @@
#include "components/config.hpp"
#include "settings.hpp"
#include "modules/meta/event_handler.hpp"
-#include "modules/meta/input_handler.hpp"
#include "modules/meta/static_module.hpp"
#include "x11/extensions/randr.hpp"
@@ -26,8 +25,7 @@ namespace modules {
* TODO: Implement backlight configuring using scroll events
*/
class xbacklight_module : public static_module,
- public event_handler,
- public input_handler {
+ public event_handler {
public:
explicit xbacklight_module(const bar_settings& bar, string name_);
diff --git a/include/modules/xkeyboard.hpp b/include/modules/xkeyboard.hpp
index 73187479..e5c6d1d9 100644
--- a/include/modules/xkeyboard.hpp
+++ b/include/modules/xkeyboard.hpp
@@ -4,7 +4,6 @@
#include "components/config.hpp"
#include "components/types.hpp"
#include "modules/meta/event_handler.hpp"
-#include "modules/meta/input_handler.hpp"
#include "modules/meta/static_module.hpp"
#include "x11/extensions/xkb.hpp"
#include "x11/window.hpp"
@@ -19,8 +18,7 @@ namespace modules {
*/
class xkeyboard_module
: public static_module,
- public event_handler,
- public input_handler {
+ public event_handler {
public:
explicit xkeyboard_module(const bar_settings& bar, string name_);
diff --git a/include/modules/xworkspaces.hpp b/include/modules/xworkspaces.hpp
index 6d07571f..72a6aeb1 100644
--- a/include/modules/xworkspaces.hpp
+++ b/include/modules/xworkspaces.hpp
@@ -7,7 +7,6 @@
#include "components/config.hpp"
#include "components/types.hpp"
#include "modules/meta/event_handler.hpp"
-#include "modules/meta/input_handler.hpp"
#include "modules/meta/static_module.hpp"
#include "x11/ewmh.hpp"
#include "x11/icccm.hpp"
@@ -52,8 +51,7 @@ namespace modules {
* Module used to display EWMH desktops
*/
class xworkspaces_module : public static_module,
- public event_handler,
- public input_handler {
+ public event_handler {
public:
explicit xworkspaces_module(const bar_settings& bar, string name_);