input: Add a scroll_factor config option

This is not a setting handled by libinput; we have to scale the
scrolling ourselves.

This should match the behavior of the `scroll_factor` defined in
sway-input(5).
This commit is contained in:
Ian Douglas Scott 2023-09-01 12:33:55 -07:00
parent 511ee8d87a
commit 20159a6c8c
4 changed files with 39 additions and 6 deletions

View file

@ -15,6 +15,7 @@ use crate::{
};
use calloop::{timer::Timer, RegistrationToken};
use cosmic_protocols::screencopy::v1::server::zcosmic_screencopy_session_v1::InputType;
#[allow(deprecated)]
use smithay::{
backend::input::{
Axis, AxisSource, Device, DeviceCapability, InputBackend, InputEvent, KeyState,
@ -27,7 +28,10 @@ use smithay::{
Seat, SeatState,
},
output::Output,
reexports::wayland_server::DisplayHandle,
reexports::{
input::event::pointer::PointerAxisEvent as LibinputPointerAxisEvent,
wayland_server::DisplayHandle,
},
utils::{Logical, Point, Rectangle, Serial, SERIAL_COUNTER},
wayland::{
keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitorSeat, seat::WaylandFocus,
@ -40,6 +44,7 @@ use tracing::info;
use tracing::{error, trace, warn};
use std::{
any::Any,
cell::RefCell,
collections::HashMap,
time::{Duration, Instant},
@ -171,7 +176,9 @@ impl State {
&mut self,
event: InputEvent<B>,
needs_key_repetition: bool,
) {
) where
<B as InputBackend>::PointerAxisEvent: 'static,
{
use smithay::backend::input::Event;
match event {
@ -737,6 +744,15 @@ impl State {
}
}
InputEvent::PointerAxis { event, .. } => {
#[allow(deprecated)]
let scroll_factor = if let Some(event) =
<dyn Any>::downcast_ref::<LibinputPointerAxisEvent>(&event)
{
self.common.config.scroll_factor(&event.device())
} else {
1.0
};
let device = event.device();
for seat in self.common.seats().cloned().collect::<Vec<_>>().iter() {
#[cfg(feature = "debug")]
@ -775,7 +791,8 @@ impl State {
let mut frame =
AxisFrame::new(event.time_msec()).source(event.source());
if horizontal_amount != 0.0 {
frame = frame.value(Axis::Horizontal, horizontal_amount);
frame = frame
.value(Axis::Horizontal, scroll_factor * horizontal_amount);
if let Some(discrete) = horizontal_amount_discrete {
frame = frame.discrete(Axis::Horizontal, discrete as i32);
}
@ -783,7 +800,8 @@ impl State {
frame = frame.stop(Axis::Horizontal);
}
if vertical_amount != 0.0 {
frame = frame.value(Axis::Vertical, vertical_amount);
frame =
frame.value(Axis::Vertical, scroll_factor * vertical_amount);
if let Some(discrete) = vertical_amount_discrete {
frame = frame.discrete(Axis::Vertical, discrete as i32);
}