diff --git a/.gitignore b/.gitignore index 2e37e57e..56a2f73d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ vgcore.* *.swp packagecache /subprojects/**/ -/build +/build* /dist /meson.egg-info diff --git a/src/modules/backlight.cpp b/src/modules/backlight.cpp index e4bcf7c3..25eeaa2e 100644 --- a/src/modules/backlight.cpp +++ b/src/modules/backlight.cpp @@ -104,6 +104,18 @@ waybar::modules::Backlight::Backlight(const std::string &name, config["device"].isString() ? config["device"].asString() : "") { label_.set_name("backlight"); + // Get initial state + { + std::unique_ptr 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] { std::unique_ptr udev{udev_new()}; check_nn(udev.get(), "Udev new failed"); @@ -129,22 +141,6 @@ waybar::modules::Backlight::Backlight(const std::string &name, "epoll_ctl failed: {}"); epoll_event events[EPOLL_MAX_EVENTS]; - // Get initial state - { - decltype(devices_) devices; - { - std::scoped_lock lock(udev_thread_mutex_); - devices = devices_; - } - enumerate_devices(devices.begin(), devices.end(), - std::back_inserter(devices), udev.get()); - { - std::scoped_lock lock(udev_thread_mutex_); - devices_ = devices; - } - dp.emit(); - } - while (udev_thread_.isRunning()) { const int event_count = epoll_wait(epoll_fd.get(), events, EPOLL_MAX_EVENTS,