mirror of
				https://github.com/rad4day/Waybar.git
				synced 2025-10-29 23:22:41 +01:00 
			
		
		
		
	 b8322c4b4b
			
		
	
	b8322c4b4b
	
	
	
		
			
			The AButton class is designed as full a substitute to ALabel. The GtkButton attribute 'button_' is initialized with a label. This label can the be referenced by the subsequent inheritors of AButton instead of the GtkLabel attribute 'label_' of ALabel. For convenience a GtkLabel* 'label_' attribute is added to AButton. If the button cannot be clicked it is disabled, effectively acting like its label predecessor. GtkButton seems to catch one-click mouse events regardless of the flags set on it. Therefore, 'signal_pressed' is connected to a function creating a fake GdkEventButton* and calling 'handleToggle' (for details on this possible bug in GTK see: https://stackoverflow.com/questions/45334911 ) In accordance with other GtkButtons (i.e. the sway/workspace ones) set_relief(Gtk::RELIEF_NONE) is called on the 'button_' instance.
		
			
				
	
	
		
			57 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| #pragma once
 | |
| 
 | |
| #ifdef FILESYSTEM_EXPERIMENTAL
 | |
| #include <experimental/filesystem>
 | |
| #else
 | |
| #include <filesystem>
 | |
| #endif
 | |
| #include <fmt/format.h>
 | |
| #include <sys/inotify.h>
 | |
| 
 | |
| #include <algorithm>
 | |
| #include <fstream>
 | |
| #include <string>
 | |
| #include <vector>
 | |
| 
 | |
| #include "AButton.hpp"
 | |
| #include "util/sleeper_thread.hpp"
 | |
| 
 | |
| namespace waybar::modules {
 | |
| 
 | |
| #ifdef FILESYSTEM_EXPERIMENTAL
 | |
| namespace fs = std::experimental::filesystem;
 | |
| #else
 | |
| namespace fs = std::filesystem;
 | |
| #endif
 | |
| 
 | |
| class Battery : public AButton {
 | |
|  public:
 | |
|   Battery(const std::string&, const Json::Value&);
 | |
|   ~Battery();
 | |
|   auto update() -> void;
 | |
| 
 | |
|  private:
 | |
|   static inline const fs::path data_dir_ = "/sys/class/power_supply/";
 | |
| 
 | |
|   void refreshBatteries();
 | |
|   void worker();
 | |
|   const std::string getAdapterStatus(uint8_t capacity) const;
 | |
|   const std::tuple<uint8_t, float, std::string, float> getInfos();
 | |
|   const std::string formatTimeRemaining(float hoursRemaining);
 | |
| 
 | |
|   int global_watch;
 | |
|   std::map<fs::path, int> batteries_;
 | |
|   fs::path adapter_;
 | |
|   int battery_watch_fd_;
 | |
|   int global_watch_fd_;
 | |
|   std::mutex battery_list_mutex_;
 | |
|   std::string old_status_;
 | |
|   bool warnFirstTime_{true};
 | |
| 
 | |
|   util::SleeperThread thread_;
 | |
|   util::SleeperThread thread_battery_update_;
 | |
|   util::SleeperThread thread_timer_;
 | |
| };
 | |
| 
 | |
| }  // namespace waybar::modules
 |