From 8e04f15ed6cab970822bb4766900229e13e5b12a Mon Sep 17 00:00:00 2001 From: Patrick Ziegler Date: Sat, 20 Jan 2024 18:09:12 +0100 Subject: [PATCH] fix(backlight): %backlight% token appearing on the bar (#3081) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix backlight initial value matching the actual brightness level The initial value is `0`. If the actual brightness is also `0` you see `%percentage%` token as text, it’s not being replaced. Since `m_brightness` is an `int` the initial value could be just `-1` since the actual brightness is never goes below zero. Thus this bug will never show up again because actual brightness on first render won’t match the “old” `m_brightness` value. See also for more detailed explanation of the bug: https://github.com/polybar/polybar/discussions/3079#discussioncomment-8169932 * Add docs --------- Co-authored-by: Viacheslav Lotsmanov --- CHANGELOG.md | 2 ++ include/modules/backlight.hpp | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 386452a2..010b678f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- `internal/backlight`: Module could display the literal `%percentage%` token if the backlight reports a value of 0 at startup ([`#3081`](https://github.com/polybar/polybar/pull/3081)) by [@unclechu](https://github.com/unclechu) ## [3.7.1] - 2023-11-27 ### Build diff --git a/include/modules/backlight.hpp b/include/modules/backlight.hpp index 685814dd..f878643d 100644 --- a/include/modules/backlight.hpp +++ b/include/modules/backlight.hpp @@ -67,7 +67,12 @@ namespace modules { brightness_handle m_val; brightness_handle m_max; - int m_percentage = 0; + /** + * Initial value set to a negative number so that any value read from the backlight file triggers an update during + * the first read. + * Otherwise, tokens may not be replaced + */ + int m_percentage = -1; chrono::duration m_interval{}; chrono::steady_clock::time_point m_lastpoll;