mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-05-23 14:08:33 +03:00
move feature flags to build.rs
This commit is contained in:
25
input-capture/build.rs
Normal file
25
input-capture/build.rs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
fn main() {
|
||||||
|
let unix = cfg!(unix);
|
||||||
|
let layer_shell = cfg!(feature = "layer_shell");
|
||||||
|
let libei = cfg!(feature = "libei");
|
||||||
|
let x11 = cfg!(feature = "x11");
|
||||||
|
let macos = cfg!(target_os = "macos");
|
||||||
|
|
||||||
|
let libei = unix && !macos && libei;
|
||||||
|
let layer_shell = unix && !macos && layer_shell;
|
||||||
|
let x11 = unix && !macos && x11;
|
||||||
|
|
||||||
|
println!("cargo::rustc-check-cfg=cfg(layer_shell)");
|
||||||
|
println!("cargo::rustc-check-cfg=cfg(libei)");
|
||||||
|
println!("cargo::rustc-check-cfg=cfg(x11)");
|
||||||
|
|
||||||
|
if layer_shell {
|
||||||
|
println!("cargo::rustc-cfg=layer_shell");
|
||||||
|
}
|
||||||
|
if libei {
|
||||||
|
println!("cargo::rustc-cfg=libei");
|
||||||
|
}
|
||||||
|
if x11 {
|
||||||
|
println!("cargo::rustc-cfg=x11");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,16 +8,16 @@ pub enum InputCaptureError {
|
|||||||
Capture(#[from] CaptureError),
|
Capture(#[from] CaptureError),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
#[cfg(layer_shell)]
|
||||||
use std::io;
|
use std::io;
|
||||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
#[cfg(layer_shell)]
|
||||||
use wayland_client::{
|
use wayland_client::{
|
||||||
ConnectError, DispatchError,
|
ConnectError, DispatchError,
|
||||||
backend::WaylandError,
|
backend::WaylandError,
|
||||||
globals::{BindError, GlobalError},
|
globals::{BindError, GlobalError},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
#[cfg(libei)]
|
||||||
use ashpd::desktop::ResponseError;
|
use ashpd::desktop::ResponseError;
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
@@ -31,13 +31,13 @@ pub enum CaptureError {
|
|||||||
EndOfStream,
|
EndOfStream,
|
||||||
#[error("io error: `{0}`")]
|
#[error("io error: `{0}`")]
|
||||||
Io(#[from] std::io::Error),
|
Io(#[from] std::io::Error),
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
#[cfg(libei)]
|
||||||
#[error("libei error: `{0}`")]
|
#[error("libei error: `{0}`")]
|
||||||
Reis(#[from] reis::Error),
|
Reis(#[from] reis::Error),
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
#[cfg(libei)]
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Portal(#[from] ashpd::Error),
|
Portal(#[from] ashpd::Error),
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
#[cfg(libei)]
|
||||||
#[error("libei disconnected - reason: `{0}`")]
|
#[error("libei disconnected - reason: `{0}`")]
|
||||||
Disconnected(String),
|
Disconnected(String),
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
@@ -61,13 +61,13 @@ pub enum CaptureError {
|
|||||||
pub enum CaptureCreationError {
|
pub enum CaptureCreationError {
|
||||||
#[error("no backend available")]
|
#[error("no backend available")]
|
||||||
NoAvailableBackend,
|
NoAvailableBackend,
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
#[cfg(libei)]
|
||||||
#[error("error creating input-capture-portal backend: `{0}`")]
|
#[error("error creating input-capture-portal backend: `{0}`")]
|
||||||
Libei(#[from] LibeiCaptureCreationError),
|
Libei(#[from] LibeiCaptureCreationError),
|
||||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
#[cfg(layer_shell)]
|
||||||
#[error("error creating layer-shell capture backend: `{0}`")]
|
#[error("error creating layer-shell capture backend: `{0}`")]
|
||||||
LayerShell(#[from] LayerShellCaptureCreationError),
|
LayerShell(#[from] LayerShellCaptureCreationError),
|
||||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
#[cfg(x11)]
|
||||||
#[error("error creating x11 capture backend: `{0}`")]
|
#[error("error creating x11 capture backend: `{0}`")]
|
||||||
X11(#[from] X11InputCaptureCreationError),
|
X11(#[from] X11InputCaptureCreationError),
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
@@ -80,7 +80,7 @@ pub enum CaptureCreationError {
|
|||||||
|
|
||||||
impl CaptureCreationError {
|
impl CaptureCreationError {
|
||||||
/// request was intentionally denied by the user
|
/// request was intentionally denied by the user
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
#[cfg(libei)]
|
||||||
pub(crate) fn cancelled_by_user(&self) -> bool {
|
pub(crate) fn cancelled_by_user(&self) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
self,
|
self,
|
||||||
@@ -89,20 +89,20 @@ impl CaptureCreationError {
|
|||||||
)))
|
)))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
#[cfg(not(all(unix, feature = "libei", not(target_os = "macos"))))]
|
#[cfg(not(libei))]
|
||||||
pub(crate) fn cancelled_by_user(&self) -> bool {
|
pub(crate) fn cancelled_by_user(&self) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
#[cfg(libei)]
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum LibeiCaptureCreationError {
|
pub enum LibeiCaptureCreationError {
|
||||||
#[error("xdg-desktop-portal: `{0}`")]
|
#[error("xdg-desktop-portal: `{0}`")]
|
||||||
Ashpd(#[from] ashpd::Error),
|
Ashpd(#[from] ashpd::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
#[cfg(layer_shell)]
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
#[error("{protocol} protocol not supported: {inner}")]
|
#[error("{protocol} protocol not supported: {inner}")]
|
||||||
pub struct WaylandBindError {
|
pub struct WaylandBindError {
|
||||||
@@ -110,14 +110,14 @@ pub struct WaylandBindError {
|
|||||||
protocol: &'static str,
|
protocol: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
#[cfg(layer_shell)]
|
||||||
impl WaylandBindError {
|
impl WaylandBindError {
|
||||||
pub(crate) fn new(inner: BindError, protocol: &'static str) -> Self {
|
pub(crate) fn new(inner: BindError, protocol: &'static str) -> Self {
|
||||||
Self { inner, protocol }
|
Self { inner, protocol }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
#[cfg(layer_shell)]
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum LayerShellCaptureCreationError {
|
pub enum LayerShellCaptureCreationError {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
@@ -134,7 +134,7 @@ pub enum LayerShellCaptureCreationError {
|
|||||||
Io(#[from] io::Error),
|
Io(#[from] io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
#[cfg(x11)]
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum X11InputCaptureCreationError {
|
pub enum X11InputCaptureCreationError {
|
||||||
#[error("X11 input capture is not yet implemented :(")]
|
#[error("X11 input capture is not yet implemented :(")]
|
||||||
|
|||||||
@@ -15,19 +15,19 @@ pub use error::{CaptureCreationError, CaptureError, InputCaptureError};
|
|||||||
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
#[cfg(libei)]
|
||||||
mod libei;
|
mod libei;
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
mod macos;
|
mod macos;
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
#[cfg(layer_shell)]
|
||||||
mod layer_shell;
|
mod layer_shell;
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
mod windows;
|
mod windows;
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
#[cfg(x11)]
|
||||||
mod x11;
|
mod x11;
|
||||||
|
|
||||||
/// fallback input capture (does not produce events)
|
/// fallback input capture (does not produce events)
|
||||||
@@ -85,11 +85,11 @@ impl Display for Position {
|
|||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
pub enum Backend {
|
pub enum Backend {
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
#[cfg(libei)]
|
||||||
InputCapturePortal,
|
InputCapturePortal,
|
||||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
#[cfg(layer_shell)]
|
||||||
LayerShell,
|
LayerShell,
|
||||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
#[cfg(x11)]
|
||||||
X11,
|
X11,
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
Windows,
|
Windows,
|
||||||
@@ -101,11 +101,11 @@ pub enum Backend {
|
|||||||
impl Display for Backend {
|
impl Display for Backend {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
#[cfg(libei)]
|
||||||
Backend::InputCapturePortal => write!(f, "input-capture-portal"),
|
Backend::InputCapturePortal => write!(f, "input-capture-portal"),
|
||||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
#[cfg(layer_shell)]
|
||||||
Backend::LayerShell => write!(f, "layer-shell"),
|
Backend::LayerShell => write!(f, "layer-shell"),
|
||||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
#[cfg(x11)]
|
||||||
Backend::X11 => write!(f, "X11"),
|
Backend::X11 => write!(f, "X11"),
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
Backend::Windows => write!(f, "windows"),
|
Backend::Windows => write!(f, "windows"),
|
||||||
@@ -298,11 +298,11 @@ async fn create_backend(
|
|||||||
CaptureCreationError,
|
CaptureCreationError,
|
||||||
> {
|
> {
|
||||||
match backend {
|
match backend {
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
#[cfg(libei)]
|
||||||
Backend::InputCapturePortal => Ok(Box::new(libei::LibeiInputCapture::new().await?)),
|
Backend::InputCapturePortal => Ok(Box::new(libei::LibeiInputCapture::new().await?)),
|
||||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
#[cfg(layer_shell)]
|
||||||
Backend::LayerShell => Ok(Box::new(layer_shell::LayerShellInputCapture::new()?)),
|
Backend::LayerShell => Ok(Box::new(layer_shell::LayerShellInputCapture::new()?)),
|
||||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
#[cfg(x11)]
|
||||||
Backend::X11 => Ok(Box::new(x11::X11InputCapture::new()?)),
|
Backend::X11 => Ok(Box::new(x11::X11InputCapture::new()?)),
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
Backend::Windows => Ok(Box::new(windows::WindowsInputCapture::new())),
|
Backend::Windows => Ok(Box::new(windows::WindowsInputCapture::new())),
|
||||||
@@ -327,11 +327,11 @@ async fn create(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for backend in [
|
for backend in [
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
#[cfg(libei)]
|
||||||
Backend::InputCapturePortal,
|
Backend::InputCapturePortal,
|
||||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
#[cfg(layer_shell)]
|
||||||
Backend::LayerShell,
|
Backend::LayerShell,
|
||||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
#[cfg(x11)]
|
||||||
Backend::X11,
|
Backend::X11,
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
Backend::Windows,
|
Backend::Windows,
|
||||||
|
|||||||
Reference in New Issue
Block a user