Add switch-keys for Caps Lock swap | Generated by AI
Here’s a full breakdown of the commit:
Commit: cf64c23 — feat: add ww linux switch-keys — swap Caps Lock and Left Ctrl on X11
New file: ww/linux/switch_keys.py (260 lines)
Core module with 3 responsibilities:
- State detection — checks 3 sources to determine whether the swap is active:
setxkbmap -queryfor thectrl:swapcapsoption- Live
xmodmap -pkeoutput to see if keycodes 37/66 are remapped ~/.Xmodmapfile on disk for persistent config
- Runtime apply/revert:
on→ runssetxkbmap -option ctrl:swapcapsoff→ clears all options (setxkbmap -option), re-addsterminate:ctrl_alt_bksp, and resets xmodmap for keycodes 37 and 66
- Persistence management:
--persistonon: writes~/.Xmodmapwith keycode-based swap (keycode 66 = Control_L,keycode 37 = Caps_Lock, clear/add Lock/Control) and appends the xmodmap load line to~/.xprofile--persistonoff: removes~/.Xmodmapand strips the swap-related lines from~/.xprofile- Without
--persist, prompts interactively: “Also persist this setting across reboots?”
- Argument parsing via argparse with one optional positional arg (
on/off) and a--persistflag
Modified: ww/linux/main.py (+3 lines)
- Added
switch-keysto the help listing - Added the import-and-call route:
elif subcmd == "switch-keys"→from ww.linux.switch_keys import run; run()
Modified: ww/main.py (+1 line)
- Added
" ww linux switch-keys Swap Caps Lock and Left Control keys"to the top-level help output
Design choices:
- Targets X11 only (errors out if
DISPLAYorXDG_SESSION_TYPE=x11isn’t set) - Uses
setxkbmapfor runtime (lightweight, no Xmodmap reset needed) and~/.Xmodmapfor persistence (autoloaded by most X11 display managers) - Tracks both the
setxkbmap -queryoption AND livexmodmapstate, because the two can independently set the swap