2022-03-15 16:54:06 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <libupower-glib/upower.h>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "ALabel.hpp"
|
|
|
|
#include "gtkmm/box.h"
|
|
|
|
#include "gtkmm/image.h"
|
|
|
|
#include "gtkmm/label.h"
|
2022-03-19 16:09:55 +00:00
|
|
|
#include "modules/upower/upower_tooltip.hpp"
|
2022-03-15 16:54:06 +00:00
|
|
|
|
2022-03-19 16:09:55 +00:00
|
|
|
namespace waybar::modules::upower {
|
2022-03-15 16:54:06 +00:00
|
|
|
|
|
|
|
class UPower : public AModule {
|
|
|
|
public:
|
|
|
|
UPower(const std::string &, const Json::Value &);
|
|
|
|
~UPower();
|
|
|
|
auto update() -> void;
|
|
|
|
|
2022-03-19 16:09:55 +00:00
|
|
|
private:
|
2022-03-19 09:52:05 +00:00
|
|
|
typedef std::unordered_map<std::string, UpDevice *> Devices;
|
|
|
|
|
2022-03-15 16:54:06 +00:00
|
|
|
static void deviceAdded_cb(UpClient *client, UpDevice *device, gpointer data);
|
2022-03-19 09:52:05 +00:00
|
|
|
static void deviceRemoved_cb(UpClient *client, const gchar *objectPath, gpointer data);
|
|
|
|
static void deviceNotify_cb(UpDevice *device, GParamSpec *pspec, gpointer user_data);
|
2022-03-15 21:49:40 +00:00
|
|
|
static void prepareForSleep_cb(GDBusConnection *system_bus, const gchar *sender_name,
|
|
|
|
const gchar *object_path, const gchar *interface_name,
|
|
|
|
const gchar *signal_name, GVariant *parameters,
|
|
|
|
gpointer user_data);
|
2022-03-19 09:52:05 +00:00
|
|
|
void removeDevice(const gchar *objectPath);
|
2022-03-19 10:34:34 +00:00
|
|
|
void addDevice(UpDevice *device);
|
2022-03-15 16:54:06 +00:00
|
|
|
void setDisplayDevice();
|
|
|
|
void resetDevices();
|
2022-03-19 10:34:34 +00:00
|
|
|
void removeDevices();
|
2022-03-19 16:09:55 +00:00
|
|
|
bool show_tooltip_callback(int, int, bool, const Glib::RefPtr<Gtk::Tooltip> &tooltip);
|
2022-03-15 16:54:06 +00:00
|
|
|
|
|
|
|
Gtk::Box box_;
|
|
|
|
Gtk::Image icon_;
|
|
|
|
Gtk::Label label_;
|
|
|
|
|
2022-03-15 19:22:04 +00:00
|
|
|
// Config
|
|
|
|
bool hideIfEmpty = true;
|
2022-03-19 16:09:55 +00:00
|
|
|
bool tooltip_enabled = true;
|
|
|
|
uint tooltip_spacing = 4;
|
2022-03-19 10:19:08 +00:00
|
|
|
uint iconSize = 20;
|
2022-03-15 19:22:04 +00:00
|
|
|
|
2022-03-19 09:52:05 +00:00
|
|
|
Devices devices;
|
|
|
|
std::mutex m_Mutex;
|
|
|
|
UpClient *client;
|
|
|
|
UpDevice *displayDevice;
|
|
|
|
guint login1_id;
|
|
|
|
GDBusConnection *login1_connection;
|
2022-03-19 16:09:55 +00:00
|
|
|
UPowerTooltip *upower_tooltip;
|
2022-03-15 16:54:06 +00:00
|
|
|
};
|
|
|
|
|
2022-03-19 16:09:55 +00:00
|
|
|
} // namespace waybar::modules::upower
|