Laptop: MacbookPro 11,5 with AMD gpu
OS: Lubuntu 17.04
I followed the instruction at https://wiki.archlinux.org/index.php/MacBookPro11,x and it worked.
- disable automatic gpu switching in MacOS X (not sure if that helped).
- download and compile https://github.com/problame/gmux_backlight
sudo setpci -v -H1 -s 00:01.00 BRIDGE_CONTROL=0sudo gmux_backlight 120- can adjust brightness with script.
The problem is that
- Have to use
sudoeverytime - The F1/F2 key do not change brightness.
How to fix this?
Update (following terdon's answer)
Moved the compiled gmux_backlight to /usr/sbin/
Used sudo visudo to let each of the user run gmux_backlight with sudo and without entering password.
<username1> ALL=NOPASSWD:/usr/sbin/gmux_backlight
<username2> ALL=NOPASSWD:/usr/sbin/gmux_backlight
<username3> ALL=NOPASSWD:/usr/sbin/gmux_backlight
Create /etc/init.d/gmux_backlight_fix and sudo chmod +x the script.
#!/bin/bash -e
setpci -v -H1 -s 00:01.00 BRIDGE_CONTROL=0 >/dev/null
Symlink the script to run level 2 (the grpahical run level for Ubuntu) with lowest priority (99) by following How to run a script during boot as root.
sudo ln -s /etc/init.d/gmux_backlight_fix /etc/rc2.d/S99gmux_backlight_fix
Added to section of ~/.config/openbox/lubuntu-rc.xml for each user.
<keyboard>
<chainQuitKey>C-g</chainQuitKey>
<!-- My Keys -->
<keybind key="XF86LaunchA">
<action name="Execute">
<command>sudo gmux_backlight -10</command>
</action>
</keybind>
<keybind key="XF86LaunchB">
<action name="Execute">
<command>sudo gmux_backlight +10</command>
</action>
</keybind>
I use Fn-F3 and Fn-F4 because Lubuntu can not automatically detect Fn-F1 and Fn-F2 on the laptop.
Initially I wrote a bash script that takes argument and grant every user to run it with sudo. A while later, I worry that people can break the bash script and run any command with sudo privilege. So I use the compiled binary instead of my bash script.
The old bash script is /usr/sbin/gmux_capped_backlight:
#!/bin/bash -e
# setpci
setpci -v -H1 -s 00:01.00 BRIDGE_CONTROL=0 >/dev/null
# Get current brightness
CB="$( cat /sys/class/backlight/gmux_backlight/brightness )"
# Split characters of argument
arg=$1
first_char=${arg:0:1}
other_char=${arg:1}
# Desired Brightness
if [ $first_char == "+" ]; then
Brightness=$(expr $CB + $other_char)
elif [ $first_char == "-" ]; then
Brightness=$(expr $CB - $other_char)
else
Brightness=$arg
fi
# Limit the range of brightness #
Max=1024
Min=0
if [ $Brightness -gt $Max ]; then
Brightness=$Max
fi
if [ $Brightness -lt $Min ]; then
Brightness=$Min
fi