windows: Add back `hide_title_bar` checks (#32427)

张小白 created

These `if` condition checks were removed in #30828, and this PR adds
them back. This is especially important in the handling of
`WM_NCHITTEST`, where all the calculations are based on the assumption
that `hide_title_bar = true`.


Release Notes:

- N/A

Change summary

crates/gpui/src/platform/windows/events.rs | 45 +++++++++++++----------
1 file changed, 26 insertions(+), 19 deletions(-)

Detailed changes

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

@@ -888,6 +888,32 @@ fn handle_hit_test_msg(
         return None;
     }
 
+    let mut lock = state_ptr.state.borrow_mut();
+    if let Some(mut callback) = lock.callbacks.hit_test_window_control.take() {
+        drop(lock);
+        let area = callback();
+        state_ptr
+            .state
+            .borrow_mut()
+            .callbacks
+            .hit_test_window_control = Some(callback);
+        if let Some(area) = area {
+            return match area {
+                WindowControlArea::Drag => Some(HTCAPTION as _),
+                WindowControlArea::Close => Some(HTCLOSE as _),
+                WindowControlArea::Max => Some(HTMAXBUTTON as _),
+                WindowControlArea::Min => Some(HTMINBUTTON as _),
+            };
+        }
+    } else {
+        drop(lock);
+    }
+
+    if !state_ptr.hide_title_bar {
+        // If the OS draws the title bar, we don't need to handle hit test messages.
+        return None;
+    }
+
     // default handler for resize areas
     let hit = unsafe { DefWindowProcW(handle, msg, wparam, lparam) };
     if matches!(
@@ -922,25 +948,6 @@ fn handle_hit_test_msg(
         return Some(HTTOP as _);
     }
 
-    let mut lock = state_ptr.state.borrow_mut();
-    if let Some(mut callback) = lock.callbacks.hit_test_window_control.take() {
-        drop(lock);
-        let area = callback();
-        state_ptr
-            .state
-            .borrow_mut()
-            .callbacks
-            .hit_test_window_control = Some(callback);
-        if let Some(area) = area {
-            return match area {
-                WindowControlArea::Drag => Some(HTCAPTION as _),
-                WindowControlArea::Close => Some(HTCLOSE as _),
-                WindowControlArea::Max => Some(HTMAXBUTTON as _),
-                WindowControlArea::Min => Some(HTMINBUTTON as _),
-            };
-        }
-    }
-
     Some(HTCLIENT as _)
 }