Merge pull request #199 from ianhattendorf/fix/backlight-disable-not-found

Disable backlight module if no backlights found
This commit is contained in:
Alex 2019-03-01 09:31:49 +01:00 committed by GitHub
commit 2c411b9848
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 17 deletions

2
.gitignore vendored
View File

@ -5,7 +5,7 @@ vgcore.*
*.swp *.swp
packagecache packagecache
/subprojects/**/ /subprojects/**/
/build /build*
/dist /dist
/meson.egg-info /meson.egg-info

View File

@ -104,6 +104,18 @@ waybar::modules::Backlight::Backlight(const std::string &name,
config["device"].isString() ? config["device"].asString() : "") { config["device"].isString() ? config["device"].asString() : "") {
label_.set_name("backlight"); label_.set_name("backlight");
// Get initial state
{
std::unique_ptr<udev, UdevDeleter> udev_check{udev_new()};
check_nn(udev_check.get(), "Udev check new failed");
enumerate_devices(devices_.begin(), devices_.end(),
std::back_inserter(devices_), udev_check.get());
if (devices_.empty()) {
throw std::runtime_error("No backlight found");
}
dp.emit();
}
udev_thread_ = [this] { udev_thread_ = [this] {
std::unique_ptr<udev, UdevDeleter> udev{udev_new()}; std::unique_ptr<udev, UdevDeleter> udev{udev_new()};
check_nn(udev.get(), "Udev new failed"); check_nn(udev.get(), "Udev new failed");
@ -129,22 +141,6 @@ waybar::modules::Backlight::Backlight(const std::string &name,
"epoll_ctl failed: {}"); "epoll_ctl failed: {}");
epoll_event events[EPOLL_MAX_EVENTS]; epoll_event events[EPOLL_MAX_EVENTS];
// Get initial state
{
decltype(devices_) devices;
{
std::scoped_lock<std::mutex> lock(udev_thread_mutex_);
devices = devices_;
}
enumerate_devices(devices.begin(), devices.end(),
std::back_inserter(devices), udev.get());
{
std::scoped_lock<std::mutex> lock(udev_thread_mutex_);
devices_ = devices;
}
dp.emit();
}
while (udev_thread_.isRunning()) { while (udev_thread_.isRunning()) {
const int event_count = const int event_count =
epoll_wait(epoll_fd.get(), events, EPOLL_MAX_EVENTS, epoll_wait(epoll_fd.get(), events, EPOLL_MAX_EVENTS,