1
0
Fork 0

Use keyboard_types::KeyboardEvent directly instead of wrapping it

This commit is contained in:
Joakim Frostegård 2020-11-13 23:17:46 +01:00
parent 546b0d6eae
commit 0a6a0bdffd
4 changed files with 10 additions and 26 deletions

View file

@ -1,10 +1,6 @@
use crate::{WindowInfo, Point}; use keyboard_types::KeyboardEvent;
#[derive(Debug, Clone, PartialEq)] use crate::{WindowInfo, Point};
pub enum KeyboardEvent {
KeyPressed(keyboard_types::KeyboardEvent),
KeyReleased(keyboard_types::KeyboardEvent),
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)] #[derive(Debug, Copy, Clone, Eq, PartialEq)]

View file

@ -15,7 +15,7 @@ use objc::{
use uuid::Uuid; use uuid::Uuid;
use crate::{ use crate::{
Event, KeyboardEvent, MouseButton, MouseEvent, Point, WindowHandler, Event, MouseButton, MouseEvent, Point, WindowHandler,
WindowOpenOptions WindowOpenOptions
}; };
use crate::MouseEvent::{ButtonPressed, ButtonReleased}; use crate::MouseEvent::{ButtonPressed, ButtonReleased};
@ -351,9 +351,7 @@ extern "C" fn key_down<H: WindowHandler>(this: &Object, _: Sel, event: id){
}; };
if let Some(key_event) = state.process_native_key_event(event){ if let Some(key_event) = state.process_native_key_event(event){
let event = Event::Keyboard(KeyboardEvent::KeyPressed(key_event)); state.trigger_event(Event::Keyboard(key_event));
state.trigger_event(event);
} }
} }
@ -364,8 +362,6 @@ extern "C" fn key_up<H: WindowHandler>(this: &Object, _: Sel, event: id){
}; };
if let Some(key_event) = state.process_native_key_event(event){ if let Some(key_event) = state.process_native_key_event(event){
let event = Event::Keyboard(KeyboardEvent::KeyReleased(key_event)); state.trigger_event(Event::Keyboard(key_event));
state.trigger_event(event);
} }
} }

View file

@ -23,7 +23,7 @@ use raw_window_handle::{
}; };
use crate::{ use crate::{
Event, KeyboardEvent, MouseButton, MouseEvent, Parent::WithParent, ScrollDelta, WindowEvent, Event, MouseButton, MouseEvent, Parent::WithParent, ScrollDelta, WindowEvent,
WindowHandler, WindowInfo, WindowOpenOptions, WindowScalePolicy, Size, Point, PhySize, PhyPoint, WindowHandler, WindowInfo, WindowOpenOptions, WindowScalePolicy, Size, Point, PhySize, PhyPoint,
}; };

View file

@ -11,8 +11,8 @@ use raw_window_handle::{
use super::XcbConnection; use super::XcbConnection;
use crate::{ use crate::{
Event, KeyboardEvent, MouseButton, MouseCursor, MouseEvent, Parent, Event, MouseButton, MouseCursor, MouseEvent, Parent, ScrollDelta,
ScrollDelta, WindowEvent, WindowHandler, WindowInfo, WindowOpenOptions, WindowEvent, WindowHandler, WindowInfo, WindowOpenOptions,
WindowScalePolicy, PhyPoint, PhySize, WindowScalePolicy, PhyPoint, PhySize,
}; };
@ -396,26 +396,18 @@ impl Window {
xcb::KEY_PRESS => { xcb::KEY_PRESS => {
let event = unsafe { xcb::cast_event::<xcb::KeyPressEvent>(&event) }; let event = unsafe { xcb::cast_event::<xcb::KeyPressEvent>(&event) };
let event = Event::Keyboard(KeyboardEvent::KeyPressed(
convert_key_press_event(&event)
));
handler.on_event( handler.on_event(
self, self,
event Event::Keyboard(convert_key_press_event(&event))
); );
} }
xcb::KEY_RELEASE => { xcb::KEY_RELEASE => {
let event = unsafe { xcb::cast_event::<xcb::KeyReleaseEvent>(&event) }; let event = unsafe { xcb::cast_event::<xcb::KeyReleaseEvent>(&event) };
let event = Event::Keyboard(KeyboardEvent::KeyReleased(
convert_key_release_event(&event)
));
handler.on_event( handler.on_event(
self, self,
event Event::Keyboard(convert_key_release_event(&event))
); );
} }