From bf5f58e0ced6d280289bd82aba4ef4288fd6c95c Mon Sep 17 00:00:00 2001 From: Sahil Yeole Date: Wed, 20 Sep 2023 19:55:13 +0530 Subject: [PATCH] fix wayland cursor mismatch Signed-off-by: Sahil Yeole --- src/server/wayland.rs | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/server/wayland.rs b/src/server/wayland.rs index efed83936..44cf8bf4a 100644 --- a/src/server/wayland.rs +++ b/src/server/wayland.rs @@ -2,6 +2,7 @@ use super::*; use hbb_common::{allow_err, platform::linux::DISTRO}; use scrap::{is_cursor_embedded, set_map_err, Capturer, Display, Frame, TraitCapturer}; use std::io; +use std::process::{Command, Output}; use crate::client::{ SCRAP_OTHER_VERSION_OR_X11_REQUIRED, SCRAP_UBUNTU_HIGHER_REQUIRED, SCRAP_X11_REQUIRED, @@ -115,6 +116,22 @@ pub(super) fn is_inited() -> Option { } } +fn get_max_desktop_resolution() -> Option { + // works with Xwayland + let output: Output = Command::new("sh") + .arg("-c") + .arg("xrandr | awk '/current/ { print $8,$9,$10 }'") + .output() + .ok()?; + + if output.status.success() { + let result = String::from_utf8_lossy(&output.stdout); + Some(result.trim().to_string()) + } else { + None + } +} + pub(super) async fn check_init() -> ResultType<()> { if !scrap::is_x11() { let mut minx = 0; @@ -151,10 +168,20 @@ pub(super) async fn check_init() -> ResultType<()> { num_cpus::get(), ); - minx = origin.0; - maxx = origin.0 + width as i32; - miny = origin.1; - maxy = origin.1 + height as i32; + let (max_width, max_height) = match get_max_desktop_resolution() { + Some(result) if !result.is_empty() => { + let resolution: Vec<&str> = result.split(" ").collect(); + let w: i32 = resolution[0].parse().unwrap_or(origin.0 + width as i32); + let h: i32 = resolution[2].trim_end_matches(",").parse().unwrap_or(origin.1 + height as i32); + (w, h) + } + _ => (origin.0 + width as i32, origin.1 + height as i32) + }; + + minx = 0; + maxx = max_width; + miny = 0; + maxy = max_height; let capturer = Box::into_raw(Box::new( Capturer::new(display, true).with_context(|| "Failed to create capturer")?,