11use std:: path:: PathBuf ;
2- use WindowId ;
2+ use { WindowId , DeviceId , AxisId , ButtonId } ;
33
44#[ derive( Clone , Debug ) ]
55pub enum Event {
66 WindowEvent {
77 window_id : WindowId ,
88 event : WindowEvent ,
9- }
9+ } ,
10+ DeviceEvent {
11+ device_id : DeviceId ,
12+ event : DeviceEvent ,
13+ } ,
1014}
1115
1216#[ derive( Clone , Debug ) ]
@@ -35,31 +39,36 @@ pub enum WindowEvent {
3539 Focused ( bool ) ,
3640
3741 /// An event from the keyboard has been received.
38- KeyboardInput ( ElementState , ScanCode , Option < VirtualKeyCode > , ModifiersState ) ,
42+ KeyboardInput { device_id : DeviceId , input : KeyboardInput } ,
3943
4044 /// The cursor has moved on the window.
4145 ///
42- /// The parameter are the (x,y) coords in pixels relative to the top-left corner of the window.
43- MouseMoved ( i32 , i32 ) ,
46+ /// `position` is (x,y) coords in pixels relative to the top-left corner of the window. Because the range of this
47+ /// data is limited by the display area and it may have been transformed by the OS to implement effects such as
48+ /// mouse acceleration, it should not be used to implement non-cursor-like interactions such as 3D camera control.
49+ MouseMoved { device_id : DeviceId , position : ( f64 , f64 ) } ,
4450
4551 /// The cursor has entered the window.
46- MouseEntered ,
52+ MouseEntered { device_id : DeviceId } ,
4753
4854 /// The cursor has left the window.
49- MouseLeft ,
55+ MouseLeft { device_id : DeviceId } ,
5056
5157 /// A mouse wheel movement or touchpad scroll occurred.
52- MouseWheel ( MouseScrollDelta , TouchPhase ) ,
58+ MouseWheel { device_id : DeviceId , delta : MouseScrollDelta , phase : TouchPhase } ,
5359
54- /// An event from the mouse has been received.
55- MouseInput ( ElementState , MouseButton ) ,
60+ /// An mouse button press has been received.
61+ MouseInput { device_id : DeviceId , state : ElementState , button : MouseButton } ,
5662
5763 /// Touchpad pressure event.
5864 ///
5965 /// At the moment, only supported on Apple forcetouch-capable macbooks.
6066 /// The parameters are: pressure level (value between 0 and 1 representing how hard the touchpad
6167 /// is being pressed) and stage (integer representing the click level).
62- TouchpadPressure ( f32 , i64 ) ,
68+ TouchpadPressure { device_id : DeviceId , pressure : f32 , stage : i64 } ,
69+
70+ /// Motion on some analog axis not otherwise handled. May overlap with mouse motion.
71+ AxisMotion { device_id : DeviceId , axis : AxisId , value : f64 } ,
6372
6473 /// The window needs to be redrawn.
6574 Refresh ,
@@ -73,6 +82,48 @@ pub enum WindowEvent {
7382 Touch ( Touch )
7483}
7584
85+ /// Represents raw hardware events that are not associated with any particular window.
86+ ///
87+ /// Useful for interactions that diverge significantly from a conventional 2D GUI, such as 3D camera or first-person
88+ /// game controls. Many physical actions, such as mouse movement, can produce both device and window events. Because
89+ /// window events typically arise from virtual devices (corresponding to GUI cursors and keyboard focus) the device IDs
90+ /// may not match.
91+ ///
92+ /// Note that these events are delivered regardless of input focus.
93+ #[ derive( Clone , Debug ) ]
94+ pub enum DeviceEvent {
95+ Added ,
96+ Removed ,
97+ Motion { axis : AxisId , value : f64 } ,
98+ Button { button : ButtonId , state : ElementState } ,
99+ Key ( KeyboardInput ) ,
100+ Text { codepoint : char } ,
101+ }
102+
103+ #[ derive( Debug , Clone , Copy ) ]
104+ pub struct KeyboardInput {
105+ /// Identifies the physical key pressed
106+ ///
107+ /// This should not change if the user adjusts the host's keyboard map. Use when the physical location of the
108+ /// key is more important than the key's host GUI semantics, such as for movement controls in a first-person
109+ /// game.
110+ pub scancode : ScanCode ,
111+
112+ pub state : ElementState ,
113+
114+ /// Identifies the semantic meaning of the key
115+ ///
116+ /// Use when the semantics of the key are more important than the physical location of the key, such as when
117+ /// implementing appropriate behavior for "page up."
118+ pub virtual_keycode : Option < VirtualKeyCode > ,
119+
120+ /// Modifier keys active at the time of this input.
121+ ///
122+ /// This is tracked internally to avoid tracking errors arising from modifier key state changes when events from
123+ /// this device are not being delivered to the application, e.g. due to keyboard focus being elsewhere.
124+ pub modifiers : ModifiersState
125+ }
126+
76127#[ derive( Debug , Hash , PartialEq , Eq , Clone , Copy ) ]
77128pub enum TouchPhase {
78129 Started ,
@@ -98,13 +149,14 @@ pub enum TouchPhase {
98149///
99150/// Touch may be cancelled if for example window lost focus.
100151pub struct Touch {
152+ pub device_id : DeviceId ,
101153 pub phase : TouchPhase ,
102154 pub location : ( f64 , f64 ) ,
103155 /// unique identifier of a finger.
104156 pub id : u64
105157}
106158
107- pub type ScanCode = u8 ;
159+ pub type ScanCode = u32 ;
108160
109161#[ derive( Debug , Hash , PartialEq , Eq , Clone , Copy ) ]
110162pub enum ElementState {
0 commit comments