Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

gpui: Fix title bar clicks being delayed on macOS 27 (#58947)

Anthony Eidc8554b46e789
diff --git a/crates/gpui_macos/src/window.rs b/crates/gpui_macos/src/window.rs
index b0abd8ffb7e..51adfe50b32 100644
--- a/crates/gpui_macos/src/window.rs
+++ b/crates/gpui_macos/src/window.rs
@@ -288,6 +288,15 @@ unsafe fn build_classes() {
sel!(characterIndexForPoint:),
character_index_for_point as extern "C" fn(&Object, Sel, NSPoint) -> u64,
);
+
+ // Undocumented SPI, also implemented by Chromium's content view. This
+ // lets full size content windows mark our Metal view as app owned title
+ // bar content, avoiding AppKit's title bar click-delay behavior.
+ decl.add_method(
+ sel!(_opaqueRectForWindowMoveWhenInTitlebar),
+ opaque_rect_for_window_move_when_in_titlebar
+ as extern "C" fn(&Object, Sel) -> NSRect,
+ );
decl.register()
};
BLURRED_VIEW_CLASS = {
@@ -2753,6 +2762,25 @@ extern "C" fn accepts_first_mouse(this: &Object, _: Sel, _: id) -> BOOL {
YES
}
+extern "C" fn opaque_rect_for_window_move_when_in_titlebar(this: &Object, _: Sel) -> NSRect {
+ unsafe {
+ let window: id = msg_send![this, window];
+ if window == nil {
+ return NSRect::new(NSPoint::new(0., 0.), NSSize::new(0., 0.));
+ }
+
+ let style_mask: NSWindowStyleMask = msg_send![window, styleMask];
+ if style_mask.contains(NSWindowStyleMask::NSFullSizeContentViewWindowMask) {
+ // Declare the entire view as opaque content for window move purposes
+ // when using a custom titlebar, so AppKit doesn't wait for double click
+ // disambiguation before delivering clicks to titlebar controls.
+ msg_send![this, bounds]
+ } else {
+ NSRect::new(NSPoint::new(0., 0.), NSSize::new(0., 0.))
+ }
+ }
+}
+
extern "C" fn character_index_for_point(this: &Object, _: Sel, position: NSPoint) -> u64 {
let position = screen_point_to_gpui_point(this, position);
with_input_handler(this, |input_handler| {