waybar/include/AModule.hpp

69 lines
2.8 KiB
C++
Raw Permalink Normal View History

2019-06-15 14:57:52 +02:00
#pragma once
#include <glibmm/dispatcher.h>
#include <glibmm/markup.h>
#include <gtkmm/eventbox.h>
#include <json/json.h>
2019-06-15 14:57:52 +02:00
#include "IModule.hpp"
namespace waybar {
class AModule : public IModule {
public:
virtual ~AModule();
2023-03-02 14:57:07 +01:00
auto update() -> void override;
2023-01-23 09:25:02 +01:00
virtual auto refresh(int) -> void{};
2023-03-02 14:57:07 +01:00
operator Gtk::Widget &() override;
2023-04-03 09:41:24 +02:00
auto doAction(const std::string &name) -> void override;
2019-06-15 14:57:52 +02:00
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);
2019-06-15 14:57:52 +02:00
enum SCROLL_DIR { NONE, UP, DOWN, LEFT, RIGHT };
SCROLL_DIR getScrollDir(GdkEventScroll *e);
2022-04-06 08:37:19 +02:00
bool tooltipEnabled();
2019-06-15 14:57:52 +02:00
2022-04-06 08:37:19 +02:00
const std::string name_;
2019-06-15 14:57:52 +02:00
const Json::Value &config_;
2022-04-06 08:37:19 +02:00
Gtk::EventBox event_box_;
2019-06-15 14:57:52 +02:00
virtual bool handleToggle(GdkEventButton *const &ev);
virtual bool handleScroll(GdkEventScroll *);
private:
std::vector<int> pid_;
2022-04-06 08:37:19 +02:00
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_{
2022-04-06 08:37:19 +02:00
{std::make_pair(1, GdkEventType::GDK_BUTTON_PRESS), "on-click"},
2023-08-13 18:20:43 +02:00
{std::make_pair(1, GdkEventType::GDK_BUTTON_RELEASE), "on-click-release"},
2022-04-06 08:37:19 +02:00
{std::make_pair(1, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click"},
{std::make_pair(1, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click"},
{std::make_pair(2, GdkEventType::GDK_BUTTON_PRESS), "on-click-middle"},
2023-08-13 18:20:43 +02:00
{std::make_pair(2, GdkEventType::GDK_BUTTON_RELEASE), "on-click-middle-release"},
2022-04-06 08:37:19 +02:00
{std::make_pair(2, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-middle"},
{std::make_pair(2, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-middle"},
{std::make_pair(3, GdkEventType::GDK_BUTTON_PRESS), "on-click-right"},
2023-08-13 18:20:43 +02:00
{std::make_pair(3, GdkEventType::GDK_BUTTON_RELEASE), "on-click-right-release"},
2022-04-06 08:37:19 +02:00
{std::make_pair(3, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-right"},
{std::make_pair(3, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-right"},
{std::make_pair(8, GdkEventType::GDK_BUTTON_PRESS), "on-click-backward"},
2023-08-13 18:20:43 +02:00
{std::make_pair(8, GdkEventType::GDK_BUTTON_RELEASE), "on-click-backward-release"},
2022-04-06 08:37:19 +02:00
{std::make_pair(8, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-backward"},
{std::make_pair(8, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-backward"},
2022-04-06 08:37:19 +02:00
{std::make_pair(9, GdkEventType::GDK_BUTTON_PRESS), "on-click-forward"},
2023-08-13 18:20:43 +02:00
{std::make_pair(9, GdkEventType::GDK_BUTTON_RELEASE), "on-click-forward-release"},
2022-04-06 08:37:19 +02:00
{std::make_pair(9, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-forward"},
{std::make_pair(9, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-forward"}};
2019-06-15 14:57:52 +02:00
};
} // namespace waybar