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,
new_level,
self.common.config.cosmic_conf.accessibility_zoom.view_moves,
true,
);
if new_level > 1.

View file

@ -835,37 +835,82 @@ impl State {
if let Some(seat) = maybe_seat {
self.common.idle_notifier_state.notify_activity(&seat);
let mut frame = AxisFrame::new(event.time_msec()).source(event.source());
if let Some(horizontal_amount) = event.amount(Axis::Horizontal) {
if horizontal_amount != 0.0 {
frame =
frame.value(Axis::Horizontal, scroll_factor * horizontal_amount);
if let Some(discrete) = event.amount_v120(Axis::Horizontal) {
frame = frame.v120(
Axis::Horizontal,
(discrete * scroll_factor).round() as i32,
);
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;
}
} else if event.source() == AxisSource::Finger {
frame = frame.stop(Axis::Horizontal);
}
}
if let Some(vertical_amount) = event.amount(Axis::Vertical) {
if vertical_amount != 0.0 {
frame = frame.value(Axis::Vertical, scroll_factor * vertical_amount);
if let Some(discrete) = event.amount_v120(Axis::Vertical) {
frame = frame.v120(
Axis::Vertical,
(discrete * scroll_factor).round() as i32,
);
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 if event.source() == AxisSource::Finger {
frame = frame.stop(Axis::Vertical);
}
} else {
let mut frame = AxisFrame::new(event.time_msec()).source(event.source());
if let Some(horizontal_amount) = event.amount(Axis::Horizontal) {
if horizontal_amount != 0.0 {
frame = frame
.value(Axis::Horizontal, scroll_factor * horizontal_amount);
if let Some(discrete) = event.amount_v120(Axis::Horizontal) {
frame = frame.v120(
Axis::Horizontal,
(discrete * scroll_factor).round() as i32,
);
}
} else if event.source() == AxisSource::Finger {
frame = frame.stop(Axis::Horizontal);
}
}
if let Some(vertical_amount) = event.amount(Axis::Vertical) {
if vertical_amount != 0.0 {
frame =
frame.value(Axis::Vertical, scroll_factor * vertical_amount);
if let Some(discrete) = event.amount_v120(Axis::Vertical) {
frame = frame.v120(
Axis::Vertical,
(discrete * scroll_factor).round() as i32,
);
}
} else if event.source() == AxisSource::Finger {
frame = frame.stop(Axis::Vertical);
}
}
let ptr = seat.get_pointer().unwrap();
ptr.axis(self, frame);
ptr.frame(self);
}
let ptr = seat.get_pointer().unwrap();
ptr.axis(self, frame);
ptr.frame(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. {
return;
}
@ -2099,7 +2105,7 @@ impl Shell {
seat: seat.clone(),
level,
movement,
previous_level: Some((previous_level, Instant::now())),
previous_level: animate.then_some((previous_level, Instant::now())),
});
}