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:
parent
511ee8d87a
commit
20159a6c8c
4 changed files with 39 additions and 6 deletions
|
|
@ -42,6 +42,7 @@ pub struct ScrollConfig {
|
|||
pub method: Option<ScrollMethod>,
|
||||
pub natural_scroll: Option<bool>,
|
||||
pub scroll_button: Option<u32>,
|
||||
pub scroll_factor: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ pub fn for_device(device: &InputDevice) -> InputConfig {
|
|||
} else {
|
||||
None
|
||||
},
|
||||
scroll_factor: None,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
|
@ -83,7 +84,7 @@ pub fn for_device(device: &InputDevice) -> InputConfig {
|
|||
|
||||
// Get setting from `device_config` if present, then `default_config`
|
||||
// Returns `is_default` to indicate this is a default value.
|
||||
fn get_config<'a, T: 'a, F: Fn(&'a InputConfig) -> Option<T>>(
|
||||
pub fn get_config<'a, T: 'a, F: Fn(&'a InputConfig) -> Option<T>>(
|
||||
device_config: Option<&'a InputConfig>,
|
||||
default_config: &'a InputConfig,
|
||||
f: F,
|
||||
|
|
|
|||
|
|
@ -412,13 +412,26 @@ impl Config {
|
|||
}
|
||||
|
||||
pub fn read_device(&self, device: &mut InputDevice) {
|
||||
let (device_config, default_config) = self.get_device_config(device);
|
||||
input_config::update_device(device, device_config, default_config);
|
||||
}
|
||||
|
||||
pub fn scroll_factor(&self, device: &InputDevice) -> f64 {
|
||||
let (device_config, default_config) = self.get_device_config(device);
|
||||
input_config::get_config(device_config, default_config, |x| {
|
||||
x.scroll_config.as_ref()?.scroll_factor
|
||||
})
|
||||
.map_or(1.0, |x| x.0)
|
||||
}
|
||||
|
||||
fn get_device_config(&self, device: &InputDevice) -> (Option<&InputConfig>, &InputConfig) {
|
||||
let default_config = if device.config_tap_finger_count() > 0 {
|
||||
&self.input_touchpad
|
||||
} else {
|
||||
&self.input_default
|
||||
};
|
||||
let device_config = self.input_devices.get(device.name());
|
||||
input_config::update_device(device, device_config, default_config);
|
||||
(device_config, default_config)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue