From 00383ae967fef6216396c3acaf96a7002b013298 Mon Sep 17 00:00:00 2001 From: Chris Copeland Date: Sun, 27 Feb 2022 10:35:23 -0800 Subject: [PATCH] Add `ToggleMaximized` key binding action --- CHANGELOG.md | 3 ++- alacritty/src/config/bindings.rs | 3 +++ alacritty/src/display/mod.rs | 2 +- alacritty/src/display/window.rs | 18 +++++++++++------- alacritty/src/input.rs | 1 + 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f75e598..15b9a41c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Track and report surface damage information to Wayland compositors - Escape sequence for undercurl, dotted and dashed underlines (`CSI 4 : [3-5] m`) +- `ToggleMaximized` key binding action to (un-)maximize the active window, not bound by default ### Changed @@ -28,7 +29,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added - - Option `font.builtin_box_drawing` to disable the built-in font for drawing box characters +- Option `font.builtin_box_drawing` to disable the built-in font for drawing box characters ### Changed diff --git a/alacritty/src/config/bindings.rs b/alacritty/src/config/bindings.rs index 6de0d4b1..99d41c28 100644 --- a/alacritty/src/config/bindings.rs +++ b/alacritty/src/config/bindings.rs @@ -186,6 +186,9 @@ pub enum Action { /// Toggle fullscreen. ToggleFullscreen, + /// Toggle maximized. + ToggleMaximized, + /// Toggle simple fullscreen on macOS. #[cfg(target_os = "macos")] ToggleSimpleFullscreen, diff --git a/alacritty/src/display/mod.rs b/alacritty/src/display/mod.rs index dda32b0f..dfd43d04 100644 --- a/alacritty/src/display/mod.rs +++ b/alacritty/src/display/mod.rs @@ -249,7 +249,7 @@ impl Display { debug!("Estimated cell size: {} x {}", cell_width, cell_height); // Spawn the Alacritty window. - let mut window = Window::new( + let window = Window::new( event_loop, config, identity, diff --git a/alacritty/src/display/window.rs b/alacritty/src/display/window.rs index 222e52b0..2d473999 100644 --- a/alacritty/src/display/window.rs +++ b/alacritty/src/display/window.rs @@ -235,7 +235,7 @@ impl Window { } #[inline] - pub fn set_inner_size(&mut self, size: PhysicalSize) { + pub fn set_inner_size(&self, size: PhysicalSize) { self.window().set_inner_size(size); } @@ -379,7 +379,6 @@ impl Window { self.window().id() } - #[cfg(not(any(target_os = "macos", windows)))] pub fn set_maximized(&self, maximized: bool) { self.window().set_maximized(maximized); } @@ -389,16 +388,21 @@ impl Window { } /// Toggle the window's fullscreen state. - pub fn toggle_fullscreen(&mut self) { + pub fn toggle_fullscreen(&self) { self.set_fullscreen(self.window().fullscreen().is_none()); } + /// Toggle the window's maximized state. + pub fn toggle_maximized(&self) { + self.set_maximized(!self.window().is_maximized()); + } + #[cfg(target_os = "macos")] - pub fn toggle_simple_fullscreen(&mut self) { + pub fn toggle_simple_fullscreen(&self) { self.set_simple_fullscreen(!self.window().simple_fullscreen()); } - pub fn set_fullscreen(&mut self, fullscreen: bool) { + pub fn set_fullscreen(&self, fullscreen: bool) { if fullscreen { self.window().set_fullscreen(Some(Fullscreen::Borderless(None))); } else { @@ -407,7 +411,7 @@ impl Window { } #[cfg(target_os = "macos")] - pub fn set_simple_fullscreen(&mut self, simple_fullscreen: bool) { + pub fn set_simple_fullscreen(&self, simple_fullscreen: bool) { self.window().set_simple_fullscreen(simple_fullscreen); } @@ -417,7 +421,7 @@ impl Window { } /// Adjust the IME editor position according to the new location of the cursor. - pub fn update_ime_position(&mut self, point: Point, size: &SizeInfo) { + pub fn update_ime_position(&self, point: Point, size: &SizeInfo) { let nspot_x = f64::from(size.padding_x() + point.column.0 as f32 * size.cell_width()); let nspot_y = f64::from(size.padding_y() + (point.line.0 + 1) as f32 * size.cell_height()); diff --git a/alacritty/src/input.rs b/alacritty/src/input.rs index f1b4a138..8572e1ab 100644 --- a/alacritty/src/input.rs +++ b/alacritty/src/input.rs @@ -259,6 +259,7 @@ impl Execute for Action { ctx.paste(&text); }, Action::ToggleFullscreen => ctx.window().toggle_fullscreen(), + Action::ToggleMaximized => ctx.window().toggle_maximized(), #[cfg(target_os = "macos")] Action::ToggleSimpleFullscreen => ctx.window().toggle_simple_fullscreen(), #[cfg(target_os = "macos")]