waybar/include/modules/upower/upower.hpp

73 lines
2.2 KiB
C++
Raw Normal View History

2022-03-15 17:54:06 +01:00
#pragma once
#include <libupower-glib/upower.h>
#include <iostream>
#include <map>
#include <string>
#include "ALabel.hpp"
#include "glibconfig.h"
2022-03-15 17:54:06 +01:00
#include "gtkmm/box.h"
#include "gtkmm/image.h"
#include "gtkmm/label.h"
#include "modules/upower/upower_tooltip.hpp"
2022-03-15 17:54:06 +01:00
namespace waybar::modules::upower {
2022-03-15 17:54:06 +01:00
class UPower : public AModule {
public:
UPower(const std::string &, const Json::Value &);
~UPower();
auto update() -> void;
private:
2022-03-19 10:52:05 +01:00
typedef std::unordered_map<std::string, UpDevice *> Devices;
const std::string DEFAULT_FORMAT = "{percentage}";
const std::string DEFAULT_FORMAT_ALT = "{percentage} {time}";
2022-03-15 17:54:06 +01:00
static void deviceAdded_cb(UpClient *client, UpDevice *device, gpointer data);
2022-03-19 10:52:05 +01:00
static void deviceRemoved_cb(UpClient *client, const gchar *objectPath, gpointer data);
static void deviceNotify_cb(UpDevice *device, GParamSpec *pspec, gpointer user_data);
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 10:52:05 +01:00
void removeDevice(const gchar *objectPath);
2022-03-19 11:34:34 +01:00
void addDevice(UpDevice *device);
2022-03-15 17:54:06 +01:00
void setDisplayDevice();
void resetDevices();
2022-03-19 11:34:34 +01:00
void removeDevices();
bool show_tooltip_callback(int, int, bool, const Glib::RefPtr<Gtk::Tooltip> &tooltip);
bool handleToggle(GdkEventButton *const &);
std::string timeToString(gint64 time);
2022-03-15 17:54:06 +01:00
2022-03-19 19:22:00 +01:00
const std::string getDeviceStatus(UpDeviceState &state);
2022-03-15 17:54:06 +01:00
Gtk::Box box_;
Gtk::Image icon_;
Gtk::Label label_;
// Config
bool hideIfEmpty = true;
bool tooltip_enabled = true;
uint tooltip_spacing = 4;
2022-03-21 13:50:46 +01:00
uint tooltip_padding = 4;
uint iconSize = 20;
std::string format = DEFAULT_FORMAT;
std::string format_alt = DEFAULT_FORMAT_ALT;
2022-03-19 10:52:05 +01:00
Devices devices;
std::mutex m_Mutex;
UpClient *client;
UpDevice *displayDevice;
guint login1_id;
GDBusConnection *login1_connection;
UPowerTooltip *upower_tooltip;
2022-03-19 19:22:00 +01:00
std::string lastStatus;
bool showAltText;
2022-03-15 17:54:06 +01:00
};
} // namespace waybar::modules::upower