| 1 | // This file contains generated code. Do not edit directly. |
| 2 | // To regenerate this, run 'make'. |
| 3 | |
| 4 | //! Bindings to the `Shape` X11 extension. |
| 5 | |
| 6 | #![allow (clippy::too_many_arguments)] |
| 7 | // The code generator is simpler if it can always use conversions |
| 8 | #![allow (clippy::useless_conversion)] |
| 9 | |
| 10 | #[allow (unused_imports)] |
| 11 | use alloc::borrow::Cow; |
| 12 | #[allow (unused_imports)] |
| 13 | use core::convert::TryInto; |
| 14 | use alloc::vec; |
| 15 | use alloc::vec::Vec; |
| 16 | use core::convert::TryFrom; |
| 17 | use crate::errors::ParseError; |
| 18 | #[allow (unused_imports)] |
| 19 | use crate::x11_utils::TryIntoUSize; |
| 20 | use crate::BufWithFds; |
| 21 | #[allow (unused_imports)] |
| 22 | use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; |
| 23 | #[allow (unused_imports)] |
| 24 | use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; |
| 25 | #[allow (unused_imports)] |
| 26 | use super::xproto; |
| 27 | |
| 28 | /// The X11 name of the extension for QueryExtension |
| 29 | pub const X11_EXTENSION_NAME: &str = "SHAPE" ; |
| 30 | |
| 31 | /// The version number of this extension that this client library supports. |
| 32 | /// |
| 33 | /// This constant contains the version number of this extension that is supported |
| 34 | /// by this build of x11rb. For most things, it does not make sense to use this |
| 35 | /// information. If you need to send a `QueryVersion`, it is recommended to instead |
| 36 | /// send the maximum version of the extension that you need. |
| 37 | pub const X11_XML_VERSION: (u32, u32) = (1, 1); |
| 38 | |
| 39 | pub type Op = u8; |
| 40 | |
| 41 | pub type Kind = u8; |
| 42 | |
| 43 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 44 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 45 | pub struct SO(u8); |
| 46 | impl SO { |
| 47 | pub const SET: Self = Self(0); |
| 48 | pub const UNION: Self = Self(1); |
| 49 | pub const INTERSECT: Self = Self(2); |
| 50 | pub const SUBTRACT: Self = Self(3); |
| 51 | pub const INVERT: Self = Self(4); |
| 52 | } |
| 53 | impl From<SO> for u8 { |
| 54 | #[inline ] |
| 55 | fn from(input: SO) -> Self { |
| 56 | input.0 |
| 57 | } |
| 58 | } |
| 59 | impl From<SO> for Option<u8> { |
| 60 | #[inline ] |
| 61 | fn from(input: SO) -> Self { |
| 62 | Some(input.0) |
| 63 | } |
| 64 | } |
| 65 | impl From<SO> for u16 { |
| 66 | #[inline ] |
| 67 | fn from(input: SO) -> Self { |
| 68 | u16::from(input.0) |
| 69 | } |
| 70 | } |
| 71 | impl From<SO> for Option<u16> { |
| 72 | #[inline ] |
| 73 | fn from(input: SO) -> Self { |
| 74 | Some(u16::from(input.0)) |
| 75 | } |
| 76 | } |
| 77 | impl From<SO> for u32 { |
| 78 | #[inline ] |
| 79 | fn from(input: SO) -> Self { |
| 80 | u32::from(input.0) |
| 81 | } |
| 82 | } |
| 83 | impl From<SO> for Option<u32> { |
| 84 | #[inline ] |
| 85 | fn from(input: SO) -> Self { |
| 86 | Some(u32::from(input.0)) |
| 87 | } |
| 88 | } |
| 89 | impl From<u8> for SO { |
| 90 | #[inline ] |
| 91 | fn from(value: u8) -> Self { |
| 92 | Self(value) |
| 93 | } |
| 94 | } |
| 95 | impl core::fmt::Debug for SO { |
| 96 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 97 | let variants: [(u32, &'static str, &'static …); 5] = [ |
| 98 | (Self::SET.0.into(), "SET" , "Set" ), |
| 99 | (Self::UNION.0.into(), "UNION" , "Union" ), |
| 100 | (Self::INTERSECT.0.into(), "INTERSECT" , "Intersect" ), |
| 101 | (Self::SUBTRACT.0.into(), "SUBTRACT" , "Subtract" ), |
| 102 | (Self::INVERT.0.into(), "INVERT" , "Invert" ), |
| 103 | ]; |
| 104 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 109 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 110 | pub struct SK(u8); |
| 111 | impl SK { |
| 112 | pub const BOUNDING: Self = Self(0); |
| 113 | pub const CLIP: Self = Self(1); |
| 114 | pub const INPUT: Self = Self(2); |
| 115 | } |
| 116 | impl From<SK> for u8 { |
| 117 | #[inline ] |
| 118 | fn from(input: SK) -> Self { |
| 119 | input.0 |
| 120 | } |
| 121 | } |
| 122 | impl From<SK> for Option<u8> { |
| 123 | #[inline ] |
| 124 | fn from(input: SK) -> Self { |
| 125 | Some(input.0) |
| 126 | } |
| 127 | } |
| 128 | impl From<SK> for u16 { |
| 129 | #[inline ] |
| 130 | fn from(input: SK) -> Self { |
| 131 | u16::from(input.0) |
| 132 | } |
| 133 | } |
| 134 | impl From<SK> for Option<u16> { |
| 135 | #[inline ] |
| 136 | fn from(input: SK) -> Self { |
| 137 | Some(u16::from(input.0)) |
| 138 | } |
| 139 | } |
| 140 | impl From<SK> for u32 { |
| 141 | #[inline ] |
| 142 | fn from(input: SK) -> Self { |
| 143 | u32::from(input.0) |
| 144 | } |
| 145 | } |
| 146 | impl From<SK> for Option<u32> { |
| 147 | #[inline ] |
| 148 | fn from(input: SK) -> Self { |
| 149 | Some(u32::from(input.0)) |
| 150 | } |
| 151 | } |
| 152 | impl From<u8> for SK { |
| 153 | #[inline ] |
| 154 | fn from(value: u8) -> Self { |
| 155 | Self(value) |
| 156 | } |
| 157 | } |
| 158 | impl core::fmt::Debug for SK { |
| 159 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 160 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 161 | (Self::BOUNDING.0.into(), "BOUNDING" , "Bounding" ), |
| 162 | (Self::CLIP.0.into(), "CLIP" , "Clip" ), |
| 163 | (Self::INPUT.0.into(), "INPUT" , "Input" ), |
| 164 | ]; |
| 165 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /// Opcode for the Notify event |
| 170 | pub const NOTIFY_EVENT: u8 = 0; |
| 171 | #[derive (Clone, Copy, Default)] |
| 172 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 173 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 174 | pub struct NotifyEvent { |
| 175 | pub response_type: u8, |
| 176 | pub shape_kind: SK, |
| 177 | pub sequence: u16, |
| 178 | pub affected_window: xproto::Window, |
| 179 | pub extents_x: i16, |
| 180 | pub extents_y: i16, |
| 181 | pub extents_width: u16, |
| 182 | pub extents_height: u16, |
| 183 | pub server_time: xproto::Timestamp, |
| 184 | pub shaped: bool, |
| 185 | } |
| 186 | impl_debug_if_no_extra_traits!(NotifyEvent, "NotifyEvent" ); |
| 187 | impl TryParse for NotifyEvent { |
| 188 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 189 | let remaining: &[u8] = initial_value; |
| 190 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 191 | let (shape_kind: u8, remaining: &[u8]) = Kind::try_parse(remaining)?; |
| 192 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 193 | let (affected_window: u32, remaining: &[u8]) = xproto::Window::try_parse(remaining)?; |
| 194 | let (extents_x: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 195 | let (extents_y: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 196 | let (extents_width: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 197 | let (extents_height: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 198 | let (server_time: u32, remaining: &[u8]) = xproto::Timestamp::try_parse(remaining)?; |
| 199 | let (shaped: bool, remaining: &[u8]) = bool::try_parse(remaining)?; |
| 200 | let remaining: &[u8] = remaining.get(11..).ok_or(err:ParseError::InsufficientData)?; |
| 201 | let shape_kind: SK = shape_kind.into(); |
| 202 | let result: NotifyEvent = NotifyEvent { response_type, shape_kind, sequence, affected_window, extents_x, extents_y, extents_width, extents_height, server_time, shaped }; |
| 203 | let _ = remaining; |
| 204 | let remaining: &[u8] = initial_value.get(32..) |
| 205 | .ok_or(err:ParseError::InsufficientData)?; |
| 206 | Ok((result, remaining)) |
| 207 | } |
| 208 | } |
| 209 | impl Serialize for NotifyEvent { |
| 210 | type Bytes = [u8; 32]; |
| 211 | fn serialize(&self) -> [u8; 32] { |
| 212 | let response_type_bytes = self.response_type.serialize(); |
| 213 | let shape_kind_bytes = Kind::from(self.shape_kind).serialize(); |
| 214 | let sequence_bytes = self.sequence.serialize(); |
| 215 | let affected_window_bytes = self.affected_window.serialize(); |
| 216 | let extents_x_bytes = self.extents_x.serialize(); |
| 217 | let extents_y_bytes = self.extents_y.serialize(); |
| 218 | let extents_width_bytes = self.extents_width.serialize(); |
| 219 | let extents_height_bytes = self.extents_height.serialize(); |
| 220 | let server_time_bytes = self.server_time.serialize(); |
| 221 | let shaped_bytes = self.shaped.serialize(); |
| 222 | [ |
| 223 | response_type_bytes[0], |
| 224 | shape_kind_bytes[0], |
| 225 | sequence_bytes[0], |
| 226 | sequence_bytes[1], |
| 227 | affected_window_bytes[0], |
| 228 | affected_window_bytes[1], |
| 229 | affected_window_bytes[2], |
| 230 | affected_window_bytes[3], |
| 231 | extents_x_bytes[0], |
| 232 | extents_x_bytes[1], |
| 233 | extents_y_bytes[0], |
| 234 | extents_y_bytes[1], |
| 235 | extents_width_bytes[0], |
| 236 | extents_width_bytes[1], |
| 237 | extents_height_bytes[0], |
| 238 | extents_height_bytes[1], |
| 239 | server_time_bytes[0], |
| 240 | server_time_bytes[1], |
| 241 | server_time_bytes[2], |
| 242 | server_time_bytes[3], |
| 243 | shaped_bytes[0], |
| 244 | 0, |
| 245 | 0, |
| 246 | 0, |
| 247 | 0, |
| 248 | 0, |
| 249 | 0, |
| 250 | 0, |
| 251 | 0, |
| 252 | 0, |
| 253 | 0, |
| 254 | 0, |
| 255 | ] |
| 256 | } |
| 257 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 258 | bytes.reserve(32); |
| 259 | self.response_type.serialize_into(bytes); |
| 260 | Kind::from(self.shape_kind).serialize_into(bytes); |
| 261 | self.sequence.serialize_into(bytes); |
| 262 | self.affected_window.serialize_into(bytes); |
| 263 | self.extents_x.serialize_into(bytes); |
| 264 | self.extents_y.serialize_into(bytes); |
| 265 | self.extents_width.serialize_into(bytes); |
| 266 | self.extents_height.serialize_into(bytes); |
| 267 | self.server_time.serialize_into(bytes); |
| 268 | self.shaped.serialize_into(bytes); |
| 269 | bytes.extend_from_slice(&[0; 11]); |
| 270 | } |
| 271 | } |
| 272 | impl From<&NotifyEvent> for [u8; 32] { |
| 273 | fn from(input: &NotifyEvent) -> Self { |
| 274 | let response_type_bytes = input.response_type.serialize(); |
| 275 | let shape_kind_bytes = Kind::from(input.shape_kind).serialize(); |
| 276 | let sequence_bytes = input.sequence.serialize(); |
| 277 | let affected_window_bytes = input.affected_window.serialize(); |
| 278 | let extents_x_bytes = input.extents_x.serialize(); |
| 279 | let extents_y_bytes = input.extents_y.serialize(); |
| 280 | let extents_width_bytes = input.extents_width.serialize(); |
| 281 | let extents_height_bytes = input.extents_height.serialize(); |
| 282 | let server_time_bytes = input.server_time.serialize(); |
| 283 | let shaped_bytes = input.shaped.serialize(); |
| 284 | [ |
| 285 | response_type_bytes[0], |
| 286 | shape_kind_bytes[0], |
| 287 | sequence_bytes[0], |
| 288 | sequence_bytes[1], |
| 289 | affected_window_bytes[0], |
| 290 | affected_window_bytes[1], |
| 291 | affected_window_bytes[2], |
| 292 | affected_window_bytes[3], |
| 293 | extents_x_bytes[0], |
| 294 | extents_x_bytes[1], |
| 295 | extents_y_bytes[0], |
| 296 | extents_y_bytes[1], |
| 297 | extents_width_bytes[0], |
| 298 | extents_width_bytes[1], |
| 299 | extents_height_bytes[0], |
| 300 | extents_height_bytes[1], |
| 301 | server_time_bytes[0], |
| 302 | server_time_bytes[1], |
| 303 | server_time_bytes[2], |
| 304 | server_time_bytes[3], |
| 305 | shaped_bytes[0], |
| 306 | 0, |
| 307 | 0, |
| 308 | 0, |
| 309 | 0, |
| 310 | 0, |
| 311 | 0, |
| 312 | 0, |
| 313 | 0, |
| 314 | 0, |
| 315 | 0, |
| 316 | 0, |
| 317 | ] |
| 318 | } |
| 319 | } |
| 320 | impl From<NotifyEvent> for [u8; 32] { |
| 321 | fn from(input: NotifyEvent) -> Self { |
| 322 | Self::from(&input) |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | /// Opcode for the QueryVersion request |
| 327 | pub const QUERY_VERSION_REQUEST: u8 = 0; |
| 328 | #[derive (Clone, Copy, Default)] |
| 329 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 330 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 331 | pub struct QueryVersionRequest; |
| 332 | impl_debug_if_no_extra_traits!(QueryVersionRequest, "QueryVersionRequest" ); |
| 333 | impl QueryVersionRequest { |
| 334 | /// Serialize this request into bytes for the provided connection |
| 335 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 336 | let length_so_far = 0; |
| 337 | let mut request0 = vec![ |
| 338 | major_opcode, |
| 339 | QUERY_VERSION_REQUEST, |
| 340 | 0, |
| 341 | 0, |
| 342 | ]; |
| 343 | let length_so_far = length_so_far + request0.len(); |
| 344 | assert_eq!(length_so_far % 4, 0); |
| 345 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 346 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 347 | ([request0.into()], vec![]) |
| 348 | } |
| 349 | /// Parse this request given its header, its body, and any fds that go along with it |
| 350 | #[cfg (feature = "request-parsing" )] |
| 351 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 352 | if header.minor_opcode != QUERY_VERSION_REQUEST { |
| 353 | return Err(ParseError::InvalidValue); |
| 354 | } |
| 355 | let _ = value; |
| 356 | Ok(QueryVersionRequest |
| 357 | ) |
| 358 | } |
| 359 | } |
| 360 | impl Request for QueryVersionRequest { |
| 361 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 362 | |
| 363 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 364 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 365 | // Flatten the buffers into a single vector |
| 366 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 367 | (buf, fds) |
| 368 | } |
| 369 | } |
| 370 | impl crate::x11_utils::ReplyRequest for QueryVersionRequest { |
| 371 | type Reply = QueryVersionReply; |
| 372 | } |
| 373 | |
| 374 | #[derive (Clone, Copy, Default)] |
| 375 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 376 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 377 | pub struct QueryVersionReply { |
| 378 | pub sequence: u16, |
| 379 | pub length: u32, |
| 380 | pub major_version: u16, |
| 381 | pub minor_version: u16, |
| 382 | } |
| 383 | impl_debug_if_no_extra_traits!(QueryVersionReply, "QueryVersionReply" ); |
| 384 | impl TryParse for QueryVersionReply { |
| 385 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 386 | let remaining: &[u8] = initial_value; |
| 387 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 388 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 389 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 390 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 391 | let (major_version: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 392 | let (minor_version: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 393 | if response_type != 1 { |
| 394 | return Err(ParseError::InvalidValue); |
| 395 | } |
| 396 | let result: QueryVersionReply = QueryVersionReply { sequence, length, major_version, minor_version }; |
| 397 | let _ = remaining; |
| 398 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 399 | .ok_or(err:ParseError::InsufficientData)?; |
| 400 | Ok((result, remaining)) |
| 401 | } |
| 402 | } |
| 403 | impl Serialize for QueryVersionReply { |
| 404 | type Bytes = [u8; 12]; |
| 405 | fn serialize(&self) -> [u8; 12] { |
| 406 | let response_type_bytes = &[1]; |
| 407 | let sequence_bytes = self.sequence.serialize(); |
| 408 | let length_bytes = self.length.serialize(); |
| 409 | let major_version_bytes = self.major_version.serialize(); |
| 410 | let minor_version_bytes = self.minor_version.serialize(); |
| 411 | [ |
| 412 | response_type_bytes[0], |
| 413 | 0, |
| 414 | sequence_bytes[0], |
| 415 | sequence_bytes[1], |
| 416 | length_bytes[0], |
| 417 | length_bytes[1], |
| 418 | length_bytes[2], |
| 419 | length_bytes[3], |
| 420 | major_version_bytes[0], |
| 421 | major_version_bytes[1], |
| 422 | minor_version_bytes[0], |
| 423 | minor_version_bytes[1], |
| 424 | ] |
| 425 | } |
| 426 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 427 | bytes.reserve(12); |
| 428 | let response_type_bytes = &[1]; |
| 429 | bytes.push(response_type_bytes[0]); |
| 430 | bytes.extend_from_slice(&[0; 1]); |
| 431 | self.sequence.serialize_into(bytes); |
| 432 | self.length.serialize_into(bytes); |
| 433 | self.major_version.serialize_into(bytes); |
| 434 | self.minor_version.serialize_into(bytes); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | /// Opcode for the Rectangles request |
| 439 | pub const RECTANGLES_REQUEST: u8 = 1; |
| 440 | #[derive (Clone, Default)] |
| 441 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 442 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 443 | pub struct RectanglesRequest<'input> { |
| 444 | pub operation: SO, |
| 445 | pub destination_kind: SK, |
| 446 | pub ordering: xproto::ClipOrdering, |
| 447 | pub destination_window: xproto::Window, |
| 448 | pub x_offset: i16, |
| 449 | pub y_offset: i16, |
| 450 | pub rectangles: Cow<'input, [xproto::Rectangle]>, |
| 451 | } |
| 452 | impl_debug_if_no_extra_traits!(RectanglesRequest<'_>, "RectanglesRequest" ); |
| 453 | impl<'input> RectanglesRequest<'input> { |
| 454 | /// Serialize this request into bytes for the provided connection |
| 455 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 456 | let length_so_far = 0; |
| 457 | let operation_bytes = Op::from(self.operation).serialize(); |
| 458 | let destination_kind_bytes = Kind::from(self.destination_kind).serialize(); |
| 459 | let ordering_bytes = u8::from(self.ordering).serialize(); |
| 460 | let destination_window_bytes = self.destination_window.serialize(); |
| 461 | let x_offset_bytes = self.x_offset.serialize(); |
| 462 | let y_offset_bytes = self.y_offset.serialize(); |
| 463 | let mut request0 = vec![ |
| 464 | major_opcode, |
| 465 | RECTANGLES_REQUEST, |
| 466 | 0, |
| 467 | 0, |
| 468 | operation_bytes[0], |
| 469 | destination_kind_bytes[0], |
| 470 | ordering_bytes[0], |
| 471 | 0, |
| 472 | destination_window_bytes[0], |
| 473 | destination_window_bytes[1], |
| 474 | destination_window_bytes[2], |
| 475 | destination_window_bytes[3], |
| 476 | x_offset_bytes[0], |
| 477 | x_offset_bytes[1], |
| 478 | y_offset_bytes[0], |
| 479 | y_offset_bytes[1], |
| 480 | ]; |
| 481 | let length_so_far = length_so_far + request0.len(); |
| 482 | let rectangles_bytes = self.rectangles.serialize(); |
| 483 | let length_so_far = length_so_far + rectangles_bytes.len(); |
| 484 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 485 | let length_so_far = length_so_far + padding0.len(); |
| 486 | assert_eq!(length_so_far % 4, 0); |
| 487 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 488 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 489 | ([request0.into(), rectangles_bytes.into(), padding0.into()], vec![]) |
| 490 | } |
| 491 | /// Parse this request given its header, its body, and any fds that go along with it |
| 492 | #[cfg (feature = "request-parsing" )] |
| 493 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 494 | if header.minor_opcode != RECTANGLES_REQUEST { |
| 495 | return Err(ParseError::InvalidValue); |
| 496 | } |
| 497 | let (operation, remaining) = Op::try_parse(value)?; |
| 498 | let operation = operation.into(); |
| 499 | let (destination_kind, remaining) = Kind::try_parse(remaining)?; |
| 500 | let destination_kind = destination_kind.into(); |
| 501 | let (ordering, remaining) = u8::try_parse(remaining)?; |
| 502 | let ordering = ordering.into(); |
| 503 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 504 | let (destination_window, remaining) = xproto::Window::try_parse(remaining)?; |
| 505 | let (x_offset, remaining) = i16::try_parse(remaining)?; |
| 506 | let (y_offset, remaining) = i16::try_parse(remaining)?; |
| 507 | let mut remaining = remaining; |
| 508 | // Length is 'everything left in the input' |
| 509 | let mut rectangles = Vec::new(); |
| 510 | while !remaining.is_empty() { |
| 511 | let (v, new_remaining) = xproto::Rectangle::try_parse(remaining)?; |
| 512 | remaining = new_remaining; |
| 513 | rectangles.push(v); |
| 514 | } |
| 515 | let _ = remaining; |
| 516 | Ok(RectanglesRequest { |
| 517 | operation, |
| 518 | destination_kind, |
| 519 | ordering, |
| 520 | destination_window, |
| 521 | x_offset, |
| 522 | y_offset, |
| 523 | rectangles: Cow::Owned(rectangles), |
| 524 | }) |
| 525 | } |
| 526 | /// Clone all borrowed data in this RectanglesRequest. |
| 527 | pub fn into_owned(self) -> RectanglesRequest<'static> { |
| 528 | RectanglesRequest { |
| 529 | operation: self.operation, |
| 530 | destination_kind: self.destination_kind, |
| 531 | ordering: self.ordering, |
| 532 | destination_window: self.destination_window, |
| 533 | x_offset: self.x_offset, |
| 534 | y_offset: self.y_offset, |
| 535 | rectangles: Cow::Owned(self.rectangles.into_owned()), |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | impl<'input> Request for RectanglesRequest<'input> { |
| 540 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 541 | |
| 542 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 543 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(major_opcode); |
| 544 | // Flatten the buffers into a single vector |
| 545 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 546 | (buf, fds) |
| 547 | } |
| 548 | } |
| 549 | impl<'input> crate::x11_utils::VoidRequest for RectanglesRequest<'input> { |
| 550 | } |
| 551 | |
| 552 | /// Opcode for the Mask request |
| 553 | pub const MASK_REQUEST: u8 = 2; |
| 554 | #[derive (Clone, Copy, Default)] |
| 555 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 556 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 557 | pub struct MaskRequest { |
| 558 | pub operation: SO, |
| 559 | pub destination_kind: SK, |
| 560 | pub destination_window: xproto::Window, |
| 561 | pub x_offset: i16, |
| 562 | pub y_offset: i16, |
| 563 | pub source_bitmap: xproto::Pixmap, |
| 564 | } |
| 565 | impl_debug_if_no_extra_traits!(MaskRequest, "MaskRequest" ); |
| 566 | impl MaskRequest { |
| 567 | /// Serialize this request into bytes for the provided connection |
| 568 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 569 | let length_so_far = 0; |
| 570 | let operation_bytes = Op::from(self.operation).serialize(); |
| 571 | let destination_kind_bytes = Kind::from(self.destination_kind).serialize(); |
| 572 | let destination_window_bytes = self.destination_window.serialize(); |
| 573 | let x_offset_bytes = self.x_offset.serialize(); |
| 574 | let y_offset_bytes = self.y_offset.serialize(); |
| 575 | let source_bitmap_bytes = self.source_bitmap.serialize(); |
| 576 | let mut request0 = vec![ |
| 577 | major_opcode, |
| 578 | MASK_REQUEST, |
| 579 | 0, |
| 580 | 0, |
| 581 | operation_bytes[0], |
| 582 | destination_kind_bytes[0], |
| 583 | 0, |
| 584 | 0, |
| 585 | destination_window_bytes[0], |
| 586 | destination_window_bytes[1], |
| 587 | destination_window_bytes[2], |
| 588 | destination_window_bytes[3], |
| 589 | x_offset_bytes[0], |
| 590 | x_offset_bytes[1], |
| 591 | y_offset_bytes[0], |
| 592 | y_offset_bytes[1], |
| 593 | source_bitmap_bytes[0], |
| 594 | source_bitmap_bytes[1], |
| 595 | source_bitmap_bytes[2], |
| 596 | source_bitmap_bytes[3], |
| 597 | ]; |
| 598 | let length_so_far = length_so_far + request0.len(); |
| 599 | assert_eq!(length_so_far % 4, 0); |
| 600 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 601 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 602 | ([request0.into()], vec![]) |
| 603 | } |
| 604 | /// Parse this request given its header, its body, and any fds that go along with it |
| 605 | #[cfg (feature = "request-parsing" )] |
| 606 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 607 | if header.minor_opcode != MASK_REQUEST { |
| 608 | return Err(ParseError::InvalidValue); |
| 609 | } |
| 610 | let (operation, remaining) = Op::try_parse(value)?; |
| 611 | let operation = operation.into(); |
| 612 | let (destination_kind, remaining) = Kind::try_parse(remaining)?; |
| 613 | let destination_kind = destination_kind.into(); |
| 614 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 615 | let (destination_window, remaining) = xproto::Window::try_parse(remaining)?; |
| 616 | let (x_offset, remaining) = i16::try_parse(remaining)?; |
| 617 | let (y_offset, remaining) = i16::try_parse(remaining)?; |
| 618 | let (source_bitmap, remaining) = xproto::Pixmap::try_parse(remaining)?; |
| 619 | let _ = remaining; |
| 620 | Ok(MaskRequest { |
| 621 | operation, |
| 622 | destination_kind, |
| 623 | destination_window, |
| 624 | x_offset, |
| 625 | y_offset, |
| 626 | source_bitmap, |
| 627 | }) |
| 628 | } |
| 629 | } |
| 630 | impl Request for MaskRequest { |
| 631 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 632 | |
| 633 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 634 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 635 | // Flatten the buffers into a single vector |
| 636 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 637 | (buf, fds) |
| 638 | } |
| 639 | } |
| 640 | impl crate::x11_utils::VoidRequest for MaskRequest { |
| 641 | } |
| 642 | |
| 643 | /// Opcode for the Combine request |
| 644 | pub const COMBINE_REQUEST: u8 = 3; |
| 645 | #[derive (Clone, Copy, Default)] |
| 646 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 647 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 648 | pub struct CombineRequest { |
| 649 | pub operation: SO, |
| 650 | pub destination_kind: SK, |
| 651 | pub source_kind: SK, |
| 652 | pub destination_window: xproto::Window, |
| 653 | pub x_offset: i16, |
| 654 | pub y_offset: i16, |
| 655 | pub source_window: xproto::Window, |
| 656 | } |
| 657 | impl_debug_if_no_extra_traits!(CombineRequest, "CombineRequest" ); |
| 658 | impl CombineRequest { |
| 659 | /// Serialize this request into bytes for the provided connection |
| 660 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 661 | let length_so_far = 0; |
| 662 | let operation_bytes = Op::from(self.operation).serialize(); |
| 663 | let destination_kind_bytes = Kind::from(self.destination_kind).serialize(); |
| 664 | let source_kind_bytes = Kind::from(self.source_kind).serialize(); |
| 665 | let destination_window_bytes = self.destination_window.serialize(); |
| 666 | let x_offset_bytes = self.x_offset.serialize(); |
| 667 | let y_offset_bytes = self.y_offset.serialize(); |
| 668 | let source_window_bytes = self.source_window.serialize(); |
| 669 | let mut request0 = vec![ |
| 670 | major_opcode, |
| 671 | COMBINE_REQUEST, |
| 672 | 0, |
| 673 | 0, |
| 674 | operation_bytes[0], |
| 675 | destination_kind_bytes[0], |
| 676 | source_kind_bytes[0], |
| 677 | 0, |
| 678 | destination_window_bytes[0], |
| 679 | destination_window_bytes[1], |
| 680 | destination_window_bytes[2], |
| 681 | destination_window_bytes[3], |
| 682 | x_offset_bytes[0], |
| 683 | x_offset_bytes[1], |
| 684 | y_offset_bytes[0], |
| 685 | y_offset_bytes[1], |
| 686 | source_window_bytes[0], |
| 687 | source_window_bytes[1], |
| 688 | source_window_bytes[2], |
| 689 | source_window_bytes[3], |
| 690 | ]; |
| 691 | let length_so_far = length_so_far + request0.len(); |
| 692 | assert_eq!(length_so_far % 4, 0); |
| 693 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 694 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 695 | ([request0.into()], vec![]) |
| 696 | } |
| 697 | /// Parse this request given its header, its body, and any fds that go along with it |
| 698 | #[cfg (feature = "request-parsing" )] |
| 699 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 700 | if header.minor_opcode != COMBINE_REQUEST { |
| 701 | return Err(ParseError::InvalidValue); |
| 702 | } |
| 703 | let (operation, remaining) = Op::try_parse(value)?; |
| 704 | let operation = operation.into(); |
| 705 | let (destination_kind, remaining) = Kind::try_parse(remaining)?; |
| 706 | let destination_kind = destination_kind.into(); |
| 707 | let (source_kind, remaining) = Kind::try_parse(remaining)?; |
| 708 | let source_kind = source_kind.into(); |
| 709 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 710 | let (destination_window, remaining) = xproto::Window::try_parse(remaining)?; |
| 711 | let (x_offset, remaining) = i16::try_parse(remaining)?; |
| 712 | let (y_offset, remaining) = i16::try_parse(remaining)?; |
| 713 | let (source_window, remaining) = xproto::Window::try_parse(remaining)?; |
| 714 | let _ = remaining; |
| 715 | Ok(CombineRequest { |
| 716 | operation, |
| 717 | destination_kind, |
| 718 | source_kind, |
| 719 | destination_window, |
| 720 | x_offset, |
| 721 | y_offset, |
| 722 | source_window, |
| 723 | }) |
| 724 | } |
| 725 | } |
| 726 | impl Request for CombineRequest { |
| 727 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 728 | |
| 729 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 730 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 731 | // Flatten the buffers into a single vector |
| 732 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 733 | (buf, fds) |
| 734 | } |
| 735 | } |
| 736 | impl crate::x11_utils::VoidRequest for CombineRequest { |
| 737 | } |
| 738 | |
| 739 | /// Opcode for the Offset request |
| 740 | pub const OFFSET_REQUEST: u8 = 4; |
| 741 | #[derive (Clone, Copy, Default)] |
| 742 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 743 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 744 | pub struct OffsetRequest { |
| 745 | pub destination_kind: SK, |
| 746 | pub destination_window: xproto::Window, |
| 747 | pub x_offset: i16, |
| 748 | pub y_offset: i16, |
| 749 | } |
| 750 | impl_debug_if_no_extra_traits!(OffsetRequest, "OffsetRequest" ); |
| 751 | impl OffsetRequest { |
| 752 | /// Serialize this request into bytes for the provided connection |
| 753 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 754 | let length_so_far = 0; |
| 755 | let destination_kind_bytes = Kind::from(self.destination_kind).serialize(); |
| 756 | let destination_window_bytes = self.destination_window.serialize(); |
| 757 | let x_offset_bytes = self.x_offset.serialize(); |
| 758 | let y_offset_bytes = self.y_offset.serialize(); |
| 759 | let mut request0 = vec![ |
| 760 | major_opcode, |
| 761 | OFFSET_REQUEST, |
| 762 | 0, |
| 763 | 0, |
| 764 | destination_kind_bytes[0], |
| 765 | 0, |
| 766 | 0, |
| 767 | 0, |
| 768 | destination_window_bytes[0], |
| 769 | destination_window_bytes[1], |
| 770 | destination_window_bytes[2], |
| 771 | destination_window_bytes[3], |
| 772 | x_offset_bytes[0], |
| 773 | x_offset_bytes[1], |
| 774 | y_offset_bytes[0], |
| 775 | y_offset_bytes[1], |
| 776 | ]; |
| 777 | let length_so_far = length_so_far + request0.len(); |
| 778 | assert_eq!(length_so_far % 4, 0); |
| 779 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 780 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 781 | ([request0.into()], vec![]) |
| 782 | } |
| 783 | /// Parse this request given its header, its body, and any fds that go along with it |
| 784 | #[cfg (feature = "request-parsing" )] |
| 785 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 786 | if header.minor_opcode != OFFSET_REQUEST { |
| 787 | return Err(ParseError::InvalidValue); |
| 788 | } |
| 789 | let (destination_kind, remaining) = Kind::try_parse(value)?; |
| 790 | let destination_kind = destination_kind.into(); |
| 791 | let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; |
| 792 | let (destination_window, remaining) = xproto::Window::try_parse(remaining)?; |
| 793 | let (x_offset, remaining) = i16::try_parse(remaining)?; |
| 794 | let (y_offset, remaining) = i16::try_parse(remaining)?; |
| 795 | let _ = remaining; |
| 796 | Ok(OffsetRequest { |
| 797 | destination_kind, |
| 798 | destination_window, |
| 799 | x_offset, |
| 800 | y_offset, |
| 801 | }) |
| 802 | } |
| 803 | } |
| 804 | impl Request for OffsetRequest { |
| 805 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 806 | |
| 807 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 808 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 809 | // Flatten the buffers into a single vector |
| 810 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 811 | (buf, fds) |
| 812 | } |
| 813 | } |
| 814 | impl crate::x11_utils::VoidRequest for OffsetRequest { |
| 815 | } |
| 816 | |
| 817 | /// Opcode for the QueryExtents request |
| 818 | pub const QUERY_EXTENTS_REQUEST: u8 = 5; |
| 819 | #[derive (Clone, Copy, Default)] |
| 820 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 821 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 822 | pub struct QueryExtentsRequest { |
| 823 | pub destination_window: xproto::Window, |
| 824 | } |
| 825 | impl_debug_if_no_extra_traits!(QueryExtentsRequest, "QueryExtentsRequest" ); |
| 826 | impl QueryExtentsRequest { |
| 827 | /// Serialize this request into bytes for the provided connection |
| 828 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 829 | let length_so_far = 0; |
| 830 | let destination_window_bytes = self.destination_window.serialize(); |
| 831 | let mut request0 = vec![ |
| 832 | major_opcode, |
| 833 | QUERY_EXTENTS_REQUEST, |
| 834 | 0, |
| 835 | 0, |
| 836 | destination_window_bytes[0], |
| 837 | destination_window_bytes[1], |
| 838 | destination_window_bytes[2], |
| 839 | destination_window_bytes[3], |
| 840 | ]; |
| 841 | let length_so_far = length_so_far + request0.len(); |
| 842 | assert_eq!(length_so_far % 4, 0); |
| 843 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 844 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 845 | ([request0.into()], vec![]) |
| 846 | } |
| 847 | /// Parse this request given its header, its body, and any fds that go along with it |
| 848 | #[cfg (feature = "request-parsing" )] |
| 849 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 850 | if header.minor_opcode != QUERY_EXTENTS_REQUEST { |
| 851 | return Err(ParseError::InvalidValue); |
| 852 | } |
| 853 | let (destination_window, remaining) = xproto::Window::try_parse(value)?; |
| 854 | let _ = remaining; |
| 855 | Ok(QueryExtentsRequest { |
| 856 | destination_window, |
| 857 | }) |
| 858 | } |
| 859 | } |
| 860 | impl Request for QueryExtentsRequest { |
| 861 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 862 | |
| 863 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 864 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 865 | // Flatten the buffers into a single vector |
| 866 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 867 | (buf, fds) |
| 868 | } |
| 869 | } |
| 870 | impl crate::x11_utils::ReplyRequest for QueryExtentsRequest { |
| 871 | type Reply = QueryExtentsReply; |
| 872 | } |
| 873 | |
| 874 | #[derive (Clone, Copy, Default)] |
| 875 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 876 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 877 | pub struct QueryExtentsReply { |
| 878 | pub sequence: u16, |
| 879 | pub length: u32, |
| 880 | pub bounding_shaped: bool, |
| 881 | pub clip_shaped: bool, |
| 882 | pub bounding_shape_extents_x: i16, |
| 883 | pub bounding_shape_extents_y: i16, |
| 884 | pub bounding_shape_extents_width: u16, |
| 885 | pub bounding_shape_extents_height: u16, |
| 886 | pub clip_shape_extents_x: i16, |
| 887 | pub clip_shape_extents_y: i16, |
| 888 | pub clip_shape_extents_width: u16, |
| 889 | pub clip_shape_extents_height: u16, |
| 890 | } |
| 891 | impl_debug_if_no_extra_traits!(QueryExtentsReply, "QueryExtentsReply" ); |
| 892 | impl TryParse for QueryExtentsReply { |
| 893 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 894 | let remaining = initial_value; |
| 895 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 896 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 897 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 898 | let (length, remaining) = u32::try_parse(remaining)?; |
| 899 | let (bounding_shaped, remaining) = bool::try_parse(remaining)?; |
| 900 | let (clip_shaped, remaining) = bool::try_parse(remaining)?; |
| 901 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 902 | let (bounding_shape_extents_x, remaining) = i16::try_parse(remaining)?; |
| 903 | let (bounding_shape_extents_y, remaining) = i16::try_parse(remaining)?; |
| 904 | let (bounding_shape_extents_width, remaining) = u16::try_parse(remaining)?; |
| 905 | let (bounding_shape_extents_height, remaining) = u16::try_parse(remaining)?; |
| 906 | let (clip_shape_extents_x, remaining) = i16::try_parse(remaining)?; |
| 907 | let (clip_shape_extents_y, remaining) = i16::try_parse(remaining)?; |
| 908 | let (clip_shape_extents_width, remaining) = u16::try_parse(remaining)?; |
| 909 | let (clip_shape_extents_height, remaining) = u16::try_parse(remaining)?; |
| 910 | if response_type != 1 { |
| 911 | return Err(ParseError::InvalidValue); |
| 912 | } |
| 913 | let result = QueryExtentsReply { sequence, length, bounding_shaped, clip_shaped, bounding_shape_extents_x, bounding_shape_extents_y, bounding_shape_extents_width, bounding_shape_extents_height, clip_shape_extents_x, clip_shape_extents_y, clip_shape_extents_width, clip_shape_extents_height }; |
| 914 | let _ = remaining; |
| 915 | let remaining = initial_value.get(32 + length as usize * 4..) |
| 916 | .ok_or(ParseError::InsufficientData)?; |
| 917 | Ok((result, remaining)) |
| 918 | } |
| 919 | } |
| 920 | impl Serialize for QueryExtentsReply { |
| 921 | type Bytes = [u8; 28]; |
| 922 | fn serialize(&self) -> [u8; 28] { |
| 923 | let response_type_bytes = &[1]; |
| 924 | let sequence_bytes = self.sequence.serialize(); |
| 925 | let length_bytes = self.length.serialize(); |
| 926 | let bounding_shaped_bytes = self.bounding_shaped.serialize(); |
| 927 | let clip_shaped_bytes = self.clip_shaped.serialize(); |
| 928 | let bounding_shape_extents_x_bytes = self.bounding_shape_extents_x.serialize(); |
| 929 | let bounding_shape_extents_y_bytes = self.bounding_shape_extents_y.serialize(); |
| 930 | let bounding_shape_extents_width_bytes = self.bounding_shape_extents_width.serialize(); |
| 931 | let bounding_shape_extents_height_bytes = self.bounding_shape_extents_height.serialize(); |
| 932 | let clip_shape_extents_x_bytes = self.clip_shape_extents_x.serialize(); |
| 933 | let clip_shape_extents_y_bytes = self.clip_shape_extents_y.serialize(); |
| 934 | let clip_shape_extents_width_bytes = self.clip_shape_extents_width.serialize(); |
| 935 | let clip_shape_extents_height_bytes = self.clip_shape_extents_height.serialize(); |
| 936 | [ |
| 937 | response_type_bytes[0], |
| 938 | 0, |
| 939 | sequence_bytes[0], |
| 940 | sequence_bytes[1], |
| 941 | length_bytes[0], |
| 942 | length_bytes[1], |
| 943 | length_bytes[2], |
| 944 | length_bytes[3], |
| 945 | bounding_shaped_bytes[0], |
| 946 | clip_shaped_bytes[0], |
| 947 | 0, |
| 948 | 0, |
| 949 | bounding_shape_extents_x_bytes[0], |
| 950 | bounding_shape_extents_x_bytes[1], |
| 951 | bounding_shape_extents_y_bytes[0], |
| 952 | bounding_shape_extents_y_bytes[1], |
| 953 | bounding_shape_extents_width_bytes[0], |
| 954 | bounding_shape_extents_width_bytes[1], |
| 955 | bounding_shape_extents_height_bytes[0], |
| 956 | bounding_shape_extents_height_bytes[1], |
| 957 | clip_shape_extents_x_bytes[0], |
| 958 | clip_shape_extents_x_bytes[1], |
| 959 | clip_shape_extents_y_bytes[0], |
| 960 | clip_shape_extents_y_bytes[1], |
| 961 | clip_shape_extents_width_bytes[0], |
| 962 | clip_shape_extents_width_bytes[1], |
| 963 | clip_shape_extents_height_bytes[0], |
| 964 | clip_shape_extents_height_bytes[1], |
| 965 | ] |
| 966 | } |
| 967 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 968 | bytes.reserve(28); |
| 969 | let response_type_bytes = &[1]; |
| 970 | bytes.push(response_type_bytes[0]); |
| 971 | bytes.extend_from_slice(&[0; 1]); |
| 972 | self.sequence.serialize_into(bytes); |
| 973 | self.length.serialize_into(bytes); |
| 974 | self.bounding_shaped.serialize_into(bytes); |
| 975 | self.clip_shaped.serialize_into(bytes); |
| 976 | bytes.extend_from_slice(&[0; 2]); |
| 977 | self.bounding_shape_extents_x.serialize_into(bytes); |
| 978 | self.bounding_shape_extents_y.serialize_into(bytes); |
| 979 | self.bounding_shape_extents_width.serialize_into(bytes); |
| 980 | self.bounding_shape_extents_height.serialize_into(bytes); |
| 981 | self.clip_shape_extents_x.serialize_into(bytes); |
| 982 | self.clip_shape_extents_y.serialize_into(bytes); |
| 983 | self.clip_shape_extents_width.serialize_into(bytes); |
| 984 | self.clip_shape_extents_height.serialize_into(bytes); |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | /// Opcode for the SelectInput request |
| 989 | pub const SELECT_INPUT_REQUEST: u8 = 6; |
| 990 | #[derive (Clone, Copy, Default)] |
| 991 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 992 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 993 | pub struct SelectInputRequest { |
| 994 | pub destination_window: xproto::Window, |
| 995 | pub enable: bool, |
| 996 | } |
| 997 | impl_debug_if_no_extra_traits!(SelectInputRequest, "SelectInputRequest" ); |
| 998 | impl SelectInputRequest { |
| 999 | /// Serialize this request into bytes for the provided connection |
| 1000 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 1001 | let length_so_far = 0; |
| 1002 | let destination_window_bytes = self.destination_window.serialize(); |
| 1003 | let enable_bytes = self.enable.serialize(); |
| 1004 | let mut request0 = vec![ |
| 1005 | major_opcode, |
| 1006 | SELECT_INPUT_REQUEST, |
| 1007 | 0, |
| 1008 | 0, |
| 1009 | destination_window_bytes[0], |
| 1010 | destination_window_bytes[1], |
| 1011 | destination_window_bytes[2], |
| 1012 | destination_window_bytes[3], |
| 1013 | enable_bytes[0], |
| 1014 | 0, |
| 1015 | 0, |
| 1016 | 0, |
| 1017 | ]; |
| 1018 | let length_so_far = length_so_far + request0.len(); |
| 1019 | assert_eq!(length_so_far % 4, 0); |
| 1020 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 1021 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 1022 | ([request0.into()], vec![]) |
| 1023 | } |
| 1024 | /// Parse this request given its header, its body, and any fds that go along with it |
| 1025 | #[cfg (feature = "request-parsing" )] |
| 1026 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 1027 | if header.minor_opcode != SELECT_INPUT_REQUEST { |
| 1028 | return Err(ParseError::InvalidValue); |
| 1029 | } |
| 1030 | let (destination_window, remaining) = xproto::Window::try_parse(value)?; |
| 1031 | let (enable, remaining) = bool::try_parse(remaining)?; |
| 1032 | let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; |
| 1033 | let _ = remaining; |
| 1034 | Ok(SelectInputRequest { |
| 1035 | destination_window, |
| 1036 | enable, |
| 1037 | }) |
| 1038 | } |
| 1039 | } |
| 1040 | impl Request for SelectInputRequest { |
| 1041 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 1042 | |
| 1043 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 1044 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 1045 | // Flatten the buffers into a single vector |
| 1046 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 1047 | (buf, fds) |
| 1048 | } |
| 1049 | } |
| 1050 | impl crate::x11_utils::VoidRequest for SelectInputRequest { |
| 1051 | } |
| 1052 | |
| 1053 | /// Opcode for the InputSelected request |
| 1054 | pub const INPUT_SELECTED_REQUEST: u8 = 7; |
| 1055 | #[derive (Clone, Copy, Default)] |
| 1056 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 1057 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1058 | pub struct InputSelectedRequest { |
| 1059 | pub destination_window: xproto::Window, |
| 1060 | } |
| 1061 | impl_debug_if_no_extra_traits!(InputSelectedRequest, "InputSelectedRequest" ); |
| 1062 | impl InputSelectedRequest { |
| 1063 | /// Serialize this request into bytes for the provided connection |
| 1064 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 1065 | let length_so_far = 0; |
| 1066 | let destination_window_bytes = self.destination_window.serialize(); |
| 1067 | let mut request0 = vec![ |
| 1068 | major_opcode, |
| 1069 | INPUT_SELECTED_REQUEST, |
| 1070 | 0, |
| 1071 | 0, |
| 1072 | destination_window_bytes[0], |
| 1073 | destination_window_bytes[1], |
| 1074 | destination_window_bytes[2], |
| 1075 | destination_window_bytes[3], |
| 1076 | ]; |
| 1077 | let length_so_far = length_so_far + request0.len(); |
| 1078 | assert_eq!(length_so_far % 4, 0); |
| 1079 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 1080 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 1081 | ([request0.into()], vec![]) |
| 1082 | } |
| 1083 | /// Parse this request given its header, its body, and any fds that go along with it |
| 1084 | #[cfg (feature = "request-parsing" )] |
| 1085 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 1086 | if header.minor_opcode != INPUT_SELECTED_REQUEST { |
| 1087 | return Err(ParseError::InvalidValue); |
| 1088 | } |
| 1089 | let (destination_window, remaining) = xproto::Window::try_parse(value)?; |
| 1090 | let _ = remaining; |
| 1091 | Ok(InputSelectedRequest { |
| 1092 | destination_window, |
| 1093 | }) |
| 1094 | } |
| 1095 | } |
| 1096 | impl Request for InputSelectedRequest { |
| 1097 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 1098 | |
| 1099 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 1100 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 1101 | // Flatten the buffers into a single vector |
| 1102 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 1103 | (buf, fds) |
| 1104 | } |
| 1105 | } |
| 1106 | impl crate::x11_utils::ReplyRequest for InputSelectedRequest { |
| 1107 | type Reply = InputSelectedReply; |
| 1108 | } |
| 1109 | |
| 1110 | #[derive (Clone, Copy, Default)] |
| 1111 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 1112 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1113 | pub struct InputSelectedReply { |
| 1114 | pub enabled: bool, |
| 1115 | pub sequence: u16, |
| 1116 | pub length: u32, |
| 1117 | } |
| 1118 | impl_debug_if_no_extra_traits!(InputSelectedReply, "InputSelectedReply" ); |
| 1119 | impl TryParse for InputSelectedReply { |
| 1120 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 1121 | let remaining: &[u8] = initial_value; |
| 1122 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 1123 | let (enabled: bool, remaining: &[u8]) = bool::try_parse(remaining)?; |
| 1124 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 1125 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 1126 | if response_type != 1 { |
| 1127 | return Err(ParseError::InvalidValue); |
| 1128 | } |
| 1129 | let result: InputSelectedReply = InputSelectedReply { enabled, sequence, length }; |
| 1130 | let _ = remaining; |
| 1131 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 1132 | .ok_or(err:ParseError::InsufficientData)?; |
| 1133 | Ok((result, remaining)) |
| 1134 | } |
| 1135 | } |
| 1136 | impl Serialize for InputSelectedReply { |
| 1137 | type Bytes = [u8; 8]; |
| 1138 | fn serialize(&self) -> [u8; 8] { |
| 1139 | let response_type_bytes = &[1]; |
| 1140 | let enabled_bytes = self.enabled.serialize(); |
| 1141 | let sequence_bytes = self.sequence.serialize(); |
| 1142 | let length_bytes = self.length.serialize(); |
| 1143 | [ |
| 1144 | response_type_bytes[0], |
| 1145 | enabled_bytes[0], |
| 1146 | sequence_bytes[0], |
| 1147 | sequence_bytes[1], |
| 1148 | length_bytes[0], |
| 1149 | length_bytes[1], |
| 1150 | length_bytes[2], |
| 1151 | length_bytes[3], |
| 1152 | ] |
| 1153 | } |
| 1154 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 1155 | bytes.reserve(8); |
| 1156 | let response_type_bytes = &[1]; |
| 1157 | bytes.push(response_type_bytes[0]); |
| 1158 | self.enabled.serialize_into(bytes); |
| 1159 | self.sequence.serialize_into(bytes); |
| 1160 | self.length.serialize_into(bytes); |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | /// Opcode for the GetRectangles request |
| 1165 | pub const GET_RECTANGLES_REQUEST: u8 = 8; |
| 1166 | #[derive (Clone, Copy, Default)] |
| 1167 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 1168 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1169 | pub struct GetRectanglesRequest { |
| 1170 | pub window: xproto::Window, |
| 1171 | pub source_kind: SK, |
| 1172 | } |
| 1173 | impl_debug_if_no_extra_traits!(GetRectanglesRequest, "GetRectanglesRequest" ); |
| 1174 | impl GetRectanglesRequest { |
| 1175 | /// Serialize this request into bytes for the provided connection |
| 1176 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 1177 | let length_so_far = 0; |
| 1178 | let window_bytes = self.window.serialize(); |
| 1179 | let source_kind_bytes = Kind::from(self.source_kind).serialize(); |
| 1180 | let mut request0 = vec![ |
| 1181 | major_opcode, |
| 1182 | GET_RECTANGLES_REQUEST, |
| 1183 | 0, |
| 1184 | 0, |
| 1185 | window_bytes[0], |
| 1186 | window_bytes[1], |
| 1187 | window_bytes[2], |
| 1188 | window_bytes[3], |
| 1189 | source_kind_bytes[0], |
| 1190 | 0, |
| 1191 | 0, |
| 1192 | 0, |
| 1193 | ]; |
| 1194 | let length_so_far = length_so_far + request0.len(); |
| 1195 | assert_eq!(length_so_far % 4, 0); |
| 1196 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 1197 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 1198 | ([request0.into()], vec![]) |
| 1199 | } |
| 1200 | /// Parse this request given its header, its body, and any fds that go along with it |
| 1201 | #[cfg (feature = "request-parsing" )] |
| 1202 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 1203 | if header.minor_opcode != GET_RECTANGLES_REQUEST { |
| 1204 | return Err(ParseError::InvalidValue); |
| 1205 | } |
| 1206 | let (window, remaining) = xproto::Window::try_parse(value)?; |
| 1207 | let (source_kind, remaining) = Kind::try_parse(remaining)?; |
| 1208 | let source_kind = source_kind.into(); |
| 1209 | let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; |
| 1210 | let _ = remaining; |
| 1211 | Ok(GetRectanglesRequest { |
| 1212 | window, |
| 1213 | source_kind, |
| 1214 | }) |
| 1215 | } |
| 1216 | } |
| 1217 | impl Request for GetRectanglesRequest { |
| 1218 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 1219 | |
| 1220 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 1221 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 1222 | // Flatten the buffers into a single vector |
| 1223 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 1224 | (buf, fds) |
| 1225 | } |
| 1226 | } |
| 1227 | impl crate::x11_utils::ReplyRequest for GetRectanglesRequest { |
| 1228 | type Reply = GetRectanglesReply; |
| 1229 | } |
| 1230 | |
| 1231 | #[derive (Clone, Default)] |
| 1232 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 1233 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1234 | pub struct GetRectanglesReply { |
| 1235 | pub ordering: xproto::ClipOrdering, |
| 1236 | pub sequence: u16, |
| 1237 | pub length: u32, |
| 1238 | pub rectangles: Vec<xproto::Rectangle>, |
| 1239 | } |
| 1240 | impl_debug_if_no_extra_traits!(GetRectanglesReply, "GetRectanglesReply" ); |
| 1241 | impl TryParse for GetRectanglesReply { |
| 1242 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 1243 | let remaining: &[u8] = initial_value; |
| 1244 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 1245 | let (ordering: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 1246 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 1247 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 1248 | let (rectangles_len: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 1249 | let remaining: &[u8] = remaining.get(20..).ok_or(err:ParseError::InsufficientData)?; |
| 1250 | let (rectangles: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<xproto::Rectangle>(data:remaining, list_length:rectangles_len.try_to_usize()?)?; |
| 1251 | if response_type != 1 { |
| 1252 | return Err(ParseError::InvalidValue); |
| 1253 | } |
| 1254 | let ordering: ClipOrdering = ordering.into(); |
| 1255 | let result: GetRectanglesReply = GetRectanglesReply { ordering, sequence, length, rectangles }; |
| 1256 | let _ = remaining; |
| 1257 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 1258 | .ok_or(err:ParseError::InsufficientData)?; |
| 1259 | Ok((result, remaining)) |
| 1260 | } |
| 1261 | } |
| 1262 | impl Serialize for GetRectanglesReply { |
| 1263 | type Bytes = Vec<u8>; |
| 1264 | fn serialize(&self) -> Vec<u8> { |
| 1265 | let mut result: Vec = Vec::new(); |
| 1266 | self.serialize_into(&mut result); |
| 1267 | result |
| 1268 | } |
| 1269 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 1270 | bytes.reserve(additional:32); |
| 1271 | let response_type_bytes: &[u8; 1] = &[1]; |
| 1272 | bytes.push(response_type_bytes[0]); |
| 1273 | u8::from(self.ordering).serialize_into(bytes); |
| 1274 | self.sequence.serialize_into(bytes); |
| 1275 | self.length.serialize_into(bytes); |
| 1276 | let rectangles_len: u32 = u32::try_from(self.rectangles.len()).expect(msg:"`rectangles` has too many elements" ); |
| 1277 | rectangles_len.serialize_into(bytes); |
| 1278 | bytes.extend_from_slice(&[0; 20]); |
| 1279 | self.rectangles.serialize_into(bytes); |
| 1280 | } |
| 1281 | } |
| 1282 | impl GetRectanglesReply { |
| 1283 | /// Get the value of the `rectangles_len` field. |
| 1284 | /// |
| 1285 | /// The `rectangles_len` field is used as the length field of the `rectangles` field. |
| 1286 | /// This function computes the field's value again based on the length of the list. |
| 1287 | /// |
| 1288 | /// # Panics |
| 1289 | /// |
| 1290 | /// Panics if the value cannot be represented in the target type. This |
| 1291 | /// cannot happen with values of the struct received from the X11 server. |
| 1292 | pub fn rectangles_len(&self) -> u32 { |
| 1293 | self.rectangles.len() |
| 1294 | .try_into().unwrap() |
| 1295 | } |
| 1296 | } |
| 1297 | |
| 1298 | |