-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
117 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use std::{fmt::Display, io}; | ||
|
||
use thiserror::Error; | ||
use wayland_client::{backend::WaylandError, globals::{BindError, GlobalError}, ConnectError, DispatchError}; | ||
|
||
|
||
#[derive(Debug, Error)] | ||
pub enum EmulationCreationError { | ||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))] | ||
Wlroots(#[from] WlrootsEmulationCreationError), | ||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))] | ||
Libei(#[from] LibeiEmulationCreationError), | ||
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))] | ||
Xdp(#[from] XdpEmulationCreationError), | ||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))] | ||
X11(#[from] X11EmulationCreationError), | ||
} | ||
|
||
impl Display for EmulationCreationError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
let reason = match self { | ||
EmulationCreationError::Wlroots(e) => format!("wlroots backend: {e}"), | ||
EmulationCreationError::Libei(e) => todo!("libei backend: {e}"), | ||
EmulationCreationError::Xdp(e) => todo!("desktop portal backend: {e}"), | ||
EmulationCreationError::X11(e) => todo!("x11 backend: {e}"), | ||
}; | ||
write!(f, "could not create input emulation backend: {reason}") | ||
} | ||
} | ||
|
||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))] | ||
#[derive(Debug, Error)] | ||
pub enum WlrootsEmulationCreationError { | ||
Connect(#[from] ConnectError), | ||
Global(#[from] GlobalError), | ||
Wayland(#[from] WaylandError), | ||
Bind(#[from] WaylandBindError), | ||
Dispatch(#[from] DispatchError), | ||
Io(#[from] io::Error), | ||
} | ||
|
||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))] | ||
#[derive(Debug, Error)] | ||
pub struct WaylandBindError { | ||
inner: BindError, | ||
protocol: &'static str, | ||
} | ||
#[cfg(all(unix, feature = "wayland", 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")))] | ||
impl Display for WaylandBindError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!( | ||
f, | ||
"{} protocol not supported: {}", | ||
self.protocol, self.inner | ||
) | ||
} | ||
} | ||
|
||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))] | ||
impl Display for WlrootsEmulationCreationError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
WlrootsEmulationCreationError::Bind(e) => write!(f, "{e}"), | ||
WlrootsEmulationCreationError::Connect(e) => { | ||
write!(f, "could not connect to wayland compositor: {e}") | ||
} | ||
WlrootsEmulationCreationError::Global(e) => write!(f, "wayland error: {e}"), | ||
WlrootsEmulationCreationError::Wayland(e) => write!(f, "wayland error: {e}"), | ||
WlrootsEmulationCreationError::Dispatch(e) => { | ||
write!(f, "error dispatching wayland events: {e}") | ||
} | ||
WlrootsEmulationCreationError::Io(e) => write!(f, "io error: {e}"), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))] | ||
#[derive(Debug, Error)] | ||
pub enum LibeiEmulationCreationError {} | ||
|
||
|
||
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))] | ||
#[derive(Debug, Error)] | ||
pub enum XdpEmulationCreationError {} | ||
|
||
|
||
|
||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))] | ||
#[derive(Debug, Error)] | ||
pub enum X11EmulationCreationError {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
use anyhow::{anyhow, Result}; | ||
use std::{ | ||
collections::HashMap, | ||
os::{fd::OwnedFd, unix::net::UnixStream}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters