@@ -78,7 +78,7 @@ pub(crate) enum Event {
78
78
///
79
79
/// [`ApplicationHandler::device_event`]: crate::application::ApplicationHandler::device_event
80
80
#[ allow( clippy:: enum_variant_names) ]
81
- DeviceEvent { device_id : DeviceId , event : DeviceEvent } ,
81
+ DeviceEvent { device_id : Option < DeviceId > , event : DeviceEvent } ,
82
82
83
83
/// See [`ApplicationHandler::suspended`] for details.
84
84
///
@@ -199,7 +199,7 @@ pub enum WindowEvent {
199
199
/// numpad keys act as if NumLock wasn't active. When this is used, the OS sends fake key
200
200
/// events which are not marked as `is_synthetic`.
201
201
KeyboardInput {
202
- device_id : DeviceId ,
202
+ device_id : Option < DeviceId > ,
203
203
event : KeyEvent ,
204
204
205
205
/// If `true`, the event was generated synthetically by winit
@@ -236,7 +236,7 @@ pub enum WindowEvent {
236
236
/// [`padding`]: https://developer.mozilla.org/en-US/docs/Web/CSS/padding
237
237
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
238
238
CursorMoved {
239
- device_id : DeviceId ,
239
+ device_id : Option < DeviceId > ,
240
240
241
241
/// (x,y) coords in pixels relative to the top-left corner of the window. Because the range
242
242
/// of this data is limited by the display area and it may have been transformed by
@@ -255,7 +255,7 @@ pub enum WindowEvent {
255
255
/// [`border`]: https://developer.mozilla.org/en-US/docs/Web/CSS/border
256
256
/// [`padding`]: https://developer.mozilla.org/en-US/docs/Web/CSS/padding
257
257
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
258
- CursorEntered { device_id : DeviceId } ,
258
+ CursorEntered { device_id : Option < DeviceId > } ,
259
259
260
260
/// The cursor has left the window.
261
261
///
@@ -266,13 +266,13 @@ pub enum WindowEvent {
266
266
/// [`border`]: https://developer.mozilla.org/en-US/docs/Web/CSS/border
267
267
/// [`padding`]: https://developer.mozilla.org/en-US/docs/Web/CSS/padding
268
268
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
269
- CursorLeft { device_id : DeviceId } ,
269
+ CursorLeft { device_id : Option < DeviceId > } ,
270
270
271
271
/// A mouse wheel movement or touchpad scroll occurred.
272
- MouseWheel { device_id : DeviceId , delta : MouseScrollDelta , phase : TouchPhase } ,
272
+ MouseWheel { device_id : Option < DeviceId > , delta : MouseScrollDelta , phase : TouchPhase } ,
273
273
274
274
/// An mouse button press has been received.
275
- MouseInput { device_id : DeviceId , state : ElementState , button : MouseButton } ,
275
+ MouseInput { device_id : Option < DeviceId > , state : ElementState , button : MouseButton } ,
276
276
277
277
/// Two-finger pinch gesture, often used for magnification.
278
278
///
@@ -281,7 +281,7 @@ pub enum WindowEvent {
281
281
/// - Only available on **macOS** and **iOS**.
282
282
/// - On iOS, not recognized by default. It must be enabled when needed.
283
283
PinchGesture {
284
- device_id : DeviceId ,
284
+ device_id : Option < DeviceId > ,
285
285
/// Positive values indicate magnification (zooming in) and negative
286
286
/// values indicate shrinking (zooming out).
287
287
///
@@ -297,7 +297,7 @@ pub enum WindowEvent {
297
297
/// - Only available on **iOS**.
298
298
/// - On iOS, not recognized by default. It must be enabled when needed.
299
299
PanGesture {
300
- device_id : DeviceId ,
300
+ device_id : Option < DeviceId > ,
301
301
/// Change in pixels of pan gesture from last update.
302
302
delta : PhysicalPosition < f32 > ,
303
303
phase : TouchPhase ,
@@ -321,7 +321,7 @@ pub enum WindowEvent {
321
321
///
322
322
/// - Only available on **macOS 10.8** and later, and **iOS**.
323
323
/// - On iOS, not recognized by default. It must be enabled when needed.
324
- DoubleTapGesture { device_id : DeviceId } ,
324
+ DoubleTapGesture { device_id : Option < DeviceId > } ,
325
325
326
326
/// Two-finger rotation gesture.
327
327
///
@@ -333,7 +333,7 @@ pub enum WindowEvent {
333
333
/// - Only available on **macOS** and **iOS**.
334
334
/// - On iOS, not recognized by default. It must be enabled when needed.
335
335
RotationGesture {
336
- device_id : DeviceId ,
336
+ device_id : Option < DeviceId > ,
337
337
/// change in rotation in degrees
338
338
delta : f32 ,
339
339
phase : TouchPhase ,
@@ -344,7 +344,7 @@ pub enum WindowEvent {
344
344
/// At the moment, only supported on Apple forcetouch-capable macbooks.
345
345
/// The parameters are: pressure level (value between 0 and 1 representing how hard the
346
346
/// touchpad is being pressed) and stage (integer representing the click level).
347
- TouchpadPressure { device_id : DeviceId , pressure : f32 , stage : i64 } ,
347
+ TouchpadPressure { device_id : Option < DeviceId > , pressure : f32 , stage : i64 } ,
348
348
349
349
/// Touch event has been received
350
350
///
@@ -440,25 +440,6 @@ pub enum WindowEvent {
440
440
#[ derive( Debug , Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
441
441
pub struct DeviceId ( pub ( crate ) platform_impl:: DeviceId ) ;
442
442
443
- impl Default for DeviceId {
444
- fn default ( ) -> Self {
445
- Self :: dummy ( )
446
- }
447
- }
448
-
449
- impl DeviceId {
450
- /// Returns a dummy id, useful for unit testing.
451
- ///
452
- /// # Notes
453
- ///
454
- /// The only guarantee made about the return value of this function is that
455
- /// it will always be equal to itself and to future values returned by this function.
456
- /// No other guarantees are made. This may be equal to a real `DeviceId`.
457
- pub const fn dummy ( ) -> Self {
458
- DeviceId ( platform_impl:: DeviceId :: dummy ( ) )
459
- }
460
- }
461
-
462
443
/// Identifier of a finger in a touch event.
463
444
///
464
445
/// Whenever a touch event is received it contains a `FingerId` which uniquely identifies the finger
@@ -467,14 +448,8 @@ impl DeviceId {
467
448
pub struct FingerId ( pub ( crate ) platform_impl:: FingerId ) ;
468
449
469
450
impl FingerId {
470
- /// Returns a dummy id, useful for unit testing.
471
- ///
472
- /// # Notes
473
- ///
474
- /// The only guarantee made about the return value of this function is that
475
- /// it will always be equal to itself and to future values returned by this function.
476
- /// No other guarantees are made. This may be equal to a real `FingerId`.
477
- pub const fn dummy ( ) -> Self {
451
+ #[ cfg( test) ]
452
+ pub ( crate ) const fn dummy ( ) -> Self {
478
453
FingerId ( platform_impl:: FingerId :: dummy ( ) )
479
454
}
480
455
}
@@ -865,7 +840,7 @@ pub enum TouchPhase {
865
840
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
866
841
#[ derive( Debug , Clone , Copy , PartialEq ) ]
867
842
pub struct Touch {
868
- pub device_id : DeviceId ,
843
+ pub device_id : Option < DeviceId > ,
869
844
pub phase : TouchPhase ,
870
845
pub location : PhysicalPosition < f64 > ,
871
846
/// Describes how hard the screen was pressed. May be `None` if the platform
@@ -1046,7 +1021,6 @@ mod tests {
1046
1021
( $closure: expr) => { {
1047
1022
#[ allow( unused_mut) ]
1048
1023
let mut x = $closure;
1049
- let did = event:: DeviceId :: dummy( ) ;
1050
1024
let fid = event:: FingerId :: dummy( ) ;
1051
1025
1052
1026
#[ allow( deprecated) ]
@@ -1057,7 +1031,7 @@ mod tests {
1057
1031
use crate :: window:: WindowId ;
1058
1032
1059
1033
// Mainline events.
1060
- let wid = WindowId :: dummy ( ) ;
1034
+ let wid = WindowId :: from_raw ( 0 ) ;
1061
1035
x( NewEvents ( event:: StartCause :: Init ) ) ;
1062
1036
x( AboutToWait ) ;
1063
1037
x( LoopExiting ) ;
@@ -1076,39 +1050,39 @@ mod tests {
1076
1050
with_window_event( HoveredFile ( "x.txt" . into( ) ) ) ;
1077
1051
with_window_event( HoveredFileCancelled ) ;
1078
1052
with_window_event( Ime ( Enabled ) ) ;
1079
- with_window_event( CursorMoved { device_id: did , position: ( 0 , 0 ) . into( ) } ) ;
1053
+ with_window_event( CursorMoved { device_id: None , position: ( 0 , 0 ) . into( ) } ) ;
1080
1054
with_window_event( ModifiersChanged ( event:: Modifiers :: default ( ) ) ) ;
1081
- with_window_event( CursorEntered { device_id: did } ) ;
1082
- with_window_event( CursorLeft { device_id: did } ) ;
1055
+ with_window_event( CursorEntered { device_id: None } ) ;
1056
+ with_window_event( CursorLeft { device_id: None } ) ;
1083
1057
with_window_event( MouseWheel {
1084
- device_id: did ,
1058
+ device_id: None ,
1085
1059
delta: event:: MouseScrollDelta :: LineDelta ( 0.0 , 0.0 ) ,
1086
1060
phase: event:: TouchPhase :: Started ,
1087
1061
} ) ;
1088
1062
with_window_event( MouseInput {
1089
- device_id: did ,
1063
+ device_id: None ,
1090
1064
state: event:: ElementState :: Pressed ,
1091
1065
button: event:: MouseButton :: Other ( 0 ) ,
1092
1066
} ) ;
1093
1067
with_window_event( PinchGesture {
1094
- device_id: did ,
1068
+ device_id: None ,
1095
1069
delta: 0.0 ,
1096
1070
phase: event:: TouchPhase :: Started ,
1097
1071
} ) ;
1098
- with_window_event( DoubleTapGesture { device_id: did } ) ;
1072
+ with_window_event( DoubleTapGesture { device_id: None } ) ;
1099
1073
with_window_event( RotationGesture {
1100
- device_id: did ,
1074
+ device_id: None ,
1101
1075
delta: 0.0 ,
1102
1076
phase: event:: TouchPhase :: Started ,
1103
1077
} ) ;
1104
1078
with_window_event( PanGesture {
1105
- device_id: did ,
1079
+ device_id: None ,
1106
1080
delta: PhysicalPosition :: <f32 >:: new( 0.0 , 0.0 ) ,
1107
1081
phase: event:: TouchPhase :: Started ,
1108
1082
} ) ;
1109
- with_window_event( TouchpadPressure { device_id: did , pressure: 0.0 , stage: 0 } ) ;
1083
+ with_window_event( TouchpadPressure { device_id: None , pressure: 0.0 , stage: 0 } ) ;
1110
1084
with_window_event( Touch ( event:: Touch {
1111
- device_id: did ,
1085
+ device_id: None ,
1112
1086
phase: event:: TouchPhase :: Started ,
1113
1087
location: ( 0.0 , 0.0 ) . into( ) ,
1114
1088
finger_id: fid,
@@ -1123,7 +1097,7 @@ mod tests {
1123
1097
use event:: DeviceEvent :: * ;
1124
1098
1125
1099
let with_device_event =
1126
- |dev_ev| x( event:: Event :: DeviceEvent { device_id: did , event: dev_ev } ) ;
1100
+ |dev_ev| x( event:: Event :: DeviceEvent { device_id: None , event: dev_ev } ) ;
1127
1101
1128
1102
with_device_event( MouseMotion { delta: ( 0.0 , 0.0 ) . into( ) } ) ;
1129
1103
with_device_event( MouseWheel {
@@ -1168,21 +1142,20 @@ mod tests {
1168
1142
} ) ;
1169
1143
let _ = event:: StartCause :: Init . clone ( ) ;
1170
1144
1171
- let did = crate :: event:: DeviceId :: dummy ( ) . clone ( ) ;
1172
1145
let fid = crate :: event:: FingerId :: dummy ( ) . clone ( ) ;
1173
- HashSet :: new ( ) . insert ( did ) ;
1174
- let mut set = [ did , did , did ] ;
1146
+ HashSet :: new ( ) . insert ( fid ) ;
1147
+ let mut set = [ fid , fid , fid ] ;
1175
1148
set. sort_unstable ( ) ;
1176
1149
let mut set2 = BTreeSet :: new ( ) ;
1177
- set2. insert ( did ) ;
1178
- set2. insert ( did ) ;
1150
+ set2. insert ( fid ) ;
1151
+ set2. insert ( fid ) ;
1179
1152
1180
1153
HashSet :: new ( ) . insert ( event:: TouchPhase :: Started . clone ( ) ) ;
1181
1154
HashSet :: new ( ) . insert ( event:: MouseButton :: Left . clone ( ) ) ;
1182
1155
HashSet :: new ( ) . insert ( event:: Ime :: Enabled ) ;
1183
1156
1184
1157
let _ = event:: Touch {
1185
- device_id : did ,
1158
+ device_id : None ,
1186
1159
phase : event:: TouchPhase :: Started ,
1187
1160
location : ( 0.0 , 0.0 ) . into ( ) ,
1188
1161
finger_id : fid,
0 commit comments