Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix title bar spacing when building on the macOS Tahoe SDK (#45351)
Agus Zubiaga95ae388c0ce8
diff --git a/crates/title_bar/build.rs b/crates/title_bar/build.rsnew file mode 100644index 00000000000..ef70268ad31--- /dev/null+++ b/crates/title_bar/build.rs@@ -0,0 +1,28 @@+#![allow(clippy::disallowed_methods, reason = "build scripts are exempt")]++fn main() {+ println!("cargo::rustc-check-cfg=cfg(macos_sdk_26)");++ #[cfg(target_os = "macos")]+ {+ use std::process::Command;++ let output = Command::new("xcrun")+ .args(["--sdk", "macosx", "--show-sdk-version"])+ .output()+ .unwrap();++ let sdk_version = String::from_utf8(output.stdout).unwrap();+ let major_version: Option<u32> = sdk_version+ .trim()+ .split('.')+ .next()+ .and_then(|v| v.parse().ok());++ if let Some(major) = major_version+ && major >= 26+ {+ println!("cargo:rustc-cfg=macos_sdk_26");+ }+ }+}diff --git a/crates/title_bar/src/platforms/platform_mac.rs b/crates/title_bar/src/platforms/platform_mac.rsindex c7becde6c1a..5e8e4e50870 100644--- a/crates/title_bar/src/platforms/platform_mac.rs+++ b/crates/title_bar/src/platforms/platform_mac.rs@@ -1,6 +1,10 @@-/// Use pixels here instead of a rem-based size because the macOS traffic-/// lights are a static size, and don't scale with the rest of the UI.-///-/// Magic number: There is one extra pixel of padding on the left side due to-/// the 1px border around the window on macOS apps.+// Use pixels here instead of a rem-based size because the macOS traffic+// lights are a static size, and don't scale with the rest of the UI.+//+// Magic number: There is one extra pixel of padding on the left side due to+// the 1px border around the window on macOS apps.+#[cfg(macos_sdk_26)]+pub const TRAFFIC_LIGHT_PADDING: f32 = 78.;++#[cfg(not(macos_sdk_26))]pub const TRAFFIC_LIGHT_PADDING: f32 = 71.;diff --git a/crates/title_bar/src/title_bar.rs b/crates/title_bar/src/title_bar.rsindex 23572677919..d7759b0df80 100644--- a/crates/title_bar/src/title_bar.rs+++ b/crates/title_bar/src/title_bar.rs@@ -447,34 +447,38 @@ impl TitleBar {return None;}- Some(- Button::new("restricted_mode_trigger", "Restricted Mode")- .style(ButtonStyle::Tinted(TintColor::Warning))- .label_size(LabelSize::Small)- .color(Color::Warning)- .icon(IconName::Warning)- .icon_color(Color::Warning)- .icon_size(IconSize::Small)- .icon_position(IconPosition::Start)- .tooltip(|_, cx| {- Tooltip::with_meta(- "You're in Restricted Mode",- Some(&ToggleWorktreeSecurity),- "Mark this project as trusted and unlock all features",- cx,- )- })- .on_click({- cx.listener(move |this, _, window, cx| {- this.workspace- .update(cx, |workspace, cx| {- workspace.show_worktree_trust_security_modal(true, window, cx)- })- .log_err();- })+ let button = Button::new("restricted_mode_trigger", "Restricted Mode")+ .style(ButtonStyle::Tinted(TintColor::Warning))+ .label_size(LabelSize::Small)+ .color(Color::Warning)+ .icon(IconName::Warning)+ .icon_color(Color::Warning)+ .icon_size(IconSize::Small)+ .icon_position(IconPosition::Start)+ .tooltip(|_, cx| {+ Tooltip::with_meta(+ "You're in Restricted Mode",+ Some(&ToggleWorktreeSecurity),+ "Mark this project as trusted and unlock all features",+ cx,+ )+ })+ .on_click({+ cx.listener(move |this, _, window, cx| {+ this.workspace+ .update(cx, |workspace, cx| {+ workspace.show_worktree_trust_security_modal(true, window, cx)+ })+ .log_err();})- .into_any_element(),- )+ });++ if cfg!(macos_sdk_26) {+ // Make up for Tahoe's traffic light buttons having less spacing around them+ Some(div().child(button).ml_0p5().into_any_element())+ } else {+ Some(button.into_any_element())+ }}pub fn render_project_host(&self, cx: &mut Context<Self>) -> Option<AnyElement> {