Added custom tooltip with device icon, device name and battery status

This commit is contained in:
Erik Reider
2022-03-19 17:09:55 +01:00
parent 4196e0d5d1
commit 7fac2afb85
6 changed files with 229 additions and 18 deletions

View File

@ -10,8 +10,9 @@
#include "gtkmm/box.h"
#include "gtkmm/image.h"
#include "gtkmm/label.h"
#include "modules/upower/upower_tooltip.hpp"
namespace waybar::modules {
namespace waybar::modules::upower {
class UPower : public AModule {
public:
@ -19,9 +20,9 @@ class UPower : public AModule {
~UPower();
auto update() -> void;
private:
typedef std::unordered_map<std::string, UpDevice *> Devices;
private:
static void deviceAdded_cb(UpClient *client, UpDevice *device, gpointer data);
static void deviceRemoved_cb(UpClient *client, const gchar *objectPath, gpointer data);
static void deviceNotify_cb(UpDevice *device, GParamSpec *pspec, gpointer user_data);
@ -34,6 +35,7 @@ class UPower : public AModule {
void setDisplayDevice();
void resetDevices();
void removeDevices();
bool show_tooltip_callback(int, int, bool, const Glib::RefPtr<Gtk::Tooltip> &tooltip);
Gtk::Box box_;
Gtk::Image icon_;
@ -41,6 +43,8 @@ class UPower : public AModule {
// Config
bool hideIfEmpty = true;
bool tooltip_enabled = true;
uint tooltip_spacing = 4;
uint iconSize = 20;
Devices devices;
@ -49,6 +53,7 @@ class UPower : public AModule {
UpDevice *displayDevice;
guint login1_id;
GDBusConnection *login1_connection;
UPowerTooltip *upower_tooltip;
};
} // namespace waybar::modules
} // namespace waybar::modules::upower

View File

@ -0,0 +1,29 @@
#pragma once
#include <libupower-glib/upower.h>
#include "gtkmm/box.h"
#include "gtkmm/label.h"
#include "gtkmm/window.h"
namespace waybar::modules::upower {
class UPowerTooltip : public Gtk::Window {
private:
typedef std::unordered_map<std::string, UpDevice*> Devices;
std::string getDeviceIcon(UpDeviceKind& kind);
Gtk::Box* contentBox;
uint iconSize;
uint tooltipSpacing;
public:
UPowerTooltip(uint iconSize, uint tooltipSpacing);
~UPowerTooltip();
uint updateTooltip(Devices& devices);
};
} // namespace waybar::modules::upower