shell: Allow triggering zoom
This commit is contained in:
parent
2e2943d99c
commit
c01de20b2b
3 changed files with 40 additions and 0 deletions
|
|
@ -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 => (),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1966,6 +1966,24 @@ impl Shell {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn trigger_zoom(
|
||||
&mut self,
|
||||
seat: &Seat<State>,
|
||||
focal_point: Point<f64, Global>,
|
||||
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<State>, Point<f64, Global>, f64)> {
|
||||
self.zoom_state.as_ref().map(|s| s.level())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue