1#![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::dri3;
29#[allow(unused_imports)]
30use super::randr;
31#[allow(unused_imports)]
32use super::sync;
33#[allow(unused_imports)]
34use super::xfixes;
35#[allow(unused_imports)]
36use super::xproto;
37
38pub use x11rb_protocol::protocol::present::*;
39
40async fn major_opcode<Conn: RequestConnection + ?Sized>(conn: &Conn) -> Result<u8, ConnectionError> {
42 let info = conn.extension_information(X11_EXTENSION_NAME).await?;
43 let info = info.ok_or(ConnectionError::UnsupportedExtension)?;
44 Ok(info.major_opcode)
45}
46
47pub async fn query_version<Conn>(conn: &Conn, major_version: u32, minor_version: u32) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError>
48where
49 Conn: RequestConnection + ?Sized,
50{
51 let request0 = QueryVersionRequest {
52 major_version,
53 minor_version,
54 };
55 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
56 let slices = [IoSlice::new(&bytes[0])];
57 assert_eq!(slices.len(), bytes.len());
58 conn.send_request_with_reply(&slices, fds).await
59}
60pub async fn pixmap<'c, 'input, Conn>(conn: &'c Conn, window: xproto::Window, pixmap: xproto::Pixmap, serial: u32, valid: xfixes::Region, update: xfixes::Region, x_off: i16, y_off: i16, target_crtc: randr::Crtc, wait_fence: sync::Fence, idle_fence: sync::Fence, options: u32, target_msc: u64, divisor: u64, remainder: u64, notifies: &'input [Notify]) -> Result<VoidCookie<'c, Conn>, ConnectionError>
61where
62 Conn: RequestConnection + ?Sized,
63{
64 let request0 = PixmapRequest {
65 window,
66 pixmap,
67 serial,
68 valid,
69 update,
70 x_off,
71 y_off,
72 target_crtc,
73 wait_fence,
74 idle_fence,
75 options,
76 target_msc,
77 divisor,
78 remainder,
79 notifies: Cow::Borrowed(notifies),
80 };
81 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
82 let slices = [IoSlice::new(&bytes[0]), IoSlice::new(&bytes[1]), IoSlice::new(&bytes[2])];
83 assert_eq!(slices.len(), bytes.len());
84 conn.send_request_without_reply(&slices, fds).await
85}
86pub async fn notify_msc<Conn>(conn: &Conn, window: xproto::Window, serial: u32, target_msc: u64, divisor: u64, remainder: u64) -> Result<VoidCookie<'_, Conn>, ConnectionError>
87where
88 Conn: RequestConnection + ?Sized,
89{
90 let request0 = NotifyMSCRequest {
91 window,
92 serial,
93 target_msc,
94 divisor,
95 remainder,
96 };
97 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
98 let slices = [IoSlice::new(&bytes[0])];
99 assert_eq!(slices.len(), bytes.len());
100 conn.send_request_without_reply(&slices, fds).await
101}
102pub async fn select_input<Conn>(conn: &Conn, eid: Event, window: xproto::Window, event_mask: EventMask) -> Result<VoidCookie<'_, Conn>, ConnectionError>
103where
104 Conn: RequestConnection + ?Sized,
105{
106 let request0 = SelectInputRequest {
107 eid,
108 window,
109 event_mask,
110 };
111 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
112 let slices = [IoSlice::new(&bytes[0])];
113 assert_eq!(slices.len(), bytes.len());
114 conn.send_request_without_reply(&slices, fds).await
115}
116pub async fn query_capabilities<Conn>(conn: &Conn, target: u32) -> Result<Cookie<'_, Conn, QueryCapabilitiesReply>, ConnectionError>
117where
118 Conn: RequestConnection + ?Sized,
119{
120 let request0 = QueryCapabilitiesRequest {
121 target,
122 };
123 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
124 let slices = [IoSlice::new(&bytes[0])];
125 assert_eq!(slices.len(), bytes.len());
126 conn.send_request_with_reply(&slices, fds).await
127}
128pub async fn pixmap_synced<'c, 'input, Conn>(conn: &'c Conn, window: xproto::Window, pixmap: xproto::Pixmap, serial: u32, valid: xfixes::Region, update: xfixes::Region, x_off: i16, y_off: i16, target_crtc: randr::Crtc, acquire_syncobj: dri3::Syncobj, release_syncobj: dri3::Syncobj, acquire_point: u64, release_point: u64, options: u32, target_msc: u64, divisor: u64, remainder: u64, notifies: &'input [Notify]) -> Result<VoidCookie<'c, Conn>, ConnectionError>
129where
130 Conn: RequestConnection + ?Sized,
131{
132 let request0 = PixmapSyncedRequest {
133 window,
134 pixmap,
135 serial,
136 valid,
137 update,
138 x_off,
139 y_off,
140 target_crtc,
141 acquire_syncobj,
142 release_syncobj,
143 acquire_point,
144 release_point,
145 options,
146 target_msc,
147 divisor,
148 remainder,
149 notifies: Cow::Borrowed(notifies),
150 };
151 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
152 let slices = [IoSlice::new(&bytes[0]), IoSlice::new(&bytes[1]), IoSlice::new(&bytes[2])];
153 assert_eq!(slices.len(), bytes.len());
154 conn.send_request_without_reply(&slices, fds).await
155}
156pub trait ConnectionExt: RequestConnection {
158 fn present_query_version(&self, major_version: u32, minor_version: u32) -> Pin<Box<dyn Future<Output = Result<Cookie<'_, Self, QueryVersionReply>, ConnectionError>> + Send + '_>>
159 {
160 Box::pin(query_version(self, major_version, minor_version))
161 }
162 fn present_pixmap<'c, 'input, 'future>(&'c self, window: xproto::Window, pixmap: xproto::Pixmap, serial: u32, valid: xfixes::Region, update: xfixes::Region, x_off: i16, y_off: i16, target_crtc: randr::Crtc, wait_fence: sync::Fence, idle_fence: sync::Fence, options: u32, target_msc: u64, divisor: u64, remainder: u64, notifies: &'input [Notify]) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'c, Self>, ConnectionError>> + Send + 'future>>
163 where
164 'c: 'future,
165 'input: 'future,
166 {
167 Box::pin(self::pixmap(self, window, pixmap, serial, valid, update, x_off, y_off, target_crtc, wait_fence, idle_fence, options, target_msc, divisor, remainder, notifies))
168 }
169 fn present_notify_msc(&self, window: xproto::Window, serial: u32, target_msc: u64, divisor: u64, remainder: u64) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
170 {
171 Box::pin(notify_msc(self, window, serial, target_msc, divisor, remainder))
172 }
173 fn present_select_input(&self, eid: Event, window: xproto::Window, event_mask: EventMask) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
174 {
175 Box::pin(select_input(self, eid, window, event_mask))
176 }
177 fn present_query_capabilities(&self, target: u32) -> Pin<Box<dyn Future<Output = Result<Cookie<'_, Self, QueryCapabilitiesReply>, ConnectionError>> + Send + '_>>
178 {
179 Box::pin(query_capabilities(self, target))
180 }
181 fn present_pixmap_synced<'c, 'input, 'future>(&'c self, window: xproto::Window, pixmap: xproto::Pixmap, serial: u32, valid: xfixes::Region, update: xfixes::Region, x_off: i16, y_off: i16, target_crtc: randr::Crtc, acquire_syncobj: dri3::Syncobj, release_syncobj: dri3::Syncobj, acquire_point: u64, release_point: u64, options: u32, target_msc: u64, divisor: u64, remainder: u64, notifies: &'input [Notify]) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'c, Self>, ConnectionError>> + Send + 'future>>
182 where
183 'c: 'future,
184 'input: 'future,
185 {
186 Box::pin(pixmap_synced(self, window, pixmap, serial, valid, update, x_off, y_off, target_crtc, acquire_syncobj, release_syncobj, acquire_point, release_point, options, target_msc, divisor, remainder, notifies))
187 }
188}
189
190impl<C: RequestConnection + ?Sized> ConnectionExt for C {}