2019-02-10 10:35:19 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-11-24 12:28:52 +01:00
|
|
|
#include "ALabel.hpp"
|
2023-02-03 12:58:52 +01:00
|
|
|
#include "giomm/dbusproxy.h"
|
2019-02-10 10:35:19 +01:00
|
|
|
#include "util/json.hpp"
|
|
|
|
#include "util/sleeper_thread.hpp"
|
|
|
|
|
|
|
|
struct udev;
|
|
|
|
struct udev_device;
|
|
|
|
|
|
|
|
namespace waybar::modules {
|
|
|
|
|
2022-11-24 12:28:52 +01:00
|
|
|
class Backlight : public ALabel {
|
2019-02-10 10:35:19 +01:00
|
|
|
class BacklightDev {
|
2019-04-18 17:52:00 +02:00
|
|
|
public:
|
2019-02-10 10:35:19 +01:00
|
|
|
BacklightDev() = default;
|
2022-10-18 23:43:15 +02:00
|
|
|
BacklightDev(std::string name, int actual, int max, bool powered);
|
2022-04-06 08:37:19 +02:00
|
|
|
std::string_view name() const;
|
|
|
|
int get_actual() const;
|
|
|
|
void set_actual(int actual);
|
|
|
|
int get_max() const;
|
|
|
|
void set_max(int max);
|
2022-10-18 23:43:15 +02:00
|
|
|
bool get_powered() const;
|
|
|
|
void set_powered(bool powered);
|
2019-04-18 17:52:00 +02:00
|
|
|
friend inline bool operator==(const BacklightDev &lhs, const BacklightDev &rhs) {
|
|
|
|
return lhs.name_ == rhs.name_ && lhs.actual_ == rhs.actual_ && lhs.max_ == rhs.max_;
|
2019-02-10 10:35:19 +01:00
|
|
|
}
|
|
|
|
|
2019-04-18 17:52:00 +02:00
|
|
|
private:
|
2019-02-10 10:35:19 +01:00
|
|
|
std::string name_;
|
2022-04-06 08:37:19 +02:00
|
|
|
int actual_ = 1;
|
|
|
|
int max_ = 1;
|
2022-10-18 23:43:15 +02:00
|
|
|
bool powered_ = true;
|
2019-02-10 10:35:19 +01:00
|
|
|
};
|
|
|
|
|
2019-04-18 17:52:00 +02:00
|
|
|
public:
|
2019-02-10 10:35:19 +01:00
|
|
|
Backlight(const std::string &, const Json::Value &);
|
|
|
|
~Backlight();
|
|
|
|
auto update() -> void;
|
|
|
|
|
2019-04-18 17:52:00 +02:00
|
|
|
private:
|
2019-02-10 10:35:19 +01:00
|
|
|
template <class ForwardIt>
|
2019-04-18 17:52:00 +02:00
|
|
|
static const BacklightDev *best_device(ForwardIt first, ForwardIt last, std::string_view);
|
2019-02-10 10:35:19 +01:00
|
|
|
template <class ForwardIt, class Inserter>
|
2019-04-18 17:52:00 +02:00
|
|
|
static void upsert_device(ForwardIt first, ForwardIt last, Inserter inserter, udev_device *dev);
|
2019-02-10 10:35:19 +01:00
|
|
|
template <class ForwardIt, class Inserter>
|
2019-04-18 17:52:00 +02:00
|
|
|
static void enumerate_devices(ForwardIt first, ForwardIt last, Inserter inserter, udev *udev);
|
2019-02-10 10:35:19 +01:00
|
|
|
|
2023-02-01 14:40:36 +01:00
|
|
|
bool handleScroll(GdkEventScroll* e);
|
|
|
|
|
2022-04-06 08:37:19 +02:00
|
|
|
const std::string preferred_device_;
|
2019-02-10 10:35:19 +01:00
|
|
|
static constexpr int EPOLL_MAX_EVENTS = 16;
|
|
|
|
|
|
|
|
std::optional<BacklightDev> previous_best_;
|
2022-04-06 08:37:19 +02:00
|
|
|
std::string previous_format_;
|
2019-02-26 04:05:44 +01:00
|
|
|
|
2022-04-06 08:37:19 +02:00
|
|
|
std::mutex udev_thread_mutex_;
|
2019-02-26 04:05:44 +01:00
|
|
|
std::vector<BacklightDev> devices_;
|
|
|
|
// thread must destruct before shared data
|
2019-05-29 17:53:22 +02:00
|
|
|
util::SleeperThread udev_thread_;
|
2023-02-03 12:58:52 +01:00
|
|
|
|
|
|
|
Glib::RefPtr<Gio::DBus::Proxy> login_proxy_;
|
2019-02-10 10:35:19 +01:00
|
|
|
};
|
2019-04-18 17:52:00 +02:00
|
|
|
} // namespace waybar::modules
|