As my keyboard layout doesn't suit me, I run xmodmap
on login. The script is named .profile
and it runs OK, but it breaks the Unity interface.
I want to know where to put the xmodmap
line so that it executes on my login and doesn't break anything.
I have already tried putting it in the .bash_login
and .bash_profile
files, without success (xmodmap
doesn't set my keyboard).
What are my options?
The correct place to put
xmodmap ~/.Xmodmap
(so that your changes are read at startup) is in~/.xinitrc
(see explanation below), although you could alternately place thexmodmap
command as a startup item (/usr/bin/xmodmap /home/user/.Xmodmap
). I can say that for 12.04 (and presumably 12.10) that these two alternatives definitely do work, as either way they are read after you log in withlightdm
. (I changed Return to Right Shift, and the change only took effect after entering my password and logging in).Please note: if you are on Xfce, it is noted on the official Xfce FAQ that you may have to create a startup item instead of using
~/.xinitrc
, and that you might have to delay the execution so thexmodmap
changes are not overwritten bysetxkbmap
. You can use a delay to achieve this in your startup entry:(For the startup entry it is necessary to specify absolute paths)
Each time
setxkbmap
is run to change keyboard layout, you will have to runxmodmap ~/.Xmodmap
again in the terminal.Creating
~/.xinitrc
Create a file in your home folder called
.xinitrc
withand place in it:
Your
Xmodmap
file should not have entries in thexmodmap -e " "
style as that is used in the terminal for temporarily setting the values. It must have entries in this format:It is often confusing which of the various
X
files (such as.xprofile
,.xinitrc
, etc) are read at startup, but.xinitrc
does seem to be still read under 12.04, whereas.Xmodmap
or.xinputrc
are not read by themselves.I'm using ElementaryOS (with its GNOME based window manager) and found a solution through using
xdg
autostart scripts. Many window managers are using xdg so I assume this approach also will work in other environments. At least it should work with GNOME.xdg run scripts in
~/.config/autostart
upon login in a X session. To load xmodmap config upon login, add the following script to~/.config/autostart/xmodmap.desktop
:Then logout and login again, and your Xmodmap configuration should've been loaded.
If it's not working, try to run xmodmap in terminal to see if it's xmodmap that complains:
If you don't get any error, run the following command to debug:
I don't have the unity interface in front of me just now, but try clicking the Applications button on the launcher, then type startup.
There should be an app called Startup Applications (or some such). Click it and add your xmodmap command (eg
xmodmap /home/thiago/.Xmodmap
).It is important to use absolute path, not
~/Xmodmap
.If it still doesn't work, you can try adding a bit of delay as suggested by hxpax.
On Mint 17/18, I can achieve that bu put my scripts into the Startup Application, with 1 second delay.
As Mint 18 is derived from Ubuntu 1604, I think you can do the same, or install Startup Application managing panel first if it is not there.
Hope it helps.
I wasn't having much joy with any of the suggestions above (the .bashrc option wasn't really viable as it runs xmodmap on every new terminal)
I touched a script called
xmodstartup.sh
in my home folderwith it saved, I then did
sudo chmod +x xmodstartup.sh
then I simply added the executable file to gnome's "startup application preferences" window. bish bosh, English layout y Español on
altgr
:)For gnome3:
xinitrc starts with
/etc/X11/xinit/xinitrc
and contains only one command:. /etc/X11/Xsession
This global Xsession file sets paths that are being executed:I put
echo $(date) >> ~/sesscheck
in$USERXSESSIONRC
to check if this file is being executed on gnome login. It works. However, if you putxmodmap ~/.Xmodmap
instead of test file record, keys mapping stays default. It means that default xmodmap overrides settings when xinitrc already started.As said above by @kontrollanten, the most reliable way is to create a
.desktop
file and put it into~/.config/autostart
directory. Desktop entry example, modifying keymap after Gnome user login:In my case, I lost numpad functionality at all and needed to map numpad keycodes to exact digits. So,
~/.Xmodmap
is:Seems that even .config/autostart is a bit finicky. Jay had a good solution but I've realized you could put the commands in xmodmap.desktop while just making sure to sleep the 1 second without having to make the extra bash script.
Putting xmodmap changes in
~/.bashrc
or/etc/bash.bashrc
doesn't break anything.Only downside is that one has to open a terminal after each boot to get it activated.