Skip to content

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

fix(wayland): scale portal pointer coordinates on niri (#15683)

Fadouse3cf32e706660
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<SyncConnection>,
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