This commit is contained in:
Michael Zhang 2021-07-28 16:30:28 -05:00
parent c519114a9f
commit 544b2a0652
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
5 changed files with 53 additions and 17 deletions

View file

@ -15,6 +15,7 @@ default = ["backend-x11", "backend-x11-glx"]
backend-x11 = ["leanshot-x11"] backend-x11 = ["leanshot-x11"]
backend-x11-glx = ["backend-x11", "leanshot-x11/glx"] backend-x11-glx = ["backend-x11", "leanshot-x11/glx"]
backend-xcb = ["xcb-util", "xcb"] backend-xcb = ["xcb-util", "xcb"]
backend-wayland = []
[dependencies] [dependencies]
anyhow = "1.0.42" 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-util = { version = "0.3.0", features = ["image", "cursor"], optional = true }
xcb = { version = "0.9.0", optional = true } xcb = { version = "0.9.0", optional = true }
[package.metadata.cargo-all-features] # wayland
skip_feature_sets = [
["backend-x11", "backend-xcb"],
[],
]
skip_optional_dependencies = true

34
src/gui_wayland.rs Normal file
View file

@ -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<Self> {
todo!()
}
}
impl Gui for WaylandGui {
type Capture = ScreenCapture;
fn capture_entire_screen(&self) -> Result<Self::Capture> {
todo!()
}
fn interactive_select(&self, _: &Self::Capture) -> Result<Option<Rectangle>> {
todo!()
}
}
pub struct ScreenCapture {}
impl Capture for ScreenCapture {
fn save_cropped_to(&self, to: impl AsRef<Path>, section: Option<Rectangle>) -> Result<()> {
todo!()
}
}

View file

@ -1,8 +1,8 @@
use std::path::Path; use std::path::Path;
use anyhow::Result; use anyhow::Result;
use x11::xlib::{Display, Image as XImage, Screen};
use image::{Bgra, DynamicImage, ImageBuffer}; use image::{Bgra, DynamicImage, ImageBuffer};
use x11::xlib::{Display, Image as XImage, Screen};
use crate::gui_trait::{Capture, Gui}; use crate::gui_trait::{Capture, Gui};
use crate::rect::Rectangle; use crate::rect::Rectangle;
@ -36,10 +36,7 @@ impl Gui for X11Gui {
Ok(ScreenCapture { image }) Ok(ScreenCapture { image })
} }
fn interactive_select( fn interactive_select(&self, _: &Self::Capture) -> Result<Option<Rectangle>> {
&self,
_: &Self::Capture,
) -> Result<Option<Rectangle>> {
todo!() todo!()
} }
} }
@ -49,11 +46,7 @@ pub struct ScreenCapture {
} }
impl Capture for ScreenCapture { impl Capture for ScreenCapture {
fn save_cropped_to( fn save_cropped_to(&self, to: impl AsRef<Path>, section: Option<Rectangle>) -> Result<()> {
&self,
to: impl AsRef<Path>,
section: Option<Rectangle>,
) -> Result<()> {
let to = to.as_ref(); let to = to.as_ref();
let buffer = self.image.buffer(); let buffer = self.image.buffer();

View file

@ -8,6 +8,10 @@ extern crate leanshot_x11 as x11;
#[cfg(all(feature = "backend-x11", feature = "backend-xcb"))] #[cfg(all(feature = "backend-x11", feature = "backend-xcb"))]
compile_error!("don't enable both x11 and xcb backends"); 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; mod gui_trait;
@ -17,6 +21,9 @@ mod gui_xcb;
#[cfg(feature = "backend-x11")] #[cfg(feature = "backend-x11")]
mod gui_x11; mod gui_x11;
#[cfg(feature = "backend-wayland")]
mod gui_wayland;
mod rect; mod rect;
mod singleton; mod singleton;
@ -52,6 +59,11 @@ fn get_gui() -> Result<crate::gui_x11::X11Gui> {
crate::gui_x11::X11Gui::new() crate::gui_x11::X11Gui::new()
} }
#[cfg(feature = "backend-wayland")]
fn get_gui() -> Result<crate::gui_wayland::WaylandGui> {
crate::gui_wayland::WaylandGui::new()
}
fn run(opt: &Options, gui: impl Gui) -> Result<()> { fn run(opt: &Options, gui: impl Gui) -> Result<()> {
let capture = gui.capture_entire_screen()?; let capture = gui.capture_entire_screen()?;

View file

@ -9,9 +9,9 @@ use crate::rect::Rectangle;
use super::atom::Atom; use super::atom::Atom;
use super::display::{Display, GetDisplay}; use super::display::{Display, GetDisplay};
use super::screen::Screen;
use super::drawable::Drawable; use super::drawable::Drawable;
use super::image::Image; use super::image::Image;
use super::screen::Screen;
pub use self::attr::{EventMask, SetWindowAttributes, WindowAttributes}; pub use self::attr::{EventMask, SetWindowAttributes, WindowAttributes};