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

Substract virtual keycode not sent in WindowEvent #979

Closed
chrisduerr opened this issue Jan 8, 2018 · 6 comments
Closed

Substract virtual keycode not sent in WindowEvent #979

chrisduerr opened this issue Jan 8, 2018 · 6 comments

Comments

@chrisduerr
Copy link
Contributor

chrisduerr commented Jan 8, 2018

This issue was originally reported by @NickeZ in alacritty/alacritty#1010.

I've tested this with a slightly modified version of the window.rs example:
https://gist.github.com/chrisduerr/5dead96a0279592d2e320e088b611a87

The general issue is that when the Shift key and the Substract key are pressed at the same time, the WindowEvent's KeyboardInput will have None as virtual_keycode.

However reading the DeviceEvent's KeyboardInput, it will report Some(Substract) as the virtual_keycode.

To compare the two outputs directly, here's the WindowEvent output:

KeyboardInput { device_id: DeviceId(X(DeviceId(3))), input: KeyboardInput { scancode: 12, state: Released, virtual_keycode: None, modifiers: ModifiersState { shift: true, ctrl: false, alt: false, logo: false } } }

And here's the DeviceEvent output:

Key(KeyboardInput { scancode: 12, state: Released, virtual_keycode: Some(Subtract), modifiers: ModifiersState { shift: false, ctrl: false, alt: false, logo: false } })

To be it seems like the WindowEvent should also report Some(Substract) as the virtual_keycode, or report Some(Underline) at least. However not reporting any virtual_keycode seems a bit strange to me.

Simililar problems have been reported for the Key0 virtual_keycode.

@NickeZ
Copy link

NickeZ commented Jan 9, 2018

It is actually a change in winit that broke this. If I revert the following changeset it works again: rust-windowing/winit@52a78d6#diff-c3f6b02da9e467b737e84b8236fa5ba2

@NickeZ
Copy link

NickeZ commented Jan 9, 2018

The following changes to winit and alacritty fixes my issues. I don't know what the proper solution is though. Seems like a lot of fields will have to be added to these structs to support all keys.

diff --git a/src/events.rs b/src/events.rs
index 2947db1..3ed5b02 100644
--- a/src/events.rs
+++ b/src/events.rs
@@ -379,6 +379,7 @@ pub enum VirtualKeyCode {
     LBracket,
     LControl,
     LMenu,
+    LParen,
     LShift,
     LWin,
     Mail,
@@ -404,6 +405,7 @@ pub enum VirtualKeyCode {
     RBracket,
     RControl,
     RMenu,
+    RParen,
     RShift,
     RWin,
     Semicolon,
@@ -414,6 +416,7 @@ pub enum VirtualKeyCode {
     Sysrq,
     Tab,
     Underline,
+    Underscore,
     Unlabeled,
     VolumeDown,
     VolumeUp,
diff --git a/src/platform/linux/x11/events.rs b/src/platform/linux/x11/events.rs
index c17cfe7..76e3209 100644
--- a/src/platform/linux/x11/events.rs
+++ b/src/platform/linux/x11/events.rs
@@ -181,8 +181,8 @@ pub fn keysym_to_element(keysym: libc::c_uint) -> Option<VirtualKeyCode> {
         //ffi::XK_ampersand => events::VirtualKeyCode::Ampersand,
         ffi::XK_apostrophe => events::VirtualKeyCode::Apostrophe,
         //ffi::XK_quoteright => events::VirtualKeyCode::Quoteright,
-        //ffi::XK_parenleft => events::VirtualKeyCode::Parenleft,
-        //ffi::XK_parenright => events::VirtualKeyCode::Parenright,
+        ffi::XK_parenleft => events::VirtualKeyCode::LParen,
+        ffi::XK_parenright => events::VirtualKeyCode::RParen,
         //ffi::XK_asterisk => events::VirtualKeyCode::Asterisk,
         ffi::XK_plus => events::VirtualKeyCode::Add,
         ffi::XK_comma => events::VirtualKeyCode::Comma,
@@ -236,7 +236,7 @@ pub fn keysym_to_element(keysym: libc::c_uint) -> Option<VirtualKeyCode> {
         ffi::XK_backslash => events::VirtualKeyCode::Backslash,
         ffi::XK_bracketright => events::VirtualKeyCode::RBracket,
         //ffi::XK_asciicircum => events::VirtualKeyCode::Asciicircum,
-        //ffi::XK_underscore => events::VirtualKeyCode::Underscore,
+        ffi::XK_underscore => events::VirtualKeyCode::Underscore,
         ffi::XK_grave => events::VirtualKeyCode::Grave,
         //ffi::XK_quoteleft => events::VirtualKeyCode::Quoteleft,
         ffi::XK_a => events::VirtualKeyCode::A,
diff --git a/src/config.rs b/src/config.rs
index be96715..56c4a30 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1841,6 +1841,7 @@ enum Key {
     LBracket,
     LControl,
     LMenu,
+    LParen,
     LShift,
     LWin,
     Mail,
@@ -1866,6 +1867,7 @@ enum Key {
     RBracket,
     RControl,
     RMenu,
+    RParen,
     RShift,
     RWin,
     Semicolon,
@@ -1876,6 +1878,7 @@ enum Key {
     Sysrq,
     Tab,
     Underline,
+    Underscore,
     Unlabeled,
     VolumeDown,
     VolumeUp,
@@ -1998,6 +2001,7 @@ impl Key {
             Key::LBracket => LBracket,
             Key::LControl => LControl,
             Key::LMenu => LMenu,
+            Key::LParen => LParen,
             Key::LShift => LShift,
             Key::LWin => LWin,
             Key::Mail => Mail,
@@ -2023,6 +2027,7 @@ impl Key {
             Key::RBracket => RBracket,
             Key::RControl => RControl,
             Key::RMenu => RMenu,
+            Key::RParen => RParen,
             Key::RShift => RShift,
             Key::RWin => RWin,
             Key::Semicolon => Semicolon,
@@ -2033,6 +2038,7 @@ impl Key {
             Key::Sysrq => Sysrq,
             Key::Tab => Tab,
             Key::Underline => Underline,
+            Key::Underscore => Underscore,
             Key::Unlabeled => Unlabeled,
             Key::VolumeDown => VolumeDown,
             Key::VolumeUp => VolumeUp,

@francesca64
Copy link
Member

Was this ever fixed? (This also belongs on winit, obviously.)

@NickeZ
Copy link

NickeZ commented May 16, 2018

No, I never submitted a PR because my patch doesn't solve the general problem that there are a lot of commented out keys in src/platform/linux/x11/events.rs.

@francesca64
Copy link
Member

That problem will honestly never be fixed unless someone decides to push for more rigorous keyboard API design (rust-windowing/winit#71) which I don't see as likely to happen in the foreseeable future.

@traviscross
Copy link

This issue has been filed with winit as rust-windowing/winit#600.

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

No branches or pull requests

4 participants