From 6cfc4dc857b33929ad96e9f9acb4dd533a4f5c59 Mon Sep 17 00:00:00 2001 From: Smit Barmase Date: Mon, 10 Mar 2025 21:32:52 +0000 Subject: [PATCH] gpui: Fix transparent titlebar in fullscreen mode on macOS (#26403) Closes #23735 This PR fixes an issue where Zed shows a transparent title bar in fullscreen mode on macOS instead of the default gray one. When switching to fullscreen mode, we change the title bar appearance to opaque. When exiting fullscreen mode, we check the existing `appears_transparent` flag that we pass to gpui to decide whether to change the title bar back to transparent or not. Note: Regardless of the `appears_transparent` flag, gpui should always show an opaque title bar in fullscreen mode to prevent a broken appearance, as macOS always displays the title bar in fullscreen mode upon mouse interaction. https://github.com/user-attachments/assets/211fb185-239b-454e-ac7f-b93b25d33805 Release Notes: - Fixed issue where Zed showed transparent titlebar in fullscreen mode on macOS. --- crates/gpui/src/platform/mac/window.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index ba5011ef160af20b97d9c118d662fb80b0449153..382ae6f7a77a0a0ae42c747afcdcd56b7fc27426 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -268,6 +268,10 @@ unsafe fn build_window_class(name: &'static str, superclass: &Class) -> *const C sel!(windowWillEnterFullScreen:), window_will_enter_fullscreen as extern "C" fn(&Object, Sel, id), ); + decl.add_method( + sel!(windowWillExitFullScreen:), + window_will_exit_fullscreen as extern "C" fn(&Object, Sel, id), + ); decl.add_method( sel!(windowDidMove:), window_did_move as extern "C" fn(&Object, Sel, id), @@ -334,6 +338,7 @@ struct MacWindowState { last_key_equivalent: Option, synthetic_drag_counter: usize, traffic_light_position: Option>, + transparent_titlebar: bool, previous_modifiers_changed_event: Option, keystroke_for_do_command: Option, do_command_handled: Option, @@ -613,6 +618,9 @@ impl MacWindow { traffic_light_position: titlebar .as_ref() .and_then(|titlebar| titlebar.traffic_light_position), + transparent_titlebar: titlebar + .as_ref() + .map_or(true, |titlebar| titlebar.appears_transparent), previous_modifiers_changed_event: None, keystroke_for_do_command: None, do_command_handled: None, @@ -1490,6 +1498,19 @@ extern "C" fn window_will_enter_fullscreen(this: &Object, _: Sel, _: id) { let window_state = unsafe { get_window_state(this) }; let mut lock = window_state.as_ref().lock(); lock.fullscreen_restore_bounds = lock.bounds(); + unsafe { + lock.native_window.setTitlebarAppearsTransparent_(NO); + } +} + +extern "C" fn window_will_exit_fullscreen(this: &Object, _: Sel, _: id) { + let window_state = unsafe { get_window_state(this) }; + let mut lock = window_state.as_ref().lock(); + if lock.transparent_titlebar { + unsafe { + lock.native_window.setTitlebarAppearsTransparent_(YES); + } + } } extern "C" fn window_did_move(this: &Object, _: Sel, _: id) {