ISSUE#1977. AModule implements module actions call

Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
This commit is contained in:
Viktar Lukashonak
2023-02-28 15:32:28 +03:00
parent 09142fa322
commit e25a7c9719
5 changed files with 96 additions and 74 deletions

View File

@ -11,16 +11,20 @@ namespace waybar {
class AModule : public IModule {
public:
AModule(const Json::Value &, const std::string &, const std::string &, bool enable_click = false,
bool enable_scroll = false);
virtual ~AModule();
virtual auto update() -> void;
virtual auto refresh(int) -> void{};
virtual operator Gtk::Widget &();
virtual auto doAction(const std::string& name) -> void;
Glib::Dispatcher dp;
protected:
// Don't need to make an object directly
// Derived classes are able to use it
AModule(const Json::Value &, const std::string &, const std::string &, bool enable_click = false,
bool enable_scroll = false);
enum SCROLL_DIR { NONE, UP, DOWN, LEFT, RIGHT };
SCROLL_DIR getScrollDir(GdkEventScroll *e);
@ -37,6 +41,7 @@ class AModule : public IModule {
std::vector<int> pid_;
gdouble distance_scrolled_y_;
gdouble distance_scrolled_x_;
std::map<std::string, std::string> eventActionMap_;
static const inline std::map<std::pair<uint, GdkEventType>, std::string> eventMap_{
{std::make_pair(1, GdkEventType::GDK_BUTTON_PRESS), "on-click"},
{std::make_pair(1, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click"},

View File

@ -9,6 +9,7 @@ class IModule {
virtual ~IModule() = default;
virtual auto update() -> void = 0;
virtual operator Gtk::Widget&() = 0;
virtual auto doAction(const std::string& name) -> void = 0;
};
} // namespace waybar

View File

@ -15,26 +15,26 @@ enum class WeeksSide {
HIDDEN,
};
enum class CldMode { MONTH, YEAR };
enum class CldMode {
MONTH,
YEAR
};
class Clock : public ALabel {
class Clock final : public ALabel {
public:
Clock(const std::string&, const Json::Value&);
~Clock() = default;
auto update() -> void;
auto doAction(const std::string& name) -> void override;
private:
util::SleeperThread thread_;
std::map<std::pair<uint, GdkEventType>, void (waybar::modules::Clock::*)()> eventMap_;
std::locale locale_;
std::vector<const date::time_zone*> time_zones_;
int current_time_zone_idx_;
bool is_calendar_in_tooltip_;
bool is_timezoned_list_in_tooltip_;
bool handleScroll(GdkEventScroll* e);
bool handleToggle(GdkEventButton* const& e);
auto first_day_of_week() -> date::weekday;
const date::time_zone* current_timezone();
bool is_timezone_fixed();
@ -56,6 +56,20 @@ class Clock : public ALabel {
/*Calendar functions*/
auto get_calendar(const date::zoned_seconds& now, const date::zoned_seconds& wtime)
-> std::string;
/*Clock actions*/
void cldModeSwitch();
void cldShift_up();
void cldShift_down();
void tz_up();
void tz_down();
// ModuleActionMap
static inline std::map<const std::string, void(waybar::modules::Clock::* const)()> actionMap_{
{"mode", &waybar::modules::Clock::cldModeSwitch},
{"shift_up", &waybar::modules::Clock::cldShift_up},
{"shift_down", &waybar::modules::Clock::cldShift_down},
{"tz_up", &waybar::modules::Clock::tz_up},
{"tz_down", &waybar::modules::Clock::tz_down}
};
};
} // namespace waybar::modules