backlight: auto-detect default card (#2728)

* auto-detect a default backlight

* Implemented suggestions

* added changelog

* Implemented suggestions

* Fix changelog formatting

Co-authored-by: patrick96 <p.ziegler96@gmail.com>
This commit is contained in:
raffael0 2022-06-16 12:54:38 +02:00 committed by GitHub
parent b2c5d8e0e2
commit f3e27a205e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- `internal/fs`: Use `/` as a fallback if no mountpoints are specified ([`#2572`](https://github.com/polybar/polybar/issues/2572), [`#2705`](https://github.com/polybar/polybar/pull/2705))
- `internal/backlight`: Detect backlight if none specified ([`#2572`](https://github.com/polybar/polybar/issues/2572), [`#2728`](https://github.com/polybar/polybar/pull/2728))
### Fixed
- Waiting for double click interval on modules that don't have a double click action ([`#2663`](https://github.com/polybar/polybar/issues/2663), [`#2695`](https://github.com/polybar/polybar/pull/2695))

View File

@ -27,9 +27,28 @@ namespace modules {
: inotify_module<backlight_module>(bar, move(name_)) {
m_router->register_action(EVENT_DEC, [this]() { action_dec(); });
m_router->register_action(EVENT_INC, [this]() { action_inc(); });
auto card = m_conf.get(name(), "card", ""s);
if (card.empty()) {
vector<string> backlight_card_names = file_util::list_files(string_util::replace(PATH_BACKLIGHT, "%card%", ""));
backlight_card_names.erase(std::remove_if(backlight_card_names.begin(), backlight_card_names.end(),
[&](const string& card) -> bool {
auto dir = string_util::replace(PATH_BACKLIGHT, "%card%", card);
return !(file_util::is_file(dir + "/actual_brightness") &&
file_util::is_file(dir + "/brightness") &&
file_util::is_file(dir + "/max_brightness"));
}),
backlight_card_names.end());
auto card = m_conf.get(name(), "card");
if (backlight_card_names.empty()) {
throw module_error("no viable default backlight found");
}
card = backlight_card_names.at(0);
if (backlight_card_names.size() > 1) {
m_log.warn("%s: multiple backlights found, using %s", name(), card);
} else {
m_log.info("%s: no backlight specified, using `%s`", name(), card);
}
}
// Get flag to check if we should add scroll handlers for changing value
m_scroll = m_conf.get(name(), "enable-scroll", m_scroll);