@@ -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) {
@@ -687,14 +696,16 @@ impl<T: Event> WinitAppRunnerState<T> {
687
696
}
688
697
689
698
fn forward_bevy_events ( & mut self ) {
699
+ let raw_winit_events = self . raw_winit_events . drain ( ..) . collect :: < Vec < _ > > ( ) ;
690
700
let buffered_events = self . bevy_window_events . drain ( ..) . collect :: < Vec < _ > > ( ) ;
701
+ let world = self . world_mut ( ) ;
691
702
692
- if buffered_events. is_empty ( ) {
693
- return ;
703
+ if !raw_winit_events. is_empty ( ) {
704
+ world
705
+ . resource_mut :: < Events < RawWinitWindowEvent > > ( )
706
+ . send_batch ( raw_winit_events) ;
694
707
}
695
708
696
- let world = self . world_mut ( ) ;
697
-
698
709
for winit_event in buffered_events. iter ( ) {
699
710
match winit_event. clone ( ) {
700
711
BevyWindowEvent :: AppLifecycle ( e) => {
@@ -781,9 +792,11 @@ impl<T: Event> WinitAppRunnerState<T> {
781
792
}
782
793
}
783
794
784
- world
785
- . resource_mut :: < Events < BevyWindowEvent > > ( )
786
- . send_batch ( buffered_events) ;
795
+ if !buffered_events. is_empty ( ) {
796
+ world
797
+ . resource_mut :: < Events < BevyWindowEvent > > ( )
798
+ . send_batch ( buffered_events) ;
799
+ }
787
800
}
788
801
789
802
#[ cfg( feature = "custom_cursor" ) ]
0 commit comments