x11rb_async/protocol/
shm.rs

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;
25use std::future::Future;
26use std::pin::Pin;
27#[allow(unused_imports)]
28use super::xproto;
29
30pub use x11rb_protocol::protocol::shm::*;
31
32/// Get the major opcode of this extension
33async fn major_opcode<Conn: RequestConnection + ?Sized>(conn: &Conn) -> Result<u8, ConnectionError> {
34    let info = conn.extension_information(X11_EXTENSION_NAME).await?;
35    let info = info.ok_or(ConnectionError::UnsupportedExtension)?;
36    Ok(info.major_opcode)
37}
38
39/// Query the version of the MIT-SHM extension..
40///
41/// This is used to determine the version of the MIT-SHM extension supported by the
42/// X server.  Clients MUST NOT make other requests in this extension until a reply
43/// to this requests indicates the X server supports them.
44pub async fn query_version<Conn>(conn: &Conn) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError>
45where
46    Conn: RequestConnection + ?Sized,
47{
48    let request0 = QueryVersionRequest;
49    let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
50    let slices = [IoSlice::new(&bytes[0])];
51    assert_eq!(slices.len(), bytes.len());
52    conn.send_request_with_reply(&slices, fds).await
53}
54/// Attach a System V shared memory segment..
55///
56/// Attach a System V shared memory segment to the server.  This will fail unless
57/// the server has permission to map the segment.  The client may destroy the segment
58/// as soon as it receives a XCB_SHM_COMPLETION event with the shmseg value in this
59/// request and with the appropriate serial number.
60///
61/// # Fields
62///
63/// * `shmseg` - A shared memory segment ID created with xcb_generate_id().
64/// * `shmid` - The System V shared memory segment the server should map.
65/// * `read_only` - True if the segment shall be mapped read only by the X11 server, otherwise false.
66pub async fn attach<Conn>(conn: &Conn, shmseg: Seg, shmid: u32, read_only: bool) -> Result<VoidCookie<'_, Conn>, ConnectionError>
67where
68    Conn: RequestConnection + ?Sized,
69{
70    let request0 = AttachRequest {
71        shmseg,
72        shmid,
73        read_only,
74    };
75    let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
76    let slices = [IoSlice::new(&bytes[0])];
77    assert_eq!(slices.len(), bytes.len());
78    conn.send_request_without_reply(&slices, fds).await
79}
80/// Destroys the specified shared memory segment..
81///
82/// Destroys the specified shared memory segment.  This will never fail unless the
83/// segment number is incorrect.
84///
85/// # Fields
86///
87/// * `shmseg` - The segment to be destroyed.
88pub async fn detach<Conn>(conn: &Conn, shmseg: Seg) -> Result<VoidCookie<'_, Conn>, ConnectionError>
89where
90    Conn: RequestConnection + ?Sized,
91{
92    let request0 = DetachRequest {
93        shmseg,
94    };
95    let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
96    let slices = [IoSlice::new(&bytes[0])];
97    assert_eq!(slices.len(), bytes.len());
98    conn.send_request_without_reply(&slices, fds).await
99}
100/// Copy data from the shared memory to the specified drawable..
101///
102/// Copy data from the shared memory to the specified drawable.  The amount of bytes
103/// written to the destination image is always equal to the number of bytes read
104/// from the shared memory segment.
105///
106/// # Fields
107///
108/// * `drawable` - The drawable to draw to.
109/// * `gc` - The graphics context to use.
110/// * `total_width` - The total width of the source image.
111/// * `total_height` - The total height of the source image.
112/// * `src_x` - The source X coordinate of the sub-image to copy.
113/// * `src_y` - The source Y coordinate of the sub-image to copy.
114/// * `src_width` - The width, in source image coordinates, of the data to copy from the source.
115/// The X server will use this to determine the amount of data to copy.  The amount
116/// of the destination image that is overwritten is determined automatically.
117/// * `src_height` - The height, in source image coordinates, of the data to copy from the source.
118/// The X server will use this to determine the amount of data to copy.  The amount
119/// of the destination image that is overwritten is determined automatically.
120/// * `dst_x` - The X coordinate on the destination drawable to copy to.
121/// * `dst_y` - The Y coordinate on the destination drawable to copy to.
122/// * `depth` - The depth to use.
123/// * `format` - The format of the image being drawn.  If it is XYBitmap, depth must be 1, or a
124/// "BadMatch" error results.  The foreground pixel in the GC determines the source
125/// for the one bits in the image, and the background pixel determines the source
126/// for the zero bits.  For XYPixmap and ZPixmap, the depth must match the depth of
127/// the drawable, or a "BadMatch" error results.
128/// * `send_event` - True if the server should send an XCB_SHM_COMPLETION event when the blit
129/// completes.
130/// * `offset` - The offset that the source image starts at.
131pub async 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>
132where
133    Conn: RequestConnection + ?Sized,
134{
135    let request0 = PutImageRequest {
136        drawable,
137        gc,
138        total_width,
139        total_height,
140        src_x,
141        src_y,
142        src_width,
143        src_height,
144        dst_x,
145        dst_y,
146        depth,
147        format,
148        send_event,
149        shmseg,
150        offset,
151    };
152    let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
153    let slices = [IoSlice::new(&bytes[0])];
154    assert_eq!(slices.len(), bytes.len());
155    conn.send_request_without_reply(&slices, fds).await
156}
157/// Copies data from the specified drawable to the shared memory segment..
158///
159/// Copy data from the specified drawable to the shared memory segment.  The amount
160/// of bytes written to the destination image is always equal to the number of bytes
161/// read from the shared memory segment.
162///
163/// # Fields
164///
165/// * `drawable` - The drawable to copy the image out of.
166/// * `x` - The X coordinate in the drawable to begin copying at.
167/// * `y` - The Y coordinate in the drawable to begin copying at.
168/// * `width` - The width of the image to copy.
169/// * `height` - The height of the image to copy.
170/// * `plane_mask` - A mask that determines which planes are used.
171/// * `format` - The format to use for the copy (???).
172/// * `shmseg` - The destination shared memory segment.
173/// * `offset` - The offset in the shared memory segment to copy data to.
174pub async 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>
175where
176    Conn: RequestConnection + ?Sized,
177{
178    let request0 = GetImageRequest {
179        drawable,
180        x,
181        y,
182        width,
183        height,
184        plane_mask,
185        format,
186        shmseg,
187        offset,
188    };
189    let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
190    let slices = [IoSlice::new(&bytes[0])];
191    assert_eq!(slices.len(), bytes.len());
192    conn.send_request_with_reply(&slices, fds).await
193}
194/// Create a pixmap backed by shared memory..
195///
196/// Create a pixmap backed by shared memory.  Writes to the shared memory will be
197/// reflected in the contents of the pixmap, and writes to the pixmap will be
198/// reflected in the contents of the shared memory.
199///
200/// # Fields
201///
202/// * `pid` - A pixmap ID created with xcb_generate_id().
203/// * `drawable` - The drawable to create the pixmap in.
204/// * `width` - The width of the pixmap to create.  Must be nonzero, or a Value error results.
205/// * `height` - The height of the pixmap to create.  Must be nonzero, or a Value error results.
206/// * `depth` - The depth of the pixmap to create.  Must be nonzero, or a Value error results.
207/// * `shmseg` - The shared memory segment to use to create the pixmap.
208/// * `offset` - The offset in the segment to create the pixmap at.
209pub async 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>
210where
211    Conn: RequestConnection + ?Sized,
212{
213    let request0 = CreatePixmapRequest {
214        pid,
215        drawable,
216        width,
217        height,
218        depth,
219        shmseg,
220        offset,
221    };
222    let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
223    let slices = [IoSlice::new(&bytes[0])];
224    assert_eq!(slices.len(), bytes.len());
225    conn.send_request_without_reply(&slices, fds).await
226}
227/// Create a shared memory segment.
228///
229/// Create a shared memory segment.  The file descriptor will be mapped at offset
230/// zero, and the size will be obtained using fstat().  A zero size will result in a
231/// Value error.
232///
233/// # Fields
234///
235/// * `shmseg` - A shared memory segment ID created with xcb_generate_id().
236/// * `shm_fd` - The file descriptor the server should mmap().
237/// * `read_only` - True if the segment shall be mapped read only by the X11 server, otherwise false.
238pub async fn attach_fd<Conn, A>(conn: &Conn, shmseg: Seg, shm_fd: A, read_only: bool) -> Result<VoidCookie<'_, Conn>, ConnectionError>
239where
240    Conn: RequestConnection + ?Sized,
241    A: Into<RawFdContainer> + Send,
242{
243    let shm_fd: RawFdContainer = shm_fd.into();
244    let request0 = AttachFdRequest {
245        shmseg,
246        shm_fd,
247        read_only,
248    };
249    let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
250    let slices = [IoSlice::new(&bytes[0])];
251    assert_eq!(slices.len(), bytes.len());
252    conn.send_request_without_reply(&slices, fds).await
253}
254/// Asks the server to allocate a shared memory segment..
255///
256/// Asks the server to allocate a shared memory segment.  The server’s reply will
257/// include a file descriptor for the client to pass to mmap().
258///
259/// # Fields
260///
261/// * `shmseg` - A shared memory segment ID created with xcb_generate_id().
262/// * `size` - The size of the segment to create.
263/// * `read_only` - True if the server should map the segment read-only; otherwise false.
264pub async fn create_segment<Conn>(conn: &Conn, shmseg: Seg, size: u32, read_only: bool) -> Result<CookieWithFds<'_, Conn, CreateSegmentReply>, ConnectionError>
265where
266    Conn: RequestConnection + ?Sized,
267{
268    let request0 = CreateSegmentRequest {
269        shmseg,
270        size,
271        read_only,
272    };
273    let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
274    let slices = [IoSlice::new(&bytes[0])];
275    assert_eq!(slices.len(), bytes.len());
276    conn.send_request_with_reply_with_fds(&slices, fds).await
277}
278/// Extension trait defining the requests of this extension.
279pub trait ConnectionExt: RequestConnection {
280    /// Query the version of the MIT-SHM extension..
281    ///
282    /// This is used to determine the version of the MIT-SHM extension supported by the
283    /// X server.  Clients MUST NOT make other requests in this extension until a reply
284    /// to this requests indicates the X server supports them.
285    fn shm_query_version(&self) -> Pin<Box<dyn Future<Output = Result<Cookie<'_, Self, QueryVersionReply>, ConnectionError>> + Send + '_>>
286    {
287        Box::pin(query_version(self))
288    }
289    /// Attach a System V shared memory segment..
290    ///
291    /// Attach a System V shared memory segment to the server.  This will fail unless
292    /// the server has permission to map the segment.  The client may destroy the segment
293    /// as soon as it receives a XCB_SHM_COMPLETION event with the shmseg value in this
294    /// request and with the appropriate serial number.
295    ///
296    /// # Fields
297    ///
298    /// * `shmseg` - A shared memory segment ID created with xcb_generate_id().
299    /// * `shmid` - The System V shared memory segment the server should map.
300    /// * `read_only` - True if the segment shall be mapped read only by the X11 server, otherwise false.
301    fn shm_attach(&self, shmseg: Seg, shmid: u32, read_only: bool) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
302    {
303        Box::pin(attach(self, shmseg, shmid, read_only))
304    }
305    /// Destroys the specified shared memory segment..
306    ///
307    /// Destroys the specified shared memory segment.  This will never fail unless the
308    /// segment number is incorrect.
309    ///
310    /// # Fields
311    ///
312    /// * `shmseg` - The segment to be destroyed.
313    fn shm_detach(&self, shmseg: Seg) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
314    {
315        Box::pin(detach(self, shmseg))
316    }
317    /// Copy data from the shared memory to the specified drawable..
318    ///
319    /// Copy data from the shared memory to the specified drawable.  The amount of bytes
320    /// written to the destination image is always equal to the number of bytes read
321    /// from the shared memory segment.
322    ///
323    /// # Fields
324    ///
325    /// * `drawable` - The drawable to draw to.
326    /// * `gc` - The graphics context to use.
327    /// * `total_width` - The total width of the source image.
328    /// * `total_height` - The total height of the source image.
329    /// * `src_x` - The source X coordinate of the sub-image to copy.
330    /// * `src_y` - The source Y coordinate of the sub-image to copy.
331    /// * `src_width` - The width, in source image coordinates, of the data to copy from the source.
332    /// The X server will use this to determine the amount of data to copy.  The amount
333    /// of the destination image that is overwritten is determined automatically.
334    /// * `src_height` - The height, in source image coordinates, of the data to copy from the source.
335    /// The X server will use this to determine the amount of data to copy.  The amount
336    /// of the destination image that is overwritten is determined automatically.
337    /// * `dst_x` - The X coordinate on the destination drawable to copy to.
338    /// * `dst_y` - The Y coordinate on the destination drawable to copy to.
339    /// * `depth` - The depth to use.
340    /// * `format` - The format of the image being drawn.  If it is XYBitmap, depth must be 1, or a
341    /// "BadMatch" error results.  The foreground pixel in the GC determines the source
342    /// for the one bits in the image, and the background pixel determines the source
343    /// for the zero bits.  For XYPixmap and ZPixmap, the depth must match the depth of
344    /// the drawable, or a "BadMatch" error results.
345    /// * `send_event` - True if the server should send an XCB_SHM_COMPLETION event when the blit
346    /// completes.
347    /// * `offset` - The offset that the source image starts at.
348    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) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
349    {
350        Box::pin(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))
351    }
352    /// Copies data from the specified drawable to the shared memory segment..
353    ///
354    /// Copy data from the specified drawable to the shared memory segment.  The amount
355    /// of bytes written to the destination image is always equal to the number of bytes
356    /// read from the shared memory segment.
357    ///
358    /// # Fields
359    ///
360    /// * `drawable` - The drawable to copy the image out of.
361    /// * `x` - The X coordinate in the drawable to begin copying at.
362    /// * `y` - The Y coordinate in the drawable to begin copying at.
363    /// * `width` - The width of the image to copy.
364    /// * `height` - The height of the image to copy.
365    /// * `plane_mask` - A mask that determines which planes are used.
366    /// * `format` - The format to use for the copy (???).
367    /// * `shmseg` - The destination shared memory segment.
368    /// * `offset` - The offset in the shared memory segment to copy data to.
369    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) -> Pin<Box<dyn Future<Output = Result<Cookie<'_, Self, GetImageReply>, ConnectionError>> + Send + '_>>
370    {
371        Box::pin(get_image(self, drawable, x, y, width, height, plane_mask, format, shmseg, offset))
372    }
373    /// Create a pixmap backed by shared memory..
374    ///
375    /// Create a pixmap backed by shared memory.  Writes to the shared memory will be
376    /// reflected in the contents of the pixmap, and writes to the pixmap will be
377    /// reflected in the contents of the shared memory.
378    ///
379    /// # Fields
380    ///
381    /// * `pid` - A pixmap ID created with xcb_generate_id().
382    /// * `drawable` - The drawable to create the pixmap in.
383    /// * `width` - The width of the pixmap to create.  Must be nonzero, or a Value error results.
384    /// * `height` - The height of the pixmap to create.  Must be nonzero, or a Value error results.
385    /// * `depth` - The depth of the pixmap to create.  Must be nonzero, or a Value error results.
386    /// * `shmseg` - The shared memory segment to use to create the pixmap.
387    /// * `offset` - The offset in the segment to create the pixmap at.
388    fn shm_create_pixmap(&self, pid: xproto::Pixmap, drawable: xproto::Drawable, width: u16, height: u16, depth: u8, shmseg: Seg, offset: u32) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
389    {
390        Box::pin(create_pixmap(self, pid, drawable, width, height, depth, shmseg, offset))
391    }
392    /// Create a shared memory segment.
393    ///
394    /// Create a shared memory segment.  The file descriptor will be mapped at offset
395    /// zero, and the size will be obtained using fstat().  A zero size will result in a
396    /// Value error.
397    ///
398    /// # Fields
399    ///
400    /// * `shmseg` - A shared memory segment ID created with xcb_generate_id().
401    /// * `shm_fd` - The file descriptor the server should mmap().
402    /// * `read_only` - True if the segment shall be mapped read only by the X11 server, otherwise false.
403    fn shm_attach_fd<A>(&self, shmseg: Seg, shm_fd: A, read_only: bool) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
404    where
405        A: Into<RawFdContainer> + Send + 'static,
406    {
407        Box::pin(attach_fd(self, shmseg, shm_fd, read_only))
408    }
409    /// Asks the server to allocate a shared memory segment..
410    ///
411    /// Asks the server to allocate a shared memory segment.  The server’s reply will
412    /// include a file descriptor for the client to pass to mmap().
413    ///
414    /// # Fields
415    ///
416    /// * `shmseg` - A shared memory segment ID created with xcb_generate_id().
417    /// * `size` - The size of the segment to create.
418    /// * `read_only` - True if the server should map the segment read-only; otherwise false.
419    fn shm_create_segment(&self, shmseg: Seg, size: u32, read_only: bool) -> Pin<Box<dyn Future<Output = Result<CookieWithFds<'_, Self, CreateSegmentReply>, ConnectionError>> + Send + '_>>
420    {
421        Box::pin(create_segment(self, shmseg, size, read_only))
422    }
423}
424
425impl<C: RequestConnection + ?Sized> ConnectionExt for C {}