input: Zoom on Super+Scroll

This commit is contained in:
Victoria Brekenfeld 2025-02-05 18:05:08 +01:00 committed by Victoria Brekenfeld
parent 58f96e6f4a
commit b7d4a66c22
3 changed files with 81 additions and 29 deletions

View file

@ -1053,6 +1053,7 @@ impl State {
seat, seat,
new_level, new_level,
self.common.config.cosmic_conf.accessibility_zoom.view_moves, self.common.config.cosmic_conf.accessibility_zoom.view_moves,
true,
); );
if new_level > 1. if new_level > 1.

View file

@ -835,11 +835,54 @@ impl State {
if let Some(seat) = maybe_seat { if let Some(seat) = maybe_seat {
self.common.idle_notifier_state.notify_activity(&seat); self.common.idle_notifier_state.notify_activity(&seat);
if seat.get_keyboard().unwrap().modifier_state().logo {
if let Some(mut percentage) = event
.amount_v120(Axis::Vertical)
.map(|val| val / 120.)
.or_else(|| event.amount(Axis::Vertical))
.map(|val| val * scroll_factor)
{
let mut shell = self.common.shell.write().unwrap();
let (zoom_seat, current_level) = shell
.zoom_level(None)
.map(|(s, _, l)| (s, l))
.unwrap_or_else(|| (seat.clone(), 1.0));
if current_level == 1. && percentage.is_sign_positive() {
return;
}
if event.source() == AxisSource::Wheel {
percentage *= 5.;
}
let new_level = (current_level - percentage as f64 / 100.).max(1.0);
if zoom_seat == seat {
shell.trigger_zoom(
&seat,
new_level,
self.common.config.cosmic_conf.accessibility_zoom.view_moves,
event.source() == AxisSource::Wheel,
);
if new_level > 1.
&& self
.common
.config
.cosmic_conf
.accessibility_zoom
.start_on_login
{
self.common.config.dynamic_conf.zoom_state_mut().last_level =
new_level;
}
}
}
} else {
let mut frame = AxisFrame::new(event.time_msec()).source(event.source()); let mut frame = AxisFrame::new(event.time_msec()).source(event.source());
if let Some(horizontal_amount) = event.amount(Axis::Horizontal) { if let Some(horizontal_amount) = event.amount(Axis::Horizontal) {
if horizontal_amount != 0.0 { if horizontal_amount != 0.0 {
frame = frame = frame
frame.value(Axis::Horizontal, scroll_factor * horizontal_amount); .value(Axis::Horizontal, scroll_factor * horizontal_amount);
if let Some(discrete) = event.amount_v120(Axis::Horizontal) { if let Some(discrete) = event.amount_v120(Axis::Horizontal) {
frame = frame.v120( frame = frame.v120(
Axis::Horizontal, Axis::Horizontal,
@ -852,7 +895,8 @@ impl State {
} }
if let Some(vertical_amount) = event.amount(Axis::Vertical) { if let Some(vertical_amount) = event.amount(Axis::Vertical) {
if vertical_amount != 0.0 { if vertical_amount != 0.0 {
frame = frame.value(Axis::Vertical, scroll_factor * vertical_amount); frame =
frame.value(Axis::Vertical, scroll_factor * vertical_amount);
if let Some(discrete) = event.amount_v120(Axis::Vertical) { if let Some(discrete) = event.amount_v120(Axis::Vertical) {
frame = frame.v120( frame = frame.v120(
Axis::Vertical, Axis::Vertical,
@ -868,6 +912,7 @@ impl State {
ptr.frame(self); ptr.frame(self);
} }
} }
}
InputEvent::GestureSwipeBegin { event, .. } => { InputEvent::GestureSwipeBegin { event, .. } => {
let maybe_seat = self let maybe_seat = self

View file

@ -2074,7 +2074,13 @@ impl Shell {
} }
} }
pub fn trigger_zoom(&mut self, seat: &Seat<State>, level: f64, movement: ZoomMovement) { pub fn trigger_zoom(
&mut self,
seat: &Seat<State>,
level: f64,
movement: ZoomMovement,
animate: bool,
) {
if self.zoom_state.is_none() && level == 1. { if self.zoom_state.is_none() && level == 1. {
return; return;
} }
@ -2099,7 +2105,7 @@ impl Shell {
seat: seat.clone(), seat: seat.clone(),
level, level,
movement, movement,
previous_level: Some((previous_level, Instant::now())), previous_level: animate.then_some((previous_level, Instant::now())),
}); });
} }