Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Wrong keycodes reported for non-standard layouts. Fixed upstream #139

Closed
salty-horse opened this issue Dec 8, 2017 · 6 comments
Closed

Comments

@salty-horse
Copy link

servo-glutin reports no, or wrong, keycodes for most of my letter keys.

I encountered this bug while using Webrender's Wrench. It supports keyboard shortcuts to activate features, and none of them worked.

This has been fixed in winit, which is used by upstream glutin: rust-windowing/winit#273

There's a lot of changes between the codebases, but I managed to fix this by changing

let mut keysym = unsafe {
    (self.display.xlib.XKeycodeToKeysym)(self.display.display, event.keycode as ffi::KeyCode, 0)
};

to

let mut keysym = unsafe {
    let mut keysym = 0;
    let raw_ev: *mut ffi::XKeyEvent = event;
    (self.display.xlib.XLookupString)(raw_ev, ptr::null_mut(), 0, &mut keysym, ptr::null_mut());
    keysym
};

This is what setxkbmap reports for my keyboard:

$ setxkbmap  -print
xkb_keymap {
	xkb_keycodes  { include "evdev+aliases(qwerty)"	};
	xkb_types     { include "complete"	};
	xkb_compat    { include "complete"	};
	xkb_symbols   { include "pc+il+us:2+us:3+inet(evdev)+group(alt_shift_toggle)+compose(ralt)"	};
	xkb_geometry  { include "pc(pc105)"	};
};

I don't know how many more bugs lurk in servo-glutin that were fixed upstream (e.g. The function keycode_to_element should be named keysym_to_element). Are there any plans to merge upstream fixes?

@emilio
Copy link
Member

emilio commented Dec 8, 2017

See also servo/servo#19120

@emilio
Copy link
Member

emilio commented Dec 8, 2017

And the previous attempt servo/servo#17311

@paulrouget
Copy link

Is this fixed?

@salty-horse
Copy link
Author

This isn't fixed in branch servo (c18c62d).

I had to apply this fix from the commit I linked in my original report:

diff --git a/src/api/x11/input.rs b/src/api/x11/input.rs
index 9e600c4..d24fe11 100644
--- a/src/api/x11/input.rs
+++ b/src/api/x11/input.rs
@@ -158,3 +158,5 @@ impl XInputEventHandler {
         let mut keysym = unsafe {
-            (self.display.xlib.XKeycodeToKeysym)(self.display.display, event.keycode as ffi::KeyCode, 0)
+            let mut keysym = 0;
+            (self.display.xlib.XLookupString)(event, ptr::null_mut(), 0, &mut keysym, ptr::null_mut());
+            keysym
         };

I tested it by applying the following patch, running cargo run --example window, and presing H. Without the fix mentioned above, it didn't print the message.

diff --git a/examples/window.rs b/examples/window.rs
index ddf98a9..c811652 100644
--- a/examples/window.rs
+++ b/examples/window.rs
@@ -33,2 +33,3 @@ fn main() {
             glutin::Event::Closed => break,
+            glutin::Event::KeyboardInput(_, _, Some(glutin::VirtualKeyCode::H)) => println!("Pressed H"),
             _ => ()

@paulrouget
Copy link

Servo uses upstream glutin now.

@salty-horse
Copy link
Author

Upstream glutin is fine. You may close this bug if this codebase is deprecated.

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

No branches or pull requests

4 participants