You are not logged in.

#1 2021-06-04 00:29:55

mikl
Member
Registered: 2021-06-02
Posts: 8

How to set keyboard rebindings and mouse keys after suspend and resume

Got openbox with lightdm and light-locker all set up.

Initially, keyboard configurations set with xkbset and xmodmap at login are lost after suspending, which is normal and expected behavior.

Custom file ~/bin/resume.sh contains the xkbset and xmodmap configurations to be restored:

#!/bin/bash
export DISPLAY=:0
xkbset exp m
xkbset m
xkbset ma 10 30 10 50 900
xmodmap -e "keycode  25 = w W w W KP_Divide Lstroke lstroke"
xmodmap -e "keycode  26 = e E e E KP_Up KP_Up EuroSign"
xmodmap -e "keycode  27 = r R r R KP_Subtract registered paragraph"
xmodmap -e "keycode  39 = s S s S KP_Left KP_Left ssharp"
xmodmap -e "keycode  40 = d D d D KP_Begin KP_Begin eth"
xmodmap -e "keycode  41 = f F f F KP_Right KP_Right dstroke"
xmodmap -e "keycode  54 = c C c C KP_Down KP_Down cent"
xmodmap -e "keycode  29 = y Y y Y Home yen leftarrow"
xmodmap -e "keycode  30 = u U u U Insert uparrow downarrow uparrow u U downarrow uparrow"
xmodmap -e "keycode  31 = i I i I Up Up rightarrow"
xmodmap -e "keycode  32 = o O o O Delete Oslash oslash Oslash o O oslash Oslash"
xmodmap -e "keycode  33 = p P p P Prior THORN thorn"
xmodmap -e "keycode  43 = h H h H End Hstroke hstroke"
xmodmap -e "keycode  44 = j J j J Left Left dead_hook"
xmodmap -e "keycode  45 = k K k K Down Down kra"
xmodmap -e "keycode  46 = l L l L Right Right lstroke"
xmodmap -e "keycode  47 = ntilde Ntilde ntilde Ntilde Next dead_doubleacute asciitilde"
xmodmap -e "keycode  60 = period colon period colon Pointer_Button1 Pointer_Button1 periodcentered"
xmodmap -e "keycode  61 = minus underscore minus underscore Pointer_Button3 Pointer_Button3 dead_belowdot"

Created a new service /etc/systemd/system/resume@.service to execute these commands every time after resuming from suspend:

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

[Service]
User=%I
Type=simple
ExecStart=/home/%I/bin/resume.sh

[Install]
WantedBy=suspend.target

The service was enabled with:

$ sudo systemctl enable resume@miguel

Problem: The service is executing after resuming from suspend but the problem is that xkbset and xmodmap configurations are not getting restored. If I execute ~/bin/resume.sh myself after resuming, then xkbset and xmodmap configurations get restored.

Logs after attempt:

$ systemctl status resume@miguel
○ resume@miguel.service - User resume actions
     Loaded: loaded (/etc/systemd/system/resume@.service; enabled; vendor preset: disabled)
     Active: inactive (dead)

jun 03 19:24:35 coalstone systemd[1]: Started User resume actions.
jun 03 19:24:36 coalstone systemd[1]: resume@miguel.service: Deactivated successfully.
$ journalctl -u resume@miguel
(no errors today)

Last edited by mikl (2021-06-04 00:34:21)

Offline

#2 2021-06-04 04:59:34

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

Re: How to set keyboard rebindings and mouse keys after suspend and resume

Race condition?
The keyboard gets re-attached by the server after the resume, what can take a brief moment.
If your script runs ahead of that, the changes are lost.

You could "ExecStartPre=/usr/bin/sleep 10" for a quick test.

Offline

#3 2021-06-04 08:20:30

mikl
Member
Registered: 2021-06-02
Posts: 8

Re: How to set keyboard rebindings and mouse keys after suspend and resume

seth wrote:

Race condition?
The keyboard gets re-attached by the server after the resume, what can take a brief moment.
If your script runs ahead of that, the changes are lost.

You could "ExecStartPre=/usr/bin/sleep 10" for a quick test.

Thanks for the input. Tryed with 20 seconds: the the times I quickly unlocked the screen before the 20 seconds passed, the configuration became effective; the times I took 30+ seconds to unlock the screen, the configuration never became effective. By disabling light-locker the problem is gone, but I need to lock when suspending. Now I have been trying to lock the screen after resume.sh is executed and not before: tryed by starting light-locker with --no-lock-on-suspend flag, and tryed ExecStartPost=/usr/bin/light-locker-command -l with Environment=DISPLAY=:0, which gives error and journalctl doesn't say what the error is; then tryed light-locker-command -l at the end of ~/resume.sh which also gives error with no details from journalctl either. Also not sure these solutions would be ideal.

Last edited by mikl (2021-06-04 08:28:59)

Offline

#4 2021-06-04 12:10:25

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

Re: How to set keyboard rebindings and mouse keys after suspend and resume

https://aur.archlinux.org/packages/i3lock-color/ doesn't inhibit the input alteration :-P

Is this tied to lightdm-locker or the suspension, ie. can you "(sleep 10;  xkbset -m) & lightdm-locker-command -l" and that disables the mouse acceleration?
If not, you'd probably have the script poll "light-locker-command -q" until it's no longer active… :\

Offline

#5 2021-06-05 09:04:58

mikl
Member
Registered: 2021-06-02
Posts: 8

Re: How to set keyboard rebindings and mouse keys after suspend and resume

seth wrote:

https://aur.archlinux.org/packages/i3lock-color/ doesn't inhibit the input alteration :-P

Is this tied to lightdm-locker or the suspension, ie. can you "(sleep 10;  xkbset -m) & lightdm-locker-command -l" and that disables the mouse acceleration?
If not, you'd probably have the script poll "light-locker-command -q" until it's no longer active… :\

Definitely it's tied to light-locker: when it's locking the screen these input alteration commands don't work. I tryed (sleep 10;  xkbset -m) & lightdm-locker-command -l and mouse acceleration doesn't get disabled if I let the screen locked for 10+ seconds, on the other hand when I executed sleep 10;  xkbset -m without locking the screen, then after 10 seconds mouse acceleration got disabled.

I guess i3lock would be a solution, but I really like light-locker because it allows to switch between multiple users' sessions by using the lightdm greeter. Polling until the screen is unlocked sounds better to me, maybe will end up using this solution, but I would like to find out why it happens that the commands don't work while light-locker is locking the screen.

Offline

#6 2021-06-05 14:10:21

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

Re: How to set keyboard rebindings and mouse keys after suspend and resume

lightdm-locker probably just grabs the entire server instead of only the input and everything else no longer can talk to the server then.
https://github.com/the-cavalry/light-lo … grab-x11.c doesn't look like that, though - but idk enough about the gtk API to tell for sure what it does under the hood.

I guess what could be nice was if light-locker would allow you to run scripts before it locks and after it unlocks.

Offline

#7 2022-10-15 02:28:09

mikl
Member
Registered: 2021-06-02
Posts: 8

Re: How to set keyboard rebindings and mouse keys after suspend and resume

I fixed this problem by creating a custom layout directly with the X Keyboard Extension, here is how I did it ===> https://bbs.archlinux.org/viewtopic.php?id=278502

Bonus: if need to work with many keyboards & layouts, you can use

xkblayout-state set <zero based index>

which will help to switch between the layouts that have been set with for example

sudo localectl set-x11-keymap es,es-custom pc104

(refer to the link).

Last edited by mikl (2022-10-15 02:43:08)

Offline

Board footer

Powered by FluxBB