Rename WheelTracker to ScrollTracker
Browse files at this commit6ba195211bf60c3b753e4167b047b055dd5c129dParent: afaaf364 changed files +46 -42
- src/lib.rs +1 -1
- src/niri.rs +5 -5
- src/scroll_tracker.rs +40 -0
- src/wheel_tracker.rs +0 -36
src/lib.rsmodified+1 -1
| @@ -16,10 +16,10 @@ pub mod niri; | ||
| 16 | 16 | pub mod protocols; |
| 17 | 17 | pub mod render_helpers; |
| 18 | 18 | pub mod rubber_band; |
| 19 | +pub mod scroll_tracker; | |
| 19 | 20 | pub mod swipe_tracker; |
| 20 | 21 | pub mod ui; |
| 21 | 22 | pub mod utils; |
| 22 | -pub mod wheel_tracker; | |
| 23 | 23 | pub mod window; |
| 24 | 24 | |
| 25 | 25 | #[cfg(not(feature = "xdp-gnome-screencast"))] |
src/niri.rsmodified+5 -5
| @@ -106,6 +106,7 @@ use crate::protocols::screencopy::{Screencopy, ScreencopyManagerState}; | ||
| 106 | 106 | use crate::pw_utils::{Cast, PipeWire}; |
| 107 | 107 | use crate::render_helpers::renderer::NiriRenderer; |
| 108 | 108 | use crate::render_helpers::{render_to_shm, render_to_texture, render_to_vec}; |
| 109 | +use crate::scroll_tracker::ScrollTracker; | |
| 109 | 110 | use crate::ui::config_error_notification::ConfigErrorNotification; |
| 110 | 111 | use crate::ui::exit_confirm_dialog::ExitConfirmDialog; |
| 111 | 112 | use crate::ui::hotkey_overlay::HotkeyOverlay; |
| @@ -114,7 +115,6 @@ use crate::utils::spawning::CHILD_ENV; | ||
| 114 | 115 | use crate::utils::{ |
| 115 | 116 | center, center_f64, get_monotonic_time, make_screenshot_path, output_size, write_png_rgba8, |
| 116 | 117 | }; |
| 117 | -use crate::wheel_tracker::WheelTracker; | |
| 118 | 118 | use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped, WindowRef}; |
| 119 | 119 | use crate::{animation, niri_render_elements}; |
| 120 | 120 | |
| @@ -206,8 +206,8 @@ pub struct Niri { | ||
| 206 | 206 | pub pointer_focus: PointerFocus, |
| 207 | 207 | pub tablet_cursor_location: Option<Point<f64, Logical>>, |
| 208 | 208 | pub gesture_swipe_3f_cumulative: Option<(f64, f64)>, |
| 209 | - pub vertical_wheel_tracker: WheelTracker, | |
| 210 | - pub horizontal_wheel_tracker: WheelTracker, | |
| 209 | + pub vertical_wheel_tracker: ScrollTracker, | |
| 210 | + pub horizontal_wheel_tracker: ScrollTracker, | |
| 211 | 211 | pub mods_with_wheel_binds: HashSet<Modifiers>, |
| 212 | 212 | |
| 213 | 213 | pub lock_state: LockState, |
| @@ -1321,8 +1321,8 @@ impl Niri { | ||
| 1321 | 1321 | pointer_focus: PointerFocus::default(), |
| 1322 | 1322 | tablet_cursor_location: None, |
| 1323 | 1323 | gesture_swipe_3f_cumulative: None, |
| 1324 | - vertical_wheel_tracker: WheelTracker::new(), | |
| 1325 | - horizontal_wheel_tracker: WheelTracker::new(), | |
| 1324 | + vertical_wheel_tracker: ScrollTracker::new(120), | |
| 1325 | + horizontal_wheel_tracker: ScrollTracker::new(120), | |
| 1326 | 1326 | mods_with_wheel_binds, |
| 1327 | 1327 | |
| 1328 | 1328 | lock_state: LockState::Unlocked, |
src/scroll_tracker.rsadded+40 -0
| @@ -0,0 +1,40 @@ | ||
| 1 | +pub struct ScrollTracker { | |
| 2 | + tick: f64, | |
| 3 | + last: f64, | |
| 4 | + acc: f64, | |
| 5 | +} | |
| 6 | + | |
| 7 | +impl ScrollTracker { | |
| 8 | + #[allow(clippy::new_without_default)] | |
| 9 | + pub fn new(tick: i8) -> Self { | |
| 10 | + Self { | |
| 11 | + tick: f64::from(tick), | |
| 12 | + last: 0., | |
| 13 | + acc: 0., | |
| 14 | + } | |
| 15 | + } | |
| 16 | + | |
| 17 | + pub fn accumulate(&mut self, amount: f64) -> i8 { | |
| 18 | + let changed_direction = (self.last > 0. && amount < 0.) || (self.last < 0. && amount > 0.); | |
| 19 | + if changed_direction { | |
| 20 | + self.acc = 0. | |
| 21 | + } | |
| 22 | + | |
| 23 | + self.last = amount; | |
| 24 | + self.acc += amount; | |
| 25 | + | |
| 26 | + let mut ticks = 0; | |
| 27 | + if self.acc.abs() >= self.tick { | |
| 28 | + let clamped = self.acc.clamp(-127. * self.tick, 127. * self.tick); | |
| 29 | + ticks = (clamped as i16 / self.tick as i16) as i8; | |
| 30 | + self.acc %= self.tick; | |
| 31 | + } | |
| 32 | + | |
| 33 | + ticks | |
| 34 | + } | |
| 35 | + | |
| 36 | + pub fn reset(&mut self) { | |
| 37 | + self.last = 0.; | |
| 38 | + self.acc = 0.; | |
| 39 | + } | |
| 40 | +} |
src/wheel_tracker.rsdeleted+0 -36
| @@ -1,36 +0,0 @@ | ||
| 1 | -pub struct WheelTracker { | |
| 2 | - last: f64, | |
| 3 | - acc: f64, | |
| 4 | -} | |
| 5 | - | |
| 6 | -impl WheelTracker { | |
| 7 | - #[allow(clippy::new_without_default)] | |
| 8 | - pub fn new() -> Self { | |
| 9 | - Self { last: 0., acc: 0. } | |
| 10 | - } | |
| 11 | - | |
| 12 | - pub fn accumulate(&mut self, amount_v120: f64) -> i8 { | |
| 13 | - let changed_direction = | |
| 14 | - (self.last > 0. && amount_v120 < 0.) || (self.last < 0. && amount_v120 > 0.); | |
| 15 | - if changed_direction { | |
| 16 | - self.acc = 0. | |
| 17 | - } | |
| 18 | - | |
| 19 | - self.last = amount_v120; | |
| 20 | - self.acc += amount_v120; | |
| 21 | - | |
| 22 | - let mut ticks = 0; | |
| 23 | - if self.acc.abs() >= 120. { | |
| 24 | - let clamped = self.acc.clamp(-127. * 120., 127. * 120.); | |
| 25 | - ticks = (clamped as i16 / 120) as i8; | |
| 26 | - self.acc %= 120.; | |
| 27 | - } | |
| 28 | - | |
| 29 | - ticks | |
| 30 | - } | |
| 31 | - | |
| 32 | - pub fn reset(&mut self) { | |
| 33 | - self.last = 0.; | |
| 34 | - self.acc = 0.; | |
| 35 | - } | |
| 36 | -} |