From 2b31a3f11285fd98eb9b66c3d779c6850de51912 Mon Sep 17 00:00:00 2001 From: patrick96 Date: Tue, 15 Oct 2019 16:39:18 +0200 Subject: [PATCH] fix(backlight): Use 'brightness' with amdgpu_bl0 The amdgpu driver seems to set 'actual_brightness' wrong. Fixes #1870 Ref: https://github.com/Alexays/Waybar/issues/335 --- cmake/02-opts.cmake | 6 ++---- include/settings.hpp.cmake | 3 +-- src/modules/backlight.cpp | 17 +++++++++++++---- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/cmake/02-opts.cmake b/cmake/02-opts.cmake index 61e8613e..16506a7c 100644 --- a/cmake/02-opts.cmake +++ b/cmake/02-opts.cmake @@ -67,10 +67,8 @@ set(SETTING_CONNECTION_TEST_IP "8.8.8.8" CACHE STRING "Address to ping when testing network connection") set(SETTING_PATH_ADAPTER "/sys/class/power_supply/%adapter%" CACHE STRING "Path to adapter") -set(SETTING_PATH_BACKLIGHT_MAX "/sys/class/backlight/%card%/max_brightness" - CACHE STRING "Path to file containing the maximum backlight value") -set(SETTING_PATH_BACKLIGHT_VAL "/sys/class/backlight/%card%/actual_brightness" - CACHE STRING "Path to file containing the current backlight value") +set(SETTING_PATH_BACKLIGHT "/sys/class/backlight/%card%" + CACHE STRING "Path to backlight sysfs folder") set(SETTING_PATH_BATTERY "/sys/class/power_supply/%battery%" CACHE STRING "Path to battery") set(SETTING_PATH_CPU_INFO "/proc/stat" diff --git a/include/settings.hpp.cmake b/include/settings.hpp.cmake index 62dd905e..39aca327 100644 --- a/include/settings.hpp.cmake +++ b/include/settings.hpp.cmake @@ -64,8 +64,7 @@ static constexpr const char* BSPWM_SOCKET_PATH{"@SETTING_BSPWM_SOCKET_PATH@"}; static constexpr const char* BSPWM_STATUS_PREFIX{"@SETTING_BSPWM_STATUS_PREFIX@"}; static constexpr const char* CONNECTION_TEST_IP{"@SETTING_CONNECTION_TEST_IP@"}; static constexpr const char* PATH_ADAPTER{"@SETTING_PATH_ADAPTER@"}; -static constexpr const char* PATH_BACKLIGHT_MAX{"@SETTING_PATH_BACKLIGHT_MAX@"}; -static constexpr const char* PATH_BACKLIGHT_VAL{"@SETTING_PATH_BACKLIGHT_VAL@"}; +static constexpr const char* PATH_BACKLIGHT{"@SETTING_PATH_BACKLIGHT@"}; static constexpr const char* PATH_BATTERY{"@SETTING_PATH_BATTERY@"}; static constexpr const char* PATH_CPU_INFO{"@SETTING_PATH_CPU_INFO@"}; static constexpr const char* PATH_MEMORY_INFO{"@SETTING_PATH_MEMORY_INFO@"}; diff --git a/src/modules/backlight.cpp b/src/modules/backlight.cpp index 3562fad5..2a47b336 100644 --- a/src/modules/backlight.cpp +++ b/src/modules/backlight.cpp @@ -40,12 +40,21 @@ namespace modules { m_ramp = load_ramp(m_conf, name(), TAG_RAMP); } - // Build path to the file where the current/maximum brightness value is located - m_val.filepath(string_util::replace(PATH_BACKLIGHT_VAL, "%card%", card)); - m_max.filepath(string_util::replace(PATH_BACKLIGHT_MAX, "%card%", card)); + // Build path to the sysfs folder the current/maximum brightness values are located + auto path_backlight = string_util::replace(PATH_BACKLIGHT, "%card%", card); + + /* + * amdgpu drivers set the actual_brightness in a different scale than [0, max_brightness] + * The only sensible way is to use the 'brightness' file instead + * Ref: https://github.com/Alexays/Waybar/issues/335 + */ + auto path_backlight_val = path_backlight + "/" + (card == "amdgpu_bl0"? "brightness" : "actual_brightness"); + + m_val.filepath(path_backlight_val); + m_max.filepath(path_backlight + "/max_brightness"); // Add inotify watch - watch(string_util::replace(PATH_BACKLIGHT_VAL, "%card%", card)); + watch(path_backlight_val); } void backlight_module::idle() {