Brightness settings are targeting the wrong device

I am running Fedora 35 Workstation (Gnome) on a Panasonic CF-20 Toughbook. Using the brightness buttons or the brightness slider, do not have any effect on the actual display brightness.

Observations:

  • The hardware buttons (KEY_BRIGHTNESSDOWNand KEY_BRIGHTNESSUP) change value of the brightness slider
  • Both, the hardware button and the brightness slider change the value in /sys/class/backlight/panasonic/brightness
  • The display brightness only changes when altering the value in /sys/class/backlight/intel_backlight/brightness

How can I tell the system to use intel_backlight instead of panasonic for setting the display brightness?

Asking round in a few chats, I got pointed out to [SOLVED] How to change the Notebook LCD backlight brightness - Linux Mint Forums which then links to [SOLVED] How to change the Notebook LCD backlight brightness - Linux Mint Forums. The solution there is:

  • write a script watching the brightness of one device and mirroring changes to the other
  • have it started automatically as a systemd unit

I would have preferred a solution more in the direction of: hey, not that device, but that one. Using the mirroring script feels quite hacky.

Nonetheless, this is what I ended up with:

Content of file /usr/local/bin/redirect-brightness

#!/bin/bash

# NAME: redirect-brightness
# PATH: /usr/local/bin
# DESC: Redirect to correct driver when Ubuntu is adjusting the wrong
#       /sys/class/DRIVER_NAME/brightness

# DATE: June 13, 2018. Modified April 21, 2022.

# NOTE: Written for Ubuntu question:
#       https://askubuntu.com/q/1045624/307523
#       Updated for Fedora question:
#       https://ask.fedoraproject.org/t/brightness-settings-are-targeting-the-wrong-device/21445
#       Use together with systemd unit from:
#       https://forums.linuxmint.com/viewtopic.php?t=319948

WatchDriver="/sys/class/backlight/panasonic"
PatchDriver="/sys/class/backlight/intel_backlight"

# Must be running as sudo
if [[ $(id -u) != 0 ]]; then
    echo >&2 "Root access required. Use: 'sudo redirect-brightness'"
    exit 1
fi

# inotifywait required
type inotifywait >/dev/null 2>&1 || \
    { echo >&2 "'inotifywait' required but it's not installed.  Aborting."; \
      echo >&2 "Use 'sudo dnf install inotify-tools' to install it.'"; \
      exit 1; }

# Was right watch driver directory name setup correctly?
if [[ ! -d $WatchDriver ]]; then
    echo >&2 "Watch directory: '$WatchDriver'"; \
    echo >&2 "does not exist. Did you spell it correctly? Aborting.'"; \
    exit 1;
fi

# Was right patch driver directory name setup correctly?
if [[ ! -d $PatchDriver ]]; then
    echo >&2 "Redirect to directory: '$PatchDriver'"; \
    echo >&2 "does not exist. Did you spell it correctly? Aborting.'"; \
    exit 1;
fi

# Get maximum brightness values
WatchMax=$(<$WatchDriver/max_brightness)
PatchMax=$(<$PatchDriver/max_brightness)

# PARM: 1="-l" or "--log-file" then write each step to log file.
fLogFile=false
if [[ $1 == "-l" ]] || [[ $1 == "--log-file" ]]; then
    fLogFile=true
    LogFile=/tmp/redirect-brightness.log
    echo redirect-brightness LOG FILE > $LogFile
    echo WatchMax: $WatchMax PatchMax: $PatchMax >> $LogFile
fi

SetBrightness () {
    # Calculate watch current percentage
    WatchAct=$(<$WatchDriver/actual_brightness)
    WatchPer=$(( WatchAct * 100 / WatchMax ))
    [[ $fLogFile == true ]] && echo WatchAct: $WatchAct WatchPer: $WatchPer >> $LogFile
    # Reverse engineer patch brightness to set
    PatchAct=$(( PatchMax * WatchPer / 100 ))
    echo $PatchAct | sudo tee $PatchDriver/brightness
    [[ $fLogFile == true ]] && echo PatchAct: $PatchAct >> $LogFile
}

# When machine boots, set brightness to last saved value
SetBrightness

# Wait forever for user to press Fn keys adjusting brightness up/down.
while (true); do
    inotifywait --event modify $WatchDriver/actual_brightness
    [[ $fLogFile == true ]] && \
        echo "Processing modify event in $WatchDriver/actual_brightness" >> $LogFile
    SetBrightness
done

Make it executable and test it

sudo chmod + /usr/local/bin/redirect-brightness
sudo /usr/local/bin/redirect-brightness

Your system might miss some dependencies. Install them as told by the script.
Content of file /etc/systemd/system/redirect-brightness.service

[Unit]
Description=Redirect Backlight Brightness from one driver to another

[Service]
ExecStart=/usr/local/bin/redirect-brightness

[Install]
WantedBy=basic.target

Enable and start the systemd unit

sudo systemctl enable redirect-brightness
sudo systemctl start redirect-brightness