xmodmap Way
First, check this out.
Here's my version of .xsession
:
#! /usr/bin/env sh
GTK_IM_MODULE=xim
QT_IM_MODULE=xim
xmodmap ~/.Xmodmap-Apple
and the corresponding ~/.Xmodmap-Apple
(for the Russian version):
keycode 94 = grave asciitilde Cyrillic_io Cyrillic_IO
keycode 191 = Print Sys_Req Print Sys_Req Print Sys_Req
keycode 192 = Scroll_Lock NoSymbol Scroll_Lock NoSymbol Scroll_Lock
keycode 193 = Pause Break Pause Break Pause Break
keycode 49 = less greater less greater
keycode 108 = Multi_key Alt_L Multi_key Alt_L
setxkbmap way
In Linux, setxkbmap
is used to switch keyboard layouts. Alas, setxkbmap
& xmodmap
can't work together: they reset each other's changes :( You'll have to pick one of:
- Just don't switch layouts
- Invoke
xmodmap
after every layout switching (or make a script replacing setxkbmap
)
- modify
xkb
key mappings for your keyboard.
We'll use the latter. First, check which layout you're using:
$ setxkbmap -print
xkb_keymap {
xkb_keycodes { include "evdev+aliases(qwerty)" };
xkb_types { include "complete+caps(internal)" };
xkb_compat { include "complete" };
xkb_symbols { include "pc+us+ru:2+inet(evdev)+altwin(meta_win)+group(alt_shift_toggle)+compose(ralt)+eurosign(e)+terminate(ctrl_alt_bksp)+macintosh_vndr/apple(alupckeys)" };
xkb_geometry { include "pc(pc104)" };
};
Here's your symbols map: xkb_symbols ... macintosh_vndr/apple(alupckeys)
In Ubuntu, we have a mapping for apple keyboards here: '/usr/share/X11/xkb/symbols/macintosh_vndr/apple'. First, backup this file. This file has several sections, each starts like this:
xkb_symbols "extended" {
xkb_symbols "laptop" {
xkb_symbols "laptop_bad_switch" {
xkb_symbols "alukbd" {
xkb_symbols "alupckeys" {
The latter mapping, "alupckeys"
, replaces F13-F15 with PrintScreen, ScrollLock, Pause. Use it if you lack these keys :)
Choose the section you've got from the command output above, and append the following, before the final }
of the section:
key <LSGT> { [ grave, asciitilde, grave, asciitilde ] };
};
Now, restart X. Yeehaw, enjoy having the tilde key on the correct place :)
This command can also help:
$ setxkbmap -option "apple:alupckeys" -print | xkbcomp - $DISPLAY