Score:1

xmodmap not running in .profile

br flag

I recently followed this guide to get some keys mapped to my Alt Gr https://medium.com/@retprogramisto/how-to-make-custom-keyboard-map-with-xmodmap-1341a1552d4f

It worked fine, but when it came to getting the command xmodmap ~/.Xmodmap to run on startup, I didn't have .xinitrc in my home directory, so I put it in my .profile.

After a reboot, it didn't run the command (I guess) and my accented characters are not mapped like they should be.

Was it a mistake to put the command in .profile? Should I perhaps create .xinitrc and put it in there?

Thanks.

$ lsb_release -a && uname -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:    20.04
Codename:   focal
Linux leon 5.11.0-46-generic #51~20.04.1-Ubuntu SMP Fri Jan 7 06:51:40 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Score:2
cn flag

The keyboard in your user session may not have been initialized yet when .profile is being run when you log in.

Xmodmap is not anymore the ideal way to change keyboard layouts. For example, when switching keyboard layouts, it will need to be reloaded each time. Unfortunately, editing kbd files directly is complicated and not applicable on a per user basis.

Formally, a file .Xmodmap would automatically be sourced when logging in. This is not anymore so since Gnome 3.8. .xinitrc, on the other hand, is relevant only if you use startx rather than a login manager to load your session.

Instead you can automatically run the command on login using an autostart launcher: create a .desktop launcher in your autostart directory with the command

gedit ~/.config/autostart/xmodmap.desktop

and enter following code:

[Desktop Entry]
Name=Xmodmap
Exec=xmodmap /home/<yourlogin/.Xmodmap
Terminal=false
Type=Application
X-GNOME-Autostart-Delay=1
X-GNOME-Autostart-enabled=true

Without delay, the activation may not systematically succeed. X-GNOME-Autostart-Delay=1 introduces a delay of one second before running the command.

user126440 avatar
br flag
Thanks. It's a bit hacky, but it worked :)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.