34
34
//!
35
35
//! [`EventLoop::run(...)`]: crate::event_loop::EventLoop::run
36
36
//! [`ControlFlow::WaitUntil`]: crate::event_loop::ControlFlow::WaitUntil
37
- use smol_str:: SmolStr ;
38
37
use std:: path:: PathBuf ;
38
+ use std:: sync:: { Mutex , Weak } ;
39
39
#[ cfg( not( wasm_platform) ) ]
40
40
use std:: time:: Instant ;
41
+
42
+ use smol_str:: SmolStr ;
41
43
#[ cfg( wasm_platform) ]
42
44
use web_time:: Instant ;
43
45
@@ -54,8 +56,8 @@ use crate::{
54
56
/// Describes a generic event.
55
57
///
56
58
/// See the module-level docs for more information on the event loop manages each event.
57
- #[ derive( Debug , PartialEq ) ]
58
- pub enum Event < ' a , T : ' static > {
59
+ #[ derive( Debug ) ]
60
+ pub enum Event < T : ' static > {
59
61
/// Emitted when new events arrive from the OS to be processed.
60
62
///
61
63
/// This event type is useful as a place to put code that should be done before you start
@@ -67,7 +69,7 @@ pub enum Event<'a, T: 'static> {
67
69
/// Emitted when the OS sends an event to a winit window.
68
70
WindowEvent {
69
71
window_id : WindowId ,
70
- event : WindowEvent < ' a > ,
72
+ event : WindowEvent ,
71
73
} ,
72
74
73
75
/// Emitted when the OS sends an event to a device.
@@ -261,33 +263,9 @@ pub enum Event<'a, T: 'static> {
261
263
LoopDestroyed ,
262
264
}
263
265
264
- impl < T : Clone > Clone for Event < ' static , T > {
265
- fn clone ( & self ) -> Self {
266
- use self :: Event :: * ;
267
- match self {
268
- WindowEvent { window_id, event } => WindowEvent {
269
- window_id : * window_id,
270
- event : event. clone ( ) ,
271
- } ,
272
- UserEvent ( event) => UserEvent ( event. clone ( ) ) ,
273
- DeviceEvent { device_id, event } => DeviceEvent {
274
- device_id : * device_id,
275
- event : event. clone ( ) ,
276
- } ,
277
- NewEvents ( cause) => NewEvents ( * cause) ,
278
- MainEventsCleared => MainEventsCleared ,
279
- RedrawRequested ( wid) => RedrawRequested ( * wid) ,
280
- RedrawEventsCleared => RedrawEventsCleared ,
281
- LoopDestroyed => LoopDestroyed ,
282
- Suspended => Suspended ,
283
- Resumed => Resumed ,
284
- }
285
- }
286
- }
287
-
288
- impl < ' a , T > Event < ' a , T > {
266
+ impl < T > Event < T > {
289
267
#[ allow( clippy:: result_large_err) ]
290
- pub fn map_nonuser_event < U > ( self ) -> Result < Event < ' a , U > , Event < ' a , T > > {
268
+ pub fn map_nonuser_event < U > ( self ) -> Result < Event < U > , Event < T > > {
291
269
use self :: Event :: * ;
292
270
match self {
293
271
UserEvent ( _) => Err ( self ) ,
@@ -302,26 +280,6 @@ impl<'a, T> Event<'a, T> {
302
280
Resumed => Ok ( Resumed ) ,
303
281
}
304
282
}
305
-
306
- /// If the event doesn't contain a reference, turn it into an event with a `'static` lifetime.
307
- /// Otherwise, return `None`.
308
- pub fn to_static ( self ) -> Option < Event < ' static , T > > {
309
- use self :: Event :: * ;
310
- match self {
311
- WindowEvent { window_id, event } => event
312
- . to_static ( )
313
- . map ( |event| WindowEvent { window_id, event } ) ,
314
- UserEvent ( event) => Some ( UserEvent ( event) ) ,
315
- DeviceEvent { device_id, event } => Some ( DeviceEvent { device_id, event } ) ,
316
- NewEvents ( cause) => Some ( NewEvents ( cause) ) ,
317
- MainEventsCleared => Some ( MainEventsCleared ) ,
318
- RedrawRequested ( wid) => Some ( RedrawRequested ( wid) ) ,
319
- RedrawEventsCleared => Some ( RedrawEventsCleared ) ,
320
- LoopDestroyed => Some ( LoopDestroyed ) ,
321
- Suspended => Some ( Suspended ) ,
322
- Resumed => Some ( Resumed ) ,
323
- }
324
- }
325
283
}
326
284
327
285
/// Describes the reason the event loop is resuming.
@@ -355,8 +313,8 @@ pub enum StartCause {
355
313
}
356
314
357
315
/// Describes an event from a [`Window`].
358
- #[ derive( Debug , PartialEq ) ]
359
- pub enum WindowEvent < ' a > {
316
+ #[ derive( Debug , Clone ) ]
317
+ pub enum WindowEvent {
360
318
/// The activation token was delivered back and now could be used.
361
319
///
362
320
#[ cfg_attr(
@@ -590,7 +548,9 @@ pub enum WindowEvent<'a> {
590
548
/// For more information about DPI in general, see the [`dpi`](crate::dpi) module.
591
549
ScaleFactorChanged {
592
550
scale_factor : f64 ,
593
- new_inner_size : & ' a mut PhysicalSize < u32 > ,
551
+ /// The pointer could be upgraded successfully only from the callback for this event,
552
+ /// otherwise it'll always fail to do so.
553
+ new_inner_size : Weak < Mutex < PhysicalSize < u32 > > > ,
594
554
} ,
595
555
596
556
/// The system window theme has changed.
@@ -619,209 +579,6 @@ pub enum WindowEvent<'a> {
619
579
Occluded ( bool ) ,
620
580
}
621
581
622
- impl Clone for WindowEvent < ' static > {
623
- fn clone ( & self ) -> Self {
624
- use self :: WindowEvent :: * ;
625
- return match self {
626
- ActivationTokenDone { serial, token } => ActivationTokenDone {
627
- serial : * serial,
628
- token : token. clone ( ) ,
629
- } ,
630
- Resized ( size) => Resized ( * size) ,
631
- Moved ( pos) => Moved ( * pos) ,
632
- CloseRequested => CloseRequested ,
633
- Destroyed => Destroyed ,
634
- DroppedFile ( file) => DroppedFile ( file. clone ( ) ) ,
635
- HoveredFile ( file) => HoveredFile ( file. clone ( ) ) ,
636
- HoveredFileCancelled => HoveredFileCancelled ,
637
- Focused ( f) => Focused ( * f) ,
638
- KeyboardInput {
639
- device_id,
640
- event,
641
- is_synthetic,
642
- } => KeyboardInput {
643
- device_id : * device_id,
644
- event : event. clone ( ) ,
645
- is_synthetic : * is_synthetic,
646
- } ,
647
- Ime ( preedit_state) => Ime ( preedit_state. clone ( ) ) ,
648
- ModifiersChanged ( modifiers) => ModifiersChanged ( * modifiers) ,
649
- CursorMoved {
650
- device_id,
651
- position,
652
- } => CursorMoved {
653
- device_id : * device_id,
654
- position : * position,
655
- } ,
656
- CursorEntered { device_id } => CursorEntered {
657
- device_id : * device_id,
658
- } ,
659
- CursorLeft { device_id } => CursorLeft {
660
- device_id : * device_id,
661
- } ,
662
- MouseWheel {
663
- device_id,
664
- delta,
665
- phase,
666
- } => MouseWheel {
667
- device_id : * device_id,
668
- delta : * delta,
669
- phase : * phase,
670
- } ,
671
- MouseInput {
672
- device_id,
673
- state,
674
- button,
675
- } => MouseInput {
676
- device_id : * device_id,
677
- state : * state,
678
- button : * button,
679
- } ,
680
- TouchpadMagnify {
681
- device_id,
682
- delta,
683
- phase,
684
- } => TouchpadMagnify {
685
- device_id : * device_id,
686
- delta : * delta,
687
- phase : * phase,
688
- } ,
689
- SmartMagnify { device_id } => SmartMagnify {
690
- device_id : * device_id,
691
- } ,
692
- TouchpadRotate {
693
- device_id,
694
- delta,
695
- phase,
696
- } => TouchpadRotate {
697
- device_id : * device_id,
698
- delta : * delta,
699
- phase : * phase,
700
- } ,
701
- TouchpadPressure {
702
- device_id,
703
- pressure,
704
- stage,
705
- } => TouchpadPressure {
706
- device_id : * device_id,
707
- pressure : * pressure,
708
- stage : * stage,
709
- } ,
710
- AxisMotion {
711
- device_id,
712
- axis,
713
- value,
714
- } => AxisMotion {
715
- device_id : * device_id,
716
- axis : * axis,
717
- value : * value,
718
- } ,
719
- Touch ( touch) => Touch ( * touch) ,
720
- ThemeChanged ( theme) => ThemeChanged ( * theme) ,
721
- ScaleFactorChanged { .. } => {
722
- unreachable ! ( "Static event can't be about scale factor changing" )
723
- }
724
- Occluded ( occluded) => Occluded ( * occluded) ,
725
- } ;
726
- }
727
- }
728
-
729
- impl < ' a > WindowEvent < ' a > {
730
- pub fn to_static ( self ) -> Option < WindowEvent < ' static > > {
731
- use self :: WindowEvent :: * ;
732
- match self {
733
- ActivationTokenDone { serial, token } => Some ( ActivationTokenDone { serial, token } ) ,
734
- Resized ( size) => Some ( Resized ( size) ) ,
735
- Moved ( position) => Some ( Moved ( position) ) ,
736
- CloseRequested => Some ( CloseRequested ) ,
737
- Destroyed => Some ( Destroyed ) ,
738
- DroppedFile ( file) => Some ( DroppedFile ( file) ) ,
739
- HoveredFile ( file) => Some ( HoveredFile ( file) ) ,
740
- HoveredFileCancelled => Some ( HoveredFileCancelled ) ,
741
- Focused ( focused) => Some ( Focused ( focused) ) ,
742
- KeyboardInput {
743
- device_id,
744
- event,
745
- is_synthetic,
746
- } => Some ( KeyboardInput {
747
- device_id,
748
- event,
749
- is_synthetic,
750
- } ) ,
751
- ModifiersChanged ( modifers) => Some ( ModifiersChanged ( modifers) ) ,
752
- Ime ( event) => Some ( Ime ( event) ) ,
753
- CursorMoved {
754
- device_id,
755
- position,
756
- } => Some ( CursorMoved {
757
- device_id,
758
- position,
759
- } ) ,
760
- CursorEntered { device_id } => Some ( CursorEntered { device_id } ) ,
761
- CursorLeft { device_id } => Some ( CursorLeft { device_id } ) ,
762
- MouseWheel {
763
- device_id,
764
- delta,
765
- phase,
766
- } => Some ( MouseWheel {
767
- device_id,
768
- delta,
769
- phase,
770
- } ) ,
771
- MouseInput {
772
- device_id,
773
- state,
774
- button,
775
- } => Some ( MouseInput {
776
- device_id,
777
- state,
778
- button,
779
- } ) ,
780
- TouchpadMagnify {
781
- device_id,
782
- delta,
783
- phase,
784
- } => Some ( TouchpadMagnify {
785
- device_id,
786
- delta,
787
- phase,
788
- } ) ,
789
- SmartMagnify { device_id } => Some ( SmartMagnify { device_id } ) ,
790
- TouchpadRotate {
791
- device_id,
792
- delta,
793
- phase,
794
- } => Some ( TouchpadRotate {
795
- device_id,
796
- delta,
797
- phase,
798
- } ) ,
799
- TouchpadPressure {
800
- device_id,
801
- pressure,
802
- stage,
803
- } => Some ( TouchpadPressure {
804
- device_id,
805
- pressure,
806
- stage,
807
- } ) ,
808
- AxisMotion {
809
- device_id,
810
- axis,
811
- value,
812
- } => Some ( AxisMotion {
813
- device_id,
814
- axis,
815
- value,
816
- } ) ,
817
- Touch ( touch) => Some ( Touch ( touch) ) ,
818
- ThemeChanged ( theme) => Some ( ThemeChanged ( theme) ) ,
819
- ScaleFactorChanged { .. } => None ,
820
- Occluded ( occluded) => Some ( Occluded ( occluded) ) ,
821
- }
822
- }
823
- }
824
-
825
582
/// Identifier of an input device.
826
583
///
827
584
/// Whenever you receive an event arising from a particular input device, this event contains a `DeviceId` which
0 commit comments