Bumping this! Your pinkies will thank me
All of my muscle memory is Mac based, and I use a Mac at work and in my personal life, but I happened across a Dell Latitude E7470 and figured I might as well give Linux a go on it (since my Macbook Pro is from 2012 and is pretty heavy, and I just didn't want to have to bother with \r\n line endings). So it's been a slow-moving work in progress to figure out how to modify the system to match my muscle memory instead of relearning keyboard shortcuts.
At first, I was just using the Keyboard > Layouts > Options... settings for "Ctrl is mapped to Alt; Alt is mapped to Win" but, and this is a very minor thing, I didn't like that my settings didn't apply until after I got past the greeter. I was also having trouble getting ~/.Xmodmap to run on start (either by itself, as part of .xinitrc and as a custom startup command in startup applications and in /etc/default/
I'm currently running Ubuntu MATE 19.10 (Eoan), and the keyboard is recognized as a pc105
You'll have to modify the script below (or the individual files, if you've already made other modifications to them that you want to keep) to match whatever keyboard your computer has.
Make ~/.Xmodmap:
echo '! -*- coding: utf-8 -*-
! keycode 37 = Control_L NoSymbol Control_L
! keycode 64 = Alt_L Meta_L Alt_L Meta_L
! keycode 105 = Control_R NoSymbol Control_R
! keycode 108 = Alt_R Meta_R Alt_R Meta_R
! keycode 133 = Super_L NoSymbol Super_L
! keycode 134 = Super_R NoSymbol Super_R
! keycode 135 = Menu NoSymbol Menu
! keycode 147 = XF86MenuKB NoSymbol XF86MenuKB
! keycode 204 = NoSymbol Alt_L NoSymbol Alt_L
! keycode 206 = NoSymbol Super_L NoSymbol Super_L
!
! keycode 105 = Alt_R Meta_R
clear control
clear mod1
clear mod4
keycode 37 = Super_L
keycode 105 = Super_R
keycode 133 = Alt_L Meta_L
keycode 64 = Control_L
keycode 108 = Control_R
add control = Control_L Control_R
add mod1 = Alt_L Meta_L
add mod4 = Super_L Super_R' > ~/.Xmodmap
make ~/.xinitrc:
echo 'if [ -s ~/.Xmodmap ]; then
xmodmap ~/.Xmodmap
fi
xmodmap ~/.Xmodmap' > ~/.xinitrc
Modify X11 Keyboard symbol file for your keyboard (the important part here is the include "altwin(ctrl_alt_win)"
before // End of modifier mappings.
This is an otherwise unmodified /usr/share/X11/xkb/symbols/pc file):
echo 'default partial alphanumeric_keys modifier_keys
xkb_symbols "pc105" {
key <ESC> { [ Escape ] };
// The extra key on many European keyboards:
key <LSGT> { [ less, greater, bar, brokenbar ] };
// The following keys are common to all layouts.
key <BKSL> { [ backslash, bar ] };
key <SPCE> { [ space ] };
include "srvr_ctrl(fkey2vt)"
include "pc(editing)"
include "keypad(x11)"
key <BKSP> { [ BackSpace, BackSpace ] };
key <TAB> { [ Tab, ISO_Left_Tab ] };
key <RTRN> { [ Return ] };
key <CAPS> { [ Caps_Lock ] };
key <NMLK> { [ Num_Lock ] };
key <LFSH> { [ Shift_L ] };
key <LCTL> { [ Control_L ] };
key <LWIN> { [ Super_L ] };
key <RTSH> { [ Shift_R ] };
key <RCTL> { [ Control_R ] };
key <RWIN> { [ Super_R ] };
key <MENU> { [ Menu ] };
// Beginning of modifier mappings.
modifier_map Shift { Shift_L, Shift_R };
modifier_map Lock { Caps_Lock };
modifier_map Control{ Control_L, Control_R };
modifier_map Mod2 { Num_Lock };
modifier_map Mod4 { Super_L, Super_R };
// Fake keys for virtual<->real modifiers mapping:
key <LVL3> { [ ISO_Level3_Shift ] };
key <MDSW> { [ Mode_switch ] };
modifier_map Mod5 { <LVL3>, <MDSW> };
key <ALT> { [ NoSymbol, Alt_L ] };
include "altwin(meta_alt)"
key <META> { [ NoSymbol, Meta_L ] };
modifier_map Mod1 { <META> };
key <SUPR> { [ NoSymbol, Super_L ] };
modifier_map Mod4 { <SUPR> };
key <HYPR> { [ NoSymbol, Hyper_L ] };
modifier_map Mod4 { <HYPR> };
include "altwin(ctrl_alt_win)"
// End of modifier mappings.
key <OUTP> { [ XF86Display ] };
key <KITG> { [ XF86KbdLightOnOff ] };
key <KIDN> { [ XF86KbdBrightnessDown ] };
key <KIUP> { [ XF86KbdBrightnessUp ] };
};
hidden partial alphanumeric_keys
xkb_symbols "editing" {
key <PRSC> {
type= "PC_ALT_LEVEL2",
symbols[Group1]= [ Print, Sys_Req ]
};
key <SCLK> { [ Scroll_Lock ] };
key <PAUS> {
type= "PC_CONTROL_LEVEL2",
symbols[Group1]= [ Pause, Break ]
};
key <INS> { [ Insert ] };
key <HOME> { [ Home ] };
key <PGUP> { [ Prior ] };
key <DELE> { [ Delete ] };
key <END> { [ End ] };
key <PGDN> { [ Next ] };
key <UP> { [ Up ] };
key <LEFT> { [ Left ] };
key <DOWN> { [ Down ] };
key <RGHT> { [ Right ] };
};' >/usr/share/x11/xkb/symbols/pc
And just in case, here's the relevant part of /usr/share/X11/xkb/symbols/altwin if you need to add it manually:
// Ctrl is mapped to the Alt, Alt to the Super, and Win to the Ctrl keys.
partial modifier_keys
xkb_symbols "ctrl_alt_win" {
key <LALT> { [ Control_L, Control_L ] };
key <RALT> { type[Group1] = "TWO_LEVEL",
symbols[Group1] = [ Control_R, Control_R ] };
key <LWIN> { [ Alt_L, Meta_L ] };
key <RWIN> { [ Alt_R, Meta_R ] };
key <LCTL> { [ Super_L ] };
key <RCTL> { [ Super_R ] };
modifier_map Control { <RALT>, <LALT> };
modifier_map Mod1 { <LWIN>, <RWIN> };
modifier_map Mod4 { <LCTL>, <RCTL> };
};
Modify /etc/defaults/keyboard:
echo '# KEYBOARD CONFIGURATION FILE
# Consult the keyboard(5) manual page.
XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS="caps:shift_nocancel,ctrl:alt,alt:win,win:ctrl"
BACKSPACE="guess"' >/etc/default/keyboard
And finally, here's my GNOME and Marco keybinding dconf dumps:
GNOME:
[org/gnome/desktop/wm/keybindings]
activate-window-menu=['disabled']
begin-move=['disabled']
close=['<Control>q']
maximize=['<Alt><Super>m']
minimize=['<Control>m']
move-to-corner-ne=['disabled']
move-to-corner-nw=['disabled']
move-to-corner-se=['disabled']
move-to-corner-sw=['disabled']
move-to-side-e=['disabled']
move-to-side-n=['disabled']
move-to-side-s=['disabled']
move-to-side-w=['disabled']
move-to-workspace-1=['<Shift><Super>Home']
move-to-workspace-down=['<Shift><Super>Next']
move-to-workspace-up=['<Shift><Super>Prior']
show-desktop=['<Control>F3']
switch-to-workspace-1=['<Super>Home']
switch-to-workspace-down=['<Super>Next']
switch-to-workspace-up=['<Super>Prior']
switch-windows=['disabled']
switch-windows-backward=['disabled']
toggle-fullscreen=['<Control><Super>f']
toggle-maximized=['<Shift><Control>m']
toggle-shaded=['<Alt><Super>s']
unmaximize=['<Control><Alt>m']
Marco:
[org/mate/marco/global-keybindings]
cycle-group='<Primary>grave'
cycle-panels='disabled'
cycle-windows='<Alt>grave'
run-command-screenshot='<Primary><Shift>numbersign'
run-command-window-screenshot='<Primary><Shift>dollar'
show-desktop='<Primary>F3'
switch-group='<Alt>Tab'
switch-to-workspace-1='<Primary><Mod4>1'
switch-to-workspace-2='<Primary><Mod4>3'
switch-to-workspace-3='<Primary><Mod4>2'
switch-to-workspace-4='<Primary><Mod4>4'
switch-to-workspace-down='<Mod4>Down'
switch-to-workspace-left='<Mod4>Left'
switch-to-workspace-prev='<Shift><Mod4>Tab'
switch-to-workspace-right='<Mod4>Right'
switch-to-workspace-up='<Mod4>Up'
switch-windows='<Primary>Tab'
[org/mate/marco/window-keybindings]
activate-window-menu='disabled'
begin-move='<Primary><Shift><Mod4>m'
begin-resize='<Primary><Shift><Mod4>r'
close='<Primary>q'
maximize='<Alt><Mod4>m'
maximize-horizontally='<Alt><Mod4>h'
maximize-vertically='<Alt><Mod4>v'
minimize='<Primary>m'
move-to-corner-ne='<Alt><Mod4>2'
move-to-corner-nw='<Alt><Mod4>1'
move-to-corner-se='<Alt><Mod4>4'
move-to-corner-sw='<Alt><Mod4>3'
move-to-side-e='<Alt><Mod4>Left'
move-to-side-n='<Alt><Mod4>Up'
move-to-side-s='<Alt><Mod4>Down'
move-to-side-w='<Alt><Mod4>Right'
move-to-workspace-1='<Primary><Alt><Mod4>1'
move-to-workspace-2='<Primary><Alt><Mod4>2'
move-to-workspace-3='<Primary><Alt><Mod4>3'
move-to-workspace-4='<Primary><Alt><Mod4>4'
move-to-workspace-down='<Primary><Mod4>Down'
move-to-workspace-left='<Primary><Mod4>Left'
move-to-workspace-right='<Primary><Mod4>Right'
move-to-workspace-up='<Primary><Mod4>Up'
tile-to-corner-ne='<Shift><Alt>at'
tile-to-corner-nw='<Shift><Alt>exclam'
tile-to-corner-se='<Shift><Alt>dollar'
tile-to-corner-sw='<Shift><Alt>numbersign'
tile-to-side-e='<Shift><Alt>Right'
tile-to-side-w='<Shift><Alt>Left'
toggle-fullscreen='<Primary><Mod4>f'
toggle-maximized='<Primary><Shift>m'
toggle-shaded='<Alt><Mod4>s'
unmaximize='<Alt><Mod4>r'