microsoft / wslg

Enabling the Windows Subsystem for Linux to include support for Wayland and X server related scenarios
MIT License
10.17k stars 304 forks source link

Alt-space doesn't generate an X11 KeyPress #1068

Open aimfiz opened 1 year ago

aimfiz commented 1 year ago

Windows build number:

10.0.22621.1702

Your Distribution version:

22.04

Your WSL versions:

WSL version: 1.2.5.0 Kernel version: 5.15.90.1 WSLg version: 1.0.51 MSRDC version: 1.2.3770 Direct3D version: 1.608.2-61064218 DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows version: 10.0.22621.1702

Steps to reproduce:

xev -event keyboard [type alt-space]

WSL logs:

No response

WSL dumps:

No response

Expected behavior:

KeyPress event, serial 25, synthetic NO, window 0x600001,
    root 0x390, subw 0x0, time 8639038, (132,-51), root:(1023,471),
    state 0x10, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyPress event, serial 28, synthetic NO, window 0x600001,
    root 0x390, subw 0x0, time 8639100, (132,-51), root:(1023,471),
    state 0x18, keycode 65 (keysym 0x20, space), same_screen YES,
    XLookupString gives 1 bytes: (20) " "
    XmbLookupString gives 1 bytes: (20) " "
    XFilterEvent returns: False

KeyRelease event, serial 28, synthetic NO, window 0x600001,
    root 0x390, subw 0x0, time 8639200, (132,-51), root:(1023,471),
    state 0x18, keycode 65 (keysym 0x20, space), same_screen YES,
    XLookupString gives 1 bytes: (20) " "
    XFilterEvent returns: False

KeyRelease event, serial 28, synthetic NO, window 0x600001,
    root 0x390, subw 0x0, time 8640190, (132,-51), root:(1023,471),
    state 0x18, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

Actual behavior:

KeyPress event, serial 25, synthetic NO, window 0x600001,
    root 0x390, subw 0x0, time 8639038, (132,-51), root:(1023,471),
    state 0x10, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyRelease event, serial 28, synthetic NO, window 0x600001,
    root 0x390, subw 0x0, time 8640190, (132,-51), root:(1023,471),
    state 0x18, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

If pressing alt-space brought up the usual Windows menu for the window, then I would assume that that was the intended behavior, but it doesn't do that either. It just does nothing. If it's supposed to bring up a Windows menu, and that bug gets fixed, then please consider this bug report to be a feature request for some way to turn that feature off and have the alt-space usable by X11 applications.

terlar commented 1 year ago

This is quite annoying, I managed to get a work-around for my use-case by using PowerToys Keyboard Manager, by rebinding Alt-Space shortcut to Escape, since in my application Escape is same as Alt, but then I always have to do Alt-Space Space to get Alt-Space. Would be really nice if this could be fixed somehow, wherever this get's lost.

aimfiz commented 1 year ago

@terlar, thank you for your response, which helped me find a workaround. In PowerToys Keyboard Manager, make a shortcut mapping Alt-Space to Alt-F13 for application "msrdc.exe", and in WSL map keycode 191 to space using "xmodmap -e 'keycode 191 = space'". This seems to work well, making all WSL windows see alt-space as the ordinary key combination alt-space, while it retains its usual meaning in Windows windows (pulling up the application menu).

UndeadKernel commented 1 year ago

Could there maybe be a way to configure keybindings for msrdc.exe? I would also like to use Alt-Space in many of my GUI applications (e.g., emacs).

aimfiz commented 1 year ago

Could there maybe be a way to configure keybindings for msrdc.exe? I would also like to use Alt-Space in many of my GUI applications (e.g., emacs).

The PowerToys Keyboard Manager does provide a way to configure keybindings for msrdc. Are you saying you're unable to get my workaround to work? Or are you just saying there should be a more convenient way to do it?

Here's what my Keyboard Manager shortcut looks like in PowerToys: image

And here's the operative line in my ~/.bash_profile:

xmodmap -e 'keycode 191 = space'

With those measures in place, starting emacs with "emacs -Q" and then entering the key sequence Ctrl-h c Alt-space causes emacs to respond with "M-SPC runs the command just-one-space".

goldfita commented 1 year ago

If you just want the default behavior for emacs Alt-space, it's easier to remap F13 to the function just-one-space than messing with xmodmap.

(keymap-global-set "<XF86Tools>" 'just-one-space)

In PowerToys, you would then map Alt-space to F13, not Alt-F13.

mavbozo commented 12 months ago

I'm also having this trouble with my emacs where I bind ALT+SPACE to specific function

saccohuo commented 11 months ago

Could there maybe be a way to configure keybindings for msrdc.exe? I would also like to use Alt-Space in many of my GUI applications (e.g., emacs).

The PowerToys Keyboard Manager does provide a way to configure keybindings for msrdc. Are you saying you're unable to get my workaround to work? Or are you just saying there should be a more convenient way to do it?

Here's what my Keyboard Manager shortcut looks like in PowerToys: image

And here's the operative line in my ~/.bash_profile:

xmodmap -e 'keycode 191 = space'

With those measures in place, starting emacs with "emacs -Q" and then entering the key sequence Ctrl-h c Alt-space causes emacs to respond with "M-SPC runs the command just-one-space".

If you are using emacs in wslg, replace the second step in @aimfiz 's solution to add xmodmap setting in emacs.

  1. Add Alt+Space-->Alt+F13 in PowerToys Keyboard Manager.
  2. Add (eshell-command "xmodmap -e 'keycode 191 = space'") into your emacs init file, for example init.el.