My Laptop FN Keys
This post is just a note to myself. It is about the configuration of my laptop after installing a new OS (or configuring a new window manager in this case) which I keep forgetting. I realize that I need to configure the same items every time I do a fresh set-up, and I keep forgetting about long file paths and where to look for several settings files etc.
This post will serve me as look-up when I set up my system next time, maybe it is useful for someone else, by chance.
My set-up
I'm using an Asus zenbook UX31, running Parabola GNU/Linux and i3-gaps window manager
I have the following function (fn) keys, that tend to not work out of the box when installing a new OS/wm:
- F1: sleep
- F2: toggle WiFi
- F3: decrease keyboard backlight
- F4: increase keyboard backlight
- F5: decrease screen brightness
- F6: increase screen brightness
- F7: turn off screen
- F8: toggle alternate screen
- F9: disable touch pad
- F10: mute audio
- F11: decrease volume
- F12: increase volume
I usually don't need all of those, but especially the screen brightness, keyboard leds and audio keys are important to me. This is how I can set the appropriate keybindings:
Keyboard backlight leds
The file containing the keyboards leds' brightness is /sys/class/leds/asus::kbd_backlight/brightness
.
It contains just the number that represents the brightness level, which ranges from 0 (leds off) to 3 (max brightness). I've written a script to increase or decrease the level stepwise.
#!/bin/bash if [ -z $1 ]; then echo "usage $0 [-inc|-dec]" exit 1 fi PATH=/sys/class/leds/asus\:\:kbd_backlight/brightness OLD=$(/usr/bin/cat $PATH) if [ $1 == "-inc" ] then if [ $OLD -lt 3 ] then echo $(($OLD + 1)) > $PATH fi elif [ $1 == "-dec" ] then if [ $OLD -gt 0 ] then echo $(($OLD - 1)) > $PATH fi fi
or using Python:
#!/usr/bin/env python import sys path = "/sys/class/leds/asus::kbd_backlight/brightness" try: with open(path, 'r') as b_old: brightness = int(b_old.read()) except: sys.exit(1) if sys.argv[1] == "-inc" and brightness < 3: brightness += 1 elif sys.argv[1] == "-dec" and brightness > 0: brightness -= 1 try: with open(path, 'w') as b_new: b_new.write(str(brightness)) except: sys.exit(1)
Either script works the same way. You must be root to write the brightness file, however. To overcome this in my i3 .config, I modified the sudoers file
sudo visudo %robin ALL = NOPASSWD: \<path to script\>
This will allow me (Group robin) to execute the script without typing the sudo password. If you want to add this feature for all users on your machine, just add the users to users group and put that into the sudoers instead
usermod -aG users <username>
I can now add the keybinding to my .config file
bindsym $mod+F3 sudo exec set_kbd_backlight -dec bindsym $mod+F4 sudo exec set_kbd_backlight -inc
The keyboard backlight brightness was luckily the lengthiest part of all.
The screen brightness
The screen brightness can be adjusted with the xbacklight
tool. The commands for my i3 .config are
bindsym $mod+F5 exec xbacklight -dec 5 bindsym $mod+F6 exec xbacklight -inc 5
to decrease or increase the brightness by 5% each time.
Audio keys
I'm using pulseaudio per default. Although I heard about cpu consumption issues, I did not yet have reason to switch this to alsa only. The pulseaudio settings can be controlled with the pactl tool. The audio
sinks can be listed with pactl list short sinks
I only have one sink wich is labelled #0, so my keybindings in .config are
bindsym $mod+F10 exec pactl set-sink-mute 0 toggle bindsym $mod+F11 exec pactl set-sink-volume 0 -5% bindsym $mod+F12 exec pactl set-sink-volume 0 +5%
to toggle mute or decrease and increase the volume by 5% per keypress.