Skip to content

Commit

Permalink
feat!: adopt slurp and use libwaysip
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Dec 19, 2023
1 parent bc90604 commit 2cd6524
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 39 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
29 changes: 10 additions & 19 deletions src/screencast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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()
Expand Down
17 changes: 8 additions & 9 deletions src/screenshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand All @@ -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(
Expand Down Expand Up @@ -126,13 +126,12 @@ impl ScreenShotBackend {
) -> fdo::Result<PortalResponse<Color>> {
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(
Expand Down

0 comments on commit 2cd6524

Please sign in to comment.