diff --git a/crates/gpui/src/platform/windows/events.rs b/crates/gpui/src/platform/windows/events.rs index 70aac60658ea3e4ce806106ac9cc2116ff5cd7d9..986928ddea2025a51ed0fb38430e809deba4767f 100644 --- a/crates/gpui/src/platform/windows/events.rs +++ b/crates/gpui/src/platform/windows/events.rs @@ -217,7 +217,13 @@ fn handle_destroy_msg(handle: HWND, state_ptr: Rc) -> Opt callback(); } unsafe { - PostMessageW(None, CLOSE_ONE_WINDOW, None, LPARAM(handle.0 as isize)).log_err(); + PostMessageW( + None, + CLOSE_ONE_WINDOW, + WPARAM(state_ptr.validation_number), + LPARAM(handle.0 as isize), + ) + .log_err(); } Some(0) } diff --git a/crates/gpui/src/platform/windows/platform.rs b/crates/gpui/src/platform/windows/platform.rs index 45e404788d1be93c26d5aceb29bbae7fb9997823..edd69d4dc922c74355181cf284007016aed73358 100644 --- a/crates/gpui/src/platform/windows/platform.rs +++ b/crates/gpui/src/platform/windows/platform.rs @@ -58,6 +58,7 @@ pub(crate) struct WindowsPlatform { clipboard_metadata_format: u32, windows_version: WindowsVersion, bitmap_factory: ManuallyDrop, + validation_number: usize, } pub(crate) struct WindowsPlatformState { @@ -111,6 +112,7 @@ impl WindowsPlatform { let clipboard_metadata_format = register_clipboard_format(CLIPBOARD_METADATA_FORMAT).unwrap(); let windows_version = WindowsVersion::new().expect("Error retrieve windows version"); + let validation_number = rand::random::(); Self { state, @@ -123,6 +125,7 @@ impl WindowsPlatform { clipboard_metadata_format, windows_version, bitmap_factory, + validation_number, } } @@ -159,7 +162,16 @@ impl WindowsPlatform { }); } - fn close_one_window(&self, target_window: HWND) -> bool { + fn close_one_window( + &self, + target_window: HWND, + validation_number: usize, + msg: *const MSG, + ) -> bool { + if validation_number != self.validation_number { + unsafe { DispatchMessageW(msg) }; + return false; + } let mut lock = self.raw_window_handles.write(); let index = lock .iter() @@ -206,7 +218,11 @@ impl Platform for WindowsPlatform { match msg.message { WM_QUIT => break 'a, CLOSE_ONE_WINDOW => { - if self.close_one_window(HWND(msg.lParam.0 as _)) { + if self.close_one_window( + HWND(msg.lParam.0 as _), + msg.wParam.0, + &msg, + ) { break 'a; } } @@ -316,6 +332,7 @@ impl Platform for WindowsPlatform { self.foreground_executor.clone(), lock.current_cursor, self.windows_version, + self.validation_number, )?; drop(lock); let handle = window.get_raw_handle(); diff --git a/crates/gpui/src/platform/windows/window.rs b/crates/gpui/src/platform/windows/window.rs index 0904b615c4f0cc29eb0b1aa863bac83ed0ca4e9f..ce388d8444f96f0b25c6463d321c53fe563934d4 100644 --- a/crates/gpui/src/platform/windows/window.rs +++ b/crates/gpui/src/platform/windows/window.rs @@ -62,6 +62,7 @@ pub(crate) struct WindowsWindowStatePtr { pub(crate) is_movable: bool, pub(crate) executor: ForegroundExecutor, pub(crate) windows_version: WindowsVersion, + pub(crate) validation_number: usize, } impl WindowsWindowState { @@ -224,6 +225,7 @@ impl WindowsWindowStatePtr { is_movable: context.is_movable, executor: context.executor.clone(), windows_version: context.windows_version, + validation_number: context.validation_number, })) } } @@ -250,6 +252,7 @@ struct WindowCreateContext { executor: ForegroundExecutor, current_cursor: HCURSOR, windows_version: WindowsVersion, + validation_number: usize, } impl WindowsWindow { @@ -260,6 +263,7 @@ impl WindowsWindow { executor: ForegroundExecutor, current_cursor: HCURSOR, windows_version: WindowsVersion, + validation_number: usize, ) -> Result { let classname = register_wnd_class(icon); let hide_title_bar = params @@ -300,6 +304,7 @@ impl WindowsWindow { executor, current_cursor, windows_version, + validation_number, }; let lpparam = Some(&context as *const _ as *const _); let creation_result = unsafe {