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=0
sudo gmux_backlight 120
- can adjust brightness with script.
The problem is that
- Have to use
sudo
everytime - 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
Fn
+F1
andFn
+F2
insted ofF1
/F2
because your F1 and F2 keys would never reach normal apps. Obviously, this would be OP oversight and not yours. But I'm curious ifxbindkeys
can trapFn
+Fx
as I've never tried it and it might make a great user-friendly GUI project down the road to link key combos to scripts. – WinEunuuchs2Unix Jul 09 '17 at 00:07xbindkeys -k
, to be sure. And yes, it can bind them. On my keyboard, for example, which has a function key, that's recognized. – terdon Jul 09 '17 at 00:10xbindkeys
recognizesFn
key combos. I'm just so used to other OS's not being able to recognize that in the past. – WinEunuuchs2Unix Jul 09 '17 at 00:14terdon
. And yes, it is a risk. To make it slightly less risky, put the script in a directory other users don't have write access to, like/usr/local/bin
. The real danger here is someone maliciously changing the script to something destructive (considerrm -rf /usr /etc /lib
for example). Since you run it withsudo
, anything dangerous put in there will be run with elevated privileges. Saving it in/usr/bin
makes that harder to do. – terdon Jul 09 '17 at 23:46