diff --git a/Cargo.toml b/Cargo.toml index 10d87510a..8c60117cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,7 +108,7 @@ png = { version = "0.18", optional = true } [target.'cfg(target_os = "macos")'.dependencies] # muda builds the menu bar, and objc2-app-kit's NSAlert backs `window.confirm`. objc2 = "0.6" -objc2-app-kit = { version = "0.3", default-features = false, features = ["std", "NSAlert", "NSApplication", "NSButton", "NSControl", "NSResponder", "NSView"] } +objc2-app-kit = { version = "0.3", default-features = false, features = ["std", "NSAlert", "NSApplication", "NSButton", "NSControl", "NSResponder", "NSView", "NSWindow"] } objc2-foundation = { version = "0.3", default-features = false, features = ["std", "NSString"] } muda = "0.20" # `window.confirm` panel added to wry's WKUIDelegate (src/commands/app.rs). diff --git a/src/commands/app.rs b/src/commands/app.rs index c770486c7..8e9320fcb 100644 --- a/src/commands/app.rs +++ b/src/commands/app.rs @@ -1058,6 +1058,11 @@ mod imp { sync_maximized(&webview, page_maximized); } #[cfg(target_os = "macos")] + Event::WindowEvent { + event: WindowEvent::Resized(_), + .. + } => align_traffic_lights(&window, zoom_percent), + #[cfg(target_os = "macos")] Event::UserEvent(UserEvent::Menu(id)) if id == quit_item.id() => { begin_quit(&mut quit, &window, &webview, control_flow); } @@ -1256,11 +1261,34 @@ mod imp { #[cfg(target_os = "macos")] fn align_traffic_lights(window: &Window, percent: i32) { + use objc2_app_kit::{NSWindow, NSWindowButton}; + use objc2_foundation::NSPoint; use tao::dpi::LogicalPosition; use tao::platform::macos::WindowExtMacOS; let zoom = (f64::from(percent) / 100.0).max(1.0); - window.set_traffic_light_inset(LogicalPosition::new(16.0, 22.0 + 20.0 * (zoom - 1.0))); + // Tao owns this window for the duration of the main-thread event. + let native_window = unsafe { &*window.ns_window().cast::() }; + let inset = native_window + .standardWindowButton(NSWindowButton::CloseButton) + .and_then(|button| { + let container = unsafe { button.superview()?.superview()? }; + let bounds = button.bounds(); + let center = button.convertPoint_toView( + NSPoint::new( + bounds.origin.x + bounds.size.width / 2.0, + bounds.origin.y + bounds.size.height / 2.0, + ), + None, + ); + let current = native_window.frame().size.height - center.y; + Some( + container.frame().size.height - button.frame().size.height + 20.0 * zoom + - current, + ) + }) + .unwrap_or(22.0 + 20.0 * (zoom - 1.0)); + window.set_traffic_light_inset(LogicalPosition::new(16.0, inset)); // Tao reapplies the inset on a title change, not on request_redraw. window.set_title(&window.title()); } diff --git a/ui/src/App.tsx b/ui/src/App.tsx index 5fa1c8491..0522d16bf 100644 --- a/ui/src/App.tsx +++ b/ui/src/App.tsx @@ -1815,7 +1815,7 @@ export default function App({ runtime, projectId, pane }: { runtime: RuntimeInfo return (
- {projectId &&
+ {projectId &&
{ if (railVisible) setRailOpen(false);