Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/wm-endsession.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
tao: patch
---

Emit `Event::LoopDestroyed` on receiving `WM_ENDSESSION` message on Windows
20 changes: 17 additions & 3 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ use std::{
use windows::{
core::{s, BOOL, PCWSTR},
Win32::{
Foundation::{HANDLE, HINSTANCE, HWND, LPARAM, LRESULT, POINT, RECT, WAIT_TIMEOUT, WPARAM},
Foundation::{
HANDLE, HINSTANCE, HWND, LPARAM, LRESULT, POINT, RECT, TRUE, WAIT_TIMEOUT, WPARAM,
},
Graphics::Gdi::*,
System::{
LibraryLoader::GetModuleHandleW,
Expand Down Expand Up @@ -642,15 +644,15 @@ lazy_static! {
RegisterWindowMessageA(s!("TaskbarCreated"))
};
static ref THREAD_EVENT_TARGET_WINDOW_CLASS: Vec<u16> = unsafe {
let class_name= util::encode_wide("Tao Thread Event Target");
let class_name = util::encode_wide("Tao Thread Event Target");

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

// We don't process `WM_QUERYENDSESSION` yet until we introduce the same mechanism as Tauri's `ExitRequested` event
// win32wm::WM_QUERYENDSESSION => {}
win32wm::WM_ENDSESSION => {
// `wParam` is `FALSE` is for if the shutdown gets canceled,
// and we don't need to handle that case since we didn't do anything prior in response to `WM_QUERYENDSESSION`
if wparam.0 == TRUE.0 as usize {
subclass_input.event_loop_runner.loop_destroyed();
}
// Note: after we return 0 here, Windows will shut us down
LRESULT(0)
}

_ if msg == *USER_EVENT_MSG_ID => {
if let Ok(event) = subclass_input.user_event_receiver.recv() {
subclass_input.send_event(Event::UserEvent(event));
Expand Down
1 change: 1 addition & 0 deletions src/platform_impl/windows/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ pub type GetDpiForMonitor = unsafe extern "system" fn(
type GetSystemMetricsForDpi =
unsafe extern "system" fn(nindex: SYSTEM_METRICS_INDEX, dpi: u32) -> i32;
pub type EnableNonClientDpiScaling = unsafe extern "system" fn(hwnd: HWND) -> BOOL;
#[allow(non_snake_case)]
pub type AdjustWindowRectExForDpi = unsafe extern "system" fn(
rect: *mut RECT,
dwStyle: WINDOW_STYLE,
Expand Down
Loading