mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Battery event (#18)
This commit is contained in:
@ -15,7 +15,7 @@ namespace waybar {
|
||||
class Factory {
|
||||
public:
|
||||
Factory(Bar &bar, Json::Value config);
|
||||
IModule &makeModule(std::string name);
|
||||
IModule *makeModule(std::string name);
|
||||
private:
|
||||
Bar &_bar;
|
||||
Json::Value _config;
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <fmt/format.h>
|
||||
#include <sys/inotify.h>
|
||||
#include "util/chrono.hpp"
|
||||
#include "IModule.hpp"
|
||||
|
||||
@ -18,7 +19,7 @@ namespace waybar::modules {
|
||||
auto update() -> void;
|
||||
operator Gtk::Widget&();
|
||||
private:
|
||||
std::string _getIcon(uint32_t percentage);
|
||||
std::string _getIcon(uint16_t percentage);
|
||||
static inline const fs::path _data_dir = "/sys/class/power_supply/";
|
||||
std::vector<fs::path> _batteries;
|
||||
util::SleeperThread _thread;
|
||||
|
@ -39,7 +39,9 @@ namespace waybar::util {
|
||||
func();
|
||||
} while (do_run);
|
||||
}}
|
||||
{}
|
||||
{
|
||||
defined = true;
|
||||
}
|
||||
|
||||
SleeperThread& operator=(std::function<void()> func)
|
||||
{
|
||||
@ -48,6 +50,7 @@ namespace waybar::util {
|
||||
func();
|
||||
} while (do_run);
|
||||
});
|
||||
defined = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -72,14 +75,17 @@ namespace waybar::util {
|
||||
~SleeperThread()
|
||||
{
|
||||
do_run = false;
|
||||
condvar.notify_all();
|
||||
thread.join();
|
||||
if (defined) {
|
||||
condvar.notify_all();
|
||||
thread.join();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::thread thread;
|
||||
std::condition_variable condvar;
|
||||
std::mutex mutex;
|
||||
bool defined = false;
|
||||
bool do_run = true;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user