Skip to content

Commit 4820bca

Browse files
committed
fix(windows): emit LoopDestroyed on WM_ENDSESSION
1 parent 5ac00b5 commit 4820bca

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

.changes/wm-endsession.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
tao: patch
3+
---
4+
5+
Emit `Event::LoopDestroyed` on receiving `WM_ENDSESSION` message on Windows

src/platform_impl/windows/event_loop.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ use std::{
2222
use windows::{
2323
core::{s, BOOL, PCWSTR},
2424
Win32::{
25-
Foundation::{HANDLE, HINSTANCE, HWND, LPARAM, LRESULT, POINT, RECT, WAIT_TIMEOUT, WPARAM},
25+
Foundation::{
26+
HANDLE, HINSTANCE, HWND, LPARAM, LRESULT, POINT, RECT, TRUE, WAIT_TIMEOUT, WPARAM,
27+
},
2628
Graphics::Gdi::*,
2729
System::{
2830
LibraryLoader::GetModuleHandleW,
@@ -642,15 +644,15 @@ lazy_static! {
642644
RegisterWindowMessageA(s!("TaskbarCreated"))
643645
};
644646
static ref THREAD_EVENT_TARGET_WINDOW_CLASS: Vec<u16> = unsafe {
645-
let class_name= util::encode_wide("Tao Thread Event Target");
647+
let class_name = util::encode_wide("Tao Thread Event Target");
646648

647649
let class = WNDCLASSEXW {
648650
cbSize: mem::size_of::<WNDCLASSEXW>() as u32,
649651
style: Default::default(),
650652
lpfnWndProc: Some(util::call_default_window_proc),
651653
cbClsExtra: 0,
652654
cbWndExtra: 0,
653-
hInstance:HINSTANCE(GetModuleHandleW(PCWSTR::null()).unwrap_or_default().0),
655+
hInstance: HINSTANCE(GetModuleHandleW(PCWSTR::null()).unwrap_or_default().0),
654656
hIcon: HICON::default(),
655657
hCursor: HCURSOR::default(), // must be null in order for cursor state to work properly
656658
hbrBackground: HBRUSH::default(),
@@ -2380,6 +2382,18 @@ unsafe extern "system" fn thread_event_target_callback<T: 'static>(
23802382
DefSubclassProc(window, msg, wparam, lparam)
23812383
}
23822384

2385+
// We don't process `WM_QUERYENDSESSION` yet until we introduce the same mechanism as Tauri's `ExitRequested` event
2386+
// win32wm::WM_QUERYENDSESSION => {}
2387+
win32wm::WM_ENDSESSION => {
2388+
// `wParam` is `FALSE` is for if the shutdown gets canceled,
2389+
// and we don't need to handle that case since we didn't do anything prior in response to `WM_QUERYENDSESSION`
2390+
if wparam.0 == TRUE.0 as usize {
2391+
subclass_input.event_loop_runner.loop_destroyed();
2392+
}
2393+
// Note: after we return 0 here, Windows will shut us down
2394+
LRESULT(0)
2395+
}
2396+
23832397
_ if msg == *USER_EVENT_MSG_ID => {
23842398
if let Ok(event) = subclass_input.user_event_receiver.recv() {
23852399
subclass_input.send_event(Event::UserEvent(event));

src/platform_impl/windows/util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ pub type GetDpiForMonitor = unsafe extern "system" fn(
291291
type GetSystemMetricsForDpi =
292292
unsafe extern "system" fn(nindex: SYSTEM_METRICS_INDEX, dpi: u32) -> i32;
293293
pub type EnableNonClientDpiScaling = unsafe extern "system" fn(hwnd: HWND) -> BOOL;
294+
#[allow(non_snake_case)]
294295
pub type AdjustWindowRectExForDpi = unsafe extern "system" fn(
295296
rect: *mut RECT,
296297
dwStyle: WINDOW_STYLE,

0 commit comments

Comments
 (0)