gpui(windows): Fix clicks to inactive windows not dispatching to the clicked window (#45237)

Lukas Wirth created

Release Notes:

- Fixed an issue on windows where clicking buttons on windows in the
background would not register as being clicked on that window

Change summary

crates/gpui/src/platform/windows/events.rs | 5 +++++
crates/gpui/src/window.rs                  | 2 +-
2 files changed, 6 insertions(+), 1 deletion(-)

Detailed changes

crates/gpui/src/platform/windows/events.rs 🔗

@@ -40,6 +40,11 @@ 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).log_err() };
+                None
+            }
             WM_ACTIVATE => self.handle_activate_msg(wparam),
             WM_CREATE => self.handle_create_msg(handle),
             WM_MOVE => self.handle_move_msg(handle, lparam),

crates/gpui/src/window.rs 🔗

@@ -4966,7 +4966,7 @@ impl<V: 'static> From<WindowHandle<V>> for AnyWindowHandle {
 }
 
 /// A handle to a window with any root view type, which can be downcast to a window with a specific root view type.
-#[derive(Copy, Clone, PartialEq, Eq, Hash)]
+#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
 pub struct AnyWindowHandle {
     pub(crate) id: WindowId,
     state_type: TypeId,