@@ -140,15 +140,14 @@ impl<T> ThreadMsgTargetSubclassInput<T> {
140
140
}
141
141
142
142
pub struct EventLoop < T : ' static > {
143
- // Id of the background thread from the Win32 API.
144
- thread_msg_target : HWND ,
145
143
thread_msg_sender : Sender < T > ,
146
144
window_target : RootELW < T >
147
145
}
148
146
149
147
pub struct EventLoopWindowTarget < T > {
150
148
thread_id : DWORD ,
151
149
trigger_newevents_on_redraw : Arc < AtomicBool > ,
150
+ thread_msg_target : HWND ,
152
151
pub ( crate ) runner_shared : EventLoopRunnerShared < T > ,
153
152
}
154
153
@@ -172,11 +171,12 @@ impl<T: 'static> EventLoop<T> {
172
171
let ( thread_msg_target, thread_msg_sender) = thread_event_target_window ( runner_shared. clone ( ) ) ;
173
172
174
173
EventLoop {
175
- thread_msg_target , thread_msg_sender,
174
+ thread_msg_sender,
176
175
window_target : RootELW {
177
176
p : EventLoopWindowTarget {
178
177
thread_id,
179
178
trigger_newevents_on_redraw : Arc :: new ( AtomicBool :: new ( true ) ) ,
179
+ thread_msg_target,
180
180
runner_shared
181
181
} ,
182
182
_marker : PhantomData
@@ -261,7 +261,7 @@ impl<T: 'static> EventLoop<T> {
261
261
262
262
pub fn create_proxy ( & self ) -> EventLoopProxy < T > {
263
263
EventLoopProxy {
264
- target_window : self . thread_msg_target ,
264
+ target_window : self . window_target . p . thread_msg_target ,
265
265
event_send : self . thread_msg_sender . clone ( )
266
266
}
267
267
}
@@ -272,7 +272,8 @@ impl<T> EventLoopWindowTarget<T> {
272
272
pub ( crate ) fn create_thread_executor ( & self ) -> EventLoopThreadExecutor {
273
273
EventLoopThreadExecutor {
274
274
thread_id : self . thread_id ,
275
- trigger_newevents_on_redraw : self . trigger_newevents_on_redraw . clone ( )
275
+ trigger_newevents_on_redraw : self . trigger_newevents_on_redraw . clone ( ) ,
276
+ target_window : self . thread_msg_target
276
277
}
277
278
}
278
279
}
@@ -327,7 +328,7 @@ impl<T> EventLoopRunner<T> {
327
328
control_flow : ControlFlow :: default ( ) ,
328
329
runner_state : RunnerState :: New ,
329
330
in_modal_loop : false ,
330
- modal_redraw_window : event_loop. thread_msg_target ,
331
+ modal_redraw_window : event_loop. window_target . p . thread_msg_target ,
331
332
event_handler : mem:: transmute :: <
332
333
Box < FnMut ( Event < T > , & mut ControlFlow ) > ,
333
334
Box < FnMut ( Event < T > , & mut ControlFlow ) >
@@ -558,16 +559,20 @@ fn dur2timeout(dur: Duration) -> DWORD {
558
559
impl < T > Drop for EventLoop < T > {
559
560
fn drop ( & mut self ) {
560
561
unsafe {
561
- winuser:: DestroyWindow ( self . thread_msg_target ) ;
562
+ winuser:: DestroyWindow ( self . window_target . p . thread_msg_target ) ;
562
563
}
563
564
}
564
565
}
565
566
566
567
pub ( crate ) struct EventLoopThreadExecutor {
567
568
thread_id : DWORD ,
568
- trigger_newevents_on_redraw : Arc < AtomicBool >
569
+ trigger_newevents_on_redraw : Arc < AtomicBool > ,
570
+ target_window : HWND
569
571
}
570
572
573
+ unsafe impl Send for EventLoopThreadExecutor { }
574
+ unsafe impl Sync for EventLoopThreadExecutor { }
575
+
571
576
impl EventLoopThreadExecutor {
572
577
/// Check to see if we're in the parent event loop's thread.
573
578
pub ( super ) fn in_event_loop_thread ( & self ) -> bool {
@@ -605,11 +610,11 @@ impl EventLoopThreadExecutor {
605
610
606
611
let raw = Box :: into_raw ( boxed2) ;
607
612
608
- let res = winuser:: PostThreadMessageA ( self . thread_id , * EXEC_MSG_ID ,
609
- raw as * mut ( ) as usize as WPARAM , 0 ) ;
610
- // PostThreadMessage can only fail if the thread ID is invalid (which shouldn't happen
611
- // as the events loop is still alive) or if the queue is full.
612
- assert ! ( res != 0 , "PostThreadMessage failed ; is the messages queue full?" ) ;
613
+ let res = winuser:: PostMessageW (
614
+ self . target_window , * EXEC_MSG_ID ,
615
+ raw as * mut ( ) as usize as WPARAM , 0
616
+ ) ;
617
+ assert ! ( res != 0 , "PostMessage failed ; is the messages queue full?" ) ;
613
618
}
614
619
}
615
620
}
0 commit comments