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_macos: Fix traffic lights animation during fullscreen exit (#64339)

tidely613a80b9e9ce
diff --git a/crates/gpui_macos/src/window.rs b/crates/gpui_macos/src/window.rs
index bd4996011f6..9a6c503a528 100644
--- a/crates/gpui_macos/src/window.rs
+++ b/crates/gpui_macos/src/window.rs
@@ -455,6 +455,10 @@ unsafe fn build_window_class(name: &'static str, superclass: &Class) -> *const C
sel!(windowWillExitFullScreen:),
window_will_exit_fullscreen as extern "C" fn(&Object, Sel, id),
);
+ decl.add_method(
+ sel!(windowDidFailToExitFullScreen:),
+ window_did_fail_to_exit_fullscreen as extern "C" fn(&Object, Sel, id),
+ );
decl.add_method(
sel!(windowDidExitFullScreen:),
window_did_exit_fullscreen as extern "C" fn(&Object, Sel, id),
@@ -548,6 +552,7 @@ unsafe fn build_window_class(name: &'static str, superclass: &Class) -> *const C
}
}
+#[derive(Clone, Copy)]
struct TrafficLightFrames {
titlebar: Objc2NSRect,
close: Objc2NSRect,
@@ -679,6 +684,7 @@ struct MacWindowState {
synthetic_drag_counter: usize,
traffic_light_position: Option<Point<Pixels>>,
traffic_light_frames: Option<TrafficLightFrames>,
+ pre_fullscreen_traffic_light_frames: Option<TrafficLightFrames>,
transparent_titlebar: bool,
previous_modifiers_changed_event: Option<PlatformInput>,
keystroke_for_do_command: Option<Keystroke>,
@@ -692,6 +698,7 @@ struct MacWindowState {
// windows draw their own titlebar and move the window via `start_window_move`.
app_owns_titlebar_drag: bool,
fullscreen_restore_bounds: Bounds<Pixels>,
+ is_exiting_fullscreen: bool,
simple_fullscreen_state: Option<SimpleFullscreenState>,
move_tab_to_new_window_callback: Option<Box<dyn FnMut()>>,
merge_all_windows_callback: Option<Box<dyn FnMut()>>,
@@ -708,7 +715,7 @@ struct MacWindowState {
impl MacWindowState {
fn move_traffic_light(&mut self) {
if let Some(traffic_light_position) = self.traffic_light_position {
- if self.is_fullscreen() {
+ if self.is_fullscreen() && !self.is_exiting_fullscreen {
self.restore_traffic_light();
return;
}
@@ -1116,6 +1123,7 @@ impl MacWindow {
.as_ref()
.and_then(|titlebar| titlebar.traffic_light_position),
traffic_light_frames: None,
+ pre_fullscreen_traffic_light_frames: None,
transparent_titlebar: titlebar
.as_ref()
.is_none_or(|titlebar| titlebar.appears_transparent),
@@ -1126,6 +1134,7 @@ impl MacWindow {
first_mouse: false,
app_owns_titlebar_drag,
fullscreen_restore_bounds: Bounds::default(),
+ is_exiting_fullscreen: false,
simple_fullscreen_state: None,
move_tab_to_new_window_callback: None,
merge_all_windows_callback: None,
@@ -2991,6 +3000,8 @@ 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();
+ lock.is_exiting_fullscreen = false;
+ lock.pre_fullscreen_traffic_light_frames = lock.traffic_light_frames;
lock.restore_traffic_light();
let min_version = NSOperatingSystemVersion::new(15, 3, 0);
@@ -3004,7 +3015,8 @@ extern "C" fn window_will_enter_fullscreen(this: &Object, _: Sel, _: id) {
extern "C" fn window_will_exit_fullscreen(this: &Object, _: Sel, _: id) {
let window_state = unsafe { get_window_state(this) };
- let lock = window_state.as_ref().lock();
+ let mut lock = window_state.as_ref().lock();
+ lock.is_exiting_fullscreen = true;
let min_version = NSOperatingSystemVersion::new(15, 3, 0);
@@ -3013,13 +3025,27 @@ extern "C" fn window_will_exit_fullscreen(this: &Object, _: Sel, _: id) {
lock.native_window.setTitlebarAppearsTransparent_(YES);
}
}
+
+ lock.move_traffic_light();
+}
+
+extern "C" fn window_did_fail_to_exit_fullscreen(this: &Object, _: Sel, _: id) {
+ let window_state = unsafe { get_window_state(this) };
+ let mut lock = window_state.as_ref().lock();
+ lock.is_exiting_fullscreen = false;
+ lock.restore_traffic_light();
}
extern "C" fn window_did_exit_fullscreen(this: &Object, _: Sel, _: id) {
// SAFETY: This method is registered only on GPUI window classes, which initialize
// WINDOW_STATE_IVAR with an Arc<Mutex<MacWindowState>> during window creation.
let window_state = unsafe { get_window_state(this) };
- window_state.as_ref().lock().move_traffic_light();
+ let mut lock = window_state.as_ref().lock();
+ lock.is_exiting_fullscreen = false;
+ // Moving the buttons during the transition captures their fullscreen frames.
+ // Keep using the native windowed frames when restoring them on the next entry.
+ lock.traffic_light_frames = lock.pre_fullscreen_traffic_light_frames.take();
+ lock.move_traffic_light();
}
pub(crate) fn is_macos_version_at_least(version: NSOperatingSystemVersion) -> bool {