You are not logged in.

#1 2018-02-25 03:40:45

Jont828
Member
Registered: 2018-01-12
Posts: 32

[GNOME] "xmodmap" resets after suspend

Hello, I am using xmodmap to remap some keys using "xmodmap ~/.Xmodmap," but the configuration resets after I suspend.

In .xinitrc, I have:
[[ -f /home/jont828/.Xmodmap ]] && xmodmap /home/jont828/.Xmodmap
exec gnome-session

In /usr/lib/systemd/system-sleep/my-script.sh, I have:
#!/bin/sh
case "$1" in
  post)
    xmodmap /home/jont828/.Xmodmap
    echo "Waking up at $(date)" >> /home/jont828/Desktop/test.txt
    # Place your post suspend (resume) commands here, or `exit 0` if no post suspend action required
    ;;
esac

I am trying to make it so it will reload the keymappings after I wake up my computer, but it's not working. The script responsds, however, because the echo with $(date) does output to test.txt. I also read the sleep hooks page, but in /etc/systemd/system, neither the file suspend@.service nor resume@.service exists. I am at a loss as to what to do. Any suggestions are more than welcome! Thanks!

Last edited by Jont828 (2018-02-25 05:49:01)

Offline

#2 2018-02-25 03:46:26

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,449
Website

Re: [GNOME] "xmodmap" resets after suspend

Your script isn't working as it is run as root and without DISPLAY set.  You might be able to work around those, but it'd be better to just do it right in the first place:

Jont828 wrote:

I also read the sleep hooks page, but in /etc/systemd/system, neither the file suspend@.service nor resume@.service exists.

wiki wrote:

Separate files should be created...

emphasis added


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2018-02-25 06:22:45

Jont828
Member
Registered: 2018-01-12
Posts: 32

Re: [GNOME] "xmodmap" resets after suspend

Thanks! So on the wiki, it also mentioned that separate files should be created for user actions and root/system actions. I saw on this thread that their service was put in ~/.config/systemd/user. Should I still put resume@.service in /etc/systemd/system?

I put resume@.service in /etc/systemd/system right now, and when I run "sudo systemctl start resume@jont828," I get the following error: "Failed to start resume@jont828.service: Unit resume@jont828.service is not loaded properly: Exec format error." Am I missing something? All I did was change the command in "ExecStart."

Offline

#4 2018-02-25 12:07:55

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,449
Website

Re: [GNOME] "xmodmap" resets after suspend

Jont828 wrote:

I saw on this thread that their service was put in ~/.config/systemd/user. Should I still put resume@.service in /etc/systemd/system?

Yes, that other thread is making an understandable mistake, but a mistake nonetheless.  There are system user services, that's not what these are.  You want to make a system service that just happens to take your username as a parameter.

Jont828 wrote:

I put resume@.service in /etc/systemd/system right now, and when I run "sudo systemctl start resume@jont828"

You should enable the service, not start it.  I'm not sure if that would explain the error you're getting, but first try just enabling it.  If you still have problems, post your service file(s).


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2018-02-26 16:54:17

Jont828
Member
Registered: 2018-01-12
Posts: 32

Re: [GNOME] "xmodmap" resets after suspend

I enabled the service but I got the following errors:

sudo systemctl start resume@jont828:

Failed to start resume@jont828.service: Unit resume@jont828.service is not loaded properly: Exec format error.
See system logs and 'systemctl status resume@jont828.service' for details.

sudo systemctl status resume@jont828:

● resume@jont828.service - User resume actions
   Loaded: error (Reason: Exec format error)
   Active: inactive (dead)

Feb 26 02:32:35 jonathan-thinkpad systemd[1]: /etc/systemd/system/resume@.service:8: Executable path is not absolute: xmodmap /home/jont828/.>
Feb 26 02:32:35 jonathan-thinkpad systemd[1]: resume@jont828.service: Cannot add dependency job, ignoring: Unit resume@jont828.service is not l>
Feb 26 11:07:07 jonathan-thinkpad systemd[1]: /etc/systemd/system/resume@.service:8: Executable path is not absolute: xmodmap /home/jont828/.>
Feb 26 11:07:07 jonathan-thinkpad systemd[1]: resume@jont828.service: Cannot add dependency job, ignoring: Unit resume@jont828.service is not l>
Feb 26 11:47:56 jonathan-thinkpad systemd[1]: /etc/systemd/system/resume@.service:8: Executable path is not absolute: xmodmap /home/jont828/.>
Feb 26 11:47:56 jonathan-thinkpad systemd[1]: resume@jont828.service: Unit configuration has fatal error, unit will not be started.
Feb 26 11:48:21 jonathan-thinkpad systemd[1]: /etc/systemd/system/resume@.service:8: Executable path is not absolute: xmodmap /home/jont828/.>
Feb 26 11:48:21 jonathan-thinkpad systemd[1]: resume@jont828.service: Unit configuration has fatal error, unit will not be started.
Feb 26 11:48:29 jonathan-thinkpad systemd[1]: /etc/systemd/system/resume@.service:8: Executable path is not absolute: xmodmap /home/jont828/.>
Feb 26 11:48:29 jonathan-thinkpad systemd[1]: resume@jont828.service: Unit configuration has fatal error, unit will not be started.

/etc/systemd/system/resume@.service

[Unit]
Description=User resume actions
After=suspend.target

[Service]
User=jont828
Type=simple
ExecStart=xmodmap /home/jont828/.Xmodmap

[Install]
WantedBy=suspend.target

Offline

#6 2018-02-28 02:34:24

Jont828
Member
Registered: 2018-01-12
Posts: 32

Re: [GNOME] "xmodmap" resets after suspend

Hey, quick update. I've almost got it working! So I followed the error message from my previous post and changed "ExecStart=xmodmap /home/jont828/.Xmodmap" to ExecStart=/usr/bin/xmodmap /home/jont828/.Xmodmap" because it wanted an absolute path. I then enabled the service. So far, using "sudo systemctl status resume@jont828," I can see from the time stamps that it ran the service and logged "Started User resume actions" when I wake up from suspend. However, the changes don't seem to stick. The service runs, but once I'm given the password prompt, the changes are reset. Anyone know what to do about this? Do I need to be running xmodmap at a different time or under a different user or something? Thanks!

Offline

#7 2018-02-28 03:05:08

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,449
Website

Re: [GNOME] "xmodmap" resets after suspend

You will need the Environment line from the example in the wiki specifying your DISPLAY:

Environment=DISPLAY=:0

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB