mirror of
				https://github.com/rad4day/Waybar.git
				synced 2025-10-31 07:52:42 +01:00 
			
		
		
		
	Added custom tooltip with device icon, device name and battery status
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
							
								
								
									
										29
									
								
								include/modules/upower/upower_tooltip.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								include/modules/upower/upower_tooltip.hpp
									
									
									
									
									
										Normal 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 | ||||
		Reference in New Issue
	
	Block a user
	 Erik Reider
					Erik Reider