From c01de20b2b48036d97ed434f7f5481b5461594c5 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Thu, 23 Jan 2025 15:45:19 +0100 Subject: [PATCH] shell: Allow triggering zoom --- data/keybindings.ron | 3 +++ src/input/actions.rs | 19 +++++++++++++++++++ src/shell/mod.rs | 18 ++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/data/keybindings.ron b/data/keybindings.ron index c5cefd38..4d28914f 100644 --- a/data/keybindings.ron +++ b/data/keybindings.ron @@ -70,6 +70,9 @@ (modifiers: [Super], key: "r"): Resizing(Outwards), (modifiers: [Super, Shift], key: "r"): Resizing(Inwards), + (modifiers: [Super], key: "equal"): ZoomIn, + (modifiers: [Super], key: "minus"): ZoomOut, + (modifiers: [Super], key: "b"): System(WebBrowser), (modifiers: [Super], key: "f"): System(HomeFolder), (modifiers: [Super], key: "t"): System(Terminal), diff --git a/src/input/actions.rs b/src/input/actions.rs index fa819f93..3306e44e 100644 --- a/src/input/actions.rs +++ b/src/input/actions.rs @@ -1026,6 +1026,25 @@ impl State { Action::Spawn(command) => self.spawn_command(command), + x @ Action::ZoomIn | x @ Action::ZoomOut => { + let mut shell = self.common.shell.write().unwrap(); + let pointer_loc = seat.get_pointer().unwrap().current_location().as_global(); + let (zoom_seat, _, current_level) = shell + .zoom_level() + .unwrap_or_else(|| (seat.clone(), pointer_loc, 1.0)); + if &zoom_seat == seat { + shell.trigger_zoom( + seat, + pointer_loc, + match x { + Action::ZoomIn => current_level + 1.0, + Action::ZoomOut => (current_level - 1.0).max(1.0), + _ => unreachable!(), + }, + ); + } + } + // Do nothing Action::Disable => (), } diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 71ec2f64..30f6d8c6 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -1966,6 +1966,24 @@ impl Shell { } } + pub fn trigger_zoom( + &mut self, + seat: &Seat, + focal_point: Point, + level: f64, + ) { + if level == 1. { + self.zoom_state.take(); + } else { + self.zoom_state = Some(ZoomState { + seat: seat.clone(), + level, + focal_point, + previous: None, + }); + } + } + pub fn zoom_level(&self) -> Option<(Seat, Point, f64)> { self.zoom_state.as_ref().map(|s| s.level()) }