Skip to content

Lightweight native Discord client for Windows, Linux and macOS, written in Rust. No Electron, no browser engine.

Scroll as far per wheel notch as Discord (#51)

VRonGitHub7a36e1ae7b01
diff --git a/apps/rustcord/src/app.rs b/apps/rustcord/src/app.rs
index 335cf1e..d3eecbb 100644
--- a/apps/rustcord/src/app.rs
+++ b/apps/rustcord/src/app.rs
@@ -550,6 +550,7 @@ impl RustCord {
crate::video::install(&cc.egui_ctx);
crate::emoji::install_text_emoji(&cc.egui_ctx);
style::install_fonts(&cc.egui_ctx);
+ style::use_system_scroll_speed(&cc.egui_ctx);
crate::spellcheck::install(&cc.egui_ctx);
let config_dir = directories::ProjectDirs::from("dev", "RustCord", "RustCord")
diff --git a/apps/rustcord/src/style.rs b/apps/rustcord/src/style.rs
index 3b76809..555803b 100644
--- a/apps/rustcord/src/style.rs
+++ b/apps/rustcord/src/style.rs
@@ -811,6 +811,42 @@ fn system_text_antialiasing() -> u8 {
0
}
+/// Scroll as far per mouse-wheel notch as Chromium, and so Discord, does.
+/// egui's own 40 points felt stiff next to it (#51).
+pub fn use_system_scroll_speed(ctx: &egui::Context) {
+ let per_notch = wheel_points_per_notch();
+ log::info!("scrolling: {per_notch:.0} px per wheel notch");
+ ctx.options_mut(|o| o.line_scroll_speed = per_notch);
+}
+
+/// Windows: the "lines to scroll" mouse setting × 100/3 px (100 px with the
+/// default 3 lines), as Chromium's wheel events count it.
+#[cfg(windows)]
+fn wheel_points_per_notch() -> f32 {
+ use windows_sys::Win32::UI::WindowsAndMessaging::{SystemParametersInfoW, SPI_GETWHEELSCROLLLINES};
+ // "One screen at a time" (WHEEL_PAGESCROLL, UINT_MAX): the default is used then.
+ const WHEEL_PAGESCROLL: u32 = u32::MAX;
+ let mut lines: u32 = 0;
+ // SAFETY: SPI_GETWHEELSCROLLLINES writes one 32-bit value to the pointer.
+ let ok = unsafe { SystemParametersInfoW(SPI_GETWHEELSCROLLLINES, 0, (&mut lines as *mut u32).cast(), 0) };
+ if ok == 0 || lines == 0 || lines == WHEEL_PAGESCROLL {
+ lines = 3;
+ }
+ lines.min(100) as f32 * 100.0 / 3.0
+}
+
+/// Linux: Chromium's fixed 53 px per notch (touchpads send exact distances).
+#[cfg(all(unix, not(target_os = "macos")))]
+fn wheel_points_per_notch() -> f32 {
+ 53.0
+}
+
+/// macOS: Chromium's 40 px per notch of a mouse without precise scrolling.
+#[cfg(target_os = "macos")]
+fn wheel_points_per_notch() -> f32 {
+ 40.0
+}
+
/// Prefer the system UI font where available, and add symbol/emoji
/// fallbacks so more of Discord's text renders.
pub fn install_fonts(ctx: &egui::Context) {
diff --git a/apps/rustcord/src/ui/popups.rs b/apps/rustcord/src/ui/popups.rs
index 37c9241..312925f 100644
--- a/apps/rustcord/src/ui/popups.rs
+++ b/apps/rustcord/src/ui/popups.rs
@@ -63,7 +63,9 @@ impl RustCord {
ui.ctx().move_to_top(ui.layer_id());
let wheel = ui.input(|i| i.smooth_scroll_delta.y);
if wheel != 0.0 {
- zoom = (zoom * (wheel * 0.003).exp()).clamp(1.25, 12.0);
+ // About ×1.13 per wheel notch, however far a notch scrolls.
+ let notch = ui.ctx().options(|o| o.line_scroll_speed);
+ zoom = (zoom * (wheel / notch * 0.12).exp()).clamp(1.25, 12.0);
}
let size = fitted * zoom;
let at = ui.input(|i| i.pointer.hover_pos()).unwrap_or(screen.center());