diff --git a/wezterm-gui/src/scripting/guiwin.rs b/wezterm-gui/src/scripting/guiwin.rs index 9ca9b619d..a38f0d83a 100644 --- a/wezterm-gui/src/scripting/guiwin.rs +++ b/wezterm-gui/src/scripting/guiwin.rs @@ -50,6 +50,14 @@ impl UserData for GuiWin { this.window.set_window_position(euclid::point2(x, y)); Ok(()) }); + methods.add_method("maximize", |_, this, _: ()| { + this.window.maximize(); + Ok(()) + }); + methods.add_method("restore", |_, this, _: ()| { + this.window.restore(); + Ok(()) + }); methods.add_method( "toast_notification", |_, _, (title, message, url, timeout): (String, String, Option, Option)| { diff --git a/window/src/lib.rs b/window/src/lib.rs index 32729dd53..1a647117b 100644 --- a/window/src/lib.rs +++ b/window/src/lib.rs @@ -289,6 +289,9 @@ pub trait WindowOps { /// and/or in the task manager/task switcher fn set_icon(&self, _image: Image) {} + fn maximize(&self) {} + fn restore(&self) {} + fn toggle_fullscreen(&self) {} fn config_did_change(&self, _config: &config::ConfigHandle) {} diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs index 059afc259..93ab63153 100644 --- a/window/src/os/macos/window.rs +++ b/window/src/os/macos/window.rs @@ -687,6 +687,20 @@ impl WindowOps for Window { }); } + fn maximize(&self) { + Connection::with_window_inner(self.id, move |inner| { + inner.maximize(); + Ok(()) + }); + } + + fn restore(&self) { + Connection::with_window_inner(self.id, move |inner| { + inner.restore(); + Ok(()) + }); + } + fn set_resize_increments(&self, x: u16, y: u16) { Connection::with_window_inner(self.id, move |inner| { inner.set_resize_increments(x, y); @@ -1030,6 +1044,26 @@ impl WindowInner { } } + fn is_zoomed(&self) -> bool { + unsafe { msg_send![*self.window, isZoomed] } + } + + fn maximize(&mut self) { + if !self.is_zoomed() { + unsafe { + NSWindow::zoom_(*self.window, nil); + } + } + } + + fn restore(&mut self) { + if self.is_zoomed() { + unsafe { + NSWindow::zoom_(*self.window, nil); + } + } + } + fn toggle_fullscreen(&mut self) { let native_fullscreen = self.config.native_macos_fullscreen_mode;