2022-03-15 16:54:06 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <libupower-glib/upower.h>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2022-05-23 16:23:00 +00:00
|
|
|
#include <unordered_map>
|
2022-03-15 16:54:06 +00:00
|
|
|
|
|
|
|
#include "ALabel.hpp"
|
2022-03-19 20:15:48 +00:00
|
|
|
#include "glibconfig.h"
|
2022-03-15 16:54:06 +00:00
|
|
|
#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 &);
|
2023-03-02 13:57:07 +00:00
|
|
|
virtual ~UPower();
|
|
|
|
auto update() -> void override;
|
2022-03-15 16:54:06 +00:00
|
|
|
|
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-19 20:15:48 +00:00
|
|
|
const std::string DEFAULT_FORMAT = "{percentage}";
|
|
|
|
const std::string DEFAULT_FORMAT_ALT = "{percentage} {time}";
|
|
|
|
|
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-25 16:27:36 +00:00
|
|
|
static void upowerAppear(GDBusConnection *conn, const gchar *name, const gchar *name_owner,
|
|
|
|
gpointer data);
|
|
|
|
static void upowerDisappear(GDBusConnection *connection, const gchar *name, gpointer user_data);
|
|
|
|
|
2022-04-06 06:37:19 +00:00
|
|
|
void removeDevice(const gchar *objectPath);
|
|
|
|
void addDevice(UpDevice *device);
|
|
|
|
void setDisplayDevice();
|
|
|
|
void resetDevices();
|
|
|
|
void removeDevices();
|
|
|
|
bool show_tooltip_callback(int, int, bool, const Glib::RefPtr<Gtk::Tooltip> &tooltip);
|
2023-03-02 13:57:07 +00:00
|
|
|
bool handleToggle(GdkEventButton *const &) override;
|
2022-03-19 20:15:48 +00:00
|
|
|
std::string timeToString(gint64 time);
|
2022-03-15 16:54:06 +00:00
|
|
|
|
2022-03-19 18:22:00 +00:00
|
|
|
const std::string getDeviceStatus(UpDeviceState &state);
|
|
|
|
|
2022-04-06 06:37:19 +00:00
|
|
|
Gtk::Box box_;
|
2022-03-15 16:54:06 +00:00
|
|
|
Gtk::Image icon_;
|
|
|
|
Gtk::Label label_;
|
|
|
|
|
2022-03-15 19:22:04 +00:00
|
|
|
// Config
|
2022-04-06 06:37:19 +00:00
|
|
|
bool hideIfEmpty = true;
|
|
|
|
bool tooltip_enabled = true;
|
|
|
|
uint tooltip_spacing = 4;
|
|
|
|
uint tooltip_padding = 4;
|
|
|
|
uint iconSize = 20;
|
2022-03-19 20:15:48 +00:00
|
|
|
std::string format = DEFAULT_FORMAT;
|
|
|
|
std::string format_alt = DEFAULT_FORMAT_ALT;
|
2022-03-15 19:22:04 +00:00
|
|
|
|
2022-04-06 06:37:19 +00:00
|
|
|
Devices devices;
|
|
|
|
std::mutex m_Mutex;
|
|
|
|
UpClient *client;
|
2024-01-22 08:22:19 +00:00
|
|
|
UpDevice *displayDevice = nullptr;
|
2022-04-06 06:37:19 +00:00
|
|
|
guint login1_id;
|
2022-03-19 09:52:05 +00:00
|
|
|
GDBusConnection *login1_connection;
|
2023-10-22 23:14:52 +00:00
|
|
|
std::unique_ptr<UPowerTooltip> upower_tooltip;
|
2022-04-06 06:37:19 +00:00
|
|
|
std::string lastStatus;
|
2024-03-18 10:47:43 +00:00
|
|
|
const char *lastWarningLevel;
|
2022-04-06 06:37:19 +00:00
|
|
|
bool showAltText;
|
2023-11-28 18:39:08 +00:00
|
|
|
bool showIcon = true;
|
2022-04-06 06:37:19 +00:00
|
|
|
bool upowerRunning;
|
|
|
|
guint upowerWatcher_id;
|
2023-06-09 15:22:01 +00:00
|
|
|
std::string nativePath_;
|
2022-03-15 16:54:06 +00:00
|
|
|
};
|
|
|
|
|
2022-03-19 16:09:55 +00:00
|
|
|
} // namespace waybar::modules::upower
|