Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong virtual keycode in WindowEvent from Alt key while holding Shift on X11 #1656

Closed
Bakutomo opened this issue Aug 18, 2020 · 3 comments
Closed
Labels
B - bug Dang, that shouldn't have happened C - needs discussion Direction must be ironed out DS - x11

Comments

@Bakutomo
Copy link

Platform:

X11 on Linux

Steps to reproduce:

  1. cargo run --example window | grep KeyboardInput
  2. hold either shift key down
  3. press or release the alt key

Expected result:

A WindowEvent with virtual_keycode: Some(LAlt)

Actual result:

A WindowEvent with virtual_keycode: None

The below output is from the input sequence:
press LShift, press LAlt, release LShift, release LAlt

DeviceEvent { device_id: DeviceId(X(DeviceId(12))), event: Key(KeyboardInput { scancode: 42, state: Pressed, virtual_keycode: Some(LShift), modifiers: (empty) }) }
WindowEvent { window_id: WindowId(X(WindowId(117440513))), event: KeyboardInput { device_id: DeviceId(X(DeviceId(3))), input: KeyboardInput { scancode: 42, state: Pressed, virtual_keycode: Some(LShift), modifiers: SHIFT }, is_synthetic: false } }

DeviceEvent { device_id: DeviceId(X(DeviceId(12))), event: Key(KeyboardInput { scancode: 56, state: Pressed, virtual_keycode: Some(LAlt), modifiers: SHIFT }) }
WindowEvent { window_id: WindowId(X(WindowId(117440513))), event: KeyboardInput { device_id: DeviceId(X(DeviceId(3))), input: KeyboardInput { scancode: 56, state: Pressed, virtual_keycode: None, modifiers: SHIFT | ALT }, is_synthetic: false } }

DeviceEvent { device_id: DeviceId(X(DeviceId(12))), event: Key(KeyboardInput { scancode: 42, state: Released, virtual_keycode: Some(LShift), modifiers: SHIFT | ALT }) }
WindowEvent { window_id: WindowId(X(WindowId(117440513))), event: KeyboardInput { device_id: DeviceId(X(DeviceId(3))), input: KeyboardInput { scancode: 42, state: Released, virtual_keycode: Some(LShift), modifiers: ALT }, is_synthetic: false } }

DeviceEvent { device_id: DeviceId(X(DeviceId(12))), event: Key(KeyboardInput { scancode: 56, state: Released, virtual_keycode: Some(LAlt), modifiers: ALT }) }
WindowEvent { window_id: WindowId(X(WindowId(117440513))), event: KeyboardInput { device_id: DeviceId(X(DeviceId(3))), input: KeyboardInput { scancode: 56, state: Released, virtual_keycode: Some(LAlt), modifiers: (empty) }, is_synthetic: false } }

Note that the virtual_keycode in DeviceEvent is correct. Only WindowEvent is affected. The same problem also happens if I hold RShift instead of LShift.

@murarth murarth added DS - x11 C - needs discussion Direction must be ironed out B - bug Dang, that shouldn't have happened labels Aug 18, 2020
@murarth
Copy link
Contributor

murarth commented Aug 19, 2020

The root cause of the problem is simple: On X11, winit uses an X KeySym value to determine which VirtualKeyCode to assign. X tells winit that the Alt key has a different keysym value when the Shift modifier is set. (Modifier state is not taken into account for DeviceEvent keysym lookup, which is why the virtual keycode is accurate for device events.)

Unfortunately, the solution is not so simple. winit could translate Shift+Alt keysyms to LAlt and RAlt, but I'm not sure whether that would be accurate for every possible environment. (These keysyms correspond to XK_Meta_L and XK_Meta_R on my system.)

Alternatively, winit could ignore modifier state altogether when assigning a key event's virtual keycode, but this has wider implications. There was some discussion on #812 about changing how winit determines virtual keycode, but it seems that no conclusions were reached.

@alice-i-cecile
Copy link

Reproduced in Leafwing-Studios/Emergence#342.

@kchibisov
Copy link
Member

not an issue anymore iirc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B - bug Dang, that shouldn't have happened C - needs discussion Direction must be ironed out DS - x11
Development

No branches or pull requests

4 participants