Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

fix(mobile): honor reverse mouse wheel setting (#16337)

HeZheng341193290e2b
diff --git a/src/platform/mobile_wheel.rs b/src/platform/mobile_wheel.rs
new file mode 100644
index 000000000..ac5ffca42
--- /dev/null
+++ b/src/platform/mobile_wheel.rs
@@ -0,0 +1,32 @@
+pub(crate) fn mobile_wheel_delta(xy: (i32, i32), reverse_mouse_wheel: &str) -> (i32, i32) {
+ if reverse_mouse_wheel == "Y" {
+ (xy.0.saturating_neg(), xy.1.saturating_neg())
+ } else {
+ xy
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::mobile_wheel_delta;
+
+ #[test]
+ fn reverses_both_axes_when_enabled() {
+ assert_eq!(mobile_wheel_delta((2, -3), "Y"), (-2, 3));
+ assert_eq!(mobile_wheel_delta((0, 4), "Y"), (0, -4));
+ }
+
+ #[test]
+ fn preserves_both_axes_when_disabled() {
+ assert_eq!(mobile_wheel_delta((2, -3), "N"), (2, -3));
+ assert_eq!(mobile_wheel_delta((2, -3), ""), (2, -3));
+ }
+
+ #[test]
+ fn reversing_minimum_delta_does_not_overflow() {
+ assert_eq!(
+ mobile_wheel_delta((i32::MIN, i32::MIN), "Y"),
+ (i32::MAX, i32::MAX)
+ );
+ }
+}
diff --git a/src/ui_session_interface.rs b/src/ui_session_interface.rs
index 37aa7a67e..2fa0ee6a5 100644
--- a/src/ui_session_interface.rs
+++ b/src/ui_session_interface.rs
@@ -51,6 +51,10 @@ use crate::common::GrabState;
use crate::keyboard;
use crate::{client::Data, client::Interface};
+#[cfg(any(target_os = "android", target_os = "ios", test))]
+#[path = "platform/mobile_wheel.rs"]
+mod mobile_wheel;
+
const CHANGE_RESOLUTION_VALID_TIMEOUT_SECS: u64 = 15;
#[derive(Clone, Default)]
@@ -1234,6 +1238,12 @@ impl<T: InvokeUiSession> Session<T> {
} else {
(x, y)
};
+ #[cfg(any(target_os = "android", target_os = "ios"))]
+ let (x, y) = if event_type == MOUSE_TYPE_WHEEL || event_type == MOUSE_TYPE_TRACKPAD {
+ mobile_wheel::mobile_wheel_delta((x, y), &self.lc.read().unwrap().reverse_mouse_wheel)
+ } else {
+ (x, y)
+ };
// #[cfg(not(any(target_os = "android", target_os = "ios")))]
let (alt, ctrl, shift, command) =