From 51019f8e65b8d883b220f82617f8bebd418de87e Mon Sep 17 00:00:00 2001 From: Adam Williams <67129355+Adams-Galaxy@users.noreply.github.com> Date: Mon, 24 Aug 2026 08:57:04 +1200 Subject: [PATCH] macos: Fix window border when opacity<1 and shadow enabled (#8038) This was seemingly due to MacOS quirks, and was fixed by using a slightly transparent bg color to fix WM composition. refs: #5158 --- Co-authored-by: Adam Williams --- window/src/os/macos/window.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs index ec4b645ca..34e0123ac 100644 --- a/window/src/os/macos/window.rs +++ b/window/src/os/macos/window.rs @@ -58,6 +58,23 @@ const NSViewLayerContentsPlacementTopLeft: NSInteger = 11; #[allow(non_upper_case_globals)] const NSViewLayerContentsRedrawDuringViewResize: NSInteger = 2; +/// Returns the background color to use for the window. +unsafe fn window_background_color(is_opaque: bool) -> id { + let clear_color = cocoa::appkit::NSColor::clearColor(nil); + if is_opaque { + clear_color + } else { + // An alpha of zero puts NSWindow into a special mode for irregularly + // shaped windows, where shadows are generated from the window contents. + // A nearly transparent color avoids that mode while preserving transparency. + // See: + // + // iTerm2 uses the same workaround: + // + msg_send![clear_color, colorWithAlphaComponent: 0.01f64] + } +} + #[link(name = "CoreGraphics", kind = "framework")] extern "C" { fn CGSMainConnectionID() -> id; @@ -524,7 +541,8 @@ impl Window { let _: () = msg_send![*window, setRestorable: NO]; window.setReleasedWhenClosed_(NO); - window.setBackgroundColor_(cocoa::appkit::NSColor::clearColor(nil)); + let is_opaque = config.window_background_opacity >= 1.0; + window.setBackgroundColor_(window_background_color(is_opaque)); // Tell Cocoa that we output in sRGB, so it handles color space // conversion for non-sRGB displays. @@ -1104,6 +1122,9 @@ impl WindowInner { is_opaque }; self.window.setHasShadow_(to_yes_no(needs_shadow)); + + self.window + .setBackgroundColor_(window_background_color(is_opaque)); } }