aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortomaka <pierre.krieger1708@gmail.com>2014-10-27 07:20:00 +0100
committertomaka <pierre.krieger1708@gmail.com>2014-10-27 07:20:00 +0100
commit32eba169949bfb279cbc09e49801c63027c8a6ab (patch)
treea620ab99f5e535d5cd7cf67e584c12f9f1e2a793 /src
parent03c55230f0ecbf0ac2fff1a0ca2248ebdafe5215 (diff)
parente19dd83925b062d15422a318f727ddef6042023e (diff)
downloadglutin-32eba169949bfb279cbc09e49801c63027c8a6ab.tar.gz
glutin-32eba169949bfb279cbc09e49801c63027c8a6ab.zip
Merge pull request #77 from glennw/x11-modifiers
Add support for keyboard modifiers on x11.
Diffstat (limited to 'src')
-rw-r--r--src/x11/window/mod.rs34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs
index c2381fd..d244d61 100644
--- a/src/x11/window/mod.rs
+++ b/src/x11/window/mod.rs
@@ -1,6 +1,7 @@
-use {Event, WindowBuilder};
+use {Event, WindowBuilder, KeyModifiers};
use libc;
use std::{mem, ptr};
+use std::cell::Cell;
use std::sync::atomic::AtomicBool;
use super::ffi;
use sync::one::{Once, ONCE_INIT};
@@ -31,6 +32,7 @@ pub struct Window {
xf86_desk_mode: *mut ffi::XF86VidModeModeInfo,
screen_id: libc::c_int,
is_fullscreen: bool,
+ current_modifiers: Cell<KeyModifiers>,
}
impl Window {
@@ -256,6 +258,7 @@ impl Window {
xf86_desk_mode: xf86_desk_mode,
screen_id: screen_id,
is_fullscreen: builder.monitor.is_some(),
+ current_modifiers: Cell::new(KeyModifiers::empty()),
};
// calling glViewport
@@ -377,7 +380,10 @@ impl Window {
},
ffi::KeyPress | ffi::KeyRelease => {
- use {KeyboardInput, Pressed, Released, ReceivedCharacter, KeyModifiers};
+ use {KeyboardInput, Pressed, Released, ReceivedCharacter};
+ use {LEFT_CONTROL_MODIFIER, RIGHT_CONTROL_MODIFIER};
+ use {LEFT_SHIFT_MODIFIER, RIGHT_SHIFT_MODIFIER};
+ use {LEFT_ALT_MODIFIER, RIGHT_ALT_MODIFIER, CAPS_LOCK_MODIFIER};
let event: &mut ffi::XKeyEvent = unsafe { mem::transmute(&xev) };
if event.type_ == ffi::KeyPress {
@@ -408,10 +414,32 @@ impl Window {
ffi::XKeycodeToKeysym(self.display, event.keycode as ffi::KeyCode, 0)
};
+ let modifier_flag = match keysym as u32 {
+ ffi::XK_Shift_L => Some(LEFT_SHIFT_MODIFIER),
+ ffi::XK_Shift_R => Some(RIGHT_SHIFT_MODIFIER),
+ ffi::XK_Control_L => Some(LEFT_CONTROL_MODIFIER),
+ ffi::XK_Control_R => Some(RIGHT_CONTROL_MODIFIER),
+ ffi::XK_Caps_Lock => Some(CAPS_LOCK_MODIFIER),
+ ffi::XK_Meta_L => Some(LEFT_ALT_MODIFIER),
+ ffi::XK_Meta_R => Some(RIGHT_ALT_MODIFIER),
+ _ => None,
+ };
+ match modifier_flag {
+ Some(flag) => {
+ let mut current_modifiers = self.current_modifiers.get();
+ match state {
+ Pressed => current_modifiers.insert(flag),
+ Released => current_modifiers.remove(flag),
+ }
+ self.current_modifiers.set(current_modifiers);
+ }
+ None => {}
+ }
+
let vkey = events::keycode_to_element(keysym as libc::c_uint);
events.push(KeyboardInput(state, event.keycode as u8,
- vkey, KeyModifiers::empty()));
+ vkey, self.current_modifiers.get()));
//
},