0

I have an xmodmap file ~/.Xmodmap and it works perfectly. I put it in the startup applications app in ubuntu 19.10 like this xmodmap /home/yasser/.Xmodmap and it works when first booting up. However, after suspend, the file just doesn't work. I tried creating a script in /usr/lib/pm-utils/sleep.d/999zxmodmap with this content:

#!/bin/bash

    case $1 in
        pre)
            exit 0
        ;;
        post)
            export DISPLAY=:0
            sleep 10
            xmodmap /home/yasser/.Xmodmap
        ;;
    esac

I saw this suggested somewhere else, but this didn't work. Here is my ~/.Xmodmap file if that can help:

keycode 66 = Mode_switch
keysym j = j J Left
keysym l = l L Right
keysym i = i I Up
keysym k = k K Down
keysym h = h H Home
keysym semicolon = semicolon colon End

Thanks a lot in advance for your help.

0

Try adding this line just after your export DISPLAY=:0 line:

export XAUTHORITY=/home/yasser/.Xauthority

When an X11 GUI session is started, ~/.Xmodmap is automatically read as the user logging in.

But when /usr/lib/pm-utils/sleep.d/999zxmodmap is executed after resuming from suspend, it is executed as root.

Like any X11 application, the xmodmap command needs two things to access the GUI session: the DISPLAY environment variable, and the X11 session cookie (= a key of sorts). By default, the session cookie is stored in ~/.Xauthority and it is recreated on every X11 login. When your script runs the xmodmap command as root, it will look for the session cookie in /root/.Xauthority... which is not the right place to look if the currently logged-in user is yasser.

Fortunately, you can use the XAUTHORITY environment variable to tell X11 applications to find the session cookie in a non-standard location... and because root can access everything, the xmodmap command running as root will be able to read yasser's cookie file.

| improve this answer | |
  • Thanks but unfortunately that didn't work as well. a question though, when I checked my home folder ` ~/.Xauthority` is not there, is that normal? – Yasser Apr 17 at 23:57
  • Your distribution might routinely place it in a non-default location: run echo $XAUTHORITY in a terminal window in your regular GUI session and then adjust the value in the script to match. – telcoM Apr 17 at 23:59
  • I found it in /run/user/1000/gdm/Xauthority and changed accordingly but still not working I don't understand why. anyways thanks for your help and if you have any other suggestion let me knnow please. – Yasser Apr 18 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.