Compare commits

..

4 Commits

Author SHA1 Message Date
Ferdinand Schober
ac5ba3da37 Merge branch 'main' into move-feature-flags-to-build-script 2026-05-16 17:09:29 +02:00
Ferdinand Schober
1fa3800d3c windows: fix clippy lints 2026-05-16 17:09:06 +02:00
Ferdinand Schober
743895516c same for input-emulation 2026-05-16 12:23:26 +02:00
Ferdinand Schober
b65ca44ea2 move feature flags to build.rs 2026-05-16 12:16:09 +02:00
16 changed files with 143 additions and 235 deletions

25
Cargo.lock generated
View File

@@ -1087,30 +1087,6 @@ dependencies = [
"system-deps", "system-deps",
] ]
[[package]]
name = "gdk4-wayland"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd34518488cd624a85e75e82540bc24c72cfeb0aea6bad7faed683ca3977dba0"
dependencies = [
"gdk4",
"gdk4-wayland-sys",
"gio",
"glib",
"libc",
]
[[package]]
name = "gdk4-wayland-sys"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c7a0f2332c531d62ee3f14f5e839ac1abac59e9b052adf1495124c00d89a34b"
dependencies = [
"glib-sys",
"libc",
"system-deps",
]
[[package]] [[package]]
name = "generic-array" name = "generic-array"
version = "0.14.7" version = "0.14.7"
@@ -1913,7 +1889,6 @@ name = "lan-mouse-gtk"
version = "0.2.0" version = "0.2.0"
dependencies = [ dependencies = [
"async-channel", "async-channel",
"gdk4-wayland",
"glib-build-tools", "glib-build-tools",
"gtk4", "gtk4",
"hostname", "hostname",

25
input-capture/build.rs Normal file
View 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");
}
}

View File

@@ -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 :(")]

View File

@@ -2,7 +2,6 @@ use std::{
collections::{HashMap, HashSet, VecDeque}, collections::{HashMap, HashSet, VecDeque},
fmt::Display, fmt::Display,
mem::swap, mem::swap,
sync::{Arc, Mutex},
task::{Poll, ready}, task::{Poll, ready},
}; };
@@ -16,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)
@@ -86,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,
@@ -102,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"),
@@ -130,24 +129,6 @@ pub struct InputCapture {
pending: VecDeque<(CaptureHandle, CaptureEvent)>, pending: VecDeque<(CaptureHandle, CaptureEvent)>,
} }
#[derive(Clone, Debug)]
pub enum WindowIdentifier {
Wayland(String),
X11(u32),
}
#[cfg(all(unix, feature = "libei"))]
impl Into<ashpd::WindowIdentifier> for WindowIdentifier {
fn into(self) -> ashpd::WindowIdentifier {
match self {
WindowIdentifier::Wayland(handle) => {
ashpd::WindowIdentifier::from_xdg_foreign_exported(handle)
}
WindowIdentifier::X11(_) => todo!(),
}
}
}
impl InputCapture { impl InputCapture {
/// create a new client with the given id /// create a new client with the given id
pub async fn create(&mut self, id: CaptureHandle, pos: Position) -> Result<(), CaptureError> { pub async fn create(&mut self, id: CaptureHandle, pos: Position) -> Result<(), CaptureError> {
@@ -209,11 +190,8 @@ impl InputCapture {
} }
/// creates a new [`InputCapture`] /// creates a new [`InputCapture`]
pub async fn new( pub async fn new(backend: Option<Backend>) -> Result<Self, CaptureCreationError> {
backend: Option<Backend>, let capture = create(backend).await?;
window_identifier: Arc<Mutex<Option<WindowIdentifier>>>,
) -> Result<Self, CaptureCreationError> {
let capture = create(backend, window_identifier).await?;
Ok(Self { Ok(Self {
capture, capture,
id_map: Default::default(), id_map: Default::default(),
@@ -315,19 +293,16 @@ trait Capture: Stream<Item = Result<(Position, CaptureEvent), CaptureError>> + U
async fn create_backend( async fn create_backend(
backend: Backend, backend: Backend,
window_identifier: Arc<Mutex<Option<WindowIdentifier>>>,
) -> Result< ) -> Result<
Box<dyn Capture<Item = Result<(Position, CaptureEvent), CaptureError>>>, Box<dyn Capture<Item = Result<(Position, CaptureEvent), CaptureError>>>,
CaptureCreationError, CaptureCreationError,
> { > {
match backend { match backend {
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))] #[cfg(libei)]
Backend::InputCapturePortal => Ok(Box::new( Backend::InputCapturePortal => Ok(Box::new(libei::LibeiInputCapture::new().await?)),
libei::LibeiInputCapture::new(window_identifier).await?, #[cfg(layer_shell)]
)),
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
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())),
@@ -339,13 +314,12 @@ async fn create_backend(
async fn create( async fn create(
backend: Option<Backend>, backend: Option<Backend>,
window_identifier: Arc<Mutex<Option<WindowIdentifier>>>,
) -> Result< ) -> Result<
Box<dyn Capture<Item = Result<(Position, CaptureEvent), CaptureError>>>, Box<dyn Capture<Item = Result<(Position, CaptureEvent), CaptureError>>>,
CaptureCreationError, CaptureCreationError,
> { > {
if let Some(backend) = backend { if let Some(backend) = backend {
let b = create_backend(backend, window_identifier).await; let b = create_backend(backend).await;
if b.is_ok() { if b.is_ok() {
log::info!("using capture backend: {backend}"); log::info!("using capture backend: {backend}");
} }
@@ -353,18 +327,18 @@ 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,
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
Backend::MacOs, Backend::MacOs,
] { ] {
match create_backend(backend, window_identifier.clone()).await { match create_backend(backend).await {
Ok(b) => { Ok(b) => {
log::info!("using capture backend: {backend}"); log::info!("using capture backend: {backend}");
return Ok(b); return Ok(b);

View File

@@ -23,7 +23,7 @@ use std::{
os::unix::net::UnixStream, os::unix::net::UnixStream,
pin::Pin, pin::Pin,
rc::Rc, rc::Rc,
sync::{Arc, Mutex}, sync::Arc,
task::{Context, Poll}, task::{Context, Poll},
}; };
use tokio::{ use tokio::{
@@ -39,7 +39,7 @@ use futures_core::Stream;
use input_event::Event; use input_event::Event;
use crate::{CaptureEvent, WindowIdentifier}; use crate::CaptureEvent;
use super::{ use super::{
Capture as LanMouseInputCapture, Position, Capture as LanMouseInputCapture, Position,
@@ -161,17 +161,13 @@ async fn update_barriers(
async fn create_session( async fn create_session(
input_capture: &InputCapture, input_capture: &InputCapture,
window_identifier: Arc<Mutex<Option<WindowIdentifier>>>,
) -> std::result::Result<(Session<InputCapture>, BitFlags<Capabilities>), ashpd::Error> { ) -> std::result::Result<(Session<InputCapture>, BitFlags<Capabilities>), ashpd::Error> {
log::debug!("creating input capture session: {window_identifier:?}"); log::debug!("creating input capture session");
let window_identifier = window_identifier.lock().unwrap().clone();
let create_session_options = CreateSessionOptions::default().set_capabilities( let create_session_options = CreateSessionOptions::default().set_capabilities(
Capabilities::Keyboard | Capabilities::Pointer | Capabilities::Touchscreen, Capabilities::Keyboard | Capabilities::Pointer | Capabilities::Touchscreen,
); );
let ashpd_window_identifier: Option<ashpd::WindowIdentifier> =
window_identifier.map(|i| i.into());
input_capture input_capture
.create_session(ashpd_window_identifier.as_ref(), create_session_options) .create_session(None, create_session_options)
.await .await
} }
@@ -216,15 +212,10 @@ async fn libei_event_handler(
} }
impl LibeiInputCapture { impl LibeiInputCapture {
/// creates a new libei input capture pub async fn new() -> std::result::Result<Self, LibeiCaptureCreationError> {
/// `window_id` is a window identifier for user prompts
pub async fn new(
window_identifier: Arc<Mutex<Option<WindowIdentifier>>>,
) -> std::result::Result<Self, LibeiCaptureCreationError> {
let input_capture = Box::pin(InputCapture::new().await?); let input_capture = Box::pin(InputCapture::new().await?);
let input_capture_ptr = input_capture.as_ref().get_ref() as *const InputCapture; let input_capture_ptr = input_capture.as_ref().get_ref() as *const InputCapture;
let first_session = let first_session = Some(create_session(unsafe { &*input_capture_ptr }).await?);
Some(create_session(unsafe { &*input_capture_ptr }, window_identifier.clone()).await?);
let (event_tx, event_rx) = mpsc::channel(1); let (event_tx, event_rx) = mpsc::channel(1);
let (notify_capture, notify_rx) = mpsc::channel(1); let (notify_capture, notify_rx) = mpsc::channel(1);
@@ -239,7 +230,6 @@ impl LibeiInputCapture {
first_session, first_session,
event_tx, event_tx,
cancellation_token.clone(), cancellation_token.clone(),
window_identifier,
); );
let capture_task = tokio::task::spawn_local(capture); let capture_task = tokio::task::spawn_local(capture);
@@ -264,7 +254,6 @@ async fn do_capture(
session: Option<(Session<InputCapture>, BitFlags<Capabilities>)>, session: Option<(Session<InputCapture>, BitFlags<Capabilities>)>,
event_tx: Sender<(Position, CaptureEvent)>, event_tx: Sender<(Position, CaptureEvent)>,
cancellation_token: CancellationToken, cancellation_token: CancellationToken,
window_identifier: Arc<Mutex<Option<WindowIdentifier>>>,
) -> Result<(), CaptureError> { ) -> Result<(), CaptureError> {
let mut session = session.map(|s| s.0); let mut session = session.map(|s| s.0);
@@ -310,11 +299,7 @@ async fn do_capture(
// create session // create session
let mut session = match session.take() { let mut session = match session.take() {
Some(s) => s, Some(s) => s,
None => { None => create_session(input_capture).await?.0,
create_session(input_capture, window_identifier.clone())
.await?
.0
}
}; };
let capture_session = do_capture_session( let capture_session = do_capture_session(

View File

@@ -222,11 +222,8 @@ fn start_routine(
} }
/* run message loop */ /* run message loop */
loop { while let Some(msg) = get_msg() {
// mouse / keybrd proc do not actually return a message // mouse / keybrd proc do not actually return a message
let Some(msg) = get_msg() else {
break;
};
if msg.hwnd.0.is_null() { if msg.hwnd.0.is_null() {
/* messages sent via PostThreadMessage */ /* messages sent via PostThreadMessage */
match msg.wParam.0 { match msg.wParam.0 {

31
input-emulation/build.rs Normal file
View File

@@ -0,0 +1,31 @@
fn main() {
let unix = cfg!(unix);
let libei = cfg!(feature = "libei");
let x11 = cfg!(feature = "x11");
let macos = cfg!(target_os = "macos");
let wlroots = cfg!(feature = "wlroots");
let rdp = cfg!(feature = "remote_desktop_portal");
let libei = unix && !macos && libei;
let wlroots = unix && !macos && wlroots;
let x11 = unix && !macos && x11;
let rdp = unix && !macos && rdp;
println!("cargo::rustc-check-cfg=cfg(wlroots)");
println!("cargo::rustc-check-cfg=cfg(libei)");
println!("cargo::rustc-check-cfg=cfg(x11)");
println!("cargo::rustc-check-cfg=cfg(rdp)");
if libei {
println!("cargo::rustc-cfg=libei");
}
if x11 {
println!("cargo::rustc-cfg=x11");
}
if wlroots {
println!("cargo::rustc-cfg=wlroots");
}
if rdp {
println!("cargo::rustc-cfg=rdp");
}
}

View File

@@ -6,16 +6,12 @@ pub enum InputEmulationError {
Emulate(#[from] EmulationError), Emulate(#[from] EmulationError),
} }
#[cfg(all( #[cfg(any(libei, rdp))]
unix,
any(feature = "remote_desktop_portal", feature = "libei"),
not(target_os = "macos")
))]
use ashpd::{Error::Response, desktop::ResponseError}; use ashpd::{Error::Response, desktop::ResponseError};
use std::io; use std::io;
use thiserror::Error; use thiserror::Error;
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))] #[cfg(wlroots)]
use wayland_client::{ use wayland_client::{
ConnectError, DispatchError, ConnectError, DispatchError,
backend::WaylandError, backend::WaylandError,
@@ -26,17 +22,13 @@ use wayland_client::{
pub enum EmulationError { pub enum EmulationError {
#[error("event stream closed")] #[error("event stream closed")]
EndOfStream, EndOfStream,
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))] #[cfg(libei)]
#[error("libei error: `{0}`")] #[error("libei error: `{0}`")]
Libei(#[from] reis::Error), Libei(#[from] reis::Error),
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))] #[cfg(wlroots)]
#[error("wayland error: `{0}`")] #[error("wayland error: `{0}`")]
Wayland(#[from] wayland_client::backend::WaylandError), Wayland(#[from] wayland_client::backend::WaylandError),
#[cfg(all( #[cfg(any(rdp, libei))]
unix,
any(feature = "remote_desktop_portal", feature = "libei"),
not(target_os = "macos")
))]
#[error("xdg-desktop-portal: `{0}`")] #[error("xdg-desktop-portal: `{0}`")]
Ashpd(#[from] ashpd::Error), Ashpd(#[from] ashpd::Error),
#[error("io error: `{0}`")] #[error("io error: `{0}`")]
@@ -45,16 +37,16 @@ pub enum EmulationError {
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum EmulationCreationError { pub enum EmulationCreationError {
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))] #[cfg(wlroots)]
#[error("wlroots backend: `{0}`")] #[error("wlroots backend: `{0}`")]
Wlroots(#[from] WlrootsEmulationCreationError), Wlroots(#[from] WlrootsEmulationCreationError),
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))] #[cfg(libei)]
#[error("libei backend: `{0}`")] #[error("libei backend: `{0}`")]
Libei(#[from] LibeiEmulationCreationError), Libei(#[from] LibeiEmulationCreationError),
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))] #[cfg(rdp)]
#[error("xdg-desktop-portal: `{0}`")] #[error("xdg-desktop-portal: `{0}`")]
Xdp(#[from] XdpEmulationCreationError), Xdp(#[from] XdpEmulationCreationError),
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))] #[cfg(x11)]
#[error("x11: `{0}`")] #[error("x11: `{0}`")]
X11(#[from] X11EmulationCreationError), X11(#[from] X11EmulationCreationError),
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
@@ -70,7 +62,7 @@ pub enum EmulationCreationError {
impl EmulationCreationError { impl EmulationCreationError {
/// request was intentionally denied by the user /// request was intentionally denied by the user
pub(crate) fn cancelled_by_user(&self) -> bool { pub(crate) fn cancelled_by_user(&self) -> bool {
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))] #[cfg(libei)]
if matches!( if matches!(
self, self,
EmulationCreationError::Libei(LibeiEmulationCreationError::Ashpd(Response( EmulationCreationError::Libei(LibeiEmulationCreationError::Ashpd(Response(
@@ -79,7 +71,7 @@ impl EmulationCreationError {
) { ) {
return true; return true;
} }
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))] #[cfg(rdp)]
if matches!( if matches!(
self, self,
EmulationCreationError::Xdp(XdpEmulationCreationError::Ashpd(Response( EmulationCreationError::Xdp(XdpEmulationCreationError::Ashpd(Response(
@@ -92,7 +84,7 @@ impl EmulationCreationError {
} }
} }
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))] #[cfg(wlroots)]
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum WlrootsEmulationCreationError { pub enum WlrootsEmulationCreationError {
#[error(transparent)] #[error(transparent)]
@@ -109,7 +101,7 @@ pub enum WlrootsEmulationCreationError {
Io(#[from] std::io::Error), Io(#[from] std::io::Error),
} }
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))] #[cfg(wlroots)]
#[derive(Debug, Error)] #[derive(Debug, Error)]
#[error("wayland protocol \"{protocol}\" not supported: {inner}")] #[error("wayland protocol \"{protocol}\" not supported: {inner}")]
pub struct WaylandBindError { pub struct WaylandBindError {
@@ -117,14 +109,14 @@ pub struct WaylandBindError {
protocol: &'static str, protocol: &'static str,
} }
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))] #[cfg(wlroots)]
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 = "libei", not(target_os = "macos")))] #[cfg(libei)]
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum LibeiEmulationCreationError { pub enum LibeiEmulationCreationError {
#[error(transparent)] #[error(transparent)]
@@ -135,14 +127,14 @@ pub enum LibeiEmulationCreationError {
Reis(#[from] reis::Error), Reis(#[from] reis::Error),
} }
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))] #[cfg(rdp)]
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum XdpEmulationCreationError { pub enum XdpEmulationCreationError {
#[error(transparent)] #[error(transparent)]
Ashpd(#[from] ashpd::Error), Ashpd(#[from] ashpd::Error),
} }
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))] #[cfg(x11)]
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum X11EmulationCreationError { pub enum X11EmulationCreationError {
#[error("could not open display")] #[error("could not open display")]

View File

@@ -11,16 +11,16 @@ pub use self::error::{EmulationCreationError, EmulationError, InputEmulationErro
#[cfg(windows)] #[cfg(windows)]
mod windows; mod windows;
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))] #[cfg(x11)]
mod x11; mod x11;
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))] #[cfg(wlroots)]
mod wlroots; mod wlroots;
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))] #[cfg(rdp)]
mod xdg_desktop_portal; mod xdg_desktop_portal;
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))] #[cfg(libei)]
mod libei; mod libei;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
@@ -34,13 +34,13 @@ pub type EmulationHandle = u64;
#[derive(Clone, Copy, Debug, Eq, PartialEq)] #[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Backend { pub enum Backend {
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))] #[cfg(wlroots)]
Wlroots, Wlroots,
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))] #[cfg(libei)]
Libei, Libei,
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))] #[cfg(rdp)]
Xdp, Xdp,
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))] #[cfg(x11)]
X11, X11,
#[cfg(windows)] #[cfg(windows)]
Windows, Windows,
@@ -52,13 +52,13 @@ 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 = "wlroots", not(target_os = "macos")))] #[cfg(wlroots)]
Backend::Wlroots => write!(f, "wlroots"), Backend::Wlroots => write!(f, "wlroots"),
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))] #[cfg(libei)]
Backend::Libei => write!(f, "libei"), Backend::Libei => write!(f, "libei"),
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))] #[cfg(rdp)]
Backend::Xdp => write!(f, "xdg-desktop-portal"), Backend::Xdp => write!(f, "xdg-desktop-portal"),
#[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"),
@@ -78,13 +78,13 @@ pub struct InputEmulation {
impl InputEmulation { impl InputEmulation {
async fn with_backend(backend: Backend) -> Result<InputEmulation, EmulationCreationError> { async fn with_backend(backend: Backend) -> Result<InputEmulation, EmulationCreationError> {
let emulation: Box<dyn Emulation> = match backend { let emulation: Box<dyn Emulation> = match backend {
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))] #[cfg(wlroots)]
Backend::Wlroots => Box::new(wlroots::WlrootsEmulation::new()?), Backend::Wlroots => Box::new(wlroots::WlrootsEmulation::new()?),
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))] #[cfg(libei)]
Backend::Libei => Box::new(libei::LibeiEmulation::new().await?), Backend::Libei => Box::new(libei::LibeiEmulation::new().await?),
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))] #[cfg(x11)]
Backend::X11 => Box::new(x11::X11Emulation::new()?), Backend::X11 => Box::new(x11::X11Emulation::new()?),
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))] #[cfg(rdp)]
Backend::Xdp => Box::new(xdg_desktop_portal::DesktopPortalEmulation::new().await?), Backend::Xdp => Box::new(xdg_desktop_portal::DesktopPortalEmulation::new().await?),
#[cfg(windows)] #[cfg(windows)]
Backend::Windows => Box::new(windows::WindowsEmulation::new()?), Backend::Windows => Box::new(windows::WindowsEmulation::new()?),
@@ -109,13 +109,13 @@ impl InputEmulation {
} }
for backend in [ for backend in [
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))] #[cfg(wlroots)]
Backend::Wlroots, Backend::Wlroots,
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))] #[cfg(libei)]
Backend::Libei, Backend::Libei,
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))] #[cfg(rdp)]
Backend::Xdp, Backend::Xdp,
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))] #[cfg(x11)]
Backend::X11, Backend::X11,
#[cfg(windows)] #[cfg(windows)]
Backend::Windows, Backend::Windows,

View File

@@ -15,13 +15,5 @@ log = "0.4.20"
lan-mouse-ipc = { path = "../lan-mouse-ipc", version = "0.2.0" } lan-mouse-ipc = { path = "../lan-mouse-ipc", version = "0.2.0" }
thiserror = "2.0.0" thiserror = "2.0.0"
[target.'cfg(all(unix, not(target_os="macos")))'.dependencies]
gdk4_wayland = { package = "gdk4-wayland", version="0.9.6", optional=true }
[build-dependencies] [build-dependencies]
glib-build-tools = { version = "0.20.0" } glib-build-tools = { version = "0.20.0" }
[features]
default = ["wayland_window_identifier"]
wayland_window_identifier = ["dep:gdk4_wayland"]

View File

@@ -14,7 +14,7 @@ use std::{env, process, str};
use window::Window; use window::Window;
use lan_mouse_ipc::{FrontendEvent, FrontendRequest, WindowIdentifier}; use lan_mouse_ipc::FrontendEvent;
use adw::Application; use adw::Application;
use gtk::{IconTheme, gdk::Display, glib::clone, prelude::*}; use gtk::{IconTheme, gdk::Display, glib::clone, prelude::*};
@@ -23,9 +23,6 @@ use gtk::{gio, glib, prelude::ApplicationExt};
use self::client_object::ClientObject; use self::client_object::ClientObject;
use self::key_object::KeyObject; use self::key_object::KeyObject;
#[cfg(all(unix, feature = "wayland_window_identifier", not(target_os = "macos")))]
use gdk4_wayland::WaylandToplevel;
use thiserror::Error; use thiserror::Error;
#[derive(Error, Debug)] #[derive(Error, Debug)]
@@ -230,28 +227,6 @@ fn build_ui(app: &Application) {
}); });
} }
// export TopLevel handle and send it to the service so that it can put the InpuCapture / RemoteDesktop
// windows on top of it using xdg-foreign.
#[cfg(all(unix, feature = "wayland_window_identifier", not(target_os = "macos")))]
window.connect_show(|window| {
// needs the surface so we have to present first!
if let Some(surface) = window.surface() {
if surface.display().backend().is_wayland() {
// let surface = surface.downcast::<WaylandSurface>();
let toplevel = surface.downcast::<WaylandToplevel>().expect("xdg-toplevel");
let window = window.clone();
toplevel.export_handle(move |_toplevel, handle| {
if let Ok(handle) = handle {
let handle = handle.to_string();
window.request(FrontendRequest::WindowIdentifier(
WindowIdentifier::Wayland(handle),
));
}
});
}
}
});
glib::spawn_future_local(clone!( glib::spawn_future_local(clone!(
#[weak] #[weak]
window, window,

View File

@@ -433,7 +433,7 @@ impl Window {
self.request(FrontendRequest::RemoveAuthorizedKey(fp)); self.request(FrontendRequest::RemoveAuthorizedKey(fp));
} }
pub(crate) fn request(&self, request: FrontendRequest) { fn request(&self, request: FrontendRequest) {
let mut requester = self.imp().frontend_request_writer.borrow_mut(); let mut requester = self.imp().frontend_request_writer.borrow_mut();
let requester = requester.as_mut().unwrap(); let requester = requester.as_mut().unwrap();
if let Err(e) = requester.request(request) { if let Err(e) = requester.request(request) {

View File

@@ -255,14 +255,6 @@ pub enum FrontendRequest {
UpdateEnterHook(u64, Option<String>), UpdateEnterHook(u64, Option<String>),
/// save config file /// save config file
SaveConfiguration, SaveConfiguration,
/// window identifier used to present input-capture / remote-desktop prompts
WindowIdentifier(WindowIdentifier),
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum WindowIdentifier {
Wayland(String),
X11(u32),
} }
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, Serialize, Deserialize)] #[derive(Clone, Copy, PartialEq, Eq, Debug, Default, Serialize, Deserialize)]

View File

@@ -1,14 +1,12 @@
use std::{ use std::{
cell::{Cell, RefCell}, cell::{Cell, RefCell},
rc::Rc, rc::Rc,
sync::{Arc, Mutex},
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use futures::StreamExt; use futures::StreamExt;
use input_capture::{ use input_capture::{
CaptureError, CaptureEvent, CaptureHandle, InputCapture, InputCaptureError, Position, CaptureError, CaptureEvent, CaptureHandle, InputCapture, InputCaptureError, Position,
WindowIdentifier,
}; };
use input_event::{Event, KeyboardEvent, scancode}; use input_event::{Event, KeyboardEvent, scancode};
use lan_mouse_proto::ProtoEvent; use lan_mouse_proto::ProtoEvent;
@@ -70,7 +68,6 @@ impl Capture {
backend: Option<input_capture::Backend>, backend: Option<input_capture::Backend>,
conn: LanMouseConnection, conn: LanMouseConnection,
release_bind: Vec<scancode::Linux>, release_bind: Vec<scancode::Linux>,
window_identifier: Arc<Mutex<Option<WindowIdentifier>>>,
) -> Self { ) -> Self {
let (request_tx, request_rx) = channel(); let (request_tx, request_rx) = channel();
let (event_tx, event_rx) = channel(); let (event_tx, event_rx) = channel();
@@ -85,7 +82,6 @@ impl Capture {
request_rx, request_rx,
release_bind: Rc::new(RefCell::new(release_bind)), release_bind: Rc::new(RefCell::new(release_bind)),
state: Default::default(), state: Default::default(),
window_identifier,
}; };
let task = spawn_local(capture_task.run()); let task = spawn_local(capture_task.run());
Self { Self {
@@ -170,7 +166,6 @@ struct CaptureTask {
release_bind: Rc<RefCell<Vec<scancode::Linux>>>, release_bind: Rc<RefCell<Vec<scancode::Linux>>>,
request_rx: Receiver<CaptureRequest>, request_rx: Receiver<CaptureRequest>,
state: State, state: State,
window_identifier: Arc<Mutex<Option<WindowIdentifier>>>,
} }
impl CaptureTask { impl CaptureTask {
@@ -205,7 +200,6 @@ impl CaptureTask {
} }
async fn run(mut self) { async fn run(mut self) {
tokio::time::sleep(Duration::from_secs(1)).await;
loop { loop {
if let Err(e) = self.do_capture().await { if let Err(e) = self.do_capture().await {
log::warn!("input capture exited: {e}"); log::warn!("input capture exited: {e}");
@@ -230,7 +224,7 @@ impl CaptureTask {
async fn do_capture(&mut self) -> Result<(), InputCaptureError> { async fn do_capture(&mut self) -> Result<(), InputCaptureError> {
/* allow cancelling capture request */ /* allow cancelling capture request */
let mut capture = tokio::select! { let mut capture = tokio::select! {
r = InputCapture::new(self.backend, self.window_identifier.clone()) => r?, r = InputCapture::new(self.backend) => r?,
_ = self.cancellation_token.cancelled() => return Ok(()), _ = self.cancellation_token.cancelled() => return Ok(()),
}; };

View File

@@ -1,5 +1,3 @@
use std::sync::{Arc, Mutex};
use crate::config::Config; use crate::config::Config;
use clap::Args; use clap::Args;
use futures::StreamExt; use futures::StreamExt;
@@ -14,7 +12,7 @@ pub async fn run(config: Config, _args: TestCaptureArgs) -> Result<(), InputCapt
log::info!("creating input capture"); log::info!("creating input capture");
let backend = config.capture_backend().map(|b| b.into()); let backend = config.capture_backend().map(|b| b.into());
loop { loop {
let mut input_capture = InputCapture::new(backend, Arc::new(Mutex::new(None))).await?; let mut input_capture = InputCapture::new(backend).await?;
log::info!("creating clients"); log::info!("creating clients");
input_capture.create(0, Position::Left).await?; input_capture.create(0, Position::Left).await?;
input_capture.create(4, Position::Left).await?; input_capture.create(4, Position::Left).await?;

View File

@@ -19,7 +19,7 @@ use std::{
collections::{HashMap, HashSet, VecDeque}, collections::{HashMap, HashSet, VecDeque},
io, io,
net::{IpAddr, SocketAddr}, net::{IpAddr, SocketAddr},
sync::{Arc, Mutex, RwLock}, sync::{Arc, RwLock},
}; };
use thiserror::Error; use thiserror::Error;
use tokio::{process::Command, signal, sync::Notify}; use tokio::{process::Command, signal, sync::Notify};
@@ -70,7 +70,6 @@ pub struct Service {
/// map from capture handle to connection info /// map from capture handle to connection info
incoming_conn_info: HashMap<ClientHandle, Incoming>, incoming_conn_info: HashMap<ClientHandle, Incoming>,
next_trigger_handle: u64, next_trigger_handle: u64,
window_identifier: Arc<Mutex<Option<input_capture::WindowIdentifier>>>,
} }
#[derive(Debug)] #[derive(Debug)]
@@ -102,13 +101,7 @@ impl Service {
// input capture + emulation // input capture + emulation
let capture_backend = config.capture_backend().map(|b| b.into()); let capture_backend = config.capture_backend().map(|b| b.into());
let window_identifier = Arc::new(Mutex::new(None)); let capture = Capture::new(capture_backend, conn, config.release_bind());
let capture = Capture::new(
capture_backend,
conn,
config.release_bind(),
window_identifier.clone(),
);
let emulation_backend = config.emulation_backend().map(|b| b.into()); let emulation_backend = config.emulation_backend().map(|b| b.into());
let emulation = Emulation::new(emulation_backend, listener); let emulation = Emulation::new(emulation_backend, listener);
@@ -133,7 +126,6 @@ impl Service {
incoming_conn_info: Default::default(), incoming_conn_info: Default::default(),
incoming_conns: Default::default(), incoming_conns: Default::default(),
next_trigger_handle: 0, next_trigger_handle: 0,
window_identifier,
}; };
Ok(service) Ok(service)
} }
@@ -226,20 +218,6 @@ impl Service {
self.update_enter_hook(handle, enter_hook) self.update_enter_hook(handle, enter_hook)
} }
FrontendRequest::SaveConfiguration => self.save_config(), FrontendRequest::SaveConfiguration => self.save_config(),
FrontendRequest::WindowIdentifier(handle) => {
log::info!("xdg-foreign handle: {handle:?}");
self.window_identifier
.lock()
.unwrap()
.replace(match handle {
lan_mouse_ipc::WindowIdentifier::Wayland(handle) => {
input_capture::WindowIdentifier::Wayland(handle)
}
lan_mouse_ipc::WindowIdentifier::X11(xid) => {
input_capture::WindowIdentifier::X11(xid)
}
});
}
} }
} }