mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-09-17 23:31:31 +02:00
fix(wm): ensure window msg threads are stopped
This commit ensures that message handling threads for windows that are created by komorebi are exited properly when the windows are destroyed. For some reason, passing the HWND returned by CreateWindowExW to GetMessageW continues returning TRUE even after the window has been destroyed. If HWND::NULL (via the Default trait) is passed to GetMessageW, which retrieves messages for any window belonging to the current thread (our threads here only own a single window), GetMessageW returns FALSE as expected after the window is destroyed. re #862
This commit is contained in:
@@ -98,13 +98,19 @@ impl Border {
|
||||
let hwnd = WindowsApi::create_border_window(PCWSTR(name.as_ptr()), h_module)?;
|
||||
hwnd_sender.send(hwnd)?;
|
||||
|
||||
let mut message = MSG::default();
|
||||
unsafe {
|
||||
while GetMessageW(&mut message, HWND(hwnd), 0, 0).into() {
|
||||
TranslateMessage(&message);
|
||||
DispatchMessageW(&message);
|
||||
std::thread::sleep(Duration::from_millis(10));
|
||||
let mut msg: MSG = MSG::default();
|
||||
|
||||
loop {
|
||||
unsafe {
|
||||
if !GetMessageW(&mut msg, HWND::default(), 0, 0).as_bool() {
|
||||
tracing::debug!("border window event processing thread shutdown");
|
||||
break;
|
||||
};
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessageW(&msg);
|
||||
}
|
||||
|
||||
std::thread::sleep(Duration::from_millis(10))
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user