You are not logged in.

#1 2018-11-02 19:00:07

rukumar333
Member
Registered: 2017-01-10
Posts: 12

setxkbmap does not persist after putting machine on sleep mode

I have a script which swaps the ctrl key and caps lock key (for emacs). Here are the contents of the script:

setxkbmap -option ctrl:swapcaps

It is contained in a script swap-ctrl.sh which I then added to my startup applications on Cinnamon. When I first turn on my machine, the two keys are swapped. However, when I put my laptop on sleep mode and then awaken it, the changes do not persist and I have to run the script manually. However, this does not always happen. Sometimes the changes do persist. If any additional information would be helpful, let me know and I can post it here. Thanks!

Offline

#2 2018-11-02 22:07:46

seth
Member
Registered: 2012-09-03
Posts: 30,970

Re: setxkbmap does not persist after putting machine on sleep mode

Your keyboard gets de- and re-attached (usually USB related)
You could either put that option into an xorg configlet (so it will automatically apply to all matching keyboards when added) or add it as systemd sleep hook (for the latter you'll have to manage the DISPLAY variable and the calling UID, since the hooks run as root)

Offline

#3 2018-11-02 22:16:27

rukumar333
Member
Registered: 2017-01-10
Posts: 12

Re: setxkbmap does not persist after putting machine on sleep mode

Not sure if this matters, but my keyboard is not attached via USB, it is just the regular keyboard that is on my laptop. I will try the two things that you mentioned though.

Offline

#4 2018-11-02 22:27:37

seth
Member
Registered: 2012-09-03
Posts: 30,970

Re: setxkbmap does not persist after putting machine on sleep mode

USB is not a plug, but a bus.
Check "lsusb" on whether your keyboard is there.

Offline

#5 2018-11-02 22:38:41

rukumar333
Member
Registered: 2017-01-10
Posts: 12

Re: setxkbmap does not persist after putting machine on sleep mode

This is the output of lsusb:

Bus 002 Device 002: ID 8087:8000 Intel Corp. 
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:8008 Intel Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 003: ID 8087:07dc Intel Corp. 
Bus 003 Device 002: ID 174f:1474 Syntek 
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Also, what exactly do I have to do with the DISPLAY variable and calling UID? I created the sleep hook but since I did not do anything with those, I am getting the following error:

Nov 02 18:32:57 keyblade systemd[15299]: resume@rushil.service: Failed to execute command: Exec format error
Nov 02 18:32:57 keyblade systemd[15299]: resume@rushil.service: Failed at step EXEC spawning /home/rushil/scripts/swap-ctrl.sh: Exec format error

Offline

#6 2018-11-02 22:58:27

rukumar333
Member
Registered: 2017-01-10
Posts: 12

Re: setxkbmap does not persist after putting machine on sleep mode

I actually got the sleep hook to run properly. But even then, it does not work. The keys are not swapped. This is the content of the service file /etc/systemd/system/resume@.service

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

[Service]
User=%I
Type=simple
Environment=DISPLAY=:0
ExecStart=/home/rushil/scripts/swap-ctrl.sh

[Install]
WantedBy=suspend.target

Here is the output of the status:

● resume@rushil.service - User resume actions
   Loaded: loaded (/etc/systemd/system/resume@.service; enabled; vendor preset: disabled)
   Active: inactive (dead)

Nov 02 18:42:11 keyblade systemd[16224]: resume@rushil.service: Failed to execute command: Exec format error
Nov 02 18:42:11 keyblade systemd[16224]: resume@rushil.service: Failed at step EXEC spawning /home/rushil/scripts/swap-ctrl.sh: Exec format error
Nov 02 18:42:11 keyblade systemd[1]: resume@rushil.service: Main process exited, code=exited, status=203/EXEC
Nov 02 18:42:11 keyblade systemd[1]: resume@rushil.service: Failed with result 'exit-code'.
Nov 02 18:47:33 keyblade systemd[1]: Started User resume actions.
Nov 02 18:47:33 keyblade systemd[1]: resume@rushil.service: Main process exited, code=exited, status=255/n/a
Nov 02 18:47:33 keyblade systemd[1]: resume@rushil.service: Failed with result 'exit-code'.
Nov 02 18:49:20 keyblade systemd[1]: Started User resume actions.
Nov 02 18:50:35 keyblade systemd[1]: Started User resume actions.
Nov 02 18:50:54 keyblade systemd[1]: Started User resume actions.

The errors are when my script was not set up properly. I added the DISPLAY part as you mentioned but do not know what to do with the UID.

Offline

#7 2018-11-03 08:29:18

seth
Member
Registered: 2012-09-03
Posts: 30,970

Re: setxkbmap does not persist after putting machine on sleep mode

The error message seems pretty straight forward, upload the scriptfile somewhere (no copypasta - it's very much likely malformed)

Offline

#8 2018-11-06 20:27:28

rukumar333
Member
Registered: 2017-01-10
Posts: 12

Re: setxkbmap does not persist after putting machine on sleep mode

Thanks for your help! I was having trouble with the sleep hook but managed to get it working (at least so far) with the xorg configlet. In case anyone needs to see the solution, I created the file /etc/X11/xorg.conf.d/00-keyboard.conf with the contents:

Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        Option "XkbOptions" "ctrl:swapcaps"
EndSection

Offline

Board footer

Powered by FluxBB