Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
gpui_windows: Align inactive GPUI popup behavior on Windows with other platforms (#61411)
roboin826f28eb8ffa
diff --git a/crates/gpui_windows/src/events.rs b/crates/gpui_windows/src/events.rsindex 9f548722674..1bd18493d0b 100644--- a/crates/gpui_windows/src/events.rs+++ b/crates/gpui_windows/src/events.rs@@ -86,11 +86,13 @@ impl WindowsWindowInner {lparam: LPARAM,) -> LRESULT {let handled = match msg {- // eagerly activate the window, so calls to `active_window` will work correctly- WM_MOUSEACTIVATE => {- unsafe { SetActiveWindow(handle).ok() };- None- }+ // `DefWindowProc` answers `MA_NOACTIVATE` for a left click on `HTCAPTION`.+ // The activation is only triggered when `DefWindowProc` handles the following `WM_NCLBUTTONDOWN`.+ // The GPUI event is dispatched in between, so a click handler runs while `active_window` is still+ // whichever window was active before the click. If that handler consumes the+ // press, `DefWindowProc` never sees it, so the window is never activated at all.+ // So, let's eagerly activate the window.+ WM_MOUSEACTIVATE => Some(MA_ACTIVATE as isize),WM_ACTIVATE => self.handle_activate_msg(wparam),WM_CREATE => self.handle_create_msg(handle),WM_MOVE => self.handle_move_msg(handle, lparam),@@ -687,7 +689,11 @@ impl WindowsWindowInner {.ok().log_err();} else {- if let Some(ctx) = ImeContext::get(handle) {+ // The IME context is per-thread, so without this check a change in this+ // window's text input state could commit an IME composition happening in another window.+ if GetFocus() == handle+ && let Some(ctx) = ImeContext::get(handle)+ {ImmNotifyIME(*ctx, NI_COMPOSITIONSTR, CPS_COMPLETE, 0).ok().log_err();diff --git a/crates/gpui_windows/src/window.rs b/crates/gpui_windows/src/window.rsindex 99d095f9aab..af240716c90 100644--- a/crates/gpui_windows/src/window.rs+++ b/crates/gpui_windows/src/window.rs@@ -469,7 +469,7 @@ impl WindowsWindow {);let (mut dwexstyle, dwstyle) = if params.kind == WindowKind::PopUp {- (WS_EX_TOOLWINDOW, WINDOW_STYLE(0x0))+ (WS_EX_TOOLWINDOW | WS_EX_TOPMOST, WINDOW_STYLE(0x0))} else {let mut dwstyle = WS_SYSMENU;@@ -560,6 +560,10 @@ impl WindowsWindow {&this.state.border_offset,)?;if params.show {+ let mut placement = placement;+ if !params.focus {+ placement.showCmd = SW_SHOWNOACTIVATE.0 as u32;+ }unsafe { SetWindowPlacement(hwnd, &placement)? };} else {this.state.initial_placement.set(Some(WindowOpenStatus {