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

KeyCode not sent for modified keys? #600

Closed
icefoxen opened this issue Jul 13, 2018 · 9 comments
Closed

KeyCode not sent for modified keys? #600

icefoxen opened this issue Jul 13, 2018 · 9 comments
Labels
B - bug Dang, that shouldn't have happened C - needs investigation Issue must be confirmed and researched DS - x11 S - platform parity Unintended platform differences

Comments

@icefoxen
Copy link
Contributor

Basically this is a question about "is this behavior intended?"

Using SDL2, when I press / then SDL sends a Slash keycode. Winit does the same. But if you press shift-/ (aka ?), SDL sends you the Slash keycode and Winit gives you the scancode but None for the keycode. Not sure what the "correct" approach is, so, is this intentional?

@francesca64
Copy link
Member

Which platforms?

@francesca64 francesca64 added F - question There's no such thing as a stupid one S - api Design and usability C - needs investigation Issue must be confirmed and researched labels Jul 13, 2018
@icefoxen
Copy link
Contributor Author

icefoxen commented Jul 13, 2018

Only looked at Linux+X11. Let me check Windows.

@icefoxen
Copy link
Contributor Author

Ok, on Windows, it uses SDL2's behavior; shift-/ produces a Slash keycode.

It didn't occur to me that there would be platform-specific differences/bugs. XD Linux is using xorg 1.19.6 on Debian Buster. Unfortunately I can't check Wayland or MacOS.

@francesca64
Copy link
Member

Looks like macOS has the same behavior as SDL too. Wayland just uses libxkbcommon, so it probably works too, though I can check with Weston I think.

It didn't occur to me that there would be platform-specific differences/bugs. XD

Much of winit's development history was pretty disjointed (since most people only contribute to one platform) so things like this are still pretty common, despite my best efforts.

@francesca64 francesca64 added B - bug Dang, that shouldn't have happened DS - x11 S - platform parity Unintended platform differences and removed S - api Design and usability F - question There's no such thing as a stupid one labels Jul 13, 2018
@icefoxen
Copy link
Contributor Author

Well, I'll see if I can submit a PR then. Likely culprits appear to be around https://github.com/tomaka/winit/blob/master/src/platform/linux/x11/mod.rs#L579 or https://github.com/tomaka/winit/blob/master/src/platform/linux/x11/mod.rs#L1031 . keysym_to_element() seems to mostly just do what it should be doing, I need to dig through X docs (start at man xkeyevent?) to figure out the details of what's going on.

@francesca64
Copy link
Member

francesca64 commented Jul 13, 2018

Well XLookupString is objectively terrible, or something like that (very deprecated). Since that's how we get the keysym, and we use the keysym to get the virtual keycode, that's an easy hole for problems.

The XI_Raw* stuff is for DeviceEvent, which use XInput2. If you want to know what that entails, well, I can tell you that too... XKeycodeToKeysym is probably deprecated too.

@icefoxen
Copy link
Contributor Author

Well, okay then, that gives me some idea of how things are. Where should I start for non-objectively terrible X input documentation, if such a thing even exists? :-)

@francesca64
Copy link
Member

As a rule of thumb with X11, information is sparse and unverifiable. You have the API docs, but those aren't prescriptive, and often aren't helpful until after you understand the problem. You have StackOverflow questions, but those usually only get one answer, and nothing spectacular... so, I almost always end up rummaging through the source code of Xlib, GLFW, GTK, etc.

GLFW is usually the best place to look, since GTK is pretty labyrinthian. SDL is easy enough to follow too, though I usually only check there if GLFW lets me down... I haven't checked out Qt, but I imagine it's slightly cleaner (but bigger) than GTK. Qt supposedly contains the arcane secrets of how to unify KeyboardInput with ReceivedCharacter on Windows, but, that's only a rumor.

It looks like XLookupString actually isn't deprecated? XKeycodeToKeysym is though, but I guess that doesn't matter here. Using XLookupString seems like it was a hack in the first place, since it's not really intended for getting keysyms, I don't think.

If your travels take you to XKB, you've gone too far. While using XKB would modernize our X11 keyboard stack, it would be a project... it has no interoperability with Xlib's built-in XIM client, so we'd have to write our own XIM client. While a pure Rust XIM client would be quite sexy compared to Xlib's globally-stateful thread-unsafe deadlock-happy dumpster-fire client, it would be a major pain to make. libxkbcommon-x11 also isn't always installed, so it would have to be reimplemented too... it was a total bummer when I realized all of this (especially since it wasn't until after trial-and-erroring my way through switching winit to using XKB).

Since XInput2 and XKB go hand in hand, this means solutions involving XInput2 are also out, though there's no risk of you finding those! The full extent of XInput2's documentation is a few blogspot posts by the guy who designed it (I'm not joking).

@traviscross
Copy link

This issue appears to be related to the following issues in projects which depend on winit:

rust-windowing/glutin#979
alacritty/alacritty#1054
alacritty/alacritty#1010

On the winit side, this appears related to:

#273
#274
commit 52a78d6

@Osspial Osspial added this to the Keyboard Events Overhaul milestone Apr 24, 2019
kchibisov added a commit that referenced this issue May 28, 2023
Overhaul the keyboard API in winit to mimic the W3C specification
to achieve better crossplatform parity. The `KeyboardInput` event
is now uses `KeyEvent` which consists of:

  - `physical_key` - a cross platform way to refer to scancodes;
  - `logical_key`  - keysym value, which shows your key respecting the
                     layout;
  - `text`         - the text produced by this keypress;
  - `location`     - the location of the key on the keyboard;
  - `repeat`       - whether the key was produced by the repeat.

And also a `platform_specific` field which encapsulates extra
information on desktop platforms, like key without modifiers
and text with all modifiers.

The `Modifiers` were also slightly reworked as in, the information
whether the left or right modifier is pressed is now also exposed
on platforms where it could be queried reliably. The support was
also added for the web and orbital platforms finishing the API
change.

This change made the `OptionAsAlt` API on macOS redundant thus it
was removed all together.

Co-Authored-By: Artúr Kovács <kovacs.artur.barnabas@gmail.com>
Co-Authored-By: Kirill Chibisov <contact@kchibisov.com>
Co-Authored-By: daxpedda <daxpedda@gmail.com>
Fixes: #2631.
Fixes: #2055.
Fixes: #2032.
Fixes: #1904.
Fixes: #1810.
Fixes: #1700.
Fixes: #1443.
Fixes: #1343.
Fixes: #1208.
Fixes: #1151.
Fixes: #812.
Fixes: #600.
Fixes: #361.
Fixes: #343.
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 investigation Issue must be confirmed and researched DS - x11 S - platform parity Unintended platform differences
Development

No branches or pull requests

4 participants