aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/events.rs16
-rw-r--r--src/osx/event.rs18
-rw-r--r--src/osx/mod.rs12
-rw-r--r--src/win32/init.rs8
-rw-r--r--src/x11/window/mod.rs33
5 files changed, 12 insertions, 75 deletions
diff --git a/src/events.rs b/src/events.rs
index 59f44b4..fde55f5 100644
--- a/src/events.rs
+++ b/src/events.rs
@@ -18,7 +18,7 @@ pub enum Event {
Focused(bool),
/// An event from the keyboard has been received.
- KeyboardInput(ElementState, ScanCode, Option<VirtualKeyCode>, KeyModifiers),
+ KeyboardInput(ElementState, ScanCode, Option<VirtualKeyCode>),
/// The cursor has moved on the window.
///
@@ -35,20 +35,6 @@ pub enum Event {
pub type ScanCode = u8;
-bitflags!(
- #[deriving(Show)]
- flags KeyModifiers: u8 {
- const LEFT_CONTROL_MODIFIER = 1,
- const RIGHT_CONTROL_MODIFIER = 2,
- const LEFT_SHIFT_MODIFIER = 4,
- const RIGHT_SHIFT_MODIFIER = 8,
- const LEFT_ALT_MODIFIER = 16,
- const RIGHT_ALT_MODIFIER = 32,
- const NUM_LOCK_MODIFIER = 64,
- const CAPS_LOCK_MODIFIER = 128
- }
-)
-
#[deriving(Show, Hash, PartialEq, Eq, Clone)]
pub enum ElementState {
Pressed,
diff --git a/src/osx/event.rs b/src/osx/event.rs
index a4128a4..b5853bc 100644
--- a/src/osx/event.rs
+++ b/src/osx/event.rs
@@ -1,25 +1,7 @@
use events;
-use events::KeyModifiers;
use cocoa::base::NSUInteger;
use cocoa::appkit;
-pub fn modifierflag_to_element(flag: NSUInteger) -> KeyModifiers {
- let mut modifiers = KeyModifiers::empty();
- if flag & appkit::NSShiftKeyMask as u64 == appkit::NSShiftKeyMask as u64 {
- modifiers = modifiers | events::LEFT_SHIFT_MODIFIER;
- }
- if flag & appkit::NSControlKeyMask as u64 == appkit::NSControlKeyMask as u64 {
- modifiers = modifiers | events::LEFT_CONTROL_MODIFIER;
- }
- if flag & appkit::NSAlternateKeyMask as u64 == appkit::NSAlternateKeyMask as u64 {
- modifiers = modifiers | events::LEFT_ALT_MODIFIER;
- }
- if flag & appkit::NSNumericPadKeyMask as u64 == appkit::NSNumericPadKeyMask as u64 {
- modifiers = modifiers | events::NUM_LOCK_MODIFIER;
- }
- modifiers
-}
-
pub fn vkeycode_to_element(code: u16) -> Option<events::VirtualKeyCode> {
Some(match code {
0x00 => events::A,
diff --git a/src/osx/mod.rs b/src/osx/mod.rs
index de7e902..ea79f04 100644
--- a/src/osx/mod.rs
+++ b/src/osx/mod.rs
@@ -18,7 +18,7 @@ use core_foundation::bundle::{CFBundleGetBundleWithIdentifier, CFBundleGetFuncti
use std::c_str::CString;
use {MouseInput, Pressed, Released, LeftMouseButton, RightMouseButton, MouseMoved, ReceivedCharacter,
- KeyboardInput, KeyModifiers};
+ KeyboardInput};
use events;
@@ -252,13 +252,11 @@ impl Window {
}
let vkey = event::vkeycode_to_element(event.keycode());
- let modifiers = event::modifierflag_to_element(event.modifierFlags());
- events.push(KeyboardInput(Pressed, event.keycode() as u8, vkey, modifiers));
+ events.push(KeyboardInput(Pressed, event.keycode() as u8, vkey));
},
NSKeyUp => {
let vkey = event::vkeycode_to_element(event.keycode());
- let modifiers = event::modifierflag_to_element(event.modifierFlags());
- events.push(KeyboardInput(Released, event.keycode() as u8, vkey, modifiers));
+ events.push(KeyboardInput(Released, event.keycode() as u8, vkey));
},
NSFlagsChanged => {
let shift_modifier = Window::modifier_event(event, appkit::NSShiftKeyMask as u64, events::LShift, shift_pressed);
@@ -295,10 +293,10 @@ impl Window {
unsafe fn modifier_event(event: id, keymask: u64, key: events::VirtualKeyCode, key_pressed: bool) -> Option<Event> {
if !key_pressed && Window::modifier_key_pressed(event, keymask) {
- return Some(KeyboardInput(Pressed, event.keycode() as u8, Some(key), KeyModifiers::empty()));
+ return Some(KeyboardInput(Pressed, event.keycode() as u8, Some(key)));
}
else if key_pressed && !Window::modifier_key_pressed(event, keymask) {
- return Some(KeyboardInput(Released, event.keycode() as u8, Some(key), KeyModifiers::empty()));
+ return Some(KeyboardInput(Released, event.keycode() as u8, Some(key)));
}
return None;
diff --git a/src/win32/init.rs b/src/win32/init.rs
index beef44b..a380c84 100644
--- a/src/win32/init.rs
+++ b/src/win32/init.rs
@@ -485,18 +485,18 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT,
},
ffi::WM_KEYDOWN => {
- use events::{KeyboardInput, KeyModifiers, Pressed};
+ use events::{KeyboardInput, Pressed};
let scancode = ((lparam >> 16) & 0xff) as u8;
let vkey = event::vkeycode_to_element(wparam);
- send_event(window, KeyboardInput(Pressed, scancode, vkey, KeyModifiers::empty()));
+ send_event(window, KeyboardInput(Pressed, scancode, vkey));
0
},
ffi::WM_KEYUP => {
- use events::{KeyboardInput, KeyModifiers, Released};
+ use events::{KeyboardInput, Released};
let scancode = ((lparam >> 16) & 0xff) as u8;
let vkey = event::vkeycode_to_element(wparam);
- send_event(window, KeyboardInput(Released, scancode, vkey, KeyModifiers::empty()));
+ send_event(window, KeyboardInput(Released, scancode, vkey));
0
},
diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs
index f7f62b0..34d0d3b 100644
--- a/src/x11/window/mod.rs
+++ b/src/x11/window/mod.rs
@@ -1,4 +1,4 @@
-use {Event, WindowBuilder, KeyModifiers};
+use {Event, WindowBuilder};
use {CreationError, OsError};
use libc;
use std::{mem, ptr};
@@ -33,7 +33,6 @@ pub struct Window {
xf86_desk_mode: *mut ffi::XF86VidModeModeInfo,
screen_id: libc::c_int,
is_fullscreen: bool,
- current_modifiers: Cell<KeyModifiers>,
current_size: Cell<(libc::c_int, libc::c_int)>,
}
@@ -265,7 +264,6 @@ impl Window {
xf86_desk_mode: xf86_desk_mode,
screen_id: screen_id,
is_fullscreen: builder.monitor.is_some(),
- current_modifiers: Cell::new(KeyModifiers::empty()),
current_size: Cell::new((0, 0)),
};
@@ -399,9 +397,6 @@ impl Window {
ffi::KeyPress | ffi::KeyRelease => {
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 {
@@ -432,33 +427,9 @@ 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, self.current_modifiers.get()));
- //
+ events.push(KeyboardInput(state, event.keycode as u8, vkey));
},
ffi::ButtonPress | ffi::ButtonRelease => {