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

[Left/RightShift + <key>] not picked up by get_keys on wayland #349

Open
bhavyakukkar opened this issue Mar 28, 2024 · 3 comments
Open

[Left/RightShift + <key>] not picked up by get_keys on wayland #349

bhavyakukkar opened this issue Mar 28, 2024 · 3 comments
Labels

Comments

@bhavyakukkar
Copy link

When pressing the Left/Right-Shift key first, followed by any other key, the set of keys down returned by get_keys only contains the Left/Right-Shift key on the wayland build.

This is a program to demonstrate the issue:

use minifb::{Key, Window, WindowOptions, KeyRepeat};

fn main() {
    let mut buffer: Vec<u32> = vec![0; 200*200];
    let mut window = Window::new("", 200, 200, WindowOptions::default()).unwrap();

    window.limit_update_rate(Some(std::time::Duration::from_micros(16600)));

    loop {
        if window.is_open() {
            let keys = window.get_keys();
            if keys.len() == 2 {
                panic!("Received these two keys: {:?}", keys);
            }

            window
                .update_with_buffer(&buffer, 200, 200)
                .unwrap();
        }
    }
}

This program,

  • when run with only the 'x11' cargo feature:

does panic when LeftShift+L (LeftShift then L) is typed (desired behavior)

thread 'main' panicked at src/main.rs:13:17:
Received these two keys: [L, LeftShift]
  • when run with only the 'wayland' cargo feature:

does not panic when LeftShift+L (LeftShift then L) is typed (undesired behavior)

I have tested:

  • both builds on two wayland-compositors: sway & dwl (letting the compositor infer & start an xwayland server for the X11 builds)
    The problem only occurs in the wayland builds, i.e. the program does not panic on the wayland builds.
  • the X11 build on two xorg window-managers: dwm & bspwm
    The problem does not occur, i.e. the program does panic.

Additionally,

  • I tried both the latest crates.io version (v0.25.0) and git version (latest commit 29af982) of minifb

$ rustc --version
rustc 1.76.0 (07dca489a 2024-02-04) (Void Linux)

bhavyakukkar added a commit to bhavyakukkar/pixylene that referenced this issue Mar 30, 2024
- Force minifb to build x11 window since wayland window currently has an
  inconsistency with pressing shift keys, as reported in [this
  issue](emoon/rust_minifb#349)
@emoon emoon added the wayland label Apr 1, 2024
@emoon
Copy link
Owner

emoon commented Apr 1, 2024

Thanks for the report

@Aeledfyr
Copy link

It looks like the source of this issue is that the wayland -> XKB keycode mapping takes into account whether shift is held and return the uppercase versions, but the XKB -> minifb keycode mapping only handles the lowercase XKB keycodes.

let key_xkb = unsafe { ffi_dispatch!(XKBH, xkb_state_key_get_one_sym, keymap_state, key) };

As an example, when a is pressed without shift, this returns 97 (0x61), which is recognized as key::XKB_KEY_a and mapped to Key::A. When shift is held, key_xkb instead becomes 65 (0x41), which has no mapping and is ignored.

The same issue applies to all keys (on my keyboard) except enter, space, escape, backspace, control, and function keys. Oddly, left alt and tab are both affected, so fixing that may take additional consideration.

@emoon
Copy link
Owner

emoon commented Jan 21, 2025

Thanks. I have started to move over to the latest wayland crates on a new branch, but it will likely take a while to get that work done as there are tons of code that doesn't work anymore and I haven't written any of the wayland backend myself, but there are tons of wayland open issues so I will try to get to them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants