1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-26 16:34:23 +03:00

lua: add window:maximize() and window:restore() methods

Implemented on macOS only for the moment.

refs: https://github.com/wez/wezterm/issues/284
This commit is contained in:
Wez Furlong 2022-07-06 23:10:14 -07:00
parent 533e52c589
commit 8853df02ca
3 changed files with 45 additions and 0 deletions

View File

@ -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<String>, Option<u64>)| {

View File

@ -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) {}

View File

@ -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;