1// This file contains generated code. Do not edit directly.
2// To regenerate this, run 'make'.
3
4//! Bindings to the `Shm` X11 extension.
5
6#![allow(clippy::too_many_arguments)]
7
8#[allow(unused_imports)]
9use std::borrow::Cow;
10#[allow(unused_imports)]
11use std::convert::TryInto;
12#[allow(unused_imports)]
13use crate::utils::RawFdContainer;
14#[allow(unused_imports)]
15use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd};
16use std::io::IoSlice;
17use crate::connection::RequestConnection;
18#[allow(unused_imports)]
19use crate::connection::Connection as X11Connection;
20#[allow(unused_imports)]
21use crate::cookie::{Cookie, CookieWithFds, VoidCookie};
22use crate::errors::ConnectionError;
23#[allow(unused_imports)]
24use crate::errors::ReplyOrIdError;
25#[allow(unused_imports)]
26use super::xproto;
27
28pub use x11rb_protocol::protocol::shm::*;
29
30/// Get the major opcode of this extension
31fn major_opcode<Conn: RequestConnection + ?Sized>(conn: &Conn) -> Result<u8, ConnectionError> {
32 let info: Option = conn.extension_information(X11_EXTENSION_NAME)?;
33 let info: ExtensionInformation = info.ok_or(err:ConnectionError::UnsupportedExtension)?;
34 Ok(info.major_opcode)
35}
36
37pub fn query_version<Conn>(conn: &Conn) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError>
38where
39 Conn: RequestConnection + ?Sized,
40{
41 let request0: QueryVersionRequest = QueryVersionRequest;
42 let (bytes: Vec>, fds: Vec) = request0.serialize(major_opcode:major_opcode(conn)?);
43 let slices: Vec> = bytes.iter().map(|b: &Cow<'_, [u8]>| IoSlice::new(buf:b)).collect::<Vec<_>>();
44 conn.send_request_with_reply(&slices, fds)
45}
46
47pub fn attach<Conn>(conn: &Conn, shmseg: Seg, shmid: u32, read_only: bool) -> Result<VoidCookie<'_, Conn>, ConnectionError>
48where
49 Conn: RequestConnection + ?Sized,
50{
51 let request0: AttachRequest = AttachRequest {
52 shmseg,
53 shmid,
54 read_only,
55 };
56 let (bytes: Vec>, fds: Vec) = request0.serialize(major_opcode:major_opcode(conn)?);
57 let slices: Vec> = bytes.iter().map(|b: &Cow<'_, [u8]>| IoSlice::new(buf:b)).collect::<Vec<_>>();
58 conn.send_request_without_reply(&slices, fds)
59}
60
61pub fn detach<Conn>(conn: &Conn, shmseg: Seg) -> Result<VoidCookie<'_, Conn>, ConnectionError>
62where
63 Conn: RequestConnection + ?Sized,
64{
65 let request0: DetachRequest = DetachRequest {
66 shmseg,
67 };
68 let (bytes: Vec>, fds: Vec) = request0.serialize(major_opcode:major_opcode(conn)?);
69 let slices: Vec> = bytes.iter().map(|b: &Cow<'_, [u8]>| IoSlice::new(buf:b)).collect::<Vec<_>>();
70 conn.send_request_without_reply(&slices, fds)
71}
72
73pub fn put_image<Conn>(conn: &Conn, drawable: xproto::Drawable, gc: xproto::Gcontext, total_width: u16, total_height: u16, src_x: u16, src_y: u16, src_width: u16, src_height: u16, dst_x: i16, dst_y: i16, depth: u8, format: u8, send_event: bool, shmseg: Seg, offset: u32) -> Result<VoidCookie<'_, Conn>, ConnectionError>
74where
75 Conn: RequestConnection + ?Sized,
76{
77 let request0: PutImageRequest = PutImageRequest {
78 drawable,
79 gc,
80 total_width,
81 total_height,
82 src_x,
83 src_y,
84 src_width,
85 src_height,
86 dst_x,
87 dst_y,
88 depth,
89 format,
90 send_event,
91 shmseg,
92 offset,
93 };
94 let (bytes: Vec>, fds: Vec) = request0.serialize(major_opcode:major_opcode(conn)?);
95 let slices: Vec> = bytes.iter().map(|b: &Cow<'_, [u8]>| IoSlice::new(buf:b)).collect::<Vec<_>>();
96 conn.send_request_without_reply(&slices, fds)
97}
98
99pub fn get_image<Conn>(conn: &Conn, drawable: xproto::Drawable, x: i16, y: i16, width: u16, height: u16, plane_mask: u32, format: u8, shmseg: Seg, offset: u32) -> Result<Cookie<'_, Conn, GetImageReply>, ConnectionError>
100where
101 Conn: RequestConnection + ?Sized,
102{
103 let request0: GetImageRequest = GetImageRequest {
104 drawable,
105 x,
106 y,
107 width,
108 height,
109 plane_mask,
110 format,
111 shmseg,
112 offset,
113 };
114 let (bytes: Vec>, fds: Vec) = request0.serialize(major_opcode:major_opcode(conn)?);
115 let slices: Vec> = bytes.iter().map(|b: &Cow<'_, [u8]>| IoSlice::new(buf:b)).collect::<Vec<_>>();
116 conn.send_request_with_reply(&slices, fds)
117}
118
119pub fn create_pixmap<Conn>(conn: &Conn, pid: xproto::Pixmap, drawable: xproto::Drawable, width: u16, height: u16, depth: u8, shmseg: Seg, offset: u32) -> Result<VoidCookie<'_, Conn>, ConnectionError>
120where
121 Conn: RequestConnection + ?Sized,
122{
123 let request0: CreatePixmapRequest = CreatePixmapRequest {
124 pid,
125 drawable,
126 width,
127 height,
128 depth,
129 shmseg,
130 offset,
131 };
132 let (bytes: Vec>, fds: Vec) = request0.serialize(major_opcode:major_opcode(conn)?);
133 let slices: Vec> = bytes.iter().map(|b: &Cow<'_, [u8]>| IoSlice::new(buf:b)).collect::<Vec<_>>();
134 conn.send_request_without_reply(&slices, fds)
135}
136
137pub fn attach_fd<Conn, A>(conn: &Conn, shmseg: Seg, shm_fd: A, read_only: bool) -> Result<VoidCookie<'_, Conn>, ConnectionError>
138where
139 Conn: RequestConnection + ?Sized,
140 A: Into<RawFdContainer>,
141{
142 let shm_fd: RawFdContainer = shm_fd.into();
143 let request0: AttachFdRequest = AttachFdRequest {
144 shmseg,
145 shm_fd,
146 read_only,
147 };
148 let (bytes: Vec>, fds: Vec) = request0.serialize(major_opcode:major_opcode(conn)?);
149 let slices: Vec> = bytes.iter().map(|b: &Cow<'_, [u8]>| IoSlice::new(buf:b)).collect::<Vec<_>>();
150 conn.send_request_without_reply(&slices, fds)
151}
152
153pub fn create_segment<Conn>(conn: &Conn, shmseg: Seg, size: u32, read_only: bool) -> Result<CookieWithFds<'_, Conn, CreateSegmentReply>, ConnectionError>
154where
155 Conn: RequestConnection + ?Sized,
156{
157 let request0: CreateSegmentRequest = CreateSegmentRequest {
158 shmseg,
159 size,
160 read_only,
161 };
162 let (bytes: Vec>, fds: Vec) = request0.serialize(major_opcode:major_opcode(conn)?);
163 let slices: Vec> = bytes.iter().map(|b: &Cow<'_, [u8]>| IoSlice::new(buf:b)).collect::<Vec<_>>();
164 conn.send_request_with_reply_with_fds(&slices, fds)
165}
166
167/// Extension trait defining the requests of this extension.
168pub trait ConnectionExt: RequestConnection {
169 fn shm_query_version(&self) -> Result<Cookie<'_, Self, QueryVersionReply>, ConnectionError>
170 {
171 query_version(self)
172 }
173 fn shm_attach(&self, shmseg: Seg, shmid: u32, read_only: bool) -> Result<VoidCookie<'_, Self>, ConnectionError>
174 {
175 attach(self, shmseg, shmid, read_only)
176 }
177 fn shm_detach(&self, shmseg: Seg) -> Result<VoidCookie<'_, Self>, ConnectionError>
178 {
179 detach(self, shmseg)
180 }
181 fn shm_put_image(&self, drawable: xproto::Drawable, gc: xproto::Gcontext, total_width: u16, total_height: u16, src_x: u16, src_y: u16, src_width: u16, src_height: u16, dst_x: i16, dst_y: i16, depth: u8, format: u8, send_event: bool, shmseg: Seg, offset: u32) -> Result<VoidCookie<'_, Self>, ConnectionError>
182 {
183 put_image(self, drawable, gc, total_width, total_height, src_x, src_y, src_width, src_height, dst_x, dst_y, depth, format, send_event, shmseg, offset)
184 }
185 fn shm_get_image(&self, drawable: xproto::Drawable, x: i16, y: i16, width: u16, height: u16, plane_mask: u32, format: u8, shmseg: Seg, offset: u32) -> Result<Cookie<'_, Self, GetImageReply>, ConnectionError>
186 {
187 get_image(self, drawable, x, y, width, height, plane_mask, format, shmseg, offset)
188 }
189 fn shm_create_pixmap(&self, pid: xproto::Pixmap, drawable: xproto::Drawable, width: u16, height: u16, depth: u8, shmseg: Seg, offset: u32) -> Result<VoidCookie<'_, Self>, ConnectionError>
190 {
191 create_pixmap(self, pid, drawable, width, height, depth, shmseg, offset)
192 }
193 fn shm_attach_fd<A>(&self, shmseg: Seg, shm_fd: A, read_only: bool) -> Result<VoidCookie<'_, Self>, ConnectionError>
194 where
195 A: Into<RawFdContainer>,
196 {
197 attach_fd(self, shmseg, shm_fd, read_only)
198 }
199 fn shm_create_segment(&self, shmseg: Seg, size: u32, read_only: bool) -> Result<CookieWithFds<'_, Self, CreateSegmentReply>, ConnectionError>
200 {
201 create_segment(self, shmseg, size, read_only)
202 }
203}
204
205impl<C: RequestConnection + ?Sized> ConnectionExt for C {}
206
207/// A RAII-like wrapper around a [Seg].
208///
209/// Instances of this struct represent a Seg that is freed in `Drop`.
210///
211/// Any errors during `Drop` are silently ignored. Most likely an error here means that your
212/// X11 connection is broken and later requests will also fail.
213#[derive(Debug)]
214pub struct SegWrapper<'c, C: RequestConnection>(&'c C, Seg);
215
216impl<'c, C: RequestConnection> SegWrapper<'c, C>
217{
218 /// Assume ownership of the given resource and destroy it in `Drop`.
219 pub fn for_seg(conn: &'c C, id: Seg) -> Self {
220 SegWrapper(conn, id)
221 }
222
223 /// Get the XID of the wrapped resource
224 pub fn seg(&self) -> Seg {
225 self.1
226 }
227
228 /// Assume ownership of the XID of the wrapped resource
229 ///
230 /// This function destroys this wrapper without freeing the underlying resource.
231 pub fn into_seg(self) -> Seg {
232 let id: u32 = self.1;
233 std::mem::forget(self);
234 id
235 }
236}
237
238impl<'c, C: X11Connection> SegWrapper<'c, C>
239{
240
241 /// Create a new Seg and return a Seg wrapper and a cookie.
242 ///
243 /// This is a thin wrapper around [attach] that allocates an id for the Seg.
244 /// This function returns the resulting `SegWrapper` that owns the created Seg and frees
245 /// it in `Drop`. This also returns a `VoidCookie` that comes from the call to
246 /// [attach].
247 ///
248 /// Errors can come from the call to [X11Connection::generate_id] or [attach].
249 pub fn attach_and_get_cookie(conn: &'c C, shmid: u32, read_only: bool) -> Result<(Self, VoidCookie<'c, C>), ReplyOrIdError>
250 {
251 let shmseg = conn.generate_id()?;
252 let cookie = attach(conn, shmseg, shmid, read_only)?;
253 Ok((Self::for_seg(conn, shmseg), cookie))
254 }
255
256 /// Create a new Seg and return a Seg wrapper
257 ///
258 /// This is a thin wrapper around [attach] that allocates an id for the Seg.
259 /// This function returns the resulting `SegWrapper` that owns the created Seg and frees
260 /// it in `Drop`.
261 ///
262 /// Errors can come from the call to [X11Connection::generate_id] or [attach].
263 pub fn attach(conn: &'c C, shmid: u32, read_only: bool) -> Result<Self, ReplyOrIdError>
264 {
265 Ok(Self::attach_and_get_cookie(conn, shmid, read_only)?.0)
266 }
267
268 /// Create a new Seg and return a Seg wrapper and a cookie.
269 ///
270 /// This is a thin wrapper around [attach_fd] that allocates an id for the Seg.
271 /// This function returns the resulting `SegWrapper` that owns the created Seg and frees
272 /// it in `Drop`. This also returns a `VoidCookie` that comes from the call to
273 /// [attach_fd].
274 ///
275 /// Errors can come from the call to [X11Connection::generate_id] or [attach_fd].
276 pub fn attach_fd_and_get_cookie<A>(conn: &'c C, shm_fd: A, read_only: bool) -> Result<(Self, VoidCookie<'c, C>), ReplyOrIdError>
277 where
278 A: Into<RawFdContainer>,
279 {
280 let shmseg = conn.generate_id()?;
281 let cookie = attach_fd(conn, shmseg, shm_fd, read_only)?;
282 Ok((Self::for_seg(conn, shmseg), cookie))
283 }
284
285 /// Create a new Seg and return a Seg wrapper
286 ///
287 /// This is a thin wrapper around [attach_fd] that allocates an id for the Seg.
288 /// This function returns the resulting `SegWrapper` that owns the created Seg and frees
289 /// it in `Drop`.
290 ///
291 /// Errors can come from the call to [X11Connection::generate_id] or [attach_fd].
292 pub fn attach_fd<A>(conn: &'c C, shm_fd: A, read_only: bool) -> Result<Self, ReplyOrIdError>
293 where
294 A: Into<RawFdContainer>,
295 {
296 Ok(Self::attach_fd_and_get_cookie(conn, shm_fd, read_only)?.0)
297 }
298}
299
300impl<C: RequestConnection> From<&SegWrapper<'_, C>> for Seg {
301 fn from(from: &SegWrapper<'_, C>) -> Self {
302 from.1
303 }
304}
305
306impl<C: RequestConnection> Drop for SegWrapper<'_, C> {
307 fn drop(&mut self) {
308 let _ = detach(self.0, self.1);
309 }
310}
311