1#[derive(Debug, Error)]
2pub enum InputEmulationError {
3 #[error("error creating input-emulation: `{0}`")]
4 Create(#[from] EmulationCreationError),
5 #[error("error emulating input: `{0}`")]
6 Emulate(#[from] EmulationError),
7}
8
9#[cfg(all(
10 unix,
11 any(feature = "remote_desktop_portal", feature = "libei"),
12 not(target_os = "macos")
13))]
14use ashpd::{desktop::ResponseError, Error::Response};
15use std::io;
16use thiserror::Error;
17
18#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
19use wayland_client::{
20 backend::WaylandError,
21 globals::{BindError, GlobalError},
22 ConnectError, DispatchError,
23};
24
25#[derive(Debug, Error)]
26pub enum EmulationError {
27 #[error("event stream closed")]
28 EndOfStream,
29 #[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
30 #[error("libei error: `{0}`")]
31 Libei(#[from] reis::Error),
32 #[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
33 #[error("wayland error: `{0}`")]
34 Wayland(#[from] wayland_client::backend::WaylandError),
35 #[cfg(all(
36 unix,
37 any(feature = "remote_desktop_portal", feature = "libei"),
38 not(target_os = "macos")
39 ))]
40 #[error("xdg-desktop-portal: `{0}`")]
41 Ashpd(#[from] ashpd::Error),
42 #[error("io error: `{0}`")]
43 Io(#[from] io::Error),
44}
45
46#[derive(Debug, Error)]
47pub enum EmulationCreationError {
48 #[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
49 #[error("wlroots backend: `{0}`")]
50 Wlroots(#[from] WlrootsEmulationCreationError),
51 #[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
52 #[error("libei backend: `{0}`")]
53 Libei(#[from] LibeiEmulationCreationError),
54 #[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
55 #[error("xdg-desktop-portal: `{0}`")]
56 Xdp(#[from] XdpEmulationCreationError),
57 #[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
58 #[error("x11: `{0}`")]
59 X11(#[from] X11EmulationCreationError),
60 #[cfg(target_os = "macos")]
61 #[error("macos: `{0}`")]
62 MacOs(#[from] MacOSEmulationCreationError),
63 #[cfg(windows)]
64 #[error("windows: `{0}`")]
65 Windows(#[from] WindowsEmulationCreationError),
66 #[error("capture error")]
67 NoAvailableBackend,
68}
69
70impl EmulationCreationError {
71 pub(crate) fn cancelled_by_user(&self) -> bool {
73 #[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
74 if matches!(
75 self,
76 EmulationCreationError::Libei(LibeiEmulationCreationError::Ashpd(Response(
77 ResponseError::Cancelled,
78 )))
79 ) {
80 return true;
81 }
82 #[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
83 if matches!(
84 self,
85 EmulationCreationError::Xdp(XdpEmulationCreationError::Ashpd(Response(
86 ResponseError::Cancelled,
87 )))
88 ) {
89 return true;
90 }
91 false
92 }
93}
94
95#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
96#[derive(Debug, Error)]
97pub enum WlrootsEmulationCreationError {
98 #[error(transparent)]
99 Connect(#[from] ConnectError),
100 #[error(transparent)]
101 Global(#[from] GlobalError),
102 #[error(transparent)]
103 Wayland(#[from] WaylandError),
104 #[error(transparent)]
105 Bind(#[from] WaylandBindError),
106 #[error(transparent)]
107 Dispatch(#[from] DispatchError),
108 #[error(transparent)]
109 Io(#[from] std::io::Error),
110}
111
112#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
113#[derive(Debug, Error)]
114#[error("wayland protocol \"{protocol}\" not supported: {inner}")]
115pub struct WaylandBindError {
116 inner: BindError,
117 protocol: &'static str,
118}
119
120#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
121impl WaylandBindError {
122 pub(crate) fn new(inner: BindError, protocol: &'static str) -> Self {
123 Self { inner, protocol }
124 }
125}
126
127#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
128#[derive(Debug, Error)]
129pub enum LibeiEmulationCreationError {
130 #[error(transparent)]
131 Ashpd(#[from] ashpd::Error),
132 #[error(transparent)]
133 Io(#[from] std::io::Error),
134 #[error(transparent)]
135 Reis(#[from] reis::Error),
136}
137
138#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
139#[derive(Debug, Error)]
140pub enum XdpEmulationCreationError {
141 #[error(transparent)]
142 Ashpd(#[from] ashpd::Error),
143}
144
145#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
146#[derive(Debug, Error)]
147pub enum X11EmulationCreationError {
148 #[error("could not open display")]
149 OpenDisplay,
150}
151
152#[cfg(target_os = "macos")]
153#[derive(Debug, Error)]
154pub enum MacOSEmulationCreationError {
155 #[error("could not create event source")]
156 EventSourceCreation,
157}
158
159#[cfg(windows)]
160#[derive(Debug, Error)]
161pub enum WindowsEmulationCreationError {}