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

* fix(wayland): scale portal pointer coordinates on niri

* perf(wayland): cache portal scaling desktop check
This commit is contained in:
Fadouse
2026-08-04 14:18:41 +08:00
committed by GitHub
parent 6f1eb164d6
commit 3cf32e7066
+28 -2
View File
@@ -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