@@ -46,8 +46,8 @@ use crate::{
46
46
accessibility:: AccessKitAdapters ,
47
47
converters, create_windows,
48
48
system:: { create_monitors, CachedWindow } ,
49
- AppSendEvent , CreateMonitorParams , CreateWindowParams , EventLoopProxyWrapper , UpdateMode ,
50
- WinitSettings , WinitWindows ,
49
+ AppSendEvent , CreateMonitorParams , CreateWindowParams , EventLoopProxyWrapper ,
50
+ RawWinitWindowEvent , UpdateMode , WinitSettings , WinitWindows ,
51
51
} ;
52
52
53
53
/// Persistent state that is used to run the [`App`] according to the current
@@ -80,6 +80,8 @@ struct WinitAppRunnerState<T: Event> {
80
80
previous_lifecycle : AppLifecycle ,
81
81
/// Bevy window events to send
82
82
bevy_window_events : Vec < bevy_window:: WindowEvent > ,
83
+ /// Raw Winit window events to send
84
+ raw_winit_events : Vec < RawWinitWindowEvent > ,
83
85
_marker : PhantomData < T > ,
84
86
85
87
event_writer_system_state : SystemState < (
@@ -121,6 +123,7 @@ impl<T: Event> WinitAppRunnerState<T> {
121
123
// 3 seems to be enough, 5 is a safe margin
122
124
startup_forced_updates : 5 ,
123
125
bevy_window_events : Vec :: new ( ) ,
126
+ raw_winit_events : Vec :: new ( ) ,
124
127
_marker : PhantomData ,
125
128
event_writer_system_state,
126
129
}
@@ -250,6 +253,12 @@ impl<T: Event> ApplicationHandler<T> for WinitAppRunnerState<T> {
250
253
return ;
251
254
} ;
252
255
256
+ // Store a copy of the event to send to an EventWriter later.
257
+ self . raw_winit_events . push ( RawWinitWindowEvent {
258
+ window_id,
259
+ event : event. clone ( ) ,
260
+ } ) ;
261
+
253
262
// Allow AccessKit to respond to `WindowEvent`s before they reach
254
263
// the engine.
255
264
if let Some ( adapter) = access_kit_adapters. get_mut ( & window) {
@@ -688,14 +697,16 @@ impl<T: Event> WinitAppRunnerState<T> {
688
697
}
689
698
690
699
fn forward_bevy_events ( & mut self ) {
700
+ let raw_winit_events = self . raw_winit_events . drain ( ..) . collect :: < Vec < _ > > ( ) ;
691
701
let buffered_events = self . bevy_window_events . drain ( ..) . collect :: < Vec < _ > > ( ) ;
702
+ let world = self . world_mut ( ) ;
692
703
693
- if buffered_events. is_empty ( ) {
694
- return ;
704
+ if !raw_winit_events. is_empty ( ) {
705
+ world
706
+ . resource_mut :: < Events < RawWinitWindowEvent > > ( )
707
+ . send_batch ( raw_winit_events) ;
695
708
}
696
709
697
- let world = self . world_mut ( ) ;
698
-
699
710
for winit_event in buffered_events. iter ( ) {
700
711
match winit_event. clone ( ) {
701
712
BevyWindowEvent :: AppLifecycle ( e) => {
@@ -782,9 +793,11 @@ impl<T: Event> WinitAppRunnerState<T> {
782
793
}
783
794
}
784
795
785
- world
786
- . resource_mut :: < Events < BevyWindowEvent > > ( )
787
- . send_batch ( buffered_events) ;
796
+ if !buffered_events. is_empty ( ) {
797
+ world
798
+ . resource_mut :: < Events < BevyWindowEvent > > ( )
799
+ . send_batch ( buffered_events) ;
800
+ }
788
801
}
789
802
790
803
#[ cfg( feature = "custom_cursor" ) ]
0 commit comments