11

I have a custom key mapping in the file ~/.Xmodmap which can be activated by running xmodmap ~/.Xmodmap.

However, I want this to happen automatically when I login. I have tried the following without success:

  • ~/.xinitrc with content xmodmap ~/.Xmodmap, as suggested here
  • ~/.xsession with content xmodmap ~/.Xmodmap, as suggested here
  • ~/.xsessionrc with content xmodmap ~/.Xmodmap, as suggested here

Obviously something is going wrong, but what? And how can I fix this?

3 Answers 3

6

Apparently for gnome it should be ~/.xprofile, but that file is executed too early for xmodmap to work.

So I got it to work by creating .config/autostart/xmodmap.desktop

[Desktop Entry]
Type=Application
Exec=/home/tvbox/bin/modmap
Hidden=false
X-GNOME-Autostart-enabled=true
Name=xmodmap
Comment=xmodmap script

And in /home/tvbox/bin/modmap, I have:

xmodmap ~/.Xmodmap
4
  • 2
    Thanks! Although I solved it eventually using another method: You can change key behaviour in the following file /usr/share/X11/xkb/symbols/pc
    – MuadDev
    Commented Nov 1, 2018 at 15:46
  • doesn't work for me (16.04) Commented Sep 2, 2020 at 0:25
  • @MuadDev Thank you!!! This also works on 20.04. I have been struggling with this same issue for hours, and your solution finally solved my problem.
    – Jakob KS
    Commented Nov 8, 2021 at 13:50
  • The .desktop file method does not work for everyone. The Startup Applications GUI in Pop_OS uses the .desktop file method. But it didn't work for me. MuadDev's method, however, did the trick.
    – Spero
    Commented Nov 22, 2023 at 7:03
2

I ran into the same problem and found the solution provided by MuadDev worked (on Ubuntu 20.04, but I think this might also apply to 18.04 and up).

In /usr/share/X11/xkb/symbols/pc Just add the line:

modifier_map Mod3   { Scroll_Lock };

Under the section // Beginning of modifier mappings.

Then you just need to do a reboot, and you're good to go.

Thanks for the hint MuadDev!

1

I tried the solution found here but somehow it didn't work. After a few days searching and experimenting, finally I found the culprit, i.e. Wayland.

My system is Ubuntu 18.10 and I used to log in per default. However recently I changed to Ubuntu on Wayland at login manager and since then my ~/.Xmodmap stopped working.

As I read on other sites, Wayland uses xkb instead of xmodmap. However it's still cumbersome to configure xkb. So for an average user like me the temporary solution is to switch back to Ubuntu at login screen. I hope this help other people who experience similar issue.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .