Skip to content

X11: DeviceEvent::Key modifiers never set #483

Closed

Description

@gmorenz

Arch Linux
x11
winit - all tested: 0.11.3 / 0.12.0 / current git head (eadd9a1)

All the fields of ModifierState are always false, regardless of whether or not I am holding shift/ctrl/alt/windows key. Shift/ctrl/false/window key presses and releases are registered as key event's and passed to my application, they just don't change the modifier state.

Test code:

extern crate winit;

use winit::{Event, EventsLoop, DeviceEvent, WindowEvent, Window, ControlFlow};

fn main() {
    let mut events_loop = EventsLoop::new();
    let _window = Window::new(&events_loop);

    events_loop.run_forever(|event| {
        match event {
            Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
                return ControlFlow::Break;
            },
            Event::DeviceEvent { event: DeviceEvent::Key(key), .. } => {
                println!("{:?}", key);
                if key.modifiers.shift == true {
                    panic!("... I can't get here?");
                }
            },
            _ => ()
        };

        ControlFlow::Continue
    });
}

Activity

  1. francesca64 commented on Apr 25, 2018

    @francesca64
    Member

    By your repro code, I'm guessing you're referring to the DeviceEvent modifiers and not WindowEvent?

  2. gmorenz commented on Apr 25, 2018

    @gmorenz
    Author

    Ah, you're right, WindowEvent works correctly, I'm guessing this is intentional and counts as user error then?

  3. francesca64 commented on Apr 25, 2018

    @francesca64
    Member

    Well, intentional is a strong word. It's just that the relevant X11 event has no modifier info associated with it, and so the only straightforward solution for this is to make a round-trip to the X server (which is something I've been working on reducing).

    I've thought of a cool idea for how to fix this, so I'll reopen this.

  4. changed the title [-]Key modifiers never set[/-] [+]X11: DeviceEvent::Key modifiers never set[/+] on Apr 25, 2018
  5. added
    B - bug
    DS - x11
    on Apr 25, 2018
  6. added
    D - hard
    P - low
    on May 6, 2018
  7. xla commented on May 21, 2019

    @xla

    @francesca64 Ran into this issue as well, Is it advised to track the state of the modifier keys independently? I'd like to perform an action when the user presses e.g. alt + n.

  8. francesca64 commented on May 21, 2019

    @francesca64
    Member

    @xla I'm not active here anymore. The X11 backend doesn't currently have a maintainer, so this bug probably won't be fixed for a while. You only need this feature if you want to handle modifiers while the window isn't focused; @Osspial is a better person to ask if you need more advice.

    For anyone who wants to fix this in the future, using the Xkb extension is the only way. This is esoteric, but I have a reference implementation here: francesca64@fe0e98e (I remember there being another branch from my second attempt to do this, but I didn't see one). The normal way to interpret the Xkb state info is using libxkbcommon, which is ubiquitous, but libxkbcommon-x11 isn't! So, to implement this, parts of libxkbcommon would have to be reimplemented. Note that getting Xkb to interop with XIM isn't possible, so you'd either A) only use Xkb for a subset of keyboard handling (like the modifiers in this issue), or B) write a custom IME client, which will likely be necessary longterm anyway due to the thread-safety/etc. issues with XIM, but is no small undertaking.

  9. murarth commented on Dec 5, 2019

    @murarth
    Contributor

    Closed by #1132, which implemented manual modifier state tracking in X11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    B - bugD - hardDS - x11P - low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions