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::xfixes;
29#[allow(unused_imports)]
30use super::xproto;
31
32pub use x11rb_protocol::protocol::composite::*;
33
34async fn major_opcode<Conn: RequestConnection + ?Sized>(conn: &Conn) -> Result<u8, ConnectionError> {
36 let info = conn.extension_information(X11_EXTENSION_NAME).await?;
37 let info = info.ok_or(ConnectionError::UnsupportedExtension)?;
38 Ok(info.major_opcode)
39}
40
41pub async fn query_version<Conn>(conn: &Conn, client_major_version: u32, client_minor_version: u32) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError>
51where
52 Conn: RequestConnection + ?Sized,
53{
54 let request0 = QueryVersionRequest {
55 client_major_version,
56 client_minor_version,
57 };
58 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
59 let slices = [IoSlice::new(&bytes[0])];
60 assert_eq!(slices.len(), bytes.len());
61 conn.send_request_with_reply(&slices, fds).await
62}
63pub async fn redirect_window<Conn>(conn: &Conn, window: xproto::Window, update: Redirect) -> Result<VoidCookie<'_, Conn>, ConnectionError>
79where
80 Conn: RequestConnection + ?Sized,
81{
82 let request0 = RedirectWindowRequest {
83 window,
84 update,
85 };
86 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
87 let slices = [IoSlice::new(&bytes[0])];
88 assert_eq!(slices.len(), bytes.len());
89 conn.send_request_without_reply(&slices, fds).await
90}
91pub async fn redirect_subwindows<Conn>(conn: &Conn, window: xproto::Window, update: Redirect) -> Result<VoidCookie<'_, Conn>, ConnectionError>
105where
106 Conn: RequestConnection + ?Sized,
107{
108 let request0 = RedirectSubwindowsRequest {
109 window,
110 update,
111 };
112 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
113 let slices = [IoSlice::new(&bytes[0])];
114 assert_eq!(slices.len(), bytes.len());
115 conn.send_request_without_reply(&slices, fds).await
116}
117pub async fn unredirect_window<Conn>(conn: &Conn, window: xproto::Window, update: Redirect) -> Result<VoidCookie<'_, Conn>, ConnectionError>
129where
130 Conn: RequestConnection + ?Sized,
131{
132 let request0 = UnredirectWindowRequest {
133 window,
134 update,
135 };
136 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
137 let slices = [IoSlice::new(&bytes[0])];
138 assert_eq!(slices.len(), bytes.len());
139 conn.send_request_without_reply(&slices, fds).await
140}
141pub async fn unredirect_subwindows<Conn>(conn: &Conn, window: xproto::Window, update: Redirect) -> Result<VoidCookie<'_, Conn>, ConnectionError>
153where
154 Conn: RequestConnection + ?Sized,
155{
156 let request0 = UnredirectSubwindowsRequest {
157 window,
158 update,
159 };
160 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
161 let slices = [IoSlice::new(&bytes[0])];
162 assert_eq!(slices.len(), bytes.len());
163 conn.send_request_without_reply(&slices, fds).await
164}
165pub async fn create_region_from_border_clip<Conn>(conn: &Conn, region: xfixes::Region, window: xproto::Window) -> Result<VoidCookie<'_, Conn>, ConnectionError>
166where
167 Conn: RequestConnection + ?Sized,
168{
169 let request0 = CreateRegionFromBorderClipRequest {
170 region,
171 window,
172 };
173 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
174 let slices = [IoSlice::new(&bytes[0])];
175 assert_eq!(slices.len(), bytes.len());
176 conn.send_request_without_reply(&slices, fds).await
177}
178pub async fn name_window_pixmap<Conn>(conn: &Conn, window: xproto::Window, pixmap: xproto::Pixmap) -> Result<VoidCookie<'_, Conn>, ConnectionError>
179where
180 Conn: RequestConnection + ?Sized,
181{
182 let request0 = NameWindowPixmapRequest {
183 window,
184 pixmap,
185 };
186 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
187 let slices = [IoSlice::new(&bytes[0])];
188 assert_eq!(slices.len(), bytes.len());
189 conn.send_request_without_reply(&slices, fds).await
190}
191pub async fn get_overlay_window<Conn>(conn: &Conn, window: xproto::Window) -> Result<Cookie<'_, Conn, GetOverlayWindowReply>, ConnectionError>
192where
193 Conn: RequestConnection + ?Sized,
194{
195 let request0 = GetOverlayWindowRequest {
196 window,
197 };
198 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
199 let slices = [IoSlice::new(&bytes[0])];
200 assert_eq!(slices.len(), bytes.len());
201 conn.send_request_with_reply(&slices, fds).await
202}
203pub async fn release_overlay_window<Conn>(conn: &Conn, window: xproto::Window) -> Result<VoidCookie<'_, Conn>, ConnectionError>
204where
205 Conn: RequestConnection + ?Sized,
206{
207 let request0 = ReleaseOverlayWindowRequest {
208 window,
209 };
210 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
211 let slices = [IoSlice::new(&bytes[0])];
212 assert_eq!(slices.len(), bytes.len());
213 conn.send_request_without_reply(&slices, fds).await
214}
215pub trait ConnectionExt: RequestConnection {
217 fn composite_query_version(&self, client_major_version: u32, client_minor_version: u32) -> Pin<Box<dyn Future<Output = Result<Cookie<'_, Self, QueryVersionReply>, ConnectionError>> + Send + '_>>
227 {
228 Box::pin(query_version(self, client_major_version, client_minor_version))
229 }
230 fn composite_redirect_window(&self, window: xproto::Window, update: Redirect) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
246 {
247 Box::pin(redirect_window(self, window, update))
248 }
249 fn composite_redirect_subwindows(&self, window: xproto::Window, update: Redirect) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
263 {
264 Box::pin(redirect_subwindows(self, window, update))
265 }
266 fn composite_unredirect_window(&self, window: xproto::Window, update: Redirect) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
278 {
279 Box::pin(unredirect_window(self, window, update))
280 }
281 fn composite_unredirect_subwindows(&self, window: xproto::Window, update: Redirect) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
293 {
294 Box::pin(unredirect_subwindows(self, window, update))
295 }
296 fn composite_create_region_from_border_clip(&self, region: xfixes::Region, window: xproto::Window) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
297 {
298 Box::pin(create_region_from_border_clip(self, region, window))
299 }
300 fn composite_name_window_pixmap(&self, window: xproto::Window, pixmap: xproto::Pixmap) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
301 {
302 Box::pin(name_window_pixmap(self, window, pixmap))
303 }
304 fn composite_get_overlay_window(&self, window: xproto::Window) -> Pin<Box<dyn Future<Output = Result<Cookie<'_, Self, GetOverlayWindowReply>, ConnectionError>> + Send + '_>>
305 {
306 Box::pin(get_overlay_window(self, window))
307 }
308 fn composite_release_overlay_window(&self, window: xproto::Window) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
309 {
310 Box::pin(release_overlay_window(self, window))
311 }
312}
313
314impl<C: RequestConnection + ?Sized> ConnectionExt for C {}