You are not logged in.

#1 2019-05-02 01:36:05

zw963
Member
Registered: 2018-06-18
Posts: 213

Xmodmap(or xkb settings) invalid after wake up from suspend in Xorg

Hi, all.

i am suspend to system with a bash function in command line.

suspend ()
{
    echo -n mem | sudo tee /sys/power/state
}

after wake up, i found swap capslock/ctrl is invalid, which is work
before suspend.

Question: how to make capslock/ctrl keep working even wake up from suspend?

Following is some attempt, but no luck. (maybe wrong)

1. create a executable script /usr/lib/systemd/system-sleep/run_xmodmap, no work.

#!/bin/bash

case $1 in
    pre)
        echo 'enter suspend' > /tmp/enter_suspend
        ;;
    post)
         xmodmap /home/zw963/.Xmodmap
         echo 'enter suspend' > /tmp/exit_suspend
        /home/zw963/Dropbox/common/sh/say
esac

And run `systemctl suspend`, and wake up, script in post is executed,
but Ctrl is not swapped as expected.


The same issue happen on following command which invalid after suspend.

gsettings set org.gnome.desktop.interface gtk-key-theme Emacs

Thanks

--------------

BTW: I use xorgs, and bumblebee.

Last edited by zw963 (2019-05-02 01:41:56)

Offline

#2 2019-05-02 06:13:04

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,517

Re: Xmodmap(or xkb settings) invalid after wake up from suspend in Xorg

The keyboard gets (virtually) re-attached, you'd have to go for xkb configuration in an xorg configlet: https://wiki.archlinux.org/index.php/Xo … tion_files
As for xmodmap, the sleep hooks (as well as udev rules, if you wanted) run as root and w/o any knowledge of the X11 server, ie. you'll have to "sudo -u zw963" and also (typically) "export DISPLAY=:0"
Here's nice script to fetch the relevant environment variables from the xinit process, you'll have to adjust that if you're not using xinit: https://gist.github.com/AladW/de1c5676d93d05a5a0e1

Offline

#3 2019-05-03 04:50:58

zw963
Member
Registered: 2018-06-18
Posts: 213

Re: Xmodmap(or xkb settings) invalid after wake up from suspend in Xorg

> Here's nice script to fetch the relevant environment variables from the xinit process, you'll have to adjust that if you're not using xinit: https://gist.github.com/AladW/de1c5676d93d05a5a0e1

This function not owrk for me, e.g. $DISPlAY wrong result, i use GDM.

DISPLAY=:1BASH_FUNC_my_editor_open%%=() {  local ln=${line_number++}${line_number};

Following is code:

        pid=$(pgrep -t tty$(fgconsole) gdm)
        pid=$(pgrep -P $pid -n)
        echo $pid
        
        import_environment() {
            (( pid )) && for var; do
                IFS='=' read key val < <(egrep -z "$var" /proc/$pid/environ)
                
                printf -v "$key" %s "$val"
                [[ ${!key} ]] && export "$key"
            done
        }
        
        import_environment XAUTHORITY USER DISPLAY

> As for xmodmap, the sleep hooks (as well as udev rules, if you wanted) run as root and w/o any knowledge of the X11 server, ie. you'll have to "sudo -u zw963" and also (typically) "export DISPLAY=:0"

After add following code to /usr/lib/systemd/system-sleep/run_xmodmap, still not work

case $1 in
    pre)
        echo 'enter suspend' > /tmp/enter_suspend
        ;;
    post)
        export DISPLAY=:1  # <= this DISPLAY before suspend
        sudo -u zw963 xmodmap /home/zw963/.Xmodmap &> /tmp/exit_suspend # <= no see any error here.
esac

Thanks

Last edited by zw963 (2019-05-03 04:53:46)

Offline

#4 2019-05-03 07:26:36

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,517

Re: Xmodmap(or xkb settings) invalid after wake up from suspend in Xorg

Because GDM runs on DISPLAY :0 and spawns your session on DISPLAY :1
sudo will drop the environment, you'll have to set it there. Eg. using "env"

Offline

Board footer

Powered by FluxBB