gpui Windows: no calls on destroyed windows, no deferred report after close
The window procedure records WM_DESTROY, revokes drag-drop while the handle is valid and drops the activation callback; Drop leaves a destroyed window alone. A dispatch after quit logs at debug. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
09479941ff
commit
3466f108c4
6 files changed
+28
-10
No files matched your search
+11
-3
@@ -9,7 +9,7 @@ use std::{
|
||||
use anyhow::Context;
|
||||
use gpui_util::ResultExt;
|
||||
use windows::Win32::{
|
||||
Foundation::{FILETIME, LPARAM, WPARAM},
|
||||
Foundation::{ERROR_INVALID_WINDOW_HANDLE, FILETIME, LPARAM, WPARAM},
|
||||
Media::{timeBeginPeriod, timeEndPeriod},
|
||||
System::Threading::{
|
||||
CloseThreadpoolTimer, CreateThreadpoolTimer, GetCurrentThread, PTP_CALLBACK_INSTANCE,
|
||||
@@ -119,14 +119,22 @@ impl PlatformDispatcher for WindowsDispatcher {
|
||||
match self.main_sender.send(priority, runnable) {
|
||||
Ok(_) => {
|
||||
if !self.wake_posted.swap(true, Ordering::AcqRel) {
|
||||
unsafe {
|
||||
let posted = unsafe {
|
||||
PostMessageW(
|
||||
Some(self.platform_window_handle.as_raw()),
|
||||
WM_GPUI_TASK_DISPATCHED_ON_MAIN_THREAD,
|
||||
WPARAM(self.validation_number),
|
||||
LPARAM(0),
|
||||
)
|
||||
.log_err();
|
||||
};
|
||||
match posted {
|
||||
// The platform window is gone: the app has quit.
|
||||
Err(e) if e.code() == ERROR_INVALID_WINDOW_HANDLE.to_hresult() => {
|
||||
log::debug!("main-thread task after quit, dropped");
|
||||
}
|
||||
result => {
|
||||
result.log_err();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -341,6 +341,10 @@ impl WindowsWindowInner {
|
||||
}
|
||||
|
||||
fn handle_destroy_msg(&self, handle: HWND) -> Option<isize> {
|
||||
self.state.destroyed.set(true);
|
||||
unsafe { windows::Win32::System::Ole::RevokeDragDrop(handle).log_err() };
|
||||
// Its deferred report would find no window.
|
||||
self.state.callbacks.active_status_change.take();
|
||||
let callback = { self.state.callbacks.close.take() };
|
||||
// Re-enable parent window if this was a modal dialog
|
||||
if let Some(parent_hwnd) = self.parent_hwnd {
|
||||
|
||||
+8
-5
@@ -62,6 +62,7 @@ pub struct WindowsWindowState {
|
||||
pub last_reported_capslock: Cell<Option<Capslock>>,
|
||||
pub hovered: Cell<bool>,
|
||||
pub last_visibility: Cell<Option<WindowVisibility>>,
|
||||
pub destroyed: Cell<bool>,
|
||||
pub direct_manipulation: DirectManipulationHandler,
|
||||
|
||||
pub renderer: RefCell<DirectXRenderer>,
|
||||
@@ -177,6 +178,7 @@ impl WindowsWindowState {
|
||||
last_reported_capslock: Cell::new(last_reported_capslock),
|
||||
hovered: Cell::new(hovered),
|
||||
last_visibility: Cell::new(None),
|
||||
destroyed: Cell::new(false),
|
||||
renderer: RefCell::new(renderer),
|
||||
force_render_pending: Cell::new(false),
|
||||
click_state,
|
||||
@@ -610,10 +612,14 @@ impl rwh::HasDisplayHandle for WindowsWindow {
|
||||
impl Drop for WindowsWindow {
|
||||
fn drop(&mut self) {
|
||||
self.0.dialog_owner.close();
|
||||
unsafe { ShowWindowAsync(self.0.hwnd, SW_HIDE).ok().log_err() };
|
||||
// `DestroyWindow` below sends `WM_SHOWWINDOW`; without a callback the
|
||||
// resulting visibility report has nothing to notify.
|
||||
self.0.state.callbacks.visibility_change.take();
|
||||
// Windows already destroyed it.
|
||||
if self.0.state.destroyed.get() {
|
||||
return;
|
||||
}
|
||||
unsafe { ShowWindowAsync(self.0.hwnd, SW_HIDE).ok().log_err() };
|
||||
// clone this `Rc` to prevent early release of the pointer
|
||||
let this = self.0.clone();
|
||||
self.0
|
||||
@@ -621,10 +627,7 @@ impl Drop for WindowsWindow {
|
||||
.spawn(async move {
|
||||
this.dialog_owner.when_idle().await;
|
||||
let handle = this.hwnd;
|
||||
unsafe {
|
||||
RevokeDragDrop(handle).log_err();
|
||||
DestroyWindow(handle).log_err();
|
||||
}
|
||||
unsafe { DestroyWindow(handle).log_err() };
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user