Restoring keyboard settings in Xorg environment after suspending

linux, udev, xorg

Solution

The problem was resolved by adding a custom script `/etc/pm/sleep.d/00-keyboard` that executes (not only) on system resume:

#!/bin/bash
case $1 in
  hibernate)
    # Going to suspend to disk
    ;;
  suspend)
    # Going to suspend to RAM
    ;;
  thaw)
    # Resuming after hibernating
    ;;
  resume)
    # Resuming after suspending
    echo "Restoring keyboard settings..."
    /opt/scripts/keyboard.sh
    ;;
  *)
    echo "Something went wrong"
    ;;
esac

For more information see https://wiki.archlinux.org/index.php/Pm-utils#Creating_your_own_hooks

Problem

I'm not using huge DE like Gnome or KDE and changing keyboard rate with `xset` command: ``` xset r rate 250 70 ``` But after system suspending (by `pm-suspend`) this settings are lost because udev removes and again adds all devices. I tried to use udev rules: ``` # /etc/udev/rules.d/00-custom-keyboard.rules ACTION=="add", SUBSYSTEM=="usb", RUN+="/usr/bin/xset r rate 250 70" # Not working ACTION=="add", SUBSYSTEM=="usb", RUN+="touch /tmp/test" # Working pretty! ``` I think the first rule is not working because `xset` utility requires some context data which is not available in the `evdev` context. I tried to use xorg config, but found only the option to change the keyboard layout, namely `XkbLayout` and `XkbOptions` Is there some way to automaticaly restore keyboard settings after system suspending?

Original source