2019-06-15 12:57:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <glibmm/dispatcher.h>
|
2024-02-22 18:06:41 +00:00
|
|
|
#include <gtkmm/gestureclick.h>
|
|
|
|
#include <gtkmm/eventcontrollerscroll.h>
|
2019-06-15 12:57:52 +00:00
|
|
|
#include <json/json.h>
|
2020-05-27 07:10:38 +00:00
|
|
|
|
2019-06-15 12:57:52 +00:00
|
|
|
#include "IModule.hpp"
|
|
|
|
|
|
|
|
namespace waybar {
|
|
|
|
|
|
|
|
class AModule : public IModule {
|
|
|
|
public:
|
2024-02-15 06:04:42 +00:00
|
|
|
static constexpr const char *MODULE_CLASS = "module";
|
|
|
|
|
2019-06-15 12:57:52 +00:00
|
|
|
virtual ~AModule();
|
2023-03-02 13:57:07 +00:00
|
|
|
auto update() -> void override;
|
2023-01-23 08:25:02 +00:00
|
|
|
virtual auto refresh(int) -> void{};
|
2023-03-02 13:57:07 +00:00
|
|
|
operator Gtk::Widget &() override;
|
2023-04-03 07:41:24 +00:00
|
|
|
auto doAction(const std::string &name) -> void override;
|
2019-06-15 12:57:52 +00:00
|
|
|
|
2023-10-17 16:11:48 +00:00
|
|
|
/// Emitting on this dispatcher triggers a update() call
|
2019-06-15 12:57:52 +00:00
|
|
|
Glib::Dispatcher dp;
|
|
|
|
|
|
|
|
protected:
|
2023-02-28 12:32:28 +00:00
|
|
|
// 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);
|
2022-04-06 06:37:19 +00:00
|
|
|
const std::string name_;
|
2019-06-15 12:57:52 +00:00
|
|
|
const Json::Value &config_;
|
2024-02-24 17:32:14 +00:00
|
|
|
Glib::RefPtr<Gtk::GestureClick> controllClick_;
|
|
|
|
Glib::RefPtr<Gtk::EventControllerScroll> controllScroll_;
|
2024-02-26 17:54:52 +00:00
|
|
|
|
|
|
|
void bindEvents(Gtk::Widget& wg);
|
|
|
|
bool tooltipEnabled();
|
|
|
|
|
2024-02-22 18:06:41 +00:00
|
|
|
virtual void handleToggle(int n_press, double dx, double dy);
|
|
|
|
virtual void handleRelease(int n_press, double dx, double dy);
|
|
|
|
virtual bool handleScroll(double dx, double dy);
|
2019-06-15 12:57:52 +00:00
|
|
|
|
|
|
|
private:
|
2024-02-26 17:54:52 +00:00
|
|
|
enum SCROLL_DIR { NONE, UP, DOWN, LEFT, RIGHT };
|
2023-11-10 14:57:26 +00:00
|
|
|
const bool isTooltip;
|
2019-06-15 12:57:52 +00:00
|
|
|
std::vector<int> pid_;
|
2024-02-22 18:06:41 +00:00
|
|
|
double distance_scrolled_x_{0.0};
|
2024-02-24 17:32:14 +00:00
|
|
|
double distance_scrolled_y_{0.0};
|
2024-02-22 18:06:41 +00:00
|
|
|
Glib::RefPtr<const Gdk::Event> currEvent_;
|
2023-02-28 12:32:28 +00:00
|
|
|
std::map<std::string, std::string> eventActionMap_;
|
2024-02-22 18:06:41 +00:00
|
|
|
static const inline std::map<std::pair<std::pair<uint, int>,Gdk::Event::Type>, std::string> eventMap_ {
|
|
|
|
{std::make_pair(std::make_pair(1u, 1), Gdk::Event::Type::BUTTON_PRESS), "on-click"},
|
|
|
|
{std::make_pair(std::make_pair(1u, 1), Gdk::Event::Type::BUTTON_RELEASE), "on-click-release"},
|
|
|
|
{std::make_pair(std::make_pair(1u, 2), Gdk::Event::Type::BUTTON_PRESS), "on-double-click"},
|
|
|
|
{std::make_pair(std::make_pair(1u, 3), Gdk::Event::Type::BUTTON_PRESS), "on-triple-click"},
|
|
|
|
{std::make_pair(std::make_pair(2u, 1), Gdk::Event::Type::BUTTON_PRESS), "on-click-middle"},
|
|
|
|
{std::make_pair(std::make_pair(2u, 1), Gdk::Event::Type::BUTTON_RELEASE), "on-click-middle-release"},
|
|
|
|
{std::make_pair(std::make_pair(2u, 2), Gdk::Event::Type::BUTTON_PRESS), "on-double-click-middle"},
|
|
|
|
{std::make_pair(std::make_pair(2u, 3), Gdk::Event::Type::BUTTON_PRESS), "on-triple-click-middle"},
|
|
|
|
{std::make_pair(std::make_pair(3u, 1), Gdk::Event::Type::BUTTON_PRESS), "on-click-right"},
|
|
|
|
{std::make_pair(std::make_pair(3u, 1), Gdk::Event::Type::BUTTON_RELEASE), "on-click-right-release"},
|
|
|
|
{std::make_pair(std::make_pair(3u, 2), Gdk::Event::Type::BUTTON_PRESS), "on-double-click-right"},
|
|
|
|
{std::make_pair(std::make_pair(3u, 3), Gdk::Event::Type::BUTTON_PRESS), "on-triple-click-right"},
|
|
|
|
{std::make_pair(std::make_pair(8u, 1), Gdk::Event::Type::BUTTON_PRESS), "on-click-backward"},
|
|
|
|
{std::make_pair(std::make_pair(8u, 1), Gdk::Event::Type::BUTTON_RELEASE), "on-click-backward-release"},
|
|
|
|
{std::make_pair(std::make_pair(8u, 2), Gdk::Event::Type::BUTTON_PRESS), "on-double-click-backward"},
|
|
|
|
{std::make_pair(std::make_pair(8u, 3), Gdk::Event::Type::BUTTON_PRESS), "on-triple-click-backward"},
|
|
|
|
{std::make_pair(std::make_pair(9u, 1), Gdk::Event::Type::BUTTON_PRESS), "on-click-forward"},
|
|
|
|
{std::make_pair(std::make_pair(9u, 1), Gdk::Event::Type::BUTTON_RELEASE), "on-click-forward-release"},
|
|
|
|
{std::make_pair(std::make_pair(9u, 2), Gdk::Event::Type::BUTTON_PRESS), "on-double-click-forward"},
|
|
|
|
{std::make_pair(std::make_pair(9u, 3), Gdk::Event::Type::BUTTON_PRESS), "on-triple-click-forward"}
|
|
|
|
};
|
|
|
|
void handleClickEvent(uint n_button, int n_press, Gdk::Event::Type n_evtype);
|
|
|
|
const SCROLL_DIR getScrollDir(Glib::RefPtr<const Gdk::Event> e);
|
2019-06-15 12:57:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace waybar
|