9

I am using Ubuntu 14.04.

I have a custom Xmodmap keyboard layout. However, when I resume after suspend, the layout is gone.

I have tried all things which were mentioned in the answers to this question: How do I set Xmodmap on login?

Neither using .xinitrc nor adding a command in the startup apps works. Well, they do work after a usual reboot, but not after suspend.

Is there a file that is always execute after loggin in, no matter if it was a reboot or a resume from suspension?

3

2 Answers 2

4

@i08in https://askubuntu.com/a/92235/72576 seems to do the job.

This is what I ended up with on my Debian jessie, KDE.

/etc/pm/sleep.d/20_xmodmap.sh

case "${1}" in
    resume|thaw)
        su $USER -c "sleep 3; /usr/bin/xmodmap /home/$USER/.Xmodmap" &
;;
esac

Note: At first it may seem to not work, but just give it a minute or so. There seems to be something with X that cuses this delay, though I haven't cared enough to check on it... See https://superuser.com/q/626769/185360 for more info.

1
  • Don't forget to mark your script as executable. Additionally, on my machine I can do away with the "sleep 3", so you may want to fiddle with the duration in an attempt to reduce the delay without affecting the operation of the script.
    – fouric
    Aug 6, 2015 at 17:27
0

All of it is a bullshit code all around. Are you guys really don't have no problems with an XAUTHORITY and DISPLAY? I don't believe that. So here's the really working solution (remember to replace $USER with your username):

step 1. Generate your ".Xmodmap" file with the mapping, in my case it is:

keycode 96 = XF86AudioLowerVolume
keycode 95 = XF86AudioMute
keycode 76 = XF86AudioNext
keycode 75 = XF86AudioPlay
keycode 74 = XF86AudioPrev

and place it under /home/$USER/.Xmodmap path

step 2. Create a startup application preference (go to Startup Application Preferences from super-button search menu) and add the following:

Name: xmodmap
Command: /bin/bash -c "sleep 7 && xmodmap ~/.Xmodmap"
Comment: 

and Save it. And close the Startup Application Preferences

step 3. now go to /usr/lib/systemd/system-sleep folder, like this:

cd /usr/lib/systemd/system-sleep 

step 4. create a file named "xkeyboard.sh", you can do it like this (sudo rights are required):

sudo touch xkeyboard.sh

step 5. now get your $XAUTHORITY variable value, you can do it like this:

echo $XAUTHORITY

in my case it returned me the following:

/run/user/1000/gdm/Xauthority

write it down somewhere

step 6. open up your newely created file for editing, you can do it like this:

sudo nano xkeyboard.sh

step 7: paste this code. Make sure to replace $USER with your username and $XAUTH with the variable you wrote down before:

   #!/bin/bash

    echo "Running xkeyboard.sh with argument: $1" >> /tmp/xkeyboard.log
    
    if [ "${1}" == "pre" ]; then
        echo "pre" >> /tmp/xkeyboard.log
        # Nothing to do for pre-sleep
    elif [ "${1}" == "post" ]; then
        echo "post" >> /tmp/xkeyboard.log
        export DISPLAY=:0  # Set the DISPLAY variable
        export XAUTHORITY=$XAUTH
        /bin/bash -c "sleep 7 && xmodmap home/$USER/.Xmodmap" >> /tmp/xkeyboard.log 2>&1
    fi

in this code i've added up logging to /tmp/xkeyboard.log file, so if keyboard mapping doesn't work, you can go there and checkout what's the matter.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .