polybar/include/modules/xbacklight.hpp

64 lines
1.8 KiB
C++
Raw Normal View History

#pragma once
#include "components/config.hpp"
2017-01-11 02:07:28 +00:00
#include "settings.hpp"
#include "modules/meta/event_handler.hpp"
#include "modules/meta/input_handler.hpp"
2016-11-20 22:04:31 +00:00
#include "modules/meta/static_module.hpp"
2016-12-21 13:55:19 +00:00
#include "x11/extensions/randr.hpp"
2016-11-19 05:22:44 +00:00
POLYBAR_NS
2016-11-20 22:04:31 +00:00
class connection;
namespace modules {
/**
* Backlight module built using the RandR X extension.
*
* This is built as a replacement for the old backlight
* module that was set up using with inotify watches listening
* for changes to the raw file handle.
*
* This module is a lot faster, it's more responsive and it will
* be dormant until new values are reported. Inotify watches
* are a bit random when it comes to proc-/sysfs.
*
* TODO: Implement backlight configuring using scroll events
*/
class xbacklight_module : public static_module<xbacklight_module>,
public event_handler<evt::randr_notify>,
public input_handler {
public:
explicit xbacklight_module(const bar_settings& bar, string name_);
2016-11-20 22:04:31 +00:00
2016-11-02 19:22:45 +00:00
void update();
string get_output();
2016-11-25 12:55:15 +00:00
bool build(builder* builder, const string& tag) const;
protected:
void handle(const evt::randr_notify& evt);
2016-12-23 19:43:52 +00:00
bool input(string&& cmd);
private:
static constexpr const char* TAG_LABEL{"<label>"};
static constexpr const char* TAG_BAR{"<bar>"};
static constexpr const char* TAG_RAMP{"<ramp>"};
static constexpr const char* EVENT_SCROLLUP{"xbacklight+"};
static constexpr const char* EVENT_SCROLLDOWN{"xbacklight-"};
2016-11-20 22:04:31 +00:00
connection& m_connection;
monitor_t m_output;
2016-12-15 08:29:14 +00:00
xcb_window_t m_proxy{};
ramp_t m_ramp;
label_t m_label;
progressbar_t m_progressbar;
bool m_scroll{true};
std::atomic<int> m_percentage{0};
};
}
2016-11-19 05:22:44 +00:00
POLYBAR_NS_END