1 // This file contains generated code. Do not edit directly. 2 // To regenerate this, run 'make'. 3 4 //! Bindings to the `Composite` X11 extension. 5 6 #![allow(clippy::too_many_arguments)] 7 8 #[allow(unused_imports)] 9 use std::borrow::Cow; 10 use std::convert::TryFrom; 11 #[allow(unused_imports)] 12 use std::convert::TryInto; 13 use std::io::IoSlice; 14 #[allow(unused_imports)] 15 use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; 16 #[allow(unused_imports)] 17 use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; 18 use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; 19 #[allow(unused_imports)] 20 use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; 21 use crate::errors::{ConnectionError, ParseError}; 22 use super::xfixes; 23 use super::xproto; 24 25 /// The X11 name of the extension for QueryExtension 26 pub const X11_EXTENSION_NAME: &str = "Composite"; 27 28 /// The version number of this extension that this client library supports. 29 /// 30 /// This constant contains the version number of this extension that is supported 31 /// by this build of x11rb. For most things, it does not make sense to use this 32 /// information. If you need to send a `QueryVersion`, it is recommended to instead 33 /// send the maximum version of the extension that you need. 34 pub const X11_XML_VERSION: (u32, u32) = (0, 4); 35 36 #[derive(Clone, Copy, PartialEq, Eq)] 37 pub struct Redirect(u8); 38 impl Redirect { 39 pub const AUTOMATIC: Self = Self(0); 40 pub const MANUAL: Self = Self(1); 41 } 42 impl From<Redirect> for u8 { 43 #[inline] 44 fn from(input: Redirect) -> Self { 45 input.0 46 } 47 } 48 impl From<Redirect> for Option<u8> { 49 #[inline] 50 fn from(input: Redirect) -> Self { 51 Some(input.0) 52 } 53 } 54 impl From<Redirect> for u16 { 55 #[inline] 56 fn from(input: Redirect) -> Self { 57 u16::from(input.0) 58 } 59 } 60 impl From<Redirect> for Option<u16> { 61 #[inline] 62 fn from(input: Redirect) -> Self { 63 Some(u16::from(input.0)) 64 } 65 } 66 impl From<Redirect> for u32 { 67 #[inline] 68 fn from(input: Redirect) -> Self { 69 u32::from(input.0) 70 } 71 } 72 impl From<Redirect> for Option<u32> { 73 #[inline] 74 fn from(input: Redirect) -> Self { 75 Some(u32::from(input.0)) 76 } 77 } 78 impl From<u8> for Redirect { 79 #[inline] 80 fn from(value: u8) -> Self { 81 Self(value) 82 } 83 } 84 impl std::fmt::Debug for Redirect { 85 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 86 let variants = [ 87 (Self::AUTOMATIC.0.into(), "AUTOMATIC", "Automatic"), 88 (Self::MANUAL.0.into(), "MANUAL", "Manual"), 89 ]; 90 pretty_print_enum(fmt, self.0.into(), &variants) 91 } 92 } 93 94 /// Opcode for the QueryVersion request 95 pub const QUERY_VERSION_REQUEST: u8 = 0; 96 #[derive(Debug, Clone, Copy, PartialEq, Eq)] 97 pub struct QueryVersionRequest { 98 pub client_major_version: u32, 99 pub client_minor_version: u32, 100 } 101 impl QueryVersionRequest { 102 /// Serialize this request into bytes for the provided connection 103 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> 104 where 105 Conn: RequestConnection + ?Sized, 106 { 107 let extension_information = conn.extension_information(X11_EXTENSION_NAME)? 108 .ok_or(ConnectionError::UnsupportedExtension)?; 109 let length_so_far = 0; 110 let client_major_version_bytes = self.client_major_version.serialize(); 111 let client_minor_version_bytes = self.client_minor_version.serialize(); 112 let mut request0 = vec![ 113 extension_information.major_opcode, 114 QUERY_VERSION_REQUEST, 115 0, 116 0, 117 client_major_version_bytes[0], 118 client_major_version_bytes[1], 119 client_major_version_bytes[2], 120 client_major_version_bytes[3], 121 client_minor_version_bytes[0], 122 client_minor_version_bytes[1], 123 client_minor_version_bytes[2], 124 client_minor_version_bytes[3], 125 ]; 126 let length_so_far = length_so_far + request0.len(); 127 assert_eq!(length_so_far % 4, 0); 128 let length = u16::try_from(length_so_far / 4).unwrap_or(0); 129 request0[2..4].copy_from_slice(&length.to_ne_bytes()); 130 Ok((vec![request0.into()], vec![])) 131 } 132 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError> 133 where 134 Conn: RequestConnection + ?Sized, 135 { 136 let (bytes, fds) = self.serialize(conn)?; 137 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>(); 138 conn.send_request_with_reply(&slices, fds) 139 } 140 /// Parse this request given its header, its body, and any fds that go along with it 141 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { 142 if header.minor_opcode != QUERY_VERSION_REQUEST { 143 return Err(ParseError::InvalidValue); 144 } 145 let (client_major_version, remaining) = u32::try_parse(value)?; 146 let (client_minor_version, remaining) = u32::try_parse(remaining)?; 147 let _ = remaining; 148 Ok(QueryVersionRequest { 149 client_major_version, 150 client_minor_version, 151 }) 152 } 153 } 154 impl Request for QueryVersionRequest { 155 type Reply = QueryVersionReply; 156 } 157 pub fn query_version<Conn>(conn: &Conn, client_major_version: u32, client_minor_version: u32) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError> 158 where 159 Conn: RequestConnection + ?Sized, 160 { 161 let request0 = QueryVersionRequest { 162 client_major_version, 163 client_minor_version, 164 }; 165 request0.send(conn) 166 } 167 168 #[derive(Debug, Clone, Copy, PartialEq, Eq)] 169 pub struct QueryVersionReply { 170 pub sequence: u16, 171 pub length: u32, 172 pub major_version: u32, 173 pub minor_version: u32, 174 } 175 impl TryParse for QueryVersionReply { 176 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { 177 let remaining = initial_value; 178 let (response_type, remaining) = u8::try_parse(remaining)?; 179 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; 180 let (sequence, remaining) = u16::try_parse(remaining)?; 181 let (length, remaining) = u32::try_parse(remaining)?; 182 let (major_version, remaining) = u32::try_parse(remaining)?; 183 let (minor_version, remaining) = u32::try_parse(remaining)?; 184 let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?; 185 if response_type != 1 { 186 return Err(ParseError::InvalidValue); 187 } 188 let result = QueryVersionReply { sequence, length, major_version, minor_version }; 189 let _ = remaining; 190 let remaining = initial_value.get(32 + length as usize * 4..) 191 .ok_or(ParseError::InsufficientData)?; 192 Ok((result, remaining)) 193 } 194 } 195 196 /// Opcode for the RedirectWindow request 197 pub const REDIRECT_WINDOW_REQUEST: u8 = 1; 198 #[derive(Debug, Clone, Copy, PartialEq, Eq)] 199 pub struct RedirectWindowRequest { 200 pub window: xproto::Window, 201 pub update: Redirect, 202 } 203 impl RedirectWindowRequest { 204 /// Serialize this request into bytes for the provided connection 205 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> 206 where 207 Conn: RequestConnection + ?Sized, 208 { 209 let extension_information = conn.extension_information(X11_EXTENSION_NAME)? 210 .ok_or(ConnectionError::UnsupportedExtension)?; 211 let length_so_far = 0; 212 let window_bytes = self.window.serialize(); 213 let update_bytes = u8::from(self.update).serialize(); 214 let mut request0 = vec![ 215 extension_information.major_opcode, 216 REDIRECT_WINDOW_REQUEST, 217 0, 218 0, 219 window_bytes[0], 220 window_bytes[1], 221 window_bytes[2], 222 window_bytes[3], 223 update_bytes[0], 224 0, 225 0, 226 0, 227 ]; 228 let length_so_far = length_so_far + request0.len(); 229 assert_eq!(length_so_far % 4, 0); 230 let length = u16::try_from(length_so_far / 4).unwrap_or(0); 231 request0[2..4].copy_from_slice(&length.to_ne_bytes()); 232 Ok((vec![request0.into()], vec![])) 233 } 234 pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> 235 where 236 Conn: RequestConnection + ?Sized, 237 { 238 let (bytes, fds) = self.serialize(conn)?; 239 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>(); 240 conn.send_request_without_reply(&slices, fds) 241 } 242 /// Parse this request given its header, its body, and any fds that go along with it 243 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { 244 if header.minor_opcode != REDIRECT_WINDOW_REQUEST { 245 return Err(ParseError::InvalidValue); 246 } 247 let (window, remaining) = xproto::Window::try_parse(value)?; 248 let (update, remaining) = u8::try_parse(remaining)?; 249 let update = update.into(); 250 let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; 251 let _ = remaining; 252 Ok(RedirectWindowRequest { 253 window, 254 update, 255 }) 256 } 257 } 258 impl Request for RedirectWindowRequest { 259 type Reply = (); 260 } 261 pub fn redirect_window<Conn>(conn: &Conn, window: xproto::Window, update: Redirect) -> Result<VoidCookie<'_, Conn>, ConnectionError> 262 where 263 Conn: RequestConnection + ?Sized, 264 { 265 let request0 = RedirectWindowRequest { 266 window, 267 update, 268 }; 269 request0.send(conn) 270 } 271 272 /// Opcode for the RedirectSubwindows request 273 pub const REDIRECT_SUBWINDOWS_REQUEST: u8 = 2; 274 #[derive(Debug, Clone, Copy, PartialEq, Eq)] 275 pub struct RedirectSubwindowsRequest { 276 pub window: xproto::Window, 277 pub update: Redirect, 278 } 279 impl RedirectSubwindowsRequest { 280 /// Serialize this request into bytes for the provided connection 281 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> 282 where 283 Conn: RequestConnection + ?Sized, 284 { 285 let extension_information = conn.extension_information(X11_EXTENSION_NAME)? 286 .ok_or(ConnectionError::UnsupportedExtension)?; 287 let length_so_far = 0; 288 let window_bytes = self.window.serialize(); 289 let update_bytes = u8::from(self.update).serialize(); 290 let mut request0 = vec![ 291 extension_information.major_opcode, 292 REDIRECT_SUBWINDOWS_REQUEST, 293 0, 294 0, 295 window_bytes[0], 296 window_bytes[1], 297 window_bytes[2], 298 window_bytes[3], 299 update_bytes[0], 300 0, 301 0, 302 0, 303 ]; 304 let length_so_far = length_so_far + request0.len(); 305 assert_eq!(length_so_far % 4, 0); 306 let length = u16::try_from(length_so_far / 4).unwrap_or(0); 307 request0[2..4].copy_from_slice(&length.to_ne_bytes()); 308 Ok((vec![request0.into()], vec![])) 309 } 310 pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> 311 where 312 Conn: RequestConnection + ?Sized, 313 { 314 let (bytes, fds) = self.serialize(conn)?; 315 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>(); 316 conn.send_request_without_reply(&slices, fds) 317 } 318 /// Parse this request given its header, its body, and any fds that go along with it 319 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { 320 if header.minor_opcode != REDIRECT_SUBWINDOWS_REQUEST { 321 return Err(ParseError::InvalidValue); 322 } 323 let (window, remaining) = xproto::Window::try_parse(value)?; 324 let (update, remaining) = u8::try_parse(remaining)?; 325 let update = update.into(); 326 let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; 327 let _ = remaining; 328 Ok(RedirectSubwindowsRequest { 329 window, 330 update, 331 }) 332 } 333 } 334 impl Request for RedirectSubwindowsRequest { 335 type Reply = (); 336 } 337 pub fn redirect_subwindows<Conn>(conn: &Conn, window: xproto::Window, update: Redirect) -> Result<VoidCookie<'_, Conn>, ConnectionError> 338 where 339 Conn: RequestConnection + ?Sized, 340 { 341 let request0 = RedirectSubwindowsRequest { 342 window, 343 update, 344 }; 345 request0.send(conn) 346 } 347 348 /// Opcode for the UnredirectWindow request 349 pub const UNREDIRECT_WINDOW_REQUEST: u8 = 3; 350 #[derive(Debug, Clone, Copy, PartialEq, Eq)] 351 pub struct UnredirectWindowRequest { 352 pub window: xproto::Window, 353 pub update: Redirect, 354 } 355 impl UnredirectWindowRequest { 356 /// Serialize this request into bytes for the provided connection 357 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> 358 where 359 Conn: RequestConnection + ?Sized, 360 { 361 let extension_information = conn.extension_information(X11_EXTENSION_NAME)? 362 .ok_or(ConnectionError::UnsupportedExtension)?; 363 let length_so_far = 0; 364 let window_bytes = self.window.serialize(); 365 let update_bytes = u8::from(self.update).serialize(); 366 let mut request0 = vec![ 367 extension_information.major_opcode, 368 UNREDIRECT_WINDOW_REQUEST, 369 0, 370 0, 371 window_bytes[0], 372 window_bytes[1], 373 window_bytes[2], 374 window_bytes[3], 375 update_bytes[0], 376 0, 377 0, 378 0, 379 ]; 380 let length_so_far = length_so_far + request0.len(); 381 assert_eq!(length_so_far % 4, 0); 382 let length = u16::try_from(length_so_far / 4).unwrap_or(0); 383 request0[2..4].copy_from_slice(&length.to_ne_bytes()); 384 Ok((vec![request0.into()], vec![])) 385 } 386 pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> 387 where 388 Conn: RequestConnection + ?Sized, 389 { 390 let (bytes, fds) = self.serialize(conn)?; 391 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>(); 392 conn.send_request_without_reply(&slices, fds) 393 } 394 /// Parse this request given its header, its body, and any fds that go along with it 395 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { 396 if header.minor_opcode != UNREDIRECT_WINDOW_REQUEST { 397 return Err(ParseError::InvalidValue); 398 } 399 let (window, remaining) = xproto::Window::try_parse(value)?; 400 let (update, remaining) = u8::try_parse(remaining)?; 401 let update = update.into(); 402 let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; 403 let _ = remaining; 404 Ok(UnredirectWindowRequest { 405 window, 406 update, 407 }) 408 } 409 } 410 impl Request for UnredirectWindowRequest { 411 type Reply = (); 412 } 413 pub fn unredirect_window<Conn>(conn: &Conn, window: xproto::Window, update: Redirect) -> Result<VoidCookie<'_, Conn>, ConnectionError> 414 where 415 Conn: RequestConnection + ?Sized, 416 { 417 let request0 = UnredirectWindowRequest { 418 window, 419 update, 420 }; 421 request0.send(conn) 422 } 423 424 /// Opcode for the UnredirectSubwindows request 425 pub const UNREDIRECT_SUBWINDOWS_REQUEST: u8 = 4; 426 #[derive(Debug, Clone, Copy, PartialEq, Eq)] 427 pub struct UnredirectSubwindowsRequest { 428 pub window: xproto::Window, 429 pub update: Redirect, 430 } 431 impl UnredirectSubwindowsRequest { 432 /// Serialize this request into bytes for the provided connection 433 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> 434 where 435 Conn: RequestConnection + ?Sized, 436 { 437 let extension_information = conn.extension_information(X11_EXTENSION_NAME)? 438 .ok_or(ConnectionError::UnsupportedExtension)?; 439 let length_so_far = 0; 440 let window_bytes = self.window.serialize(); 441 let update_bytes = u8::from(self.update).serialize(); 442 let mut request0 = vec![ 443 extension_information.major_opcode, 444 UNREDIRECT_SUBWINDOWS_REQUEST, 445 0, 446 0, 447 window_bytes[0], 448 window_bytes[1], 449 window_bytes[2], 450 window_bytes[3], 451 update_bytes[0], 452 0, 453 0, 454 0, 455 ]; 456 let length_so_far = length_so_far + request0.len(); 457 assert_eq!(length_so_far % 4, 0); 458 let length = u16::try_from(length_so_far / 4).unwrap_or(0); 459 request0[2..4].copy_from_slice(&length.to_ne_bytes()); 460 Ok((vec![request0.into()], vec![])) 461 } 462 pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> 463 where 464 Conn: RequestConnection + ?Sized, 465 { 466 let (bytes, fds) = self.serialize(conn)?; 467 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>(); 468 conn.send_request_without_reply(&slices, fds) 469 } 470 /// Parse this request given its header, its body, and any fds that go along with it 471 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { 472 if header.minor_opcode != UNREDIRECT_SUBWINDOWS_REQUEST { 473 return Err(ParseError::InvalidValue); 474 } 475 let (window, remaining) = xproto::Window::try_parse(value)?; 476 let (update, remaining) = u8::try_parse(remaining)?; 477 let update = update.into(); 478 let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; 479 let _ = remaining; 480 Ok(UnredirectSubwindowsRequest { 481 window, 482 update, 483 }) 484 } 485 } 486 impl Request for UnredirectSubwindowsRequest { 487 type Reply = (); 488 } 489 pub fn unredirect_subwindows<Conn>(conn: &Conn, window: xproto::Window, update: Redirect) -> Result<VoidCookie<'_, Conn>, ConnectionError> 490 where 491 Conn: RequestConnection + ?Sized, 492 { 493 let request0 = UnredirectSubwindowsRequest { 494 window, 495 update, 496 }; 497 request0.send(conn) 498 } 499 500 /// Opcode for the CreateRegionFromBorderClip request 501 pub const CREATE_REGION_FROM_BORDER_CLIP_REQUEST: u8 = 5; 502 #[derive(Debug, Clone, Copy, PartialEq, Eq)] 503 pub struct CreateRegionFromBorderClipRequest { 504 pub region: xfixes::Region, 505 pub window: xproto::Window, 506 } 507 impl CreateRegionFromBorderClipRequest { 508 /// Serialize this request into bytes for the provided connection 509 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> 510 where 511 Conn: RequestConnection + ?Sized, 512 { 513 let extension_information = conn.extension_information(X11_EXTENSION_NAME)? 514 .ok_or(ConnectionError::UnsupportedExtension)?; 515 let length_so_far = 0; 516 let region_bytes = self.region.serialize(); 517 let window_bytes = self.window.serialize(); 518 let mut request0 = vec![ 519 extension_information.major_opcode, 520 CREATE_REGION_FROM_BORDER_CLIP_REQUEST, 521 0, 522 0, 523 region_bytes[0], 524 region_bytes[1], 525 region_bytes[2], 526 region_bytes[3], 527 window_bytes[0], 528 window_bytes[1], 529 window_bytes[2], 530 window_bytes[3], 531 ]; 532 let length_so_far = length_so_far + request0.len(); 533 assert_eq!(length_so_far % 4, 0); 534 let length = u16::try_from(length_so_far / 4).unwrap_or(0); 535 request0[2..4].copy_from_slice(&length.to_ne_bytes()); 536 Ok((vec![request0.into()], vec![])) 537 } 538 pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> 539 where 540 Conn: RequestConnection + ?Sized, 541 { 542 let (bytes, fds) = self.serialize(conn)?; 543 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>(); 544 conn.send_request_without_reply(&slices, fds) 545 } 546 /// Parse this request given its header, its body, and any fds that go along with it 547 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { 548 if header.minor_opcode != CREATE_REGION_FROM_BORDER_CLIP_REQUEST { 549 return Err(ParseError::InvalidValue); 550 } 551 let (region, remaining) = xfixes::Region::try_parse(value)?; 552 let (window, remaining) = xproto::Window::try_parse(remaining)?; 553 let _ = remaining; 554 Ok(CreateRegionFromBorderClipRequest { 555 region, 556 window, 557 }) 558 } 559 } 560 impl Request for CreateRegionFromBorderClipRequest { 561 type Reply = (); 562 } 563 pub fn create_region_from_border_clip<Conn>(conn: &Conn, region: xfixes::Region, window: xproto::Window) -> Result<VoidCookie<'_, Conn>, ConnectionError> 564 where 565 Conn: RequestConnection + ?Sized, 566 { 567 let request0 = CreateRegionFromBorderClipRequest { 568 region, 569 window, 570 }; 571 request0.send(conn) 572 } 573 574 /// Opcode for the NameWindowPixmap request 575 pub const NAME_WINDOW_PIXMAP_REQUEST: u8 = 6; 576 #[derive(Debug, Clone, Copy, PartialEq, Eq)] 577 pub struct NameWindowPixmapRequest { 578 pub window: xproto::Window, 579 pub pixmap: xproto::Pixmap, 580 } 581 impl NameWindowPixmapRequest { 582 /// Serialize this request into bytes for the provided connection 583 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> 584 where 585 Conn: RequestConnection + ?Sized, 586 { 587 let extension_information = conn.extension_information(X11_EXTENSION_NAME)? 588 .ok_or(ConnectionError::UnsupportedExtension)?; 589 let length_so_far = 0; 590 let window_bytes = self.window.serialize(); 591 let pixmap_bytes = self.pixmap.serialize(); 592 let mut request0 = vec![ 593 extension_information.major_opcode, 594 NAME_WINDOW_PIXMAP_REQUEST, 595 0, 596 0, 597 window_bytes[0], 598 window_bytes[1], 599 window_bytes[2], 600 window_bytes[3], 601 pixmap_bytes[0], 602 pixmap_bytes[1], 603 pixmap_bytes[2], 604 pixmap_bytes[3], 605 ]; 606 let length_so_far = length_so_far + request0.len(); 607 assert_eq!(length_so_far % 4, 0); 608 let length = u16::try_from(length_so_far / 4).unwrap_or(0); 609 request0[2..4].copy_from_slice(&length.to_ne_bytes()); 610 Ok((vec![request0.into()], vec![])) 611 } 612 pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> 613 where 614 Conn: RequestConnection + ?Sized, 615 { 616 let (bytes, fds) = self.serialize(conn)?; 617 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>(); 618 conn.send_request_without_reply(&slices, fds) 619 } 620 /// Parse this request given its header, its body, and any fds that go along with it 621 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { 622 if header.minor_opcode != NAME_WINDOW_PIXMAP_REQUEST { 623 return Err(ParseError::InvalidValue); 624 } 625 let (window, remaining) = xproto::Window::try_parse(value)?; 626 let (pixmap, remaining) = xproto::Pixmap::try_parse(remaining)?; 627 let _ = remaining; 628 Ok(NameWindowPixmapRequest { 629 window, 630 pixmap, 631 }) 632 } 633 } 634 impl Request for NameWindowPixmapRequest { 635 type Reply = (); 636 } 637 pub fn name_window_pixmap<Conn>(conn: &Conn, window: xproto::Window, pixmap: xproto::Pixmap) -> Result<VoidCookie<'_, Conn>, ConnectionError> 638 where 639 Conn: RequestConnection + ?Sized, 640 { 641 let request0 = NameWindowPixmapRequest { 642 window, 643 pixmap, 644 }; 645 request0.send(conn) 646 } 647 648 /// Opcode for the GetOverlayWindow request 649 pub const GET_OVERLAY_WINDOW_REQUEST: u8 = 7; 650 #[derive(Debug, Clone, Copy, PartialEq, Eq)] 651 pub struct GetOverlayWindowRequest { 652 pub window: xproto::Window, 653 } 654 impl GetOverlayWindowRequest { 655 /// Serialize this request into bytes for the provided connection 656 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> 657 where 658 Conn: RequestConnection + ?Sized, 659 { 660 let extension_information = conn.extension_information(X11_EXTENSION_NAME)? 661 .ok_or(ConnectionError::UnsupportedExtension)?; 662 let length_so_far = 0; 663 let window_bytes = self.window.serialize(); 664 let mut request0 = vec![ 665 extension_information.major_opcode, 666 GET_OVERLAY_WINDOW_REQUEST, 667 0, 668 0, 669 window_bytes[0], 670 window_bytes[1], 671 window_bytes[2], 672 window_bytes[3], 673 ]; 674 let length_so_far = length_so_far + request0.len(); 675 assert_eq!(length_so_far % 4, 0); 676 let length = u16::try_from(length_so_far / 4).unwrap_or(0); 677 request0[2..4].copy_from_slice(&length.to_ne_bytes()); 678 Ok((vec![request0.into()], vec![])) 679 } 680 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetOverlayWindowReply>, ConnectionError> 681 where 682 Conn: RequestConnection + ?Sized, 683 { 684 let (bytes, fds) = self.serialize(conn)?; 685 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>(); 686 conn.send_request_with_reply(&slices, fds) 687 } 688 /// Parse this request given its header, its body, and any fds that go along with it 689 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { 690 if header.minor_opcode != GET_OVERLAY_WINDOW_REQUEST { 691 return Err(ParseError::InvalidValue); 692 } 693 let (window, remaining) = xproto::Window::try_parse(value)?; 694 let _ = remaining; 695 Ok(GetOverlayWindowRequest { 696 window, 697 }) 698 } 699 } 700 impl Request for GetOverlayWindowRequest { 701 type Reply = GetOverlayWindowReply; 702 } 703 pub fn get_overlay_window<Conn>(conn: &Conn, window: xproto::Window) -> Result<Cookie<'_, Conn, GetOverlayWindowReply>, ConnectionError> 704 where 705 Conn: RequestConnection + ?Sized, 706 { 707 let request0 = GetOverlayWindowRequest { 708 window, 709 }; 710 request0.send(conn) 711 } 712 713 #[derive(Debug, Clone, Copy, PartialEq, Eq)] 714 pub struct GetOverlayWindowReply { 715 pub sequence: u16, 716 pub length: u32, 717 pub overlay_win: xproto::Window, 718 } 719 impl TryParse for GetOverlayWindowReply { 720 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { 721 let remaining = initial_value; 722 let (response_type, remaining) = u8::try_parse(remaining)?; 723 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; 724 let (sequence, remaining) = u16::try_parse(remaining)?; 725 let (length, remaining) = u32::try_parse(remaining)?; 726 let (overlay_win, remaining) = xproto::Window::try_parse(remaining)?; 727 let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; 728 if response_type != 1 { 729 return Err(ParseError::InvalidValue); 730 } 731 let result = GetOverlayWindowReply { sequence, length, overlay_win }; 732 let _ = remaining; 733 let remaining = initial_value.get(32 + length as usize * 4..) 734 .ok_or(ParseError::InsufficientData)?; 735 Ok((result, remaining)) 736 } 737 } 738 739 /// Opcode for the ReleaseOverlayWindow request 740 pub const RELEASE_OVERLAY_WINDOW_REQUEST: u8 = 8; 741 #[derive(Debug, Clone, Copy, PartialEq, Eq)] 742 pub struct ReleaseOverlayWindowRequest { 743 pub window: xproto::Window, 744 } 745 impl ReleaseOverlayWindowRequest { 746 /// Serialize this request into bytes for the provided connection 747 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> 748 where 749 Conn: RequestConnection + ?Sized, 750 { 751 let extension_information = conn.extension_information(X11_EXTENSION_NAME)? 752 .ok_or(ConnectionError::UnsupportedExtension)?; 753 let length_so_far = 0; 754 let window_bytes = self.window.serialize(); 755 let mut request0 = vec![ 756 extension_information.major_opcode, 757 RELEASE_OVERLAY_WINDOW_REQUEST, 758 0, 759 0, 760 window_bytes[0], 761 window_bytes[1], 762 window_bytes[2], 763 window_bytes[3], 764 ]; 765 let length_so_far = length_so_far + request0.len(); 766 assert_eq!(length_so_far % 4, 0); 767 let length = u16::try_from(length_so_far / 4).unwrap_or(0); 768 request0[2..4].copy_from_slice(&length.to_ne_bytes()); 769 Ok((vec![request0.into()], vec![])) 770 } 771 pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> 772 where 773 Conn: RequestConnection + ?Sized, 774 { 775 let (bytes, fds) = self.serialize(conn)?; 776 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>(); 777 conn.send_request_without_reply(&slices, fds) 778 } 779 /// Parse this request given its header, its body, and any fds that go along with it 780 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { 781 if header.minor_opcode != RELEASE_OVERLAY_WINDOW_REQUEST { 782 return Err(ParseError::InvalidValue); 783 } 784 let (window, remaining) = xproto::Window::try_parse(value)?; 785 let _ = remaining; 786 Ok(ReleaseOverlayWindowRequest { 787 window, 788 }) 789 } 790 } 791 impl Request for ReleaseOverlayWindowRequest { 792 type Reply = (); 793 } 794 pub fn release_overlay_window<Conn>(conn: &Conn, window: xproto::Window) -> Result<VoidCookie<'_, Conn>, ConnectionError> 795 where 796 Conn: RequestConnection + ?Sized, 797 { 798 let request0 = ReleaseOverlayWindowRequest { 799 window, 800 }; 801 request0.send(conn) 802 } 803 804 /// Extension trait defining the requests of this extension. 805 pub trait ConnectionExt: RequestConnection { 806 fn composite_query_version(&self, client_major_version: u32, client_minor_version: u32) -> Result<Cookie<'_, Self, QueryVersionReply>, ConnectionError> 807 { 808 query_version(self, client_major_version, client_minor_version) 809 } 810 fn composite_redirect_window(&self, window: xproto::Window, update: Redirect) -> Result<VoidCookie<'_, Self>, ConnectionError> 811 { 812 redirect_window(self, window, update) 813 } 814 fn composite_redirect_subwindows(&self, window: xproto::Window, update: Redirect) -> Result<VoidCookie<'_, Self>, ConnectionError> 815 { 816 redirect_subwindows(self, window, update) 817 } 818 fn composite_unredirect_window(&self, window: xproto::Window, update: Redirect) -> Result<VoidCookie<'_, Self>, ConnectionError> 819 { 820 unredirect_window(self, window, update) 821 } 822 fn composite_unredirect_subwindows(&self, window: xproto::Window, update: Redirect) -> Result<VoidCookie<'_, Self>, ConnectionError> 823 { 824 unredirect_subwindows(self, window, update) 825 } 826 fn composite_create_region_from_border_clip(&self, region: xfixes::Region, window: xproto::Window) -> Result<VoidCookie<'_, Self>, ConnectionError> 827 { 828 create_region_from_border_clip(self, region, window) 829 } 830 fn composite_name_window_pixmap(&self, window: xproto::Window, pixmap: xproto::Pixmap) -> Result<VoidCookie<'_, Self>, ConnectionError> 831 { 832 name_window_pixmap(self, window, pixmap) 833 } 834 fn composite_get_overlay_window(&self, window: xproto::Window) -> Result<Cookie<'_, Self, GetOverlayWindowReply>, ConnectionError> 835 { 836 get_overlay_window(self, window) 837 } 838 fn composite_release_overlay_window(&self, window: xproto::Window) -> Result<VoidCookie<'_, Self>, ConnectionError> 839 { 840 release_overlay_window(self, window) 841 } 842 } 843 844 impl<C: RequestConnection + ?Sized> ConnectionExt for C {} 845