forge
Explore
Log in

Don't you dare go Hollow

Rename WheelTracker to ScrollTracker

Browse files at this commit

6ba195211bf60c3b753e4167b047b055dd5c129dIvan MolodetskikhParent: afaaf36
src/lib.rsmodified+1 -1
@@ -16,10 +16,10 @@ pub mod niri;
1616 pub mod protocols;
1717 pub mod render_helpers;
1818 pub mod rubber_band;
19+pub mod scroll_tracker;
1920 pub mod swipe_tracker;
2021 pub mod ui;
2122 pub mod utils;
22-pub mod wheel_tracker;
2323 pub mod window;
2424
2525 #[cfg(not(feature = "xdp-gnome-screencast"))]
src/niri.rsmodified+5 -5
@@ -106,6 +106,7 @@ use crate::protocols::screencopy::{Screencopy, ScreencopyManagerState};
106106 use crate::pw_utils::{Cast, PipeWire};
107107 use crate::render_helpers::renderer::NiriRenderer;
108108 use crate::render_helpers::{render_to_shm, render_to_texture, render_to_vec};
109+use crate::scroll_tracker::ScrollTracker;
109110 use crate::ui::config_error_notification::ConfigErrorNotification;
110111 use crate::ui::exit_confirm_dialog::ExitConfirmDialog;
111112 use crate::ui::hotkey_overlay::HotkeyOverlay;
@@ -114,7 +115,6 @@ use crate::utils::spawning::CHILD_ENV;
114115 use crate::utils::{
115116 center, center_f64, get_monotonic_time, make_screenshot_path, output_size, write_png_rgba8,
116117 };
117-use crate::wheel_tracker::WheelTracker;
118118 use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped, WindowRef};
119119 use crate::{animation, niri_render_elements};
120120
@@ -206,8 +206,8 @@ pub struct Niri {
206206 pub pointer_focus: PointerFocus,
207207 pub tablet_cursor_location: Option<Point<f64, Logical>>,
208208 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,
211211 pub mods_with_wheel_binds: HashSet<Modifiers>,
212212
213213 pub lock_state: LockState,
@@ -1321,8 +1321,8 @@ impl Niri {
13211321 pointer_focus: PointerFocus::default(),
13221322 tablet_cursor_location: None,
13231323 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),
13261326 mods_with_wheel_binds,
13271327
13281328 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-}