From 2271c3ae596a2dfec1f4c3e42ca15bfc4afecac9 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 5 Feb 2023 17:56:01 -0700 Subject: [PATCH] macos: spawn new window when clicking on dock icon If there are no windows, clicking on the dock icon will spawn a new window. Requires that `quit_when_all_windows_are_closed=false` refs: https://github.com/wez/wezterm/issues/3057 --- window/src/os/macos/app.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/window/src/os/macos/app.rs b/window/src/os/macos/app.rs index 4d94ecd17..7082a9d5c 100644 --- a/window/src/os/macos/app.rs +++ b/window/src/os/macos/app.rs @@ -68,6 +68,14 @@ extern "C" fn application_will_finish_launching( log::debug!("application_will_finish_launching"); } +extern "C" fn application_open_untitled_file(_self: &mut Object, _sel: Sel, _app: *mut Object) { + if let Some(conn) = Connection::get() { + conn.dispatch_app_event(ApplicationEvent::PerformKeyAssignment( + KeyAssignment::SpawnWindow, + )); + } +} + extern "C" fn wezterm_perform_key_assignment( _self: &mut Object, _sel: Sel, @@ -167,6 +175,10 @@ fn get_class() -> &'static Class { sel!(weztermShowAbout:), wezterm_show_about as extern "C" fn(&mut Object, Sel, *mut Object), ); + cls.add_method( + sel!(applicationOpenUntitledFile:), + application_open_untitled_file as extern "C" fn(&mut Object, Sel, *mut Object), + ); } cls.register()