From 544b2a0652e7fd755b4491a6a16c297a718cd20e Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Wed, 28 Jul 2021 16:30:28 -0500 Subject: [PATCH] a --- Cargo.toml | 9 +++------ src/gui_wayland.rs | 34 ++++++++++++++++++++++++++++++++++ src/gui_x11.rs | 13 +++---------- src/main.rs | 12 ++++++++++++ x11/src/xlib/window/mod.rs | 2 +- 5 files changed, 53 insertions(+), 17 deletions(-) create mode 100644 src/gui_wayland.rs diff --git a/Cargo.toml b/Cargo.toml index aad048d..fe08559 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ default = ["backend-x11", "backend-x11-glx"] backend-x11 = ["leanshot-x11"] backend-x11-glx = ["backend-x11", "leanshot-x11/glx"] backend-xcb = ["xcb-util", "xcb"] +backend-wayland = [] [dependencies] anyhow = "1.0.42" @@ -31,9 +32,5 @@ leanshot-x11 = { path = "x11", optional = true } xcb-util = { version = "0.3.0", features = ["image", "cursor"], optional = true } xcb = { version = "0.9.0", optional = true } -[package.metadata.cargo-all-features] -skip_feature_sets = [ - ["backend-x11", "backend-xcb"], - [], -] -skip_optional_dependencies = true +# wayland + diff --git a/src/gui_wayland.rs b/src/gui_wayland.rs new file mode 100644 index 0000000..ae6d9bb --- /dev/null +++ b/src/gui_wayland.rs @@ -0,0 +1,34 @@ +use std::path::Path; + +use anyhow::Result; + +use crate::gui_trait::{Capture, Gui}; +use crate::rect::Rectangle; + +pub struct WaylandGui {} + +impl WaylandGui { + pub fn new() -> Result { + todo!() + } +} + +impl Gui for WaylandGui { + type Capture = ScreenCapture; + + fn capture_entire_screen(&self) -> Result { + todo!() + } + + fn interactive_select(&self, _: &Self::Capture) -> Result> { + todo!() + } +} + +pub struct ScreenCapture {} + +impl Capture for ScreenCapture { + fn save_cropped_to(&self, to: impl AsRef, section: Option) -> Result<()> { + todo!() + } +} diff --git a/src/gui_x11.rs b/src/gui_x11.rs index 50cd164..10e2b7f 100644 --- a/src/gui_x11.rs +++ b/src/gui_x11.rs @@ -1,8 +1,8 @@ use std::path::Path; use anyhow::Result; -use x11::xlib::{Display, Image as XImage, Screen}; use image::{Bgra, DynamicImage, ImageBuffer}; +use x11::xlib::{Display, Image as XImage, Screen}; use crate::gui_trait::{Capture, Gui}; use crate::rect::Rectangle; @@ -36,10 +36,7 @@ impl Gui for X11Gui { Ok(ScreenCapture { image }) } - fn interactive_select( - &self, - _: &Self::Capture, - ) -> Result> { + fn interactive_select(&self, _: &Self::Capture) -> Result> { todo!() } } @@ -49,11 +46,7 @@ pub struct ScreenCapture { } impl Capture for ScreenCapture { - fn save_cropped_to( - &self, - to: impl AsRef, - section: Option, - ) -> Result<()> { + fn save_cropped_to(&self, to: impl AsRef, section: Option) -> Result<()> { let to = to.as_ref(); let buffer = self.image.buffer(); diff --git a/src/main.rs b/src/main.rs index c1eefd8..e520c92 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,10 @@ extern crate leanshot_x11 as x11; #[cfg(all(feature = "backend-x11", feature = "backend-xcb"))] compile_error!("don't enable both x11 and xcb backends"); +#[cfg(all(feature = "backend-x11", feature = "backend-wayland"))] +compile_error!("don't enable both x11 and wayland backends"); +#[cfg(all(feature = "backend-xcb", feature = "backend-wayland"))] +compile_error!("don't enable both xcb and wayland backends"); mod gui_trait; @@ -17,6 +21,9 @@ mod gui_xcb; #[cfg(feature = "backend-x11")] mod gui_x11; +#[cfg(feature = "backend-wayland")] +mod gui_wayland; + mod rect; mod singleton; @@ -52,6 +59,11 @@ fn get_gui() -> Result { crate::gui_x11::X11Gui::new() } +#[cfg(feature = "backend-wayland")] +fn get_gui() -> Result { + crate::gui_wayland::WaylandGui::new() +} + fn run(opt: &Options, gui: impl Gui) -> Result<()> { let capture = gui.capture_entire_screen()?; diff --git a/x11/src/xlib/window/mod.rs b/x11/src/xlib/window/mod.rs index 15243d3..4df56c8 100644 --- a/x11/src/xlib/window/mod.rs +++ b/x11/src/xlib/window/mod.rs @@ -9,9 +9,9 @@ use crate::rect::Rectangle; use super::atom::Atom; use super::display::{Display, GetDisplay}; -use super::screen::Screen; use super::drawable::Drawable; use super::image::Image; +use super::screen::Screen; pub use self::attr::{EventMask, SetWindowAttributes, WindowAttributes};