Ubuntu – Run configuration script at X session resume


On Ubuntu 13.04 I have to manually configure the touchpad since a bug prevents me using the standard configuration tool (changes don't save). However I created a script that sets up velocity, acceleration and scrolling, configured it to run at sartup and it works. The problem rises when I resume after suspension: especially the scrolling settings (the easiest to check) disappear.
Following other questions and answers I wrote this script (which contains the same commands I used in the over-mentioned one) located in /etc/pm/sleep.d/ZZtouchpad:

case "$1" in
        xinput  --set-prop "CyPS/2 Cypress Trackpad" "Device Accel Constant Deceleration" 2
        xinput  --set-prop "CyPS/2 Cypress Trackpad" "Device Accel Velocity Scaling" 35
        xinput  --set-prop "CyPS/2 Cypress Trackpad" "Synaptics Scrolling Distance" -20, -20

But it doesn't work at all.

Thnks for help!


I found out that the script works when suspending with pm-suspend or pm-suspend-hybrid, but when suspending from the system menu or closing the laptop lid it doesn't. It seems the error is 'unable to connect to X server'.

So, the question better be rephrased: where should I put those commands for them to be executed when the X session is resumed? I tried ~/.xinitrc, a file under ~/.xinitrc.d and ~/.xsessionrc. Any suggestions?

Best Answer

  • I had a similar problem. The issue is to connect to the X server. I solved it by stealing from /etc/acpi/sleep.sh. Put the following into /etc/pm/sleep.d/99_setup_touchpad.

    #! /bin/sh
    . /usr/share/acpi-support/power-funcs
    case "$1" in
            if pidof xscreensaver > /dev/null; then
                for x in /tmp/.X11-unix/*; do
                    displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
                    if [ x"$XAUTHORITY" != x"" ]; then
                        export DISPLAY=":$displaynum"
                        su $user -c "xinput set-prop 'CyPS/2 Cypress Trackpad' 'Device Accel Constant Deceleration' 2"
                        su $user -c "xinput set-prop 'CyPS/2 Cypress Trackpad' 'Device Accel Velocity Scaling' 35"
                        su $user -c "xinput set-prop 'CyPS/2 Cypress Trackpad' 'Synaptics Scrolling Distance' -20, -20"
            # Nothing.

    Finally make the file executable: chmod 755 /etc/pm/sleep.d/99_setup_touchpad.

    Note: I'm usually the only one logged in via X on my laptop. So the loop is just one iteration. I don't know what happens if there are more than one sesssions live at the same time. The above is good enough for me.