You are not logged in.

#1 2024-12-02 18:33:06

zakrush
Member
Registered: 2023-03-20
Posts: 28

[SOLVED] setxkbmap command in udev rule

Hello.
I write udev rule for keyboard connecting.

 sudo cat /etc/udev/rules.d/99-keyboard.rules
ACTION=="add", SUBSYSTEM=="usb", DRIVERS=="usb", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c328", RUN+="setxkbmap us,ru -option 'grp:alt_shift_toggle'"

On debug i see that command failed with exit code 1.

journalctl -f | grep setxkbmap
дек 02 21:27:11 redmi (udev-worker)[67397]: 3-1.4.3.3: /etc/udev/rules.d/99-keyboard.rules:1 RUN 'setxkbmap us,ru -option 'grp:alt_shift_toggle''
дек 02 21:27:11 redmi (udev-worker)[67397]: 3-1.4.3.3: Running command "setxkbmap us,ru -option 'grp:alt_shift_toggle'"
дек 02 21:27:11 redmi (udev-worker)[67397]: 3-1.4.3.3: Starting 'setxkbmap us,ru -option 'grp:alt_shift_toggle''
дек 02 21:27:11 redmi (udev-worker)[67397]: 3-1.4.3.3: Process 'setxkbmap us,ru -option 'grp:alt_shift_toggle'' failed with exit code 1.
дек 02 21:27:11 redmi (udev-worker)[67397]: 3-1.4.3.3: Command "setxkbmap us,ru -option 'grp:alt_shift_toggle'" returned 1 (error), ignoring.
дек 02 21:27:11 redmi (udev-worker)[67397]: 3-1.4.3.3:1.0: /etc/udev/rules.d/99-keyboard.rules:1 RUN 'setxkbmap us,ru -option 'grp:alt_shift_toggle''
дек 02 21:27:11 redmi (udev-worker)[67397]: 3-1.4.3.3:1.0: Running command "setxkbmap us,ru -option 'grp:alt_shift_toggle'"
дек 02 21:27:11 redmi (udev-worker)[67397]: 3-1.4.3.3:1.0: Starting 'setxkbmap us,ru -option 'grp:alt_shift_toggle''
дек 02 21:27:11 redmi (udev-worker)[67397]: 3-1.4.3.3:1.0: Process 'setxkbmap us,ru -option 'grp:alt_shift_toggle'' failed with exit code 1.
дек 02 21:27:11 redmi (udev-worker)[67397]: 3-1.4.3.3:1.0: Command "setxkbmap us,ru -option 'grp:alt_shift_toggle'" returned 1 (error), ignoring.
дек 02 21:27:11 redmi (udev-worker)[67423]: 3-1.4.3.3:1.1: /etc/udev/rules.d/99-keyboard.rules:1 RUN 'setxkbmap us,ru -option 'grp:alt_shift_toggle''
дек 02 21:27:11 redmi (udev-worker)[67423]: 3-1.4.3.3:1.1: Running command "setxkbmap us,ru -option 'grp:alt_shift_toggle'"
дек 02 21:27:11 redmi (udev-worker)[67423]: 3-1.4.3.3:1.1: Starting 'setxkbmap us,ru -option 'grp:alt_shift_toggle''
дек 02 21:27:11 redmi (udev-worker)[67423]: 3-1.4.3.3:1.1: Process 'setxkbmap us,ru -option 'grp:alt_shift_toggle'' failed with exit code 1.
дек 02 21:27:11 redmi (udev-worker)[67423]: 3-1.4.3.3:1.1: Command "setxkbmap us,ru -option 'grp:alt_shift_toggle'" returned 1 (error), ignoring.

The command are working correct in terminal, but doesn't work in udev. Why? I tried different variants of this command and no success.

Last edited by zakrush (2024-12-04 15:06:53)

Offline

#2 2024-12-02 19:12:49

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: [SOLVED] setxkbmap command in udev rule

The command needs to be run under your user and with the DISPLAY & XAUTHORITY variables correctly set.

See https://wiki.archlinux.org/title/Udev#T … _udev_rule for an example that might work for you with some tweaking.


Jin, Jîyan, Azadî

Offline

#3 2024-12-02 21:00:59

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

Re: [SOLVED] setxkbmap command in udev rule

Or just don't.
Configure the keyboard properly, https://wiki.archlinux.org/title/Xorg/K … tion_files
You can match product and vendor, https://man.archlinux.org/man/xorg.conf.5#MatchProduct
Get the information from xinput.

Offline

#4 2024-12-03 06:38:00

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: [SOLVED] setxkbmap command in udev rule

Yes, seth's suggestion is definitely better smile


Jin, Jîyan, Azadî

Offline

#5 2024-12-04 12:23:36

zakrush
Member
Registered: 2023-03-20
Posts: 28

Re: [SOLVED] setxkbmap command in udev rule

Head_on_a_Stick wrote:

The command needs to be run under your user and with the DISPLAY & XAUTHORITY variables correctly set.

See https://wiki.archlinux.org/title/Udev#T … _udev_rule for an example that might work for you with some tweaking.

So, I tried it.

#!/bin/bash
export DISPLAY=:0
export XAUTHORITY=/home/dm/.Xauthority
xauth add $DISPLAY . `xauth list $DISPLAY | awk '{print $3}'`
setxkbmap us,ru -option 'grp:alt_shift_toggle'

And setup it as systemd
But I can't win privilege problems.


seth wrote:

Configure the keyboard properly, https://wiki.archlinux.org/title/Xorg/K … tion_files
You can match product and vendor, https://man.archlinux.org/man/xorg.conf.5#MatchProduct
Get the information from xinput.

Ok. Thanks. I will try it.

Offline

#6 2024-12-04 15:06:31

zakrush
Member
Registered: 2023-03-20
Posts: 28

Re: [SOLVED] setxkbmap command in udev rule

seth wrote:

Or just don't.
Configure the keyboard properly, https://wiki.archlinux.org/title/Xorg/K … tion_files
You can match product and vendor, https://man.archlinux.org/man/xorg.conf.5#MatchProduct
Get the information from xinput.

Thanks a lot. It's really help me.

Offline

Board footer

Powered by FluxBB