diff --git a/Cargo.lock b/Cargo.lock index 89a5205..e7c5497 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2573,7 +2573,7 @@ checksum = "a2efa01ecfd021b1e7db27f21f4e79b35b048081c9cae9d2f898eddc98444d69" dependencies = [ "image", "log", - "memmap2 0.9.2", + "memmap2 0.9.0", "nix 0.27.1", "thiserror", "wayland-client", @@ -2583,12 +2583,12 @@ dependencies = [ [[package]] name = "libwaysip" -version = "0.1.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2eaf11ae22eca2516290fe0cf240f2d6c81778b7c54fa03f3499f34417c42a7" +checksum = "af6744b1173d3b31f38fa3bdd7e718b8b13f21b5a3fd313c7b7952a722a462d1" dependencies = [ "cairo-rs", - "memmap2 0.9.2", + "memmap2 0.9.0", "pango", "pangocairo", "tempfile", @@ -2714,9 +2714,9 @@ dependencies = [ [[package]] name = "memmap2" -version = "0.9.2" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39a69c7c189ae418f83003da62820aca28d15a07725ce51fb924999335d622ff" +checksum = "deaba38d7abf1d4cca21cc89e932e542ba2b9258664d2a9ef0e61512039c9375" dependencies = [ "libc", ] @@ -3806,7 +3806,7 @@ checksum = "1729a30a469de249c6effc17ec8d039b0aa29b3af79b819b7f51cb6ab8046a90" dependencies = [ "ab_glyph", "log", - "memmap2 0.9.2", + "memmap2 0.9.0", "smithay-client-toolkit", "tiny-skia", ] @@ -4038,7 +4038,7 @@ dependencies = [ "cursor-icon", "libc", "log", - "memmap2 0.9.2", + "memmap2 0.9.0", "rustix 0.38.28", "thiserror", "wayland-backend", @@ -4106,7 +4106,7 @@ dependencies = [ "foreign-types", "js-sys", "log", - "memmap2 0.9.2", + "memmap2 0.9.0", "objc", "raw-window-handle 0.5.2", "redox_syscall 0.4.1", @@ -5300,7 +5300,7 @@ dependencies = [ "js-sys", "libc", "log", - "memmap2 0.9.2", + "memmap2 0.9.0", "ndk", "ndk-sys", "objc2 0.4.1", diff --git a/Cargo.toml b/Cargo.toml index ab676f3..2ca6d73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,4 +57,4 @@ toml = "0.8.8" csscolorparser = "0.6.2" notify = "6.1.1" futures = "0.3.29" -libwaysip = "0.1.1" +libwaysip = "0.2.2" diff --git a/src/screencast.rs b/src/screencast.rs index 96a01fd..f6f60e8 100644 --- a/src/screencast.rs +++ b/src/screencast.rs @@ -19,6 +19,8 @@ use crate::session::{ }; use crate::PortalResponse; +use libwaysip::WaySipKind; + #[derive(SerializeDict, DeserializeDict, Type, Debug, Default)] /// Specified options for a [`Screencast::create_session`] request. #[zvariant(signature = "dict")] @@ -188,28 +190,17 @@ impl ScreenCastBackend { } drop(locked_sessions); - // TODO: use slurp now let show_cursor = current_session.cursor_mode.show_cursor(); let connection = libwayshot::WayshotConnection::new().unwrap(); let outputs = connection.get_all_outputs(); - let slurp = std::process::Command::new("slurp") - .arg("-o") - .output() - .map_err(|_| zbus::Error::Failure("Cannot find slurp".to_string()))? - .stdout; - let output = String::from_utf8_lossy(&slurp); - let output = output - .split(' ') - .next() - .ok_or(zbus::Error::Failure("Not get slurp area".to_string()))?; - - let point: Vec<&str> = output.split(',').collect(); - let x: i32 = point[0] - .parse() - .map_err(|_| zbus::Error::Failure("X is not correct".to_string()))?; - let y: i32 = point[1] - .parse() - .map_err(|_| zbus::Error::Failure("Y is not correct".to_string()))?; + + let info = match libwaysip::get_area(WaySipKind::Screen) { + Ok(Some(info)) => info, + Ok(None) => return Err(zbus::Error::Failure("You cancel it".to_string()).into()), + Err(e) => return Err(zbus::Error::Failure(format!("wayland error, {e}")).into()), + }; + + let (x, y) = info.selected_screen_info().get_position(); let Some(output) = outputs .iter() diff --git a/src/screenshot.rs b/src/screenshot.rs index df0cb87..7057723 100644 --- a/src/screenshot.rs +++ b/src/screenshot.rs @@ -8,6 +8,8 @@ use zbus::{dbus_interface, fdo, zvariant::ObjectPath}; use crate::utils::USER_RUNNING_DIR; use crate::PortalResponse; +use libwaysip::WaySipKind; + #[derive(DeserializeDict, SerializeDict, Type)] #[zvariant(signature = "dict")] struct Screenshot { @@ -65,7 +67,7 @@ impl ScreenShotBackend { match screenshotdialog::selectgui(screen_infos) { SlintSelection::Canceled => return Ok(PortalResponse::Cancelled), SlintSelection::Slurp => { - let info = match libwaysip::get_area() { + let info = match libwaysip::get_area(WaySipKind::Area) { Ok(Some(info)) => info, Ok(None) => { return Err(zbus::Error::Failure("You cancel it".to_string()).into()) @@ -75,11 +77,9 @@ impl ScreenShotBackend { } }; - let (x_coordinate_f, y_coordinate_f) = info.left_top_point(); - let (x_coordinate, y_coordinate) = - (x_coordinate_f as i32, y_coordinate_f as i32); - let width = info.width() as i32; - let height = info.height() as i32; + let (x_coordinate, y_coordinate) = info.left_top_point(); + let width = info.width(); + let height = info.height(); wayshot_connection .screenshot( @@ -126,13 +126,12 @@ impl ScreenShotBackend { ) -> fdo::Result> { let wayshot_connection = WayshotConnection::new() .map_err(|_| zbus::Error::Failure("Cannot update outputInfos".to_string()))?; - let info = match libwaysip::get_area() { + let info = match libwaysip::get_area(WaySipKind::Point) { Ok(Some(info)) => info, Ok(None) => return Err(zbus::Error::Failure("You cancel it".to_string()).into()), Err(e) => return Err(zbus::Error::Failure(format!("wayland error, {e}")).into()), }; - let (x_coordinate_f, y_coordinate_f) = info.left_top_point(); - let (x_coordinate, y_coordinate) = (x_coordinate_f as i32, y_coordinate_f as i32); + let (x_coordinate, y_coordinate) = info.left_top_point(); let image = wayshot_connection .screenshot(