diff --git a/Cargo.lock b/Cargo.lock index 69a9f6f2..7e1b7d49 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -352,6 +352,7 @@ dependencies = [ "log", "memmap2", "nix", + "thiserror", "wayland-client", "wayland-protocols", "wayland-protocols-wlr", @@ -592,6 +593,17 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "syn" +version = "2.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "tempfile" version = "3.6.0" @@ -615,6 +627,26 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "thiserror" +version = "1.0.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thread_local" version = "1.1.7" @@ -728,8 +760,6 @@ dependencies = [ "image", "libwayshot", "log", - "wayland-client", - "wayland-protocols", ] [[package]] diff --git a/libwayshot/Cargo.toml b/libwayshot/Cargo.toml index a49e9073..c447fb1a 100644 --- a/libwayshot/Cargo.toml +++ b/libwayshot/Cargo.toml @@ -9,10 +9,11 @@ version = "0.1.2" edition = "2021" [dependencies] -image = { version = "0.24", default-features = false, features = ["jpeg", "png", "pnm", "qoi"] } +image = { version = "0.24", default-features = false } log = "0.4.19" memmap2 = "0.7.1" nix = "0.26.2" +thiserror = "1" wayland-client = "0.30.2" wayland-protocols = { version = "0.30.0", features=["client", "unstable"] } wayland-protocols-wlr = { version = "0.1.0", features = ["client"] } diff --git a/libwayshot/README.md b/libwayshot/README.md index 5936005d..a18983c7 100644 --- a/libwayshot/README.md +++ b/libwayshot/README.md @@ -8,3 +8,15 @@
+# `libwayshot` + +`libwayshot` is a convenient wrapper over the wlroots screenshot protocol that provides a simple API to take screenshots with. + +# Example usage + +```rust +use libwayshot::WayshotConnection; + +let wayshot_connection = WayshotConnection::new().unwrap(); +let image_buffer = wayshot_connection.screenshot_all().unwrap(); +``` diff --git a/libwayshot/src/dispatch.rs b/libwayshot/src/dispatch.rs new file mode 100644 index 00000000..078a77e9 --- /dev/null +++ b/libwayshot/src/dispatch.rs @@ -0,0 +1,223 @@ +use std::{ + process::exit, + sync::atomic::{AtomicBool, Ordering}, +}; +use wayland_client::{ + delegate_noop, + globals::GlobalListContents, + protocol::{ + wl_buffer::WlBuffer, wl_output, wl_output::WlOutput, wl_registry, wl_registry::WlRegistry, + wl_shm::WlShm, wl_shm_pool::WlShmPool, + }, + Connection, Dispatch, QueueHandle, WEnum, + WEnum::Value, +}; +use wayland_protocols::xdg::xdg_output::zv1::client::{ + zxdg_output_manager_v1::ZxdgOutputManagerV1, zxdg_output_v1, zxdg_output_v1::ZxdgOutputV1, +}; +use wayland_protocols_wlr::screencopy::v1::client::{ + zwlr_screencopy_frame_v1, zwlr_screencopy_frame_v1::ZwlrScreencopyFrameV1, + zwlr_screencopy_manager_v1::ZwlrScreencopyManagerV1, +}; + +use crate::{ + output::{OutputInfo, OutputPositioning}, + screencopy::FrameFormat, +}; + +pub struct OutputCaptureState { + pub outputs: Vec(
+ frame_format: &FrameFormat,
+ frame_mmap: &MmapMut,
+) -> Result