refactor(modules): Make all modules input handlers

By default they will return false for calls to `input`
This commit is contained in:
patrick96 2019-12-02 19:14:26 +01:00 committed by Patrick Ziegler
parent 457e37faaf
commit 4b5007294b
15 changed files with 41 additions and 28 deletions

View File

@ -2,7 +2,6 @@
#include "settings.hpp" #include "settings.hpp"
#include "modules/meta/event_module.hpp" #include "modules/meta/event_module.hpp"
#include "modules/meta/input_handler.hpp"
POLYBAR_NS POLYBAR_NS
@ -19,7 +18,7 @@ namespace modules {
using mixer_t = shared_ptr<alsa::mixer>; using mixer_t = shared_ptr<alsa::mixer>;
using control_t = shared_ptr<alsa::control>; using control_t = shared_ptr<alsa::control>;
class alsa_module : public event_module<alsa_module>, public input_handler { class alsa_module : public event_module<alsa_module> {
public: public:
explicit alsa_module(const bar_settings&, string); explicit alsa_module(const bar_settings&, string);

View File

@ -1,13 +1,12 @@
#pragma once #pragma once
#include "modules/meta/event_module.hpp" #include "modules/meta/event_module.hpp"
#include "modules/meta/input_handler.hpp"
#include "utils/bspwm.hpp" #include "utils/bspwm.hpp"
POLYBAR_NS POLYBAR_NS
namespace modules { namespace modules {
class bspwm_module : public event_module<bspwm_module>, public input_handler { class bspwm_module : public event_module<bspwm_module> {
public: public:
enum class state { enum class state {
NONE = 0U, NONE = 0U,

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "modules/meta/input_handler.hpp"
#include "modules/meta/timer_module.hpp" #include "modules/meta/timer_module.hpp"
#include <iostream> #include <iostream>
@ -10,7 +9,7 @@
POLYBAR_NS POLYBAR_NS
namespace modules { namespace modules {
class date_module : public timer_module<date_module>, public input_handler { class date_module : public timer_module<date_module> {
public: public:
explicit date_module(const bar_settings&, string); explicit date_module(const bar_settings&, string);

View File

@ -4,14 +4,13 @@
#include "components/config.hpp" #include "components/config.hpp"
#include "modules/meta/event_module.hpp" #include "modules/meta/event_module.hpp"
#include "modules/meta/input_handler.hpp"
#include "utils/i3.hpp" #include "utils/i3.hpp"
#include "utils/io.hpp" #include "utils/io.hpp"
POLYBAR_NS POLYBAR_NS
namespace modules { namespace modules {
class i3_module : public event_module<i3_module>, public input_handler { class i3_module : public event_module<i3_module> {
public: public:
enum class state { enum class state {
NONE, NONE,

View File

@ -1,12 +1,11 @@
#pragma once #pragma once
#include "modules/meta/input_handler.hpp"
#include "modules/meta/static_module.hpp" #include "modules/meta/static_module.hpp"
POLYBAR_NS POLYBAR_NS
namespace modules { namespace modules {
class menu_module : public static_module<menu_module>, public input_handler { class menu_module : public static_module<menu_module> {
public: public:
struct menu_tree_item { struct menu_tree_item {
string exec; string exec;

View File

@ -9,11 +9,11 @@
#include "common.hpp" #include "common.hpp"
#include "components/types.hpp" #include "components/types.hpp"
#include "errors.hpp" #include "errors.hpp"
#include "modules/meta/input_handler.hpp"
#include "utils/concurrency.hpp" #include "utils/concurrency.hpp"
#include "utils/functional.hpp" #include "utils/functional.hpp"
#include "utils/inotify.hpp" #include "utils/inotify.hpp"
#include "utils/string.hpp" #include "utils/string.hpp"
POLYBAR_NS POLYBAR_NS
namespace chrono = std::chrono; namespace chrono = std::chrono;
@ -118,7 +118,7 @@ namespace modules {
// class definition : module {{{ // class definition : module {{{
template <class Impl> template <class Impl>
class module : public module_interface { class module : public module_interface, public input_handler {
public: public:
module(const bar_settings bar, string name); module(const bar_settings bar, string name);
~module() noexcept; ~module() noexcept;
@ -131,6 +131,9 @@ namespace modules {
void teardown(); void teardown();
string contents(); string contents();
bool input(string&& cmd);
string input_handler_name() const;
protected: protected:
void broadcast(); void broadcast();
void idle(); void idle();

View File

@ -98,6 +98,17 @@ namespace modules {
return m_cache; return m_cache;
} }
template <typename Impl>
bool module<Impl>::input(string&&) {
// By default a module doesn't support inputs
return false;
}
template <typename Impl>
string module<Impl>::input_handler_name() const {
return m_name_raw;
}
// }}} // }}}
// module<Impl> protected {{{ // module<Impl> protected {{{

View File

@ -14,6 +14,13 @@ namespace modules {
* \returns true if the command is supported and false otherwise * \returns true if the command is supported and false otherwise
*/ */
virtual bool input(string&& cmd) = 0; 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;
}; };
} }

View File

@ -5,14 +5,13 @@
#include "utils/env.hpp" #include "utils/env.hpp"
#include "adapters/mpd.hpp" #include "adapters/mpd.hpp"
#include "modules/meta/event_module.hpp" #include "modules/meta/event_module.hpp"
#include "modules/meta/input_handler.hpp"
POLYBAR_NS POLYBAR_NS
using namespace mpd; using namespace mpd;
namespace modules { namespace modules {
class mpd_module : public event_module<mpd_module>, public input_handler { class mpd_module : public event_module<mpd_module> {
public: public:
explicit mpd_module(const bar_settings&, string); explicit mpd_module(const bar_settings&, string);

View File

@ -2,7 +2,6 @@
#include "settings.hpp" #include "settings.hpp"
#include "modules/meta/event_module.hpp" #include "modules/meta/event_module.hpp"
#include "modules/meta/input_handler.hpp"
POLYBAR_NS POLYBAR_NS
@ -12,7 +11,7 @@ class pulseaudio;
namespace modules { namespace modules {
using pulseaudio_t = shared_ptr<pulseaudio>; using pulseaudio_t = shared_ptr<pulseaudio>;
class pulseaudio_module : public event_module<pulseaudio_module>, public input_handler { class pulseaudio_module : public event_module<pulseaudio_module> {
public: public:
explicit pulseaudio_module(const bar_settings&, string); explicit pulseaudio_module(const bar_settings&, string);

View File

@ -2,7 +2,6 @@
#pragma once #pragma once
#include "modules/meta/static_module.hpp" #include "modules/meta/static_module.hpp"
#include "modules/meta/input_handler.hpp"
POLYBAR_NS POLYBAR_NS
@ -13,7 +12,7 @@ namespace modules {
* Module used to display information about the * Module used to display information about the
* currently active X window. * currently active X window.
*/ */
class systray_module : public static_module<systray_module>, public input_handler { class systray_module : public static_module<systray_module> {
public: public:
explicit systray_module(const bar_settings&, string); explicit systray_module(const bar_settings&, string);

View File

@ -12,7 +12,7 @@ namespace modules {
struct module_interface; struct module_interface;
#define DEFINE_UNSUPPORTED_MODULE(MODULE_NAME, MODULE_TYPE) \ #define DEFINE_UNSUPPORTED_MODULE(MODULE_NAME, MODULE_TYPE) \
class MODULE_NAME : public module_interface { \ class MODULE_NAME : public module_interface, public input_handler { \
public: \ public: \
MODULE_NAME(const bar_settings, string) { \ MODULE_NAME(const bar_settings, string) { \
throw application_error("No built-in support for '" + string{MODULE_TYPE} + "'"); \ throw application_error("No built-in support for '" + string{MODULE_TYPE} + "'"); \
@ -32,6 +32,12 @@ namespace modules {
string contents() { \ string contents() { \
return ""; \ return ""; \
} \ } \
string input_handler_name() const { \
return ""; \
} \
bool input(string&&) { \
return false; \
} \
} }
#if not ENABLE_I3 #if not ENABLE_I3

View File

@ -3,7 +3,6 @@
#include "components/config.hpp" #include "components/config.hpp"
#include "settings.hpp" #include "settings.hpp"
#include "modules/meta/event_handler.hpp" #include "modules/meta/event_handler.hpp"
#include "modules/meta/input_handler.hpp"
#include "modules/meta/static_module.hpp" #include "modules/meta/static_module.hpp"
#include "x11/extensions/randr.hpp" #include "x11/extensions/randr.hpp"
@ -26,8 +25,7 @@ namespace modules {
* TODO: Implement backlight configuring using scroll events * TODO: Implement backlight configuring using scroll events
*/ */
class xbacklight_module : public static_module<xbacklight_module>, class xbacklight_module : public static_module<xbacklight_module>,
public event_handler<evt::randr_notify>, public event_handler<evt::randr_notify> {
public input_handler {
public: public:
explicit xbacklight_module(const bar_settings& bar, string name_); explicit xbacklight_module(const bar_settings& bar, string name_);

View File

@ -4,7 +4,6 @@
#include "components/config.hpp" #include "components/config.hpp"
#include "components/types.hpp" #include "components/types.hpp"
#include "modules/meta/event_handler.hpp" #include "modules/meta/event_handler.hpp"
#include "modules/meta/input_handler.hpp"
#include "modules/meta/static_module.hpp" #include "modules/meta/static_module.hpp"
#include "x11/extensions/xkb.hpp" #include "x11/extensions/xkb.hpp"
#include "x11/window.hpp" #include "x11/window.hpp"
@ -19,8 +18,7 @@ namespace modules {
*/ */
class xkeyboard_module class xkeyboard_module
: public static_module<xkeyboard_module>, : public static_module<xkeyboard_module>,
public event_handler<evt::xkb_new_keyboard_notify, evt::xkb_state_notify, evt::xkb_indicator_state_notify>, public event_handler<evt::xkb_new_keyboard_notify, evt::xkb_state_notify, evt::xkb_indicator_state_notify> {
public input_handler {
public: public:
explicit xkeyboard_module(const bar_settings& bar, string name_); explicit xkeyboard_module(const bar_settings& bar, string name_);

View File

@ -7,7 +7,6 @@
#include "components/config.hpp" #include "components/config.hpp"
#include "components/types.hpp" #include "components/types.hpp"
#include "modules/meta/event_handler.hpp" #include "modules/meta/event_handler.hpp"
#include "modules/meta/input_handler.hpp"
#include "modules/meta/static_module.hpp" #include "modules/meta/static_module.hpp"
#include "x11/ewmh.hpp" #include "x11/ewmh.hpp"
#include "x11/icccm.hpp" #include "x11/icccm.hpp"
@ -52,8 +51,7 @@ namespace modules {
* Module used to display EWMH desktops * Module used to display EWMH desktops
*/ */
class xworkspaces_module : public static_module<xworkspaces_module>, class xworkspaces_module : public static_module<xworkspaces_module>,
public event_handler<evt::property_notify>, public event_handler<evt::property_notify> {
public input_handler {
public: public:
explicit xworkspaces_module(const bar_settings& bar, string name_); explicit xworkspaces_module(const bar_settings& bar, string name_);