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

Fix x11 DeviceEvent ModifiersStates #228

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub enum DeviceEvent {
Removed,
Motion { axis: AxisId, value: f64 },
Button { button: ButtonId, state: ElementState },
Key(KeyboardInput),
Key(DeviceKeyboardInput),
Text { codepoint: char },
}

Expand Down Expand Up @@ -123,6 +123,24 @@ pub struct KeyboardInput {
pub modifiers: ModifiersState
}

#[derive(Debug, Clone, Copy)]
pub struct DeviceKeyboardInput {
/// Identifies the physical key pressed
///
/// This should not change if the user adjusts the host's keyboard map. Use when the physical location of the
/// key is more important than the key's host GUI semantics, such as for movement controls in a first-person
/// game.
pub scancode: ScanCode,

pub state: ElementState,

/// Identifies the semantic meaning of the key
///
/// Use when the semantics of the key are more important than the physical location of the key, such as when
/// implementing appropriate behavior for "page up."
pub virtual_keycode: Option<VirtualKeyCode>,
}

#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
pub enum TouchPhase {
Started,
Expand Down
5 changes: 2 additions & 3 deletions src/platform/linux/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod ffi;

use platform::PlatformSpecificWindowBuilderAttributes;
use {CreationError, Event, EventsLoopClosed, WindowEvent, DeviceEvent, AxisId, ButtonId,
KeyboardInput, ControlFlow};
KeyboardInput, DeviceKeyboardInput, ControlFlow};

use std::{mem, ptr, slice};
use std::sync::{Arc, Mutex, Weak};
Expand Down Expand Up @@ -533,15 +533,14 @@ impl EventsLoop {
// TODO: Use xkbcommon for keysym and text decoding
let xev: &ffi::XIRawEvent = unsafe { &*(xev.data as *const _) };
let xkeysym = unsafe { (self.display.xlib.XKeycodeToKeysym)(self.display.display, xev.detail as ffi::KeyCode, 0) };
callback(Event::DeviceEvent { device_id: mkdid(xev.deviceid), event: DeviceEvent::Key(KeyboardInput {
callback(Event::DeviceEvent { device_id: mkdid(xev.deviceid), event: DeviceEvent::Key(DeviceKeyboardInput {
scancode: xev.detail as u32,
virtual_keycode: events::keysym_to_element(xkeysym as libc::c_uint),
state: match xev.evtype {
ffi::XI_RawKeyPress => Pressed,
ffi::XI_RawKeyRelease => Released,
_ => unreachable!(),
},
modifiers: ::events::ModifiersState::default(),
})});
}

Expand Down