.Xmodmap not automatically loaded on start

Bug #1243642 reported by Dirk Schuster
206
This bug affects 43 people
Affects Status Importance Assigned to Milestone
Ubuntu
Confirmed
Undecided
Unassigned

Bug Description

I'm using a ~/.Xmodmap file to define two keycode mappings.

13.10 doesn't seem to automatically load this file any more.
13.04 did. (same file, same laptop)

manual execution of "xmodmap ~/.Xmodmap" works on 13.10!
That means I'm e.g. able to use this key in a terminal or in geany.

I discovered, that by switching the keyboard layouts using "gnome-control-center region layouts" the mappings of the "xmodmap ~/.Xmodmap" will be lost again. Then another manual execution of "xmodmap ~/.Xmodmap" has to be executed and it works again.

Perhaps the ~/.Xmodmap is loaded and lost by the the gnome-control-center () later.

Sorry, I can't figure out which packet this bug has to be asigned to. By using apport-bug "xorg" was choosen, but it could be "xorg-server" or "gnome-control-center", also.

ProblemType: Bug
DistroRelease: Ubuntu 13.10
Package: xorg 1:7.7+1ubuntu6
ProcVersionSignature: Ubuntu 3.11.0-12.19-generic 3.11.3
Uname: Linux 3.11.0-12-generic x86_64
.tmp.unity.support.test.0:

ApportVersion: 2.12.5-0ubuntu2
Architecture: amd64
CompizPlugins: No value set for `/apps/compiz-1/general/screen0/options/active_plugins'
CompositorRunning: compiz
CompositorUnredirectDriverBlacklist: '(nouveau|Intel).*Mesa 8.0'
CompositorUnredirectFSW: true
Date: Wed Oct 23 12:05:11 2013
DistUpgraded: Fresh install
DistroCodename: saucy
DistroVariant: ubuntu
ExtraDebuggingInterest: Yes
GraphicsCard:
 Intel Corporation Mobile 4 Series Chipset Integrated Graphics Controller [8086:2a42] (rev 09) (prog-if 00 [VGA controller])
   Subsystem: Acer Incorporated [ALI] Device [1025:013c]
   Subsystem: Acer Incorporated [ALI] Device [1025:013c]
InstallationDate: Installed on 2013-10-18 (4 days ago)
InstallationMedia: Ubuntu 13.10 "Saucy Salamander" - Release amd64 (20131016.1)
MachineType: Acer Extensa 5630
MarkForUpload: True
PccardctlIdent:
 Socket 0:
   no product info available
PccardctlStatus:
 Socket 0:
   no card
ProcKernelCmdLine: BOOT_IMAGE=/vmlinuz-3.11.0-12-generic root=/dev/mapper/vg01-root ro quiet splash vt.handoff=7
SourcePackage: xorg
Symptom: display
UpgradeStatus: No upgrade log present (probably fresh install)
dmi.bios.date: 08/11/2009
dmi.bios.vendor: Phoenix Technologies LTD
dmi.bios.version: V1.34
dmi.board.name: Homa
dmi.board.vendor: Acer
dmi.board.version: Rev
dmi.chassis.type: 10
dmi.chassis.vendor: Acer
dmi.chassis.version: N/A
dmi.modalias: dmi:bvnPhoenixTechnologiesLTD:bvrV1.34:bd08/11/2009:svnAcer:pnExtensa5630:pvr0100:rvnAcer:rnHoma:rvrRev:cvnAcer:ct10:cvrN/A:
dmi.product.name: Extensa 5630
dmi.product.version: 0100
dmi.sys.vendor: Acer
version.compiz: compiz 1:0.9.10+13.10.20131011-0ubuntu1
version.ia32-libs: ia32-libs N/A
version.libdrm2: libdrm2 2.4.46-1
version.libgl1-mesa-dri: libgl1-mesa-dri 9.2.1-1ubuntu3
version.libgl1-mesa-dri-experimental: libgl1-mesa-dri-experimental N/A
version.libgl1-mesa-glx: libgl1-mesa-glx 9.2.1-1ubuntu3
version.xserver-xorg-core: xserver-xorg-core 2:1.14.3-3ubuntu2
version.xserver-xorg-input-evdev: xserver-xorg-input-evdev 1:2.7.3-0ubuntu3.1
version.xserver-xorg-video-ati: xserver-xorg-video-ati 1:7.2.0-0ubuntu10
version.xserver-xorg-video-intel: xserver-xorg-video-intel 2:2.99.904-0ubuntu2
version.xserver-xorg-video-nouveau: xserver-xorg-video-nouveau 1:1.0.9-2ubuntu1
xserver.bootTime: Wed Oct 23 11:15:16 2013
xserver.configfile: default
xserver.errors:

xserver.logfile: /var/log/Xorg.0.log
xserver.outputs:
 product id 5459
 vendor CMO
xserver.version: 2:1.14.3-3ubuntu2

Revision history for this message
Dirk Schuster (dirk-schuster) wrote :
tags: added: xmodmap
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in xorg (Ubuntu):
status: New → Confirmed
Revision history for this message
Dirk Schuster (dirk-schuster) wrote :

Hi,

Ryan gave me a hint, how to find a workaround without using ~/.Xmodmap. I describe the solution of my specific problem here, so it might be helpful for someone with a similar problem.

These links helped a lot:
https://help.ubuntu.com/community/Howto%3A%20Custom%20keyboard%20layout%20definitions
http://www.charvolant.org/~doug/xkb/html/node5.html

To use the special € and $ keys of the acer laptop in 13.10:

1. add the scancode-to-keycode mappings to /etc/rc.local

# <Euro>
setkeycodes e033 240
# <Dollar>
setkeycodes e034 241

loadkeys /home/user/.acer.map

2. create the keyboard translation table extension in /home/user/.acer.map containing:

keycode 240 = euro
 shift keycode 240 = cent
keycode 241 = dollar
 shift keycode 241 = onequarter

3. add the xbd_symbols to the symbol definition file you use, e.g.: /usr/share/X11/xkb/symbols/de

// acer Euro und Dollar Spezialtasten
    key <I248> { [ EuroSign, cent ] };
    key <I249> { [ dollar, onequarter ] };

4. optional, if you like to see the keys in the graphical represenation of the keyboard,
    change the appropriate section in the geometry definition file you use, e.g. /usr/share/X11/xkb/geometry/pc

    section "Editing" {
 top= 61;
 left= 312;
 row {
     top= 1;
     key.color= "grey20";
     keys { <INS>, <HOME>, <PGUP> };
 };
        row {
     top= 20;
     key.color= "grey20";
     keys { <DELE>, <END>, <PGDN> };
 };
 row {
     top= 58;
     keys { <I248>, { <UP>, color= "grey20" } , <I249> };
 };
 row {
     top= 77;
     key.color= "grey20";
     keys { <LEFT>, <DOWN>, <RGHT> };
 };
    }; // End of "Editing" section

And now I'm able to switch the keyboard layouts using "gnome-control-center region layouts", too, withour "loosing" the € or $ key of the acer laptop again.

cheers Dirk

Revision history for this message
Paul Dumais (paul-unstate) wrote :

Your work-around works because it doesn't rely on any modifications done by /usr/sbin/lightdm-session where it loads the modifications found in either ~/.Xkbmap or ~/.xmodmap. The modifications to the keyboard layout found in these files are run, but are immediately reverted by some other process - which is a major bug that is really frustrating because it breaks a lot of behavior. This still needs to get fixed. Anything put in ~/.Xkbmap or ~/.xmodmap is not being honored in a very silent and man-year-wasting fashion.

Revision history for this message
Hélio Nunes (dedalu-dedalu) wrote :

If you force the load of the .Xmodmap by adding the command 'xmodmap ~/.Xmodmap' in the Startup Applications, all is reverted if you suspend/resume or if you change the user and get back etc. So I managed to adapt some snippets I found, using the python dbus interface to reissue the command when resuming, changing the keyboard layout or changing sessions. It can be saved as /usr/local/bin/user-xmodmap-reload-hack (or other path/name) and then added to the Startup Applications.

I didn't test it very much and I don't have much code experience, so you are welcome to modify.

Revision history for this message
rpkrawczyk (rpkrawczyk) wrote :

Is there any solution so far? My problem is that I would like to change the keyboard map automatically per *user* and not the global map. Why is xmodmap not used anymore?

Revision history for this message
HaraldK (pifpafpuf) wrote :

Finally I got so fed up with gnome that I switched to XFCE and never looked back. Despite all the other benefits I personally think it has, .Xmodmap works as expected again, in particular also when waking up from sleep.

Revision history for this message
Rafael Nonato (rafaeln) wrote : Re: [Bug 1243642] Re: .Xmodmap not automatically loaded on start

I also got fed up, but adopted an alternative solution. I've migrated my
remappings to XKB. I plan to write out a tutorial explaining how to go
about using XKB to implement remappings. But who knows when... The internet
is, however, plenty of resources on how to go about it.

On Sat, Feb 28, 2015 at 7:10 AM HaraldK <email address hidden> wrote:

> Finally I got so fed up with gnome that I switched to XFCE and never
> looked back. Despite all the other benefits I personally think it has,
> .Xmodmap works as expected again, in particular also when waking up from
> sleep.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1243642
>
> Title:
> .Xmodmap not automatically loaded on start
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ubuntu/+source/xorg/+bug/1243642/+subscriptions
>

Revision history for this message
Uriel Tunn (u2n) wrote :

This bug remains, and the problem is just as bad after converting from an .Xmodmap file to an xkb map: THE FILE MUST BE MANUALLY RELOADED ON AWAKENING.

 - A script in /etc/pm/sleep.d does not work.
 - A script on the desktop does not work.
 - Tearing hair out does not work.

Auto-loading the map on startup is trivial. But how to auto-load even an xkb map file after a sleep? Or maybe, how to not lose the mappings during the sleep-wake process to begin with?

Getting ready to revert to 12.04 and not re-upgrade until this bug is fixed.

Revision history for this message
Rafael Nonato (rafaeln) wrote :

I don't think we are talking about the same thing when we talk of XKB. To
clarify what I am talking about, I meant editing the files under
/usr/share/X11/xkb/

On Sat, Feb 28, 2015, 23:00 Uriel Tunz <email address hidden> wrote:

> This bug remains, and the problem is just as bad after converting from
> an .Xmodmap file to an xkb map: THE FILE MUST BE MANUALLY RELOADED ON
> AWAKENING.
>
> - A script in /etc/pm/sleep.d does not work.
> - A script on the desktop does not work.
> - Tearing hair out does not work.
>
> Auto-loading the map on startup is trivial. But how to auto-load even an
> xkb map file after a sleep? Or maybe, how to not lose the mappings
> during the sleep-wake process to begin with?
>
> Getting ready to revert to 12.04 and not re-upgrade until this bug is
> fixed.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1243642
>
> Title:
> .Xmodmap not automatically loaded on start
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ubuntu/+source/xorg/+bug/1243642/+subscriptions
>

Revision history for this message
HaraldK (pifpafpuf) wrote :

Well,

% find /usr/share/X11/xkb/ -type f|wc -l
273

there are 273 files in this folder a I would definitively need a whole tutorial to change keyboard settings. My hunch is that changing xkb is a developer's job, while .Xmodmap is just great to change these one or two odd keys on the keyboard.

Revision history for this message
Rafael Nonato (rafaeln) wrote :

You are right. And though you don't have to change all of the 273 files
in there, it would be desireable for there to exist a user-level change
like was the case with .Xmodmap. I've seen a few explanations on the web
as to why Canonical would have wanted to break the old behavior, but
I'm still not sure why.

In any case, you don't have to change all of the 273 files. In most
cases, not even one. You can see a list of the already coded tweaks on
`/usr/share/X11/xkb/rules/evdev.lst` and add them. I managed to
permanently add the `grp:shifts_toggle`, `terminate:ctrl_alt_bksp` and
`caps:swapescape` tweaks (you can grep the the file `evdev.lst` to see a
more verbose description of what they do) by issuing the following
command:

`gsettings set org.gnome.desktop.input-sources xkb-options "['grp:shifts_toggle', 'terminate:ctrl_alt_bksp', 'caps:swapescape']"`

Best,
Rafa

On Sun, Mar 01, 2015 at 11:03:07AM -0000, HaraldK wrote:
> Well,
>
> % find /usr/share/X11/xkb/ -type f|wc -l
> 273
>
> there are 273 files in this folder a I would definitively need a whole
> tutorial to change keyboard settings. My hunch is that changing xkb is a
> developer's job, while .Xmodmap is just great to change these one or two
> odd keys on the keyboard.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1243642
>
> Title:
> .Xmodmap not automatically loaded on start
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ubuntu/+source/xorg/+bug/1243642/+subscriptions

Revision history for this message
Uriel Tunn (u2n) wrote :

Yes, different. Editing those system-level files affects keyboard
mapping for ALL users. But this bug is about .Xmodmap, which is
per-user. My post noted that even xkb maps are lost on suspend/sleep.

Converting .Xmodmap files to xkb is straightforward. After manually
loading the desired .Xmodmap file, then:

[[ -d "$HOME/.xkb" ]] || mkdir $HOME/.xkb
xkbcomp $DISPLAY $HOME/.xkb/xkb-map

Then edit $HOME/.xkb/xkb-map, which is fairly intuitive, if needed.
Next, since the file won't load automatically no matter what, I did:

echo 'xkbcomp $HOME/.xkb/xkb-map $DISPLAY' >> ~/.bashrc

This way, at least the map can be loaded by just popping open a
terminal. (Remove the 'xmodmap .Xmodmap' line in .bashrc, if it was there.)

On single-head, multi-user systems where everyone doesn't use the same
keyboard map, instead of just being able to switch users, it would be
necessary to change configuration and restart (if control is only
system-wide). Completely unacceptable. This bug really needs fixing.

On 03/01/2015 12:03 AM, Rafael Nonato wrote:
> I don't think we are talking about the same thing when we talk of XKB. To
> clarify what I am talking about, I meant editing the files under
> /usr/share/X11/xkb/
>

Revision history for this message
Rafael Nonato (rafaeln) wrote :

I did it differently. I went about editing the relevant files in that directory I mentioned in my other message.

Revision history for this message
Herwig Hochleitner (hhochleitner) wrote :

There is a gnome ticket for this problem, please add your use cases there:

https://bugzilla.gnome.org/show_bug.cgi?id=721873

Revision history for this message
Jonathan Harker (jesusaurus) wrote :

I'm seeing the same behaviour after an upgrade from Precise to Trusty, and it is disheartening to see that the bug was reported during an upgrade between intermediate versions with very little traction. I've added logic to my shell rc script to run xmodmap when I log in, but this does not address the case where I resume, so I still need to manually run xmodmap somewhat regularly.

Revision history for this message
Rafael Nonato (rafaeln) wrote :

I concluded there are two solutions: swap to a different distro or to a
different method. I've resorted to the second, and am now tweaking with
xkb's infrastructure to arrive at the same remappings (caps becomes escape,
escape becomes caps, left alt becomes ctrl, left ctrl becomes alt). It is
more complicated, but more robust too.

Em qui, 23 de abr de 2015 15:01, Jonathan Harker <email address hidden>
escreveu:

> I'm seeing the same behaviour after an upgrade from Precise to Trusty,
> and it is disheartening to see that the bug was reported during an
> upgrade between intermediate versions with very little traction. I've
> added logic to my shell rc script to run xmodmap when I log in, but this
> does not address the case where I resume, so I still need to manually
> run xmodmap somewhat regularly.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1243642
>
> Title:
> .Xmodmap not automatically loaded on start
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ubuntu/+source/xorg/+bug/1243642/+subscriptions
>

Revision history for this message
pablomme (pablomme) wrote :

Modifying /usr/share/X11/xkb/symbols/pc has the side effect that SDL is unable to recognize the keyboard layout, and most keys do not work in SDL applications if a modified keymap is used.

Revision history for this message
Lalo Martins (lalo.martins) wrote :

One thing to add (I'm shocked nobody mentioned yet): edits in anything in /usr/... will be lost next time the respective package is updated. So, even on single-user machines, a per-user (or at least /etc) option is *needed*.

Revision history for this message
Lalo Martins (lalo.martins) wrote :

Suggest changing the title to “Need a per-user method of remapping keys (.Xmodmap, .Xkbmap don't work)”

Revision history for this message
HaraldK (pifpafpuf) wrote :

Reading the bugzilla bug linked in #16, we are asked to not use gnome if we want to be able to tweak one or the other key on our keyboard, because they are not able to build a working UI on top of xmodmap. At least this is what I read from it.

Revision history for this message
Timo Aaltonen (tjaalton) wrote :

this annoys me enough so that I want at least a somewhat hacky thing installed by default..

usecase; remap a single key on US layout kbd so that I can use FI still being able to get "<>|"

Changed in xorg (Ubuntu):
assignee: nobody → Timo Aaltonen (tjaalton)
Revision history for this message
Tim Peeters (tpeeters) wrote :

My use case: remap the ALT and CMD keys on a Macbook so that I get the ALT and SUPER keys on the place where I am used to find them on a "normal" keyboard.

Revision history for this message
Nick (nj140824) wrote :

I just switched to Ubuntu from Debian (using xfce not gnome). .Xmodmap has worked on Debian since ... forever. I can't do without it. I thought Ubuntu was based on Debian?

Revision history for this message
Alexander Thomas (doctor-lex) wrote :

@Nick: it is based on Debian all right. Only they added stuff on top that overrides pre-existing things. I'm in exactly the same boat as you.
Xmodmap still works and it can be run from the startup applications, but something else overrides the keymap immediately after executing the startup applications. So, I added a delay to my script, only to notice that this same something still overrides the keymap at semi-random moments. I think I'll try that hacky script from comment #6, which I was about to write by myself until I found this bug report…

Revision history for this message
Hélio Nunes (dedalu-dedalu) wrote :

Alexander, the script I posted (#6) still working. I did not found any other solution to this "feature". The evil is the gnome keyboard configuration itself. As told in https://bugzilla.gnome.org/show_bug.cgi?id=721873, this is not a bug, but a side effect of using the gnome interface.

The script is a simple and user specific workaround. You could modify the xkb configuration files, but, as Uriel (#14) inform, user loaded xkb configurations gets erased as well. I still use the xmodmap because it is straightforward for my needs. A better script may interact with org.gnome.libgnomekbd.desktop and/or org.gnome.desktop.input-sources and xkbcomp.

Good luck.

Revision history for this message
Uriel Tunn (u2n) wrote :

Bug is gone in 16.04!

.Xmodmap (which IS deprecated) still needs to be converted to xkb (post 14, https://bugs.launchpad.net/ubuntu/+source/xorg/+bug/1243642/comments/14), but then everything works as before: keyboard map reloads automatically after any number of suspend/hibernate cycles. Seriously happy about this. Anyone see different behavior?

I'm keeping .Xmodmap as a kind of original source file file for reference, but editing the xkb file directly now (rarely).

Many thanks to the devs for fixing the bug.

Revision history for this message
Hélio Nunes (dedalu-dedalu) wrote :

Uriel,

it does not work for me.

Please, post the details of what you did.

Thank you.

Revision history for this message
Uriel Tunn (u2n) wrote :

@Hélio, only thing I did was upgrade to 16.04 (clean install), copy my xkb file over and load it (xkbcomp $HOME/.xkb/xkb-map $DISPLAY). That's it.

Well, it *does* get loaded on each boot via .bashrc (as noted in post 14) when a terminal is auto-opened (put in startup prefs) so not sure it will survive a reboot on its own. Will check that.

But once loaded, it remains in effect after all suspends and hibernates, same as .Xmodmap used to work. I can live with the minor inconvenience of setting up the auto-load. Just have to remember what I did after a year or more passes.

Revision history for this message
le hollandais volant (timovn) wrote :

Hello,

Not sure if this is relevant, but my .Xmodmap is loaded (using "xmodmap /home/$USER/.Xmodmap" in .xsessionrc) *only* when I’m logging into a TTY shell (non graphical shell).

When I login to Mate/Unity, something, somewhere appears to be reversing the Xmodmap instructions.

A work around would be to graphically add a startup command, delayed by ~5 seconds, but still this would not be loaded when awaking from suspend/hibernate.

Revision history for this message
sunggon (skim11) wrote :

For anyone who is interested, i just made script version of Xmodmap (e.g., xmodmap -e "code", then registered it as start up application. It works great with my chromebook and crouton setup :)

Revision history for this message
Timo Aaltonen (tjaalton) wrote :

not an X bug, reassigning

and my use case for getting "<|>" on an US layout is actually already available via altgr-shift-{8,9,i}, so I don't need hacks anymore

but I think you can drop your custom layouts in /etc/X11/xkb(/symbols?), clean up the cache in /var/lib/xkb and restart the server.. maybe it'll show up in the gui then

affects: xorg (Ubuntu) → ubuntu
Changed in ubuntu:
assignee: Timo Aaltonen (tjaalton) → nobody
Revision history for this message
rpkrawczyk (rpkrawczyk) wrote :

All answers really seem like hacks to me. What is the solution to this problem? For me, I need to remap certain characters on a per user basis in X regardless of the settings and window manager used. How can I do this (correctly)?

Revision history for this message
HaraldK (pifpafpuf) wrote :

It is a sad development that for such a simple task as to give one or two keys another meaning the completely sufficien Xmodmap does not work any more. I finally gave in and started using xkb. I described the way it worked for me in detail here: http://askubuntu.com/a/846184/367444 . The question and answers contain additional information.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.