From 3cf32e70666006e0273938bf64c6e6e67d3bb82f Mon Sep 17 00:00:00 2001 From: Fadouse Date: Tue, 4 Aug 2026 14:18:41 +0800 Subject: [PATCH] fix(wayland): scale portal pointer coordinates on niri (#15683) * fix(wayland): scale portal pointer coordinates on niri * perf(wayland): cache portal scaling desktop check --- src/server/rdp_input.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/server/rdp_input.rs b/src/server/rdp_input.rs index 81189159d..546f946c0 100644 --- a/src/server/rdp_input.rs +++ b/src/server/rdp_input.rs @@ -9,7 +9,7 @@ use std::collections::HashMap; use std::sync::Arc; pub mod client { - use hbb_common::platform::linux::is_kde; + use hbb_common::platform::linux::{DISPLAY_DESKTOP_KDE, XDG_CURRENT_DESKTOP}; use super::*; @@ -302,6 +302,19 @@ pub mod client { } } + fn desktop_is_niri(desktop: &str) -> bool { + desktop + .split(':') + .any(|name| name.eq_ignore_ascii_case("niri")) + } + + lazy_static::lazy_static! { + static ref SHOULD_SCALE_POINTER_COORDINATES: bool = + std::env::var(XDG_CURRENT_DESKTOP) + .map(|desktop| desktop == DISPLAY_DESKTOP_KDE || desktop_is_niri(&desktop)) + .unwrap_or(false); + } + pub struct RdpInputMouse { conn: Arc, session: Path<'static>, @@ -327,7 +340,7 @@ pub mod client { // For Ubuntu 24.04(Gnome 46), (x,y) is restricted from (0,0) to (400,300), but the actual range in screen is: // Logic coordinate from (0,0) to (200x150). // Or physical coordinate from (0,0) to (400,300). - let scale = if is_kde() { + let scale = if *SHOULD_SCALE_POINTER_COORDINATES { if resolution.0 == 0 || stream.get_size().0 == 0 { Some(1.0f64) } else { @@ -348,6 +361,19 @@ pub mod client { } } + #[cfg(test)] + mod tests { + use super::desktop_is_niri; + + #[test] + fn detects_niri_in_desktop_list() { + assert!(desktop_is_niri("niri")); + assert!(desktop_is_niri("NIRI")); + assert!(desktop_is_niri("GNOME:niri")); + assert!(!desktop_is_niri("GNOME")); + } + } + impl MouseControllable for RdpInputMouse { fn as_any(&self) -> &dyn std::any::Any { self