|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <libupower-glib/upower.h> |
| 4 | + |
| 5 | +#include <iostream> |
| 6 | +#include <map> |
| 7 | +#include <string> |
| 8 | + |
| 9 | +#include "ALabel.hpp" |
| 10 | +#include "glibconfig.h" |
| 11 | +#include "gtkmm/box.h" |
| 12 | +#include "gtkmm/image.h" |
| 13 | +#include "gtkmm/label.h" |
| 14 | +#include "modules/upower/upower_tooltip.hpp" |
| 15 | + |
| 16 | +namespace waybar::modules::upower { |
| 17 | + |
| 18 | +class UPower : public AModule { |
| 19 | + public: |
| 20 | + UPower(const std::string &, const Json::Value &); |
| 21 | + ~UPower(); |
| 22 | + auto update() -> void; |
| 23 | + |
| 24 | + private: |
| 25 | + typedef std::unordered_map<std::string, UpDevice *> Devices; |
| 26 | + |
| 27 | + const std::string DEFAULT_FORMAT = "{percentage}"; |
| 28 | + const std::string DEFAULT_FORMAT_ALT = "{percentage} {time}"; |
| 29 | + |
| 30 | + static void deviceAdded_cb(UpClient *client, UpDevice *device, gpointer data); |
| 31 | + static void deviceRemoved_cb(UpClient *client, const gchar *objectPath, gpointer data); |
| 32 | + static void deviceNotify_cb(UpDevice *device, GParamSpec *pspec, gpointer user_data); |
| 33 | + static void prepareForSleep_cb(GDBusConnection *system_bus, const gchar *sender_name, |
| 34 | + const gchar *object_path, const gchar *interface_name, |
| 35 | + const gchar *signal_name, GVariant *parameters, |
| 36 | + gpointer user_data); |
| 37 | + void removeDevice(const gchar *objectPath); |
| 38 | + void addDevice(UpDevice *device); |
| 39 | + void setDisplayDevice(); |
| 40 | + void resetDevices(); |
| 41 | + void removeDevices(); |
| 42 | + bool show_tooltip_callback(int, int, bool, const Glib::RefPtr<Gtk::Tooltip> &tooltip); |
| 43 | + bool handleToggle(GdkEventButton *const &); |
| 44 | + std::string timeToString(gint64 time); |
| 45 | + |
| 46 | + const std::string getDeviceStatus(UpDeviceState &state); |
| 47 | + |
| 48 | + Gtk::Box box_; |
| 49 | + Gtk::Image icon_; |
| 50 | + Gtk::Label label_; |
| 51 | + |
| 52 | + // Config |
| 53 | + bool hideIfEmpty = true; |
| 54 | + bool tooltip_enabled = true; |
| 55 | + uint tooltip_spacing = 4; |
| 56 | + uint tooltip_padding = 4; |
| 57 | + uint iconSize = 20; |
| 58 | + std::string format = DEFAULT_FORMAT; |
| 59 | + std::string format_alt = DEFAULT_FORMAT_ALT; |
| 60 | + |
| 61 | + Devices devices; |
| 62 | + std::mutex m_Mutex; |
| 63 | + UpClient *client; |
| 64 | + UpDevice *displayDevice; |
| 65 | + guint login1_id; |
| 66 | + GDBusConnection *login1_connection; |
| 67 | + UPowerTooltip *upower_tooltip; |
| 68 | + std::string lastStatus; |
| 69 | + bool showAltText; |
| 70 | +}; |
| 71 | + |
| 72 | +} // namespace waybar::modules::upower |
0 commit comments