Merge pull request #155 from pop-os/scroll-factor_jammy
input: Add a `scroll_factor` config option
This commit is contained in:
commit
1392fc7c95
4 changed files with 39 additions and 6 deletions
|
|
@ -42,6 +42,7 @@ pub struct ScrollConfig {
|
||||||
pub method: Option<ScrollMethod>,
|
pub method: Option<ScrollMethod>,
|
||||||
pub natural_scroll: Option<bool>,
|
pub natural_scroll: Option<bool>,
|
||||||
pub scroll_button: Option<u32>,
|
pub scroll_button: Option<u32>,
|
||||||
|
pub scroll_factor: Option<f64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ pub fn for_device(device: &InputDevice) -> InputConfig {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
|
scroll_factor: None,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
@ -83,7 +84,7 @@ pub fn for_device(device: &InputDevice) -> InputConfig {
|
||||||
|
|
||||||
// Get setting from `device_config` if present, then `default_config`
|
// Get setting from `device_config` if present, then `default_config`
|
||||||
// Returns `is_default` to indicate this is a default value.
|
// 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>,
|
device_config: Option<&'a InputConfig>,
|
||||||
default_config: &'a InputConfig,
|
default_config: &'a InputConfig,
|
||||||
f: F,
|
f: F,
|
||||||
|
|
|
||||||
|
|
@ -412,13 +412,26 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_device(&self, device: &mut InputDevice) {
|
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 {
|
let default_config = if device.config_tap_finger_count() > 0 {
|
||||||
&self.input_touchpad
|
&self.input_touchpad
|
||||||
} else {
|
} else {
|
||||||
&self.input_default
|
&self.input_default
|
||||||
};
|
};
|
||||||
let device_config = self.input_devices.get(device.name());
|
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 calloop::{timer::Timer, RegistrationToken};
|
||||||
use cosmic_protocols::screencopy::v1::server::zcosmic_screencopy_session_v1::InputType;
|
use cosmic_protocols::screencopy::v1::server::zcosmic_screencopy_session_v1::InputType;
|
||||||
|
#[allow(deprecated)]
|
||||||
use smithay::{
|
use smithay::{
|
||||||
backend::input::{
|
backend::input::{
|
||||||
Axis, AxisSource, Device, DeviceCapability, InputBackend, InputEvent, KeyState,
|
Axis, AxisSource, Device, DeviceCapability, InputBackend, InputEvent, KeyState,
|
||||||
|
|
@ -27,7 +28,10 @@ use smithay::{
|
||||||
Seat, SeatState,
|
Seat, SeatState,
|
||||||
},
|
},
|
||||||
output::Output,
|
output::Output,
|
||||||
reexports::wayland_server::DisplayHandle,
|
reexports::{
|
||||||
|
input::event::pointer::PointerAxisEvent as LibinputPointerAxisEvent,
|
||||||
|
wayland_server::DisplayHandle,
|
||||||
|
},
|
||||||
utils::{Logical, Point, Rectangle, Serial, SERIAL_COUNTER},
|
utils::{Logical, Point, Rectangle, Serial, SERIAL_COUNTER},
|
||||||
wayland::{
|
wayland::{
|
||||||
keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitorSeat, seat::WaylandFocus,
|
keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitorSeat, seat::WaylandFocus,
|
||||||
|
|
@ -40,6 +44,7 @@ use tracing::info;
|
||||||
use tracing::{error, trace, warn};
|
use tracing::{error, trace, warn};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
any::Any,
|
||||||
cell::RefCell,
|
cell::RefCell,
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
|
|
@ -171,7 +176,9 @@ impl State {
|
||||||
&mut self,
|
&mut self,
|
||||||
event: InputEvent<B>,
|
event: InputEvent<B>,
|
||||||
needs_key_repetition: bool,
|
needs_key_repetition: bool,
|
||||||
) {
|
) where
|
||||||
|
<B as InputBackend>::PointerAxisEvent: 'static,
|
||||||
|
{
|
||||||
use smithay::backend::input::Event;
|
use smithay::backend::input::Event;
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
|
|
@ -737,6 +744,15 @@ impl State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
InputEvent::PointerAxis { event, .. } => {
|
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();
|
let device = event.device();
|
||||||
for seat in self.common.seats().cloned().collect::<Vec<_>>().iter() {
|
for seat in self.common.seats().cloned().collect::<Vec<_>>().iter() {
|
||||||
#[cfg(feature = "debug")]
|
#[cfg(feature = "debug")]
|
||||||
|
|
@ -775,7 +791,8 @@ impl State {
|
||||||
let mut frame =
|
let mut frame =
|
||||||
AxisFrame::new(event.time_msec()).source(event.source());
|
AxisFrame::new(event.time_msec()).source(event.source());
|
||||||
if horizontal_amount != 0.0 {
|
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 {
|
if let Some(discrete) = horizontal_amount_discrete {
|
||||||
frame = frame.discrete(Axis::Horizontal, discrete as i32);
|
frame = frame.discrete(Axis::Horizontal, discrete as i32);
|
||||||
}
|
}
|
||||||
|
|
@ -783,7 +800,8 @@ impl State {
|
||||||
frame = frame.stop(Axis::Horizontal);
|
frame = frame.stop(Axis::Horizontal);
|
||||||
}
|
}
|
||||||
if vertical_amount != 0.0 {
|
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 {
|
if let Some(discrete) = vertical_amount_discrete {
|
||||||
frame = frame.discrete(Axis::Vertical, discrete as i32);
|
frame = frame.discrete(Axis::Vertical, discrete as i32);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue