From b6a63ad11f3b7e1c0df60881d33ffee2cdec8ce9 Mon Sep 17 00:00:00 2001 From: Avi Weinstock Date: Fri, 15 May 2015 18:30:40 -0400 Subject: Fix handling of numpad keys w.r.t. numlock (derived from fix mentioned at http://www.kaffe.org/pipermail/kaffe/2000-April/175201.html). Conflicts: src/api/x11/window.rs --- src/api/x11/window.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/api') diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs index 0994638..a5ccf6e 100644 --- a/src/api/x11/window.rs +++ b/src/api/x11/window.rs @@ -177,6 +177,8 @@ impl<'a> Iterator for PollEventsIterator<'a> { let state = if xev.get_type() == ffi::KeyPress { Pressed } else { Released }; + let mut kp_keysym = 0; + let written = unsafe { use std::str; @@ -184,7 +186,7 @@ impl<'a> Iterator for PollEventsIterator<'a> { let raw_ev: *mut ffi::XKeyEvent = event; let count = (self.window.x.display.xlib.Xutf8LookupString)(self.window.x.ic, mem::transmute(raw_ev), mem::transmute(buffer.as_mut_ptr()), - buffer.len() as libc::c_int, ptr::null_mut(), ptr::null_mut()); + buffer.len() as libc::c_int, &mut kp_keysym, ptr::null_mut()); str::from_utf8(&buffer[..count as usize]).unwrap_or("").to_string() }; @@ -196,10 +198,14 @@ impl<'a> Iterator for PollEventsIterator<'a> { } } - let keysym = unsafe { + let mut keysym = unsafe { (self.window.x.display.xlib.XKeycodeToKeysym)(self.window.x.display.display, event.keycode as ffi::KeyCode, 0) }; + if (ffi::XK_KP_Space as u64 <= keysym) || (keysym <= ffi::XK_KP_9 as u64) { + keysym = kp_keysym + }; + let vkey = events::keycode_to_element(keysym as libc::c_uint); return Some(KeyboardInput(state, event.keycode as u8, vkey)); -- cgit v1.2.3