M-SPC doesn’t work on WSL2 on Win11 [Solved]

Copied this from Discord to make it search-engine-findable.

Original question:

Using M-SPC to bring up the Doom key binds simply doesn’t work in any mode (insert, emacs, etc). I didn’t actually care that much until starting to use Org mode more where leaving insert mode while note taking seems like a bigger cognitive hit than when I’m programming. Any ideas why this might be happening? Running is WSL2 Ubuntu 24.04 under Win11 23H2. Already disabled powertoys power run, which initially conflicted. In most other Windows native programs M-SPC brings up the window menu (maximize, minimize, etc) but this does not occur with WSL emacs

Solution

This is a general problem with WSL GUI apps/X11 and can be solved in this comment thread on wslg: https://github.com/microsoft/wslg/issues/1068

Summary:

  1. Use Windows PowerToys Keyboard Manager to add a remap of Alt-Space to Alt-F13 for the application msrdc.exe. It is likely that some other remapper would also work, but I have not tested it.
  2. Add the line xmodmap -e 'keycode 191 = space' to the WSL .bashrc and/or .bash_profile (.bashrc is necessary for this remap to be called when Emacs is started from the Windows start menu). Keycode 191 is F13.
  3. Profit

tags: wsl, windows subsystem for linux, alt, space, leader, windows 11, alt-leader