mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
refactor: AModule
This commit is contained in:
@ -1,42 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <glibmm/markup.h>
|
||||
#include <gtkmm/eventbox.h>
|
||||
#include <gtkmm/label.h>
|
||||
#include <json/json.h>
|
||||
#include "IModule.hpp"
|
||||
#include "AModule.hpp"
|
||||
|
||||
namespace waybar {
|
||||
|
||||
class ALabel : public IModule {
|
||||
class ALabel : public AModule {
|
||||
public:
|
||||
ALabel(const Json::Value &, const std::string &, const std::string &, const std::string &format,
|
||||
uint16_t interval = 0);
|
||||
virtual ~ALabel();
|
||||
virtual ~ALabel() = default;
|
||||
virtual auto update() -> void;
|
||||
virtual std::string getIcon(uint16_t, const std::string &alt = "", uint16_t max = 0);
|
||||
virtual operator Gtk::Widget &();
|
||||
|
||||
protected:
|
||||
bool tooltipEnabled();
|
||||
|
||||
Gtk::EventBox event_box_;
|
||||
Gtk::Label label_;
|
||||
const Json::Value & config_;
|
||||
std::string format_;
|
||||
std::string click_param;
|
||||
std::mutex mutex_;
|
||||
const std::chrono::seconds interval_;
|
||||
bool alt_ = false;
|
||||
std::string default_format_;
|
||||
|
||||
virtual bool handleToggle(GdkEventButton *const &ev);
|
||||
virtual bool handleScroll(GdkEventScroll *);
|
||||
virtual bool handleToggle(GdkEventButton *const &e);
|
||||
virtual std::string getState(uint8_t value, bool lesser = false);
|
||||
|
||||
private:
|
||||
std::vector<int> pid_;
|
||||
gdouble distance_scrolled_;
|
||||
};
|
||||
|
||||
} // namespace waybar
|
||||
|
40
include/AModule.hpp
Normal file
40
include/AModule.hpp
Normal file
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <glibmm/dispatcher.h>
|
||||
#include <glibmm/markup.h>
|
||||
#include <gtkmm/eventbox.h>
|
||||
#include <json/json.h>
|
||||
#include "IModule.hpp"
|
||||
|
||||
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 operator Gtk::Widget &();
|
||||
|
||||
Glib::Dispatcher dp;
|
||||
|
||||
protected:
|
||||
enum SCROLL_DIR { NONE, UP, DOWN, LEFT, RIGHT };
|
||||
|
||||
SCROLL_DIR getScrollDir(GdkEventScroll *e);
|
||||
bool tooltipEnabled();
|
||||
|
||||
const Json::Value &config_;
|
||||
Gtk::EventBox event_box_;
|
||||
std::string click_param_;
|
||||
std::mutex mutex_;
|
||||
|
||||
virtual bool handleToggle(GdkEventButton *const &ev);
|
||||
virtual bool handleScroll(GdkEventScroll *);
|
||||
|
||||
private:
|
||||
std::vector<int> pid_;
|
||||
gdouble distance_scrolled_;
|
||||
};
|
||||
|
||||
} // namespace waybar
|
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <glibmm/dispatcher.h>
|
||||
#include <gtkmm/box.h>
|
||||
#include <gtkmm/widget.h>
|
||||
|
||||
namespace waybar {
|
||||
@ -11,7 +9,6 @@ class IModule {
|
||||
virtual ~IModule() = default;
|
||||
virtual auto update() -> void = 0;
|
||||
virtual operator Gtk::Widget &() = 0;
|
||||
Glib::Dispatcher dp; // Hmmm Maybe I should create an abstract class ?
|
||||
};
|
||||
|
||||
} // namespace waybar
|
||||
|
@ -4,8 +4,9 @@
|
||||
#include <gtkmm/cssprovider.h>
|
||||
#include <gtkmm/main.h>
|
||||
#include <gtkmm/window.h>
|
||||
#include <gtkmm/box.h>
|
||||
#include <json/json.h>
|
||||
#include "IModule.hpp"
|
||||
#include "AModule.hpp"
|
||||
#include "idle-inhibit-unstable-v1-client-protocol.h"
|
||||
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
||||
#include "xdg-output-unstable-v1-client-protocol.h"
|
||||
@ -73,9 +74,9 @@ class Bar {
|
||||
Gtk::Box center_;
|
||||
Gtk::Box right_;
|
||||
Gtk::Box box_;
|
||||
std::vector<std::unique_ptr<waybar::IModule>> modules_left_;
|
||||
std::vector<std::unique_ptr<waybar::IModule>> modules_center_;
|
||||
std::vector<std::unique_ptr<waybar::IModule>> modules_right_;
|
||||
std::vector<std::unique_ptr<waybar::AModule>> modules_left_;
|
||||
std::vector<std::unique_ptr<waybar::AModule>> modules_center_;
|
||||
std::vector<std::unique_ptr<waybar::AModule>> modules_right_;
|
||||
};
|
||||
|
||||
} // namespace waybar
|
||||
|
@ -37,7 +37,7 @@ namespace waybar {
|
||||
class Factory {
|
||||
public:
|
||||
Factory(const Bar& bar, const Json::Value& config);
|
||||
IModule* makeModule(const std::string& name) const;
|
||||
AModule* makeModule(const std::string& name) const;
|
||||
|
||||
private:
|
||||
const Bar& bar_;
|
||||
|
@ -28,7 +28,7 @@ class Pulseaudio : public ALabel {
|
||||
pa_threaded_mainloop* mainloop_;
|
||||
pa_mainloop_api* mainloop_api_;
|
||||
pa_context* context_;
|
||||
bool scrolling_;
|
||||
std::mutex mutex_;
|
||||
// SINK
|
||||
uint32_t sink_idx_{0};
|
||||
uint16_t volume_;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include "IModule.hpp"
|
||||
#include "AModule.hpp"
|
||||
#include "bar.hpp"
|
||||
#include "modules/sni/host.hpp"
|
||||
#include "modules/sni/watcher.hpp"
|
||||
@ -9,19 +9,17 @@
|
||||
|
||||
namespace waybar::modules::SNI {
|
||||
|
||||
class Tray : public IModule {
|
||||
class Tray : public AModule {
|
||||
public:
|
||||
Tray(const std::string&, const Bar&, const Json::Value&);
|
||||
~Tray() = default;
|
||||
auto update() -> void;
|
||||
operator Gtk::Widget&();
|
||||
|
||||
private:
|
||||
void onAdd(std::unique_ptr<Item>& item);
|
||||
void onRemove(std::unique_ptr<Item>& item);
|
||||
|
||||
static inline std::size_t nb_hosts_ = 0;
|
||||
const Json::Value& config_;
|
||||
Gtk::Box box_;
|
||||
SNI::Watcher watcher_;
|
||||
SNI::Host host_;
|
||||
|
@ -26,7 +26,6 @@ class Window : public ALabel, public sigc::trackable {
|
||||
void getTree();
|
||||
|
||||
const Bar& bar_;
|
||||
std::mutex mutex_;
|
||||
std::string window_;
|
||||
int windowId_;
|
||||
std::string app_id_;
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <fmt/format.h>
|
||||
#include <gtkmm/button.h>
|
||||
#include <gtkmm/label.h>
|
||||
#include "IModule.hpp"
|
||||
#include "AModule.hpp"
|
||||
#include "bar.hpp"
|
||||
#include "client.hpp"
|
||||
#include "modules/sway/ipc/client.hpp"
|
||||
@ -12,12 +12,11 @@
|
||||
|
||||
namespace waybar::modules::sway {
|
||||
|
||||
class Workspaces : public IModule, public sigc::trackable {
|
||||
class Workspaces : public AModule, public sigc::trackable {
|
||||
public:
|
||||
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
~Workspaces() = default;
|
||||
auto update() -> void;
|
||||
operator Gtk::Widget&();
|
||||
|
||||
private:
|
||||
void onCmd(const struct Ipc::ipc_response&);
|
||||
@ -33,15 +32,11 @@ class Workspaces : public IModule, public sigc::trackable {
|
||||
bool handleScroll(GdkEventScroll*);
|
||||
|
||||
const Bar& bar_;
|
||||
const Json::Value& config_;
|
||||
std::vector<Json::Value> workspaces_;
|
||||
std::vector<std::string> workspaces_order_;
|
||||
std::mutex mutex_;
|
||||
Gtk::Box box_;
|
||||
util::JsonParser parser_;
|
||||
bool scrolling_;
|
||||
std::unordered_map<std::string, Gtk::Button> buttons_;
|
||||
gdouble distance_scrolled_;
|
||||
|
||||
util::SleeperThread thread_;
|
||||
Ipc ipc_;
|
||||
|
Reference in New Issue
Block a user