Skip to content

Commit

Permalink
split features for emulation and capture backends
Browse files Browse the repository at this point in the history
  • Loading branch information
feschber committed Nov 7, 2024
1 parent 1433a30 commit a870a9e
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 65 deletions.
22 changes: 17 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,21 @@ local-channel = "0.1.5"
libc = "0.2.148"

[features]
default = ["wayland", "x11", "xdg_desktop_portal", "libei", "gtk"]
wayland = ["input-capture/wayland", "input-emulation/wayland"]
x11 = ["input-capture/x11", "input-emulation/x11"]
xdg_desktop_portal = ["input-emulation/xdg_desktop_portal"]
libei = ["input-event/libei", "input-capture/libei", "input-emulation/libei"]
default = [
"gtk",
"layer_shell_capture",
"x11_capture",
"libei_capture",
"wlroots_emulation",
"libei_emulation",
"rdp_emulation",
"x11_emulation",
]
gtk = ["dep:lan-mouse-gtk"]
layer_shell_capture = ["input-capture/layer_shell"]
x11_capture = ["input-capture/x11"]
libei_capture = ["input-event/libei", "input-capture/libei"]
libei_emulation = ["input-event/libei", "input-emulation/libei"]
wlroots_emulation = ["input-emulation/wlroots"]
x11_emulation = ["input-emulation/x11"]
rdp_emulation = ["input-emulation/remote_desktop_portal"]
4 changes: 2 additions & 2 deletions input-capture/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ windows = { version = "0.58.0", features = [
] }

[features]
default = ["wayland", "x11", "libei"]
wayland = [
default = ["layer_shell", "x11", "libei"]
layer_shell = [
"dep:wayland-client",
"dep:wayland-protocols",
"dep:wayland-protocols-wlr",
Expand Down
12 changes: 6 additions & 6 deletions input-capture/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ pub enum InputCaptureError {
Capture(#[from] CaptureError),
}

#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
use std::io;
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
use wayland_client::{
backend::WaylandError,
globals::{BindError, GlobalError},
Expand Down Expand Up @@ -64,7 +64,7 @@ pub enum CaptureCreationError {
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
#[error("error creating input-capture-portal backend: `{0}`")]
Libei(#[from] LibeiCaptureCreationError),
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
#[error("error creating layer-shell capture backend: `{0}`")]
LayerShell(#[from] LayerShellCaptureCreationError),
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
Expand Down Expand Up @@ -102,22 +102,22 @@ pub enum LibeiCaptureCreationError {
Ashpd(#[from] ashpd::Error),
}

#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
#[derive(Debug, Error)]
#[error("{protocol} protocol not supported: {inner}")]
pub struct WaylandBindError {
inner: BindError,
protocol: &'static str,
}

#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
impl WaylandBindError {
pub(crate) fn new(inner: BindError, protocol: &'static str) -> Self {
Self { inner, protocol }
}
}

#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
#[derive(Debug, Error)]
pub enum LayerShellCaptureCreationError {
#[error(transparent)]
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions input-capture/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ mod libei;
#[cfg(target_os = "macos")]
mod macos;

#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
mod wayland;
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
mod layer_shell;

#[cfg(windows)]
mod windows;
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Display for Position {
pub enum Backend {
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
InputCapturePortal,
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
LayerShell,
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
X11,
Expand All @@ -103,7 +103,7 @@ impl Display for Backend {
match self {
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
Backend::InputCapturePortal => write!(f, "input-capture-portal"),
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
Backend::LayerShell => write!(f, "layer-shell"),
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
Backend::X11 => write!(f, "X11"),
Expand Down Expand Up @@ -287,8 +287,8 @@ async fn create_backend(
match backend {
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
Backend::InputCapturePortal => Ok(Box::new(libei::LibeiInputCapture::new().await?)),
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
Backend::LayerShell => Ok(Box::new(wayland::LayerShellInputCapture::new()?)),
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
Backend::LayerShell => Ok(Box::new(layer_shell::LayerShellInputCapture::new()?)),
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
Backend::X11 => Ok(Box::new(x11::X11InputCapture::new()?)),
#[cfg(windows)]
Expand Down Expand Up @@ -316,7 +316,7 @@ async fn create(
for backend in [
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
Backend::InputCapturePortal,
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
Backend::LayerShell,
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
Backend::X11,
Expand Down
6 changes: 3 additions & 3 deletions input-emulation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ windows = { version = "0.58.0", features = [
] }

[features]
default = ["wayland", "x11", "xdg_desktop_portal", "libei"]
wayland = [
default = ["wlroots", "x11", "remote_desktop_portal", "libei"]
wlroots = [
"dep:wayland-client",
"dep:wayland-protocols",
"dep:wayland-protocols-wlr",
"dep:wayland-protocols-misc",
]
x11 = ["dep:x11"]
xdg_desktop_portal = ["dep:ashpd"]
remote_desktop_portal = ["dep:ashpd"]
libei = ["dep:reis", "dep:ashpd"]
22 changes: 11 additions & 11 deletions input-emulation/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ pub enum InputEmulationError {

#[cfg(all(
unix,
any(feature = "xdg_desktop_portal", feature = "libei"),
any(feature = "remote_desktop_portal", feature = "libei"),
not(target_os = "macos")
))]
use ashpd::{desktop::ResponseError, Error::Response};
use std::io;
use thiserror::Error;

#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
use wayland_client::{
backend::WaylandError,
globals::{BindError, GlobalError},
Expand All @@ -29,12 +29,12 @@ pub enum EmulationError {
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
#[error("libei error: `{0}`")]
Libei(#[from] reis::Error),
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
#[error("wayland error: `{0}`")]
Wayland(#[from] wayland_client::backend::WaylandError),
#[cfg(all(
unix,
any(feature = "xdg_desktop_portal", feature = "libei"),
any(feature = "remote_desktop_portal", feature = "libei"),
not(target_os = "macos")
))]
#[error("xdg-desktop-portal: `{0}`")]
Expand All @@ -45,13 +45,13 @@ pub enum EmulationError {

#[derive(Debug, Error)]
pub enum EmulationCreationError {
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
#[error("wlroots backend: `{0}`")]
Wlroots(#[from] WlrootsEmulationCreationError),
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
#[error("libei backend: `{0}`")]
Libei(#[from] LibeiEmulationCreationError),
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
#[error("xdg-desktop-portal: `{0}`")]
Xdp(#[from] XdpEmulationCreationError),
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
Expand Down Expand Up @@ -79,7 +79,7 @@ impl EmulationCreationError {
) {
return true;
}
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
if matches!(
self,
EmulationCreationError::Xdp(XdpEmulationCreationError::Ashpd(Response(
Expand All @@ -92,7 +92,7 @@ impl EmulationCreationError {
}
}

#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
#[derive(Debug, Error)]
pub enum WlrootsEmulationCreationError {
#[error(transparent)]
Expand All @@ -109,15 +109,15 @@ pub enum WlrootsEmulationCreationError {
Io(#[from] std::io::Error),
}

#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
#[derive(Debug, Error)]
#[error("wayland protocol \"{protocol}\" not supported: {inner}")]
pub struct WaylandBindError {
inner: BindError,
protocol: &'static str,
}

#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
impl WaylandBindError {
pub(crate) fn new(inner: BindError, protocol: &'static str) -> Self {
Self { inner, protocol }
Expand All @@ -135,7 +135,7 @@ pub enum LibeiEmulationCreationError {
Reis(#[from] reis::Error),
}

#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
#[derive(Debug, Error)]
pub enum XdpEmulationCreationError {
#[error(transparent)]
Expand Down
20 changes: 10 additions & 10 deletions input-emulation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ mod windows;
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
mod x11;

#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
mod wlroots;

#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
mod xdg_desktop_portal;

#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
Expand All @@ -34,11 +34,11 @@ pub type EmulationHandle = u64;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Backend {
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
Wlroots,
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
Libei,
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
Xdp,
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
X11,
Expand All @@ -52,11 +52,11 @@ pub enum Backend {
impl Display for Backend {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
Backend::Wlroots => write!(f, "wlroots"),
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
Backend::Libei => write!(f, "libei"),
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
Backend::Xdp => write!(f, "xdg-desktop-portal"),
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
Backend::X11 => write!(f, "X11"),
Expand All @@ -78,13 +78,13 @@ pub struct InputEmulation {
impl InputEmulation {
async fn with_backend(backend: Backend) -> Result<InputEmulation, EmulationCreationError> {
let emulation: Box<dyn Emulation> = match backend {
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
Backend::Wlroots => Box::new(wlroots::WlrootsEmulation::new()?),
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
Backend::Libei => Box::new(libei::LibeiEmulation::new().await?),
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
Backend::X11 => Box::new(x11::X11Emulation::new()?),
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
Backend::Xdp => Box::new(xdg_desktop_portal::DesktopPortalEmulation::new().await?),
#[cfg(windows)]
Backend::Windows => Box::new(windows::WindowsEmulation::new()?),
Expand All @@ -109,11 +109,11 @@ impl InputEmulation {
}

for backend in [
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
Backend::Wlroots,
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
Backend::Libei,
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
Backend::Xdp,
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
Backend::X11,
Expand Down
Loading

0 comments on commit a870a9e

Please sign in to comment.