I am running Ubuntu 22.04 on AMD® Ryzen 5 3400g with radeon vega 11, 32GB, with Gnome on Xorg, and a Razer Huntsman Mini USB keyboard, with "openrazer-daemon" and "RazerGenie" software to handle the keyboard configuration. All was working well after installation, except that the Gnome Super key (Windows key) did not work as it should like it did on my previous pc. I found out that the problem was caused by the Windows key had been assigned to the Compose key, whatever that is, as seen from this output:
(base) jan@argon:~$ setxkbmap -query
rules: evdev
model: pc105
layout: dk,us,us
variant: ,,
options: lv3:ralt_switch,terminate:ctrl_alt_bksp,compose:lwin
it was the "compose:lwin" mapping option that caused the problem, and I fixed it using the following simple script:
#!/bin/bash
# Delete all preset keyboard mapping options, and put all back except the compose key
/usr/bin/setxkbmap -option
/usr/bin/setxkbmap -option lv3:ralt_switch,terminate:ctrl_alt_bksp
This worked fine by issuing the script command manually. But it could not run automatically at Gnome login through .bashrc etc. So I made a Gnome autostart ".desktop" file under ~/.config/autostart:
argon:~$ cat ~/.config/autostart/setxkbmap.desktop
[Desktop Entry]
Name=Keyboard Remapping
GenericName=Gnome autostart login shell script
Comment=Keyboard options remapping
Exec=xterm -e ~/bin/keymap.sh
Terminal=false
Type=Application
X-GNOME-Autostart-enabled=true
After this it worked automatically after Gnome login.
Only problem was that after disconnect/connect the USB keyboard, the wrong keyboard mapping re-appeared !
Not the worlds most annoying problem since I can just redo the manual command. But I thought it would be fun to tie the keyboard remapping script to an udev rule. It turned out to be not so much fun, but being stubborn I did an attempt. To make a long story short, I succeded in making an udev rule to call the script, but it had no effect on the default wrong keyboard remapping after plugin of the keyboard :-) I made many iterations on the udev rule and several worked to the extent that they called the script.
the contents of the final udev rule (and prior attempts commented out) is as follows:
argon:/etc/udev/rules.d# cat 99-razer-huntsman-mini.rules
# rule to fix windows key being used as a compose key
# rather than Gnome super key
#SUBSYSTEMS=="keyboard", DRIVER=="razerkbd", ATTRS{idVendor}=="1532", \
#ATTRS{idProduct}=="0257", ATTR{INTERFACE}=="3/1/1", GOTO="setxkbmap"
#KERNEL=="3-3", ATTR{INTERFACE}=="3/1/1", SUBSYSTEM=="usb", DRIVER=="usb", \
#ATTRS{idVendor}=="1532", ATTRS{idProduct}=="0257", GOTO="setxkbmap"
#KERNEL=="3-3", ATTR{INTERFACE}=="3/0/1", SUBSYSTEM=="keyboard", DRIVER=="razerkbd", \
#ATTRS{idVendor}=="1532", ATTRS{idProduct}=="0257", GOTO="setxkbmap"
#KERNEL=="3-3", SUBSYSTEM=="keyboard", DRIVER=="razerkbd", ATTRS{idVendor}=="1532", \
#ATTRS{idProduct}=="0257", GOTO="setxkbmap"
KERNEL=="3-3", SUBSYSTEM=="input", DRIVER=="razerkbd", ATTRS{idVendor}=="1532", \
ATTRS{idProduct}=="0257", GOTO="setxkbmap"
LABEL="setxkbmap"
#ACTION=="add", RUN+="/usr/local/bin/keymap.sh"
#ACTION=="add", GROUP="plugdev", OWNER="jan", RUN+="/usr/bin/xterm -display :0 -e \
#'/usr/local/bin/keymap.sh'"
#ACTION=="add", RUN+="/usr/bin/su - jan -c 'export DISPLAY=:0; \
#/usr/bin/xterm -e /usr/local/bin/keymap.sh'"
ACTION=="add", RUN+="/usr/local/bin/keymap.sh"
and the contents of "/usr/local/bin/keymap.sh" was as follows:
cat /usr/local/bin/keymap.sh
#!/bin/bash
# delete all preset keyboard mapping options
su - jan -c 'export DISPLAY=:0; /usr/bin/xterm -e \
"/usr/bin/setxkbmap -option; \
/usr/bin/setxkbmap -option lv3:ralt_switch,terminate:ctrl_alt_bksp"'
echo $(date) >> /tmp/razer.log
I had to use an X application like xterm to make it work since "setxkbmap" require a display definition. The last line is a simple log so I can see how many times the mapping script is called for each plugin of the keyboard. Initially it was over 100 times but after some experimenting making more specific rules I got it down to 30. But I was unable to find a more specific rule set that would hit cleanly only once. But worst, it does not work :-(
So if anyone has an idea to fix it, I'd be glad to hear about it.
I have a feeling the problem is an Xorg problem since "setxkbmap" needs a display parameter, and even if it runs successfully it is unclear for which user of Xorg, so the mapping probably does not hit my own personal Gnome session, but I dont know how to make the remapping happen in my session.