1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#![warn(missing_docs, missing_debug_implementations)]
#![forbid(improper_ctypes, unsafe_op_in_unsafe_fn)]
#![cfg_attr(coverage, feature(no_coverage))]
use std::sync::Arc;
use wayland_backend::{
client::{InvalidId, ObjectData, ObjectId, WaylandError},
protocol::{Interface, Message},
};
mod conn;
mod event_queue;
pub mod globals;
pub mod backend {
pub use wayland_backend::client::{
Backend, InvalidId, NoWaylandLib, ObjectData, ObjectId, ReadEventsGuard, WaylandError,
WeakBackend,
};
pub use wayland_backend::protocol;
pub use wayland_backend::smallvec;
}
pub use wayland_backend::protocol::WEnum;
pub use conn::{ConnectError, Connection};
pub use event_queue::{DelegateDispatch, Dispatch, EventQueue, QueueHandle, QueueProxyData};
#[allow(missing_docs)]
pub mod protocol {
use self::__interfaces::*;
use crate as wayland_client;
pub mod __interfaces {
wayland_scanner::generate_interfaces!("wayland.xml");
}
wayland_scanner::generate_client_code!("wayland.xml");
}
pub trait Proxy: Sized {
type Event;
type Request;
fn interface() -> &'static Interface;
fn id(&self) -> ObjectId;
fn version(&self) -> u32;
fn data<U: Send + Sync + 'static>(&self) -> Option<&U>;
fn object_data(&self) -> Option<&Arc<dyn ObjectData>>;
fn backend(&self) -> &backend::WeakBackend;
fn from_id(conn: &Connection, id: ObjectId) -> Result<Self, InvalidId>;
fn send_request(&self, req: Self::Request) -> Result<(), InvalidId>;
fn send_constructor<I: Proxy>(
&self,
req: Self::Request,
data: Arc<dyn ObjectData>,
) -> Result<I, InvalidId>;
fn parse_event(
conn: &Connection,
msg: Message<ObjectId>,
) -> Result<(Self, Self::Event), DispatchError>;
#[allow(clippy::type_complexity)]
fn write_request(
&self,
conn: &Connection,
req: Self::Request,
) -> Result<(Message<ObjectId>, Option<(&'static Interface, u32)>), InvalidId>;
}
#[derive(thiserror::Error, Debug)]
pub enum DispatchError {
#[error("Bad message for interface {interface} : {msg:?}")]
BadMessage {
msg: Message<ObjectId>,
interface: &'static str,
},
#[error("Backend error: {0}")]
Backend(#[from] WaylandError),
}