Skip to content

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

fix(linux): keep the cursor visible over blank X11 cursors (#17078)

spaceminga98450a995fc
diff --git a/src/platform/linux.rs b/src/platform/linux.rs
index ab6afe190..02490e4d7 100644
--- a/src/platform/linux.rs
+++ b/src/platform/linux.rs
@@ -712,7 +712,17 @@ pub fn get_cursor() -> ResultType<Option<u64>> {
unsafe {
let img = XFixesGetCursorImage(*d);
if !img.is_null() {
- res = Some((*img).cursor_serial as u64);
+ // Hidden X11 cursors must leave the controller's previous shape visible.
+ let count = (*img).width as usize * (*img).height as usize;
+ if count != 0
+ && !(*img).pixels.is_null()
+ && cursor_image_has_visible_pixels(std::slice::from_raw_parts(
+ (*img).pixels,
+ count,
+ ))
+ {
+ res = Some((*img).cursor_serial as u64);
+ }
XFree(img as _);
}
}
@@ -722,6 +732,26 @@ pub fn get_cursor() -> ResultType<Option<u64>> {
Ok(res)
}
+fn cursor_image_has_visible_pixels(pixels: &[c_long]) -> bool {
+ pixels.iter().any(|&p| ((p >> 24) & 0xff) != 0)
+}
+
+#[cfg(test)]
+mod cursor_image_tests {
+ use super::{c_long, cursor_image_has_visible_pixels};
+
+ #[test]
+ fn only_nonzero_alpha_makes_a_cursor_visible() {
+ assert!(!cursor_image_has_visible_pixels(&[]));
+ assert!(!cursor_image_has_visible_pixels(&[0, 0x00ff_ffff]));
+ assert!(cursor_image_has_visible_pixels(&[0, 0x0100_0000]));
+ let opaque = 0xff00_0000_u32;
+ assert!(cursor_image_has_visible_pixels(&[opaque as c_long]));
+ // 64-bit Xlib sign-extends each 32-bit pixel, so an opaque pixel arrives negative.
+ assert!(cursor_image_has_visible_pixels(&[opaque as i32 as c_long]));
+ }
+}
+
pub fn get_cursor_data(hcursor: u64) -> ResultType<CursorData> {
// DRM/KMS capture: return the latest hardware-cursor snapshot from the `_drm` stream. Its id may
// have advanced past `hcursor` between get_cursor() and here, so return the latest rather than