From e07192e4e3bb2d2ba3b42ddcfa60ad5f173facdf Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 21 Mar 2024 09:36:54 -0700 Subject: [PATCH] Implement is_minimized for macOS (#9651) Release Notes: - N/A --- crates/gpui/src/platform/mac/window.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index cc51913919..b9e03168d1 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -303,6 +303,14 @@ unsafe fn build_window_class(name: &'static str, superclass: &Class) -> *const C sel!(concludeDragOperation:), conclude_drag_operation as extern "C" fn(&Object, Sel, id), ); + decl.add_method( + sel!(windowDidMiniaturize:), + window_did_miniaturize as extern "C" fn(&Object, Sel, id), + ); + decl.add_method( + sel!(windowDidDeminiaturize:), + window_did_deminiaturize as extern "C" fn(&Object, Sel, id), + ); decl.register() } @@ -342,6 +350,7 @@ struct MacWindowState { input_during_keydown: Option>, previous_keydown_inserted_text: Option, external_files_dragged: bool, + mimized: bool, } impl MacWindowState { @@ -419,9 +428,8 @@ impl MacWindowState { } } - // todo(macos) fn is_minimized(&self) -> bool { - false + self.mimized } fn is_fullscreen(&self) -> bool { @@ -599,6 +607,7 @@ impl MacWindow { input_during_keydown: None, previous_keydown_inserted_text: None, external_files_dragged: false, + mimized: false, }))); (*native_window).set_ivar( @@ -1818,6 +1827,18 @@ extern "C" fn conclude_drag_operation(this: &Object, _: Sel, _: id) { ); } +extern "C" fn window_did_miniaturize(this: &Object, _: Sel, _: id) { + let window_state = unsafe { get_window_state(this) }; + + window_state.lock().mimized = true; +} + +extern "C" fn window_did_deminiaturize(this: &Object, _: Sel, _: id) { + let window_state = unsafe { get_window_state(this) }; + + window_state.lock().mimized = false; +} + async fn synthetic_drag( window_state: Weak>, drag_id: usize,