Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restoring keyboard settings in Xorg environment after suspending

Tags:

linux

xorg

udev

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.

  1. 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.

  2. 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?

like image 557
user1051870 Avatar asked Jul 23 '13 08:07

user1051870


1 Answers

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

like image 147
user1051870 Avatar answered Oct 16 '22 02:10

user1051870