| 1 | // This file contains generated code. Do not edit directly. |
| 2 | // To regenerate this, run 'make'. |
| 3 | |
| 4 | //! Bindings to the core X11 protocol. |
| 5 | //! |
| 6 | //! For more documentation on the X11 protocol, see the |
| 7 | //! [protocol reference manual](https://www.x.org/releases/X11R7.6/doc/xproto/x11protocol.html). |
| 8 | //! This is especially recommended for looking up the exact semantics of |
| 9 | //! specific errors, events, or requests. |
| 10 | |
| 11 | #![allow (clippy::too_many_arguments)] |
| 12 | // The code generator is simpler if it can always use conversions |
| 13 | #![allow (clippy::useless_conversion)] |
| 14 | |
| 15 | #[allow (unused_imports)] |
| 16 | use alloc::borrow::Cow; |
| 17 | #[allow (unused_imports)] |
| 18 | use core::convert::TryInto; |
| 19 | use alloc::vec; |
| 20 | use alloc::vec::Vec; |
| 21 | use core::convert::TryFrom; |
| 22 | use crate::errors::ParseError; |
| 23 | #[allow (unused_imports)] |
| 24 | use crate::x11_utils::TryIntoUSize; |
| 25 | use crate::BufWithFds; |
| 26 | #[allow (unused_imports)] |
| 27 | use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; |
| 28 | #[allow (unused_imports)] |
| 29 | use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; |
| 30 | |
| 31 | #[derive (Clone, Copy, Default)] |
| 32 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 33 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 34 | pub struct Char2b { |
| 35 | pub byte1: u8, |
| 36 | pub byte2: u8, |
| 37 | } |
| 38 | impl_debug_if_no_extra_traits!(Char2b, "Char2b" ); |
| 39 | impl TryParse for Char2b { |
| 40 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 41 | let (byte1: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 42 | let (byte2: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 43 | let result: Char2b = Char2b { byte1, byte2 }; |
| 44 | Ok((result, remaining)) |
| 45 | } |
| 46 | } |
| 47 | impl Serialize for Char2b { |
| 48 | type Bytes = [u8; 2]; |
| 49 | fn serialize(&self) -> [u8; 2] { |
| 50 | let byte1_bytes: [u8; 1] = self.byte1.serialize(); |
| 51 | let byte2_bytes: [u8; 1] = self.byte2.serialize(); |
| 52 | [ |
| 53 | byte1_bytes[0], |
| 54 | byte2_bytes[0], |
| 55 | ] |
| 56 | } |
| 57 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 58 | bytes.reserve(additional:2); |
| 59 | self.byte1.serialize_into(bytes); |
| 60 | self.byte2.serialize_into(bytes); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | pub type Window = u32; |
| 65 | |
| 66 | pub type Pixmap = u32; |
| 67 | |
| 68 | pub type Cursor = u32; |
| 69 | |
| 70 | pub type Font = u32; |
| 71 | |
| 72 | pub type Gcontext = u32; |
| 73 | |
| 74 | pub type Colormap = u32; |
| 75 | |
| 76 | pub type Atom = u32; |
| 77 | |
| 78 | pub type Drawable = u32; |
| 79 | |
| 80 | pub type Fontable = u32; |
| 81 | |
| 82 | pub type Bool32 = u32; |
| 83 | |
| 84 | pub type Visualid = u32; |
| 85 | |
| 86 | pub type Timestamp = u32; |
| 87 | |
| 88 | pub type Keysym = u32; |
| 89 | |
| 90 | pub type Keycode = u8; |
| 91 | |
| 92 | pub type Keycode32 = u32; |
| 93 | |
| 94 | pub type Button = u8; |
| 95 | |
| 96 | #[derive (Clone, Copy, Default)] |
| 97 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 98 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 99 | pub struct Point { |
| 100 | pub x: i16, |
| 101 | pub y: i16, |
| 102 | } |
| 103 | impl_debug_if_no_extra_traits!(Point, "Point" ); |
| 104 | impl TryParse for Point { |
| 105 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 106 | let (x: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 107 | let (y: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 108 | let result: Point = Point { x, y }; |
| 109 | Ok((result, remaining)) |
| 110 | } |
| 111 | } |
| 112 | impl Serialize for Point { |
| 113 | type Bytes = [u8; 4]; |
| 114 | fn serialize(&self) -> [u8; 4] { |
| 115 | let x_bytes: [u8; 2] = self.x.serialize(); |
| 116 | let y_bytes: [u8; 2] = self.y.serialize(); |
| 117 | [ |
| 118 | x_bytes[0], |
| 119 | x_bytes[1], |
| 120 | y_bytes[0], |
| 121 | y_bytes[1], |
| 122 | ] |
| 123 | } |
| 124 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 125 | bytes.reserve(additional:4); |
| 126 | self.x.serialize_into(bytes); |
| 127 | self.y.serialize_into(bytes); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | #[derive (Clone, Copy, Default)] |
| 132 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 133 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 134 | pub struct Rectangle { |
| 135 | pub x: i16, |
| 136 | pub y: i16, |
| 137 | pub width: u16, |
| 138 | pub height: u16, |
| 139 | } |
| 140 | impl_debug_if_no_extra_traits!(Rectangle, "Rectangle" ); |
| 141 | impl TryParse for Rectangle { |
| 142 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 143 | let (x: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 144 | let (y: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 145 | let (width: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 146 | let (height: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 147 | let result: Rectangle = Rectangle { x, y, width, height }; |
| 148 | Ok((result, remaining)) |
| 149 | } |
| 150 | } |
| 151 | impl Serialize for Rectangle { |
| 152 | type Bytes = [u8; 8]; |
| 153 | fn serialize(&self) -> [u8; 8] { |
| 154 | let x_bytes = self.x.serialize(); |
| 155 | let y_bytes = self.y.serialize(); |
| 156 | let width_bytes = self.width.serialize(); |
| 157 | let height_bytes = self.height.serialize(); |
| 158 | [ |
| 159 | x_bytes[0], |
| 160 | x_bytes[1], |
| 161 | y_bytes[0], |
| 162 | y_bytes[1], |
| 163 | width_bytes[0], |
| 164 | width_bytes[1], |
| 165 | height_bytes[0], |
| 166 | height_bytes[1], |
| 167 | ] |
| 168 | } |
| 169 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 170 | bytes.reserve(8); |
| 171 | self.x.serialize_into(bytes); |
| 172 | self.y.serialize_into(bytes); |
| 173 | self.width.serialize_into(bytes); |
| 174 | self.height.serialize_into(bytes); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | #[derive (Clone, Copy, Default)] |
| 179 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 180 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 181 | pub struct Arc { |
| 182 | pub x: i16, |
| 183 | pub y: i16, |
| 184 | pub width: u16, |
| 185 | pub height: u16, |
| 186 | pub angle1: i16, |
| 187 | pub angle2: i16, |
| 188 | } |
| 189 | impl_debug_if_no_extra_traits!(Arc, "Arc" ); |
| 190 | impl TryParse for Arc { |
| 191 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 192 | let (x: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 193 | let (y: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 194 | let (width: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 195 | let (height: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 196 | let (angle1: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 197 | let (angle2: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 198 | let result: Arc = Arc { x, y, width, height, angle1, angle2 }; |
| 199 | Ok((result, remaining)) |
| 200 | } |
| 201 | } |
| 202 | impl Serialize for Arc { |
| 203 | type Bytes = [u8; 12]; |
| 204 | fn serialize(&self) -> [u8; 12] { |
| 205 | let x_bytes = self.x.serialize(); |
| 206 | let y_bytes = self.y.serialize(); |
| 207 | let width_bytes = self.width.serialize(); |
| 208 | let height_bytes = self.height.serialize(); |
| 209 | let angle1_bytes = self.angle1.serialize(); |
| 210 | let angle2_bytes = self.angle2.serialize(); |
| 211 | [ |
| 212 | x_bytes[0], |
| 213 | x_bytes[1], |
| 214 | y_bytes[0], |
| 215 | y_bytes[1], |
| 216 | width_bytes[0], |
| 217 | width_bytes[1], |
| 218 | height_bytes[0], |
| 219 | height_bytes[1], |
| 220 | angle1_bytes[0], |
| 221 | angle1_bytes[1], |
| 222 | angle2_bytes[0], |
| 223 | angle2_bytes[1], |
| 224 | ] |
| 225 | } |
| 226 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 227 | bytes.reserve(12); |
| 228 | self.x.serialize_into(bytes); |
| 229 | self.y.serialize_into(bytes); |
| 230 | self.width.serialize_into(bytes); |
| 231 | self.height.serialize_into(bytes); |
| 232 | self.angle1.serialize_into(bytes); |
| 233 | self.angle2.serialize_into(bytes); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | #[derive (Clone, Copy, Default)] |
| 238 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 239 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 240 | pub struct Format { |
| 241 | pub depth: u8, |
| 242 | pub bits_per_pixel: u8, |
| 243 | pub scanline_pad: u8, |
| 244 | } |
| 245 | impl_debug_if_no_extra_traits!(Format, "Format" ); |
| 246 | impl TryParse for Format { |
| 247 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 248 | let (depth: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 249 | let (bits_per_pixel: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 250 | let (scanline_pad: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 251 | let remaining: &[u8] = remaining.get(5..).ok_or(err:ParseError::InsufficientData)?; |
| 252 | let result: Format = Format { depth, bits_per_pixel, scanline_pad }; |
| 253 | Ok((result, remaining)) |
| 254 | } |
| 255 | } |
| 256 | impl Serialize for Format { |
| 257 | type Bytes = [u8; 8]; |
| 258 | fn serialize(&self) -> [u8; 8] { |
| 259 | let depth_bytes = self.depth.serialize(); |
| 260 | let bits_per_pixel_bytes = self.bits_per_pixel.serialize(); |
| 261 | let scanline_pad_bytes = self.scanline_pad.serialize(); |
| 262 | [ |
| 263 | depth_bytes[0], |
| 264 | bits_per_pixel_bytes[0], |
| 265 | scanline_pad_bytes[0], |
| 266 | 0, |
| 267 | 0, |
| 268 | 0, |
| 269 | 0, |
| 270 | 0, |
| 271 | ] |
| 272 | } |
| 273 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 274 | bytes.reserve(8); |
| 275 | self.depth.serialize_into(bytes); |
| 276 | self.bits_per_pixel.serialize_into(bytes); |
| 277 | self.scanline_pad.serialize_into(bytes); |
| 278 | bytes.extend_from_slice(&[0; 5]); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 283 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 284 | pub struct VisualClass(u8); |
| 285 | impl VisualClass { |
| 286 | pub const STATIC_GRAY: Self = Self(0); |
| 287 | pub const GRAY_SCALE: Self = Self(1); |
| 288 | pub const STATIC_COLOR: Self = Self(2); |
| 289 | pub const PSEUDO_COLOR: Self = Self(3); |
| 290 | pub const TRUE_COLOR: Self = Self(4); |
| 291 | pub const DIRECT_COLOR: Self = Self(5); |
| 292 | } |
| 293 | impl From<VisualClass> for u8 { |
| 294 | #[inline ] |
| 295 | fn from(input: VisualClass) -> Self { |
| 296 | input.0 |
| 297 | } |
| 298 | } |
| 299 | impl From<VisualClass> for Option<u8> { |
| 300 | #[inline ] |
| 301 | fn from(input: VisualClass) -> Self { |
| 302 | Some(input.0) |
| 303 | } |
| 304 | } |
| 305 | impl From<VisualClass> for u16 { |
| 306 | #[inline ] |
| 307 | fn from(input: VisualClass) -> Self { |
| 308 | u16::from(input.0) |
| 309 | } |
| 310 | } |
| 311 | impl From<VisualClass> for Option<u16> { |
| 312 | #[inline ] |
| 313 | fn from(input: VisualClass) -> Self { |
| 314 | Some(u16::from(input.0)) |
| 315 | } |
| 316 | } |
| 317 | impl From<VisualClass> for u32 { |
| 318 | #[inline ] |
| 319 | fn from(input: VisualClass) -> Self { |
| 320 | u32::from(input.0) |
| 321 | } |
| 322 | } |
| 323 | impl From<VisualClass> for Option<u32> { |
| 324 | #[inline ] |
| 325 | fn from(input: VisualClass) -> Self { |
| 326 | Some(u32::from(input.0)) |
| 327 | } |
| 328 | } |
| 329 | impl From<u8> for VisualClass { |
| 330 | #[inline ] |
| 331 | fn from(value: u8) -> Self { |
| 332 | Self(value) |
| 333 | } |
| 334 | } |
| 335 | impl core::fmt::Debug for VisualClass { |
| 336 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 337 | let variants: [(u32, &'static str, &'static …); 6] = [ |
| 338 | (Self::STATIC_GRAY.0.into(), "STATIC_GRAY" , "StaticGray" ), |
| 339 | (Self::GRAY_SCALE.0.into(), "GRAY_SCALE" , "GrayScale" ), |
| 340 | (Self::STATIC_COLOR.0.into(), "STATIC_COLOR" , "StaticColor" ), |
| 341 | (Self::PSEUDO_COLOR.0.into(), "PSEUDO_COLOR" , "PseudoColor" ), |
| 342 | (Self::TRUE_COLOR.0.into(), "TRUE_COLOR" , "TrueColor" ), |
| 343 | (Self::DIRECT_COLOR.0.into(), "DIRECT_COLOR" , "DirectColor" ), |
| 344 | ]; |
| 345 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | #[derive (Clone, Copy, Default)] |
| 350 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 351 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 352 | pub struct Visualtype { |
| 353 | pub visual_id: Visualid, |
| 354 | pub class: VisualClass, |
| 355 | pub bits_per_rgb_value: u8, |
| 356 | pub colormap_entries: u16, |
| 357 | pub red_mask: u32, |
| 358 | pub green_mask: u32, |
| 359 | pub blue_mask: u32, |
| 360 | } |
| 361 | impl_debug_if_no_extra_traits!(Visualtype, "Visualtype" ); |
| 362 | impl TryParse for Visualtype { |
| 363 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 364 | let (visual_id: u32, remaining: &[u8]) = Visualid::try_parse(remaining)?; |
| 365 | let (class: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 366 | let (bits_per_rgb_value: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 367 | let (colormap_entries: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 368 | let (red_mask: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 369 | let (green_mask: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 370 | let (blue_mask: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 371 | let remaining: &[u8] = remaining.get(4..).ok_or(err:ParseError::InsufficientData)?; |
| 372 | let class: VisualClass = class.into(); |
| 373 | let result: Visualtype = Visualtype { visual_id, class, bits_per_rgb_value, colormap_entries, red_mask, green_mask, blue_mask }; |
| 374 | Ok((result, remaining)) |
| 375 | } |
| 376 | } |
| 377 | impl Serialize for Visualtype { |
| 378 | type Bytes = [u8; 24]; |
| 379 | fn serialize(&self) -> [u8; 24] { |
| 380 | let visual_id_bytes = self.visual_id.serialize(); |
| 381 | let class_bytes = u8::from(self.class).serialize(); |
| 382 | let bits_per_rgb_value_bytes = self.bits_per_rgb_value.serialize(); |
| 383 | let colormap_entries_bytes = self.colormap_entries.serialize(); |
| 384 | let red_mask_bytes = self.red_mask.serialize(); |
| 385 | let green_mask_bytes = self.green_mask.serialize(); |
| 386 | let blue_mask_bytes = self.blue_mask.serialize(); |
| 387 | [ |
| 388 | visual_id_bytes[0], |
| 389 | visual_id_bytes[1], |
| 390 | visual_id_bytes[2], |
| 391 | visual_id_bytes[3], |
| 392 | class_bytes[0], |
| 393 | bits_per_rgb_value_bytes[0], |
| 394 | colormap_entries_bytes[0], |
| 395 | colormap_entries_bytes[1], |
| 396 | red_mask_bytes[0], |
| 397 | red_mask_bytes[1], |
| 398 | red_mask_bytes[2], |
| 399 | red_mask_bytes[3], |
| 400 | green_mask_bytes[0], |
| 401 | green_mask_bytes[1], |
| 402 | green_mask_bytes[2], |
| 403 | green_mask_bytes[3], |
| 404 | blue_mask_bytes[0], |
| 405 | blue_mask_bytes[1], |
| 406 | blue_mask_bytes[2], |
| 407 | blue_mask_bytes[3], |
| 408 | 0, |
| 409 | 0, |
| 410 | 0, |
| 411 | 0, |
| 412 | ] |
| 413 | } |
| 414 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 415 | bytes.reserve(24); |
| 416 | self.visual_id.serialize_into(bytes); |
| 417 | u8::from(self.class).serialize_into(bytes); |
| 418 | self.bits_per_rgb_value.serialize_into(bytes); |
| 419 | self.colormap_entries.serialize_into(bytes); |
| 420 | self.red_mask.serialize_into(bytes); |
| 421 | self.green_mask.serialize_into(bytes); |
| 422 | self.blue_mask.serialize_into(bytes); |
| 423 | bytes.extend_from_slice(&[0; 4]); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | #[derive (Clone, Default)] |
| 428 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 429 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 430 | pub struct Depth { |
| 431 | pub depth: u8, |
| 432 | pub visuals: Vec<Visualtype>, |
| 433 | } |
| 434 | impl_debug_if_no_extra_traits!(Depth, "Depth" ); |
| 435 | impl TryParse for Depth { |
| 436 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 437 | let (depth: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 438 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 439 | let (visuals_len: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 440 | let remaining: &[u8] = remaining.get(4..).ok_or(err:ParseError::InsufficientData)?; |
| 441 | let (visuals: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<Visualtype>(data:remaining, list_length:visuals_len.try_to_usize()?)?; |
| 442 | let result: Depth = Depth { depth, visuals }; |
| 443 | Ok((result, remaining)) |
| 444 | } |
| 445 | } |
| 446 | impl Serialize for Depth { |
| 447 | type Bytes = Vec<u8>; |
| 448 | fn serialize(&self) -> Vec<u8> { |
| 449 | let mut result: Vec = Vec::new(); |
| 450 | self.serialize_into(&mut result); |
| 451 | result |
| 452 | } |
| 453 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 454 | bytes.reserve(additional:8); |
| 455 | self.depth.serialize_into(bytes); |
| 456 | bytes.extend_from_slice(&[0; 1]); |
| 457 | let visuals_len: u16 = u16::try_from(self.visuals.len()).expect(msg:"`visuals` has too many elements" ); |
| 458 | visuals_len.serialize_into(bytes); |
| 459 | bytes.extend_from_slice(&[0; 4]); |
| 460 | self.visuals.serialize_into(bytes); |
| 461 | } |
| 462 | } |
| 463 | impl Depth { |
| 464 | /// Get the value of the `visuals_len` field. |
| 465 | /// |
| 466 | /// The `visuals_len` field is used as the length field of the `visuals` field. |
| 467 | /// This function computes the field's value again based on the length of the list. |
| 468 | /// |
| 469 | /// # Panics |
| 470 | /// |
| 471 | /// Panics if the value cannot be represented in the target type. This |
| 472 | /// cannot happen with values of the struct received from the X11 server. |
| 473 | pub fn visuals_len(&self) -> u16 { |
| 474 | self.visuals.len() |
| 475 | .try_into().unwrap() |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 480 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 481 | pub struct EventMask(u32); |
| 482 | impl EventMask { |
| 483 | pub const NO_EVENT: Self = Self(0); |
| 484 | pub const KEY_PRESS: Self = Self(1 << 0); |
| 485 | pub const KEY_RELEASE: Self = Self(1 << 1); |
| 486 | pub const BUTTON_PRESS: Self = Self(1 << 2); |
| 487 | pub const BUTTON_RELEASE: Self = Self(1 << 3); |
| 488 | pub const ENTER_WINDOW: Self = Self(1 << 4); |
| 489 | pub const LEAVE_WINDOW: Self = Self(1 << 5); |
| 490 | pub const POINTER_MOTION: Self = Self(1 << 6); |
| 491 | pub const POINTER_MOTION_HINT: Self = Self(1 << 7); |
| 492 | pub const BUTTON1_MOTION: Self = Self(1 << 8); |
| 493 | pub const BUTTON2_MOTION: Self = Self(1 << 9); |
| 494 | pub const BUTTON3_MOTION: Self = Self(1 << 10); |
| 495 | pub const BUTTON4_MOTION: Self = Self(1 << 11); |
| 496 | pub const BUTTON5_MOTION: Self = Self(1 << 12); |
| 497 | pub const BUTTON_MOTION: Self = Self(1 << 13); |
| 498 | pub const KEYMAP_STATE: Self = Self(1 << 14); |
| 499 | pub const EXPOSURE: Self = Self(1 << 15); |
| 500 | pub const VISIBILITY_CHANGE: Self = Self(1 << 16); |
| 501 | pub const STRUCTURE_NOTIFY: Self = Self(1 << 17); |
| 502 | pub const RESIZE_REDIRECT: Self = Self(1 << 18); |
| 503 | pub const SUBSTRUCTURE_NOTIFY: Self = Self(1 << 19); |
| 504 | pub const SUBSTRUCTURE_REDIRECT: Self = Self(1 << 20); |
| 505 | pub const FOCUS_CHANGE: Self = Self(1 << 21); |
| 506 | pub const PROPERTY_CHANGE: Self = Self(1 << 22); |
| 507 | pub const COLOR_MAP_CHANGE: Self = Self(1 << 23); |
| 508 | pub const OWNER_GRAB_BUTTON: Self = Self(1 << 24); |
| 509 | } |
| 510 | impl From<EventMask> for u32 { |
| 511 | #[inline ] |
| 512 | fn from(input: EventMask) -> Self { |
| 513 | input.0 |
| 514 | } |
| 515 | } |
| 516 | impl From<EventMask> for Option<u32> { |
| 517 | #[inline ] |
| 518 | fn from(input: EventMask) -> Self { |
| 519 | Some(input.0) |
| 520 | } |
| 521 | } |
| 522 | impl From<u8> for EventMask { |
| 523 | #[inline ] |
| 524 | fn from(value: u8) -> Self { |
| 525 | Self(value.into()) |
| 526 | } |
| 527 | } |
| 528 | impl From<u16> for EventMask { |
| 529 | #[inline ] |
| 530 | fn from(value: u16) -> Self { |
| 531 | Self(value.into()) |
| 532 | } |
| 533 | } |
| 534 | impl From<u32> for EventMask { |
| 535 | #[inline ] |
| 536 | fn from(value: u32) -> Self { |
| 537 | Self(value) |
| 538 | } |
| 539 | } |
| 540 | impl core::fmt::Debug for EventMask { |
| 541 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 542 | let variants = [ |
| 543 | (Self::NO_EVENT.0, "NO_EVENT" , "NoEvent" ), |
| 544 | (Self::KEY_PRESS.0, "KEY_PRESS" , "KeyPress" ), |
| 545 | (Self::KEY_RELEASE.0, "KEY_RELEASE" , "KeyRelease" ), |
| 546 | (Self::BUTTON_PRESS.0, "BUTTON_PRESS" , "ButtonPress" ), |
| 547 | (Self::BUTTON_RELEASE.0, "BUTTON_RELEASE" , "ButtonRelease" ), |
| 548 | (Self::ENTER_WINDOW.0, "ENTER_WINDOW" , "EnterWindow" ), |
| 549 | (Self::LEAVE_WINDOW.0, "LEAVE_WINDOW" , "LeaveWindow" ), |
| 550 | (Self::POINTER_MOTION.0, "POINTER_MOTION" , "PointerMotion" ), |
| 551 | (Self::POINTER_MOTION_HINT.0, "POINTER_MOTION_HINT" , "PointerMotionHint" ), |
| 552 | (Self::BUTTON1_MOTION.0, "BUTTON1_MOTION" , "Button1Motion" ), |
| 553 | (Self::BUTTON2_MOTION.0, "BUTTON2_MOTION" , "Button2Motion" ), |
| 554 | (Self::BUTTON3_MOTION.0, "BUTTON3_MOTION" , "Button3Motion" ), |
| 555 | (Self::BUTTON4_MOTION.0, "BUTTON4_MOTION" , "Button4Motion" ), |
| 556 | (Self::BUTTON5_MOTION.0, "BUTTON5_MOTION" , "Button5Motion" ), |
| 557 | (Self::BUTTON_MOTION.0, "BUTTON_MOTION" , "ButtonMotion" ), |
| 558 | (Self::KEYMAP_STATE.0, "KEYMAP_STATE" , "KeymapState" ), |
| 559 | (Self::EXPOSURE.0, "EXPOSURE" , "Exposure" ), |
| 560 | (Self::VISIBILITY_CHANGE.0, "VISIBILITY_CHANGE" , "VisibilityChange" ), |
| 561 | (Self::STRUCTURE_NOTIFY.0, "STRUCTURE_NOTIFY" , "StructureNotify" ), |
| 562 | (Self::RESIZE_REDIRECT.0, "RESIZE_REDIRECT" , "ResizeRedirect" ), |
| 563 | (Self::SUBSTRUCTURE_NOTIFY.0, "SUBSTRUCTURE_NOTIFY" , "SubstructureNotify" ), |
| 564 | (Self::SUBSTRUCTURE_REDIRECT.0, "SUBSTRUCTURE_REDIRECT" , "SubstructureRedirect" ), |
| 565 | (Self::FOCUS_CHANGE.0, "FOCUS_CHANGE" , "FocusChange" ), |
| 566 | (Self::PROPERTY_CHANGE.0, "PROPERTY_CHANGE" , "PropertyChange" ), |
| 567 | (Self::COLOR_MAP_CHANGE.0, "COLOR_MAP_CHANGE" , "ColorMapChange" ), |
| 568 | (Self::OWNER_GRAB_BUTTON.0, "OWNER_GRAB_BUTTON" , "OwnerGrabButton" ), |
| 569 | ]; |
| 570 | pretty_print_bitmask(fmt, self.0, &variants) |
| 571 | } |
| 572 | } |
| 573 | bitmask_binop!(EventMask, u32); |
| 574 | |
| 575 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 576 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 577 | pub struct BackingStore(u32); |
| 578 | impl BackingStore { |
| 579 | pub const NOT_USEFUL: Self = Self(0); |
| 580 | pub const WHEN_MAPPED: Self = Self(1); |
| 581 | pub const ALWAYS: Self = Self(2); |
| 582 | } |
| 583 | impl From<BackingStore> for u32 { |
| 584 | #[inline ] |
| 585 | fn from(input: BackingStore) -> Self { |
| 586 | input.0 |
| 587 | } |
| 588 | } |
| 589 | impl From<BackingStore> for Option<u32> { |
| 590 | #[inline ] |
| 591 | fn from(input: BackingStore) -> Self { |
| 592 | Some(input.0) |
| 593 | } |
| 594 | } |
| 595 | impl From<u8> for BackingStore { |
| 596 | #[inline ] |
| 597 | fn from(value: u8) -> Self { |
| 598 | Self(value.into()) |
| 599 | } |
| 600 | } |
| 601 | impl From<u16> for BackingStore { |
| 602 | #[inline ] |
| 603 | fn from(value: u16) -> Self { |
| 604 | Self(value.into()) |
| 605 | } |
| 606 | } |
| 607 | impl From<u32> for BackingStore { |
| 608 | #[inline ] |
| 609 | fn from(value: u32) -> Self { |
| 610 | Self(value) |
| 611 | } |
| 612 | } |
| 613 | impl core::fmt::Debug for BackingStore { |
| 614 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 615 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 616 | (Self::NOT_USEFUL.0, "NOT_USEFUL" , "NotUseful" ), |
| 617 | (Self::WHEN_MAPPED.0, "WHEN_MAPPED" , "WhenMapped" ), |
| 618 | (Self::ALWAYS.0, "ALWAYS" , "Always" ), |
| 619 | ]; |
| 620 | pretty_print_enum(fmt, self.0, &variants) |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | #[derive (Clone, Default)] |
| 625 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 626 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 627 | pub struct Screen { |
| 628 | pub root: Window, |
| 629 | pub default_colormap: Colormap, |
| 630 | pub white_pixel: u32, |
| 631 | pub black_pixel: u32, |
| 632 | pub current_input_masks: EventMask, |
| 633 | pub width_in_pixels: u16, |
| 634 | pub height_in_pixels: u16, |
| 635 | pub width_in_millimeters: u16, |
| 636 | pub height_in_millimeters: u16, |
| 637 | pub min_installed_maps: u16, |
| 638 | pub max_installed_maps: u16, |
| 639 | pub root_visual: Visualid, |
| 640 | pub backing_stores: BackingStore, |
| 641 | pub save_unders: bool, |
| 642 | pub root_depth: u8, |
| 643 | pub allowed_depths: Vec<Depth>, |
| 644 | } |
| 645 | impl_debug_if_no_extra_traits!(Screen, "Screen" ); |
| 646 | impl TryParse for Screen { |
| 647 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 648 | let (root, remaining) = Window::try_parse(remaining)?; |
| 649 | let (default_colormap, remaining) = Colormap::try_parse(remaining)?; |
| 650 | let (white_pixel, remaining) = u32::try_parse(remaining)?; |
| 651 | let (black_pixel, remaining) = u32::try_parse(remaining)?; |
| 652 | let (current_input_masks, remaining) = u32::try_parse(remaining)?; |
| 653 | let (width_in_pixels, remaining) = u16::try_parse(remaining)?; |
| 654 | let (height_in_pixels, remaining) = u16::try_parse(remaining)?; |
| 655 | let (width_in_millimeters, remaining) = u16::try_parse(remaining)?; |
| 656 | let (height_in_millimeters, remaining) = u16::try_parse(remaining)?; |
| 657 | let (min_installed_maps, remaining) = u16::try_parse(remaining)?; |
| 658 | let (max_installed_maps, remaining) = u16::try_parse(remaining)?; |
| 659 | let (root_visual, remaining) = Visualid::try_parse(remaining)?; |
| 660 | let (backing_stores, remaining) = u8::try_parse(remaining)?; |
| 661 | let (save_unders, remaining) = bool::try_parse(remaining)?; |
| 662 | let (root_depth, remaining) = u8::try_parse(remaining)?; |
| 663 | let (allowed_depths_len, remaining) = u8::try_parse(remaining)?; |
| 664 | let (allowed_depths, remaining) = crate::x11_utils::parse_list::<Depth>(remaining, allowed_depths_len.try_to_usize()?)?; |
| 665 | let current_input_masks = current_input_masks.into(); |
| 666 | let backing_stores = backing_stores.into(); |
| 667 | let result = Screen { root, default_colormap, white_pixel, black_pixel, current_input_masks, width_in_pixels, height_in_pixels, width_in_millimeters, height_in_millimeters, min_installed_maps, max_installed_maps, root_visual, backing_stores, save_unders, root_depth, allowed_depths }; |
| 668 | Ok((result, remaining)) |
| 669 | } |
| 670 | } |
| 671 | impl Serialize for Screen { |
| 672 | type Bytes = Vec<u8>; |
| 673 | fn serialize(&self) -> Vec<u8> { |
| 674 | let mut result = Vec::new(); |
| 675 | self.serialize_into(&mut result); |
| 676 | result |
| 677 | } |
| 678 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 679 | bytes.reserve(40); |
| 680 | self.root.serialize_into(bytes); |
| 681 | self.default_colormap.serialize_into(bytes); |
| 682 | self.white_pixel.serialize_into(bytes); |
| 683 | self.black_pixel.serialize_into(bytes); |
| 684 | u32::from(self.current_input_masks).serialize_into(bytes); |
| 685 | self.width_in_pixels.serialize_into(bytes); |
| 686 | self.height_in_pixels.serialize_into(bytes); |
| 687 | self.width_in_millimeters.serialize_into(bytes); |
| 688 | self.height_in_millimeters.serialize_into(bytes); |
| 689 | self.min_installed_maps.serialize_into(bytes); |
| 690 | self.max_installed_maps.serialize_into(bytes); |
| 691 | self.root_visual.serialize_into(bytes); |
| 692 | (u32::from(self.backing_stores) as u8).serialize_into(bytes); |
| 693 | self.save_unders.serialize_into(bytes); |
| 694 | self.root_depth.serialize_into(bytes); |
| 695 | let allowed_depths_len = u8::try_from(self.allowed_depths.len()).expect("`allowed_depths` has too many elements" ); |
| 696 | allowed_depths_len.serialize_into(bytes); |
| 697 | self.allowed_depths.serialize_into(bytes); |
| 698 | } |
| 699 | } |
| 700 | impl Screen { |
| 701 | /// Get the value of the `allowed_depths_len` field. |
| 702 | /// |
| 703 | /// The `allowed_depths_len` field is used as the length field of the `allowed_depths` field. |
| 704 | /// This function computes the field's value again based on the length of the list. |
| 705 | /// |
| 706 | /// # Panics |
| 707 | /// |
| 708 | /// Panics if the value cannot be represented in the target type. This |
| 709 | /// cannot happen with values of the struct received from the X11 server. |
| 710 | pub fn allowed_depths_len(&self) -> u8 { |
| 711 | self.allowed_depths.len() |
| 712 | .try_into().unwrap() |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | #[derive (Clone, Default)] |
| 717 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 718 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 719 | pub struct SetupRequest { |
| 720 | pub byte_order: u8, |
| 721 | pub protocol_major_version: u16, |
| 722 | pub protocol_minor_version: u16, |
| 723 | pub authorization_protocol_name: Vec<u8>, |
| 724 | pub authorization_protocol_data: Vec<u8>, |
| 725 | } |
| 726 | impl_debug_if_no_extra_traits!(SetupRequest, "SetupRequest" ); |
| 727 | impl TryParse for SetupRequest { |
| 728 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 729 | let value = remaining; |
| 730 | let (byte_order, remaining) = u8::try_parse(remaining)?; |
| 731 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 732 | let (protocol_major_version, remaining) = u16::try_parse(remaining)?; |
| 733 | let (protocol_minor_version, remaining) = u16::try_parse(remaining)?; |
| 734 | let (authorization_protocol_name_len, remaining) = u16::try_parse(remaining)?; |
| 735 | let (authorization_protocol_data_len, remaining) = u16::try_parse(remaining)?; |
| 736 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 737 | let (authorization_protocol_name, remaining) = crate::x11_utils::parse_u8_list(remaining, authorization_protocol_name_len.try_to_usize()?)?; |
| 738 | let authorization_protocol_name = authorization_protocol_name.to_vec(); |
| 739 | // Align offset to multiple of 4 |
| 740 | let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 741 | let misalignment = (4 - (offset % 4)) % 4; |
| 742 | let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; |
| 743 | let (authorization_protocol_data, remaining) = crate::x11_utils::parse_u8_list(remaining, authorization_protocol_data_len.try_to_usize()?)?; |
| 744 | let authorization_protocol_data = authorization_protocol_data.to_vec(); |
| 745 | // Align offset to multiple of 4 |
| 746 | let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 747 | let misalignment = (4 - (offset % 4)) % 4; |
| 748 | let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; |
| 749 | let result = SetupRequest { byte_order, protocol_major_version, protocol_minor_version, authorization_protocol_name, authorization_protocol_data }; |
| 750 | Ok((result, remaining)) |
| 751 | } |
| 752 | } |
| 753 | impl Serialize for SetupRequest { |
| 754 | type Bytes = Vec<u8>; |
| 755 | fn serialize(&self) -> Vec<u8> { |
| 756 | let mut result: Vec = Vec::new(); |
| 757 | self.serialize_into(&mut result); |
| 758 | result |
| 759 | } |
| 760 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 761 | bytes.reserve(additional:12); |
| 762 | self.byte_order.serialize_into(bytes); |
| 763 | bytes.extend_from_slice(&[0; 1]); |
| 764 | self.protocol_major_version.serialize_into(bytes); |
| 765 | self.protocol_minor_version.serialize_into(bytes); |
| 766 | let authorization_protocol_name_len: u16 = u16::try_from(self.authorization_protocol_name.len()).expect(msg:"`authorization_protocol_name` has too many elements" ); |
| 767 | authorization_protocol_name_len.serialize_into(bytes); |
| 768 | let authorization_protocol_data_len: u16 = u16::try_from(self.authorization_protocol_data.len()).expect(msg:"`authorization_protocol_data` has too many elements" ); |
| 769 | authorization_protocol_data_len.serialize_into(bytes); |
| 770 | bytes.extend_from_slice(&[0; 2]); |
| 771 | bytes.extend_from_slice(&self.authorization_protocol_name); |
| 772 | bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]); |
| 773 | bytes.extend_from_slice(&self.authorization_protocol_data); |
| 774 | bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]); |
| 775 | } |
| 776 | } |
| 777 | impl SetupRequest { |
| 778 | /// Get the value of the `authorization_protocol_name_len` field. |
| 779 | /// |
| 780 | /// The `authorization_protocol_name_len` field is used as the length field of the `authorization_protocol_name` field. |
| 781 | /// This function computes the field's value again based on the length of the list. |
| 782 | /// |
| 783 | /// # Panics |
| 784 | /// |
| 785 | /// Panics if the value cannot be represented in the target type. This |
| 786 | /// cannot happen with values of the struct received from the X11 server. |
| 787 | pub fn authorization_protocol_name_len(&self) -> u16 { |
| 788 | self.authorization_protocol_name.len() |
| 789 | .try_into().unwrap() |
| 790 | } |
| 791 | /// Get the value of the `authorization_protocol_data_len` field. |
| 792 | /// |
| 793 | /// The `authorization_protocol_data_len` field is used as the length field of the `authorization_protocol_data` field. |
| 794 | /// This function computes the field's value again based on the length of the list. |
| 795 | /// |
| 796 | /// # Panics |
| 797 | /// |
| 798 | /// Panics if the value cannot be represented in the target type. This |
| 799 | /// cannot happen with values of the struct received from the X11 server. |
| 800 | pub fn authorization_protocol_data_len(&self) -> u16 { |
| 801 | self.authorization_protocol_data.len() |
| 802 | .try_into().unwrap() |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | #[derive (Clone, Default)] |
| 807 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 808 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 809 | pub struct SetupFailed { |
| 810 | pub status: u8, |
| 811 | pub protocol_major_version: u16, |
| 812 | pub protocol_minor_version: u16, |
| 813 | pub length: u16, |
| 814 | pub reason: Vec<u8>, |
| 815 | } |
| 816 | impl_debug_if_no_extra_traits!(SetupFailed, "SetupFailed" ); |
| 817 | impl TryParse for SetupFailed { |
| 818 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 819 | let (status: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 820 | let (reason_len: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 821 | let (protocol_major_version: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 822 | let (protocol_minor_version: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 823 | let (length: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 824 | let (reason: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data:remaining, list_length:reason_len.try_to_usize()?)?; |
| 825 | let reason: Vec = reason.to_vec(); |
| 826 | let result: SetupFailed = SetupFailed { status, protocol_major_version, protocol_minor_version, length, reason }; |
| 827 | Ok((result, remaining)) |
| 828 | } |
| 829 | } |
| 830 | impl Serialize for SetupFailed { |
| 831 | type Bytes = Vec<u8>; |
| 832 | fn serialize(&self) -> Vec<u8> { |
| 833 | let mut result: Vec = Vec::new(); |
| 834 | self.serialize_into(&mut result); |
| 835 | result |
| 836 | } |
| 837 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 838 | bytes.reserve(additional:8); |
| 839 | self.status.serialize_into(bytes); |
| 840 | let reason_len: u8 = u8::try_from(self.reason.len()).expect(msg:"`reason` has too many elements" ); |
| 841 | reason_len.serialize_into(bytes); |
| 842 | self.protocol_major_version.serialize_into(bytes); |
| 843 | self.protocol_minor_version.serialize_into(bytes); |
| 844 | self.length.serialize_into(bytes); |
| 845 | bytes.extend_from_slice(&self.reason); |
| 846 | } |
| 847 | } |
| 848 | impl SetupFailed { |
| 849 | /// Get the value of the `reason_len` field. |
| 850 | /// |
| 851 | /// The `reason_len` field is used as the length field of the `reason` field. |
| 852 | /// This function computes the field's value again based on the length of the list. |
| 853 | /// |
| 854 | /// # Panics |
| 855 | /// |
| 856 | /// Panics if the value cannot be represented in the target type. This |
| 857 | /// cannot happen with values of the struct received from the X11 server. |
| 858 | pub fn reason_len(&self) -> u8 { |
| 859 | self.reason.len() |
| 860 | .try_into().unwrap() |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | #[derive (Clone, Default)] |
| 865 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 866 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 867 | pub struct SetupAuthenticate { |
| 868 | pub status: u8, |
| 869 | pub reason: Vec<u8>, |
| 870 | } |
| 871 | impl_debug_if_no_extra_traits!(SetupAuthenticate, "SetupAuthenticate" ); |
| 872 | impl TryParse for SetupAuthenticate { |
| 873 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 874 | let (status: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 875 | let remaining: &[u8] = remaining.get(5..).ok_or(err:ParseError::InsufficientData)?; |
| 876 | let (length: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 877 | let (reason: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data:remaining, list_length:u32::from(length).checked_mul(4u32).ok_or(err:ParseError::InvalidExpression)?.try_to_usize()?)?; |
| 878 | let reason: Vec = reason.to_vec(); |
| 879 | let result: SetupAuthenticate = SetupAuthenticate { status, reason }; |
| 880 | Ok((result, remaining)) |
| 881 | } |
| 882 | } |
| 883 | impl Serialize for SetupAuthenticate { |
| 884 | type Bytes = Vec<u8>; |
| 885 | fn serialize(&self) -> Vec<u8> { |
| 886 | let mut result: Vec = Vec::new(); |
| 887 | self.serialize_into(&mut result); |
| 888 | result |
| 889 | } |
| 890 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 891 | bytes.reserve(additional:8); |
| 892 | self.status.serialize_into(bytes); |
| 893 | bytes.extend_from_slice(&[0; 5]); |
| 894 | assert_eq!(self.reason.len() % 4, 0, "`reason` has an incorrect length, must be a multiple of 4" ); |
| 895 | let length: u16 = u16::try_from(self.reason.len() / 4).expect(msg:"`reason` has too many elements" ); |
| 896 | length.serialize_into(bytes); |
| 897 | bytes.extend_from_slice(&self.reason); |
| 898 | } |
| 899 | } |
| 900 | impl SetupAuthenticate { |
| 901 | /// Get the value of the `length` field. |
| 902 | /// |
| 903 | /// The `length` field is used as the length field of the `reason` field. |
| 904 | /// This function computes the field's value again based on the length of the list. |
| 905 | /// |
| 906 | /// # Panics |
| 907 | /// |
| 908 | /// Panics if the value cannot be represented in the target type. This |
| 909 | /// cannot happen with values of the struct received from the X11 server. |
| 910 | pub fn length(&self) -> u16 { |
| 911 | self.reason.len() |
| 912 | .checked_div(4).unwrap() |
| 913 | .try_into().unwrap() |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 918 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 919 | pub struct ImageOrder(u8); |
| 920 | impl ImageOrder { |
| 921 | pub const LSB_FIRST: Self = Self(0); |
| 922 | pub const MSB_FIRST: Self = Self(1); |
| 923 | } |
| 924 | impl From<ImageOrder> for u8 { |
| 925 | #[inline ] |
| 926 | fn from(input: ImageOrder) -> Self { |
| 927 | input.0 |
| 928 | } |
| 929 | } |
| 930 | impl From<ImageOrder> for Option<u8> { |
| 931 | #[inline ] |
| 932 | fn from(input: ImageOrder) -> Self { |
| 933 | Some(input.0) |
| 934 | } |
| 935 | } |
| 936 | impl From<ImageOrder> for u16 { |
| 937 | #[inline ] |
| 938 | fn from(input: ImageOrder) -> Self { |
| 939 | u16::from(input.0) |
| 940 | } |
| 941 | } |
| 942 | impl From<ImageOrder> for Option<u16> { |
| 943 | #[inline ] |
| 944 | fn from(input: ImageOrder) -> Self { |
| 945 | Some(u16::from(input.0)) |
| 946 | } |
| 947 | } |
| 948 | impl From<ImageOrder> for u32 { |
| 949 | #[inline ] |
| 950 | fn from(input: ImageOrder) -> Self { |
| 951 | u32::from(input.0) |
| 952 | } |
| 953 | } |
| 954 | impl From<ImageOrder> for Option<u32> { |
| 955 | #[inline ] |
| 956 | fn from(input: ImageOrder) -> Self { |
| 957 | Some(u32::from(input.0)) |
| 958 | } |
| 959 | } |
| 960 | impl From<u8> for ImageOrder { |
| 961 | #[inline ] |
| 962 | fn from(value: u8) -> Self { |
| 963 | Self(value) |
| 964 | } |
| 965 | } |
| 966 | impl core::fmt::Debug for ImageOrder { |
| 967 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 968 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 969 | (Self::LSB_FIRST.0.into(), "LSB_FIRST" , "LSBFirst" ), |
| 970 | (Self::MSB_FIRST.0.into(), "MSB_FIRST" , "MSBFirst" ), |
| 971 | ]; |
| 972 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | #[derive (Clone, Default)] |
| 977 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 978 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 979 | pub struct Setup { |
| 980 | pub status: u8, |
| 981 | pub protocol_major_version: u16, |
| 982 | pub protocol_minor_version: u16, |
| 983 | pub length: u16, |
| 984 | pub release_number: u32, |
| 985 | pub resource_id_base: u32, |
| 986 | pub resource_id_mask: u32, |
| 987 | pub motion_buffer_size: u32, |
| 988 | pub maximum_request_length: u16, |
| 989 | pub image_byte_order: ImageOrder, |
| 990 | pub bitmap_format_bit_order: ImageOrder, |
| 991 | pub bitmap_format_scanline_unit: u8, |
| 992 | pub bitmap_format_scanline_pad: u8, |
| 993 | pub min_keycode: Keycode, |
| 994 | pub max_keycode: Keycode, |
| 995 | pub vendor: Vec<u8>, |
| 996 | pub pixmap_formats: Vec<Format>, |
| 997 | pub roots: Vec<Screen>, |
| 998 | } |
| 999 | impl_debug_if_no_extra_traits!(Setup, "Setup" ); |
| 1000 | impl TryParse for Setup { |
| 1001 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 1002 | let value = remaining; |
| 1003 | let (status, remaining) = u8::try_parse(remaining)?; |
| 1004 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 1005 | let (protocol_major_version, remaining) = u16::try_parse(remaining)?; |
| 1006 | let (protocol_minor_version, remaining) = u16::try_parse(remaining)?; |
| 1007 | let (length, remaining) = u16::try_parse(remaining)?; |
| 1008 | let (release_number, remaining) = u32::try_parse(remaining)?; |
| 1009 | let (resource_id_base, remaining) = u32::try_parse(remaining)?; |
| 1010 | let (resource_id_mask, remaining) = u32::try_parse(remaining)?; |
| 1011 | let (motion_buffer_size, remaining) = u32::try_parse(remaining)?; |
| 1012 | let (vendor_len, remaining) = u16::try_parse(remaining)?; |
| 1013 | let (maximum_request_length, remaining) = u16::try_parse(remaining)?; |
| 1014 | let (roots_len, remaining) = u8::try_parse(remaining)?; |
| 1015 | let (pixmap_formats_len, remaining) = u8::try_parse(remaining)?; |
| 1016 | let (image_byte_order, remaining) = u8::try_parse(remaining)?; |
| 1017 | let (bitmap_format_bit_order, remaining) = u8::try_parse(remaining)?; |
| 1018 | let (bitmap_format_scanline_unit, remaining) = u8::try_parse(remaining)?; |
| 1019 | let (bitmap_format_scanline_pad, remaining) = u8::try_parse(remaining)?; |
| 1020 | let (min_keycode, remaining) = Keycode::try_parse(remaining)?; |
| 1021 | let (max_keycode, remaining) = Keycode::try_parse(remaining)?; |
| 1022 | let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; |
| 1023 | let (vendor, remaining) = crate::x11_utils::parse_u8_list(remaining, vendor_len.try_to_usize()?)?; |
| 1024 | let vendor = vendor.to_vec(); |
| 1025 | // Align offset to multiple of 4 |
| 1026 | let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 1027 | let misalignment = (4 - (offset % 4)) % 4; |
| 1028 | let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; |
| 1029 | let (pixmap_formats, remaining) = crate::x11_utils::parse_list::<Format>(remaining, pixmap_formats_len.try_to_usize()?)?; |
| 1030 | let (roots, remaining) = crate::x11_utils::parse_list::<Screen>(remaining, roots_len.try_to_usize()?)?; |
| 1031 | let image_byte_order = image_byte_order.into(); |
| 1032 | let bitmap_format_bit_order = bitmap_format_bit_order.into(); |
| 1033 | let result = Setup { status, protocol_major_version, protocol_minor_version, length, release_number, resource_id_base, resource_id_mask, motion_buffer_size, maximum_request_length, image_byte_order, bitmap_format_bit_order, bitmap_format_scanline_unit, bitmap_format_scanline_pad, min_keycode, max_keycode, vendor, pixmap_formats, roots }; |
| 1034 | Ok((result, remaining)) |
| 1035 | } |
| 1036 | } |
| 1037 | impl Serialize for Setup { |
| 1038 | type Bytes = Vec<u8>; |
| 1039 | fn serialize(&self) -> Vec<u8> { |
| 1040 | let mut result = Vec::new(); |
| 1041 | self.serialize_into(&mut result); |
| 1042 | result |
| 1043 | } |
| 1044 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 1045 | bytes.reserve(40); |
| 1046 | self.status.serialize_into(bytes); |
| 1047 | bytes.extend_from_slice(&[0; 1]); |
| 1048 | self.protocol_major_version.serialize_into(bytes); |
| 1049 | self.protocol_minor_version.serialize_into(bytes); |
| 1050 | self.length.serialize_into(bytes); |
| 1051 | self.release_number.serialize_into(bytes); |
| 1052 | self.resource_id_base.serialize_into(bytes); |
| 1053 | self.resource_id_mask.serialize_into(bytes); |
| 1054 | self.motion_buffer_size.serialize_into(bytes); |
| 1055 | let vendor_len = u16::try_from(self.vendor.len()).expect("`vendor` has too many elements" ); |
| 1056 | vendor_len.serialize_into(bytes); |
| 1057 | self.maximum_request_length.serialize_into(bytes); |
| 1058 | let roots_len = u8::try_from(self.roots.len()).expect("`roots` has too many elements" ); |
| 1059 | roots_len.serialize_into(bytes); |
| 1060 | let pixmap_formats_len = u8::try_from(self.pixmap_formats.len()).expect("`pixmap_formats` has too many elements" ); |
| 1061 | pixmap_formats_len.serialize_into(bytes); |
| 1062 | u8::from(self.image_byte_order).serialize_into(bytes); |
| 1063 | u8::from(self.bitmap_format_bit_order).serialize_into(bytes); |
| 1064 | self.bitmap_format_scanline_unit.serialize_into(bytes); |
| 1065 | self.bitmap_format_scanline_pad.serialize_into(bytes); |
| 1066 | self.min_keycode.serialize_into(bytes); |
| 1067 | self.max_keycode.serialize_into(bytes); |
| 1068 | bytes.extend_from_slice(&[0; 4]); |
| 1069 | bytes.extend_from_slice(&self.vendor); |
| 1070 | bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]); |
| 1071 | self.pixmap_formats.serialize_into(bytes); |
| 1072 | self.roots.serialize_into(bytes); |
| 1073 | } |
| 1074 | } |
| 1075 | impl Setup { |
| 1076 | /// Get the value of the `vendor_len` field. |
| 1077 | /// |
| 1078 | /// The `vendor_len` field is used as the length field of the `vendor` field. |
| 1079 | /// This function computes the field's value again based on the length of the list. |
| 1080 | /// |
| 1081 | /// # Panics |
| 1082 | /// |
| 1083 | /// Panics if the value cannot be represented in the target type. This |
| 1084 | /// cannot happen with values of the struct received from the X11 server. |
| 1085 | pub fn vendor_len(&self) -> u16 { |
| 1086 | self.vendor.len() |
| 1087 | .try_into().unwrap() |
| 1088 | } |
| 1089 | /// Get the value of the `roots_len` field. |
| 1090 | /// |
| 1091 | /// The `roots_len` field is used as the length field of the `roots` field. |
| 1092 | /// This function computes the field's value again based on the length of the list. |
| 1093 | /// |
| 1094 | /// # Panics |
| 1095 | /// |
| 1096 | /// Panics if the value cannot be represented in the target type. This |
| 1097 | /// cannot happen with values of the struct received from the X11 server. |
| 1098 | pub fn roots_len(&self) -> u8 { |
| 1099 | self.roots.len() |
| 1100 | .try_into().unwrap() |
| 1101 | } |
| 1102 | /// Get the value of the `pixmap_formats_len` field. |
| 1103 | /// |
| 1104 | /// The `pixmap_formats_len` field is used as the length field of the `pixmap_formats` field. |
| 1105 | /// This function computes the field's value again based on the length of the list. |
| 1106 | /// |
| 1107 | /// # Panics |
| 1108 | /// |
| 1109 | /// Panics if the value cannot be represented in the target type. This |
| 1110 | /// cannot happen with values of the struct received from the X11 server. |
| 1111 | pub fn pixmap_formats_len(&self) -> u8 { |
| 1112 | self.pixmap_formats.len() |
| 1113 | .try_into().unwrap() |
| 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1118 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1119 | pub struct ModMask(u16); |
| 1120 | impl ModMask { |
| 1121 | pub const SHIFT: Self = Self(1 << 0); |
| 1122 | pub const LOCK: Self = Self(1 << 1); |
| 1123 | pub const CONTROL: Self = Self(1 << 2); |
| 1124 | pub const M1: Self = Self(1 << 3); |
| 1125 | pub const M2: Self = Self(1 << 4); |
| 1126 | pub const M3: Self = Self(1 << 5); |
| 1127 | pub const M4: Self = Self(1 << 6); |
| 1128 | pub const M5: Self = Self(1 << 7); |
| 1129 | pub const ANY: Self = Self(1 << 15); |
| 1130 | } |
| 1131 | impl From<ModMask> for u16 { |
| 1132 | #[inline ] |
| 1133 | fn from(input: ModMask) -> Self { |
| 1134 | input.0 |
| 1135 | } |
| 1136 | } |
| 1137 | impl From<ModMask> for Option<u16> { |
| 1138 | #[inline ] |
| 1139 | fn from(input: ModMask) -> Self { |
| 1140 | Some(input.0) |
| 1141 | } |
| 1142 | } |
| 1143 | impl From<ModMask> for u32 { |
| 1144 | #[inline ] |
| 1145 | fn from(input: ModMask) -> Self { |
| 1146 | u32::from(input.0) |
| 1147 | } |
| 1148 | } |
| 1149 | impl From<ModMask> for Option<u32> { |
| 1150 | #[inline ] |
| 1151 | fn from(input: ModMask) -> Self { |
| 1152 | Some(u32::from(input.0)) |
| 1153 | } |
| 1154 | } |
| 1155 | impl From<u8> for ModMask { |
| 1156 | #[inline ] |
| 1157 | fn from(value: u8) -> Self { |
| 1158 | Self(value.into()) |
| 1159 | } |
| 1160 | } |
| 1161 | impl From<u16> for ModMask { |
| 1162 | #[inline ] |
| 1163 | fn from(value: u16) -> Self { |
| 1164 | Self(value) |
| 1165 | } |
| 1166 | } |
| 1167 | impl core::fmt::Debug for ModMask { |
| 1168 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1169 | let variants: [(u32, &'static str, &'static …); 9] = [ |
| 1170 | (Self::SHIFT.0.into(), "SHIFT" , "Shift" ), |
| 1171 | (Self::LOCK.0.into(), "LOCK" , "Lock" ), |
| 1172 | (Self::CONTROL.0.into(), "CONTROL" , "Control" ), |
| 1173 | (Self::M1.0.into(), "M1" , "M1" ), |
| 1174 | (Self::M2.0.into(), "M2" , "M2" ), |
| 1175 | (Self::M3.0.into(), "M3" , "M3" ), |
| 1176 | (Self::M4.0.into(), "M4" , "M4" ), |
| 1177 | (Self::M5.0.into(), "M5" , "M5" ), |
| 1178 | (Self::ANY.0.into(), "ANY" , "Any" ), |
| 1179 | ]; |
| 1180 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 1181 | } |
| 1182 | } |
| 1183 | bitmask_binop!(ModMask, u16); |
| 1184 | |
| 1185 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1186 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1187 | pub struct KeyButMask(u16); |
| 1188 | impl KeyButMask { |
| 1189 | pub const SHIFT: Self = Self(1 << 0); |
| 1190 | pub const LOCK: Self = Self(1 << 1); |
| 1191 | pub const CONTROL: Self = Self(1 << 2); |
| 1192 | pub const MOD1: Self = Self(1 << 3); |
| 1193 | pub const MOD2: Self = Self(1 << 4); |
| 1194 | pub const MOD3: Self = Self(1 << 5); |
| 1195 | pub const MOD4: Self = Self(1 << 6); |
| 1196 | pub const MOD5: Self = Self(1 << 7); |
| 1197 | pub const BUTTON1: Self = Self(1 << 8); |
| 1198 | pub const BUTTON2: Self = Self(1 << 9); |
| 1199 | pub const BUTTON3: Self = Self(1 << 10); |
| 1200 | pub const BUTTON4: Self = Self(1 << 11); |
| 1201 | pub const BUTTON5: Self = Self(1 << 12); |
| 1202 | } |
| 1203 | impl From<KeyButMask> for u16 { |
| 1204 | #[inline ] |
| 1205 | fn from(input: KeyButMask) -> Self { |
| 1206 | input.0 |
| 1207 | } |
| 1208 | } |
| 1209 | impl From<KeyButMask> for Option<u16> { |
| 1210 | #[inline ] |
| 1211 | fn from(input: KeyButMask) -> Self { |
| 1212 | Some(input.0) |
| 1213 | } |
| 1214 | } |
| 1215 | impl From<KeyButMask> for u32 { |
| 1216 | #[inline ] |
| 1217 | fn from(input: KeyButMask) -> Self { |
| 1218 | u32::from(input.0) |
| 1219 | } |
| 1220 | } |
| 1221 | impl From<KeyButMask> for Option<u32> { |
| 1222 | #[inline ] |
| 1223 | fn from(input: KeyButMask) -> Self { |
| 1224 | Some(u32::from(input.0)) |
| 1225 | } |
| 1226 | } |
| 1227 | impl From<u8> for KeyButMask { |
| 1228 | #[inline ] |
| 1229 | fn from(value: u8) -> Self { |
| 1230 | Self(value.into()) |
| 1231 | } |
| 1232 | } |
| 1233 | impl From<u16> for KeyButMask { |
| 1234 | #[inline ] |
| 1235 | fn from(value: u16) -> Self { |
| 1236 | Self(value) |
| 1237 | } |
| 1238 | } |
| 1239 | impl core::fmt::Debug for KeyButMask { |
| 1240 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1241 | let variants: [(u32, &'static str, &'static …); 13] = [ |
| 1242 | (Self::SHIFT.0.into(), "SHIFT" , "Shift" ), |
| 1243 | (Self::LOCK.0.into(), "LOCK" , "Lock" ), |
| 1244 | (Self::CONTROL.0.into(), "CONTROL" , "Control" ), |
| 1245 | (Self::MOD1.0.into(), "MOD1" , "Mod1" ), |
| 1246 | (Self::MOD2.0.into(), "MOD2" , "Mod2" ), |
| 1247 | (Self::MOD3.0.into(), "MOD3" , "Mod3" ), |
| 1248 | (Self::MOD4.0.into(), "MOD4" , "Mod4" ), |
| 1249 | (Self::MOD5.0.into(), "MOD5" , "Mod5" ), |
| 1250 | (Self::BUTTON1.0.into(), "BUTTON1" , "Button1" ), |
| 1251 | (Self::BUTTON2.0.into(), "BUTTON2" , "Button2" ), |
| 1252 | (Self::BUTTON3.0.into(), "BUTTON3" , "Button3" ), |
| 1253 | (Self::BUTTON4.0.into(), "BUTTON4" , "Button4" ), |
| 1254 | (Self::BUTTON5.0.into(), "BUTTON5" , "Button5" ), |
| 1255 | ]; |
| 1256 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 1257 | } |
| 1258 | } |
| 1259 | bitmask_binop!(KeyButMask, u16); |
| 1260 | |
| 1261 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1262 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1263 | pub struct WindowEnum(u8); |
| 1264 | impl WindowEnum { |
| 1265 | pub const NONE: Self = Self(0); |
| 1266 | } |
| 1267 | impl From<WindowEnum> for u8 { |
| 1268 | #[inline ] |
| 1269 | fn from(input: WindowEnum) -> Self { |
| 1270 | input.0 |
| 1271 | } |
| 1272 | } |
| 1273 | impl From<WindowEnum> for Option<u8> { |
| 1274 | #[inline ] |
| 1275 | fn from(input: WindowEnum) -> Self { |
| 1276 | Some(input.0) |
| 1277 | } |
| 1278 | } |
| 1279 | impl From<WindowEnum> for u16 { |
| 1280 | #[inline ] |
| 1281 | fn from(input: WindowEnum) -> Self { |
| 1282 | u16::from(input.0) |
| 1283 | } |
| 1284 | } |
| 1285 | impl From<WindowEnum> for Option<u16> { |
| 1286 | #[inline ] |
| 1287 | fn from(input: WindowEnum) -> Self { |
| 1288 | Some(u16::from(input.0)) |
| 1289 | } |
| 1290 | } |
| 1291 | impl From<WindowEnum> for u32 { |
| 1292 | #[inline ] |
| 1293 | fn from(input: WindowEnum) -> Self { |
| 1294 | u32::from(input.0) |
| 1295 | } |
| 1296 | } |
| 1297 | impl From<WindowEnum> for Option<u32> { |
| 1298 | #[inline ] |
| 1299 | fn from(input: WindowEnum) -> Self { |
| 1300 | Some(u32::from(input.0)) |
| 1301 | } |
| 1302 | } |
| 1303 | impl From<u8> for WindowEnum { |
| 1304 | #[inline ] |
| 1305 | fn from(value: u8) -> Self { |
| 1306 | Self(value) |
| 1307 | } |
| 1308 | } |
| 1309 | impl core::fmt::Debug for WindowEnum { |
| 1310 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1311 | let variants: [(u32, &'static str, &'static …); 1] = [ |
| 1312 | (Self::NONE.0.into(), "NONE" , "None" ), |
| 1313 | ]; |
| 1314 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | /// Opcode for the KeyPress event |
| 1319 | pub const KEY_PRESS_EVENT: u8 = 2; |
| 1320 | /// a key was pressed/released. |
| 1321 | /// |
| 1322 | /// # Fields |
| 1323 | /// |
| 1324 | /// * `detail` - The keycode (a number representing a physical key on the keyboard) of the key |
| 1325 | /// which was pressed. |
| 1326 | /// * `time` - Time when the event was generated (in milliseconds). |
| 1327 | /// * `root` - The root window of `child`. |
| 1328 | /// * `same_screen` - Whether the `event` window is on the same screen as the `root` window. |
| 1329 | /// * `event_x` - If `same_screen` is true, this is the X coordinate relative to the `event` |
| 1330 | /// window's origin. Otherwise, `event_x` will be set to zero. |
| 1331 | /// * `event_y` - If `same_screen` is true, this is the Y coordinate relative to the `event` |
| 1332 | /// window's origin. Otherwise, `event_y` will be set to zero. |
| 1333 | /// * `root_x` - The X coordinate of the pointer relative to the `root` window at the time of |
| 1334 | /// the event. |
| 1335 | /// * `root_y` - The Y coordinate of the pointer relative to the `root` window at the time of |
| 1336 | /// the event. |
| 1337 | /// * `state` - The logical state of the pointer buttons and modifier keys just prior to the |
| 1338 | /// event. |
| 1339 | /// |
| 1340 | /// # See |
| 1341 | /// |
| 1342 | /// * `GrabKey`: request |
| 1343 | /// * `GrabKeyboard`: request |
| 1344 | #[derive (Clone, Copy, Default)] |
| 1345 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 1346 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1347 | pub struct KeyPressEvent { |
| 1348 | pub response_type: u8, |
| 1349 | pub detail: Keycode, |
| 1350 | pub sequence: u16, |
| 1351 | pub time: Timestamp, |
| 1352 | pub root: Window, |
| 1353 | pub event: Window, |
| 1354 | pub child: Window, |
| 1355 | pub root_x: i16, |
| 1356 | pub root_y: i16, |
| 1357 | pub event_x: i16, |
| 1358 | pub event_y: i16, |
| 1359 | pub state: KeyButMask, |
| 1360 | pub same_screen: bool, |
| 1361 | } |
| 1362 | impl_debug_if_no_extra_traits!(KeyPressEvent, "KeyPressEvent" ); |
| 1363 | impl TryParse for KeyPressEvent { |
| 1364 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 1365 | let remaining = initial_value; |
| 1366 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 1367 | let (detail, remaining) = Keycode::try_parse(remaining)?; |
| 1368 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 1369 | let (time, remaining) = Timestamp::try_parse(remaining)?; |
| 1370 | let (root, remaining) = Window::try_parse(remaining)?; |
| 1371 | let (event, remaining) = Window::try_parse(remaining)?; |
| 1372 | let (child, remaining) = Window::try_parse(remaining)?; |
| 1373 | let (root_x, remaining) = i16::try_parse(remaining)?; |
| 1374 | let (root_y, remaining) = i16::try_parse(remaining)?; |
| 1375 | let (event_x, remaining) = i16::try_parse(remaining)?; |
| 1376 | let (event_y, remaining) = i16::try_parse(remaining)?; |
| 1377 | let (state, remaining) = u16::try_parse(remaining)?; |
| 1378 | let (same_screen, remaining) = bool::try_parse(remaining)?; |
| 1379 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 1380 | let state = state.into(); |
| 1381 | let result = KeyPressEvent { response_type, detail, sequence, time, root, event, child, root_x, root_y, event_x, event_y, state, same_screen }; |
| 1382 | let _ = remaining; |
| 1383 | let remaining = initial_value.get(32..) |
| 1384 | .ok_or(ParseError::InsufficientData)?; |
| 1385 | Ok((result, remaining)) |
| 1386 | } |
| 1387 | } |
| 1388 | impl Serialize for KeyPressEvent { |
| 1389 | type Bytes = [u8; 32]; |
| 1390 | fn serialize(&self) -> [u8; 32] { |
| 1391 | let response_type_bytes = self.response_type.serialize(); |
| 1392 | let detail_bytes = self.detail.serialize(); |
| 1393 | let sequence_bytes = self.sequence.serialize(); |
| 1394 | let time_bytes = self.time.serialize(); |
| 1395 | let root_bytes = self.root.serialize(); |
| 1396 | let event_bytes = self.event.serialize(); |
| 1397 | let child_bytes = self.child.serialize(); |
| 1398 | let root_x_bytes = self.root_x.serialize(); |
| 1399 | let root_y_bytes = self.root_y.serialize(); |
| 1400 | let event_x_bytes = self.event_x.serialize(); |
| 1401 | let event_y_bytes = self.event_y.serialize(); |
| 1402 | let state_bytes = u16::from(self.state).serialize(); |
| 1403 | let same_screen_bytes = self.same_screen.serialize(); |
| 1404 | [ |
| 1405 | response_type_bytes[0], |
| 1406 | detail_bytes[0], |
| 1407 | sequence_bytes[0], |
| 1408 | sequence_bytes[1], |
| 1409 | time_bytes[0], |
| 1410 | time_bytes[1], |
| 1411 | time_bytes[2], |
| 1412 | time_bytes[3], |
| 1413 | root_bytes[0], |
| 1414 | root_bytes[1], |
| 1415 | root_bytes[2], |
| 1416 | root_bytes[3], |
| 1417 | event_bytes[0], |
| 1418 | event_bytes[1], |
| 1419 | event_bytes[2], |
| 1420 | event_bytes[3], |
| 1421 | child_bytes[0], |
| 1422 | child_bytes[1], |
| 1423 | child_bytes[2], |
| 1424 | child_bytes[3], |
| 1425 | root_x_bytes[0], |
| 1426 | root_x_bytes[1], |
| 1427 | root_y_bytes[0], |
| 1428 | root_y_bytes[1], |
| 1429 | event_x_bytes[0], |
| 1430 | event_x_bytes[1], |
| 1431 | event_y_bytes[0], |
| 1432 | event_y_bytes[1], |
| 1433 | state_bytes[0], |
| 1434 | state_bytes[1], |
| 1435 | same_screen_bytes[0], |
| 1436 | 0, |
| 1437 | ] |
| 1438 | } |
| 1439 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 1440 | bytes.reserve(32); |
| 1441 | self.response_type.serialize_into(bytes); |
| 1442 | self.detail.serialize_into(bytes); |
| 1443 | self.sequence.serialize_into(bytes); |
| 1444 | self.time.serialize_into(bytes); |
| 1445 | self.root.serialize_into(bytes); |
| 1446 | self.event.serialize_into(bytes); |
| 1447 | self.child.serialize_into(bytes); |
| 1448 | self.root_x.serialize_into(bytes); |
| 1449 | self.root_y.serialize_into(bytes); |
| 1450 | self.event_x.serialize_into(bytes); |
| 1451 | self.event_y.serialize_into(bytes); |
| 1452 | u16::from(self.state).serialize_into(bytes); |
| 1453 | self.same_screen.serialize_into(bytes); |
| 1454 | bytes.extend_from_slice(&[0; 1]); |
| 1455 | } |
| 1456 | } |
| 1457 | impl From<&KeyPressEvent> for [u8; 32] { |
| 1458 | fn from(input: &KeyPressEvent) -> Self { |
| 1459 | let response_type_bytes = input.response_type.serialize(); |
| 1460 | let detail_bytes = input.detail.serialize(); |
| 1461 | let sequence_bytes = input.sequence.serialize(); |
| 1462 | let time_bytes = input.time.serialize(); |
| 1463 | let root_bytes = input.root.serialize(); |
| 1464 | let event_bytes = input.event.serialize(); |
| 1465 | let child_bytes = input.child.serialize(); |
| 1466 | let root_x_bytes = input.root_x.serialize(); |
| 1467 | let root_y_bytes = input.root_y.serialize(); |
| 1468 | let event_x_bytes = input.event_x.serialize(); |
| 1469 | let event_y_bytes = input.event_y.serialize(); |
| 1470 | let state_bytes = u16::from(input.state).serialize(); |
| 1471 | let same_screen_bytes = input.same_screen.serialize(); |
| 1472 | [ |
| 1473 | response_type_bytes[0], |
| 1474 | detail_bytes[0], |
| 1475 | sequence_bytes[0], |
| 1476 | sequence_bytes[1], |
| 1477 | time_bytes[0], |
| 1478 | time_bytes[1], |
| 1479 | time_bytes[2], |
| 1480 | time_bytes[3], |
| 1481 | root_bytes[0], |
| 1482 | root_bytes[1], |
| 1483 | root_bytes[2], |
| 1484 | root_bytes[3], |
| 1485 | event_bytes[0], |
| 1486 | event_bytes[1], |
| 1487 | event_bytes[2], |
| 1488 | event_bytes[3], |
| 1489 | child_bytes[0], |
| 1490 | child_bytes[1], |
| 1491 | child_bytes[2], |
| 1492 | child_bytes[3], |
| 1493 | root_x_bytes[0], |
| 1494 | root_x_bytes[1], |
| 1495 | root_y_bytes[0], |
| 1496 | root_y_bytes[1], |
| 1497 | event_x_bytes[0], |
| 1498 | event_x_bytes[1], |
| 1499 | event_y_bytes[0], |
| 1500 | event_y_bytes[1], |
| 1501 | state_bytes[0], |
| 1502 | state_bytes[1], |
| 1503 | same_screen_bytes[0], |
| 1504 | 0, |
| 1505 | ] |
| 1506 | } |
| 1507 | } |
| 1508 | impl From<KeyPressEvent> for [u8; 32] { |
| 1509 | fn from(input: KeyPressEvent) -> Self { |
| 1510 | Self::from(&input) |
| 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | /// Opcode for the KeyRelease event |
| 1515 | pub const KEY_RELEASE_EVENT: u8 = 3; |
| 1516 | pub type KeyReleaseEvent = KeyPressEvent; |
| 1517 | |
| 1518 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1519 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1520 | pub struct ButtonMask(u16); |
| 1521 | impl ButtonMask { |
| 1522 | pub const M1: Self = Self(1 << 8); |
| 1523 | pub const M2: Self = Self(1 << 9); |
| 1524 | pub const M3: Self = Self(1 << 10); |
| 1525 | pub const M4: Self = Self(1 << 11); |
| 1526 | pub const M5: Self = Self(1 << 12); |
| 1527 | pub const ANY: Self = Self(1 << 15); |
| 1528 | } |
| 1529 | impl From<ButtonMask> for u16 { |
| 1530 | #[inline ] |
| 1531 | fn from(input: ButtonMask) -> Self { |
| 1532 | input.0 |
| 1533 | } |
| 1534 | } |
| 1535 | impl From<ButtonMask> for Option<u16> { |
| 1536 | #[inline ] |
| 1537 | fn from(input: ButtonMask) -> Self { |
| 1538 | Some(input.0) |
| 1539 | } |
| 1540 | } |
| 1541 | impl From<ButtonMask> for u32 { |
| 1542 | #[inline ] |
| 1543 | fn from(input: ButtonMask) -> Self { |
| 1544 | u32::from(input.0) |
| 1545 | } |
| 1546 | } |
| 1547 | impl From<ButtonMask> for Option<u32> { |
| 1548 | #[inline ] |
| 1549 | fn from(input: ButtonMask) -> Self { |
| 1550 | Some(u32::from(input.0)) |
| 1551 | } |
| 1552 | } |
| 1553 | impl From<u8> for ButtonMask { |
| 1554 | #[inline ] |
| 1555 | fn from(value: u8) -> Self { |
| 1556 | Self(value.into()) |
| 1557 | } |
| 1558 | } |
| 1559 | impl From<u16> for ButtonMask { |
| 1560 | #[inline ] |
| 1561 | fn from(value: u16) -> Self { |
| 1562 | Self(value) |
| 1563 | } |
| 1564 | } |
| 1565 | impl core::fmt::Debug for ButtonMask { |
| 1566 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1567 | let variants: [(u32, &'static str, &'static …); 6] = [ |
| 1568 | (Self::M1.0.into(), "M1" , "M1" ), |
| 1569 | (Self::M2.0.into(), "M2" , "M2" ), |
| 1570 | (Self::M3.0.into(), "M3" , "M3" ), |
| 1571 | (Self::M4.0.into(), "M4" , "M4" ), |
| 1572 | (Self::M5.0.into(), "M5" , "M5" ), |
| 1573 | (Self::ANY.0.into(), "ANY" , "Any" ), |
| 1574 | ]; |
| 1575 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 1576 | } |
| 1577 | } |
| 1578 | bitmask_binop!(ButtonMask, u16); |
| 1579 | |
| 1580 | /// Opcode for the ButtonPress event |
| 1581 | pub const BUTTON_PRESS_EVENT: u8 = 4; |
| 1582 | /// a mouse button was pressed/released. |
| 1583 | /// |
| 1584 | /// # Fields |
| 1585 | /// |
| 1586 | /// * `detail` - The keycode (a number representing a physical key on the keyboard) of the key |
| 1587 | /// which was pressed. |
| 1588 | /// * `time` - Time when the event was generated (in milliseconds). |
| 1589 | /// * `root` - The root window of `child`. |
| 1590 | /// * `same_screen` - Whether the `event` window is on the same screen as the `root` window. |
| 1591 | /// * `event_x` - If `same_screen` is true, this is the X coordinate relative to the `event` |
| 1592 | /// window's origin. Otherwise, `event_x` will be set to zero. |
| 1593 | /// * `event_y` - If `same_screen` is true, this is the Y coordinate relative to the `event` |
| 1594 | /// window's origin. Otherwise, `event_y` will be set to zero. |
| 1595 | /// * `root_x` - The X coordinate of the pointer relative to the `root` window at the time of |
| 1596 | /// the event. |
| 1597 | /// * `root_y` - The Y coordinate of the pointer relative to the `root` window at the time of |
| 1598 | /// the event. |
| 1599 | /// * `state` - The logical state of the pointer buttons and modifier keys just prior to the |
| 1600 | /// event. |
| 1601 | /// |
| 1602 | /// # See |
| 1603 | /// |
| 1604 | /// * `GrabButton`: request |
| 1605 | /// * `GrabPointer`: request |
| 1606 | #[derive (Clone, Copy, Default)] |
| 1607 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 1608 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1609 | pub struct ButtonPressEvent { |
| 1610 | pub response_type: u8, |
| 1611 | pub detail: Button, |
| 1612 | pub sequence: u16, |
| 1613 | pub time: Timestamp, |
| 1614 | pub root: Window, |
| 1615 | pub event: Window, |
| 1616 | pub child: Window, |
| 1617 | pub root_x: i16, |
| 1618 | pub root_y: i16, |
| 1619 | pub event_x: i16, |
| 1620 | pub event_y: i16, |
| 1621 | pub state: KeyButMask, |
| 1622 | pub same_screen: bool, |
| 1623 | } |
| 1624 | impl_debug_if_no_extra_traits!(ButtonPressEvent, "ButtonPressEvent" ); |
| 1625 | impl TryParse for ButtonPressEvent { |
| 1626 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 1627 | let remaining = initial_value; |
| 1628 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 1629 | let (detail, remaining) = Button::try_parse(remaining)?; |
| 1630 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 1631 | let (time, remaining) = Timestamp::try_parse(remaining)?; |
| 1632 | let (root, remaining) = Window::try_parse(remaining)?; |
| 1633 | let (event, remaining) = Window::try_parse(remaining)?; |
| 1634 | let (child, remaining) = Window::try_parse(remaining)?; |
| 1635 | let (root_x, remaining) = i16::try_parse(remaining)?; |
| 1636 | let (root_y, remaining) = i16::try_parse(remaining)?; |
| 1637 | let (event_x, remaining) = i16::try_parse(remaining)?; |
| 1638 | let (event_y, remaining) = i16::try_parse(remaining)?; |
| 1639 | let (state, remaining) = u16::try_parse(remaining)?; |
| 1640 | let (same_screen, remaining) = bool::try_parse(remaining)?; |
| 1641 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 1642 | let state = state.into(); |
| 1643 | let result = ButtonPressEvent { response_type, detail, sequence, time, root, event, child, root_x, root_y, event_x, event_y, state, same_screen }; |
| 1644 | let _ = remaining; |
| 1645 | let remaining = initial_value.get(32..) |
| 1646 | .ok_or(ParseError::InsufficientData)?; |
| 1647 | Ok((result, remaining)) |
| 1648 | } |
| 1649 | } |
| 1650 | impl Serialize for ButtonPressEvent { |
| 1651 | type Bytes = [u8; 32]; |
| 1652 | fn serialize(&self) -> [u8; 32] { |
| 1653 | let response_type_bytes = self.response_type.serialize(); |
| 1654 | let detail_bytes = self.detail.serialize(); |
| 1655 | let sequence_bytes = self.sequence.serialize(); |
| 1656 | let time_bytes = self.time.serialize(); |
| 1657 | let root_bytes = self.root.serialize(); |
| 1658 | let event_bytes = self.event.serialize(); |
| 1659 | let child_bytes = self.child.serialize(); |
| 1660 | let root_x_bytes = self.root_x.serialize(); |
| 1661 | let root_y_bytes = self.root_y.serialize(); |
| 1662 | let event_x_bytes = self.event_x.serialize(); |
| 1663 | let event_y_bytes = self.event_y.serialize(); |
| 1664 | let state_bytes = u16::from(self.state).serialize(); |
| 1665 | let same_screen_bytes = self.same_screen.serialize(); |
| 1666 | [ |
| 1667 | response_type_bytes[0], |
| 1668 | detail_bytes[0], |
| 1669 | sequence_bytes[0], |
| 1670 | sequence_bytes[1], |
| 1671 | time_bytes[0], |
| 1672 | time_bytes[1], |
| 1673 | time_bytes[2], |
| 1674 | time_bytes[3], |
| 1675 | root_bytes[0], |
| 1676 | root_bytes[1], |
| 1677 | root_bytes[2], |
| 1678 | root_bytes[3], |
| 1679 | event_bytes[0], |
| 1680 | event_bytes[1], |
| 1681 | event_bytes[2], |
| 1682 | event_bytes[3], |
| 1683 | child_bytes[0], |
| 1684 | child_bytes[1], |
| 1685 | child_bytes[2], |
| 1686 | child_bytes[3], |
| 1687 | root_x_bytes[0], |
| 1688 | root_x_bytes[1], |
| 1689 | root_y_bytes[0], |
| 1690 | root_y_bytes[1], |
| 1691 | event_x_bytes[0], |
| 1692 | event_x_bytes[1], |
| 1693 | event_y_bytes[0], |
| 1694 | event_y_bytes[1], |
| 1695 | state_bytes[0], |
| 1696 | state_bytes[1], |
| 1697 | same_screen_bytes[0], |
| 1698 | 0, |
| 1699 | ] |
| 1700 | } |
| 1701 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 1702 | bytes.reserve(32); |
| 1703 | self.response_type.serialize_into(bytes); |
| 1704 | self.detail.serialize_into(bytes); |
| 1705 | self.sequence.serialize_into(bytes); |
| 1706 | self.time.serialize_into(bytes); |
| 1707 | self.root.serialize_into(bytes); |
| 1708 | self.event.serialize_into(bytes); |
| 1709 | self.child.serialize_into(bytes); |
| 1710 | self.root_x.serialize_into(bytes); |
| 1711 | self.root_y.serialize_into(bytes); |
| 1712 | self.event_x.serialize_into(bytes); |
| 1713 | self.event_y.serialize_into(bytes); |
| 1714 | u16::from(self.state).serialize_into(bytes); |
| 1715 | self.same_screen.serialize_into(bytes); |
| 1716 | bytes.extend_from_slice(&[0; 1]); |
| 1717 | } |
| 1718 | } |
| 1719 | impl From<&ButtonPressEvent> for [u8; 32] { |
| 1720 | fn from(input: &ButtonPressEvent) -> Self { |
| 1721 | let response_type_bytes = input.response_type.serialize(); |
| 1722 | let detail_bytes = input.detail.serialize(); |
| 1723 | let sequence_bytes = input.sequence.serialize(); |
| 1724 | let time_bytes = input.time.serialize(); |
| 1725 | let root_bytes = input.root.serialize(); |
| 1726 | let event_bytes = input.event.serialize(); |
| 1727 | let child_bytes = input.child.serialize(); |
| 1728 | let root_x_bytes = input.root_x.serialize(); |
| 1729 | let root_y_bytes = input.root_y.serialize(); |
| 1730 | let event_x_bytes = input.event_x.serialize(); |
| 1731 | let event_y_bytes = input.event_y.serialize(); |
| 1732 | let state_bytes = u16::from(input.state).serialize(); |
| 1733 | let same_screen_bytes = input.same_screen.serialize(); |
| 1734 | [ |
| 1735 | response_type_bytes[0], |
| 1736 | detail_bytes[0], |
| 1737 | sequence_bytes[0], |
| 1738 | sequence_bytes[1], |
| 1739 | time_bytes[0], |
| 1740 | time_bytes[1], |
| 1741 | time_bytes[2], |
| 1742 | time_bytes[3], |
| 1743 | root_bytes[0], |
| 1744 | root_bytes[1], |
| 1745 | root_bytes[2], |
| 1746 | root_bytes[3], |
| 1747 | event_bytes[0], |
| 1748 | event_bytes[1], |
| 1749 | event_bytes[2], |
| 1750 | event_bytes[3], |
| 1751 | child_bytes[0], |
| 1752 | child_bytes[1], |
| 1753 | child_bytes[2], |
| 1754 | child_bytes[3], |
| 1755 | root_x_bytes[0], |
| 1756 | root_x_bytes[1], |
| 1757 | root_y_bytes[0], |
| 1758 | root_y_bytes[1], |
| 1759 | event_x_bytes[0], |
| 1760 | event_x_bytes[1], |
| 1761 | event_y_bytes[0], |
| 1762 | event_y_bytes[1], |
| 1763 | state_bytes[0], |
| 1764 | state_bytes[1], |
| 1765 | same_screen_bytes[0], |
| 1766 | 0, |
| 1767 | ] |
| 1768 | } |
| 1769 | } |
| 1770 | impl From<ButtonPressEvent> for [u8; 32] { |
| 1771 | fn from(input: ButtonPressEvent) -> Self { |
| 1772 | Self::from(&input) |
| 1773 | } |
| 1774 | } |
| 1775 | |
| 1776 | /// Opcode for the ButtonRelease event |
| 1777 | pub const BUTTON_RELEASE_EVENT: u8 = 5; |
| 1778 | pub type ButtonReleaseEvent = ButtonPressEvent; |
| 1779 | |
| 1780 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1781 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1782 | pub struct Motion(u8); |
| 1783 | impl Motion { |
| 1784 | pub const NORMAL: Self = Self(0); |
| 1785 | pub const HINT: Self = Self(1); |
| 1786 | } |
| 1787 | impl From<Motion> for u8 { |
| 1788 | #[inline ] |
| 1789 | fn from(input: Motion) -> Self { |
| 1790 | input.0 |
| 1791 | } |
| 1792 | } |
| 1793 | impl From<Motion> for Option<u8> { |
| 1794 | #[inline ] |
| 1795 | fn from(input: Motion) -> Self { |
| 1796 | Some(input.0) |
| 1797 | } |
| 1798 | } |
| 1799 | impl From<Motion> for u16 { |
| 1800 | #[inline ] |
| 1801 | fn from(input: Motion) -> Self { |
| 1802 | u16::from(input.0) |
| 1803 | } |
| 1804 | } |
| 1805 | impl From<Motion> for Option<u16> { |
| 1806 | #[inline ] |
| 1807 | fn from(input: Motion) -> Self { |
| 1808 | Some(u16::from(input.0)) |
| 1809 | } |
| 1810 | } |
| 1811 | impl From<Motion> for u32 { |
| 1812 | #[inline ] |
| 1813 | fn from(input: Motion) -> Self { |
| 1814 | u32::from(input.0) |
| 1815 | } |
| 1816 | } |
| 1817 | impl From<Motion> for Option<u32> { |
| 1818 | #[inline ] |
| 1819 | fn from(input: Motion) -> Self { |
| 1820 | Some(u32::from(input.0)) |
| 1821 | } |
| 1822 | } |
| 1823 | impl From<u8> for Motion { |
| 1824 | #[inline ] |
| 1825 | fn from(value: u8) -> Self { |
| 1826 | Self(value) |
| 1827 | } |
| 1828 | } |
| 1829 | impl core::fmt::Debug for Motion { |
| 1830 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1831 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 1832 | (Self::NORMAL.0.into(), "NORMAL" , "Normal" ), |
| 1833 | (Self::HINT.0.into(), "HINT" , "Hint" ), |
| 1834 | ]; |
| 1835 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 1836 | } |
| 1837 | } |
| 1838 | |
| 1839 | /// Opcode for the MotionNotify event |
| 1840 | pub const MOTION_NOTIFY_EVENT: u8 = 6; |
| 1841 | /// a key was pressed. |
| 1842 | /// |
| 1843 | /// # Fields |
| 1844 | /// |
| 1845 | /// * `detail` - The keycode (a number representing a physical key on the keyboard) of the key |
| 1846 | /// which was pressed. |
| 1847 | /// * `time` - Time when the event was generated (in milliseconds). |
| 1848 | /// * `root` - The root window of `child`. |
| 1849 | /// * `same_screen` - Whether the `event` window is on the same screen as the `root` window. |
| 1850 | /// * `event_x` - If `same_screen` is true, this is the X coordinate relative to the `event` |
| 1851 | /// window's origin. Otherwise, `event_x` will be set to zero. |
| 1852 | /// * `event_y` - If `same_screen` is true, this is the Y coordinate relative to the `event` |
| 1853 | /// window's origin. Otherwise, `event_y` will be set to zero. |
| 1854 | /// * `root_x` - The X coordinate of the pointer relative to the `root` window at the time of |
| 1855 | /// the event. |
| 1856 | /// * `root_y` - The Y coordinate of the pointer relative to the `root` window at the time of |
| 1857 | /// the event. |
| 1858 | /// * `state` - The logical state of the pointer buttons and modifier keys just prior to the |
| 1859 | /// event. |
| 1860 | /// |
| 1861 | /// # See |
| 1862 | /// |
| 1863 | /// * `GrabKey`: request |
| 1864 | /// * `GrabKeyboard`: request |
| 1865 | #[derive (Clone, Copy, Default)] |
| 1866 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 1867 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1868 | pub struct MotionNotifyEvent { |
| 1869 | pub response_type: u8, |
| 1870 | pub detail: Motion, |
| 1871 | pub sequence: u16, |
| 1872 | pub time: Timestamp, |
| 1873 | pub root: Window, |
| 1874 | pub event: Window, |
| 1875 | pub child: Window, |
| 1876 | pub root_x: i16, |
| 1877 | pub root_y: i16, |
| 1878 | pub event_x: i16, |
| 1879 | pub event_y: i16, |
| 1880 | pub state: KeyButMask, |
| 1881 | pub same_screen: bool, |
| 1882 | } |
| 1883 | impl_debug_if_no_extra_traits!(MotionNotifyEvent, "MotionNotifyEvent" ); |
| 1884 | impl TryParse for MotionNotifyEvent { |
| 1885 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 1886 | let remaining = initial_value; |
| 1887 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 1888 | let (detail, remaining) = u8::try_parse(remaining)?; |
| 1889 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 1890 | let (time, remaining) = Timestamp::try_parse(remaining)?; |
| 1891 | let (root, remaining) = Window::try_parse(remaining)?; |
| 1892 | let (event, remaining) = Window::try_parse(remaining)?; |
| 1893 | let (child, remaining) = Window::try_parse(remaining)?; |
| 1894 | let (root_x, remaining) = i16::try_parse(remaining)?; |
| 1895 | let (root_y, remaining) = i16::try_parse(remaining)?; |
| 1896 | let (event_x, remaining) = i16::try_parse(remaining)?; |
| 1897 | let (event_y, remaining) = i16::try_parse(remaining)?; |
| 1898 | let (state, remaining) = u16::try_parse(remaining)?; |
| 1899 | let (same_screen, remaining) = bool::try_parse(remaining)?; |
| 1900 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 1901 | let detail = detail.into(); |
| 1902 | let state = state.into(); |
| 1903 | let result = MotionNotifyEvent { response_type, detail, sequence, time, root, event, child, root_x, root_y, event_x, event_y, state, same_screen }; |
| 1904 | let _ = remaining; |
| 1905 | let remaining = initial_value.get(32..) |
| 1906 | .ok_or(ParseError::InsufficientData)?; |
| 1907 | Ok((result, remaining)) |
| 1908 | } |
| 1909 | } |
| 1910 | impl Serialize for MotionNotifyEvent { |
| 1911 | type Bytes = [u8; 32]; |
| 1912 | fn serialize(&self) -> [u8; 32] { |
| 1913 | let response_type_bytes = self.response_type.serialize(); |
| 1914 | let detail_bytes = u8::from(self.detail).serialize(); |
| 1915 | let sequence_bytes = self.sequence.serialize(); |
| 1916 | let time_bytes = self.time.serialize(); |
| 1917 | let root_bytes = self.root.serialize(); |
| 1918 | let event_bytes = self.event.serialize(); |
| 1919 | let child_bytes = self.child.serialize(); |
| 1920 | let root_x_bytes = self.root_x.serialize(); |
| 1921 | let root_y_bytes = self.root_y.serialize(); |
| 1922 | let event_x_bytes = self.event_x.serialize(); |
| 1923 | let event_y_bytes = self.event_y.serialize(); |
| 1924 | let state_bytes = u16::from(self.state).serialize(); |
| 1925 | let same_screen_bytes = self.same_screen.serialize(); |
| 1926 | [ |
| 1927 | response_type_bytes[0], |
| 1928 | detail_bytes[0], |
| 1929 | sequence_bytes[0], |
| 1930 | sequence_bytes[1], |
| 1931 | time_bytes[0], |
| 1932 | time_bytes[1], |
| 1933 | time_bytes[2], |
| 1934 | time_bytes[3], |
| 1935 | root_bytes[0], |
| 1936 | root_bytes[1], |
| 1937 | root_bytes[2], |
| 1938 | root_bytes[3], |
| 1939 | event_bytes[0], |
| 1940 | event_bytes[1], |
| 1941 | event_bytes[2], |
| 1942 | event_bytes[3], |
| 1943 | child_bytes[0], |
| 1944 | child_bytes[1], |
| 1945 | child_bytes[2], |
| 1946 | child_bytes[3], |
| 1947 | root_x_bytes[0], |
| 1948 | root_x_bytes[1], |
| 1949 | root_y_bytes[0], |
| 1950 | root_y_bytes[1], |
| 1951 | event_x_bytes[0], |
| 1952 | event_x_bytes[1], |
| 1953 | event_y_bytes[0], |
| 1954 | event_y_bytes[1], |
| 1955 | state_bytes[0], |
| 1956 | state_bytes[1], |
| 1957 | same_screen_bytes[0], |
| 1958 | 0, |
| 1959 | ] |
| 1960 | } |
| 1961 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 1962 | bytes.reserve(32); |
| 1963 | self.response_type.serialize_into(bytes); |
| 1964 | u8::from(self.detail).serialize_into(bytes); |
| 1965 | self.sequence.serialize_into(bytes); |
| 1966 | self.time.serialize_into(bytes); |
| 1967 | self.root.serialize_into(bytes); |
| 1968 | self.event.serialize_into(bytes); |
| 1969 | self.child.serialize_into(bytes); |
| 1970 | self.root_x.serialize_into(bytes); |
| 1971 | self.root_y.serialize_into(bytes); |
| 1972 | self.event_x.serialize_into(bytes); |
| 1973 | self.event_y.serialize_into(bytes); |
| 1974 | u16::from(self.state).serialize_into(bytes); |
| 1975 | self.same_screen.serialize_into(bytes); |
| 1976 | bytes.extend_from_slice(&[0; 1]); |
| 1977 | } |
| 1978 | } |
| 1979 | impl From<&MotionNotifyEvent> for [u8; 32] { |
| 1980 | fn from(input: &MotionNotifyEvent) -> Self { |
| 1981 | let response_type_bytes = input.response_type.serialize(); |
| 1982 | let detail_bytes = u8::from(input.detail).serialize(); |
| 1983 | let sequence_bytes = input.sequence.serialize(); |
| 1984 | let time_bytes = input.time.serialize(); |
| 1985 | let root_bytes = input.root.serialize(); |
| 1986 | let event_bytes = input.event.serialize(); |
| 1987 | let child_bytes = input.child.serialize(); |
| 1988 | let root_x_bytes = input.root_x.serialize(); |
| 1989 | let root_y_bytes = input.root_y.serialize(); |
| 1990 | let event_x_bytes = input.event_x.serialize(); |
| 1991 | let event_y_bytes = input.event_y.serialize(); |
| 1992 | let state_bytes = u16::from(input.state).serialize(); |
| 1993 | let same_screen_bytes = input.same_screen.serialize(); |
| 1994 | [ |
| 1995 | response_type_bytes[0], |
| 1996 | detail_bytes[0], |
| 1997 | sequence_bytes[0], |
| 1998 | sequence_bytes[1], |
| 1999 | time_bytes[0], |
| 2000 | time_bytes[1], |
| 2001 | time_bytes[2], |
| 2002 | time_bytes[3], |
| 2003 | root_bytes[0], |
| 2004 | root_bytes[1], |
| 2005 | root_bytes[2], |
| 2006 | root_bytes[3], |
| 2007 | event_bytes[0], |
| 2008 | event_bytes[1], |
| 2009 | event_bytes[2], |
| 2010 | event_bytes[3], |
| 2011 | child_bytes[0], |
| 2012 | child_bytes[1], |
| 2013 | child_bytes[2], |
| 2014 | child_bytes[3], |
| 2015 | root_x_bytes[0], |
| 2016 | root_x_bytes[1], |
| 2017 | root_y_bytes[0], |
| 2018 | root_y_bytes[1], |
| 2019 | event_x_bytes[0], |
| 2020 | event_x_bytes[1], |
| 2021 | event_y_bytes[0], |
| 2022 | event_y_bytes[1], |
| 2023 | state_bytes[0], |
| 2024 | state_bytes[1], |
| 2025 | same_screen_bytes[0], |
| 2026 | 0, |
| 2027 | ] |
| 2028 | } |
| 2029 | } |
| 2030 | impl From<MotionNotifyEvent> for [u8; 32] { |
| 2031 | fn from(input: MotionNotifyEvent) -> Self { |
| 2032 | Self::from(&input) |
| 2033 | } |
| 2034 | } |
| 2035 | |
| 2036 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 2037 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2038 | pub struct NotifyDetail(u8); |
| 2039 | impl NotifyDetail { |
| 2040 | pub const ANCESTOR: Self = Self(0); |
| 2041 | pub const VIRTUAL: Self = Self(1); |
| 2042 | pub const INFERIOR: Self = Self(2); |
| 2043 | pub const NONLINEAR: Self = Self(3); |
| 2044 | pub const NONLINEAR_VIRTUAL: Self = Self(4); |
| 2045 | pub const POINTER: Self = Self(5); |
| 2046 | pub const POINTER_ROOT: Self = Self(6); |
| 2047 | pub const NONE: Self = Self(7); |
| 2048 | } |
| 2049 | impl From<NotifyDetail> for u8 { |
| 2050 | #[inline ] |
| 2051 | fn from(input: NotifyDetail) -> Self { |
| 2052 | input.0 |
| 2053 | } |
| 2054 | } |
| 2055 | impl From<NotifyDetail> for Option<u8> { |
| 2056 | #[inline ] |
| 2057 | fn from(input: NotifyDetail) -> Self { |
| 2058 | Some(input.0) |
| 2059 | } |
| 2060 | } |
| 2061 | impl From<NotifyDetail> for u16 { |
| 2062 | #[inline ] |
| 2063 | fn from(input: NotifyDetail) -> Self { |
| 2064 | u16::from(input.0) |
| 2065 | } |
| 2066 | } |
| 2067 | impl From<NotifyDetail> for Option<u16> { |
| 2068 | #[inline ] |
| 2069 | fn from(input: NotifyDetail) -> Self { |
| 2070 | Some(u16::from(input.0)) |
| 2071 | } |
| 2072 | } |
| 2073 | impl From<NotifyDetail> for u32 { |
| 2074 | #[inline ] |
| 2075 | fn from(input: NotifyDetail) -> Self { |
| 2076 | u32::from(input.0) |
| 2077 | } |
| 2078 | } |
| 2079 | impl From<NotifyDetail> for Option<u32> { |
| 2080 | #[inline ] |
| 2081 | fn from(input: NotifyDetail) -> Self { |
| 2082 | Some(u32::from(input.0)) |
| 2083 | } |
| 2084 | } |
| 2085 | impl From<u8> for NotifyDetail { |
| 2086 | #[inline ] |
| 2087 | fn from(value: u8) -> Self { |
| 2088 | Self(value) |
| 2089 | } |
| 2090 | } |
| 2091 | impl core::fmt::Debug for NotifyDetail { |
| 2092 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 2093 | let variants: [(u32, &'static str, &'static …); 8] = [ |
| 2094 | (Self::ANCESTOR.0.into(), "ANCESTOR" , "Ancestor" ), |
| 2095 | (Self::VIRTUAL.0.into(), "VIRTUAL" , "Virtual" ), |
| 2096 | (Self::INFERIOR.0.into(), "INFERIOR" , "Inferior" ), |
| 2097 | (Self::NONLINEAR.0.into(), "NONLINEAR" , "Nonlinear" ), |
| 2098 | (Self::NONLINEAR_VIRTUAL.0.into(), "NONLINEAR_VIRTUAL" , "NonlinearVirtual" ), |
| 2099 | (Self::POINTER.0.into(), "POINTER" , "Pointer" ), |
| 2100 | (Self::POINTER_ROOT.0.into(), "POINTER_ROOT" , "PointerRoot" ), |
| 2101 | (Self::NONE.0.into(), "NONE" , "None" ), |
| 2102 | ]; |
| 2103 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 2104 | } |
| 2105 | } |
| 2106 | |
| 2107 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 2108 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2109 | pub struct NotifyMode(u8); |
| 2110 | impl NotifyMode { |
| 2111 | pub const NORMAL: Self = Self(0); |
| 2112 | pub const GRAB: Self = Self(1); |
| 2113 | pub const UNGRAB: Self = Self(2); |
| 2114 | pub const WHILE_GRABBED: Self = Self(3); |
| 2115 | } |
| 2116 | impl From<NotifyMode> for u8 { |
| 2117 | #[inline ] |
| 2118 | fn from(input: NotifyMode) -> Self { |
| 2119 | input.0 |
| 2120 | } |
| 2121 | } |
| 2122 | impl From<NotifyMode> for Option<u8> { |
| 2123 | #[inline ] |
| 2124 | fn from(input: NotifyMode) -> Self { |
| 2125 | Some(input.0) |
| 2126 | } |
| 2127 | } |
| 2128 | impl From<NotifyMode> for u16 { |
| 2129 | #[inline ] |
| 2130 | fn from(input: NotifyMode) -> Self { |
| 2131 | u16::from(input.0) |
| 2132 | } |
| 2133 | } |
| 2134 | impl From<NotifyMode> for Option<u16> { |
| 2135 | #[inline ] |
| 2136 | fn from(input: NotifyMode) -> Self { |
| 2137 | Some(u16::from(input.0)) |
| 2138 | } |
| 2139 | } |
| 2140 | impl From<NotifyMode> for u32 { |
| 2141 | #[inline ] |
| 2142 | fn from(input: NotifyMode) -> Self { |
| 2143 | u32::from(input.0) |
| 2144 | } |
| 2145 | } |
| 2146 | impl From<NotifyMode> for Option<u32> { |
| 2147 | #[inline ] |
| 2148 | fn from(input: NotifyMode) -> Self { |
| 2149 | Some(u32::from(input.0)) |
| 2150 | } |
| 2151 | } |
| 2152 | impl From<u8> for NotifyMode { |
| 2153 | #[inline ] |
| 2154 | fn from(value: u8) -> Self { |
| 2155 | Self(value) |
| 2156 | } |
| 2157 | } |
| 2158 | impl core::fmt::Debug for NotifyMode { |
| 2159 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 2160 | let variants: [(u32, &'static str, &'static …); 4] = [ |
| 2161 | (Self::NORMAL.0.into(), "NORMAL" , "Normal" ), |
| 2162 | (Self::GRAB.0.into(), "GRAB" , "Grab" ), |
| 2163 | (Self::UNGRAB.0.into(), "UNGRAB" , "Ungrab" ), |
| 2164 | (Self::WHILE_GRABBED.0.into(), "WHILE_GRABBED" , "WhileGrabbed" ), |
| 2165 | ]; |
| 2166 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 2167 | } |
| 2168 | } |
| 2169 | |
| 2170 | /// Opcode for the EnterNotify event |
| 2171 | pub const ENTER_NOTIFY_EVENT: u8 = 7; |
| 2172 | /// the pointer is in a different window. |
| 2173 | /// |
| 2174 | /// # Fields |
| 2175 | /// |
| 2176 | /// * `event` - The window on which the event was generated. |
| 2177 | /// * `child` - If the `event` window has subwindows and the final pointer position is in one |
| 2178 | /// of them, then `child` is set to that subwindow, `XCB_WINDOW_NONE` otherwise. |
| 2179 | /// * `root` - The root window for the final cursor position. |
| 2180 | /// * `root_x` - The pointer X coordinate relative to `root`'s origin at the time of the event. |
| 2181 | /// * `root_y` - The pointer Y coordinate relative to `root`'s origin at the time of the event. |
| 2182 | /// * `event_x` - If `event` is on the same screen as `root`, this is the pointer X coordinate |
| 2183 | /// relative to the event window's origin. |
| 2184 | /// * `event_y` - If `event` is on the same screen as `root`, this is the pointer Y coordinate |
| 2185 | /// relative to the event window's origin. |
| 2186 | /// * `mode` - |
| 2187 | #[derive (Clone, Copy, Default)] |
| 2188 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 2189 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2190 | pub struct EnterNotifyEvent { |
| 2191 | pub response_type: u8, |
| 2192 | pub detail: NotifyDetail, |
| 2193 | pub sequence: u16, |
| 2194 | pub time: Timestamp, |
| 2195 | pub root: Window, |
| 2196 | pub event: Window, |
| 2197 | pub child: Window, |
| 2198 | pub root_x: i16, |
| 2199 | pub root_y: i16, |
| 2200 | pub event_x: i16, |
| 2201 | pub event_y: i16, |
| 2202 | pub state: KeyButMask, |
| 2203 | pub mode: NotifyMode, |
| 2204 | pub same_screen_focus: u8, |
| 2205 | } |
| 2206 | impl_debug_if_no_extra_traits!(EnterNotifyEvent, "EnterNotifyEvent" ); |
| 2207 | impl TryParse for EnterNotifyEvent { |
| 2208 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 2209 | let remaining = initial_value; |
| 2210 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 2211 | let (detail, remaining) = u8::try_parse(remaining)?; |
| 2212 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 2213 | let (time, remaining) = Timestamp::try_parse(remaining)?; |
| 2214 | let (root, remaining) = Window::try_parse(remaining)?; |
| 2215 | let (event, remaining) = Window::try_parse(remaining)?; |
| 2216 | let (child, remaining) = Window::try_parse(remaining)?; |
| 2217 | let (root_x, remaining) = i16::try_parse(remaining)?; |
| 2218 | let (root_y, remaining) = i16::try_parse(remaining)?; |
| 2219 | let (event_x, remaining) = i16::try_parse(remaining)?; |
| 2220 | let (event_y, remaining) = i16::try_parse(remaining)?; |
| 2221 | let (state, remaining) = u16::try_parse(remaining)?; |
| 2222 | let (mode, remaining) = u8::try_parse(remaining)?; |
| 2223 | let (same_screen_focus, remaining) = u8::try_parse(remaining)?; |
| 2224 | let detail = detail.into(); |
| 2225 | let state = state.into(); |
| 2226 | let mode = mode.into(); |
| 2227 | let result = EnterNotifyEvent { response_type, detail, sequence, time, root, event, child, root_x, root_y, event_x, event_y, state, mode, same_screen_focus }; |
| 2228 | let _ = remaining; |
| 2229 | let remaining = initial_value.get(32..) |
| 2230 | .ok_or(ParseError::InsufficientData)?; |
| 2231 | Ok((result, remaining)) |
| 2232 | } |
| 2233 | } |
| 2234 | impl Serialize for EnterNotifyEvent { |
| 2235 | type Bytes = [u8; 32]; |
| 2236 | fn serialize(&self) -> [u8; 32] { |
| 2237 | let response_type_bytes = self.response_type.serialize(); |
| 2238 | let detail_bytes = u8::from(self.detail).serialize(); |
| 2239 | let sequence_bytes = self.sequence.serialize(); |
| 2240 | let time_bytes = self.time.serialize(); |
| 2241 | let root_bytes = self.root.serialize(); |
| 2242 | let event_bytes = self.event.serialize(); |
| 2243 | let child_bytes = self.child.serialize(); |
| 2244 | let root_x_bytes = self.root_x.serialize(); |
| 2245 | let root_y_bytes = self.root_y.serialize(); |
| 2246 | let event_x_bytes = self.event_x.serialize(); |
| 2247 | let event_y_bytes = self.event_y.serialize(); |
| 2248 | let state_bytes = u16::from(self.state).serialize(); |
| 2249 | let mode_bytes = u8::from(self.mode).serialize(); |
| 2250 | let same_screen_focus_bytes = self.same_screen_focus.serialize(); |
| 2251 | [ |
| 2252 | response_type_bytes[0], |
| 2253 | detail_bytes[0], |
| 2254 | sequence_bytes[0], |
| 2255 | sequence_bytes[1], |
| 2256 | time_bytes[0], |
| 2257 | time_bytes[1], |
| 2258 | time_bytes[2], |
| 2259 | time_bytes[3], |
| 2260 | root_bytes[0], |
| 2261 | root_bytes[1], |
| 2262 | root_bytes[2], |
| 2263 | root_bytes[3], |
| 2264 | event_bytes[0], |
| 2265 | event_bytes[1], |
| 2266 | event_bytes[2], |
| 2267 | event_bytes[3], |
| 2268 | child_bytes[0], |
| 2269 | child_bytes[1], |
| 2270 | child_bytes[2], |
| 2271 | child_bytes[3], |
| 2272 | root_x_bytes[0], |
| 2273 | root_x_bytes[1], |
| 2274 | root_y_bytes[0], |
| 2275 | root_y_bytes[1], |
| 2276 | event_x_bytes[0], |
| 2277 | event_x_bytes[1], |
| 2278 | event_y_bytes[0], |
| 2279 | event_y_bytes[1], |
| 2280 | state_bytes[0], |
| 2281 | state_bytes[1], |
| 2282 | mode_bytes[0], |
| 2283 | same_screen_focus_bytes[0], |
| 2284 | ] |
| 2285 | } |
| 2286 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 2287 | bytes.reserve(32); |
| 2288 | self.response_type.serialize_into(bytes); |
| 2289 | u8::from(self.detail).serialize_into(bytes); |
| 2290 | self.sequence.serialize_into(bytes); |
| 2291 | self.time.serialize_into(bytes); |
| 2292 | self.root.serialize_into(bytes); |
| 2293 | self.event.serialize_into(bytes); |
| 2294 | self.child.serialize_into(bytes); |
| 2295 | self.root_x.serialize_into(bytes); |
| 2296 | self.root_y.serialize_into(bytes); |
| 2297 | self.event_x.serialize_into(bytes); |
| 2298 | self.event_y.serialize_into(bytes); |
| 2299 | u16::from(self.state).serialize_into(bytes); |
| 2300 | u8::from(self.mode).serialize_into(bytes); |
| 2301 | self.same_screen_focus.serialize_into(bytes); |
| 2302 | } |
| 2303 | } |
| 2304 | impl From<&EnterNotifyEvent> for [u8; 32] { |
| 2305 | fn from(input: &EnterNotifyEvent) -> Self { |
| 2306 | let response_type_bytes = input.response_type.serialize(); |
| 2307 | let detail_bytes = u8::from(input.detail).serialize(); |
| 2308 | let sequence_bytes = input.sequence.serialize(); |
| 2309 | let time_bytes = input.time.serialize(); |
| 2310 | let root_bytes = input.root.serialize(); |
| 2311 | let event_bytes = input.event.serialize(); |
| 2312 | let child_bytes = input.child.serialize(); |
| 2313 | let root_x_bytes = input.root_x.serialize(); |
| 2314 | let root_y_bytes = input.root_y.serialize(); |
| 2315 | let event_x_bytes = input.event_x.serialize(); |
| 2316 | let event_y_bytes = input.event_y.serialize(); |
| 2317 | let state_bytes = u16::from(input.state).serialize(); |
| 2318 | let mode_bytes = u8::from(input.mode).serialize(); |
| 2319 | let same_screen_focus_bytes = input.same_screen_focus.serialize(); |
| 2320 | [ |
| 2321 | response_type_bytes[0], |
| 2322 | detail_bytes[0], |
| 2323 | sequence_bytes[0], |
| 2324 | sequence_bytes[1], |
| 2325 | time_bytes[0], |
| 2326 | time_bytes[1], |
| 2327 | time_bytes[2], |
| 2328 | time_bytes[3], |
| 2329 | root_bytes[0], |
| 2330 | root_bytes[1], |
| 2331 | root_bytes[2], |
| 2332 | root_bytes[3], |
| 2333 | event_bytes[0], |
| 2334 | event_bytes[1], |
| 2335 | event_bytes[2], |
| 2336 | event_bytes[3], |
| 2337 | child_bytes[0], |
| 2338 | child_bytes[1], |
| 2339 | child_bytes[2], |
| 2340 | child_bytes[3], |
| 2341 | root_x_bytes[0], |
| 2342 | root_x_bytes[1], |
| 2343 | root_y_bytes[0], |
| 2344 | root_y_bytes[1], |
| 2345 | event_x_bytes[0], |
| 2346 | event_x_bytes[1], |
| 2347 | event_y_bytes[0], |
| 2348 | event_y_bytes[1], |
| 2349 | state_bytes[0], |
| 2350 | state_bytes[1], |
| 2351 | mode_bytes[0], |
| 2352 | same_screen_focus_bytes[0], |
| 2353 | ] |
| 2354 | } |
| 2355 | } |
| 2356 | impl From<EnterNotifyEvent> for [u8; 32] { |
| 2357 | fn from(input: EnterNotifyEvent) -> Self { |
| 2358 | Self::from(&input) |
| 2359 | } |
| 2360 | } |
| 2361 | |
| 2362 | /// Opcode for the LeaveNotify event |
| 2363 | pub const LEAVE_NOTIFY_EVENT: u8 = 8; |
| 2364 | pub type LeaveNotifyEvent = EnterNotifyEvent; |
| 2365 | |
| 2366 | /// Opcode for the FocusIn event |
| 2367 | pub const FOCUS_IN_EVENT: u8 = 9; |
| 2368 | /// NOT YET DOCUMENTED. |
| 2369 | /// |
| 2370 | /// # Fields |
| 2371 | /// |
| 2372 | /// * `event` - The window on which the focus event was generated. This is the window used by |
| 2373 | /// the X server to report the event. |
| 2374 | /// * `detail` - |
| 2375 | /// * `mode` - |
| 2376 | #[derive (Clone, Copy, Default)] |
| 2377 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 2378 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2379 | pub struct FocusInEvent { |
| 2380 | pub response_type: u8, |
| 2381 | pub detail: NotifyDetail, |
| 2382 | pub sequence: u16, |
| 2383 | pub event: Window, |
| 2384 | pub mode: NotifyMode, |
| 2385 | } |
| 2386 | impl_debug_if_no_extra_traits!(FocusInEvent, "FocusInEvent" ); |
| 2387 | impl TryParse for FocusInEvent { |
| 2388 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 2389 | let remaining: &[u8] = initial_value; |
| 2390 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2391 | let (detail: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2392 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2393 | let (event: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 2394 | let (mode: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2395 | let remaining: &[u8] = remaining.get(3..).ok_or(err:ParseError::InsufficientData)?; |
| 2396 | let detail: NotifyDetail = detail.into(); |
| 2397 | let mode: NotifyMode = mode.into(); |
| 2398 | let result: FocusInEvent = FocusInEvent { response_type, detail, sequence, event, mode }; |
| 2399 | let _ = remaining; |
| 2400 | let remaining: &[u8] = initial_value.get(32..) |
| 2401 | .ok_or(err:ParseError::InsufficientData)?; |
| 2402 | Ok((result, remaining)) |
| 2403 | } |
| 2404 | } |
| 2405 | impl Serialize for FocusInEvent { |
| 2406 | type Bytes = [u8; 12]; |
| 2407 | fn serialize(&self) -> [u8; 12] { |
| 2408 | let response_type_bytes = self.response_type.serialize(); |
| 2409 | let detail_bytes = u8::from(self.detail).serialize(); |
| 2410 | let sequence_bytes = self.sequence.serialize(); |
| 2411 | let event_bytes = self.event.serialize(); |
| 2412 | let mode_bytes = u8::from(self.mode).serialize(); |
| 2413 | [ |
| 2414 | response_type_bytes[0], |
| 2415 | detail_bytes[0], |
| 2416 | sequence_bytes[0], |
| 2417 | sequence_bytes[1], |
| 2418 | event_bytes[0], |
| 2419 | event_bytes[1], |
| 2420 | event_bytes[2], |
| 2421 | event_bytes[3], |
| 2422 | mode_bytes[0], |
| 2423 | 0, |
| 2424 | 0, |
| 2425 | 0, |
| 2426 | ] |
| 2427 | } |
| 2428 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 2429 | bytes.reserve(12); |
| 2430 | self.response_type.serialize_into(bytes); |
| 2431 | u8::from(self.detail).serialize_into(bytes); |
| 2432 | self.sequence.serialize_into(bytes); |
| 2433 | self.event.serialize_into(bytes); |
| 2434 | u8::from(self.mode).serialize_into(bytes); |
| 2435 | bytes.extend_from_slice(&[0; 3]); |
| 2436 | } |
| 2437 | } |
| 2438 | impl From<&FocusInEvent> for [u8; 32] { |
| 2439 | fn from(input: &FocusInEvent) -> Self { |
| 2440 | let response_type_bytes = input.response_type.serialize(); |
| 2441 | let detail_bytes = u8::from(input.detail).serialize(); |
| 2442 | let sequence_bytes = input.sequence.serialize(); |
| 2443 | let event_bytes = input.event.serialize(); |
| 2444 | let mode_bytes = u8::from(input.mode).serialize(); |
| 2445 | [ |
| 2446 | response_type_bytes[0], |
| 2447 | detail_bytes[0], |
| 2448 | sequence_bytes[0], |
| 2449 | sequence_bytes[1], |
| 2450 | event_bytes[0], |
| 2451 | event_bytes[1], |
| 2452 | event_bytes[2], |
| 2453 | event_bytes[3], |
| 2454 | mode_bytes[0], |
| 2455 | 0, |
| 2456 | 0, |
| 2457 | 0, |
| 2458 | // trailing padding |
| 2459 | 0, |
| 2460 | 0, |
| 2461 | 0, |
| 2462 | 0, |
| 2463 | 0, |
| 2464 | 0, |
| 2465 | 0, |
| 2466 | 0, |
| 2467 | 0, |
| 2468 | 0, |
| 2469 | 0, |
| 2470 | 0, |
| 2471 | 0, |
| 2472 | 0, |
| 2473 | 0, |
| 2474 | 0, |
| 2475 | 0, |
| 2476 | 0, |
| 2477 | 0, |
| 2478 | 0, |
| 2479 | ] |
| 2480 | } |
| 2481 | } |
| 2482 | impl From<FocusInEvent> for [u8; 32] { |
| 2483 | fn from(input: FocusInEvent) -> Self { |
| 2484 | Self::from(&input) |
| 2485 | } |
| 2486 | } |
| 2487 | |
| 2488 | /// Opcode for the FocusOut event |
| 2489 | pub const FOCUS_OUT_EVENT: u8 = 10; |
| 2490 | pub type FocusOutEvent = FocusInEvent; |
| 2491 | |
| 2492 | /// Opcode for the KeymapNotify event |
| 2493 | pub const KEYMAP_NOTIFY_EVENT: u8 = 11; |
| 2494 | #[derive (Clone, Copy, Default)] |
| 2495 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 2496 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2497 | pub struct KeymapNotifyEvent { |
| 2498 | pub response_type: u8, |
| 2499 | pub keys: [u8; 31], |
| 2500 | } |
| 2501 | impl_debug_if_no_extra_traits!(KeymapNotifyEvent, "KeymapNotifyEvent" ); |
| 2502 | impl TryParse for KeymapNotifyEvent { |
| 2503 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 2504 | let remaining: &[u8] = initial_value; |
| 2505 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2506 | let (keys: [u8; 31], remaining: &[u8]) = crate::x11_utils::parse_u8_array::<31>(data:remaining)?; |
| 2507 | let result: KeymapNotifyEvent = KeymapNotifyEvent { response_type, keys }; |
| 2508 | let _ = remaining; |
| 2509 | let remaining: &[u8] = initial_value.get(32..) |
| 2510 | .ok_or(err:ParseError::InsufficientData)?; |
| 2511 | Ok((result, remaining)) |
| 2512 | } |
| 2513 | } |
| 2514 | impl Serialize for KeymapNotifyEvent { |
| 2515 | type Bytes = [u8; 32]; |
| 2516 | fn serialize(&self) -> [u8; 32] { |
| 2517 | let response_type_bytes = self.response_type.serialize(); |
| 2518 | [ |
| 2519 | response_type_bytes[0], |
| 2520 | self.keys[0], |
| 2521 | self.keys[1], |
| 2522 | self.keys[2], |
| 2523 | self.keys[3], |
| 2524 | self.keys[4], |
| 2525 | self.keys[5], |
| 2526 | self.keys[6], |
| 2527 | self.keys[7], |
| 2528 | self.keys[8], |
| 2529 | self.keys[9], |
| 2530 | self.keys[10], |
| 2531 | self.keys[11], |
| 2532 | self.keys[12], |
| 2533 | self.keys[13], |
| 2534 | self.keys[14], |
| 2535 | self.keys[15], |
| 2536 | self.keys[16], |
| 2537 | self.keys[17], |
| 2538 | self.keys[18], |
| 2539 | self.keys[19], |
| 2540 | self.keys[20], |
| 2541 | self.keys[21], |
| 2542 | self.keys[22], |
| 2543 | self.keys[23], |
| 2544 | self.keys[24], |
| 2545 | self.keys[25], |
| 2546 | self.keys[26], |
| 2547 | self.keys[27], |
| 2548 | self.keys[28], |
| 2549 | self.keys[29], |
| 2550 | self.keys[30], |
| 2551 | ] |
| 2552 | } |
| 2553 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 2554 | bytes.reserve(32); |
| 2555 | self.response_type.serialize_into(bytes); |
| 2556 | bytes.extend_from_slice(&self.keys); |
| 2557 | } |
| 2558 | } |
| 2559 | impl From<&KeymapNotifyEvent> for [u8; 32] { |
| 2560 | fn from(input: &KeymapNotifyEvent) -> Self { |
| 2561 | let response_type_bytes = input.response_type.serialize(); |
| 2562 | [ |
| 2563 | response_type_bytes[0], |
| 2564 | input.keys[0], |
| 2565 | input.keys[1], |
| 2566 | input.keys[2], |
| 2567 | input.keys[3], |
| 2568 | input.keys[4], |
| 2569 | input.keys[5], |
| 2570 | input.keys[6], |
| 2571 | input.keys[7], |
| 2572 | input.keys[8], |
| 2573 | input.keys[9], |
| 2574 | input.keys[10], |
| 2575 | input.keys[11], |
| 2576 | input.keys[12], |
| 2577 | input.keys[13], |
| 2578 | input.keys[14], |
| 2579 | input.keys[15], |
| 2580 | input.keys[16], |
| 2581 | input.keys[17], |
| 2582 | input.keys[18], |
| 2583 | input.keys[19], |
| 2584 | input.keys[20], |
| 2585 | input.keys[21], |
| 2586 | input.keys[22], |
| 2587 | input.keys[23], |
| 2588 | input.keys[24], |
| 2589 | input.keys[25], |
| 2590 | input.keys[26], |
| 2591 | input.keys[27], |
| 2592 | input.keys[28], |
| 2593 | input.keys[29], |
| 2594 | input.keys[30], |
| 2595 | ] |
| 2596 | } |
| 2597 | } |
| 2598 | impl From<KeymapNotifyEvent> for [u8; 32] { |
| 2599 | fn from(input: KeymapNotifyEvent) -> Self { |
| 2600 | Self::from(&input) |
| 2601 | } |
| 2602 | } |
| 2603 | |
| 2604 | /// Opcode for the Expose event |
| 2605 | pub const EXPOSE_EVENT: u8 = 12; |
| 2606 | /// NOT YET DOCUMENTED. |
| 2607 | /// |
| 2608 | /// # Fields |
| 2609 | /// |
| 2610 | /// * `window` - The exposed (damaged) window. |
| 2611 | /// * `x` - The X coordinate of the left-upper corner of the exposed rectangle, relative to |
| 2612 | /// the `window`'s origin. |
| 2613 | /// * `y` - The Y coordinate of the left-upper corner of the exposed rectangle, relative to |
| 2614 | /// the `window`'s origin. |
| 2615 | /// * `width` - The width of the exposed rectangle. |
| 2616 | /// * `height` - The height of the exposed rectangle. |
| 2617 | /// * `count` - The amount of `Expose` events following this one. Simple applications that do |
| 2618 | /// not want to optimize redisplay by distinguishing between subareas of its window |
| 2619 | /// can just ignore all Expose events with nonzero counts and perform full |
| 2620 | /// redisplays on events with zero counts. |
| 2621 | #[derive (Clone, Copy, Default)] |
| 2622 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 2623 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2624 | pub struct ExposeEvent { |
| 2625 | pub response_type: u8, |
| 2626 | pub sequence: u16, |
| 2627 | pub window: Window, |
| 2628 | pub x: u16, |
| 2629 | pub y: u16, |
| 2630 | pub width: u16, |
| 2631 | pub height: u16, |
| 2632 | pub count: u16, |
| 2633 | } |
| 2634 | impl_debug_if_no_extra_traits!(ExposeEvent, "ExposeEvent" ); |
| 2635 | impl TryParse for ExposeEvent { |
| 2636 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 2637 | let remaining: &[u8] = initial_value; |
| 2638 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2639 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 2640 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2641 | let (window: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 2642 | let (x: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2643 | let (y: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2644 | let (width: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2645 | let (height: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2646 | let (count: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2647 | let remaining: &[u8] = remaining.get(2..).ok_or(err:ParseError::InsufficientData)?; |
| 2648 | let result: ExposeEvent = ExposeEvent { response_type, sequence, window, x, y, width, height, count }; |
| 2649 | let _ = remaining; |
| 2650 | let remaining: &[u8] = initial_value.get(32..) |
| 2651 | .ok_or(err:ParseError::InsufficientData)?; |
| 2652 | Ok((result, remaining)) |
| 2653 | } |
| 2654 | } |
| 2655 | impl Serialize for ExposeEvent { |
| 2656 | type Bytes = [u8; 20]; |
| 2657 | fn serialize(&self) -> [u8; 20] { |
| 2658 | let response_type_bytes = self.response_type.serialize(); |
| 2659 | let sequence_bytes = self.sequence.serialize(); |
| 2660 | let window_bytes = self.window.serialize(); |
| 2661 | let x_bytes = self.x.serialize(); |
| 2662 | let y_bytes = self.y.serialize(); |
| 2663 | let width_bytes = self.width.serialize(); |
| 2664 | let height_bytes = self.height.serialize(); |
| 2665 | let count_bytes = self.count.serialize(); |
| 2666 | [ |
| 2667 | response_type_bytes[0], |
| 2668 | 0, |
| 2669 | sequence_bytes[0], |
| 2670 | sequence_bytes[1], |
| 2671 | window_bytes[0], |
| 2672 | window_bytes[1], |
| 2673 | window_bytes[2], |
| 2674 | window_bytes[3], |
| 2675 | x_bytes[0], |
| 2676 | x_bytes[1], |
| 2677 | y_bytes[0], |
| 2678 | y_bytes[1], |
| 2679 | width_bytes[0], |
| 2680 | width_bytes[1], |
| 2681 | height_bytes[0], |
| 2682 | height_bytes[1], |
| 2683 | count_bytes[0], |
| 2684 | count_bytes[1], |
| 2685 | 0, |
| 2686 | 0, |
| 2687 | ] |
| 2688 | } |
| 2689 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 2690 | bytes.reserve(20); |
| 2691 | self.response_type.serialize_into(bytes); |
| 2692 | bytes.extend_from_slice(&[0; 1]); |
| 2693 | self.sequence.serialize_into(bytes); |
| 2694 | self.window.serialize_into(bytes); |
| 2695 | self.x.serialize_into(bytes); |
| 2696 | self.y.serialize_into(bytes); |
| 2697 | self.width.serialize_into(bytes); |
| 2698 | self.height.serialize_into(bytes); |
| 2699 | self.count.serialize_into(bytes); |
| 2700 | bytes.extend_from_slice(&[0; 2]); |
| 2701 | } |
| 2702 | } |
| 2703 | impl From<&ExposeEvent> for [u8; 32] { |
| 2704 | fn from(input: &ExposeEvent) -> Self { |
| 2705 | let response_type_bytes = input.response_type.serialize(); |
| 2706 | let sequence_bytes = input.sequence.serialize(); |
| 2707 | let window_bytes = input.window.serialize(); |
| 2708 | let x_bytes = input.x.serialize(); |
| 2709 | let y_bytes = input.y.serialize(); |
| 2710 | let width_bytes = input.width.serialize(); |
| 2711 | let height_bytes = input.height.serialize(); |
| 2712 | let count_bytes = input.count.serialize(); |
| 2713 | [ |
| 2714 | response_type_bytes[0], |
| 2715 | 0, |
| 2716 | sequence_bytes[0], |
| 2717 | sequence_bytes[1], |
| 2718 | window_bytes[0], |
| 2719 | window_bytes[1], |
| 2720 | window_bytes[2], |
| 2721 | window_bytes[3], |
| 2722 | x_bytes[0], |
| 2723 | x_bytes[1], |
| 2724 | y_bytes[0], |
| 2725 | y_bytes[1], |
| 2726 | width_bytes[0], |
| 2727 | width_bytes[1], |
| 2728 | height_bytes[0], |
| 2729 | height_bytes[1], |
| 2730 | count_bytes[0], |
| 2731 | count_bytes[1], |
| 2732 | 0, |
| 2733 | 0, |
| 2734 | // trailing padding |
| 2735 | 0, |
| 2736 | 0, |
| 2737 | 0, |
| 2738 | 0, |
| 2739 | 0, |
| 2740 | 0, |
| 2741 | 0, |
| 2742 | 0, |
| 2743 | 0, |
| 2744 | 0, |
| 2745 | 0, |
| 2746 | 0, |
| 2747 | ] |
| 2748 | } |
| 2749 | } |
| 2750 | impl From<ExposeEvent> for [u8; 32] { |
| 2751 | fn from(input: ExposeEvent) -> Self { |
| 2752 | Self::from(&input) |
| 2753 | } |
| 2754 | } |
| 2755 | |
| 2756 | /// Opcode for the GraphicsExposure event |
| 2757 | pub const GRAPHICS_EXPOSURE_EVENT: u8 = 13; |
| 2758 | #[derive (Clone, Copy, Default)] |
| 2759 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 2760 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2761 | pub struct GraphicsExposureEvent { |
| 2762 | pub response_type: u8, |
| 2763 | pub sequence: u16, |
| 2764 | pub drawable: Drawable, |
| 2765 | pub x: u16, |
| 2766 | pub y: u16, |
| 2767 | pub width: u16, |
| 2768 | pub height: u16, |
| 2769 | pub minor_opcode: u16, |
| 2770 | pub count: u16, |
| 2771 | pub major_opcode: u8, |
| 2772 | } |
| 2773 | impl_debug_if_no_extra_traits!(GraphicsExposureEvent, "GraphicsExposureEvent" ); |
| 2774 | impl TryParse for GraphicsExposureEvent { |
| 2775 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 2776 | let remaining: &[u8] = initial_value; |
| 2777 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2778 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 2779 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2780 | let (drawable: u32, remaining: &[u8]) = Drawable::try_parse(remaining)?; |
| 2781 | let (x: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2782 | let (y: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2783 | let (width: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2784 | let (height: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2785 | let (minor_opcode: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2786 | let (count: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2787 | let (major_opcode: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2788 | let remaining: &[u8] = remaining.get(3..).ok_or(err:ParseError::InsufficientData)?; |
| 2789 | let result: GraphicsExposureEvent = GraphicsExposureEvent { response_type, sequence, drawable, x, y, width, height, minor_opcode, count, major_opcode }; |
| 2790 | let _ = remaining; |
| 2791 | let remaining: &[u8] = initial_value.get(32..) |
| 2792 | .ok_or(err:ParseError::InsufficientData)?; |
| 2793 | Ok((result, remaining)) |
| 2794 | } |
| 2795 | } |
| 2796 | impl Serialize for GraphicsExposureEvent { |
| 2797 | type Bytes = [u8; 24]; |
| 2798 | fn serialize(&self) -> [u8; 24] { |
| 2799 | let response_type_bytes = self.response_type.serialize(); |
| 2800 | let sequence_bytes = self.sequence.serialize(); |
| 2801 | let drawable_bytes = self.drawable.serialize(); |
| 2802 | let x_bytes = self.x.serialize(); |
| 2803 | let y_bytes = self.y.serialize(); |
| 2804 | let width_bytes = self.width.serialize(); |
| 2805 | let height_bytes = self.height.serialize(); |
| 2806 | let minor_opcode_bytes = self.minor_opcode.serialize(); |
| 2807 | let count_bytes = self.count.serialize(); |
| 2808 | let major_opcode_bytes = self.major_opcode.serialize(); |
| 2809 | [ |
| 2810 | response_type_bytes[0], |
| 2811 | 0, |
| 2812 | sequence_bytes[0], |
| 2813 | sequence_bytes[1], |
| 2814 | drawable_bytes[0], |
| 2815 | drawable_bytes[1], |
| 2816 | drawable_bytes[2], |
| 2817 | drawable_bytes[3], |
| 2818 | x_bytes[0], |
| 2819 | x_bytes[1], |
| 2820 | y_bytes[0], |
| 2821 | y_bytes[1], |
| 2822 | width_bytes[0], |
| 2823 | width_bytes[1], |
| 2824 | height_bytes[0], |
| 2825 | height_bytes[1], |
| 2826 | minor_opcode_bytes[0], |
| 2827 | minor_opcode_bytes[1], |
| 2828 | count_bytes[0], |
| 2829 | count_bytes[1], |
| 2830 | major_opcode_bytes[0], |
| 2831 | 0, |
| 2832 | 0, |
| 2833 | 0, |
| 2834 | ] |
| 2835 | } |
| 2836 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 2837 | bytes.reserve(24); |
| 2838 | self.response_type.serialize_into(bytes); |
| 2839 | bytes.extend_from_slice(&[0; 1]); |
| 2840 | self.sequence.serialize_into(bytes); |
| 2841 | self.drawable.serialize_into(bytes); |
| 2842 | self.x.serialize_into(bytes); |
| 2843 | self.y.serialize_into(bytes); |
| 2844 | self.width.serialize_into(bytes); |
| 2845 | self.height.serialize_into(bytes); |
| 2846 | self.minor_opcode.serialize_into(bytes); |
| 2847 | self.count.serialize_into(bytes); |
| 2848 | self.major_opcode.serialize_into(bytes); |
| 2849 | bytes.extend_from_slice(&[0; 3]); |
| 2850 | } |
| 2851 | } |
| 2852 | impl From<&GraphicsExposureEvent> for [u8; 32] { |
| 2853 | fn from(input: &GraphicsExposureEvent) -> Self { |
| 2854 | let response_type_bytes = input.response_type.serialize(); |
| 2855 | let sequence_bytes = input.sequence.serialize(); |
| 2856 | let drawable_bytes = input.drawable.serialize(); |
| 2857 | let x_bytes = input.x.serialize(); |
| 2858 | let y_bytes = input.y.serialize(); |
| 2859 | let width_bytes = input.width.serialize(); |
| 2860 | let height_bytes = input.height.serialize(); |
| 2861 | let minor_opcode_bytes = input.minor_opcode.serialize(); |
| 2862 | let count_bytes = input.count.serialize(); |
| 2863 | let major_opcode_bytes = input.major_opcode.serialize(); |
| 2864 | [ |
| 2865 | response_type_bytes[0], |
| 2866 | 0, |
| 2867 | sequence_bytes[0], |
| 2868 | sequence_bytes[1], |
| 2869 | drawable_bytes[0], |
| 2870 | drawable_bytes[1], |
| 2871 | drawable_bytes[2], |
| 2872 | drawable_bytes[3], |
| 2873 | x_bytes[0], |
| 2874 | x_bytes[1], |
| 2875 | y_bytes[0], |
| 2876 | y_bytes[1], |
| 2877 | width_bytes[0], |
| 2878 | width_bytes[1], |
| 2879 | height_bytes[0], |
| 2880 | height_bytes[1], |
| 2881 | minor_opcode_bytes[0], |
| 2882 | minor_opcode_bytes[1], |
| 2883 | count_bytes[0], |
| 2884 | count_bytes[1], |
| 2885 | major_opcode_bytes[0], |
| 2886 | 0, |
| 2887 | 0, |
| 2888 | 0, |
| 2889 | // trailing padding |
| 2890 | 0, |
| 2891 | 0, |
| 2892 | 0, |
| 2893 | 0, |
| 2894 | 0, |
| 2895 | 0, |
| 2896 | 0, |
| 2897 | 0, |
| 2898 | ] |
| 2899 | } |
| 2900 | } |
| 2901 | impl From<GraphicsExposureEvent> for [u8; 32] { |
| 2902 | fn from(input: GraphicsExposureEvent) -> Self { |
| 2903 | Self::from(&input) |
| 2904 | } |
| 2905 | } |
| 2906 | |
| 2907 | /// Opcode for the NoExposure event |
| 2908 | pub const NO_EXPOSURE_EVENT: u8 = 14; |
| 2909 | #[derive (Clone, Copy, Default)] |
| 2910 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 2911 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2912 | pub struct NoExposureEvent { |
| 2913 | pub response_type: u8, |
| 2914 | pub sequence: u16, |
| 2915 | pub drawable: Drawable, |
| 2916 | pub minor_opcode: u16, |
| 2917 | pub major_opcode: u8, |
| 2918 | } |
| 2919 | impl_debug_if_no_extra_traits!(NoExposureEvent, "NoExposureEvent" ); |
| 2920 | impl TryParse for NoExposureEvent { |
| 2921 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 2922 | let remaining: &[u8] = initial_value; |
| 2923 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2924 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 2925 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2926 | let (drawable: u32, remaining: &[u8]) = Drawable::try_parse(remaining)?; |
| 2927 | let (minor_opcode: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2928 | let (major_opcode: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2929 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 2930 | let result: NoExposureEvent = NoExposureEvent { response_type, sequence, drawable, minor_opcode, major_opcode }; |
| 2931 | let _ = remaining; |
| 2932 | let remaining: &[u8] = initial_value.get(32..) |
| 2933 | .ok_or(err:ParseError::InsufficientData)?; |
| 2934 | Ok((result, remaining)) |
| 2935 | } |
| 2936 | } |
| 2937 | impl Serialize for NoExposureEvent { |
| 2938 | type Bytes = [u8; 12]; |
| 2939 | fn serialize(&self) -> [u8; 12] { |
| 2940 | let response_type_bytes = self.response_type.serialize(); |
| 2941 | let sequence_bytes = self.sequence.serialize(); |
| 2942 | let drawable_bytes = self.drawable.serialize(); |
| 2943 | let minor_opcode_bytes = self.minor_opcode.serialize(); |
| 2944 | let major_opcode_bytes = self.major_opcode.serialize(); |
| 2945 | [ |
| 2946 | response_type_bytes[0], |
| 2947 | 0, |
| 2948 | sequence_bytes[0], |
| 2949 | sequence_bytes[1], |
| 2950 | drawable_bytes[0], |
| 2951 | drawable_bytes[1], |
| 2952 | drawable_bytes[2], |
| 2953 | drawable_bytes[3], |
| 2954 | minor_opcode_bytes[0], |
| 2955 | minor_opcode_bytes[1], |
| 2956 | major_opcode_bytes[0], |
| 2957 | 0, |
| 2958 | ] |
| 2959 | } |
| 2960 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 2961 | bytes.reserve(12); |
| 2962 | self.response_type.serialize_into(bytes); |
| 2963 | bytes.extend_from_slice(&[0; 1]); |
| 2964 | self.sequence.serialize_into(bytes); |
| 2965 | self.drawable.serialize_into(bytes); |
| 2966 | self.minor_opcode.serialize_into(bytes); |
| 2967 | self.major_opcode.serialize_into(bytes); |
| 2968 | bytes.extend_from_slice(&[0; 1]); |
| 2969 | } |
| 2970 | } |
| 2971 | impl From<&NoExposureEvent> for [u8; 32] { |
| 2972 | fn from(input: &NoExposureEvent) -> Self { |
| 2973 | let response_type_bytes = input.response_type.serialize(); |
| 2974 | let sequence_bytes = input.sequence.serialize(); |
| 2975 | let drawable_bytes = input.drawable.serialize(); |
| 2976 | let minor_opcode_bytes = input.minor_opcode.serialize(); |
| 2977 | let major_opcode_bytes = input.major_opcode.serialize(); |
| 2978 | [ |
| 2979 | response_type_bytes[0], |
| 2980 | 0, |
| 2981 | sequence_bytes[0], |
| 2982 | sequence_bytes[1], |
| 2983 | drawable_bytes[0], |
| 2984 | drawable_bytes[1], |
| 2985 | drawable_bytes[2], |
| 2986 | drawable_bytes[3], |
| 2987 | minor_opcode_bytes[0], |
| 2988 | minor_opcode_bytes[1], |
| 2989 | major_opcode_bytes[0], |
| 2990 | 0, |
| 2991 | // trailing padding |
| 2992 | 0, |
| 2993 | 0, |
| 2994 | 0, |
| 2995 | 0, |
| 2996 | 0, |
| 2997 | 0, |
| 2998 | 0, |
| 2999 | 0, |
| 3000 | 0, |
| 3001 | 0, |
| 3002 | 0, |
| 3003 | 0, |
| 3004 | 0, |
| 3005 | 0, |
| 3006 | 0, |
| 3007 | 0, |
| 3008 | 0, |
| 3009 | 0, |
| 3010 | 0, |
| 3011 | 0, |
| 3012 | ] |
| 3013 | } |
| 3014 | } |
| 3015 | impl From<NoExposureEvent> for [u8; 32] { |
| 3016 | fn from(input: NoExposureEvent) -> Self { |
| 3017 | Self::from(&input) |
| 3018 | } |
| 3019 | } |
| 3020 | |
| 3021 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 3022 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3023 | pub struct Visibility(u8); |
| 3024 | impl Visibility { |
| 3025 | pub const UNOBSCURED: Self = Self(0); |
| 3026 | pub const PARTIALLY_OBSCURED: Self = Self(1); |
| 3027 | pub const FULLY_OBSCURED: Self = Self(2); |
| 3028 | } |
| 3029 | impl From<Visibility> for u8 { |
| 3030 | #[inline ] |
| 3031 | fn from(input: Visibility) -> Self { |
| 3032 | input.0 |
| 3033 | } |
| 3034 | } |
| 3035 | impl From<Visibility> for Option<u8> { |
| 3036 | #[inline ] |
| 3037 | fn from(input: Visibility) -> Self { |
| 3038 | Some(input.0) |
| 3039 | } |
| 3040 | } |
| 3041 | impl From<Visibility> for u16 { |
| 3042 | #[inline ] |
| 3043 | fn from(input: Visibility) -> Self { |
| 3044 | u16::from(input.0) |
| 3045 | } |
| 3046 | } |
| 3047 | impl From<Visibility> for Option<u16> { |
| 3048 | #[inline ] |
| 3049 | fn from(input: Visibility) -> Self { |
| 3050 | Some(u16::from(input.0)) |
| 3051 | } |
| 3052 | } |
| 3053 | impl From<Visibility> for u32 { |
| 3054 | #[inline ] |
| 3055 | fn from(input: Visibility) -> Self { |
| 3056 | u32::from(input.0) |
| 3057 | } |
| 3058 | } |
| 3059 | impl From<Visibility> for Option<u32> { |
| 3060 | #[inline ] |
| 3061 | fn from(input: Visibility) -> Self { |
| 3062 | Some(u32::from(input.0)) |
| 3063 | } |
| 3064 | } |
| 3065 | impl From<u8> for Visibility { |
| 3066 | #[inline ] |
| 3067 | fn from(value: u8) -> Self { |
| 3068 | Self(value) |
| 3069 | } |
| 3070 | } |
| 3071 | impl core::fmt::Debug for Visibility { |
| 3072 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 3073 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 3074 | (Self::UNOBSCURED.0.into(), "UNOBSCURED" , "Unobscured" ), |
| 3075 | (Self::PARTIALLY_OBSCURED.0.into(), "PARTIALLY_OBSCURED" , "PartiallyObscured" ), |
| 3076 | (Self::FULLY_OBSCURED.0.into(), "FULLY_OBSCURED" , "FullyObscured" ), |
| 3077 | ]; |
| 3078 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 3079 | } |
| 3080 | } |
| 3081 | |
| 3082 | /// Opcode for the VisibilityNotify event |
| 3083 | pub const VISIBILITY_NOTIFY_EVENT: u8 = 15; |
| 3084 | #[derive (Clone, Copy, Default)] |
| 3085 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3086 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3087 | pub struct VisibilityNotifyEvent { |
| 3088 | pub response_type: u8, |
| 3089 | pub sequence: u16, |
| 3090 | pub window: Window, |
| 3091 | pub state: Visibility, |
| 3092 | } |
| 3093 | impl_debug_if_no_extra_traits!(VisibilityNotifyEvent, "VisibilityNotifyEvent" ); |
| 3094 | impl TryParse for VisibilityNotifyEvent { |
| 3095 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3096 | let remaining: &[u8] = initial_value; |
| 3097 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3098 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 3099 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 3100 | let (window: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 3101 | let (state: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3102 | let remaining: &[u8] = remaining.get(3..).ok_or(err:ParseError::InsufficientData)?; |
| 3103 | let state: Visibility = state.into(); |
| 3104 | let result: VisibilityNotifyEvent = VisibilityNotifyEvent { response_type, sequence, window, state }; |
| 3105 | let _ = remaining; |
| 3106 | let remaining: &[u8] = initial_value.get(32..) |
| 3107 | .ok_or(err:ParseError::InsufficientData)?; |
| 3108 | Ok((result, remaining)) |
| 3109 | } |
| 3110 | } |
| 3111 | impl Serialize for VisibilityNotifyEvent { |
| 3112 | type Bytes = [u8; 12]; |
| 3113 | fn serialize(&self) -> [u8; 12] { |
| 3114 | let response_type_bytes = self.response_type.serialize(); |
| 3115 | let sequence_bytes = self.sequence.serialize(); |
| 3116 | let window_bytes = self.window.serialize(); |
| 3117 | let state_bytes = u8::from(self.state).serialize(); |
| 3118 | [ |
| 3119 | response_type_bytes[0], |
| 3120 | 0, |
| 3121 | sequence_bytes[0], |
| 3122 | sequence_bytes[1], |
| 3123 | window_bytes[0], |
| 3124 | window_bytes[1], |
| 3125 | window_bytes[2], |
| 3126 | window_bytes[3], |
| 3127 | state_bytes[0], |
| 3128 | 0, |
| 3129 | 0, |
| 3130 | 0, |
| 3131 | ] |
| 3132 | } |
| 3133 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3134 | bytes.reserve(12); |
| 3135 | self.response_type.serialize_into(bytes); |
| 3136 | bytes.extend_from_slice(&[0; 1]); |
| 3137 | self.sequence.serialize_into(bytes); |
| 3138 | self.window.serialize_into(bytes); |
| 3139 | u8::from(self.state).serialize_into(bytes); |
| 3140 | bytes.extend_from_slice(&[0; 3]); |
| 3141 | } |
| 3142 | } |
| 3143 | impl From<&VisibilityNotifyEvent> for [u8; 32] { |
| 3144 | fn from(input: &VisibilityNotifyEvent) -> Self { |
| 3145 | let response_type_bytes = input.response_type.serialize(); |
| 3146 | let sequence_bytes = input.sequence.serialize(); |
| 3147 | let window_bytes = input.window.serialize(); |
| 3148 | let state_bytes = u8::from(input.state).serialize(); |
| 3149 | [ |
| 3150 | response_type_bytes[0], |
| 3151 | 0, |
| 3152 | sequence_bytes[0], |
| 3153 | sequence_bytes[1], |
| 3154 | window_bytes[0], |
| 3155 | window_bytes[1], |
| 3156 | window_bytes[2], |
| 3157 | window_bytes[3], |
| 3158 | state_bytes[0], |
| 3159 | 0, |
| 3160 | 0, |
| 3161 | 0, |
| 3162 | // trailing padding |
| 3163 | 0, |
| 3164 | 0, |
| 3165 | 0, |
| 3166 | 0, |
| 3167 | 0, |
| 3168 | 0, |
| 3169 | 0, |
| 3170 | 0, |
| 3171 | 0, |
| 3172 | 0, |
| 3173 | 0, |
| 3174 | 0, |
| 3175 | 0, |
| 3176 | 0, |
| 3177 | 0, |
| 3178 | 0, |
| 3179 | 0, |
| 3180 | 0, |
| 3181 | 0, |
| 3182 | 0, |
| 3183 | ] |
| 3184 | } |
| 3185 | } |
| 3186 | impl From<VisibilityNotifyEvent> for [u8; 32] { |
| 3187 | fn from(input: VisibilityNotifyEvent) -> Self { |
| 3188 | Self::from(&input) |
| 3189 | } |
| 3190 | } |
| 3191 | |
| 3192 | /// Opcode for the CreateNotify event |
| 3193 | pub const CREATE_NOTIFY_EVENT: u8 = 16; |
| 3194 | #[derive (Clone, Copy, Default)] |
| 3195 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3196 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3197 | pub struct CreateNotifyEvent { |
| 3198 | pub response_type: u8, |
| 3199 | pub sequence: u16, |
| 3200 | pub parent: Window, |
| 3201 | pub window: Window, |
| 3202 | pub x: i16, |
| 3203 | pub y: i16, |
| 3204 | pub width: u16, |
| 3205 | pub height: u16, |
| 3206 | pub border_width: u16, |
| 3207 | pub override_redirect: bool, |
| 3208 | } |
| 3209 | impl_debug_if_no_extra_traits!(CreateNotifyEvent, "CreateNotifyEvent" ); |
| 3210 | impl TryParse for CreateNotifyEvent { |
| 3211 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3212 | let remaining: &[u8] = initial_value; |
| 3213 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3214 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 3215 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 3216 | let (parent: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 3217 | let (window: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 3218 | let (x: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 3219 | let (y: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 3220 | let (width: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 3221 | let (height: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 3222 | let (border_width: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 3223 | let (override_redirect: bool, remaining: &[u8]) = bool::try_parse(remaining)?; |
| 3224 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 3225 | let result: CreateNotifyEvent = CreateNotifyEvent { response_type, sequence, parent, window, x, y, width, height, border_width, override_redirect }; |
| 3226 | let _ = remaining; |
| 3227 | let remaining: &[u8] = initial_value.get(32..) |
| 3228 | .ok_or(err:ParseError::InsufficientData)?; |
| 3229 | Ok((result, remaining)) |
| 3230 | } |
| 3231 | } |
| 3232 | impl Serialize for CreateNotifyEvent { |
| 3233 | type Bytes = [u8; 24]; |
| 3234 | fn serialize(&self) -> [u8; 24] { |
| 3235 | let response_type_bytes = self.response_type.serialize(); |
| 3236 | let sequence_bytes = self.sequence.serialize(); |
| 3237 | let parent_bytes = self.parent.serialize(); |
| 3238 | let window_bytes = self.window.serialize(); |
| 3239 | let x_bytes = self.x.serialize(); |
| 3240 | let y_bytes = self.y.serialize(); |
| 3241 | let width_bytes = self.width.serialize(); |
| 3242 | let height_bytes = self.height.serialize(); |
| 3243 | let border_width_bytes = self.border_width.serialize(); |
| 3244 | let override_redirect_bytes = self.override_redirect.serialize(); |
| 3245 | [ |
| 3246 | response_type_bytes[0], |
| 3247 | 0, |
| 3248 | sequence_bytes[0], |
| 3249 | sequence_bytes[1], |
| 3250 | parent_bytes[0], |
| 3251 | parent_bytes[1], |
| 3252 | parent_bytes[2], |
| 3253 | parent_bytes[3], |
| 3254 | window_bytes[0], |
| 3255 | window_bytes[1], |
| 3256 | window_bytes[2], |
| 3257 | window_bytes[3], |
| 3258 | x_bytes[0], |
| 3259 | x_bytes[1], |
| 3260 | y_bytes[0], |
| 3261 | y_bytes[1], |
| 3262 | width_bytes[0], |
| 3263 | width_bytes[1], |
| 3264 | height_bytes[0], |
| 3265 | height_bytes[1], |
| 3266 | border_width_bytes[0], |
| 3267 | border_width_bytes[1], |
| 3268 | override_redirect_bytes[0], |
| 3269 | 0, |
| 3270 | ] |
| 3271 | } |
| 3272 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3273 | bytes.reserve(24); |
| 3274 | self.response_type.serialize_into(bytes); |
| 3275 | bytes.extend_from_slice(&[0; 1]); |
| 3276 | self.sequence.serialize_into(bytes); |
| 3277 | self.parent.serialize_into(bytes); |
| 3278 | self.window.serialize_into(bytes); |
| 3279 | self.x.serialize_into(bytes); |
| 3280 | self.y.serialize_into(bytes); |
| 3281 | self.width.serialize_into(bytes); |
| 3282 | self.height.serialize_into(bytes); |
| 3283 | self.border_width.serialize_into(bytes); |
| 3284 | self.override_redirect.serialize_into(bytes); |
| 3285 | bytes.extend_from_slice(&[0; 1]); |
| 3286 | } |
| 3287 | } |
| 3288 | impl From<&CreateNotifyEvent> for [u8; 32] { |
| 3289 | fn from(input: &CreateNotifyEvent) -> Self { |
| 3290 | let response_type_bytes = input.response_type.serialize(); |
| 3291 | let sequence_bytes = input.sequence.serialize(); |
| 3292 | let parent_bytes = input.parent.serialize(); |
| 3293 | let window_bytes = input.window.serialize(); |
| 3294 | let x_bytes = input.x.serialize(); |
| 3295 | let y_bytes = input.y.serialize(); |
| 3296 | let width_bytes = input.width.serialize(); |
| 3297 | let height_bytes = input.height.serialize(); |
| 3298 | let border_width_bytes = input.border_width.serialize(); |
| 3299 | let override_redirect_bytes = input.override_redirect.serialize(); |
| 3300 | [ |
| 3301 | response_type_bytes[0], |
| 3302 | 0, |
| 3303 | sequence_bytes[0], |
| 3304 | sequence_bytes[1], |
| 3305 | parent_bytes[0], |
| 3306 | parent_bytes[1], |
| 3307 | parent_bytes[2], |
| 3308 | parent_bytes[3], |
| 3309 | window_bytes[0], |
| 3310 | window_bytes[1], |
| 3311 | window_bytes[2], |
| 3312 | window_bytes[3], |
| 3313 | x_bytes[0], |
| 3314 | x_bytes[1], |
| 3315 | y_bytes[0], |
| 3316 | y_bytes[1], |
| 3317 | width_bytes[0], |
| 3318 | width_bytes[1], |
| 3319 | height_bytes[0], |
| 3320 | height_bytes[1], |
| 3321 | border_width_bytes[0], |
| 3322 | border_width_bytes[1], |
| 3323 | override_redirect_bytes[0], |
| 3324 | 0, |
| 3325 | // trailing padding |
| 3326 | 0, |
| 3327 | 0, |
| 3328 | 0, |
| 3329 | 0, |
| 3330 | 0, |
| 3331 | 0, |
| 3332 | 0, |
| 3333 | 0, |
| 3334 | ] |
| 3335 | } |
| 3336 | } |
| 3337 | impl From<CreateNotifyEvent> for [u8; 32] { |
| 3338 | fn from(input: CreateNotifyEvent) -> Self { |
| 3339 | Self::from(&input) |
| 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | /// Opcode for the DestroyNotify event |
| 3344 | pub const DESTROY_NOTIFY_EVENT: u8 = 17; |
| 3345 | /// a window is destroyed. |
| 3346 | /// |
| 3347 | /// # Fields |
| 3348 | /// |
| 3349 | /// * `event` - The reconfigured window or its parent, depending on whether `StructureNotify` |
| 3350 | /// or `SubstructureNotify` was selected. |
| 3351 | /// * `window` - The window that is destroyed. |
| 3352 | /// |
| 3353 | /// # See |
| 3354 | /// |
| 3355 | /// * `DestroyWindow`: request |
| 3356 | #[derive (Clone, Copy, Default)] |
| 3357 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3358 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3359 | pub struct DestroyNotifyEvent { |
| 3360 | pub response_type: u8, |
| 3361 | pub sequence: u16, |
| 3362 | pub event: Window, |
| 3363 | pub window: Window, |
| 3364 | } |
| 3365 | impl_debug_if_no_extra_traits!(DestroyNotifyEvent, "DestroyNotifyEvent" ); |
| 3366 | impl TryParse for DestroyNotifyEvent { |
| 3367 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3368 | let remaining: &[u8] = initial_value; |
| 3369 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3370 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 3371 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 3372 | let (event: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 3373 | let (window: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 3374 | let result: DestroyNotifyEvent = DestroyNotifyEvent { response_type, sequence, event, window }; |
| 3375 | let _ = remaining; |
| 3376 | let remaining: &[u8] = initial_value.get(32..) |
| 3377 | .ok_or(err:ParseError::InsufficientData)?; |
| 3378 | Ok((result, remaining)) |
| 3379 | } |
| 3380 | } |
| 3381 | impl Serialize for DestroyNotifyEvent { |
| 3382 | type Bytes = [u8; 12]; |
| 3383 | fn serialize(&self) -> [u8; 12] { |
| 3384 | let response_type_bytes = self.response_type.serialize(); |
| 3385 | let sequence_bytes = self.sequence.serialize(); |
| 3386 | let event_bytes = self.event.serialize(); |
| 3387 | let window_bytes = self.window.serialize(); |
| 3388 | [ |
| 3389 | response_type_bytes[0], |
| 3390 | 0, |
| 3391 | sequence_bytes[0], |
| 3392 | sequence_bytes[1], |
| 3393 | event_bytes[0], |
| 3394 | event_bytes[1], |
| 3395 | event_bytes[2], |
| 3396 | event_bytes[3], |
| 3397 | window_bytes[0], |
| 3398 | window_bytes[1], |
| 3399 | window_bytes[2], |
| 3400 | window_bytes[3], |
| 3401 | ] |
| 3402 | } |
| 3403 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3404 | bytes.reserve(12); |
| 3405 | self.response_type.serialize_into(bytes); |
| 3406 | bytes.extend_from_slice(&[0; 1]); |
| 3407 | self.sequence.serialize_into(bytes); |
| 3408 | self.event.serialize_into(bytes); |
| 3409 | self.window.serialize_into(bytes); |
| 3410 | } |
| 3411 | } |
| 3412 | impl From<&DestroyNotifyEvent> for [u8; 32] { |
| 3413 | fn from(input: &DestroyNotifyEvent) -> Self { |
| 3414 | let response_type_bytes = input.response_type.serialize(); |
| 3415 | let sequence_bytes = input.sequence.serialize(); |
| 3416 | let event_bytes = input.event.serialize(); |
| 3417 | let window_bytes = input.window.serialize(); |
| 3418 | [ |
| 3419 | response_type_bytes[0], |
| 3420 | 0, |
| 3421 | sequence_bytes[0], |
| 3422 | sequence_bytes[1], |
| 3423 | event_bytes[0], |
| 3424 | event_bytes[1], |
| 3425 | event_bytes[2], |
| 3426 | event_bytes[3], |
| 3427 | window_bytes[0], |
| 3428 | window_bytes[1], |
| 3429 | window_bytes[2], |
| 3430 | window_bytes[3], |
| 3431 | // trailing padding |
| 3432 | 0, |
| 3433 | 0, |
| 3434 | 0, |
| 3435 | 0, |
| 3436 | 0, |
| 3437 | 0, |
| 3438 | 0, |
| 3439 | 0, |
| 3440 | 0, |
| 3441 | 0, |
| 3442 | 0, |
| 3443 | 0, |
| 3444 | 0, |
| 3445 | 0, |
| 3446 | 0, |
| 3447 | 0, |
| 3448 | 0, |
| 3449 | 0, |
| 3450 | 0, |
| 3451 | 0, |
| 3452 | ] |
| 3453 | } |
| 3454 | } |
| 3455 | impl From<DestroyNotifyEvent> for [u8; 32] { |
| 3456 | fn from(input: DestroyNotifyEvent) -> Self { |
| 3457 | Self::from(&input) |
| 3458 | } |
| 3459 | } |
| 3460 | |
| 3461 | /// Opcode for the UnmapNotify event |
| 3462 | pub const UNMAP_NOTIFY_EVENT: u8 = 18; |
| 3463 | /// a window is unmapped. |
| 3464 | /// |
| 3465 | /// # Fields |
| 3466 | /// |
| 3467 | /// * `event` - The reconfigured window or its parent, depending on whether `StructureNotify` |
| 3468 | /// or `SubstructureNotify` was selected. |
| 3469 | /// * `window` - The window that was unmapped. |
| 3470 | /// * `from_configure` - Set to 1 if the event was generated as a result of a resizing of the window's |
| 3471 | /// parent when `window` had a win_gravity of `UnmapGravity`. |
| 3472 | /// |
| 3473 | /// # See |
| 3474 | /// |
| 3475 | /// * `UnmapWindow`: request |
| 3476 | #[derive (Clone, Copy, Default)] |
| 3477 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3478 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3479 | pub struct UnmapNotifyEvent { |
| 3480 | pub response_type: u8, |
| 3481 | pub sequence: u16, |
| 3482 | pub event: Window, |
| 3483 | pub window: Window, |
| 3484 | pub from_configure: bool, |
| 3485 | } |
| 3486 | impl_debug_if_no_extra_traits!(UnmapNotifyEvent, "UnmapNotifyEvent" ); |
| 3487 | impl TryParse for UnmapNotifyEvent { |
| 3488 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3489 | let remaining: &[u8] = initial_value; |
| 3490 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3491 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 3492 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 3493 | let (event: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 3494 | let (window: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 3495 | let (from_configure: bool, remaining: &[u8]) = bool::try_parse(remaining)?; |
| 3496 | let remaining: &[u8] = remaining.get(3..).ok_or(err:ParseError::InsufficientData)?; |
| 3497 | let result: UnmapNotifyEvent = UnmapNotifyEvent { response_type, sequence, event, window, from_configure }; |
| 3498 | let _ = remaining; |
| 3499 | let remaining: &[u8] = initial_value.get(32..) |
| 3500 | .ok_or(err:ParseError::InsufficientData)?; |
| 3501 | Ok((result, remaining)) |
| 3502 | } |
| 3503 | } |
| 3504 | impl Serialize for UnmapNotifyEvent { |
| 3505 | type Bytes = [u8; 16]; |
| 3506 | fn serialize(&self) -> [u8; 16] { |
| 3507 | let response_type_bytes = self.response_type.serialize(); |
| 3508 | let sequence_bytes = self.sequence.serialize(); |
| 3509 | let event_bytes = self.event.serialize(); |
| 3510 | let window_bytes = self.window.serialize(); |
| 3511 | let from_configure_bytes = self.from_configure.serialize(); |
| 3512 | [ |
| 3513 | response_type_bytes[0], |
| 3514 | 0, |
| 3515 | sequence_bytes[0], |
| 3516 | sequence_bytes[1], |
| 3517 | event_bytes[0], |
| 3518 | event_bytes[1], |
| 3519 | event_bytes[2], |
| 3520 | event_bytes[3], |
| 3521 | window_bytes[0], |
| 3522 | window_bytes[1], |
| 3523 | window_bytes[2], |
| 3524 | window_bytes[3], |
| 3525 | from_configure_bytes[0], |
| 3526 | 0, |
| 3527 | 0, |
| 3528 | 0, |
| 3529 | ] |
| 3530 | } |
| 3531 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3532 | bytes.reserve(16); |
| 3533 | self.response_type.serialize_into(bytes); |
| 3534 | bytes.extend_from_slice(&[0; 1]); |
| 3535 | self.sequence.serialize_into(bytes); |
| 3536 | self.event.serialize_into(bytes); |
| 3537 | self.window.serialize_into(bytes); |
| 3538 | self.from_configure.serialize_into(bytes); |
| 3539 | bytes.extend_from_slice(&[0; 3]); |
| 3540 | } |
| 3541 | } |
| 3542 | impl From<&UnmapNotifyEvent> for [u8; 32] { |
| 3543 | fn from(input: &UnmapNotifyEvent) -> Self { |
| 3544 | let response_type_bytes = input.response_type.serialize(); |
| 3545 | let sequence_bytes = input.sequence.serialize(); |
| 3546 | let event_bytes = input.event.serialize(); |
| 3547 | let window_bytes = input.window.serialize(); |
| 3548 | let from_configure_bytes = input.from_configure.serialize(); |
| 3549 | [ |
| 3550 | response_type_bytes[0], |
| 3551 | 0, |
| 3552 | sequence_bytes[0], |
| 3553 | sequence_bytes[1], |
| 3554 | event_bytes[0], |
| 3555 | event_bytes[1], |
| 3556 | event_bytes[2], |
| 3557 | event_bytes[3], |
| 3558 | window_bytes[0], |
| 3559 | window_bytes[1], |
| 3560 | window_bytes[2], |
| 3561 | window_bytes[3], |
| 3562 | from_configure_bytes[0], |
| 3563 | 0, |
| 3564 | 0, |
| 3565 | 0, |
| 3566 | // trailing padding |
| 3567 | 0, |
| 3568 | 0, |
| 3569 | 0, |
| 3570 | 0, |
| 3571 | 0, |
| 3572 | 0, |
| 3573 | 0, |
| 3574 | 0, |
| 3575 | 0, |
| 3576 | 0, |
| 3577 | 0, |
| 3578 | 0, |
| 3579 | 0, |
| 3580 | 0, |
| 3581 | 0, |
| 3582 | 0, |
| 3583 | ] |
| 3584 | } |
| 3585 | } |
| 3586 | impl From<UnmapNotifyEvent> for [u8; 32] { |
| 3587 | fn from(input: UnmapNotifyEvent) -> Self { |
| 3588 | Self::from(&input) |
| 3589 | } |
| 3590 | } |
| 3591 | |
| 3592 | /// Opcode for the MapNotify event |
| 3593 | pub const MAP_NOTIFY_EVENT: u8 = 19; |
| 3594 | /// a window was mapped. |
| 3595 | /// |
| 3596 | /// # Fields |
| 3597 | /// |
| 3598 | /// * `event` - The window which was mapped or its parent, depending on whether |
| 3599 | /// `StructureNotify` or `SubstructureNotify` was selected. |
| 3600 | /// * `window` - The window that was mapped. |
| 3601 | /// * `override_redirect` - Window managers should ignore this window if `override_redirect` is 1. |
| 3602 | /// |
| 3603 | /// # See |
| 3604 | /// |
| 3605 | /// * `MapWindow`: request |
| 3606 | #[derive (Clone, Copy, Default)] |
| 3607 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3608 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3609 | pub struct MapNotifyEvent { |
| 3610 | pub response_type: u8, |
| 3611 | pub sequence: u16, |
| 3612 | pub event: Window, |
| 3613 | pub window: Window, |
| 3614 | pub override_redirect: bool, |
| 3615 | } |
| 3616 | impl_debug_if_no_extra_traits!(MapNotifyEvent, "MapNotifyEvent" ); |
| 3617 | impl TryParse for MapNotifyEvent { |
| 3618 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3619 | let remaining: &[u8] = initial_value; |
| 3620 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3621 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 3622 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 3623 | let (event: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 3624 | let (window: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 3625 | let (override_redirect: bool, remaining: &[u8]) = bool::try_parse(remaining)?; |
| 3626 | let remaining: &[u8] = remaining.get(3..).ok_or(err:ParseError::InsufficientData)?; |
| 3627 | let result: MapNotifyEvent = MapNotifyEvent { response_type, sequence, event, window, override_redirect }; |
| 3628 | let _ = remaining; |
| 3629 | let remaining: &[u8] = initial_value.get(32..) |
| 3630 | .ok_or(err:ParseError::InsufficientData)?; |
| 3631 | Ok((result, remaining)) |
| 3632 | } |
| 3633 | } |
| 3634 | impl Serialize for MapNotifyEvent { |
| 3635 | type Bytes = [u8; 16]; |
| 3636 | fn serialize(&self) -> [u8; 16] { |
| 3637 | let response_type_bytes = self.response_type.serialize(); |
| 3638 | let sequence_bytes = self.sequence.serialize(); |
| 3639 | let event_bytes = self.event.serialize(); |
| 3640 | let window_bytes = self.window.serialize(); |
| 3641 | let override_redirect_bytes = self.override_redirect.serialize(); |
| 3642 | [ |
| 3643 | response_type_bytes[0], |
| 3644 | 0, |
| 3645 | sequence_bytes[0], |
| 3646 | sequence_bytes[1], |
| 3647 | event_bytes[0], |
| 3648 | event_bytes[1], |
| 3649 | event_bytes[2], |
| 3650 | event_bytes[3], |
| 3651 | window_bytes[0], |
| 3652 | window_bytes[1], |
| 3653 | window_bytes[2], |
| 3654 | window_bytes[3], |
| 3655 | override_redirect_bytes[0], |
| 3656 | 0, |
| 3657 | 0, |
| 3658 | 0, |
| 3659 | ] |
| 3660 | } |
| 3661 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3662 | bytes.reserve(16); |
| 3663 | self.response_type.serialize_into(bytes); |
| 3664 | bytes.extend_from_slice(&[0; 1]); |
| 3665 | self.sequence.serialize_into(bytes); |
| 3666 | self.event.serialize_into(bytes); |
| 3667 | self.window.serialize_into(bytes); |
| 3668 | self.override_redirect.serialize_into(bytes); |
| 3669 | bytes.extend_from_slice(&[0; 3]); |
| 3670 | } |
| 3671 | } |
| 3672 | impl From<&MapNotifyEvent> for [u8; 32] { |
| 3673 | fn from(input: &MapNotifyEvent) -> Self { |
| 3674 | let response_type_bytes = input.response_type.serialize(); |
| 3675 | let sequence_bytes = input.sequence.serialize(); |
| 3676 | let event_bytes = input.event.serialize(); |
| 3677 | let window_bytes = input.window.serialize(); |
| 3678 | let override_redirect_bytes = input.override_redirect.serialize(); |
| 3679 | [ |
| 3680 | response_type_bytes[0], |
| 3681 | 0, |
| 3682 | sequence_bytes[0], |
| 3683 | sequence_bytes[1], |
| 3684 | event_bytes[0], |
| 3685 | event_bytes[1], |
| 3686 | event_bytes[2], |
| 3687 | event_bytes[3], |
| 3688 | window_bytes[0], |
| 3689 | window_bytes[1], |
| 3690 | window_bytes[2], |
| 3691 | window_bytes[3], |
| 3692 | override_redirect_bytes[0], |
| 3693 | 0, |
| 3694 | 0, |
| 3695 | 0, |
| 3696 | // trailing padding |
| 3697 | 0, |
| 3698 | 0, |
| 3699 | 0, |
| 3700 | 0, |
| 3701 | 0, |
| 3702 | 0, |
| 3703 | 0, |
| 3704 | 0, |
| 3705 | 0, |
| 3706 | 0, |
| 3707 | 0, |
| 3708 | 0, |
| 3709 | 0, |
| 3710 | 0, |
| 3711 | 0, |
| 3712 | 0, |
| 3713 | ] |
| 3714 | } |
| 3715 | } |
| 3716 | impl From<MapNotifyEvent> for [u8; 32] { |
| 3717 | fn from(input: MapNotifyEvent) -> Self { |
| 3718 | Self::from(&input) |
| 3719 | } |
| 3720 | } |
| 3721 | |
| 3722 | /// Opcode for the MapRequest event |
| 3723 | pub const MAP_REQUEST_EVENT: u8 = 20; |
| 3724 | /// window wants to be mapped. |
| 3725 | /// |
| 3726 | /// # Fields |
| 3727 | /// |
| 3728 | /// * `parent` - The parent of `window`. |
| 3729 | /// * `window` - The window to be mapped. |
| 3730 | /// |
| 3731 | /// # See |
| 3732 | /// |
| 3733 | /// * `MapWindow`: request |
| 3734 | #[derive (Clone, Copy, Default)] |
| 3735 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3736 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3737 | pub struct MapRequestEvent { |
| 3738 | pub response_type: u8, |
| 3739 | pub sequence: u16, |
| 3740 | pub parent: Window, |
| 3741 | pub window: Window, |
| 3742 | } |
| 3743 | impl_debug_if_no_extra_traits!(MapRequestEvent, "MapRequestEvent" ); |
| 3744 | impl TryParse for MapRequestEvent { |
| 3745 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3746 | let remaining: &[u8] = initial_value; |
| 3747 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3748 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 3749 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 3750 | let (parent: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 3751 | let (window: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 3752 | let result: MapRequestEvent = MapRequestEvent { response_type, sequence, parent, window }; |
| 3753 | let _ = remaining; |
| 3754 | let remaining: &[u8] = initial_value.get(32..) |
| 3755 | .ok_or(err:ParseError::InsufficientData)?; |
| 3756 | Ok((result, remaining)) |
| 3757 | } |
| 3758 | } |
| 3759 | impl Serialize for MapRequestEvent { |
| 3760 | type Bytes = [u8; 12]; |
| 3761 | fn serialize(&self) -> [u8; 12] { |
| 3762 | let response_type_bytes = self.response_type.serialize(); |
| 3763 | let sequence_bytes = self.sequence.serialize(); |
| 3764 | let parent_bytes = self.parent.serialize(); |
| 3765 | let window_bytes = self.window.serialize(); |
| 3766 | [ |
| 3767 | response_type_bytes[0], |
| 3768 | 0, |
| 3769 | sequence_bytes[0], |
| 3770 | sequence_bytes[1], |
| 3771 | parent_bytes[0], |
| 3772 | parent_bytes[1], |
| 3773 | parent_bytes[2], |
| 3774 | parent_bytes[3], |
| 3775 | window_bytes[0], |
| 3776 | window_bytes[1], |
| 3777 | window_bytes[2], |
| 3778 | window_bytes[3], |
| 3779 | ] |
| 3780 | } |
| 3781 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3782 | bytes.reserve(12); |
| 3783 | self.response_type.serialize_into(bytes); |
| 3784 | bytes.extend_from_slice(&[0; 1]); |
| 3785 | self.sequence.serialize_into(bytes); |
| 3786 | self.parent.serialize_into(bytes); |
| 3787 | self.window.serialize_into(bytes); |
| 3788 | } |
| 3789 | } |
| 3790 | impl From<&MapRequestEvent> for [u8; 32] { |
| 3791 | fn from(input: &MapRequestEvent) -> Self { |
| 3792 | let response_type_bytes = input.response_type.serialize(); |
| 3793 | let sequence_bytes = input.sequence.serialize(); |
| 3794 | let parent_bytes = input.parent.serialize(); |
| 3795 | let window_bytes = input.window.serialize(); |
| 3796 | [ |
| 3797 | response_type_bytes[0], |
| 3798 | 0, |
| 3799 | sequence_bytes[0], |
| 3800 | sequence_bytes[1], |
| 3801 | parent_bytes[0], |
| 3802 | parent_bytes[1], |
| 3803 | parent_bytes[2], |
| 3804 | parent_bytes[3], |
| 3805 | window_bytes[0], |
| 3806 | window_bytes[1], |
| 3807 | window_bytes[2], |
| 3808 | window_bytes[3], |
| 3809 | // trailing padding |
| 3810 | 0, |
| 3811 | 0, |
| 3812 | 0, |
| 3813 | 0, |
| 3814 | 0, |
| 3815 | 0, |
| 3816 | 0, |
| 3817 | 0, |
| 3818 | 0, |
| 3819 | 0, |
| 3820 | 0, |
| 3821 | 0, |
| 3822 | 0, |
| 3823 | 0, |
| 3824 | 0, |
| 3825 | 0, |
| 3826 | 0, |
| 3827 | 0, |
| 3828 | 0, |
| 3829 | 0, |
| 3830 | ] |
| 3831 | } |
| 3832 | } |
| 3833 | impl From<MapRequestEvent> for [u8; 32] { |
| 3834 | fn from(input: MapRequestEvent) -> Self { |
| 3835 | Self::from(&input) |
| 3836 | } |
| 3837 | } |
| 3838 | |
| 3839 | /// Opcode for the ReparentNotify event |
| 3840 | pub const REPARENT_NOTIFY_EVENT: u8 = 21; |
| 3841 | #[derive (Clone, Copy, Default)] |
| 3842 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3843 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3844 | pub struct ReparentNotifyEvent { |
| 3845 | pub response_type: u8, |
| 3846 | pub sequence: u16, |
| 3847 | pub event: Window, |
| 3848 | pub window: Window, |
| 3849 | pub parent: Window, |
| 3850 | pub x: i16, |
| 3851 | pub y: i16, |
| 3852 | pub override_redirect: bool, |
| 3853 | } |
| 3854 | impl_debug_if_no_extra_traits!(ReparentNotifyEvent, "ReparentNotifyEvent" ); |
| 3855 | impl TryParse for ReparentNotifyEvent { |
| 3856 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3857 | let remaining: &[u8] = initial_value; |
| 3858 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3859 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 3860 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 3861 | let (event: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 3862 | let (window: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 3863 | let (parent: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 3864 | let (x: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 3865 | let (y: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 3866 | let (override_redirect: bool, remaining: &[u8]) = bool::try_parse(remaining)?; |
| 3867 | let remaining: &[u8] = remaining.get(3..).ok_or(err:ParseError::InsufficientData)?; |
| 3868 | let result: ReparentNotifyEvent = ReparentNotifyEvent { response_type, sequence, event, window, parent, x, y, override_redirect }; |
| 3869 | let _ = remaining; |
| 3870 | let remaining: &[u8] = initial_value.get(32..) |
| 3871 | .ok_or(err:ParseError::InsufficientData)?; |
| 3872 | Ok((result, remaining)) |
| 3873 | } |
| 3874 | } |
| 3875 | impl Serialize for ReparentNotifyEvent { |
| 3876 | type Bytes = [u8; 24]; |
| 3877 | fn serialize(&self) -> [u8; 24] { |
| 3878 | let response_type_bytes = self.response_type.serialize(); |
| 3879 | let sequence_bytes = self.sequence.serialize(); |
| 3880 | let event_bytes = self.event.serialize(); |
| 3881 | let window_bytes = self.window.serialize(); |
| 3882 | let parent_bytes = self.parent.serialize(); |
| 3883 | let x_bytes = self.x.serialize(); |
| 3884 | let y_bytes = self.y.serialize(); |
| 3885 | let override_redirect_bytes = self.override_redirect.serialize(); |
| 3886 | [ |
| 3887 | response_type_bytes[0], |
| 3888 | 0, |
| 3889 | sequence_bytes[0], |
| 3890 | sequence_bytes[1], |
| 3891 | event_bytes[0], |
| 3892 | event_bytes[1], |
| 3893 | event_bytes[2], |
| 3894 | event_bytes[3], |
| 3895 | window_bytes[0], |
| 3896 | window_bytes[1], |
| 3897 | window_bytes[2], |
| 3898 | window_bytes[3], |
| 3899 | parent_bytes[0], |
| 3900 | parent_bytes[1], |
| 3901 | parent_bytes[2], |
| 3902 | parent_bytes[3], |
| 3903 | x_bytes[0], |
| 3904 | x_bytes[1], |
| 3905 | y_bytes[0], |
| 3906 | y_bytes[1], |
| 3907 | override_redirect_bytes[0], |
| 3908 | 0, |
| 3909 | 0, |
| 3910 | 0, |
| 3911 | ] |
| 3912 | } |
| 3913 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3914 | bytes.reserve(24); |
| 3915 | self.response_type.serialize_into(bytes); |
| 3916 | bytes.extend_from_slice(&[0; 1]); |
| 3917 | self.sequence.serialize_into(bytes); |
| 3918 | self.event.serialize_into(bytes); |
| 3919 | self.window.serialize_into(bytes); |
| 3920 | self.parent.serialize_into(bytes); |
| 3921 | self.x.serialize_into(bytes); |
| 3922 | self.y.serialize_into(bytes); |
| 3923 | self.override_redirect.serialize_into(bytes); |
| 3924 | bytes.extend_from_slice(&[0; 3]); |
| 3925 | } |
| 3926 | } |
| 3927 | impl From<&ReparentNotifyEvent> for [u8; 32] { |
| 3928 | fn from(input: &ReparentNotifyEvent) -> Self { |
| 3929 | let response_type_bytes = input.response_type.serialize(); |
| 3930 | let sequence_bytes = input.sequence.serialize(); |
| 3931 | let event_bytes = input.event.serialize(); |
| 3932 | let window_bytes = input.window.serialize(); |
| 3933 | let parent_bytes = input.parent.serialize(); |
| 3934 | let x_bytes = input.x.serialize(); |
| 3935 | let y_bytes = input.y.serialize(); |
| 3936 | let override_redirect_bytes = input.override_redirect.serialize(); |
| 3937 | [ |
| 3938 | response_type_bytes[0], |
| 3939 | 0, |
| 3940 | sequence_bytes[0], |
| 3941 | sequence_bytes[1], |
| 3942 | event_bytes[0], |
| 3943 | event_bytes[1], |
| 3944 | event_bytes[2], |
| 3945 | event_bytes[3], |
| 3946 | window_bytes[0], |
| 3947 | window_bytes[1], |
| 3948 | window_bytes[2], |
| 3949 | window_bytes[3], |
| 3950 | parent_bytes[0], |
| 3951 | parent_bytes[1], |
| 3952 | parent_bytes[2], |
| 3953 | parent_bytes[3], |
| 3954 | x_bytes[0], |
| 3955 | x_bytes[1], |
| 3956 | y_bytes[0], |
| 3957 | y_bytes[1], |
| 3958 | override_redirect_bytes[0], |
| 3959 | 0, |
| 3960 | 0, |
| 3961 | 0, |
| 3962 | // trailing padding |
| 3963 | 0, |
| 3964 | 0, |
| 3965 | 0, |
| 3966 | 0, |
| 3967 | 0, |
| 3968 | 0, |
| 3969 | 0, |
| 3970 | 0, |
| 3971 | ] |
| 3972 | } |
| 3973 | } |
| 3974 | impl From<ReparentNotifyEvent> for [u8; 32] { |
| 3975 | fn from(input: ReparentNotifyEvent) -> Self { |
| 3976 | Self::from(&input) |
| 3977 | } |
| 3978 | } |
| 3979 | |
| 3980 | /// Opcode for the ConfigureNotify event |
| 3981 | pub const CONFIGURE_NOTIFY_EVENT: u8 = 22; |
| 3982 | /// NOT YET DOCUMENTED. |
| 3983 | /// |
| 3984 | /// # Fields |
| 3985 | /// |
| 3986 | /// * `event` - The reconfigured window or its parent, depending on whether `StructureNotify` |
| 3987 | /// or `SubstructureNotify` was selected. |
| 3988 | /// * `window` - The window whose size, position, border, and/or stacking order was changed. |
| 3989 | /// * `above_sibling` - If `XCB_NONE`, the `window` is on the bottom of the stack with respect to |
| 3990 | /// sibling windows. However, if set to a sibling window, the `window` is placed on |
| 3991 | /// top of this sibling window. |
| 3992 | /// * `x` - The X coordinate of the upper-left outside corner of `window`, relative to the |
| 3993 | /// parent window's origin. |
| 3994 | /// * `y` - The Y coordinate of the upper-left outside corner of `window`, relative to the |
| 3995 | /// parent window's origin. |
| 3996 | /// * `width` - The inside width of `window`, not including the border. |
| 3997 | /// * `height` - The inside height of `window`, not including the border. |
| 3998 | /// * `border_width` - The border width of `window`. |
| 3999 | /// * `override_redirect` - Window managers should ignore this window if `override_redirect` is 1. |
| 4000 | /// |
| 4001 | /// # See |
| 4002 | /// |
| 4003 | /// * `FreeColormap`: request |
| 4004 | #[derive (Clone, Copy, Default)] |
| 4005 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 4006 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4007 | pub struct ConfigureNotifyEvent { |
| 4008 | pub response_type: u8, |
| 4009 | pub sequence: u16, |
| 4010 | pub event: Window, |
| 4011 | pub window: Window, |
| 4012 | pub above_sibling: Window, |
| 4013 | pub x: i16, |
| 4014 | pub y: i16, |
| 4015 | pub width: u16, |
| 4016 | pub height: u16, |
| 4017 | pub border_width: u16, |
| 4018 | pub override_redirect: bool, |
| 4019 | } |
| 4020 | impl_debug_if_no_extra_traits!(ConfigureNotifyEvent, "ConfigureNotifyEvent" ); |
| 4021 | impl TryParse for ConfigureNotifyEvent { |
| 4022 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 4023 | let remaining: &[u8] = initial_value; |
| 4024 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4025 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 4026 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 4027 | let (event: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 4028 | let (window: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 4029 | let (above_sibling: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 4030 | let (x: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 4031 | let (y: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 4032 | let (width: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 4033 | let (height: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 4034 | let (border_width: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 4035 | let (override_redirect: bool, remaining: &[u8]) = bool::try_parse(remaining)?; |
| 4036 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 4037 | let result: ConfigureNotifyEvent = ConfigureNotifyEvent { response_type, sequence, event, window, above_sibling, x, y, width, height, border_width, override_redirect }; |
| 4038 | let _ = remaining; |
| 4039 | let remaining: &[u8] = initial_value.get(32..) |
| 4040 | .ok_or(err:ParseError::InsufficientData)?; |
| 4041 | Ok((result, remaining)) |
| 4042 | } |
| 4043 | } |
| 4044 | impl Serialize for ConfigureNotifyEvent { |
| 4045 | type Bytes = [u8; 28]; |
| 4046 | fn serialize(&self) -> [u8; 28] { |
| 4047 | let response_type_bytes = self.response_type.serialize(); |
| 4048 | let sequence_bytes = self.sequence.serialize(); |
| 4049 | let event_bytes = self.event.serialize(); |
| 4050 | let window_bytes = self.window.serialize(); |
| 4051 | let above_sibling_bytes = self.above_sibling.serialize(); |
| 4052 | let x_bytes = self.x.serialize(); |
| 4053 | let y_bytes = self.y.serialize(); |
| 4054 | let width_bytes = self.width.serialize(); |
| 4055 | let height_bytes = self.height.serialize(); |
| 4056 | let border_width_bytes = self.border_width.serialize(); |
| 4057 | let override_redirect_bytes = self.override_redirect.serialize(); |
| 4058 | [ |
| 4059 | response_type_bytes[0], |
| 4060 | 0, |
| 4061 | sequence_bytes[0], |
| 4062 | sequence_bytes[1], |
| 4063 | event_bytes[0], |
| 4064 | event_bytes[1], |
| 4065 | event_bytes[2], |
| 4066 | event_bytes[3], |
| 4067 | window_bytes[0], |
| 4068 | window_bytes[1], |
| 4069 | window_bytes[2], |
| 4070 | window_bytes[3], |
| 4071 | above_sibling_bytes[0], |
| 4072 | above_sibling_bytes[1], |
| 4073 | above_sibling_bytes[2], |
| 4074 | above_sibling_bytes[3], |
| 4075 | x_bytes[0], |
| 4076 | x_bytes[1], |
| 4077 | y_bytes[0], |
| 4078 | y_bytes[1], |
| 4079 | width_bytes[0], |
| 4080 | width_bytes[1], |
| 4081 | height_bytes[0], |
| 4082 | height_bytes[1], |
| 4083 | border_width_bytes[0], |
| 4084 | border_width_bytes[1], |
| 4085 | override_redirect_bytes[0], |
| 4086 | 0, |
| 4087 | ] |
| 4088 | } |
| 4089 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 4090 | bytes.reserve(28); |
| 4091 | self.response_type.serialize_into(bytes); |
| 4092 | bytes.extend_from_slice(&[0; 1]); |
| 4093 | self.sequence.serialize_into(bytes); |
| 4094 | self.event.serialize_into(bytes); |
| 4095 | self.window.serialize_into(bytes); |
| 4096 | self.above_sibling.serialize_into(bytes); |
| 4097 | self.x.serialize_into(bytes); |
| 4098 | self.y.serialize_into(bytes); |
| 4099 | self.width.serialize_into(bytes); |
| 4100 | self.height.serialize_into(bytes); |
| 4101 | self.border_width.serialize_into(bytes); |
| 4102 | self.override_redirect.serialize_into(bytes); |
| 4103 | bytes.extend_from_slice(&[0; 1]); |
| 4104 | } |
| 4105 | } |
| 4106 | impl From<&ConfigureNotifyEvent> for [u8; 32] { |
| 4107 | fn from(input: &ConfigureNotifyEvent) -> Self { |
| 4108 | let response_type_bytes = input.response_type.serialize(); |
| 4109 | let sequence_bytes = input.sequence.serialize(); |
| 4110 | let event_bytes = input.event.serialize(); |
| 4111 | let window_bytes = input.window.serialize(); |
| 4112 | let above_sibling_bytes = input.above_sibling.serialize(); |
| 4113 | let x_bytes = input.x.serialize(); |
| 4114 | let y_bytes = input.y.serialize(); |
| 4115 | let width_bytes = input.width.serialize(); |
| 4116 | let height_bytes = input.height.serialize(); |
| 4117 | let border_width_bytes = input.border_width.serialize(); |
| 4118 | let override_redirect_bytes = input.override_redirect.serialize(); |
| 4119 | [ |
| 4120 | response_type_bytes[0], |
| 4121 | 0, |
| 4122 | sequence_bytes[0], |
| 4123 | sequence_bytes[1], |
| 4124 | event_bytes[0], |
| 4125 | event_bytes[1], |
| 4126 | event_bytes[2], |
| 4127 | event_bytes[3], |
| 4128 | window_bytes[0], |
| 4129 | window_bytes[1], |
| 4130 | window_bytes[2], |
| 4131 | window_bytes[3], |
| 4132 | above_sibling_bytes[0], |
| 4133 | above_sibling_bytes[1], |
| 4134 | above_sibling_bytes[2], |
| 4135 | above_sibling_bytes[3], |
| 4136 | x_bytes[0], |
| 4137 | x_bytes[1], |
| 4138 | y_bytes[0], |
| 4139 | y_bytes[1], |
| 4140 | width_bytes[0], |
| 4141 | width_bytes[1], |
| 4142 | height_bytes[0], |
| 4143 | height_bytes[1], |
| 4144 | border_width_bytes[0], |
| 4145 | border_width_bytes[1], |
| 4146 | override_redirect_bytes[0], |
| 4147 | 0, |
| 4148 | // trailing padding |
| 4149 | 0, |
| 4150 | 0, |
| 4151 | 0, |
| 4152 | 0, |
| 4153 | ] |
| 4154 | } |
| 4155 | } |
| 4156 | impl From<ConfigureNotifyEvent> for [u8; 32] { |
| 4157 | fn from(input: ConfigureNotifyEvent) -> Self { |
| 4158 | Self::from(&input) |
| 4159 | } |
| 4160 | } |
| 4161 | |
| 4162 | /// Opcode for the ConfigureRequest event |
| 4163 | pub const CONFIGURE_REQUEST_EVENT: u8 = 23; |
| 4164 | #[derive (Clone, Copy, Default)] |
| 4165 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 4166 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4167 | pub struct ConfigureRequestEvent { |
| 4168 | pub response_type: u8, |
| 4169 | pub stack_mode: StackMode, |
| 4170 | pub sequence: u16, |
| 4171 | pub parent: Window, |
| 4172 | pub window: Window, |
| 4173 | pub sibling: Window, |
| 4174 | pub x: i16, |
| 4175 | pub y: i16, |
| 4176 | pub width: u16, |
| 4177 | pub height: u16, |
| 4178 | pub border_width: u16, |
| 4179 | pub value_mask: ConfigWindow, |
| 4180 | } |
| 4181 | impl_debug_if_no_extra_traits!(ConfigureRequestEvent, "ConfigureRequestEvent" ); |
| 4182 | impl TryParse for ConfigureRequestEvent { |
| 4183 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 4184 | let remaining: &[u8] = initial_value; |
| 4185 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4186 | let (stack_mode: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4187 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 4188 | let (parent: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 4189 | let (window: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 4190 | let (sibling: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 4191 | let (x: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 4192 | let (y: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 4193 | let (width: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 4194 | let (height: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 4195 | let (border_width: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 4196 | let (value_mask: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 4197 | let stack_mode: StackMode = stack_mode.into(); |
| 4198 | let value_mask: ConfigWindow = value_mask.into(); |
| 4199 | let result: ConfigureRequestEvent = ConfigureRequestEvent { response_type, stack_mode, sequence, parent, window, sibling, x, y, width, height, border_width, value_mask }; |
| 4200 | let _ = remaining; |
| 4201 | let remaining: &[u8] = initial_value.get(32..) |
| 4202 | .ok_or(err:ParseError::InsufficientData)?; |
| 4203 | Ok((result, remaining)) |
| 4204 | } |
| 4205 | } |
| 4206 | impl Serialize for ConfigureRequestEvent { |
| 4207 | type Bytes = [u8; 28]; |
| 4208 | fn serialize(&self) -> [u8; 28] { |
| 4209 | let response_type_bytes = self.response_type.serialize(); |
| 4210 | let stack_mode_bytes = (u32::from(self.stack_mode) as u8).serialize(); |
| 4211 | let sequence_bytes = self.sequence.serialize(); |
| 4212 | let parent_bytes = self.parent.serialize(); |
| 4213 | let window_bytes = self.window.serialize(); |
| 4214 | let sibling_bytes = self.sibling.serialize(); |
| 4215 | let x_bytes = self.x.serialize(); |
| 4216 | let y_bytes = self.y.serialize(); |
| 4217 | let width_bytes = self.width.serialize(); |
| 4218 | let height_bytes = self.height.serialize(); |
| 4219 | let border_width_bytes = self.border_width.serialize(); |
| 4220 | let value_mask_bytes = u16::from(self.value_mask).serialize(); |
| 4221 | [ |
| 4222 | response_type_bytes[0], |
| 4223 | stack_mode_bytes[0], |
| 4224 | sequence_bytes[0], |
| 4225 | sequence_bytes[1], |
| 4226 | parent_bytes[0], |
| 4227 | parent_bytes[1], |
| 4228 | parent_bytes[2], |
| 4229 | parent_bytes[3], |
| 4230 | window_bytes[0], |
| 4231 | window_bytes[1], |
| 4232 | window_bytes[2], |
| 4233 | window_bytes[3], |
| 4234 | sibling_bytes[0], |
| 4235 | sibling_bytes[1], |
| 4236 | sibling_bytes[2], |
| 4237 | sibling_bytes[3], |
| 4238 | x_bytes[0], |
| 4239 | x_bytes[1], |
| 4240 | y_bytes[0], |
| 4241 | y_bytes[1], |
| 4242 | width_bytes[0], |
| 4243 | width_bytes[1], |
| 4244 | height_bytes[0], |
| 4245 | height_bytes[1], |
| 4246 | border_width_bytes[0], |
| 4247 | border_width_bytes[1], |
| 4248 | value_mask_bytes[0], |
| 4249 | value_mask_bytes[1], |
| 4250 | ] |
| 4251 | } |
| 4252 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 4253 | bytes.reserve(28); |
| 4254 | self.response_type.serialize_into(bytes); |
| 4255 | (u32::from(self.stack_mode) as u8).serialize_into(bytes); |
| 4256 | self.sequence.serialize_into(bytes); |
| 4257 | self.parent.serialize_into(bytes); |
| 4258 | self.window.serialize_into(bytes); |
| 4259 | self.sibling.serialize_into(bytes); |
| 4260 | self.x.serialize_into(bytes); |
| 4261 | self.y.serialize_into(bytes); |
| 4262 | self.width.serialize_into(bytes); |
| 4263 | self.height.serialize_into(bytes); |
| 4264 | self.border_width.serialize_into(bytes); |
| 4265 | u16::from(self.value_mask).serialize_into(bytes); |
| 4266 | } |
| 4267 | } |
| 4268 | impl From<&ConfigureRequestEvent> for [u8; 32] { |
| 4269 | fn from(input: &ConfigureRequestEvent) -> Self { |
| 4270 | let response_type_bytes = input.response_type.serialize(); |
| 4271 | let stack_mode_bytes = (u32::from(input.stack_mode) as u8).serialize(); |
| 4272 | let sequence_bytes = input.sequence.serialize(); |
| 4273 | let parent_bytes = input.parent.serialize(); |
| 4274 | let window_bytes = input.window.serialize(); |
| 4275 | let sibling_bytes = input.sibling.serialize(); |
| 4276 | let x_bytes = input.x.serialize(); |
| 4277 | let y_bytes = input.y.serialize(); |
| 4278 | let width_bytes = input.width.serialize(); |
| 4279 | let height_bytes = input.height.serialize(); |
| 4280 | let border_width_bytes = input.border_width.serialize(); |
| 4281 | let value_mask_bytes = u16::from(input.value_mask).serialize(); |
| 4282 | [ |
| 4283 | response_type_bytes[0], |
| 4284 | stack_mode_bytes[0], |
| 4285 | sequence_bytes[0], |
| 4286 | sequence_bytes[1], |
| 4287 | parent_bytes[0], |
| 4288 | parent_bytes[1], |
| 4289 | parent_bytes[2], |
| 4290 | parent_bytes[3], |
| 4291 | window_bytes[0], |
| 4292 | window_bytes[1], |
| 4293 | window_bytes[2], |
| 4294 | window_bytes[3], |
| 4295 | sibling_bytes[0], |
| 4296 | sibling_bytes[1], |
| 4297 | sibling_bytes[2], |
| 4298 | sibling_bytes[3], |
| 4299 | x_bytes[0], |
| 4300 | x_bytes[1], |
| 4301 | y_bytes[0], |
| 4302 | y_bytes[1], |
| 4303 | width_bytes[0], |
| 4304 | width_bytes[1], |
| 4305 | height_bytes[0], |
| 4306 | height_bytes[1], |
| 4307 | border_width_bytes[0], |
| 4308 | border_width_bytes[1], |
| 4309 | value_mask_bytes[0], |
| 4310 | value_mask_bytes[1], |
| 4311 | // trailing padding |
| 4312 | 0, |
| 4313 | 0, |
| 4314 | 0, |
| 4315 | 0, |
| 4316 | ] |
| 4317 | } |
| 4318 | } |
| 4319 | impl From<ConfigureRequestEvent> for [u8; 32] { |
| 4320 | fn from(input: ConfigureRequestEvent) -> Self { |
| 4321 | Self::from(&input) |
| 4322 | } |
| 4323 | } |
| 4324 | |
| 4325 | /// Opcode for the GravityNotify event |
| 4326 | pub const GRAVITY_NOTIFY_EVENT: u8 = 24; |
| 4327 | #[derive (Clone, Copy, Default)] |
| 4328 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 4329 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4330 | pub struct GravityNotifyEvent { |
| 4331 | pub response_type: u8, |
| 4332 | pub sequence: u16, |
| 4333 | pub event: Window, |
| 4334 | pub window: Window, |
| 4335 | pub x: i16, |
| 4336 | pub y: i16, |
| 4337 | } |
| 4338 | impl_debug_if_no_extra_traits!(GravityNotifyEvent, "GravityNotifyEvent" ); |
| 4339 | impl TryParse for GravityNotifyEvent { |
| 4340 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 4341 | let remaining: &[u8] = initial_value; |
| 4342 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4343 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 4344 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 4345 | let (event: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 4346 | let (window: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 4347 | let (x: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 4348 | let (y: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 4349 | let result: GravityNotifyEvent = GravityNotifyEvent { response_type, sequence, event, window, x, y }; |
| 4350 | let _ = remaining; |
| 4351 | let remaining: &[u8] = initial_value.get(32..) |
| 4352 | .ok_or(err:ParseError::InsufficientData)?; |
| 4353 | Ok((result, remaining)) |
| 4354 | } |
| 4355 | } |
| 4356 | impl Serialize for GravityNotifyEvent { |
| 4357 | type Bytes = [u8; 16]; |
| 4358 | fn serialize(&self) -> [u8; 16] { |
| 4359 | let response_type_bytes = self.response_type.serialize(); |
| 4360 | let sequence_bytes = self.sequence.serialize(); |
| 4361 | let event_bytes = self.event.serialize(); |
| 4362 | let window_bytes = self.window.serialize(); |
| 4363 | let x_bytes = self.x.serialize(); |
| 4364 | let y_bytes = self.y.serialize(); |
| 4365 | [ |
| 4366 | response_type_bytes[0], |
| 4367 | 0, |
| 4368 | sequence_bytes[0], |
| 4369 | sequence_bytes[1], |
| 4370 | event_bytes[0], |
| 4371 | event_bytes[1], |
| 4372 | event_bytes[2], |
| 4373 | event_bytes[3], |
| 4374 | window_bytes[0], |
| 4375 | window_bytes[1], |
| 4376 | window_bytes[2], |
| 4377 | window_bytes[3], |
| 4378 | x_bytes[0], |
| 4379 | x_bytes[1], |
| 4380 | y_bytes[0], |
| 4381 | y_bytes[1], |
| 4382 | ] |
| 4383 | } |
| 4384 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 4385 | bytes.reserve(16); |
| 4386 | self.response_type.serialize_into(bytes); |
| 4387 | bytes.extend_from_slice(&[0; 1]); |
| 4388 | self.sequence.serialize_into(bytes); |
| 4389 | self.event.serialize_into(bytes); |
| 4390 | self.window.serialize_into(bytes); |
| 4391 | self.x.serialize_into(bytes); |
| 4392 | self.y.serialize_into(bytes); |
| 4393 | } |
| 4394 | } |
| 4395 | impl From<&GravityNotifyEvent> for [u8; 32] { |
| 4396 | fn from(input: &GravityNotifyEvent) -> Self { |
| 4397 | let response_type_bytes = input.response_type.serialize(); |
| 4398 | let sequence_bytes = input.sequence.serialize(); |
| 4399 | let event_bytes = input.event.serialize(); |
| 4400 | let window_bytes = input.window.serialize(); |
| 4401 | let x_bytes = input.x.serialize(); |
| 4402 | let y_bytes = input.y.serialize(); |
| 4403 | [ |
| 4404 | response_type_bytes[0], |
| 4405 | 0, |
| 4406 | sequence_bytes[0], |
| 4407 | sequence_bytes[1], |
| 4408 | event_bytes[0], |
| 4409 | event_bytes[1], |
| 4410 | event_bytes[2], |
| 4411 | event_bytes[3], |
| 4412 | window_bytes[0], |
| 4413 | window_bytes[1], |
| 4414 | window_bytes[2], |
| 4415 | window_bytes[3], |
| 4416 | x_bytes[0], |
| 4417 | x_bytes[1], |
| 4418 | y_bytes[0], |
| 4419 | y_bytes[1], |
| 4420 | // trailing padding |
| 4421 | 0, |
| 4422 | 0, |
| 4423 | 0, |
| 4424 | 0, |
| 4425 | 0, |
| 4426 | 0, |
| 4427 | 0, |
| 4428 | 0, |
| 4429 | 0, |
| 4430 | 0, |
| 4431 | 0, |
| 4432 | 0, |
| 4433 | 0, |
| 4434 | 0, |
| 4435 | 0, |
| 4436 | 0, |
| 4437 | ] |
| 4438 | } |
| 4439 | } |
| 4440 | impl From<GravityNotifyEvent> for [u8; 32] { |
| 4441 | fn from(input: GravityNotifyEvent) -> Self { |
| 4442 | Self::from(&input) |
| 4443 | } |
| 4444 | } |
| 4445 | |
| 4446 | /// Opcode for the ResizeRequest event |
| 4447 | pub const RESIZE_REQUEST_EVENT: u8 = 25; |
| 4448 | #[derive (Clone, Copy, Default)] |
| 4449 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 4450 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4451 | pub struct ResizeRequestEvent { |
| 4452 | pub response_type: u8, |
| 4453 | pub sequence: u16, |
| 4454 | pub window: Window, |
| 4455 | pub width: u16, |
| 4456 | pub height: u16, |
| 4457 | } |
| 4458 | impl_debug_if_no_extra_traits!(ResizeRequestEvent, "ResizeRequestEvent" ); |
| 4459 | impl TryParse for ResizeRequestEvent { |
| 4460 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 4461 | let remaining: &[u8] = initial_value; |
| 4462 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4463 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 4464 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 4465 | let (window: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 4466 | let (width: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 4467 | let (height: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 4468 | let result: ResizeRequestEvent = ResizeRequestEvent { response_type, sequence, window, width, height }; |
| 4469 | let _ = remaining; |
| 4470 | let remaining: &[u8] = initial_value.get(32..) |
| 4471 | .ok_or(err:ParseError::InsufficientData)?; |
| 4472 | Ok((result, remaining)) |
| 4473 | } |
| 4474 | } |
| 4475 | impl Serialize for ResizeRequestEvent { |
| 4476 | type Bytes = [u8; 12]; |
| 4477 | fn serialize(&self) -> [u8; 12] { |
| 4478 | let response_type_bytes = self.response_type.serialize(); |
| 4479 | let sequence_bytes = self.sequence.serialize(); |
| 4480 | let window_bytes = self.window.serialize(); |
| 4481 | let width_bytes = self.width.serialize(); |
| 4482 | let height_bytes = self.height.serialize(); |
| 4483 | [ |
| 4484 | response_type_bytes[0], |
| 4485 | 0, |
| 4486 | sequence_bytes[0], |
| 4487 | sequence_bytes[1], |
| 4488 | window_bytes[0], |
| 4489 | window_bytes[1], |
| 4490 | window_bytes[2], |
| 4491 | window_bytes[3], |
| 4492 | width_bytes[0], |
| 4493 | width_bytes[1], |
| 4494 | height_bytes[0], |
| 4495 | height_bytes[1], |
| 4496 | ] |
| 4497 | } |
| 4498 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 4499 | bytes.reserve(12); |
| 4500 | self.response_type.serialize_into(bytes); |
| 4501 | bytes.extend_from_slice(&[0; 1]); |
| 4502 | self.sequence.serialize_into(bytes); |
| 4503 | self.window.serialize_into(bytes); |
| 4504 | self.width.serialize_into(bytes); |
| 4505 | self.height.serialize_into(bytes); |
| 4506 | } |
| 4507 | } |
| 4508 | impl From<&ResizeRequestEvent> for [u8; 32] { |
| 4509 | fn from(input: &ResizeRequestEvent) -> Self { |
| 4510 | let response_type_bytes = input.response_type.serialize(); |
| 4511 | let sequence_bytes = input.sequence.serialize(); |
| 4512 | let window_bytes = input.window.serialize(); |
| 4513 | let width_bytes = input.width.serialize(); |
| 4514 | let height_bytes = input.height.serialize(); |
| 4515 | [ |
| 4516 | response_type_bytes[0], |
| 4517 | 0, |
| 4518 | sequence_bytes[0], |
| 4519 | sequence_bytes[1], |
| 4520 | window_bytes[0], |
| 4521 | window_bytes[1], |
| 4522 | window_bytes[2], |
| 4523 | window_bytes[3], |
| 4524 | width_bytes[0], |
| 4525 | width_bytes[1], |
| 4526 | height_bytes[0], |
| 4527 | height_bytes[1], |
| 4528 | // trailing padding |
| 4529 | 0, |
| 4530 | 0, |
| 4531 | 0, |
| 4532 | 0, |
| 4533 | 0, |
| 4534 | 0, |
| 4535 | 0, |
| 4536 | 0, |
| 4537 | 0, |
| 4538 | 0, |
| 4539 | 0, |
| 4540 | 0, |
| 4541 | 0, |
| 4542 | 0, |
| 4543 | 0, |
| 4544 | 0, |
| 4545 | 0, |
| 4546 | 0, |
| 4547 | 0, |
| 4548 | 0, |
| 4549 | ] |
| 4550 | } |
| 4551 | } |
| 4552 | impl From<ResizeRequestEvent> for [u8; 32] { |
| 4553 | fn from(input: ResizeRequestEvent) -> Self { |
| 4554 | Self::from(&input) |
| 4555 | } |
| 4556 | } |
| 4557 | |
| 4558 | /// # Fields |
| 4559 | /// |
| 4560 | /// * `OnTop` - The window is now on top of all siblings. |
| 4561 | /// * `OnBottom` - The window is now below all siblings. |
| 4562 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 4563 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4564 | pub struct Place(u8); |
| 4565 | impl Place { |
| 4566 | pub const ON_TOP: Self = Self(0); |
| 4567 | pub const ON_BOTTOM: Self = Self(1); |
| 4568 | } |
| 4569 | impl From<Place> for u8 { |
| 4570 | #[inline ] |
| 4571 | fn from(input: Place) -> Self { |
| 4572 | input.0 |
| 4573 | } |
| 4574 | } |
| 4575 | impl From<Place> for Option<u8> { |
| 4576 | #[inline ] |
| 4577 | fn from(input: Place) -> Self { |
| 4578 | Some(input.0) |
| 4579 | } |
| 4580 | } |
| 4581 | impl From<Place> for u16 { |
| 4582 | #[inline ] |
| 4583 | fn from(input: Place) -> Self { |
| 4584 | u16::from(input.0) |
| 4585 | } |
| 4586 | } |
| 4587 | impl From<Place> for Option<u16> { |
| 4588 | #[inline ] |
| 4589 | fn from(input: Place) -> Self { |
| 4590 | Some(u16::from(input.0)) |
| 4591 | } |
| 4592 | } |
| 4593 | impl From<Place> for u32 { |
| 4594 | #[inline ] |
| 4595 | fn from(input: Place) -> Self { |
| 4596 | u32::from(input.0) |
| 4597 | } |
| 4598 | } |
| 4599 | impl From<Place> for Option<u32> { |
| 4600 | #[inline ] |
| 4601 | fn from(input: Place) -> Self { |
| 4602 | Some(u32::from(input.0)) |
| 4603 | } |
| 4604 | } |
| 4605 | impl From<u8> for Place { |
| 4606 | #[inline ] |
| 4607 | fn from(value: u8) -> Self { |
| 4608 | Self(value) |
| 4609 | } |
| 4610 | } |
| 4611 | impl core::fmt::Debug for Place { |
| 4612 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 4613 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 4614 | (Self::ON_TOP.0.into(), "ON_TOP" , "OnTop" ), |
| 4615 | (Self::ON_BOTTOM.0.into(), "ON_BOTTOM" , "OnBottom" ), |
| 4616 | ]; |
| 4617 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 4618 | } |
| 4619 | } |
| 4620 | |
| 4621 | /// Opcode for the CirculateNotify event |
| 4622 | pub const CIRCULATE_NOTIFY_EVENT: u8 = 26; |
| 4623 | /// NOT YET DOCUMENTED. |
| 4624 | /// |
| 4625 | /// # Fields |
| 4626 | /// |
| 4627 | /// * `event` - Either the restacked window or its parent, depending on whether |
| 4628 | /// `StructureNotify` or `SubstructureNotify` was selected. |
| 4629 | /// * `window` - The restacked window. |
| 4630 | /// * `place` - |
| 4631 | /// |
| 4632 | /// # See |
| 4633 | /// |
| 4634 | /// * `CirculateWindow`: request |
| 4635 | #[derive (Clone, Copy, Default)] |
| 4636 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 4637 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4638 | pub struct CirculateNotifyEvent { |
| 4639 | pub response_type: u8, |
| 4640 | pub sequence: u16, |
| 4641 | pub event: Window, |
| 4642 | pub window: Window, |
| 4643 | pub place: Place, |
| 4644 | } |
| 4645 | impl_debug_if_no_extra_traits!(CirculateNotifyEvent, "CirculateNotifyEvent" ); |
| 4646 | impl TryParse for CirculateNotifyEvent { |
| 4647 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 4648 | let remaining: &[u8] = initial_value; |
| 4649 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4650 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 4651 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 4652 | let (event: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 4653 | let (window: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 4654 | let remaining: &[u8] = remaining.get(4..).ok_or(err:ParseError::InsufficientData)?; |
| 4655 | let (place: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4656 | let remaining: &[u8] = remaining.get(3..).ok_or(err:ParseError::InsufficientData)?; |
| 4657 | let place: Place = place.into(); |
| 4658 | let result: CirculateNotifyEvent = CirculateNotifyEvent { response_type, sequence, event, window, place }; |
| 4659 | let _ = remaining; |
| 4660 | let remaining: &[u8] = initial_value.get(32..) |
| 4661 | .ok_or(err:ParseError::InsufficientData)?; |
| 4662 | Ok((result, remaining)) |
| 4663 | } |
| 4664 | } |
| 4665 | impl Serialize for CirculateNotifyEvent { |
| 4666 | type Bytes = [u8; 20]; |
| 4667 | fn serialize(&self) -> [u8; 20] { |
| 4668 | let response_type_bytes = self.response_type.serialize(); |
| 4669 | let sequence_bytes = self.sequence.serialize(); |
| 4670 | let event_bytes = self.event.serialize(); |
| 4671 | let window_bytes = self.window.serialize(); |
| 4672 | let place_bytes = u8::from(self.place).serialize(); |
| 4673 | [ |
| 4674 | response_type_bytes[0], |
| 4675 | 0, |
| 4676 | sequence_bytes[0], |
| 4677 | sequence_bytes[1], |
| 4678 | event_bytes[0], |
| 4679 | event_bytes[1], |
| 4680 | event_bytes[2], |
| 4681 | event_bytes[3], |
| 4682 | window_bytes[0], |
| 4683 | window_bytes[1], |
| 4684 | window_bytes[2], |
| 4685 | window_bytes[3], |
| 4686 | 0, |
| 4687 | 0, |
| 4688 | 0, |
| 4689 | 0, |
| 4690 | place_bytes[0], |
| 4691 | 0, |
| 4692 | 0, |
| 4693 | 0, |
| 4694 | ] |
| 4695 | } |
| 4696 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 4697 | bytes.reserve(20); |
| 4698 | self.response_type.serialize_into(bytes); |
| 4699 | bytes.extend_from_slice(&[0; 1]); |
| 4700 | self.sequence.serialize_into(bytes); |
| 4701 | self.event.serialize_into(bytes); |
| 4702 | self.window.serialize_into(bytes); |
| 4703 | bytes.extend_from_slice(&[0; 4]); |
| 4704 | u8::from(self.place).serialize_into(bytes); |
| 4705 | bytes.extend_from_slice(&[0; 3]); |
| 4706 | } |
| 4707 | } |
| 4708 | impl From<&CirculateNotifyEvent> for [u8; 32] { |
| 4709 | fn from(input: &CirculateNotifyEvent) -> Self { |
| 4710 | let response_type_bytes = input.response_type.serialize(); |
| 4711 | let sequence_bytes = input.sequence.serialize(); |
| 4712 | let event_bytes = input.event.serialize(); |
| 4713 | let window_bytes = input.window.serialize(); |
| 4714 | let place_bytes = u8::from(input.place).serialize(); |
| 4715 | [ |
| 4716 | response_type_bytes[0], |
| 4717 | 0, |
| 4718 | sequence_bytes[0], |
| 4719 | sequence_bytes[1], |
| 4720 | event_bytes[0], |
| 4721 | event_bytes[1], |
| 4722 | event_bytes[2], |
| 4723 | event_bytes[3], |
| 4724 | window_bytes[0], |
| 4725 | window_bytes[1], |
| 4726 | window_bytes[2], |
| 4727 | window_bytes[3], |
| 4728 | 0, |
| 4729 | 0, |
| 4730 | 0, |
| 4731 | 0, |
| 4732 | place_bytes[0], |
| 4733 | 0, |
| 4734 | 0, |
| 4735 | 0, |
| 4736 | // trailing padding |
| 4737 | 0, |
| 4738 | 0, |
| 4739 | 0, |
| 4740 | 0, |
| 4741 | 0, |
| 4742 | 0, |
| 4743 | 0, |
| 4744 | 0, |
| 4745 | 0, |
| 4746 | 0, |
| 4747 | 0, |
| 4748 | 0, |
| 4749 | ] |
| 4750 | } |
| 4751 | } |
| 4752 | impl From<CirculateNotifyEvent> for [u8; 32] { |
| 4753 | fn from(input: CirculateNotifyEvent) -> Self { |
| 4754 | Self::from(&input) |
| 4755 | } |
| 4756 | } |
| 4757 | |
| 4758 | /// Opcode for the CirculateRequest event |
| 4759 | pub const CIRCULATE_REQUEST_EVENT: u8 = 27; |
| 4760 | pub type CirculateRequestEvent = CirculateNotifyEvent; |
| 4761 | |
| 4762 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 4763 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4764 | pub struct Property(u8); |
| 4765 | impl Property { |
| 4766 | pub const NEW_VALUE: Self = Self(0); |
| 4767 | pub const DELETE: Self = Self(1); |
| 4768 | } |
| 4769 | impl From<Property> for u8 { |
| 4770 | #[inline ] |
| 4771 | fn from(input: Property) -> Self { |
| 4772 | input.0 |
| 4773 | } |
| 4774 | } |
| 4775 | impl From<Property> for Option<u8> { |
| 4776 | #[inline ] |
| 4777 | fn from(input: Property) -> Self { |
| 4778 | Some(input.0) |
| 4779 | } |
| 4780 | } |
| 4781 | impl From<Property> for u16 { |
| 4782 | #[inline ] |
| 4783 | fn from(input: Property) -> Self { |
| 4784 | u16::from(input.0) |
| 4785 | } |
| 4786 | } |
| 4787 | impl From<Property> for Option<u16> { |
| 4788 | #[inline ] |
| 4789 | fn from(input: Property) -> Self { |
| 4790 | Some(u16::from(input.0)) |
| 4791 | } |
| 4792 | } |
| 4793 | impl From<Property> for u32 { |
| 4794 | #[inline ] |
| 4795 | fn from(input: Property) -> Self { |
| 4796 | u32::from(input.0) |
| 4797 | } |
| 4798 | } |
| 4799 | impl From<Property> for Option<u32> { |
| 4800 | #[inline ] |
| 4801 | fn from(input: Property) -> Self { |
| 4802 | Some(u32::from(input.0)) |
| 4803 | } |
| 4804 | } |
| 4805 | impl From<u8> for Property { |
| 4806 | #[inline ] |
| 4807 | fn from(value: u8) -> Self { |
| 4808 | Self(value) |
| 4809 | } |
| 4810 | } |
| 4811 | impl core::fmt::Debug for Property { |
| 4812 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 4813 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 4814 | (Self::NEW_VALUE.0.into(), "NEW_VALUE" , "NewValue" ), |
| 4815 | (Self::DELETE.0.into(), "DELETE" , "Delete" ), |
| 4816 | ]; |
| 4817 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 4818 | } |
| 4819 | } |
| 4820 | |
| 4821 | /// Opcode for the PropertyNotify event |
| 4822 | pub const PROPERTY_NOTIFY_EVENT: u8 = 28; |
| 4823 | /// a window property changed. |
| 4824 | /// |
| 4825 | /// # Fields |
| 4826 | /// |
| 4827 | /// * `window` - The window whose associated property was changed. |
| 4828 | /// * `atom` - The property's atom, to indicate which property was changed. |
| 4829 | /// * `time` - A timestamp of the server time when the property was changed. |
| 4830 | /// * `state` - |
| 4831 | /// |
| 4832 | /// # See |
| 4833 | /// |
| 4834 | /// * `ChangeProperty`: request |
| 4835 | #[derive (Clone, Copy, Default)] |
| 4836 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 4837 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4838 | pub struct PropertyNotifyEvent { |
| 4839 | pub response_type: u8, |
| 4840 | pub sequence: u16, |
| 4841 | pub window: Window, |
| 4842 | pub atom: Atom, |
| 4843 | pub time: Timestamp, |
| 4844 | pub state: Property, |
| 4845 | } |
| 4846 | impl_debug_if_no_extra_traits!(PropertyNotifyEvent, "PropertyNotifyEvent" ); |
| 4847 | impl TryParse for PropertyNotifyEvent { |
| 4848 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 4849 | let remaining: &[u8] = initial_value; |
| 4850 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4851 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 4852 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 4853 | let (window: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 4854 | let (atom: u32, remaining: &[u8]) = Atom::try_parse(remaining)?; |
| 4855 | let (time: u32, remaining: &[u8]) = Timestamp::try_parse(remaining)?; |
| 4856 | let (state: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4857 | let remaining: &[u8] = remaining.get(3..).ok_or(err:ParseError::InsufficientData)?; |
| 4858 | let state: Property = state.into(); |
| 4859 | let result: PropertyNotifyEvent = PropertyNotifyEvent { response_type, sequence, window, atom, time, state }; |
| 4860 | let _ = remaining; |
| 4861 | let remaining: &[u8] = initial_value.get(32..) |
| 4862 | .ok_or(err:ParseError::InsufficientData)?; |
| 4863 | Ok((result, remaining)) |
| 4864 | } |
| 4865 | } |
| 4866 | impl Serialize for PropertyNotifyEvent { |
| 4867 | type Bytes = [u8; 20]; |
| 4868 | fn serialize(&self) -> [u8; 20] { |
| 4869 | let response_type_bytes = self.response_type.serialize(); |
| 4870 | let sequence_bytes = self.sequence.serialize(); |
| 4871 | let window_bytes = self.window.serialize(); |
| 4872 | let atom_bytes = self.atom.serialize(); |
| 4873 | let time_bytes = self.time.serialize(); |
| 4874 | let state_bytes = u8::from(self.state).serialize(); |
| 4875 | [ |
| 4876 | response_type_bytes[0], |
| 4877 | 0, |
| 4878 | sequence_bytes[0], |
| 4879 | sequence_bytes[1], |
| 4880 | window_bytes[0], |
| 4881 | window_bytes[1], |
| 4882 | window_bytes[2], |
| 4883 | window_bytes[3], |
| 4884 | atom_bytes[0], |
| 4885 | atom_bytes[1], |
| 4886 | atom_bytes[2], |
| 4887 | atom_bytes[3], |
| 4888 | time_bytes[0], |
| 4889 | time_bytes[1], |
| 4890 | time_bytes[2], |
| 4891 | time_bytes[3], |
| 4892 | state_bytes[0], |
| 4893 | 0, |
| 4894 | 0, |
| 4895 | 0, |
| 4896 | ] |
| 4897 | } |
| 4898 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 4899 | bytes.reserve(20); |
| 4900 | self.response_type.serialize_into(bytes); |
| 4901 | bytes.extend_from_slice(&[0; 1]); |
| 4902 | self.sequence.serialize_into(bytes); |
| 4903 | self.window.serialize_into(bytes); |
| 4904 | self.atom.serialize_into(bytes); |
| 4905 | self.time.serialize_into(bytes); |
| 4906 | u8::from(self.state).serialize_into(bytes); |
| 4907 | bytes.extend_from_slice(&[0; 3]); |
| 4908 | } |
| 4909 | } |
| 4910 | impl From<&PropertyNotifyEvent> for [u8; 32] { |
| 4911 | fn from(input: &PropertyNotifyEvent) -> Self { |
| 4912 | let response_type_bytes = input.response_type.serialize(); |
| 4913 | let sequence_bytes = input.sequence.serialize(); |
| 4914 | let window_bytes = input.window.serialize(); |
| 4915 | let atom_bytes = input.atom.serialize(); |
| 4916 | let time_bytes = input.time.serialize(); |
| 4917 | let state_bytes = u8::from(input.state).serialize(); |
| 4918 | [ |
| 4919 | response_type_bytes[0], |
| 4920 | 0, |
| 4921 | sequence_bytes[0], |
| 4922 | sequence_bytes[1], |
| 4923 | window_bytes[0], |
| 4924 | window_bytes[1], |
| 4925 | window_bytes[2], |
| 4926 | window_bytes[3], |
| 4927 | atom_bytes[0], |
| 4928 | atom_bytes[1], |
| 4929 | atom_bytes[2], |
| 4930 | atom_bytes[3], |
| 4931 | time_bytes[0], |
| 4932 | time_bytes[1], |
| 4933 | time_bytes[2], |
| 4934 | time_bytes[3], |
| 4935 | state_bytes[0], |
| 4936 | 0, |
| 4937 | 0, |
| 4938 | 0, |
| 4939 | // trailing padding |
| 4940 | 0, |
| 4941 | 0, |
| 4942 | 0, |
| 4943 | 0, |
| 4944 | 0, |
| 4945 | 0, |
| 4946 | 0, |
| 4947 | 0, |
| 4948 | 0, |
| 4949 | 0, |
| 4950 | 0, |
| 4951 | 0, |
| 4952 | ] |
| 4953 | } |
| 4954 | } |
| 4955 | impl From<PropertyNotifyEvent> for [u8; 32] { |
| 4956 | fn from(input: PropertyNotifyEvent) -> Self { |
| 4957 | Self::from(&input) |
| 4958 | } |
| 4959 | } |
| 4960 | |
| 4961 | /// Opcode for the SelectionClear event |
| 4962 | pub const SELECTION_CLEAR_EVENT: u8 = 29; |
| 4963 | #[derive (Clone, Copy, Default)] |
| 4964 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 4965 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4966 | pub struct SelectionClearEvent { |
| 4967 | pub response_type: u8, |
| 4968 | pub sequence: u16, |
| 4969 | pub time: Timestamp, |
| 4970 | pub owner: Window, |
| 4971 | pub selection: Atom, |
| 4972 | } |
| 4973 | impl_debug_if_no_extra_traits!(SelectionClearEvent, "SelectionClearEvent" ); |
| 4974 | impl TryParse for SelectionClearEvent { |
| 4975 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 4976 | let remaining: &[u8] = initial_value; |
| 4977 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4978 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 4979 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 4980 | let (time: u32, remaining: &[u8]) = Timestamp::try_parse(remaining)?; |
| 4981 | let (owner: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 4982 | let (selection: u32, remaining: &[u8]) = Atom::try_parse(remaining)?; |
| 4983 | let result: SelectionClearEvent = SelectionClearEvent { response_type, sequence, time, owner, selection }; |
| 4984 | let _ = remaining; |
| 4985 | let remaining: &[u8] = initial_value.get(32..) |
| 4986 | .ok_or(err:ParseError::InsufficientData)?; |
| 4987 | Ok((result, remaining)) |
| 4988 | } |
| 4989 | } |
| 4990 | impl Serialize for SelectionClearEvent { |
| 4991 | type Bytes = [u8; 16]; |
| 4992 | fn serialize(&self) -> [u8; 16] { |
| 4993 | let response_type_bytes = self.response_type.serialize(); |
| 4994 | let sequence_bytes = self.sequence.serialize(); |
| 4995 | let time_bytes = self.time.serialize(); |
| 4996 | let owner_bytes = self.owner.serialize(); |
| 4997 | let selection_bytes = self.selection.serialize(); |
| 4998 | [ |
| 4999 | response_type_bytes[0], |
| 5000 | 0, |
| 5001 | sequence_bytes[0], |
| 5002 | sequence_bytes[1], |
| 5003 | time_bytes[0], |
| 5004 | time_bytes[1], |
| 5005 | time_bytes[2], |
| 5006 | time_bytes[3], |
| 5007 | owner_bytes[0], |
| 5008 | owner_bytes[1], |
| 5009 | owner_bytes[2], |
| 5010 | owner_bytes[3], |
| 5011 | selection_bytes[0], |
| 5012 | selection_bytes[1], |
| 5013 | selection_bytes[2], |
| 5014 | selection_bytes[3], |
| 5015 | ] |
| 5016 | } |
| 5017 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 5018 | bytes.reserve(16); |
| 5019 | self.response_type.serialize_into(bytes); |
| 5020 | bytes.extend_from_slice(&[0; 1]); |
| 5021 | self.sequence.serialize_into(bytes); |
| 5022 | self.time.serialize_into(bytes); |
| 5023 | self.owner.serialize_into(bytes); |
| 5024 | self.selection.serialize_into(bytes); |
| 5025 | } |
| 5026 | } |
| 5027 | impl From<&SelectionClearEvent> for [u8; 32] { |
| 5028 | fn from(input: &SelectionClearEvent) -> Self { |
| 5029 | let response_type_bytes = input.response_type.serialize(); |
| 5030 | let sequence_bytes = input.sequence.serialize(); |
| 5031 | let time_bytes = input.time.serialize(); |
| 5032 | let owner_bytes = input.owner.serialize(); |
| 5033 | let selection_bytes = input.selection.serialize(); |
| 5034 | [ |
| 5035 | response_type_bytes[0], |
| 5036 | 0, |
| 5037 | sequence_bytes[0], |
| 5038 | sequence_bytes[1], |
| 5039 | time_bytes[0], |
| 5040 | time_bytes[1], |
| 5041 | time_bytes[2], |
| 5042 | time_bytes[3], |
| 5043 | owner_bytes[0], |
| 5044 | owner_bytes[1], |
| 5045 | owner_bytes[2], |
| 5046 | owner_bytes[3], |
| 5047 | selection_bytes[0], |
| 5048 | selection_bytes[1], |
| 5049 | selection_bytes[2], |
| 5050 | selection_bytes[3], |
| 5051 | // trailing padding |
| 5052 | 0, |
| 5053 | 0, |
| 5054 | 0, |
| 5055 | 0, |
| 5056 | 0, |
| 5057 | 0, |
| 5058 | 0, |
| 5059 | 0, |
| 5060 | 0, |
| 5061 | 0, |
| 5062 | 0, |
| 5063 | 0, |
| 5064 | 0, |
| 5065 | 0, |
| 5066 | 0, |
| 5067 | 0, |
| 5068 | ] |
| 5069 | } |
| 5070 | } |
| 5071 | impl From<SelectionClearEvent> for [u8; 32] { |
| 5072 | fn from(input: SelectionClearEvent) -> Self { |
| 5073 | Self::from(&input) |
| 5074 | } |
| 5075 | } |
| 5076 | |
| 5077 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 5078 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5079 | pub struct Time(u8); |
| 5080 | impl Time { |
| 5081 | pub const CURRENT_TIME: Self = Self(0); |
| 5082 | } |
| 5083 | impl From<Time> for u8 { |
| 5084 | #[inline ] |
| 5085 | fn from(input: Time) -> Self { |
| 5086 | input.0 |
| 5087 | } |
| 5088 | } |
| 5089 | impl From<Time> for Option<u8> { |
| 5090 | #[inline ] |
| 5091 | fn from(input: Time) -> Self { |
| 5092 | Some(input.0) |
| 5093 | } |
| 5094 | } |
| 5095 | impl From<Time> for u16 { |
| 5096 | #[inline ] |
| 5097 | fn from(input: Time) -> Self { |
| 5098 | u16::from(input.0) |
| 5099 | } |
| 5100 | } |
| 5101 | impl From<Time> for Option<u16> { |
| 5102 | #[inline ] |
| 5103 | fn from(input: Time) -> Self { |
| 5104 | Some(u16::from(input.0)) |
| 5105 | } |
| 5106 | } |
| 5107 | impl From<Time> for u32 { |
| 5108 | #[inline ] |
| 5109 | fn from(input: Time) -> Self { |
| 5110 | u32::from(input.0) |
| 5111 | } |
| 5112 | } |
| 5113 | impl From<Time> for Option<u32> { |
| 5114 | #[inline ] |
| 5115 | fn from(input: Time) -> Self { |
| 5116 | Some(u32::from(input.0)) |
| 5117 | } |
| 5118 | } |
| 5119 | impl From<u8> for Time { |
| 5120 | #[inline ] |
| 5121 | fn from(value: u8) -> Self { |
| 5122 | Self(value) |
| 5123 | } |
| 5124 | } |
| 5125 | impl core::fmt::Debug for Time { |
| 5126 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 5127 | let variants: [(u32, &'static str, &'static …); 1] = [ |
| 5128 | (Self::CURRENT_TIME.0.into(), "CURRENT_TIME" , "CurrentTime" ), |
| 5129 | ]; |
| 5130 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 5131 | } |
| 5132 | } |
| 5133 | |
| 5134 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 5135 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5136 | pub struct AtomEnum(u8); |
| 5137 | impl AtomEnum { |
| 5138 | pub const NONE: Self = Self(0); |
| 5139 | pub const ANY: Self = Self(0); |
| 5140 | pub const PRIMARY: Self = Self(1); |
| 5141 | pub const SECONDARY: Self = Self(2); |
| 5142 | pub const ARC: Self = Self(3); |
| 5143 | pub const ATOM: Self = Self(4); |
| 5144 | pub const BITMAP: Self = Self(5); |
| 5145 | pub const CARDINAL: Self = Self(6); |
| 5146 | pub const COLORMAP: Self = Self(7); |
| 5147 | pub const CURSOR: Self = Self(8); |
| 5148 | pub const CUT_BUFFE_R0: Self = Self(9); |
| 5149 | pub const CUT_BUFFE_R1: Self = Self(10); |
| 5150 | pub const CUT_BUFFE_R2: Self = Self(11); |
| 5151 | pub const CUT_BUFFE_R3: Self = Self(12); |
| 5152 | pub const CUT_BUFFE_R4: Self = Self(13); |
| 5153 | pub const CUT_BUFFE_R5: Self = Self(14); |
| 5154 | pub const CUT_BUFFE_R6: Self = Self(15); |
| 5155 | pub const CUT_BUFFE_R7: Self = Self(16); |
| 5156 | pub const DRAWABLE: Self = Self(17); |
| 5157 | pub const FONT: Self = Self(18); |
| 5158 | pub const INTEGER: Self = Self(19); |
| 5159 | pub const PIXMAP: Self = Self(20); |
| 5160 | pub const POINT: Self = Self(21); |
| 5161 | pub const RECTANGLE: Self = Self(22); |
| 5162 | pub const RESOURCE_MANAGER: Self = Self(23); |
| 5163 | pub const RGB_COLOR_MAP: Self = Self(24); |
| 5164 | pub const RGB_BEST_MAP: Self = Self(25); |
| 5165 | pub const RGB_BLUE_MAP: Self = Self(26); |
| 5166 | pub const RGB_DEFAULT_MAP: Self = Self(27); |
| 5167 | pub const RGB_GRAY_MAP: Self = Self(28); |
| 5168 | pub const RGB_GREEN_MAP: Self = Self(29); |
| 5169 | pub const RGB_RED_MAP: Self = Self(30); |
| 5170 | pub const STRING: Self = Self(31); |
| 5171 | pub const VISUALID: Self = Self(32); |
| 5172 | pub const WINDOW: Self = Self(33); |
| 5173 | pub const WM_COMMAND: Self = Self(34); |
| 5174 | pub const WM_HINTS: Self = Self(35); |
| 5175 | pub const WM_CLIENT_MACHINE: Self = Self(36); |
| 5176 | pub const WM_ICON_NAME: Self = Self(37); |
| 5177 | pub const WM_ICON_SIZE: Self = Self(38); |
| 5178 | pub const WM_NAME: Self = Self(39); |
| 5179 | pub const WM_NORMAL_HINTS: Self = Self(40); |
| 5180 | pub const WM_SIZE_HINTS: Self = Self(41); |
| 5181 | pub const WM_ZOOM_HINTS: Self = Self(42); |
| 5182 | pub const MIN_SPACE: Self = Self(43); |
| 5183 | pub const NORM_SPACE: Self = Self(44); |
| 5184 | pub const MAX_SPACE: Self = Self(45); |
| 5185 | pub const END_SPACE: Self = Self(46); |
| 5186 | pub const SUPERSCRIPT_X: Self = Self(47); |
| 5187 | pub const SUPERSCRIPT_Y: Self = Self(48); |
| 5188 | pub const SUBSCRIPT_X: Self = Self(49); |
| 5189 | pub const SUBSCRIPT_Y: Self = Self(50); |
| 5190 | pub const UNDERLINE_POSITION: Self = Self(51); |
| 5191 | pub const UNDERLINE_THICKNESS: Self = Self(52); |
| 5192 | pub const STRIKEOUT_ASCENT: Self = Self(53); |
| 5193 | pub const STRIKEOUT_DESCENT: Self = Self(54); |
| 5194 | pub const ITALIC_ANGLE: Self = Self(55); |
| 5195 | pub const X_HEIGHT: Self = Self(56); |
| 5196 | pub const QUAD_WIDTH: Self = Self(57); |
| 5197 | pub const WEIGHT: Self = Self(58); |
| 5198 | pub const POINT_SIZE: Self = Self(59); |
| 5199 | pub const RESOLUTION: Self = Self(60); |
| 5200 | pub const COPYRIGHT: Self = Self(61); |
| 5201 | pub const NOTICE: Self = Self(62); |
| 5202 | pub const FONT_NAME: Self = Self(63); |
| 5203 | pub const FAMILY_NAME: Self = Self(64); |
| 5204 | pub const FULL_NAME: Self = Self(65); |
| 5205 | pub const CAP_HEIGHT: Self = Self(66); |
| 5206 | pub const WM_CLASS: Self = Self(67); |
| 5207 | pub const WM_TRANSIENT_FOR: Self = Self(68); |
| 5208 | } |
| 5209 | impl From<AtomEnum> for u8 { |
| 5210 | #[inline ] |
| 5211 | fn from(input: AtomEnum) -> Self { |
| 5212 | input.0 |
| 5213 | } |
| 5214 | } |
| 5215 | impl From<AtomEnum> for Option<u8> { |
| 5216 | #[inline ] |
| 5217 | fn from(input: AtomEnum) -> Self { |
| 5218 | Some(input.0) |
| 5219 | } |
| 5220 | } |
| 5221 | impl From<AtomEnum> for u16 { |
| 5222 | #[inline ] |
| 5223 | fn from(input: AtomEnum) -> Self { |
| 5224 | u16::from(input.0) |
| 5225 | } |
| 5226 | } |
| 5227 | impl From<AtomEnum> for Option<u16> { |
| 5228 | #[inline ] |
| 5229 | fn from(input: AtomEnum) -> Self { |
| 5230 | Some(u16::from(input.0)) |
| 5231 | } |
| 5232 | } |
| 5233 | impl From<AtomEnum> for u32 { |
| 5234 | #[inline ] |
| 5235 | fn from(input: AtomEnum) -> Self { |
| 5236 | u32::from(input.0) |
| 5237 | } |
| 5238 | } |
| 5239 | impl From<AtomEnum> for Option<u32> { |
| 5240 | #[inline ] |
| 5241 | fn from(input: AtomEnum) -> Self { |
| 5242 | Some(u32::from(input.0)) |
| 5243 | } |
| 5244 | } |
| 5245 | impl From<u8> for AtomEnum { |
| 5246 | #[inline ] |
| 5247 | fn from(value: u8) -> Self { |
| 5248 | Self(value) |
| 5249 | } |
| 5250 | } |
| 5251 | impl core::fmt::Debug for AtomEnum { |
| 5252 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 5253 | let variants = [ |
| 5254 | (Self::NONE.0.into(), "NONE" , "None" ), |
| 5255 | (Self::ANY.0.into(), "ANY" , "Any" ), |
| 5256 | (Self::PRIMARY.0.into(), "PRIMARY" , "PRIMARY" ), |
| 5257 | (Self::SECONDARY.0.into(), "SECONDARY" , "SECONDARY" ), |
| 5258 | (Self::ARC.0.into(), "ARC" , "ARC" ), |
| 5259 | (Self::ATOM.0.into(), "ATOM" , "ATOM" ), |
| 5260 | (Self::BITMAP.0.into(), "BITMAP" , "BITMAP" ), |
| 5261 | (Self::CARDINAL.0.into(), "CARDINAL" , "CARDINAL" ), |
| 5262 | (Self::COLORMAP.0.into(), "COLORMAP" , "COLORMAP" ), |
| 5263 | (Self::CURSOR.0.into(), "CURSOR" , "CURSOR" ), |
| 5264 | (Self::CUT_BUFFE_R0.0.into(), "CUT_BUFFE_R0" , "CUT_BUFFER0" ), |
| 5265 | (Self::CUT_BUFFE_R1.0.into(), "CUT_BUFFE_R1" , "CUT_BUFFER1" ), |
| 5266 | (Self::CUT_BUFFE_R2.0.into(), "CUT_BUFFE_R2" , "CUT_BUFFER2" ), |
| 5267 | (Self::CUT_BUFFE_R3.0.into(), "CUT_BUFFE_R3" , "CUT_BUFFER3" ), |
| 5268 | (Self::CUT_BUFFE_R4.0.into(), "CUT_BUFFE_R4" , "CUT_BUFFER4" ), |
| 5269 | (Self::CUT_BUFFE_R5.0.into(), "CUT_BUFFE_R5" , "CUT_BUFFER5" ), |
| 5270 | (Self::CUT_BUFFE_R6.0.into(), "CUT_BUFFE_R6" , "CUT_BUFFER6" ), |
| 5271 | (Self::CUT_BUFFE_R7.0.into(), "CUT_BUFFE_R7" , "CUT_BUFFER7" ), |
| 5272 | (Self::DRAWABLE.0.into(), "DRAWABLE" , "DRAWABLE" ), |
| 5273 | (Self::FONT.0.into(), "FONT" , "FONT" ), |
| 5274 | (Self::INTEGER.0.into(), "INTEGER" , "INTEGER" ), |
| 5275 | (Self::PIXMAP.0.into(), "PIXMAP" , "PIXMAP" ), |
| 5276 | (Self::POINT.0.into(), "POINT" , "POINT" ), |
| 5277 | (Self::RECTANGLE.0.into(), "RECTANGLE" , "RECTANGLE" ), |
| 5278 | (Self::RESOURCE_MANAGER.0.into(), "RESOURCE_MANAGER" , "RESOURCE_MANAGER" ), |
| 5279 | (Self::RGB_COLOR_MAP.0.into(), "RGB_COLOR_MAP" , "RGB_COLOR_MAP" ), |
| 5280 | (Self::RGB_BEST_MAP.0.into(), "RGB_BEST_MAP" , "RGB_BEST_MAP" ), |
| 5281 | (Self::RGB_BLUE_MAP.0.into(), "RGB_BLUE_MAP" , "RGB_BLUE_MAP" ), |
| 5282 | (Self::RGB_DEFAULT_MAP.0.into(), "RGB_DEFAULT_MAP" , "RGB_DEFAULT_MAP" ), |
| 5283 | (Self::RGB_GRAY_MAP.0.into(), "RGB_GRAY_MAP" , "RGB_GRAY_MAP" ), |
| 5284 | (Self::RGB_GREEN_MAP.0.into(), "RGB_GREEN_MAP" , "RGB_GREEN_MAP" ), |
| 5285 | (Self::RGB_RED_MAP.0.into(), "RGB_RED_MAP" , "RGB_RED_MAP" ), |
| 5286 | (Self::STRING.0.into(), "STRING" , "STRING" ), |
| 5287 | (Self::VISUALID.0.into(), "VISUALID" , "VISUALID" ), |
| 5288 | (Self::WINDOW.0.into(), "WINDOW" , "WINDOW" ), |
| 5289 | (Self::WM_COMMAND.0.into(), "WM_COMMAND" , "WM_COMMAND" ), |
| 5290 | (Self::WM_HINTS.0.into(), "WM_HINTS" , "WM_HINTS" ), |
| 5291 | (Self::WM_CLIENT_MACHINE.0.into(), "WM_CLIENT_MACHINE" , "WM_CLIENT_MACHINE" ), |
| 5292 | (Self::WM_ICON_NAME.0.into(), "WM_ICON_NAME" , "WM_ICON_NAME" ), |
| 5293 | (Self::WM_ICON_SIZE.0.into(), "WM_ICON_SIZE" , "WM_ICON_SIZE" ), |
| 5294 | (Self::WM_NAME.0.into(), "WM_NAME" , "WM_NAME" ), |
| 5295 | (Self::WM_NORMAL_HINTS.0.into(), "WM_NORMAL_HINTS" , "WM_NORMAL_HINTS" ), |
| 5296 | (Self::WM_SIZE_HINTS.0.into(), "WM_SIZE_HINTS" , "WM_SIZE_HINTS" ), |
| 5297 | (Self::WM_ZOOM_HINTS.0.into(), "WM_ZOOM_HINTS" , "WM_ZOOM_HINTS" ), |
| 5298 | (Self::MIN_SPACE.0.into(), "MIN_SPACE" , "MIN_SPACE" ), |
| 5299 | (Self::NORM_SPACE.0.into(), "NORM_SPACE" , "NORM_SPACE" ), |
| 5300 | (Self::MAX_SPACE.0.into(), "MAX_SPACE" , "MAX_SPACE" ), |
| 5301 | (Self::END_SPACE.0.into(), "END_SPACE" , "END_SPACE" ), |
| 5302 | (Self::SUPERSCRIPT_X.0.into(), "SUPERSCRIPT_X" , "SUPERSCRIPT_X" ), |
| 5303 | (Self::SUPERSCRIPT_Y.0.into(), "SUPERSCRIPT_Y" , "SUPERSCRIPT_Y" ), |
| 5304 | (Self::SUBSCRIPT_X.0.into(), "SUBSCRIPT_X" , "SUBSCRIPT_X" ), |
| 5305 | (Self::SUBSCRIPT_Y.0.into(), "SUBSCRIPT_Y" , "SUBSCRIPT_Y" ), |
| 5306 | (Self::UNDERLINE_POSITION.0.into(), "UNDERLINE_POSITION" , "UNDERLINE_POSITION" ), |
| 5307 | (Self::UNDERLINE_THICKNESS.0.into(), "UNDERLINE_THICKNESS" , "UNDERLINE_THICKNESS" ), |
| 5308 | (Self::STRIKEOUT_ASCENT.0.into(), "STRIKEOUT_ASCENT" , "STRIKEOUT_ASCENT" ), |
| 5309 | (Self::STRIKEOUT_DESCENT.0.into(), "STRIKEOUT_DESCENT" , "STRIKEOUT_DESCENT" ), |
| 5310 | (Self::ITALIC_ANGLE.0.into(), "ITALIC_ANGLE" , "ITALIC_ANGLE" ), |
| 5311 | (Self::X_HEIGHT.0.into(), "X_HEIGHT" , "X_HEIGHT" ), |
| 5312 | (Self::QUAD_WIDTH.0.into(), "QUAD_WIDTH" , "QUAD_WIDTH" ), |
| 5313 | (Self::WEIGHT.0.into(), "WEIGHT" , "WEIGHT" ), |
| 5314 | (Self::POINT_SIZE.0.into(), "POINT_SIZE" , "POINT_SIZE" ), |
| 5315 | (Self::RESOLUTION.0.into(), "RESOLUTION" , "RESOLUTION" ), |
| 5316 | (Self::COPYRIGHT.0.into(), "COPYRIGHT" , "COPYRIGHT" ), |
| 5317 | (Self::NOTICE.0.into(), "NOTICE" , "NOTICE" ), |
| 5318 | (Self::FONT_NAME.0.into(), "FONT_NAME" , "FONT_NAME" ), |
| 5319 | (Self::FAMILY_NAME.0.into(), "FAMILY_NAME" , "FAMILY_NAME" ), |
| 5320 | (Self::FULL_NAME.0.into(), "FULL_NAME" , "FULL_NAME" ), |
| 5321 | (Self::CAP_HEIGHT.0.into(), "CAP_HEIGHT" , "CAP_HEIGHT" ), |
| 5322 | (Self::WM_CLASS.0.into(), "WM_CLASS" , "WM_CLASS" ), |
| 5323 | (Self::WM_TRANSIENT_FOR.0.into(), "WM_TRANSIENT_FOR" , "WM_TRANSIENT_FOR" ), |
| 5324 | ]; |
| 5325 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 5326 | } |
| 5327 | } |
| 5328 | |
| 5329 | /// Opcode for the SelectionRequest event |
| 5330 | pub const SELECTION_REQUEST_EVENT: u8 = 30; |
| 5331 | #[derive (Clone, Copy, Default)] |
| 5332 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 5333 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5334 | pub struct SelectionRequestEvent { |
| 5335 | pub response_type: u8, |
| 5336 | pub sequence: u16, |
| 5337 | pub time: Timestamp, |
| 5338 | pub owner: Window, |
| 5339 | pub requestor: Window, |
| 5340 | pub selection: Atom, |
| 5341 | pub target: Atom, |
| 5342 | pub property: Atom, |
| 5343 | } |
| 5344 | impl_debug_if_no_extra_traits!(SelectionRequestEvent, "SelectionRequestEvent" ); |
| 5345 | impl TryParse for SelectionRequestEvent { |
| 5346 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 5347 | let remaining: &[u8] = initial_value; |
| 5348 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5349 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 5350 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 5351 | let (time: u32, remaining: &[u8]) = Timestamp::try_parse(remaining)?; |
| 5352 | let (owner: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 5353 | let (requestor: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 5354 | let (selection: u32, remaining: &[u8]) = Atom::try_parse(remaining)?; |
| 5355 | let (target: u32, remaining: &[u8]) = Atom::try_parse(remaining)?; |
| 5356 | let (property: u32, remaining: &[u8]) = Atom::try_parse(remaining)?; |
| 5357 | let result: SelectionRequestEvent = SelectionRequestEvent { response_type, sequence, time, owner, requestor, selection, target, property }; |
| 5358 | let _ = remaining; |
| 5359 | let remaining: &[u8] = initial_value.get(32..) |
| 5360 | .ok_or(err:ParseError::InsufficientData)?; |
| 5361 | Ok((result, remaining)) |
| 5362 | } |
| 5363 | } |
| 5364 | impl Serialize for SelectionRequestEvent { |
| 5365 | type Bytes = [u8; 28]; |
| 5366 | fn serialize(&self) -> [u8; 28] { |
| 5367 | let response_type_bytes = self.response_type.serialize(); |
| 5368 | let sequence_bytes = self.sequence.serialize(); |
| 5369 | let time_bytes = self.time.serialize(); |
| 5370 | let owner_bytes = self.owner.serialize(); |
| 5371 | let requestor_bytes = self.requestor.serialize(); |
| 5372 | let selection_bytes = self.selection.serialize(); |
| 5373 | let target_bytes = self.target.serialize(); |
| 5374 | let property_bytes = self.property.serialize(); |
| 5375 | [ |
| 5376 | response_type_bytes[0], |
| 5377 | 0, |
| 5378 | sequence_bytes[0], |
| 5379 | sequence_bytes[1], |
| 5380 | time_bytes[0], |
| 5381 | time_bytes[1], |
| 5382 | time_bytes[2], |
| 5383 | time_bytes[3], |
| 5384 | owner_bytes[0], |
| 5385 | owner_bytes[1], |
| 5386 | owner_bytes[2], |
| 5387 | owner_bytes[3], |
| 5388 | requestor_bytes[0], |
| 5389 | requestor_bytes[1], |
| 5390 | requestor_bytes[2], |
| 5391 | requestor_bytes[3], |
| 5392 | selection_bytes[0], |
| 5393 | selection_bytes[1], |
| 5394 | selection_bytes[2], |
| 5395 | selection_bytes[3], |
| 5396 | target_bytes[0], |
| 5397 | target_bytes[1], |
| 5398 | target_bytes[2], |
| 5399 | target_bytes[3], |
| 5400 | property_bytes[0], |
| 5401 | property_bytes[1], |
| 5402 | property_bytes[2], |
| 5403 | property_bytes[3], |
| 5404 | ] |
| 5405 | } |
| 5406 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 5407 | bytes.reserve(28); |
| 5408 | self.response_type.serialize_into(bytes); |
| 5409 | bytes.extend_from_slice(&[0; 1]); |
| 5410 | self.sequence.serialize_into(bytes); |
| 5411 | self.time.serialize_into(bytes); |
| 5412 | self.owner.serialize_into(bytes); |
| 5413 | self.requestor.serialize_into(bytes); |
| 5414 | self.selection.serialize_into(bytes); |
| 5415 | self.target.serialize_into(bytes); |
| 5416 | self.property.serialize_into(bytes); |
| 5417 | } |
| 5418 | } |
| 5419 | impl From<&SelectionRequestEvent> for [u8; 32] { |
| 5420 | fn from(input: &SelectionRequestEvent) -> Self { |
| 5421 | let response_type_bytes = input.response_type.serialize(); |
| 5422 | let sequence_bytes = input.sequence.serialize(); |
| 5423 | let time_bytes = input.time.serialize(); |
| 5424 | let owner_bytes = input.owner.serialize(); |
| 5425 | let requestor_bytes = input.requestor.serialize(); |
| 5426 | let selection_bytes = input.selection.serialize(); |
| 5427 | let target_bytes = input.target.serialize(); |
| 5428 | let property_bytes = input.property.serialize(); |
| 5429 | [ |
| 5430 | response_type_bytes[0], |
| 5431 | 0, |
| 5432 | sequence_bytes[0], |
| 5433 | sequence_bytes[1], |
| 5434 | time_bytes[0], |
| 5435 | time_bytes[1], |
| 5436 | time_bytes[2], |
| 5437 | time_bytes[3], |
| 5438 | owner_bytes[0], |
| 5439 | owner_bytes[1], |
| 5440 | owner_bytes[2], |
| 5441 | owner_bytes[3], |
| 5442 | requestor_bytes[0], |
| 5443 | requestor_bytes[1], |
| 5444 | requestor_bytes[2], |
| 5445 | requestor_bytes[3], |
| 5446 | selection_bytes[0], |
| 5447 | selection_bytes[1], |
| 5448 | selection_bytes[2], |
| 5449 | selection_bytes[3], |
| 5450 | target_bytes[0], |
| 5451 | target_bytes[1], |
| 5452 | target_bytes[2], |
| 5453 | target_bytes[3], |
| 5454 | property_bytes[0], |
| 5455 | property_bytes[1], |
| 5456 | property_bytes[2], |
| 5457 | property_bytes[3], |
| 5458 | // trailing padding |
| 5459 | 0, |
| 5460 | 0, |
| 5461 | 0, |
| 5462 | 0, |
| 5463 | ] |
| 5464 | } |
| 5465 | } |
| 5466 | impl From<SelectionRequestEvent> for [u8; 32] { |
| 5467 | fn from(input: SelectionRequestEvent) -> Self { |
| 5468 | Self::from(&input) |
| 5469 | } |
| 5470 | } |
| 5471 | |
| 5472 | /// Opcode for the SelectionNotify event |
| 5473 | pub const SELECTION_NOTIFY_EVENT: u8 = 31; |
| 5474 | #[derive (Clone, Copy, Default)] |
| 5475 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 5476 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5477 | pub struct SelectionNotifyEvent { |
| 5478 | pub response_type: u8, |
| 5479 | pub sequence: u16, |
| 5480 | pub time: Timestamp, |
| 5481 | pub requestor: Window, |
| 5482 | pub selection: Atom, |
| 5483 | pub target: Atom, |
| 5484 | pub property: Atom, |
| 5485 | } |
| 5486 | impl_debug_if_no_extra_traits!(SelectionNotifyEvent, "SelectionNotifyEvent" ); |
| 5487 | impl TryParse for SelectionNotifyEvent { |
| 5488 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 5489 | let remaining: &[u8] = initial_value; |
| 5490 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5491 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 5492 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 5493 | let (time: u32, remaining: &[u8]) = Timestamp::try_parse(remaining)?; |
| 5494 | let (requestor: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 5495 | let (selection: u32, remaining: &[u8]) = Atom::try_parse(remaining)?; |
| 5496 | let (target: u32, remaining: &[u8]) = Atom::try_parse(remaining)?; |
| 5497 | let (property: u32, remaining: &[u8]) = Atom::try_parse(remaining)?; |
| 5498 | let result: SelectionNotifyEvent = SelectionNotifyEvent { response_type, sequence, time, requestor, selection, target, property }; |
| 5499 | let _ = remaining; |
| 5500 | let remaining: &[u8] = initial_value.get(32..) |
| 5501 | .ok_or(err:ParseError::InsufficientData)?; |
| 5502 | Ok((result, remaining)) |
| 5503 | } |
| 5504 | } |
| 5505 | impl Serialize for SelectionNotifyEvent { |
| 5506 | type Bytes = [u8; 24]; |
| 5507 | fn serialize(&self) -> [u8; 24] { |
| 5508 | let response_type_bytes = self.response_type.serialize(); |
| 5509 | let sequence_bytes = self.sequence.serialize(); |
| 5510 | let time_bytes = self.time.serialize(); |
| 5511 | let requestor_bytes = self.requestor.serialize(); |
| 5512 | let selection_bytes = self.selection.serialize(); |
| 5513 | let target_bytes = self.target.serialize(); |
| 5514 | let property_bytes = self.property.serialize(); |
| 5515 | [ |
| 5516 | response_type_bytes[0], |
| 5517 | 0, |
| 5518 | sequence_bytes[0], |
| 5519 | sequence_bytes[1], |
| 5520 | time_bytes[0], |
| 5521 | time_bytes[1], |
| 5522 | time_bytes[2], |
| 5523 | time_bytes[3], |
| 5524 | requestor_bytes[0], |
| 5525 | requestor_bytes[1], |
| 5526 | requestor_bytes[2], |
| 5527 | requestor_bytes[3], |
| 5528 | selection_bytes[0], |
| 5529 | selection_bytes[1], |
| 5530 | selection_bytes[2], |
| 5531 | selection_bytes[3], |
| 5532 | target_bytes[0], |
| 5533 | target_bytes[1], |
| 5534 | target_bytes[2], |
| 5535 | target_bytes[3], |
| 5536 | property_bytes[0], |
| 5537 | property_bytes[1], |
| 5538 | property_bytes[2], |
| 5539 | property_bytes[3], |
| 5540 | ] |
| 5541 | } |
| 5542 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 5543 | bytes.reserve(24); |
| 5544 | self.response_type.serialize_into(bytes); |
| 5545 | bytes.extend_from_slice(&[0; 1]); |
| 5546 | self.sequence.serialize_into(bytes); |
| 5547 | self.time.serialize_into(bytes); |
| 5548 | self.requestor.serialize_into(bytes); |
| 5549 | self.selection.serialize_into(bytes); |
| 5550 | self.target.serialize_into(bytes); |
| 5551 | self.property.serialize_into(bytes); |
| 5552 | } |
| 5553 | } |
| 5554 | impl From<&SelectionNotifyEvent> for [u8; 32] { |
| 5555 | fn from(input: &SelectionNotifyEvent) -> Self { |
| 5556 | let response_type_bytes = input.response_type.serialize(); |
| 5557 | let sequence_bytes = input.sequence.serialize(); |
| 5558 | let time_bytes = input.time.serialize(); |
| 5559 | let requestor_bytes = input.requestor.serialize(); |
| 5560 | let selection_bytes = input.selection.serialize(); |
| 5561 | let target_bytes = input.target.serialize(); |
| 5562 | let property_bytes = input.property.serialize(); |
| 5563 | [ |
| 5564 | response_type_bytes[0], |
| 5565 | 0, |
| 5566 | sequence_bytes[0], |
| 5567 | sequence_bytes[1], |
| 5568 | time_bytes[0], |
| 5569 | time_bytes[1], |
| 5570 | time_bytes[2], |
| 5571 | time_bytes[3], |
| 5572 | requestor_bytes[0], |
| 5573 | requestor_bytes[1], |
| 5574 | requestor_bytes[2], |
| 5575 | requestor_bytes[3], |
| 5576 | selection_bytes[0], |
| 5577 | selection_bytes[1], |
| 5578 | selection_bytes[2], |
| 5579 | selection_bytes[3], |
| 5580 | target_bytes[0], |
| 5581 | target_bytes[1], |
| 5582 | target_bytes[2], |
| 5583 | target_bytes[3], |
| 5584 | property_bytes[0], |
| 5585 | property_bytes[1], |
| 5586 | property_bytes[2], |
| 5587 | property_bytes[3], |
| 5588 | // trailing padding |
| 5589 | 0, |
| 5590 | 0, |
| 5591 | 0, |
| 5592 | 0, |
| 5593 | 0, |
| 5594 | 0, |
| 5595 | 0, |
| 5596 | 0, |
| 5597 | ] |
| 5598 | } |
| 5599 | } |
| 5600 | impl From<SelectionNotifyEvent> for [u8; 32] { |
| 5601 | fn from(input: SelectionNotifyEvent) -> Self { |
| 5602 | Self::from(&input) |
| 5603 | } |
| 5604 | } |
| 5605 | |
| 5606 | /// # Fields |
| 5607 | /// |
| 5608 | /// * `Uninstalled` - The colormap was uninstalled. |
| 5609 | /// * `Installed` - The colormap was installed. |
| 5610 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 5611 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5612 | pub struct ColormapState(u8); |
| 5613 | impl ColormapState { |
| 5614 | pub const UNINSTALLED: Self = Self(0); |
| 5615 | pub const INSTALLED: Self = Self(1); |
| 5616 | } |
| 5617 | impl From<ColormapState> for u8 { |
| 5618 | #[inline ] |
| 5619 | fn from(input: ColormapState) -> Self { |
| 5620 | input.0 |
| 5621 | } |
| 5622 | } |
| 5623 | impl From<ColormapState> for Option<u8> { |
| 5624 | #[inline ] |
| 5625 | fn from(input: ColormapState) -> Self { |
| 5626 | Some(input.0) |
| 5627 | } |
| 5628 | } |
| 5629 | impl From<ColormapState> for u16 { |
| 5630 | #[inline ] |
| 5631 | fn from(input: ColormapState) -> Self { |
| 5632 | u16::from(input.0) |
| 5633 | } |
| 5634 | } |
| 5635 | impl From<ColormapState> for Option<u16> { |
| 5636 | #[inline ] |
| 5637 | fn from(input: ColormapState) -> Self { |
| 5638 | Some(u16::from(input.0)) |
| 5639 | } |
| 5640 | } |
| 5641 | impl From<ColormapState> for u32 { |
| 5642 | #[inline ] |
| 5643 | fn from(input: ColormapState) -> Self { |
| 5644 | u32::from(input.0) |
| 5645 | } |
| 5646 | } |
| 5647 | impl From<ColormapState> for Option<u32> { |
| 5648 | #[inline ] |
| 5649 | fn from(input: ColormapState) -> Self { |
| 5650 | Some(u32::from(input.0)) |
| 5651 | } |
| 5652 | } |
| 5653 | impl From<u8> for ColormapState { |
| 5654 | #[inline ] |
| 5655 | fn from(value: u8) -> Self { |
| 5656 | Self(value) |
| 5657 | } |
| 5658 | } |
| 5659 | impl core::fmt::Debug for ColormapState { |
| 5660 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 5661 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 5662 | (Self::UNINSTALLED.0.into(), "UNINSTALLED" , "Uninstalled" ), |
| 5663 | (Self::INSTALLED.0.into(), "INSTALLED" , "Installed" ), |
| 5664 | ]; |
| 5665 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 5666 | } |
| 5667 | } |
| 5668 | |
| 5669 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 5670 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5671 | pub struct ColormapEnum(u8); |
| 5672 | impl ColormapEnum { |
| 5673 | pub const NONE: Self = Self(0); |
| 5674 | } |
| 5675 | impl From<ColormapEnum> for u8 { |
| 5676 | #[inline ] |
| 5677 | fn from(input: ColormapEnum) -> Self { |
| 5678 | input.0 |
| 5679 | } |
| 5680 | } |
| 5681 | impl From<ColormapEnum> for Option<u8> { |
| 5682 | #[inline ] |
| 5683 | fn from(input: ColormapEnum) -> Self { |
| 5684 | Some(input.0) |
| 5685 | } |
| 5686 | } |
| 5687 | impl From<ColormapEnum> for u16 { |
| 5688 | #[inline ] |
| 5689 | fn from(input: ColormapEnum) -> Self { |
| 5690 | u16::from(input.0) |
| 5691 | } |
| 5692 | } |
| 5693 | impl From<ColormapEnum> for Option<u16> { |
| 5694 | #[inline ] |
| 5695 | fn from(input: ColormapEnum) -> Self { |
| 5696 | Some(u16::from(input.0)) |
| 5697 | } |
| 5698 | } |
| 5699 | impl From<ColormapEnum> for u32 { |
| 5700 | #[inline ] |
| 5701 | fn from(input: ColormapEnum) -> Self { |
| 5702 | u32::from(input.0) |
| 5703 | } |
| 5704 | } |
| 5705 | impl From<ColormapEnum> for Option<u32> { |
| 5706 | #[inline ] |
| 5707 | fn from(input: ColormapEnum) -> Self { |
| 5708 | Some(u32::from(input.0)) |
| 5709 | } |
| 5710 | } |
| 5711 | impl From<u8> for ColormapEnum { |
| 5712 | #[inline ] |
| 5713 | fn from(value: u8) -> Self { |
| 5714 | Self(value) |
| 5715 | } |
| 5716 | } |
| 5717 | impl core::fmt::Debug for ColormapEnum { |
| 5718 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 5719 | let variants: [(u32, &'static str, &'static …); 1] = [ |
| 5720 | (Self::NONE.0.into(), "NONE" , "None" ), |
| 5721 | ]; |
| 5722 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 5723 | } |
| 5724 | } |
| 5725 | |
| 5726 | /// Opcode for the ColormapNotify event |
| 5727 | pub const COLORMAP_NOTIFY_EVENT: u8 = 32; |
| 5728 | /// the colormap for some window changed. |
| 5729 | /// |
| 5730 | /// # Fields |
| 5731 | /// |
| 5732 | /// * `window` - The window whose associated colormap is changed, installed or uninstalled. |
| 5733 | /// * `colormap` - The colormap which is changed, installed or uninstalled. This is `XCB_NONE` |
| 5734 | /// when the colormap is changed by a call to `FreeColormap`. |
| 5735 | /// * `_new` - Indicates whether the colormap was changed (1) or installed/uninstalled (0). |
| 5736 | /// * `state` - |
| 5737 | /// |
| 5738 | /// # See |
| 5739 | /// |
| 5740 | /// * `FreeColormap`: request |
| 5741 | #[derive (Clone, Copy, Default)] |
| 5742 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 5743 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5744 | pub struct ColormapNotifyEvent { |
| 5745 | pub response_type: u8, |
| 5746 | pub sequence: u16, |
| 5747 | pub window: Window, |
| 5748 | pub colormap: Colormap, |
| 5749 | pub new: bool, |
| 5750 | pub state: ColormapState, |
| 5751 | } |
| 5752 | impl_debug_if_no_extra_traits!(ColormapNotifyEvent, "ColormapNotifyEvent" ); |
| 5753 | impl TryParse for ColormapNotifyEvent { |
| 5754 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 5755 | let remaining: &[u8] = initial_value; |
| 5756 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5757 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 5758 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 5759 | let (window: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 5760 | let (colormap: u32, remaining: &[u8]) = Colormap::try_parse(remaining)?; |
| 5761 | let (new: bool, remaining: &[u8]) = bool::try_parse(remaining)?; |
| 5762 | let (state: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5763 | let remaining: &[u8] = remaining.get(2..).ok_or(err:ParseError::InsufficientData)?; |
| 5764 | let state: ColormapState = state.into(); |
| 5765 | let result: ColormapNotifyEvent = ColormapNotifyEvent { response_type, sequence, window, colormap, new, state }; |
| 5766 | let _ = remaining; |
| 5767 | let remaining: &[u8] = initial_value.get(32..) |
| 5768 | .ok_or(err:ParseError::InsufficientData)?; |
| 5769 | Ok((result, remaining)) |
| 5770 | } |
| 5771 | } |
| 5772 | impl Serialize for ColormapNotifyEvent { |
| 5773 | type Bytes = [u8; 16]; |
| 5774 | fn serialize(&self) -> [u8; 16] { |
| 5775 | let response_type_bytes = self.response_type.serialize(); |
| 5776 | let sequence_bytes = self.sequence.serialize(); |
| 5777 | let window_bytes = self.window.serialize(); |
| 5778 | let colormap_bytes = self.colormap.serialize(); |
| 5779 | let new_bytes = self.new.serialize(); |
| 5780 | let state_bytes = u8::from(self.state).serialize(); |
| 5781 | [ |
| 5782 | response_type_bytes[0], |
| 5783 | 0, |
| 5784 | sequence_bytes[0], |
| 5785 | sequence_bytes[1], |
| 5786 | window_bytes[0], |
| 5787 | window_bytes[1], |
| 5788 | window_bytes[2], |
| 5789 | window_bytes[3], |
| 5790 | colormap_bytes[0], |
| 5791 | colormap_bytes[1], |
| 5792 | colormap_bytes[2], |
| 5793 | colormap_bytes[3], |
| 5794 | new_bytes[0], |
| 5795 | state_bytes[0], |
| 5796 | 0, |
| 5797 | 0, |
| 5798 | ] |
| 5799 | } |
| 5800 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 5801 | bytes.reserve(16); |
| 5802 | self.response_type.serialize_into(bytes); |
| 5803 | bytes.extend_from_slice(&[0; 1]); |
| 5804 | self.sequence.serialize_into(bytes); |
| 5805 | self.window.serialize_into(bytes); |
| 5806 | self.colormap.serialize_into(bytes); |
| 5807 | self.new.serialize_into(bytes); |
| 5808 | u8::from(self.state).serialize_into(bytes); |
| 5809 | bytes.extend_from_slice(&[0; 2]); |
| 5810 | } |
| 5811 | } |
| 5812 | impl From<&ColormapNotifyEvent> for [u8; 32] { |
| 5813 | fn from(input: &ColormapNotifyEvent) -> Self { |
| 5814 | let response_type_bytes = input.response_type.serialize(); |
| 5815 | let sequence_bytes = input.sequence.serialize(); |
| 5816 | let window_bytes = input.window.serialize(); |
| 5817 | let colormap_bytes = input.colormap.serialize(); |
| 5818 | let new_bytes = input.new.serialize(); |
| 5819 | let state_bytes = u8::from(input.state).serialize(); |
| 5820 | [ |
| 5821 | response_type_bytes[0], |
| 5822 | 0, |
| 5823 | sequence_bytes[0], |
| 5824 | sequence_bytes[1], |
| 5825 | window_bytes[0], |
| 5826 | window_bytes[1], |
| 5827 | window_bytes[2], |
| 5828 | window_bytes[3], |
| 5829 | colormap_bytes[0], |
| 5830 | colormap_bytes[1], |
| 5831 | colormap_bytes[2], |
| 5832 | colormap_bytes[3], |
| 5833 | new_bytes[0], |
| 5834 | state_bytes[0], |
| 5835 | 0, |
| 5836 | 0, |
| 5837 | // trailing padding |
| 5838 | 0, |
| 5839 | 0, |
| 5840 | 0, |
| 5841 | 0, |
| 5842 | 0, |
| 5843 | 0, |
| 5844 | 0, |
| 5845 | 0, |
| 5846 | 0, |
| 5847 | 0, |
| 5848 | 0, |
| 5849 | 0, |
| 5850 | 0, |
| 5851 | 0, |
| 5852 | 0, |
| 5853 | 0, |
| 5854 | ] |
| 5855 | } |
| 5856 | } |
| 5857 | impl From<ColormapNotifyEvent> for [u8; 32] { |
| 5858 | fn from(input: ColormapNotifyEvent) -> Self { |
| 5859 | Self::from(&input) |
| 5860 | } |
| 5861 | } |
| 5862 | |
| 5863 | #[derive (Debug, Copy, Clone)] |
| 5864 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5865 | pub struct ClientMessageData([u8; 20]); |
| 5866 | impl ClientMessageData { |
| 5867 | pub fn as_data8(&self) -> [u8; 20] { |
| 5868 | fn do_the_parse(remaining: &[u8]) -> Result<[u8; 20], ParseError> { |
| 5869 | let (data8, remaining) = crate::x11_utils::parse_u8_array::<20>(remaining)?; |
| 5870 | let _ = remaining; |
| 5871 | Ok(data8) |
| 5872 | } |
| 5873 | do_the_parse(&self.0).unwrap() |
| 5874 | } |
| 5875 | pub fn as_data16(&self) -> [u16; 10] { |
| 5876 | fn do_the_parse(remaining: &[u8]) -> Result<[u16; 10], ParseError> { |
| 5877 | let (data16_0, remaining) = u16::try_parse(remaining)?; |
| 5878 | let (data16_1, remaining) = u16::try_parse(remaining)?; |
| 5879 | let (data16_2, remaining) = u16::try_parse(remaining)?; |
| 5880 | let (data16_3, remaining) = u16::try_parse(remaining)?; |
| 5881 | let (data16_4, remaining) = u16::try_parse(remaining)?; |
| 5882 | let (data16_5, remaining) = u16::try_parse(remaining)?; |
| 5883 | let (data16_6, remaining) = u16::try_parse(remaining)?; |
| 5884 | let (data16_7, remaining) = u16::try_parse(remaining)?; |
| 5885 | let (data16_8, remaining) = u16::try_parse(remaining)?; |
| 5886 | let (data16_9, remaining) = u16::try_parse(remaining)?; |
| 5887 | let data16 = [ |
| 5888 | data16_0, |
| 5889 | data16_1, |
| 5890 | data16_2, |
| 5891 | data16_3, |
| 5892 | data16_4, |
| 5893 | data16_5, |
| 5894 | data16_6, |
| 5895 | data16_7, |
| 5896 | data16_8, |
| 5897 | data16_9, |
| 5898 | ]; |
| 5899 | let _ = remaining; |
| 5900 | Ok(data16) |
| 5901 | } |
| 5902 | do_the_parse(&self.0).unwrap() |
| 5903 | } |
| 5904 | pub fn as_data32(&self) -> [u32; 5] { |
| 5905 | fn do_the_parse(remaining: &[u8]) -> Result<[u32; 5], ParseError> { |
| 5906 | let (data32_0, remaining) = u32::try_parse(remaining)?; |
| 5907 | let (data32_1, remaining) = u32::try_parse(remaining)?; |
| 5908 | let (data32_2, remaining) = u32::try_parse(remaining)?; |
| 5909 | let (data32_3, remaining) = u32::try_parse(remaining)?; |
| 5910 | let (data32_4, remaining) = u32::try_parse(remaining)?; |
| 5911 | let data32 = [ |
| 5912 | data32_0, |
| 5913 | data32_1, |
| 5914 | data32_2, |
| 5915 | data32_3, |
| 5916 | data32_4, |
| 5917 | ]; |
| 5918 | let _ = remaining; |
| 5919 | Ok(data32) |
| 5920 | } |
| 5921 | do_the_parse(&self.0).unwrap() |
| 5922 | } |
| 5923 | } |
| 5924 | impl Serialize for ClientMessageData { |
| 5925 | type Bytes = [u8; 20]; |
| 5926 | fn serialize(&self) -> [u8; 20] { |
| 5927 | self.0 |
| 5928 | } |
| 5929 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 5930 | bytes.extend_from_slice(&self.0); |
| 5931 | } |
| 5932 | } |
| 5933 | impl TryParse for ClientMessageData { |
| 5934 | fn try_parse(value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 5935 | let inner: [u8; 20] = valueResult<[u8; 20], TryFromSliceError>.get(..20) |
| 5936 | .ok_or(err:ParseError::InsufficientData)? |
| 5937 | .try_into() |
| 5938 | .unwrap(); |
| 5939 | let result: ClientMessageData = ClientMessageData(inner); |
| 5940 | Ok((result, &value[20..])) |
| 5941 | } |
| 5942 | } |
| 5943 | impl From<[u8; 20]> for ClientMessageData { |
| 5944 | fn from(data8: [u8; 20]) -> Self { |
| 5945 | Self(data8) |
| 5946 | } |
| 5947 | } |
| 5948 | impl From<[u16; 10]> for ClientMessageData { |
| 5949 | fn from(data16: [u16; 10]) -> Self { |
| 5950 | let data16_0_bytes = data16[0].serialize(); |
| 5951 | let data16_1_bytes = data16[1].serialize(); |
| 5952 | let data16_2_bytes = data16[2].serialize(); |
| 5953 | let data16_3_bytes = data16[3].serialize(); |
| 5954 | let data16_4_bytes = data16[4].serialize(); |
| 5955 | let data16_5_bytes = data16[5].serialize(); |
| 5956 | let data16_6_bytes = data16[6].serialize(); |
| 5957 | let data16_7_bytes = data16[7].serialize(); |
| 5958 | let data16_8_bytes = data16[8].serialize(); |
| 5959 | let data16_9_bytes = data16[9].serialize(); |
| 5960 | let value = [ |
| 5961 | data16_0_bytes[0], |
| 5962 | data16_0_bytes[1], |
| 5963 | data16_1_bytes[0], |
| 5964 | data16_1_bytes[1], |
| 5965 | data16_2_bytes[0], |
| 5966 | data16_2_bytes[1], |
| 5967 | data16_3_bytes[0], |
| 5968 | data16_3_bytes[1], |
| 5969 | data16_4_bytes[0], |
| 5970 | data16_4_bytes[1], |
| 5971 | data16_5_bytes[0], |
| 5972 | data16_5_bytes[1], |
| 5973 | data16_6_bytes[0], |
| 5974 | data16_6_bytes[1], |
| 5975 | data16_7_bytes[0], |
| 5976 | data16_7_bytes[1], |
| 5977 | data16_8_bytes[0], |
| 5978 | data16_8_bytes[1], |
| 5979 | data16_9_bytes[0], |
| 5980 | data16_9_bytes[1], |
| 5981 | ]; |
| 5982 | Self(value) |
| 5983 | } |
| 5984 | } |
| 5985 | impl From<[u32; 5]> for ClientMessageData { |
| 5986 | fn from(data32: [u32; 5]) -> Self { |
| 5987 | let data32_0_bytes = data32[0].serialize(); |
| 5988 | let data32_1_bytes = data32[1].serialize(); |
| 5989 | let data32_2_bytes = data32[2].serialize(); |
| 5990 | let data32_3_bytes = data32[3].serialize(); |
| 5991 | let data32_4_bytes = data32[4].serialize(); |
| 5992 | let value = [ |
| 5993 | data32_0_bytes[0], |
| 5994 | data32_0_bytes[1], |
| 5995 | data32_0_bytes[2], |
| 5996 | data32_0_bytes[3], |
| 5997 | data32_1_bytes[0], |
| 5998 | data32_1_bytes[1], |
| 5999 | data32_1_bytes[2], |
| 6000 | data32_1_bytes[3], |
| 6001 | data32_2_bytes[0], |
| 6002 | data32_2_bytes[1], |
| 6003 | data32_2_bytes[2], |
| 6004 | data32_2_bytes[3], |
| 6005 | data32_3_bytes[0], |
| 6006 | data32_3_bytes[1], |
| 6007 | data32_3_bytes[2], |
| 6008 | data32_3_bytes[3], |
| 6009 | data32_4_bytes[0], |
| 6010 | data32_4_bytes[1], |
| 6011 | data32_4_bytes[2], |
| 6012 | data32_4_bytes[3], |
| 6013 | ]; |
| 6014 | Self(value) |
| 6015 | } |
| 6016 | } |
| 6017 | |
| 6018 | /// Opcode for the ClientMessage event |
| 6019 | pub const CLIENT_MESSAGE_EVENT: u8 = 33; |
| 6020 | /// NOT YET DOCUMENTED. |
| 6021 | /// |
| 6022 | /// This event represents a ClientMessage, sent by another X11 client. An example |
| 6023 | /// is a client sending the `_NET_WM_STATE` ClientMessage to the root window |
| 6024 | /// to indicate the fullscreen window state, effectively requesting that the window |
| 6025 | /// manager puts it into fullscreen mode. |
| 6026 | /// |
| 6027 | /// # Fields |
| 6028 | /// |
| 6029 | /// * `format` - Specifies how to interpret `data`. Can be either 8, 16 or 32. |
| 6030 | /// * `type` - An atom which indicates how the data should be interpreted by the receiving |
| 6031 | /// client. |
| 6032 | /// * `data` - The data itself (20 bytes max). |
| 6033 | /// |
| 6034 | /// # See |
| 6035 | /// |
| 6036 | /// * `SendEvent`: request |
| 6037 | #[derive (Clone, Copy)] |
| 6038 | #[cfg_attr (feature = "extra-traits" , derive(Debug))] |
| 6039 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6040 | pub struct ClientMessageEvent { |
| 6041 | pub response_type: u8, |
| 6042 | pub format: u8, |
| 6043 | pub sequence: u16, |
| 6044 | pub window: Window, |
| 6045 | pub type_: Atom, |
| 6046 | pub data: ClientMessageData, |
| 6047 | } |
| 6048 | impl_debug_if_no_extra_traits!(ClientMessageEvent, "ClientMessageEvent" ); |
| 6049 | impl TryParse for ClientMessageEvent { |
| 6050 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 6051 | let remaining: &[u8] = initial_value; |
| 6052 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 6053 | let (format: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 6054 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 6055 | let (window: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 6056 | let (type_: u32, remaining: &[u8]) = Atom::try_parse(remaining)?; |
| 6057 | let (data: ClientMessageData, remaining: &[u8]) = ClientMessageData::try_parse(remaining)?; |
| 6058 | let result: ClientMessageEvent = ClientMessageEvent { response_type, format, sequence, window, type_, data }; |
| 6059 | let _ = remaining; |
| 6060 | let remaining: &[u8] = initial_value.get(32..) |
| 6061 | .ok_or(err:ParseError::InsufficientData)?; |
| 6062 | Ok((result, remaining)) |
| 6063 | } |
| 6064 | } |
| 6065 | impl Serialize for ClientMessageEvent { |
| 6066 | type Bytes = [u8; 32]; |
| 6067 | fn serialize(&self) -> [u8; 32] { |
| 6068 | let response_type_bytes = self.response_type.serialize(); |
| 6069 | let format_bytes = self.format.serialize(); |
| 6070 | let sequence_bytes = self.sequence.serialize(); |
| 6071 | let window_bytes = self.window.serialize(); |
| 6072 | let type_bytes = self.type_.serialize(); |
| 6073 | let data_bytes = self.data.serialize(); |
| 6074 | [ |
| 6075 | response_type_bytes[0], |
| 6076 | format_bytes[0], |
| 6077 | sequence_bytes[0], |
| 6078 | sequence_bytes[1], |
| 6079 | window_bytes[0], |
| 6080 | window_bytes[1], |
| 6081 | window_bytes[2], |
| 6082 | window_bytes[3], |
| 6083 | type_bytes[0], |
| 6084 | type_bytes[1], |
| 6085 | type_bytes[2], |
| 6086 | type_bytes[3], |
| 6087 | data_bytes[0], |
| 6088 | data_bytes[1], |
| 6089 | data_bytes[2], |
| 6090 | data_bytes[3], |
| 6091 | data_bytes[4], |
| 6092 | data_bytes[5], |
| 6093 | data_bytes[6], |
| 6094 | data_bytes[7], |
| 6095 | data_bytes[8], |
| 6096 | data_bytes[9], |
| 6097 | data_bytes[10], |
| 6098 | data_bytes[11], |
| 6099 | data_bytes[12], |
| 6100 | data_bytes[13], |
| 6101 | data_bytes[14], |
| 6102 | data_bytes[15], |
| 6103 | data_bytes[16], |
| 6104 | data_bytes[17], |
| 6105 | data_bytes[18], |
| 6106 | data_bytes[19], |
| 6107 | ] |
| 6108 | } |
| 6109 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 6110 | bytes.reserve(32); |
| 6111 | self.response_type.serialize_into(bytes); |
| 6112 | self.format.serialize_into(bytes); |
| 6113 | self.sequence.serialize_into(bytes); |
| 6114 | self.window.serialize_into(bytes); |
| 6115 | self.type_.serialize_into(bytes); |
| 6116 | self.data.serialize_into(bytes); |
| 6117 | } |
| 6118 | } |
| 6119 | impl From<&ClientMessageEvent> for [u8; 32] { |
| 6120 | fn from(input: &ClientMessageEvent) -> Self { |
| 6121 | let response_type_bytes = input.response_type.serialize(); |
| 6122 | let format_bytes = input.format.serialize(); |
| 6123 | let sequence_bytes = input.sequence.serialize(); |
| 6124 | let window_bytes = input.window.serialize(); |
| 6125 | let type_bytes = input.type_.serialize(); |
| 6126 | let data_bytes = input.data.serialize(); |
| 6127 | [ |
| 6128 | response_type_bytes[0], |
| 6129 | format_bytes[0], |
| 6130 | sequence_bytes[0], |
| 6131 | sequence_bytes[1], |
| 6132 | window_bytes[0], |
| 6133 | window_bytes[1], |
| 6134 | window_bytes[2], |
| 6135 | window_bytes[3], |
| 6136 | type_bytes[0], |
| 6137 | type_bytes[1], |
| 6138 | type_bytes[2], |
| 6139 | type_bytes[3], |
| 6140 | data_bytes[0], |
| 6141 | data_bytes[1], |
| 6142 | data_bytes[2], |
| 6143 | data_bytes[3], |
| 6144 | data_bytes[4], |
| 6145 | data_bytes[5], |
| 6146 | data_bytes[6], |
| 6147 | data_bytes[7], |
| 6148 | data_bytes[8], |
| 6149 | data_bytes[9], |
| 6150 | data_bytes[10], |
| 6151 | data_bytes[11], |
| 6152 | data_bytes[12], |
| 6153 | data_bytes[13], |
| 6154 | data_bytes[14], |
| 6155 | data_bytes[15], |
| 6156 | data_bytes[16], |
| 6157 | data_bytes[17], |
| 6158 | data_bytes[18], |
| 6159 | data_bytes[19], |
| 6160 | ] |
| 6161 | } |
| 6162 | } |
| 6163 | impl From<ClientMessageEvent> for [u8; 32] { |
| 6164 | fn from(input: ClientMessageEvent) -> Self { |
| 6165 | Self::from(&input) |
| 6166 | } |
| 6167 | } |
| 6168 | impl ClientMessageEvent { |
| 6169 | /// Create a new `ClientMessageEvent`. |
| 6170 | /// |
| 6171 | /// This function simplifies the creation of a `ClientMessageEvent` by applying |
| 6172 | /// some useful defaults: |
| 6173 | /// - `response_type = CLIENT_MESSAGE_EVENT` |
| 6174 | /// - `sequence = 0` |
| 6175 | /// |
| 6176 | /// The other fields are set from the parameters given to this function. |
| 6177 | pub fn new(format: u8, window: Window, type_: impl Into<Atom>, data: impl Into<ClientMessageData>) -> Self { |
| 6178 | Self { |
| 6179 | response_type: CLIENT_MESSAGE_EVENT, |
| 6180 | format, |
| 6181 | sequence: 0, |
| 6182 | window, |
| 6183 | type_: type_.into(), |
| 6184 | data: data.into(), |
| 6185 | } |
| 6186 | } |
| 6187 | } |
| 6188 | |
| 6189 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 6190 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6191 | pub struct Mapping(u8); |
| 6192 | impl Mapping { |
| 6193 | pub const MODIFIER: Self = Self(0); |
| 6194 | pub const KEYBOARD: Self = Self(1); |
| 6195 | pub const POINTER: Self = Self(2); |
| 6196 | } |
| 6197 | impl From<Mapping> for u8 { |
| 6198 | #[inline ] |
| 6199 | fn from(input: Mapping) -> Self { |
| 6200 | input.0 |
| 6201 | } |
| 6202 | } |
| 6203 | impl From<Mapping> for Option<u8> { |
| 6204 | #[inline ] |
| 6205 | fn from(input: Mapping) -> Self { |
| 6206 | Some(input.0) |
| 6207 | } |
| 6208 | } |
| 6209 | impl From<Mapping> for u16 { |
| 6210 | #[inline ] |
| 6211 | fn from(input: Mapping) -> Self { |
| 6212 | u16::from(input.0) |
| 6213 | } |
| 6214 | } |
| 6215 | impl From<Mapping> for Option<u16> { |
| 6216 | #[inline ] |
| 6217 | fn from(input: Mapping) -> Self { |
| 6218 | Some(u16::from(input.0)) |
| 6219 | } |
| 6220 | } |
| 6221 | impl From<Mapping> for u32 { |
| 6222 | #[inline ] |
| 6223 | fn from(input: Mapping) -> Self { |
| 6224 | u32::from(input.0) |
| 6225 | } |
| 6226 | } |
| 6227 | impl From<Mapping> for Option<u32> { |
| 6228 | #[inline ] |
| 6229 | fn from(input: Mapping) -> Self { |
| 6230 | Some(u32::from(input.0)) |
| 6231 | } |
| 6232 | } |
| 6233 | impl From<u8> for Mapping { |
| 6234 | #[inline ] |
| 6235 | fn from(value: u8) -> Self { |
| 6236 | Self(value) |
| 6237 | } |
| 6238 | } |
| 6239 | impl core::fmt::Debug for Mapping { |
| 6240 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 6241 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 6242 | (Self::MODIFIER.0.into(), "MODIFIER" , "Modifier" ), |
| 6243 | (Self::KEYBOARD.0.into(), "KEYBOARD" , "Keyboard" ), |
| 6244 | (Self::POINTER.0.into(), "POINTER" , "Pointer" ), |
| 6245 | ]; |
| 6246 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 6247 | } |
| 6248 | } |
| 6249 | |
| 6250 | /// Opcode for the MappingNotify event |
| 6251 | pub const MAPPING_NOTIFY_EVENT: u8 = 34; |
| 6252 | /// keyboard mapping changed. |
| 6253 | /// |
| 6254 | /// # Fields |
| 6255 | /// |
| 6256 | /// * `request` - |
| 6257 | /// * `first_keycode` - The first number in the range of the altered mapping. |
| 6258 | /// * `count` - The number of keycodes altered. |
| 6259 | #[derive (Clone, Copy, Default)] |
| 6260 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6261 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6262 | pub struct MappingNotifyEvent { |
| 6263 | pub response_type: u8, |
| 6264 | pub sequence: u16, |
| 6265 | pub request: Mapping, |
| 6266 | pub first_keycode: Keycode, |
| 6267 | pub count: u8, |
| 6268 | } |
| 6269 | impl_debug_if_no_extra_traits!(MappingNotifyEvent, "MappingNotifyEvent" ); |
| 6270 | impl TryParse for MappingNotifyEvent { |
| 6271 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 6272 | let remaining: &[u8] = initial_value; |
| 6273 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 6274 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 6275 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 6276 | let (request: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 6277 | let (first_keycode: u8, remaining: &[u8]) = Keycode::try_parse(remaining)?; |
| 6278 | let (count: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 6279 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 6280 | let request: Mapping = request.into(); |
| 6281 | let result: MappingNotifyEvent = MappingNotifyEvent { response_type, sequence, request, first_keycode, count }; |
| 6282 | let _ = remaining; |
| 6283 | let remaining: &[u8] = initial_value.get(32..) |
| 6284 | .ok_or(err:ParseError::InsufficientData)?; |
| 6285 | Ok((result, remaining)) |
| 6286 | } |
| 6287 | } |
| 6288 | impl Serialize for MappingNotifyEvent { |
| 6289 | type Bytes = [u8; 8]; |
| 6290 | fn serialize(&self) -> [u8; 8] { |
| 6291 | let response_type_bytes = self.response_type.serialize(); |
| 6292 | let sequence_bytes = self.sequence.serialize(); |
| 6293 | let request_bytes = u8::from(self.request).serialize(); |
| 6294 | let first_keycode_bytes = self.first_keycode.serialize(); |
| 6295 | let count_bytes = self.count.serialize(); |
| 6296 | [ |
| 6297 | response_type_bytes[0], |
| 6298 | 0, |
| 6299 | sequence_bytes[0], |
| 6300 | sequence_bytes[1], |
| 6301 | request_bytes[0], |
| 6302 | first_keycode_bytes[0], |
| 6303 | count_bytes[0], |
| 6304 | 0, |
| 6305 | ] |
| 6306 | } |
| 6307 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 6308 | bytes.reserve(8); |
| 6309 | self.response_type.serialize_into(bytes); |
| 6310 | bytes.extend_from_slice(&[0; 1]); |
| 6311 | self.sequence.serialize_into(bytes); |
| 6312 | u8::from(self.request).serialize_into(bytes); |
| 6313 | self.first_keycode.serialize_into(bytes); |
| 6314 | self.count.serialize_into(bytes); |
| 6315 | bytes.extend_from_slice(&[0; 1]); |
| 6316 | } |
| 6317 | } |
| 6318 | impl From<&MappingNotifyEvent> for [u8; 32] { |
| 6319 | fn from(input: &MappingNotifyEvent) -> Self { |
| 6320 | let response_type_bytes = input.response_type.serialize(); |
| 6321 | let sequence_bytes = input.sequence.serialize(); |
| 6322 | let request_bytes = u8::from(input.request).serialize(); |
| 6323 | let first_keycode_bytes = input.first_keycode.serialize(); |
| 6324 | let count_bytes = input.count.serialize(); |
| 6325 | [ |
| 6326 | response_type_bytes[0], |
| 6327 | 0, |
| 6328 | sequence_bytes[0], |
| 6329 | sequence_bytes[1], |
| 6330 | request_bytes[0], |
| 6331 | first_keycode_bytes[0], |
| 6332 | count_bytes[0], |
| 6333 | 0, |
| 6334 | // trailing padding |
| 6335 | 0, |
| 6336 | 0, |
| 6337 | 0, |
| 6338 | 0, |
| 6339 | 0, |
| 6340 | 0, |
| 6341 | 0, |
| 6342 | 0, |
| 6343 | 0, |
| 6344 | 0, |
| 6345 | 0, |
| 6346 | 0, |
| 6347 | 0, |
| 6348 | 0, |
| 6349 | 0, |
| 6350 | 0, |
| 6351 | 0, |
| 6352 | 0, |
| 6353 | 0, |
| 6354 | 0, |
| 6355 | 0, |
| 6356 | 0, |
| 6357 | 0, |
| 6358 | 0, |
| 6359 | ] |
| 6360 | } |
| 6361 | } |
| 6362 | impl From<MappingNotifyEvent> for [u8; 32] { |
| 6363 | fn from(input: MappingNotifyEvent) -> Self { |
| 6364 | Self::from(&input) |
| 6365 | } |
| 6366 | } |
| 6367 | |
| 6368 | /// Opcode for the GeGeneric event |
| 6369 | pub const GE_GENERIC_EVENT: u8 = 35; |
| 6370 | /// generic event (with length). |
| 6371 | /// |
| 6372 | /// # Fields |
| 6373 | /// |
| 6374 | /// * `extension` - The major opcode of the extension creating this event |
| 6375 | /// * `length` - The amount (in 4-byte units) of data beyond 32 bytes |
| 6376 | /// * `evtype` - The extension-specific event type |
| 6377 | #[derive (Clone, Copy, Default)] |
| 6378 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6379 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6380 | pub struct GeGenericEvent { |
| 6381 | pub response_type: u8, |
| 6382 | pub extension: u8, |
| 6383 | pub sequence: u16, |
| 6384 | pub length: u32, |
| 6385 | pub event_type: u16, |
| 6386 | } |
| 6387 | impl_debug_if_no_extra_traits!(GeGenericEvent, "GeGenericEvent" ); |
| 6388 | impl TryParse for GeGenericEvent { |
| 6389 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 6390 | let remaining: &[u8] = initial_value; |
| 6391 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 6392 | let (extension: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 6393 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 6394 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 6395 | let (event_type: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 6396 | let remaining: &[u8] = remaining.get(22..).ok_or(err:ParseError::InsufficientData)?; |
| 6397 | let result: GeGenericEvent = GeGenericEvent { response_type, extension, sequence, length, event_type }; |
| 6398 | let _ = remaining; |
| 6399 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 6400 | .ok_or(err:ParseError::InsufficientData)?; |
| 6401 | Ok((result, remaining)) |
| 6402 | } |
| 6403 | } |
| 6404 | impl Serialize for GeGenericEvent { |
| 6405 | type Bytes = [u8; 32]; |
| 6406 | fn serialize(&self) -> [u8; 32] { |
| 6407 | let response_type_bytes = self.response_type.serialize(); |
| 6408 | let extension_bytes = self.extension.serialize(); |
| 6409 | let sequence_bytes = self.sequence.serialize(); |
| 6410 | let length_bytes = self.length.serialize(); |
| 6411 | let event_type_bytes = self.event_type.serialize(); |
| 6412 | [ |
| 6413 | response_type_bytes[0], |
| 6414 | extension_bytes[0], |
| 6415 | sequence_bytes[0], |
| 6416 | sequence_bytes[1], |
| 6417 | length_bytes[0], |
| 6418 | length_bytes[1], |
| 6419 | length_bytes[2], |
| 6420 | length_bytes[3], |
| 6421 | event_type_bytes[0], |
| 6422 | event_type_bytes[1], |
| 6423 | 0, |
| 6424 | 0, |
| 6425 | 0, |
| 6426 | 0, |
| 6427 | 0, |
| 6428 | 0, |
| 6429 | 0, |
| 6430 | 0, |
| 6431 | 0, |
| 6432 | 0, |
| 6433 | 0, |
| 6434 | 0, |
| 6435 | 0, |
| 6436 | 0, |
| 6437 | 0, |
| 6438 | 0, |
| 6439 | 0, |
| 6440 | 0, |
| 6441 | 0, |
| 6442 | 0, |
| 6443 | 0, |
| 6444 | 0, |
| 6445 | ] |
| 6446 | } |
| 6447 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 6448 | bytes.reserve(32); |
| 6449 | self.response_type.serialize_into(bytes); |
| 6450 | self.extension.serialize_into(bytes); |
| 6451 | self.sequence.serialize_into(bytes); |
| 6452 | self.length.serialize_into(bytes); |
| 6453 | self.event_type.serialize_into(bytes); |
| 6454 | bytes.extend_from_slice(&[0; 22]); |
| 6455 | } |
| 6456 | } |
| 6457 | |
| 6458 | /// Opcode for the Request error |
| 6459 | pub const REQUEST_ERROR: u8 = 1; |
| 6460 | |
| 6461 | /// Opcode for the Value error |
| 6462 | pub const VALUE_ERROR: u8 = 2; |
| 6463 | |
| 6464 | /// Opcode for the Window error |
| 6465 | pub const WINDOW_ERROR: u8 = 3; |
| 6466 | |
| 6467 | /// Opcode for the Pixmap error |
| 6468 | pub const PIXMAP_ERROR: u8 = 4; |
| 6469 | |
| 6470 | /// Opcode for the Atom error |
| 6471 | pub const ATOM_ERROR: u8 = 5; |
| 6472 | |
| 6473 | /// Opcode for the Cursor error |
| 6474 | pub const CURSOR_ERROR: u8 = 6; |
| 6475 | |
| 6476 | /// Opcode for the Font error |
| 6477 | pub const FONT_ERROR: u8 = 7; |
| 6478 | |
| 6479 | /// Opcode for the Match error |
| 6480 | pub const MATCH_ERROR: u8 = 8; |
| 6481 | |
| 6482 | /// Opcode for the Drawable error |
| 6483 | pub const DRAWABLE_ERROR: u8 = 9; |
| 6484 | |
| 6485 | /// Opcode for the Access error |
| 6486 | pub const ACCESS_ERROR: u8 = 10; |
| 6487 | |
| 6488 | /// Opcode for the Alloc error |
| 6489 | pub const ALLOC_ERROR: u8 = 11; |
| 6490 | |
| 6491 | /// Opcode for the Colormap error |
| 6492 | pub const COLORMAP_ERROR: u8 = 12; |
| 6493 | |
| 6494 | /// Opcode for the GContext error |
| 6495 | pub const G_CONTEXT_ERROR: u8 = 13; |
| 6496 | |
| 6497 | /// Opcode for the IDChoice error |
| 6498 | pub const ID_CHOICE_ERROR: u8 = 14; |
| 6499 | |
| 6500 | /// Opcode for the Name error |
| 6501 | pub const NAME_ERROR: u8 = 15; |
| 6502 | |
| 6503 | /// Opcode for the Length error |
| 6504 | pub const LENGTH_ERROR: u8 = 16; |
| 6505 | |
| 6506 | /// Opcode for the Implementation error |
| 6507 | pub const IMPLEMENTATION_ERROR: u8 = 17; |
| 6508 | |
| 6509 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 6510 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6511 | pub struct WindowClass(u16); |
| 6512 | impl WindowClass { |
| 6513 | pub const COPY_FROM_PARENT: Self = Self(0); |
| 6514 | pub const INPUT_OUTPUT: Self = Self(1); |
| 6515 | pub const INPUT_ONLY: Self = Self(2); |
| 6516 | } |
| 6517 | impl From<WindowClass> for u16 { |
| 6518 | #[inline ] |
| 6519 | fn from(input: WindowClass) -> Self { |
| 6520 | input.0 |
| 6521 | } |
| 6522 | } |
| 6523 | impl From<WindowClass> for Option<u16> { |
| 6524 | #[inline ] |
| 6525 | fn from(input: WindowClass) -> Self { |
| 6526 | Some(input.0) |
| 6527 | } |
| 6528 | } |
| 6529 | impl From<WindowClass> for u32 { |
| 6530 | #[inline ] |
| 6531 | fn from(input: WindowClass) -> Self { |
| 6532 | u32::from(input.0) |
| 6533 | } |
| 6534 | } |
| 6535 | impl From<WindowClass> for Option<u32> { |
| 6536 | #[inline ] |
| 6537 | fn from(input: WindowClass) -> Self { |
| 6538 | Some(u32::from(input.0)) |
| 6539 | } |
| 6540 | } |
| 6541 | impl From<u8> for WindowClass { |
| 6542 | #[inline ] |
| 6543 | fn from(value: u8) -> Self { |
| 6544 | Self(value.into()) |
| 6545 | } |
| 6546 | } |
| 6547 | impl From<u16> for WindowClass { |
| 6548 | #[inline ] |
| 6549 | fn from(value: u16) -> Self { |
| 6550 | Self(value) |
| 6551 | } |
| 6552 | } |
| 6553 | impl core::fmt::Debug for WindowClass { |
| 6554 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 6555 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 6556 | (Self::COPY_FROM_PARENT.0.into(), "COPY_FROM_PARENT" , "CopyFromParent" ), |
| 6557 | (Self::INPUT_OUTPUT.0.into(), "INPUT_OUTPUT" , "InputOutput" ), |
| 6558 | (Self::INPUT_ONLY.0.into(), "INPUT_ONLY" , "InputOnly" ), |
| 6559 | ]; |
| 6560 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 6561 | } |
| 6562 | } |
| 6563 | |
| 6564 | /// # Fields |
| 6565 | /// |
| 6566 | /// * `BackPixmap` - Overrides the default background-pixmap. The background pixmap and window must |
| 6567 | /// have the same root and same depth. Any size pixmap can be used, although some |
| 6568 | /// sizes may be faster than others. |
| 6569 | /// |
| 6570 | /// If `XCB_BACK_PIXMAP_NONE` is specified, the window has no defined background. |
| 6571 | /// The server may fill the contents with the previous screen contents or with |
| 6572 | /// contents of its own choosing. |
| 6573 | /// |
| 6574 | /// If `XCB_BACK_PIXMAP_PARENT_RELATIVE` is specified, the parent's background is |
| 6575 | /// used, but the window must have the same depth as the parent (or a Match error |
| 6576 | /// results). The parent's background is tracked, and the current version is |
| 6577 | /// used each time the window background is required. |
| 6578 | /// * `BackPixel` - Overrides `BackPixmap`. A pixmap of undefined size filled with the specified |
| 6579 | /// background pixel is used for the background. Range-checking is not performed, |
| 6580 | /// the background pixel is truncated to the appropriate number of bits. |
| 6581 | /// * `BorderPixmap` - Overrides the default border-pixmap. The border pixmap and window must have the |
| 6582 | /// same root and the same depth. Any size pixmap can be used, although some sizes |
| 6583 | /// may be faster than others. |
| 6584 | /// |
| 6585 | /// The special value `XCB_COPY_FROM_PARENT` means the parent's border pixmap is |
| 6586 | /// copied (subsequent changes to the parent's border attribute do not affect the |
| 6587 | /// child), but the window must have the same depth as the parent. |
| 6588 | /// * `BorderPixel` - Overrides `BorderPixmap`. A pixmap of undefined size filled with the specified |
| 6589 | /// border pixel is used for the border. Range checking is not performed on the |
| 6590 | /// border-pixel value, it is truncated to the appropriate number of bits. |
| 6591 | /// * `BitGravity` - Defines which region of the window should be retained if the window is resized. |
| 6592 | /// * `WinGravity` - Defines how the window should be repositioned if the parent is resized (see |
| 6593 | /// `ConfigureWindow`). |
| 6594 | /// * `BackingStore` - A backing-store of `WhenMapped` advises the server that maintaining contents of |
| 6595 | /// obscured regions when the window is mapped would be beneficial. A backing-store |
| 6596 | /// of `Always` advises the server that maintaining contents even when the window |
| 6597 | /// is unmapped would be beneficial. In this case, the server may generate an |
| 6598 | /// exposure event when the window is created. A value of `NotUseful` advises the |
| 6599 | /// server that maintaining contents is unnecessary, although a server may still |
| 6600 | /// choose to maintain contents while the window is mapped. Note that if the server |
| 6601 | /// maintains contents, then the server should maintain complete contents not just |
| 6602 | /// the region within the parent boundaries, even if the window is larger than its |
| 6603 | /// parent. While the server maintains contents, exposure events will not normally |
| 6604 | /// be generated, but the server may stop maintaining contents at any time. |
| 6605 | /// * `BackingPlanes` - The backing-planes indicates (with bits set to 1) which bit planes of the |
| 6606 | /// window hold dynamic data that must be preserved in backing-stores and during |
| 6607 | /// save-unders. |
| 6608 | /// * `BackingPixel` - The backing-pixel specifies what value to use in planes not covered by |
| 6609 | /// backing-planes. The server is free to save only the specified bit planes in the |
| 6610 | /// backing-store or save-under and regenerate the remaining planes with the |
| 6611 | /// specified pixel value. Any bits beyond the specified depth of the window in |
| 6612 | /// these values are simply ignored. |
| 6613 | /// * `OverrideRedirect` - The override-redirect specifies whether map and configure requests on this |
| 6614 | /// window should override a SubstructureRedirect on the parent, typically to |
| 6615 | /// inform a window manager not to tamper with the window. |
| 6616 | /// * `SaveUnder` - If 1, the server is advised that when this window is mapped, saving the |
| 6617 | /// contents of windows it obscures would be beneficial. |
| 6618 | /// * `EventMask` - The event-mask defines which events the client is interested in for this window |
| 6619 | /// (or for some event types, inferiors of the window). |
| 6620 | /// * `DontPropagate` - The do-not-propagate-mask defines which events should not be propagated to |
| 6621 | /// ancestor windows when no client has the event type selected in this window. |
| 6622 | /// * `Colormap` - The colormap specifies the colormap that best reflects the true colors of the window. Servers |
| 6623 | /// capable of supporting multiple hardware colormaps may use this information, and window man- |
| 6624 | /// agers may use it for InstallColormap requests. The colormap must have the same visual type |
| 6625 | /// and root as the window (or a Match error results). If CopyFromParent is specified, the parent's |
| 6626 | /// colormap is copied (subsequent changes to the parent's colormap attribute do not affect the child). |
| 6627 | /// However, the window must have the same visual type as the parent (or a Match error results), |
| 6628 | /// and the parent must not have a colormap of None (or a Match error results). For an explanation |
| 6629 | /// of None, see FreeColormap request. The colormap is copied by sharing the colormap object |
| 6630 | /// between the child and the parent, not by making a complete copy of the colormap contents. |
| 6631 | /// * `Cursor` - If a cursor is specified, it will be used whenever the pointer is in the window. If None is speci- |
| 6632 | /// fied, the parent's cursor will be used when the pointer is in the window, and any change in the |
| 6633 | /// parent's cursor will cause an immediate change in the displayed cursor. |
| 6634 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 6635 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6636 | pub struct CW(u32); |
| 6637 | impl CW { |
| 6638 | pub const BACK_PIXMAP: Self = Self(1 << 0); |
| 6639 | pub const BACK_PIXEL: Self = Self(1 << 1); |
| 6640 | pub const BORDER_PIXMAP: Self = Self(1 << 2); |
| 6641 | pub const BORDER_PIXEL: Self = Self(1 << 3); |
| 6642 | pub const BIT_GRAVITY: Self = Self(1 << 4); |
| 6643 | pub const WIN_GRAVITY: Self = Self(1 << 5); |
| 6644 | pub const BACKING_STORE: Self = Self(1 << 6); |
| 6645 | pub const BACKING_PLANES: Self = Self(1 << 7); |
| 6646 | pub const BACKING_PIXEL: Self = Self(1 << 8); |
| 6647 | pub const OVERRIDE_REDIRECT: Self = Self(1 << 9); |
| 6648 | pub const SAVE_UNDER: Self = Self(1 << 10); |
| 6649 | pub const EVENT_MASK: Self = Self(1 << 11); |
| 6650 | pub const DONT_PROPAGATE: Self = Self(1 << 12); |
| 6651 | pub const COLORMAP: Self = Self(1 << 13); |
| 6652 | pub const CURSOR: Self = Self(1 << 14); |
| 6653 | } |
| 6654 | impl From<CW> for u32 { |
| 6655 | #[inline ] |
| 6656 | fn from(input: CW) -> Self { |
| 6657 | input.0 |
| 6658 | } |
| 6659 | } |
| 6660 | impl From<CW> for Option<u32> { |
| 6661 | #[inline ] |
| 6662 | fn from(input: CW) -> Self { |
| 6663 | Some(input.0) |
| 6664 | } |
| 6665 | } |
| 6666 | impl From<u8> for CW { |
| 6667 | #[inline ] |
| 6668 | fn from(value: u8) -> Self { |
| 6669 | Self(value.into()) |
| 6670 | } |
| 6671 | } |
| 6672 | impl From<u16> for CW { |
| 6673 | #[inline ] |
| 6674 | fn from(value: u16) -> Self { |
| 6675 | Self(value.into()) |
| 6676 | } |
| 6677 | } |
| 6678 | impl From<u32> for CW { |
| 6679 | #[inline ] |
| 6680 | fn from(value: u32) -> Self { |
| 6681 | Self(value) |
| 6682 | } |
| 6683 | } |
| 6684 | impl core::fmt::Debug for CW { |
| 6685 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 6686 | let variants: [(u32, &'static str, &'static …); 15] = [ |
| 6687 | (Self::BACK_PIXMAP.0, "BACK_PIXMAP" , "BackPixmap" ), |
| 6688 | (Self::BACK_PIXEL.0, "BACK_PIXEL" , "BackPixel" ), |
| 6689 | (Self::BORDER_PIXMAP.0, "BORDER_PIXMAP" , "BorderPixmap" ), |
| 6690 | (Self::BORDER_PIXEL.0, "BORDER_PIXEL" , "BorderPixel" ), |
| 6691 | (Self::BIT_GRAVITY.0, "BIT_GRAVITY" , "BitGravity" ), |
| 6692 | (Self::WIN_GRAVITY.0, "WIN_GRAVITY" , "WinGravity" ), |
| 6693 | (Self::BACKING_STORE.0, "BACKING_STORE" , "BackingStore" ), |
| 6694 | (Self::BACKING_PLANES.0, "BACKING_PLANES" , "BackingPlanes" ), |
| 6695 | (Self::BACKING_PIXEL.0, "BACKING_PIXEL" , "BackingPixel" ), |
| 6696 | (Self::OVERRIDE_REDIRECT.0, "OVERRIDE_REDIRECT" , "OverrideRedirect" ), |
| 6697 | (Self::SAVE_UNDER.0, "SAVE_UNDER" , "SaveUnder" ), |
| 6698 | (Self::EVENT_MASK.0, "EVENT_MASK" , "EventMask" ), |
| 6699 | (Self::DONT_PROPAGATE.0, "DONT_PROPAGATE" , "DontPropagate" ), |
| 6700 | (Self::COLORMAP.0, "COLORMAP" , "Colormap" ), |
| 6701 | (Self::CURSOR.0, "CURSOR" , "Cursor" ), |
| 6702 | ]; |
| 6703 | pretty_print_bitmask(fmt, self.0, &variants) |
| 6704 | } |
| 6705 | } |
| 6706 | bitmask_binop!(CW, u32); |
| 6707 | |
| 6708 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 6709 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6710 | pub struct BackPixmap(bool); |
| 6711 | impl BackPixmap { |
| 6712 | pub const NONE: Self = Self(false); |
| 6713 | pub const PARENT_RELATIVE: Self = Self(true); |
| 6714 | } |
| 6715 | impl From<BackPixmap> for bool { |
| 6716 | #[inline ] |
| 6717 | fn from(input: BackPixmap) -> Self { |
| 6718 | input.0 |
| 6719 | } |
| 6720 | } |
| 6721 | impl From<BackPixmap> for Option<bool> { |
| 6722 | #[inline ] |
| 6723 | fn from(input: BackPixmap) -> Self { |
| 6724 | Some(input.0) |
| 6725 | } |
| 6726 | } |
| 6727 | impl From<BackPixmap> for u8 { |
| 6728 | #[inline ] |
| 6729 | fn from(input: BackPixmap) -> Self { |
| 6730 | u8::from(input.0) |
| 6731 | } |
| 6732 | } |
| 6733 | impl From<BackPixmap> for Option<u8> { |
| 6734 | #[inline ] |
| 6735 | fn from(input: BackPixmap) -> Self { |
| 6736 | Some(u8::from(input.0)) |
| 6737 | } |
| 6738 | } |
| 6739 | impl From<BackPixmap> for u16 { |
| 6740 | #[inline ] |
| 6741 | fn from(input: BackPixmap) -> Self { |
| 6742 | u16::from(input.0) |
| 6743 | } |
| 6744 | } |
| 6745 | impl From<BackPixmap> for Option<u16> { |
| 6746 | #[inline ] |
| 6747 | fn from(input: BackPixmap) -> Self { |
| 6748 | Some(u16::from(input.0)) |
| 6749 | } |
| 6750 | } |
| 6751 | impl From<BackPixmap> for u32 { |
| 6752 | #[inline ] |
| 6753 | fn from(input: BackPixmap) -> Self { |
| 6754 | u32::from(input.0) |
| 6755 | } |
| 6756 | } |
| 6757 | impl From<BackPixmap> for Option<u32> { |
| 6758 | #[inline ] |
| 6759 | fn from(input: BackPixmap) -> Self { |
| 6760 | Some(u32::from(input.0)) |
| 6761 | } |
| 6762 | } |
| 6763 | impl From<bool> for BackPixmap { |
| 6764 | #[inline ] |
| 6765 | fn from(value: bool) -> Self { |
| 6766 | Self(value) |
| 6767 | } |
| 6768 | } |
| 6769 | impl core::fmt::Debug for BackPixmap { |
| 6770 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 6771 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 6772 | (Self::NONE.0.into(), "NONE" , "None" ), |
| 6773 | (Self::PARENT_RELATIVE.0.into(), "PARENT_RELATIVE" , "ParentRelative" ), |
| 6774 | ]; |
| 6775 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 6776 | } |
| 6777 | } |
| 6778 | |
| 6779 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 6780 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6781 | pub struct Gravity(u32); |
| 6782 | impl Gravity { |
| 6783 | pub const BIT_FORGET: Self = Self(0); |
| 6784 | pub const WIN_UNMAP: Self = Self(0); |
| 6785 | pub const NORTH_WEST: Self = Self(1); |
| 6786 | pub const NORTH: Self = Self(2); |
| 6787 | pub const NORTH_EAST: Self = Self(3); |
| 6788 | pub const WEST: Self = Self(4); |
| 6789 | pub const CENTER: Self = Self(5); |
| 6790 | pub const EAST: Self = Self(6); |
| 6791 | pub const SOUTH_WEST: Self = Self(7); |
| 6792 | pub const SOUTH: Self = Self(8); |
| 6793 | pub const SOUTH_EAST: Self = Self(9); |
| 6794 | pub const STATIC: Self = Self(10); |
| 6795 | } |
| 6796 | impl From<Gravity> for u32 { |
| 6797 | #[inline ] |
| 6798 | fn from(input: Gravity) -> Self { |
| 6799 | input.0 |
| 6800 | } |
| 6801 | } |
| 6802 | impl From<Gravity> for Option<u32> { |
| 6803 | #[inline ] |
| 6804 | fn from(input: Gravity) -> Self { |
| 6805 | Some(input.0) |
| 6806 | } |
| 6807 | } |
| 6808 | impl From<u8> for Gravity { |
| 6809 | #[inline ] |
| 6810 | fn from(value: u8) -> Self { |
| 6811 | Self(value.into()) |
| 6812 | } |
| 6813 | } |
| 6814 | impl From<u16> for Gravity { |
| 6815 | #[inline ] |
| 6816 | fn from(value: u16) -> Self { |
| 6817 | Self(value.into()) |
| 6818 | } |
| 6819 | } |
| 6820 | impl From<u32> for Gravity { |
| 6821 | #[inline ] |
| 6822 | fn from(value: u32) -> Self { |
| 6823 | Self(value) |
| 6824 | } |
| 6825 | } |
| 6826 | impl core::fmt::Debug for Gravity { |
| 6827 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 6828 | let variants: [(u32, &'static str, &'static …); 12] = [ |
| 6829 | (Self::BIT_FORGET.0, "BIT_FORGET" , "BitForget" ), |
| 6830 | (Self::WIN_UNMAP.0, "WIN_UNMAP" , "WinUnmap" ), |
| 6831 | (Self::NORTH_WEST.0, "NORTH_WEST" , "NorthWest" ), |
| 6832 | (Self::NORTH.0, "NORTH" , "North" ), |
| 6833 | (Self::NORTH_EAST.0, "NORTH_EAST" , "NorthEast" ), |
| 6834 | (Self::WEST.0, "WEST" , "West" ), |
| 6835 | (Self::CENTER.0, "CENTER" , "Center" ), |
| 6836 | (Self::EAST.0, "EAST" , "East" ), |
| 6837 | (Self::SOUTH_WEST.0, "SOUTH_WEST" , "SouthWest" ), |
| 6838 | (Self::SOUTH.0, "SOUTH" , "South" ), |
| 6839 | (Self::SOUTH_EAST.0, "SOUTH_EAST" , "SouthEast" ), |
| 6840 | (Self::STATIC.0, "STATIC" , "Static" ), |
| 6841 | ]; |
| 6842 | pretty_print_enum(fmt, self.0, &variants) |
| 6843 | } |
| 6844 | } |
| 6845 | |
| 6846 | /// Auxiliary and optional information for the `create_window` function |
| 6847 | #[derive (Clone, Copy, Default)] |
| 6848 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6849 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6850 | pub struct CreateWindowAux { |
| 6851 | pub background_pixmap: Option<Pixmap>, |
| 6852 | pub background_pixel: Option<u32>, |
| 6853 | pub border_pixmap: Option<Pixmap>, |
| 6854 | pub border_pixel: Option<u32>, |
| 6855 | pub bit_gravity: Option<Gravity>, |
| 6856 | pub win_gravity: Option<Gravity>, |
| 6857 | pub backing_store: Option<BackingStore>, |
| 6858 | pub backing_planes: Option<u32>, |
| 6859 | pub backing_pixel: Option<u32>, |
| 6860 | pub override_redirect: Option<Bool32>, |
| 6861 | pub save_under: Option<Bool32>, |
| 6862 | pub event_mask: Option<EventMask>, |
| 6863 | pub do_not_propogate_mask: Option<EventMask>, |
| 6864 | pub colormap: Option<Colormap>, |
| 6865 | pub cursor: Option<Cursor>, |
| 6866 | } |
| 6867 | impl_debug_if_no_extra_traits!(CreateWindowAux, "CreateWindowAux" ); |
| 6868 | impl CreateWindowAux { |
| 6869 | #[cfg_attr (not(feature = "request-parsing" ), allow(dead_code))] |
| 6870 | fn try_parse(value: &[u8], value_mask: u32) -> Result<(Self, &[u8]), ParseError> { |
| 6871 | let switch_expr = u32::from(value_mask); |
| 6872 | let mut outer_remaining = value; |
| 6873 | let background_pixmap = if switch_expr & u32::from(CW::BACK_PIXMAP) != 0 { |
| 6874 | let remaining = outer_remaining; |
| 6875 | let (background_pixmap, remaining) = Pixmap::try_parse(remaining)?; |
| 6876 | outer_remaining = remaining; |
| 6877 | Some(background_pixmap) |
| 6878 | } else { |
| 6879 | None |
| 6880 | }; |
| 6881 | let background_pixel = if switch_expr & u32::from(CW::BACK_PIXEL) != 0 { |
| 6882 | let remaining = outer_remaining; |
| 6883 | let (background_pixel, remaining) = u32::try_parse(remaining)?; |
| 6884 | outer_remaining = remaining; |
| 6885 | Some(background_pixel) |
| 6886 | } else { |
| 6887 | None |
| 6888 | }; |
| 6889 | let border_pixmap = if switch_expr & u32::from(CW::BORDER_PIXMAP) != 0 { |
| 6890 | let remaining = outer_remaining; |
| 6891 | let (border_pixmap, remaining) = Pixmap::try_parse(remaining)?; |
| 6892 | outer_remaining = remaining; |
| 6893 | Some(border_pixmap) |
| 6894 | } else { |
| 6895 | None |
| 6896 | }; |
| 6897 | let border_pixel = if switch_expr & u32::from(CW::BORDER_PIXEL) != 0 { |
| 6898 | let remaining = outer_remaining; |
| 6899 | let (border_pixel, remaining) = u32::try_parse(remaining)?; |
| 6900 | outer_remaining = remaining; |
| 6901 | Some(border_pixel) |
| 6902 | } else { |
| 6903 | None |
| 6904 | }; |
| 6905 | let bit_gravity = if switch_expr & u32::from(CW::BIT_GRAVITY) != 0 { |
| 6906 | let remaining = outer_remaining; |
| 6907 | let (bit_gravity, remaining) = u32::try_parse(remaining)?; |
| 6908 | let bit_gravity = bit_gravity.into(); |
| 6909 | outer_remaining = remaining; |
| 6910 | Some(bit_gravity) |
| 6911 | } else { |
| 6912 | None |
| 6913 | }; |
| 6914 | let win_gravity = if switch_expr & u32::from(CW::WIN_GRAVITY) != 0 { |
| 6915 | let remaining = outer_remaining; |
| 6916 | let (win_gravity, remaining) = u32::try_parse(remaining)?; |
| 6917 | let win_gravity = win_gravity.into(); |
| 6918 | outer_remaining = remaining; |
| 6919 | Some(win_gravity) |
| 6920 | } else { |
| 6921 | None |
| 6922 | }; |
| 6923 | let backing_store = if switch_expr & u32::from(CW::BACKING_STORE) != 0 { |
| 6924 | let remaining = outer_remaining; |
| 6925 | let (backing_store, remaining) = u32::try_parse(remaining)?; |
| 6926 | let backing_store = backing_store.into(); |
| 6927 | outer_remaining = remaining; |
| 6928 | Some(backing_store) |
| 6929 | } else { |
| 6930 | None |
| 6931 | }; |
| 6932 | let backing_planes = if switch_expr & u32::from(CW::BACKING_PLANES) != 0 { |
| 6933 | let remaining = outer_remaining; |
| 6934 | let (backing_planes, remaining) = u32::try_parse(remaining)?; |
| 6935 | outer_remaining = remaining; |
| 6936 | Some(backing_planes) |
| 6937 | } else { |
| 6938 | None |
| 6939 | }; |
| 6940 | let backing_pixel = if switch_expr & u32::from(CW::BACKING_PIXEL) != 0 { |
| 6941 | let remaining = outer_remaining; |
| 6942 | let (backing_pixel, remaining) = u32::try_parse(remaining)?; |
| 6943 | outer_remaining = remaining; |
| 6944 | Some(backing_pixel) |
| 6945 | } else { |
| 6946 | None |
| 6947 | }; |
| 6948 | let override_redirect = if switch_expr & u32::from(CW::OVERRIDE_REDIRECT) != 0 { |
| 6949 | let remaining = outer_remaining; |
| 6950 | let (override_redirect, remaining) = Bool32::try_parse(remaining)?; |
| 6951 | outer_remaining = remaining; |
| 6952 | Some(override_redirect) |
| 6953 | } else { |
| 6954 | None |
| 6955 | }; |
| 6956 | let save_under = if switch_expr & u32::from(CW::SAVE_UNDER) != 0 { |
| 6957 | let remaining = outer_remaining; |
| 6958 | let (save_under, remaining) = Bool32::try_parse(remaining)?; |
| 6959 | outer_remaining = remaining; |
| 6960 | Some(save_under) |
| 6961 | } else { |
| 6962 | None |
| 6963 | }; |
| 6964 | let event_mask = if switch_expr & u32::from(CW::EVENT_MASK) != 0 { |
| 6965 | let remaining = outer_remaining; |
| 6966 | let (event_mask, remaining) = u32::try_parse(remaining)?; |
| 6967 | let event_mask = event_mask.into(); |
| 6968 | outer_remaining = remaining; |
| 6969 | Some(event_mask) |
| 6970 | } else { |
| 6971 | None |
| 6972 | }; |
| 6973 | let do_not_propogate_mask = if switch_expr & u32::from(CW::DONT_PROPAGATE) != 0 { |
| 6974 | let remaining = outer_remaining; |
| 6975 | let (do_not_propogate_mask, remaining) = u32::try_parse(remaining)?; |
| 6976 | let do_not_propogate_mask = do_not_propogate_mask.into(); |
| 6977 | outer_remaining = remaining; |
| 6978 | Some(do_not_propogate_mask) |
| 6979 | } else { |
| 6980 | None |
| 6981 | }; |
| 6982 | let colormap = if switch_expr & u32::from(CW::COLORMAP) != 0 { |
| 6983 | let remaining = outer_remaining; |
| 6984 | let (colormap, remaining) = Colormap::try_parse(remaining)?; |
| 6985 | outer_remaining = remaining; |
| 6986 | Some(colormap) |
| 6987 | } else { |
| 6988 | None |
| 6989 | }; |
| 6990 | let cursor = if switch_expr & u32::from(CW::CURSOR) != 0 { |
| 6991 | let remaining = outer_remaining; |
| 6992 | let (cursor, remaining) = Cursor::try_parse(remaining)?; |
| 6993 | outer_remaining = remaining; |
| 6994 | Some(cursor) |
| 6995 | } else { |
| 6996 | None |
| 6997 | }; |
| 6998 | let result = CreateWindowAux { background_pixmap, background_pixel, border_pixmap, border_pixel, bit_gravity, win_gravity, backing_store, backing_planes, backing_pixel, override_redirect, save_under, event_mask, do_not_propogate_mask, colormap, cursor }; |
| 6999 | Ok((result, outer_remaining)) |
| 7000 | } |
| 7001 | } |
| 7002 | impl CreateWindowAux { |
| 7003 | #[allow (dead_code)] |
| 7004 | fn serialize(&self, value_mask: u32) -> Vec<u8> { |
| 7005 | let mut result = Vec::new(); |
| 7006 | self.serialize_into(&mut result, u32::from(value_mask)); |
| 7007 | result |
| 7008 | } |
| 7009 | fn serialize_into(&self, bytes: &mut Vec<u8>, value_mask: u32) { |
| 7010 | assert_eq!(self.switch_expr(), u32::from(value_mask), "switch `value_list` has an inconsistent discriminant" ); |
| 7011 | if let Some(background_pixmap) = self.background_pixmap { |
| 7012 | background_pixmap.serialize_into(bytes); |
| 7013 | } |
| 7014 | if let Some(background_pixel) = self.background_pixel { |
| 7015 | background_pixel.serialize_into(bytes); |
| 7016 | } |
| 7017 | if let Some(border_pixmap) = self.border_pixmap { |
| 7018 | border_pixmap.serialize_into(bytes); |
| 7019 | } |
| 7020 | if let Some(border_pixel) = self.border_pixel { |
| 7021 | border_pixel.serialize_into(bytes); |
| 7022 | } |
| 7023 | if let Some(bit_gravity) = self.bit_gravity { |
| 7024 | u32::from(bit_gravity).serialize_into(bytes); |
| 7025 | } |
| 7026 | if let Some(win_gravity) = self.win_gravity { |
| 7027 | u32::from(win_gravity).serialize_into(bytes); |
| 7028 | } |
| 7029 | if let Some(backing_store) = self.backing_store { |
| 7030 | u32::from(backing_store).serialize_into(bytes); |
| 7031 | } |
| 7032 | if let Some(backing_planes) = self.backing_planes { |
| 7033 | backing_planes.serialize_into(bytes); |
| 7034 | } |
| 7035 | if let Some(backing_pixel) = self.backing_pixel { |
| 7036 | backing_pixel.serialize_into(bytes); |
| 7037 | } |
| 7038 | if let Some(override_redirect) = self.override_redirect { |
| 7039 | override_redirect.serialize_into(bytes); |
| 7040 | } |
| 7041 | if let Some(save_under) = self.save_under { |
| 7042 | save_under.serialize_into(bytes); |
| 7043 | } |
| 7044 | if let Some(event_mask) = self.event_mask { |
| 7045 | u32::from(event_mask).serialize_into(bytes); |
| 7046 | } |
| 7047 | if let Some(do_not_propogate_mask) = self.do_not_propogate_mask { |
| 7048 | u32::from(do_not_propogate_mask).serialize_into(bytes); |
| 7049 | } |
| 7050 | if let Some(colormap) = self.colormap { |
| 7051 | colormap.serialize_into(bytes); |
| 7052 | } |
| 7053 | if let Some(cursor) = self.cursor { |
| 7054 | cursor.serialize_into(bytes); |
| 7055 | } |
| 7056 | } |
| 7057 | } |
| 7058 | impl CreateWindowAux { |
| 7059 | fn switch_expr(&self) -> u32 { |
| 7060 | let mut expr_value = 0; |
| 7061 | if self.background_pixmap.is_some() { |
| 7062 | expr_value |= u32::from(CW::BACK_PIXMAP); |
| 7063 | } |
| 7064 | if self.background_pixel.is_some() { |
| 7065 | expr_value |= u32::from(CW::BACK_PIXEL); |
| 7066 | } |
| 7067 | if self.border_pixmap.is_some() { |
| 7068 | expr_value |= u32::from(CW::BORDER_PIXMAP); |
| 7069 | } |
| 7070 | if self.border_pixel.is_some() { |
| 7071 | expr_value |= u32::from(CW::BORDER_PIXEL); |
| 7072 | } |
| 7073 | if self.bit_gravity.is_some() { |
| 7074 | expr_value |= u32::from(CW::BIT_GRAVITY); |
| 7075 | } |
| 7076 | if self.win_gravity.is_some() { |
| 7077 | expr_value |= u32::from(CW::WIN_GRAVITY); |
| 7078 | } |
| 7079 | if self.backing_store.is_some() { |
| 7080 | expr_value |= u32::from(CW::BACKING_STORE); |
| 7081 | } |
| 7082 | if self.backing_planes.is_some() { |
| 7083 | expr_value |= u32::from(CW::BACKING_PLANES); |
| 7084 | } |
| 7085 | if self.backing_pixel.is_some() { |
| 7086 | expr_value |= u32::from(CW::BACKING_PIXEL); |
| 7087 | } |
| 7088 | if self.override_redirect.is_some() { |
| 7089 | expr_value |= u32::from(CW::OVERRIDE_REDIRECT); |
| 7090 | } |
| 7091 | if self.save_under.is_some() { |
| 7092 | expr_value |= u32::from(CW::SAVE_UNDER); |
| 7093 | } |
| 7094 | if self.event_mask.is_some() { |
| 7095 | expr_value |= u32::from(CW::EVENT_MASK); |
| 7096 | } |
| 7097 | if self.do_not_propogate_mask.is_some() { |
| 7098 | expr_value |= u32::from(CW::DONT_PROPAGATE); |
| 7099 | } |
| 7100 | if self.colormap.is_some() { |
| 7101 | expr_value |= u32::from(CW::COLORMAP); |
| 7102 | } |
| 7103 | if self.cursor.is_some() { |
| 7104 | expr_value |= u32::from(CW::CURSOR); |
| 7105 | } |
| 7106 | expr_value |
| 7107 | } |
| 7108 | } |
| 7109 | impl CreateWindowAux { |
| 7110 | /// Create a new instance with all fields unset / not present. |
| 7111 | pub fn new() -> Self { |
| 7112 | Default::default() |
| 7113 | } |
| 7114 | /// Set the `background_pixmap` field of this structure. |
| 7115 | #[must_use ] |
| 7116 | pub fn background_pixmap<I>(mut self, value: I) -> Self where I: Into<Option<Pixmap>> { |
| 7117 | self.background_pixmap = value.into(); |
| 7118 | self |
| 7119 | } |
| 7120 | /// Set the `background_pixel` field of this structure. |
| 7121 | #[must_use ] |
| 7122 | pub fn background_pixel<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 7123 | self.background_pixel = value.into(); |
| 7124 | self |
| 7125 | } |
| 7126 | /// Set the `border_pixmap` field of this structure. |
| 7127 | #[must_use ] |
| 7128 | pub fn border_pixmap<I>(mut self, value: I) -> Self where I: Into<Option<Pixmap>> { |
| 7129 | self.border_pixmap = value.into(); |
| 7130 | self |
| 7131 | } |
| 7132 | /// Set the `border_pixel` field of this structure. |
| 7133 | #[must_use ] |
| 7134 | pub fn border_pixel<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 7135 | self.border_pixel = value.into(); |
| 7136 | self |
| 7137 | } |
| 7138 | /// Set the `bit_gravity` field of this structure. |
| 7139 | #[must_use ] |
| 7140 | pub fn bit_gravity<I>(mut self, value: I) -> Self where I: Into<Option<Gravity>> { |
| 7141 | self.bit_gravity = value.into(); |
| 7142 | self |
| 7143 | } |
| 7144 | /// Set the `win_gravity` field of this structure. |
| 7145 | #[must_use ] |
| 7146 | pub fn win_gravity<I>(mut self, value: I) -> Self where I: Into<Option<Gravity>> { |
| 7147 | self.win_gravity = value.into(); |
| 7148 | self |
| 7149 | } |
| 7150 | /// Set the `backing_store` field of this structure. |
| 7151 | #[must_use ] |
| 7152 | pub fn backing_store<I>(mut self, value: I) -> Self where I: Into<Option<BackingStore>> { |
| 7153 | self.backing_store = value.into(); |
| 7154 | self |
| 7155 | } |
| 7156 | /// Set the `backing_planes` field of this structure. |
| 7157 | #[must_use ] |
| 7158 | pub fn backing_planes<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 7159 | self.backing_planes = value.into(); |
| 7160 | self |
| 7161 | } |
| 7162 | /// Set the `backing_pixel` field of this structure. |
| 7163 | #[must_use ] |
| 7164 | pub fn backing_pixel<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 7165 | self.backing_pixel = value.into(); |
| 7166 | self |
| 7167 | } |
| 7168 | /// Set the `override_redirect` field of this structure. |
| 7169 | #[must_use ] |
| 7170 | pub fn override_redirect<I>(mut self, value: I) -> Self where I: Into<Option<Bool32>> { |
| 7171 | self.override_redirect = value.into(); |
| 7172 | self |
| 7173 | } |
| 7174 | /// Set the `save_under` field of this structure. |
| 7175 | #[must_use ] |
| 7176 | pub fn save_under<I>(mut self, value: I) -> Self where I: Into<Option<Bool32>> { |
| 7177 | self.save_under = value.into(); |
| 7178 | self |
| 7179 | } |
| 7180 | /// Set the `event_mask` field of this structure. |
| 7181 | #[must_use ] |
| 7182 | pub fn event_mask<I>(mut self, value: I) -> Self where I: Into<Option<EventMask>> { |
| 7183 | self.event_mask = value.into(); |
| 7184 | self |
| 7185 | } |
| 7186 | /// Set the `do_not_propogate_mask` field of this structure. |
| 7187 | #[must_use ] |
| 7188 | pub fn do_not_propogate_mask<I>(mut self, value: I) -> Self where I: Into<Option<EventMask>> { |
| 7189 | self.do_not_propogate_mask = value.into(); |
| 7190 | self |
| 7191 | } |
| 7192 | /// Set the `colormap` field of this structure. |
| 7193 | #[must_use ] |
| 7194 | pub fn colormap<I>(mut self, value: I) -> Self where I: Into<Option<Colormap>> { |
| 7195 | self.colormap = value.into(); |
| 7196 | self |
| 7197 | } |
| 7198 | /// Set the `cursor` field of this structure. |
| 7199 | #[must_use ] |
| 7200 | pub fn cursor<I>(mut self, value: I) -> Self where I: Into<Option<Cursor>> { |
| 7201 | self.cursor = value.into(); |
| 7202 | self |
| 7203 | } |
| 7204 | } |
| 7205 | |
| 7206 | /// Opcode for the CreateWindow request |
| 7207 | pub const CREATE_WINDOW_REQUEST: u8 = 1; |
| 7208 | /// Creates a window. |
| 7209 | /// |
| 7210 | /// Creates an unmapped window as child of the specified `parent` window. A |
| 7211 | /// CreateNotify event will be generated. The new window is placed on top in the |
| 7212 | /// stacking order with respect to siblings. |
| 7213 | /// |
| 7214 | /// The coordinate system has the X axis horizontal and the Y axis vertical with |
| 7215 | /// the origin [0, 0] at the upper-left corner. Coordinates are integral, in terms |
| 7216 | /// of pixels, and coincide with pixel centers. Each window and pixmap has its own |
| 7217 | /// coordinate system. For a window, the origin is inside the border at the inside, |
| 7218 | /// upper-left corner. |
| 7219 | /// |
| 7220 | /// The created window is not yet displayed (mapped), call `xcb_map_window` to |
| 7221 | /// display it. |
| 7222 | /// |
| 7223 | /// The created window will initially use the same cursor as its parent. |
| 7224 | /// |
| 7225 | /// # Fields |
| 7226 | /// |
| 7227 | /// * `wid` - The ID with which you will refer to the new window, created by |
| 7228 | /// `xcb_generate_id`. |
| 7229 | /// * `depth` - Specifies the new window's depth (TODO: what unit?). |
| 7230 | /// |
| 7231 | /// The special value `XCB_COPY_FROM_PARENT` means the depth is taken from the |
| 7232 | /// `parent` window. |
| 7233 | /// * `visual` - Specifies the id for the new window's visual. |
| 7234 | /// |
| 7235 | /// The special value `XCB_COPY_FROM_PARENT` means the visual is taken from the |
| 7236 | /// `parent` window. |
| 7237 | /// * `class` - |
| 7238 | /// * `parent` - The parent window of the new window. |
| 7239 | /// * `border_width` - TODO: |
| 7240 | /// |
| 7241 | /// Must be zero if the `class` is `InputOnly` or a `xcb_match_error_t` occurs. |
| 7242 | /// * `x` - The X coordinate of the new window. |
| 7243 | /// * `y` - The Y coordinate of the new window. |
| 7244 | /// * `width` - The width of the new window. |
| 7245 | /// * `height` - The height of the new window. |
| 7246 | /// |
| 7247 | /// # Errors |
| 7248 | /// |
| 7249 | /// * `Colormap` - TODO: reasons? |
| 7250 | /// * `Match` - TODO: reasons? |
| 7251 | /// * `Cursor` - TODO: reasons? |
| 7252 | /// * `Pixmap` - TODO: reasons? |
| 7253 | /// * `Value` - TODO: reasons? |
| 7254 | /// * `Window` - TODO: reasons? |
| 7255 | /// * `Alloc` - The X server could not allocate the requested resources (no memory?). |
| 7256 | /// |
| 7257 | /// # See |
| 7258 | /// |
| 7259 | /// * `xcb_generate_id`: function |
| 7260 | /// * `MapWindow`: request |
| 7261 | /// * `CreateNotify`: event |
| 7262 | #[derive (Clone, Default)] |
| 7263 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 7264 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 7265 | pub struct CreateWindowRequest<'input> { |
| 7266 | pub depth: u8, |
| 7267 | pub wid: Window, |
| 7268 | pub parent: Window, |
| 7269 | pub x: i16, |
| 7270 | pub y: i16, |
| 7271 | pub width: u16, |
| 7272 | pub height: u16, |
| 7273 | pub border_width: u16, |
| 7274 | pub class: WindowClass, |
| 7275 | pub visual: Visualid, |
| 7276 | pub value_list: Cow<'input, CreateWindowAux>, |
| 7277 | } |
| 7278 | impl_debug_if_no_extra_traits!(CreateWindowRequest<'_>, "CreateWindowRequest" ); |
| 7279 | impl<'input> CreateWindowRequest<'input> { |
| 7280 | /// Serialize this request into bytes for the provided connection |
| 7281 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 7282 | let length_so_far = 0; |
| 7283 | let depth_bytes = self.depth.serialize(); |
| 7284 | let wid_bytes = self.wid.serialize(); |
| 7285 | let parent_bytes = self.parent.serialize(); |
| 7286 | let x_bytes = self.x.serialize(); |
| 7287 | let y_bytes = self.y.serialize(); |
| 7288 | let width_bytes = self.width.serialize(); |
| 7289 | let height_bytes = self.height.serialize(); |
| 7290 | let border_width_bytes = self.border_width.serialize(); |
| 7291 | let class_bytes = u16::from(self.class).serialize(); |
| 7292 | let visual_bytes = self.visual.serialize(); |
| 7293 | let value_mask: u32 = self.value_list.switch_expr(); |
| 7294 | let value_mask_bytes = value_mask.serialize(); |
| 7295 | let mut request0 = vec![ |
| 7296 | CREATE_WINDOW_REQUEST, |
| 7297 | depth_bytes[0], |
| 7298 | 0, |
| 7299 | 0, |
| 7300 | wid_bytes[0], |
| 7301 | wid_bytes[1], |
| 7302 | wid_bytes[2], |
| 7303 | wid_bytes[3], |
| 7304 | parent_bytes[0], |
| 7305 | parent_bytes[1], |
| 7306 | parent_bytes[2], |
| 7307 | parent_bytes[3], |
| 7308 | x_bytes[0], |
| 7309 | x_bytes[1], |
| 7310 | y_bytes[0], |
| 7311 | y_bytes[1], |
| 7312 | width_bytes[0], |
| 7313 | width_bytes[1], |
| 7314 | height_bytes[0], |
| 7315 | height_bytes[1], |
| 7316 | border_width_bytes[0], |
| 7317 | border_width_bytes[1], |
| 7318 | class_bytes[0], |
| 7319 | class_bytes[1], |
| 7320 | visual_bytes[0], |
| 7321 | visual_bytes[1], |
| 7322 | visual_bytes[2], |
| 7323 | visual_bytes[3], |
| 7324 | value_mask_bytes[0], |
| 7325 | value_mask_bytes[1], |
| 7326 | value_mask_bytes[2], |
| 7327 | value_mask_bytes[3], |
| 7328 | ]; |
| 7329 | let length_so_far = length_so_far + request0.len(); |
| 7330 | let value_list_bytes = self.value_list.serialize(u32::from(value_mask)); |
| 7331 | let length_so_far = length_so_far + value_list_bytes.len(); |
| 7332 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 7333 | let length_so_far = length_so_far + padding0.len(); |
| 7334 | assert_eq!(length_so_far % 4, 0); |
| 7335 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 7336 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 7337 | ([request0.into(), value_list_bytes.into(), padding0.into()], vec![]) |
| 7338 | } |
| 7339 | /// Parse this request given its header, its body, and any fds that go along with it |
| 7340 | #[cfg (feature = "request-parsing" )] |
| 7341 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 7342 | if header.major_opcode != CREATE_WINDOW_REQUEST { |
| 7343 | return Err(ParseError::InvalidValue); |
| 7344 | } |
| 7345 | let remaining = &[header.minor_opcode]; |
| 7346 | let (depth, remaining) = u8::try_parse(remaining)?; |
| 7347 | let _ = remaining; |
| 7348 | let (wid, remaining) = Window::try_parse(value)?; |
| 7349 | let (parent, remaining) = Window::try_parse(remaining)?; |
| 7350 | let (x, remaining) = i16::try_parse(remaining)?; |
| 7351 | let (y, remaining) = i16::try_parse(remaining)?; |
| 7352 | let (width, remaining) = u16::try_parse(remaining)?; |
| 7353 | let (height, remaining) = u16::try_parse(remaining)?; |
| 7354 | let (border_width, remaining) = u16::try_parse(remaining)?; |
| 7355 | let (class, remaining) = u16::try_parse(remaining)?; |
| 7356 | let class = class.into(); |
| 7357 | let (visual, remaining) = Visualid::try_parse(remaining)?; |
| 7358 | let (value_mask, remaining) = u32::try_parse(remaining)?; |
| 7359 | let (value_list, remaining) = CreateWindowAux::try_parse(remaining, u32::from(value_mask))?; |
| 7360 | let _ = remaining; |
| 7361 | Ok(CreateWindowRequest { |
| 7362 | depth, |
| 7363 | wid, |
| 7364 | parent, |
| 7365 | x, |
| 7366 | y, |
| 7367 | width, |
| 7368 | height, |
| 7369 | border_width, |
| 7370 | class, |
| 7371 | visual, |
| 7372 | value_list: Cow::Owned(value_list), |
| 7373 | }) |
| 7374 | } |
| 7375 | /// Clone all borrowed data in this CreateWindowRequest. |
| 7376 | pub fn into_owned(self) -> CreateWindowRequest<'static> { |
| 7377 | CreateWindowRequest { |
| 7378 | depth: self.depth, |
| 7379 | wid: self.wid, |
| 7380 | parent: self.parent, |
| 7381 | x: self.x, |
| 7382 | y: self.y, |
| 7383 | width: self.width, |
| 7384 | height: self.height, |
| 7385 | border_width: self.border_width, |
| 7386 | class: self.class, |
| 7387 | visual: self.visual, |
| 7388 | value_list: Cow::Owned(self.value_list.into_owned()), |
| 7389 | } |
| 7390 | } |
| 7391 | } |
| 7392 | impl<'input> Request for CreateWindowRequest<'input> { |
| 7393 | const EXTENSION_NAME: Option<&'static str> = None; |
| 7394 | |
| 7395 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 7396 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 7397 | // Flatten the buffers into a single vector |
| 7398 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 7399 | (buf, fds) |
| 7400 | } |
| 7401 | } |
| 7402 | impl<'input> crate::x11_utils::VoidRequest for CreateWindowRequest<'input> { |
| 7403 | } |
| 7404 | |
| 7405 | /// Auxiliary and optional information for the `change_window_attributes` function |
| 7406 | #[derive (Clone, Copy, Default)] |
| 7407 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 7408 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 7409 | pub struct ChangeWindowAttributesAux { |
| 7410 | pub background_pixmap: Option<Pixmap>, |
| 7411 | pub background_pixel: Option<u32>, |
| 7412 | pub border_pixmap: Option<Pixmap>, |
| 7413 | pub border_pixel: Option<u32>, |
| 7414 | pub bit_gravity: Option<Gravity>, |
| 7415 | pub win_gravity: Option<Gravity>, |
| 7416 | pub backing_store: Option<BackingStore>, |
| 7417 | pub backing_planes: Option<u32>, |
| 7418 | pub backing_pixel: Option<u32>, |
| 7419 | pub override_redirect: Option<Bool32>, |
| 7420 | pub save_under: Option<Bool32>, |
| 7421 | pub event_mask: Option<EventMask>, |
| 7422 | pub do_not_propogate_mask: Option<EventMask>, |
| 7423 | pub colormap: Option<Colormap>, |
| 7424 | pub cursor: Option<Cursor>, |
| 7425 | } |
| 7426 | impl_debug_if_no_extra_traits!(ChangeWindowAttributesAux, "ChangeWindowAttributesAux" ); |
| 7427 | impl ChangeWindowAttributesAux { |
| 7428 | #[cfg_attr (not(feature = "request-parsing" ), allow(dead_code))] |
| 7429 | fn try_parse(value: &[u8], value_mask: u32) -> Result<(Self, &[u8]), ParseError> { |
| 7430 | let switch_expr = u32::from(value_mask); |
| 7431 | let mut outer_remaining = value; |
| 7432 | let background_pixmap = if switch_expr & u32::from(CW::BACK_PIXMAP) != 0 { |
| 7433 | let remaining = outer_remaining; |
| 7434 | let (background_pixmap, remaining) = Pixmap::try_parse(remaining)?; |
| 7435 | outer_remaining = remaining; |
| 7436 | Some(background_pixmap) |
| 7437 | } else { |
| 7438 | None |
| 7439 | }; |
| 7440 | let background_pixel = if switch_expr & u32::from(CW::BACK_PIXEL) != 0 { |
| 7441 | let remaining = outer_remaining; |
| 7442 | let (background_pixel, remaining) = u32::try_parse(remaining)?; |
| 7443 | outer_remaining = remaining; |
| 7444 | Some(background_pixel) |
| 7445 | } else { |
| 7446 | None |
| 7447 | }; |
| 7448 | let border_pixmap = if switch_expr & u32::from(CW::BORDER_PIXMAP) != 0 { |
| 7449 | let remaining = outer_remaining; |
| 7450 | let (border_pixmap, remaining) = Pixmap::try_parse(remaining)?; |
| 7451 | outer_remaining = remaining; |
| 7452 | Some(border_pixmap) |
| 7453 | } else { |
| 7454 | None |
| 7455 | }; |
| 7456 | let border_pixel = if switch_expr & u32::from(CW::BORDER_PIXEL) != 0 { |
| 7457 | let remaining = outer_remaining; |
| 7458 | let (border_pixel, remaining) = u32::try_parse(remaining)?; |
| 7459 | outer_remaining = remaining; |
| 7460 | Some(border_pixel) |
| 7461 | } else { |
| 7462 | None |
| 7463 | }; |
| 7464 | let bit_gravity = if switch_expr & u32::from(CW::BIT_GRAVITY) != 0 { |
| 7465 | let remaining = outer_remaining; |
| 7466 | let (bit_gravity, remaining) = u32::try_parse(remaining)?; |
| 7467 | let bit_gravity = bit_gravity.into(); |
| 7468 | outer_remaining = remaining; |
| 7469 | Some(bit_gravity) |
| 7470 | } else { |
| 7471 | None |
| 7472 | }; |
| 7473 | let win_gravity = if switch_expr & u32::from(CW::WIN_GRAVITY) != 0 { |
| 7474 | let remaining = outer_remaining; |
| 7475 | let (win_gravity, remaining) = u32::try_parse(remaining)?; |
| 7476 | let win_gravity = win_gravity.into(); |
| 7477 | outer_remaining = remaining; |
| 7478 | Some(win_gravity) |
| 7479 | } else { |
| 7480 | None |
| 7481 | }; |
| 7482 | let backing_store = if switch_expr & u32::from(CW::BACKING_STORE) != 0 { |
| 7483 | let remaining = outer_remaining; |
| 7484 | let (backing_store, remaining) = u32::try_parse(remaining)?; |
| 7485 | let backing_store = backing_store.into(); |
| 7486 | outer_remaining = remaining; |
| 7487 | Some(backing_store) |
| 7488 | } else { |
| 7489 | None |
| 7490 | }; |
| 7491 | let backing_planes = if switch_expr & u32::from(CW::BACKING_PLANES) != 0 { |
| 7492 | let remaining = outer_remaining; |
| 7493 | let (backing_planes, remaining) = u32::try_parse(remaining)?; |
| 7494 | outer_remaining = remaining; |
| 7495 | Some(backing_planes) |
| 7496 | } else { |
| 7497 | None |
| 7498 | }; |
| 7499 | let backing_pixel = if switch_expr & u32::from(CW::BACKING_PIXEL) != 0 { |
| 7500 | let remaining = outer_remaining; |
| 7501 | let (backing_pixel, remaining) = u32::try_parse(remaining)?; |
| 7502 | outer_remaining = remaining; |
| 7503 | Some(backing_pixel) |
| 7504 | } else { |
| 7505 | None |
| 7506 | }; |
| 7507 | let override_redirect = if switch_expr & u32::from(CW::OVERRIDE_REDIRECT) != 0 { |
| 7508 | let remaining = outer_remaining; |
| 7509 | let (override_redirect, remaining) = Bool32::try_parse(remaining)?; |
| 7510 | outer_remaining = remaining; |
| 7511 | Some(override_redirect) |
| 7512 | } else { |
| 7513 | None |
| 7514 | }; |
| 7515 | let save_under = if switch_expr & u32::from(CW::SAVE_UNDER) != 0 { |
| 7516 | let remaining = outer_remaining; |
| 7517 | let (save_under, remaining) = Bool32::try_parse(remaining)?; |
| 7518 | outer_remaining = remaining; |
| 7519 | Some(save_under) |
| 7520 | } else { |
| 7521 | None |
| 7522 | }; |
| 7523 | let event_mask = if switch_expr & u32::from(CW::EVENT_MASK) != 0 { |
| 7524 | let remaining = outer_remaining; |
| 7525 | let (event_mask, remaining) = u32::try_parse(remaining)?; |
| 7526 | let event_mask = event_mask.into(); |
| 7527 | outer_remaining = remaining; |
| 7528 | Some(event_mask) |
| 7529 | } else { |
| 7530 | None |
| 7531 | }; |
| 7532 | let do_not_propogate_mask = if switch_expr & u32::from(CW::DONT_PROPAGATE) != 0 { |
| 7533 | let remaining = outer_remaining; |
| 7534 | let (do_not_propogate_mask, remaining) = u32::try_parse(remaining)?; |
| 7535 | let do_not_propogate_mask = do_not_propogate_mask.into(); |
| 7536 | outer_remaining = remaining; |
| 7537 | Some(do_not_propogate_mask) |
| 7538 | } else { |
| 7539 | None |
| 7540 | }; |
| 7541 | let colormap = if switch_expr & u32::from(CW::COLORMAP) != 0 { |
| 7542 | let remaining = outer_remaining; |
| 7543 | let (colormap, remaining) = Colormap::try_parse(remaining)?; |
| 7544 | outer_remaining = remaining; |
| 7545 | Some(colormap) |
| 7546 | } else { |
| 7547 | None |
| 7548 | }; |
| 7549 | let cursor = if switch_expr & u32::from(CW::CURSOR) != 0 { |
| 7550 | let remaining = outer_remaining; |
| 7551 | let (cursor, remaining) = Cursor::try_parse(remaining)?; |
| 7552 | outer_remaining = remaining; |
| 7553 | Some(cursor) |
| 7554 | } else { |
| 7555 | None |
| 7556 | }; |
| 7557 | let result = ChangeWindowAttributesAux { background_pixmap, background_pixel, border_pixmap, border_pixel, bit_gravity, win_gravity, backing_store, backing_planes, backing_pixel, override_redirect, save_under, event_mask, do_not_propogate_mask, colormap, cursor }; |
| 7558 | Ok((result, outer_remaining)) |
| 7559 | } |
| 7560 | } |
| 7561 | impl ChangeWindowAttributesAux { |
| 7562 | #[allow (dead_code)] |
| 7563 | fn serialize(&self, value_mask: u32) -> Vec<u8> { |
| 7564 | let mut result = Vec::new(); |
| 7565 | self.serialize_into(&mut result, u32::from(value_mask)); |
| 7566 | result |
| 7567 | } |
| 7568 | fn serialize_into(&self, bytes: &mut Vec<u8>, value_mask: u32) { |
| 7569 | assert_eq!(self.switch_expr(), u32::from(value_mask), "switch `value_list` has an inconsistent discriminant" ); |
| 7570 | if let Some(background_pixmap) = self.background_pixmap { |
| 7571 | background_pixmap.serialize_into(bytes); |
| 7572 | } |
| 7573 | if let Some(background_pixel) = self.background_pixel { |
| 7574 | background_pixel.serialize_into(bytes); |
| 7575 | } |
| 7576 | if let Some(border_pixmap) = self.border_pixmap { |
| 7577 | border_pixmap.serialize_into(bytes); |
| 7578 | } |
| 7579 | if let Some(border_pixel) = self.border_pixel { |
| 7580 | border_pixel.serialize_into(bytes); |
| 7581 | } |
| 7582 | if let Some(bit_gravity) = self.bit_gravity { |
| 7583 | u32::from(bit_gravity).serialize_into(bytes); |
| 7584 | } |
| 7585 | if let Some(win_gravity) = self.win_gravity { |
| 7586 | u32::from(win_gravity).serialize_into(bytes); |
| 7587 | } |
| 7588 | if let Some(backing_store) = self.backing_store { |
| 7589 | u32::from(backing_store).serialize_into(bytes); |
| 7590 | } |
| 7591 | if let Some(backing_planes) = self.backing_planes { |
| 7592 | backing_planes.serialize_into(bytes); |
| 7593 | } |
| 7594 | if let Some(backing_pixel) = self.backing_pixel { |
| 7595 | backing_pixel.serialize_into(bytes); |
| 7596 | } |
| 7597 | if let Some(override_redirect) = self.override_redirect { |
| 7598 | override_redirect.serialize_into(bytes); |
| 7599 | } |
| 7600 | if let Some(save_under) = self.save_under { |
| 7601 | save_under.serialize_into(bytes); |
| 7602 | } |
| 7603 | if let Some(event_mask) = self.event_mask { |
| 7604 | u32::from(event_mask).serialize_into(bytes); |
| 7605 | } |
| 7606 | if let Some(do_not_propogate_mask) = self.do_not_propogate_mask { |
| 7607 | u32::from(do_not_propogate_mask).serialize_into(bytes); |
| 7608 | } |
| 7609 | if let Some(colormap) = self.colormap { |
| 7610 | colormap.serialize_into(bytes); |
| 7611 | } |
| 7612 | if let Some(cursor) = self.cursor { |
| 7613 | cursor.serialize_into(bytes); |
| 7614 | } |
| 7615 | } |
| 7616 | } |
| 7617 | impl ChangeWindowAttributesAux { |
| 7618 | fn switch_expr(&self) -> u32 { |
| 7619 | let mut expr_value = 0; |
| 7620 | if self.background_pixmap.is_some() { |
| 7621 | expr_value |= u32::from(CW::BACK_PIXMAP); |
| 7622 | } |
| 7623 | if self.background_pixel.is_some() { |
| 7624 | expr_value |= u32::from(CW::BACK_PIXEL); |
| 7625 | } |
| 7626 | if self.border_pixmap.is_some() { |
| 7627 | expr_value |= u32::from(CW::BORDER_PIXMAP); |
| 7628 | } |
| 7629 | if self.border_pixel.is_some() { |
| 7630 | expr_value |= u32::from(CW::BORDER_PIXEL); |
| 7631 | } |
| 7632 | if self.bit_gravity.is_some() { |
| 7633 | expr_value |= u32::from(CW::BIT_GRAVITY); |
| 7634 | } |
| 7635 | if self.win_gravity.is_some() { |
| 7636 | expr_value |= u32::from(CW::WIN_GRAVITY); |
| 7637 | } |
| 7638 | if self.backing_store.is_some() { |
| 7639 | expr_value |= u32::from(CW::BACKING_STORE); |
| 7640 | } |
| 7641 | if self.backing_planes.is_some() { |
| 7642 | expr_value |= u32::from(CW::BACKING_PLANES); |
| 7643 | } |
| 7644 | if self.backing_pixel.is_some() { |
| 7645 | expr_value |= u32::from(CW::BACKING_PIXEL); |
| 7646 | } |
| 7647 | if self.override_redirect.is_some() { |
| 7648 | expr_value |= u32::from(CW::OVERRIDE_REDIRECT); |
| 7649 | } |
| 7650 | if self.save_under.is_some() { |
| 7651 | expr_value |= u32::from(CW::SAVE_UNDER); |
| 7652 | } |
| 7653 | if self.event_mask.is_some() { |
| 7654 | expr_value |= u32::from(CW::EVENT_MASK); |
| 7655 | } |
| 7656 | if self.do_not_propogate_mask.is_some() { |
| 7657 | expr_value |= u32::from(CW::DONT_PROPAGATE); |
| 7658 | } |
| 7659 | if self.colormap.is_some() { |
| 7660 | expr_value |= u32::from(CW::COLORMAP); |
| 7661 | } |
| 7662 | if self.cursor.is_some() { |
| 7663 | expr_value |= u32::from(CW::CURSOR); |
| 7664 | } |
| 7665 | expr_value |
| 7666 | } |
| 7667 | } |
| 7668 | impl ChangeWindowAttributesAux { |
| 7669 | /// Create a new instance with all fields unset / not present. |
| 7670 | pub fn new() -> Self { |
| 7671 | Default::default() |
| 7672 | } |
| 7673 | /// Set the `background_pixmap` field of this structure. |
| 7674 | #[must_use ] |
| 7675 | pub fn background_pixmap<I>(mut self, value: I) -> Self where I: Into<Option<Pixmap>> { |
| 7676 | self.background_pixmap = value.into(); |
| 7677 | self |
| 7678 | } |
| 7679 | /// Set the `background_pixel` field of this structure. |
| 7680 | #[must_use ] |
| 7681 | pub fn background_pixel<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 7682 | self.background_pixel = value.into(); |
| 7683 | self |
| 7684 | } |
| 7685 | /// Set the `border_pixmap` field of this structure. |
| 7686 | #[must_use ] |
| 7687 | pub fn border_pixmap<I>(mut self, value: I) -> Self where I: Into<Option<Pixmap>> { |
| 7688 | self.border_pixmap = value.into(); |
| 7689 | self |
| 7690 | } |
| 7691 | /// Set the `border_pixel` field of this structure. |
| 7692 | #[must_use ] |
| 7693 | pub fn border_pixel<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 7694 | self.border_pixel = value.into(); |
| 7695 | self |
| 7696 | } |
| 7697 | /// Set the `bit_gravity` field of this structure. |
| 7698 | #[must_use ] |
| 7699 | pub fn bit_gravity<I>(mut self, value: I) -> Self where I: Into<Option<Gravity>> { |
| 7700 | self.bit_gravity = value.into(); |
| 7701 | self |
| 7702 | } |
| 7703 | /// Set the `win_gravity` field of this structure. |
| 7704 | #[must_use ] |
| 7705 | pub fn win_gravity<I>(mut self, value: I) -> Self where I: Into<Option<Gravity>> { |
| 7706 | self.win_gravity = value.into(); |
| 7707 | self |
| 7708 | } |
| 7709 | /// Set the `backing_store` field of this structure. |
| 7710 | #[must_use ] |
| 7711 | pub fn backing_store<I>(mut self, value: I) -> Self where I: Into<Option<BackingStore>> { |
| 7712 | self.backing_store = value.into(); |
| 7713 | self |
| 7714 | } |
| 7715 | /// Set the `backing_planes` field of this structure. |
| 7716 | #[must_use ] |
| 7717 | pub fn backing_planes<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 7718 | self.backing_planes = value.into(); |
| 7719 | self |
| 7720 | } |
| 7721 | /// Set the `backing_pixel` field of this structure. |
| 7722 | #[must_use ] |
| 7723 | pub fn backing_pixel<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 7724 | self.backing_pixel = value.into(); |
| 7725 | self |
| 7726 | } |
| 7727 | /// Set the `override_redirect` field of this structure. |
| 7728 | #[must_use ] |
| 7729 | pub fn override_redirect<I>(mut self, value: I) -> Self where I: Into<Option<Bool32>> { |
| 7730 | self.override_redirect = value.into(); |
| 7731 | self |
| 7732 | } |
| 7733 | /// Set the `save_under` field of this structure. |
| 7734 | #[must_use ] |
| 7735 | pub fn save_under<I>(mut self, value: I) -> Self where I: Into<Option<Bool32>> { |
| 7736 | self.save_under = value.into(); |
| 7737 | self |
| 7738 | } |
| 7739 | /// Set the `event_mask` field of this structure. |
| 7740 | #[must_use ] |
| 7741 | pub fn event_mask<I>(mut self, value: I) -> Self where I: Into<Option<EventMask>> { |
| 7742 | self.event_mask = value.into(); |
| 7743 | self |
| 7744 | } |
| 7745 | /// Set the `do_not_propogate_mask` field of this structure. |
| 7746 | #[must_use ] |
| 7747 | pub fn do_not_propogate_mask<I>(mut self, value: I) -> Self where I: Into<Option<EventMask>> { |
| 7748 | self.do_not_propogate_mask = value.into(); |
| 7749 | self |
| 7750 | } |
| 7751 | /// Set the `colormap` field of this structure. |
| 7752 | #[must_use ] |
| 7753 | pub fn colormap<I>(mut self, value: I) -> Self where I: Into<Option<Colormap>> { |
| 7754 | self.colormap = value.into(); |
| 7755 | self |
| 7756 | } |
| 7757 | /// Set the `cursor` field of this structure. |
| 7758 | #[must_use ] |
| 7759 | pub fn cursor<I>(mut self, value: I) -> Self where I: Into<Option<Cursor>> { |
| 7760 | self.cursor = value.into(); |
| 7761 | self |
| 7762 | } |
| 7763 | } |
| 7764 | |
| 7765 | /// Opcode for the ChangeWindowAttributes request |
| 7766 | pub const CHANGE_WINDOW_ATTRIBUTES_REQUEST: u8 = 2; |
| 7767 | /// change window attributes. |
| 7768 | /// |
| 7769 | /// Changes the attributes specified by `value_mask` for the specified `window`. |
| 7770 | /// |
| 7771 | /// # Fields |
| 7772 | /// |
| 7773 | /// * `window` - The window to change. |
| 7774 | /// * `value_list` - Values for each of the attributes specified in the bitmask `value_mask`. The |
| 7775 | /// order has to correspond to the order of possible `value_mask` bits. See the |
| 7776 | /// example. |
| 7777 | /// |
| 7778 | /// # Errors |
| 7779 | /// |
| 7780 | /// * `Access` - TODO: reasons? |
| 7781 | /// * `Colormap` - TODO: reasons? |
| 7782 | /// * `Cursor` - TODO: reasons? |
| 7783 | /// * `Match` - TODO: reasons? |
| 7784 | /// * `Pixmap` - TODO: reasons? |
| 7785 | /// * `Value` - TODO: reasons? |
| 7786 | /// * `Window` - The specified `window` does not exist. |
| 7787 | #[derive (Clone, Default)] |
| 7788 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 7789 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 7790 | pub struct ChangeWindowAttributesRequest<'input> { |
| 7791 | pub window: Window, |
| 7792 | pub value_list: Cow<'input, ChangeWindowAttributesAux>, |
| 7793 | } |
| 7794 | impl_debug_if_no_extra_traits!(ChangeWindowAttributesRequest<'_>, "ChangeWindowAttributesRequest" ); |
| 7795 | impl<'input> ChangeWindowAttributesRequest<'input> { |
| 7796 | /// Serialize this request into bytes for the provided connection |
| 7797 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 7798 | let length_so_far = 0; |
| 7799 | let window_bytes = self.window.serialize(); |
| 7800 | let value_mask: u32 = self.value_list.switch_expr(); |
| 7801 | let value_mask_bytes = value_mask.serialize(); |
| 7802 | let mut request0 = vec![ |
| 7803 | CHANGE_WINDOW_ATTRIBUTES_REQUEST, |
| 7804 | 0, |
| 7805 | 0, |
| 7806 | 0, |
| 7807 | window_bytes[0], |
| 7808 | window_bytes[1], |
| 7809 | window_bytes[2], |
| 7810 | window_bytes[3], |
| 7811 | value_mask_bytes[0], |
| 7812 | value_mask_bytes[1], |
| 7813 | value_mask_bytes[2], |
| 7814 | value_mask_bytes[3], |
| 7815 | ]; |
| 7816 | let length_so_far = length_so_far + request0.len(); |
| 7817 | let value_list_bytes = self.value_list.serialize(u32::from(value_mask)); |
| 7818 | let length_so_far = length_so_far + value_list_bytes.len(); |
| 7819 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 7820 | let length_so_far = length_so_far + padding0.len(); |
| 7821 | assert_eq!(length_so_far % 4, 0); |
| 7822 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 7823 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 7824 | ([request0.into(), value_list_bytes.into(), padding0.into()], vec![]) |
| 7825 | } |
| 7826 | /// Parse this request given its header, its body, and any fds that go along with it |
| 7827 | #[cfg (feature = "request-parsing" )] |
| 7828 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 7829 | if header.major_opcode != CHANGE_WINDOW_ATTRIBUTES_REQUEST { |
| 7830 | return Err(ParseError::InvalidValue); |
| 7831 | } |
| 7832 | let remaining = &[header.minor_opcode]; |
| 7833 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 7834 | let _ = remaining; |
| 7835 | let (window, remaining) = Window::try_parse(value)?; |
| 7836 | let (value_mask, remaining) = u32::try_parse(remaining)?; |
| 7837 | let (value_list, remaining) = ChangeWindowAttributesAux::try_parse(remaining, u32::from(value_mask))?; |
| 7838 | let _ = remaining; |
| 7839 | Ok(ChangeWindowAttributesRequest { |
| 7840 | window, |
| 7841 | value_list: Cow::Owned(value_list), |
| 7842 | }) |
| 7843 | } |
| 7844 | /// Clone all borrowed data in this ChangeWindowAttributesRequest. |
| 7845 | pub fn into_owned(self) -> ChangeWindowAttributesRequest<'static> { |
| 7846 | ChangeWindowAttributesRequest { |
| 7847 | window: self.window, |
| 7848 | value_list: Cow::Owned(self.value_list.into_owned()), |
| 7849 | } |
| 7850 | } |
| 7851 | } |
| 7852 | impl<'input> Request for ChangeWindowAttributesRequest<'input> { |
| 7853 | const EXTENSION_NAME: Option<&'static str> = None; |
| 7854 | |
| 7855 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 7856 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 7857 | // Flatten the buffers into a single vector |
| 7858 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 7859 | (buf, fds) |
| 7860 | } |
| 7861 | } |
| 7862 | impl<'input> crate::x11_utils::VoidRequest for ChangeWindowAttributesRequest<'input> { |
| 7863 | } |
| 7864 | |
| 7865 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 7866 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 7867 | pub struct MapState(u8); |
| 7868 | impl MapState { |
| 7869 | pub const UNMAPPED: Self = Self(0); |
| 7870 | pub const UNVIEWABLE: Self = Self(1); |
| 7871 | pub const VIEWABLE: Self = Self(2); |
| 7872 | } |
| 7873 | impl From<MapState> for u8 { |
| 7874 | #[inline ] |
| 7875 | fn from(input: MapState) -> Self { |
| 7876 | input.0 |
| 7877 | } |
| 7878 | } |
| 7879 | impl From<MapState> for Option<u8> { |
| 7880 | #[inline ] |
| 7881 | fn from(input: MapState) -> Self { |
| 7882 | Some(input.0) |
| 7883 | } |
| 7884 | } |
| 7885 | impl From<MapState> for u16 { |
| 7886 | #[inline ] |
| 7887 | fn from(input: MapState) -> Self { |
| 7888 | u16::from(input.0) |
| 7889 | } |
| 7890 | } |
| 7891 | impl From<MapState> for Option<u16> { |
| 7892 | #[inline ] |
| 7893 | fn from(input: MapState) -> Self { |
| 7894 | Some(u16::from(input.0)) |
| 7895 | } |
| 7896 | } |
| 7897 | impl From<MapState> for u32 { |
| 7898 | #[inline ] |
| 7899 | fn from(input: MapState) -> Self { |
| 7900 | u32::from(input.0) |
| 7901 | } |
| 7902 | } |
| 7903 | impl From<MapState> for Option<u32> { |
| 7904 | #[inline ] |
| 7905 | fn from(input: MapState) -> Self { |
| 7906 | Some(u32::from(input.0)) |
| 7907 | } |
| 7908 | } |
| 7909 | impl From<u8> for MapState { |
| 7910 | #[inline ] |
| 7911 | fn from(value: u8) -> Self { |
| 7912 | Self(value) |
| 7913 | } |
| 7914 | } |
| 7915 | impl core::fmt::Debug for MapState { |
| 7916 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 7917 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 7918 | (Self::UNMAPPED.0.into(), "UNMAPPED" , "Unmapped" ), |
| 7919 | (Self::UNVIEWABLE.0.into(), "UNVIEWABLE" , "Unviewable" ), |
| 7920 | (Self::VIEWABLE.0.into(), "VIEWABLE" , "Viewable" ), |
| 7921 | ]; |
| 7922 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 7923 | } |
| 7924 | } |
| 7925 | |
| 7926 | /// Opcode for the GetWindowAttributes request |
| 7927 | pub const GET_WINDOW_ATTRIBUTES_REQUEST: u8 = 3; |
| 7928 | /// Gets window attributes. |
| 7929 | /// |
| 7930 | /// Gets the current attributes for the specified `window`. |
| 7931 | /// |
| 7932 | /// # Fields |
| 7933 | /// |
| 7934 | /// * `window` - The window to get the attributes from. |
| 7935 | /// |
| 7936 | /// # Errors |
| 7937 | /// |
| 7938 | /// * `Window` - The specified `window` does not exist. |
| 7939 | /// * `Drawable` - TODO: reasons? |
| 7940 | #[derive (Clone, Copy, Default)] |
| 7941 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 7942 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 7943 | pub struct GetWindowAttributesRequest { |
| 7944 | pub window: Window, |
| 7945 | } |
| 7946 | impl_debug_if_no_extra_traits!(GetWindowAttributesRequest, "GetWindowAttributesRequest" ); |
| 7947 | impl GetWindowAttributesRequest { |
| 7948 | /// Serialize this request into bytes for the provided connection |
| 7949 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 7950 | let length_so_far = 0; |
| 7951 | let window_bytes = self.window.serialize(); |
| 7952 | let mut request0 = vec![ |
| 7953 | GET_WINDOW_ATTRIBUTES_REQUEST, |
| 7954 | 0, |
| 7955 | 0, |
| 7956 | 0, |
| 7957 | window_bytes[0], |
| 7958 | window_bytes[1], |
| 7959 | window_bytes[2], |
| 7960 | window_bytes[3], |
| 7961 | ]; |
| 7962 | let length_so_far = length_so_far + request0.len(); |
| 7963 | assert_eq!(length_so_far % 4, 0); |
| 7964 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 7965 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 7966 | ([request0.into()], vec![]) |
| 7967 | } |
| 7968 | /// Parse this request given its header, its body, and any fds that go along with it |
| 7969 | #[cfg (feature = "request-parsing" )] |
| 7970 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 7971 | if header.major_opcode != GET_WINDOW_ATTRIBUTES_REQUEST { |
| 7972 | return Err(ParseError::InvalidValue); |
| 7973 | } |
| 7974 | let remaining = &[header.minor_opcode]; |
| 7975 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 7976 | let _ = remaining; |
| 7977 | let (window, remaining) = Window::try_parse(value)?; |
| 7978 | let _ = remaining; |
| 7979 | Ok(GetWindowAttributesRequest { |
| 7980 | window, |
| 7981 | }) |
| 7982 | } |
| 7983 | } |
| 7984 | impl Request for GetWindowAttributesRequest { |
| 7985 | const EXTENSION_NAME: Option<&'static str> = None; |
| 7986 | |
| 7987 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 7988 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 7989 | // Flatten the buffers into a single vector |
| 7990 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 7991 | (buf, fds) |
| 7992 | } |
| 7993 | } |
| 7994 | impl crate::x11_utils::ReplyRequest for GetWindowAttributesRequest { |
| 7995 | type Reply = GetWindowAttributesReply; |
| 7996 | } |
| 7997 | |
| 7998 | /// # Fields |
| 7999 | /// |
| 8000 | /// * `override_redirect` - Window managers should ignore this window if `override_redirect` is 1. |
| 8001 | /// * `visual` - The associated visual structure of `window`. |
| 8002 | /// * `backing_planes` - Planes to be preserved if possible. |
| 8003 | /// * `backing_pixel` - Value to be used when restoring planes. |
| 8004 | /// * `save_under` - Boolean, should bits under be saved? |
| 8005 | /// * `colormap` - Color map to be associated with window. |
| 8006 | /// * `all_event_masks` - Set of events all people have interest in. |
| 8007 | /// * `your_event_mask` - My event mask. |
| 8008 | /// * `do_not_propagate_mask` - Set of events that should not propagate. |
| 8009 | /// * `backing_store` - |
| 8010 | /// * `class` - |
| 8011 | /// * `bit_gravity` - |
| 8012 | /// * `win_gravity` - |
| 8013 | /// * `map_state` - |
| 8014 | #[derive (Clone, Copy, Default)] |
| 8015 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 8016 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8017 | pub struct GetWindowAttributesReply { |
| 8018 | pub backing_store: BackingStore, |
| 8019 | pub sequence: u16, |
| 8020 | pub length: u32, |
| 8021 | pub visual: Visualid, |
| 8022 | pub class: WindowClass, |
| 8023 | pub bit_gravity: Gravity, |
| 8024 | pub win_gravity: Gravity, |
| 8025 | pub backing_planes: u32, |
| 8026 | pub backing_pixel: u32, |
| 8027 | pub save_under: bool, |
| 8028 | pub map_is_installed: bool, |
| 8029 | pub map_state: MapState, |
| 8030 | pub override_redirect: bool, |
| 8031 | pub colormap: Colormap, |
| 8032 | pub all_event_masks: EventMask, |
| 8033 | pub your_event_mask: EventMask, |
| 8034 | pub do_not_propagate_mask: EventMask, |
| 8035 | } |
| 8036 | impl_debug_if_no_extra_traits!(GetWindowAttributesReply, "GetWindowAttributesReply" ); |
| 8037 | impl TryParse for GetWindowAttributesReply { |
| 8038 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 8039 | let remaining = initial_value; |
| 8040 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 8041 | let (backing_store, remaining) = u8::try_parse(remaining)?; |
| 8042 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 8043 | let (length, remaining) = u32::try_parse(remaining)?; |
| 8044 | let (visual, remaining) = Visualid::try_parse(remaining)?; |
| 8045 | let (class, remaining) = u16::try_parse(remaining)?; |
| 8046 | let (bit_gravity, remaining) = u8::try_parse(remaining)?; |
| 8047 | let (win_gravity, remaining) = u8::try_parse(remaining)?; |
| 8048 | let (backing_planes, remaining) = u32::try_parse(remaining)?; |
| 8049 | let (backing_pixel, remaining) = u32::try_parse(remaining)?; |
| 8050 | let (save_under, remaining) = bool::try_parse(remaining)?; |
| 8051 | let (map_is_installed, remaining) = bool::try_parse(remaining)?; |
| 8052 | let (map_state, remaining) = u8::try_parse(remaining)?; |
| 8053 | let (override_redirect, remaining) = bool::try_parse(remaining)?; |
| 8054 | let (colormap, remaining) = Colormap::try_parse(remaining)?; |
| 8055 | let (all_event_masks, remaining) = u32::try_parse(remaining)?; |
| 8056 | let (your_event_mask, remaining) = u32::try_parse(remaining)?; |
| 8057 | let (do_not_propagate_mask, remaining) = u16::try_parse(remaining)?; |
| 8058 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 8059 | if response_type != 1 { |
| 8060 | return Err(ParseError::InvalidValue); |
| 8061 | } |
| 8062 | let backing_store = backing_store.into(); |
| 8063 | let class = class.into(); |
| 8064 | let bit_gravity = bit_gravity.into(); |
| 8065 | let win_gravity = win_gravity.into(); |
| 8066 | let map_state = map_state.into(); |
| 8067 | let all_event_masks = all_event_masks.into(); |
| 8068 | let your_event_mask = your_event_mask.into(); |
| 8069 | let do_not_propagate_mask = do_not_propagate_mask.into(); |
| 8070 | let result = GetWindowAttributesReply { backing_store, sequence, length, visual, class, bit_gravity, win_gravity, backing_planes, backing_pixel, save_under, map_is_installed, map_state, override_redirect, colormap, all_event_masks, your_event_mask, do_not_propagate_mask }; |
| 8071 | let _ = remaining; |
| 8072 | let remaining = initial_value.get(32 + length as usize * 4..) |
| 8073 | .ok_or(ParseError::InsufficientData)?; |
| 8074 | Ok((result, remaining)) |
| 8075 | } |
| 8076 | } |
| 8077 | impl Serialize for GetWindowAttributesReply { |
| 8078 | type Bytes = [u8; 44]; |
| 8079 | fn serialize(&self) -> [u8; 44] { |
| 8080 | let response_type_bytes = &[1]; |
| 8081 | let backing_store_bytes = (u32::from(self.backing_store) as u8).serialize(); |
| 8082 | let sequence_bytes = self.sequence.serialize(); |
| 8083 | let length_bytes = self.length.serialize(); |
| 8084 | let visual_bytes = self.visual.serialize(); |
| 8085 | let class_bytes = u16::from(self.class).serialize(); |
| 8086 | let bit_gravity_bytes = (u32::from(self.bit_gravity) as u8).serialize(); |
| 8087 | let win_gravity_bytes = (u32::from(self.win_gravity) as u8).serialize(); |
| 8088 | let backing_planes_bytes = self.backing_planes.serialize(); |
| 8089 | let backing_pixel_bytes = self.backing_pixel.serialize(); |
| 8090 | let save_under_bytes = self.save_under.serialize(); |
| 8091 | let map_is_installed_bytes = self.map_is_installed.serialize(); |
| 8092 | let map_state_bytes = u8::from(self.map_state).serialize(); |
| 8093 | let override_redirect_bytes = self.override_redirect.serialize(); |
| 8094 | let colormap_bytes = self.colormap.serialize(); |
| 8095 | let all_event_masks_bytes = u32::from(self.all_event_masks).serialize(); |
| 8096 | let your_event_mask_bytes = u32::from(self.your_event_mask).serialize(); |
| 8097 | let do_not_propagate_mask_bytes = (u32::from(self.do_not_propagate_mask) as u16).serialize(); |
| 8098 | [ |
| 8099 | response_type_bytes[0], |
| 8100 | backing_store_bytes[0], |
| 8101 | sequence_bytes[0], |
| 8102 | sequence_bytes[1], |
| 8103 | length_bytes[0], |
| 8104 | length_bytes[1], |
| 8105 | length_bytes[2], |
| 8106 | length_bytes[3], |
| 8107 | visual_bytes[0], |
| 8108 | visual_bytes[1], |
| 8109 | visual_bytes[2], |
| 8110 | visual_bytes[3], |
| 8111 | class_bytes[0], |
| 8112 | class_bytes[1], |
| 8113 | bit_gravity_bytes[0], |
| 8114 | win_gravity_bytes[0], |
| 8115 | backing_planes_bytes[0], |
| 8116 | backing_planes_bytes[1], |
| 8117 | backing_planes_bytes[2], |
| 8118 | backing_planes_bytes[3], |
| 8119 | backing_pixel_bytes[0], |
| 8120 | backing_pixel_bytes[1], |
| 8121 | backing_pixel_bytes[2], |
| 8122 | backing_pixel_bytes[3], |
| 8123 | save_under_bytes[0], |
| 8124 | map_is_installed_bytes[0], |
| 8125 | map_state_bytes[0], |
| 8126 | override_redirect_bytes[0], |
| 8127 | colormap_bytes[0], |
| 8128 | colormap_bytes[1], |
| 8129 | colormap_bytes[2], |
| 8130 | colormap_bytes[3], |
| 8131 | all_event_masks_bytes[0], |
| 8132 | all_event_masks_bytes[1], |
| 8133 | all_event_masks_bytes[2], |
| 8134 | all_event_masks_bytes[3], |
| 8135 | your_event_mask_bytes[0], |
| 8136 | your_event_mask_bytes[1], |
| 8137 | your_event_mask_bytes[2], |
| 8138 | your_event_mask_bytes[3], |
| 8139 | do_not_propagate_mask_bytes[0], |
| 8140 | do_not_propagate_mask_bytes[1], |
| 8141 | 0, |
| 8142 | 0, |
| 8143 | ] |
| 8144 | } |
| 8145 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 8146 | bytes.reserve(44); |
| 8147 | let response_type_bytes = &[1]; |
| 8148 | bytes.push(response_type_bytes[0]); |
| 8149 | (u32::from(self.backing_store) as u8).serialize_into(bytes); |
| 8150 | self.sequence.serialize_into(bytes); |
| 8151 | self.length.serialize_into(bytes); |
| 8152 | self.visual.serialize_into(bytes); |
| 8153 | u16::from(self.class).serialize_into(bytes); |
| 8154 | (u32::from(self.bit_gravity) as u8).serialize_into(bytes); |
| 8155 | (u32::from(self.win_gravity) as u8).serialize_into(bytes); |
| 8156 | self.backing_planes.serialize_into(bytes); |
| 8157 | self.backing_pixel.serialize_into(bytes); |
| 8158 | self.save_under.serialize_into(bytes); |
| 8159 | self.map_is_installed.serialize_into(bytes); |
| 8160 | u8::from(self.map_state).serialize_into(bytes); |
| 8161 | self.override_redirect.serialize_into(bytes); |
| 8162 | self.colormap.serialize_into(bytes); |
| 8163 | u32::from(self.all_event_masks).serialize_into(bytes); |
| 8164 | u32::from(self.your_event_mask).serialize_into(bytes); |
| 8165 | (u32::from(self.do_not_propagate_mask) as u16).serialize_into(bytes); |
| 8166 | bytes.extend_from_slice(&[0; 2]); |
| 8167 | } |
| 8168 | } |
| 8169 | |
| 8170 | /// Opcode for the DestroyWindow request |
| 8171 | pub const DESTROY_WINDOW_REQUEST: u8 = 4; |
| 8172 | /// Destroys a window. |
| 8173 | /// |
| 8174 | /// Destroys the specified window and all of its subwindows. A DestroyNotify event |
| 8175 | /// is generated for each destroyed window (a DestroyNotify event is first generated |
| 8176 | /// for any given window's inferiors). If the window was mapped, it will be |
| 8177 | /// automatically unmapped before destroying. |
| 8178 | /// |
| 8179 | /// Calling DestroyWindow on the root window will do nothing. |
| 8180 | /// |
| 8181 | /// # Fields |
| 8182 | /// |
| 8183 | /// * `window` - The window to destroy. |
| 8184 | /// |
| 8185 | /// # Errors |
| 8186 | /// |
| 8187 | /// * `Window` - The specified window does not exist. |
| 8188 | /// |
| 8189 | /// # See |
| 8190 | /// |
| 8191 | /// * `DestroyNotify`: event |
| 8192 | /// * `MapWindow`: request |
| 8193 | /// * `UnmapWindow`: request |
| 8194 | #[derive (Clone, Copy, Default)] |
| 8195 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 8196 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8197 | pub struct DestroyWindowRequest { |
| 8198 | pub window: Window, |
| 8199 | } |
| 8200 | impl_debug_if_no_extra_traits!(DestroyWindowRequest, "DestroyWindowRequest" ); |
| 8201 | impl DestroyWindowRequest { |
| 8202 | /// Serialize this request into bytes for the provided connection |
| 8203 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 8204 | let length_so_far = 0; |
| 8205 | let window_bytes = self.window.serialize(); |
| 8206 | let mut request0 = vec![ |
| 8207 | DESTROY_WINDOW_REQUEST, |
| 8208 | 0, |
| 8209 | 0, |
| 8210 | 0, |
| 8211 | window_bytes[0], |
| 8212 | window_bytes[1], |
| 8213 | window_bytes[2], |
| 8214 | window_bytes[3], |
| 8215 | ]; |
| 8216 | let length_so_far = length_so_far + request0.len(); |
| 8217 | assert_eq!(length_so_far % 4, 0); |
| 8218 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 8219 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 8220 | ([request0.into()], vec![]) |
| 8221 | } |
| 8222 | /// Parse this request given its header, its body, and any fds that go along with it |
| 8223 | #[cfg (feature = "request-parsing" )] |
| 8224 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 8225 | if header.major_opcode != DESTROY_WINDOW_REQUEST { |
| 8226 | return Err(ParseError::InvalidValue); |
| 8227 | } |
| 8228 | let remaining = &[header.minor_opcode]; |
| 8229 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 8230 | let _ = remaining; |
| 8231 | let (window, remaining) = Window::try_parse(value)?; |
| 8232 | let _ = remaining; |
| 8233 | Ok(DestroyWindowRequest { |
| 8234 | window, |
| 8235 | }) |
| 8236 | } |
| 8237 | } |
| 8238 | impl Request for DestroyWindowRequest { |
| 8239 | const EXTENSION_NAME: Option<&'static str> = None; |
| 8240 | |
| 8241 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 8242 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 8243 | // Flatten the buffers into a single vector |
| 8244 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 8245 | (buf, fds) |
| 8246 | } |
| 8247 | } |
| 8248 | impl crate::x11_utils::VoidRequest for DestroyWindowRequest { |
| 8249 | } |
| 8250 | |
| 8251 | /// Opcode for the DestroySubwindows request |
| 8252 | pub const DESTROY_SUBWINDOWS_REQUEST: u8 = 5; |
| 8253 | #[derive (Clone, Copy, Default)] |
| 8254 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 8255 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8256 | pub struct DestroySubwindowsRequest { |
| 8257 | pub window: Window, |
| 8258 | } |
| 8259 | impl_debug_if_no_extra_traits!(DestroySubwindowsRequest, "DestroySubwindowsRequest" ); |
| 8260 | impl DestroySubwindowsRequest { |
| 8261 | /// Serialize this request into bytes for the provided connection |
| 8262 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 8263 | let length_so_far = 0; |
| 8264 | let window_bytes = self.window.serialize(); |
| 8265 | let mut request0 = vec![ |
| 8266 | DESTROY_SUBWINDOWS_REQUEST, |
| 8267 | 0, |
| 8268 | 0, |
| 8269 | 0, |
| 8270 | window_bytes[0], |
| 8271 | window_bytes[1], |
| 8272 | window_bytes[2], |
| 8273 | window_bytes[3], |
| 8274 | ]; |
| 8275 | let length_so_far = length_so_far + request0.len(); |
| 8276 | assert_eq!(length_so_far % 4, 0); |
| 8277 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 8278 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 8279 | ([request0.into()], vec![]) |
| 8280 | } |
| 8281 | /// Parse this request given its header, its body, and any fds that go along with it |
| 8282 | #[cfg (feature = "request-parsing" )] |
| 8283 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 8284 | if header.major_opcode != DESTROY_SUBWINDOWS_REQUEST { |
| 8285 | return Err(ParseError::InvalidValue); |
| 8286 | } |
| 8287 | let remaining = &[header.minor_opcode]; |
| 8288 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 8289 | let _ = remaining; |
| 8290 | let (window, remaining) = Window::try_parse(value)?; |
| 8291 | let _ = remaining; |
| 8292 | Ok(DestroySubwindowsRequest { |
| 8293 | window, |
| 8294 | }) |
| 8295 | } |
| 8296 | } |
| 8297 | impl Request for DestroySubwindowsRequest { |
| 8298 | const EXTENSION_NAME: Option<&'static str> = None; |
| 8299 | |
| 8300 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 8301 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 8302 | // Flatten the buffers into a single vector |
| 8303 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 8304 | (buf, fds) |
| 8305 | } |
| 8306 | } |
| 8307 | impl crate::x11_utils::VoidRequest for DestroySubwindowsRequest { |
| 8308 | } |
| 8309 | |
| 8310 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 8311 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8312 | pub struct SetMode(u8); |
| 8313 | impl SetMode { |
| 8314 | pub const INSERT: Self = Self(0); |
| 8315 | pub const DELETE: Self = Self(1); |
| 8316 | } |
| 8317 | impl From<SetMode> for u8 { |
| 8318 | #[inline ] |
| 8319 | fn from(input: SetMode) -> Self { |
| 8320 | input.0 |
| 8321 | } |
| 8322 | } |
| 8323 | impl From<SetMode> for Option<u8> { |
| 8324 | #[inline ] |
| 8325 | fn from(input: SetMode) -> Self { |
| 8326 | Some(input.0) |
| 8327 | } |
| 8328 | } |
| 8329 | impl From<SetMode> for u16 { |
| 8330 | #[inline ] |
| 8331 | fn from(input: SetMode) -> Self { |
| 8332 | u16::from(input.0) |
| 8333 | } |
| 8334 | } |
| 8335 | impl From<SetMode> for Option<u16> { |
| 8336 | #[inline ] |
| 8337 | fn from(input: SetMode) -> Self { |
| 8338 | Some(u16::from(input.0)) |
| 8339 | } |
| 8340 | } |
| 8341 | impl From<SetMode> for u32 { |
| 8342 | #[inline ] |
| 8343 | fn from(input: SetMode) -> Self { |
| 8344 | u32::from(input.0) |
| 8345 | } |
| 8346 | } |
| 8347 | impl From<SetMode> for Option<u32> { |
| 8348 | #[inline ] |
| 8349 | fn from(input: SetMode) -> Self { |
| 8350 | Some(u32::from(input.0)) |
| 8351 | } |
| 8352 | } |
| 8353 | impl From<u8> for SetMode { |
| 8354 | #[inline ] |
| 8355 | fn from(value: u8) -> Self { |
| 8356 | Self(value) |
| 8357 | } |
| 8358 | } |
| 8359 | impl core::fmt::Debug for SetMode { |
| 8360 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 8361 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 8362 | (Self::INSERT.0.into(), "INSERT" , "Insert" ), |
| 8363 | (Self::DELETE.0.into(), "DELETE" , "Delete" ), |
| 8364 | ]; |
| 8365 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 8366 | } |
| 8367 | } |
| 8368 | |
| 8369 | /// Opcode for the ChangeSaveSet request |
| 8370 | pub const CHANGE_SAVE_SET_REQUEST: u8 = 6; |
| 8371 | /// Changes a client's save set. |
| 8372 | /// |
| 8373 | /// TODO: explain what the save set is for. |
| 8374 | /// |
| 8375 | /// This function either adds or removes the specified window to the client's (your |
| 8376 | /// application's) save set. |
| 8377 | /// |
| 8378 | /// # Fields |
| 8379 | /// |
| 8380 | /// * `mode` - Insert to add the specified window to the save set or Delete to delete it from the save set. |
| 8381 | /// * `window` - The window to add or delete to/from your save set. |
| 8382 | /// |
| 8383 | /// # Errors |
| 8384 | /// |
| 8385 | /// * `Match` - You created the specified window. This does not make sense, you can only add |
| 8386 | /// windows created by other clients to your save set. |
| 8387 | /// * `Value` - You specified an invalid mode. |
| 8388 | /// * `Window` - The specified window does not exist. |
| 8389 | /// |
| 8390 | /// # See |
| 8391 | /// |
| 8392 | /// * `ReparentWindow`: request |
| 8393 | #[derive (Clone, Copy, Default)] |
| 8394 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 8395 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8396 | pub struct ChangeSaveSetRequest { |
| 8397 | pub mode: SetMode, |
| 8398 | pub window: Window, |
| 8399 | } |
| 8400 | impl_debug_if_no_extra_traits!(ChangeSaveSetRequest, "ChangeSaveSetRequest" ); |
| 8401 | impl ChangeSaveSetRequest { |
| 8402 | /// Serialize this request into bytes for the provided connection |
| 8403 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 8404 | let length_so_far = 0; |
| 8405 | let mode_bytes = u8::from(self.mode).serialize(); |
| 8406 | let window_bytes = self.window.serialize(); |
| 8407 | let mut request0 = vec![ |
| 8408 | CHANGE_SAVE_SET_REQUEST, |
| 8409 | mode_bytes[0], |
| 8410 | 0, |
| 8411 | 0, |
| 8412 | window_bytes[0], |
| 8413 | window_bytes[1], |
| 8414 | window_bytes[2], |
| 8415 | window_bytes[3], |
| 8416 | ]; |
| 8417 | let length_so_far = length_so_far + request0.len(); |
| 8418 | assert_eq!(length_so_far % 4, 0); |
| 8419 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 8420 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 8421 | ([request0.into()], vec![]) |
| 8422 | } |
| 8423 | /// Parse this request given its header, its body, and any fds that go along with it |
| 8424 | #[cfg (feature = "request-parsing" )] |
| 8425 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 8426 | if header.major_opcode != CHANGE_SAVE_SET_REQUEST { |
| 8427 | return Err(ParseError::InvalidValue); |
| 8428 | } |
| 8429 | let remaining = &[header.minor_opcode]; |
| 8430 | let (mode, remaining) = u8::try_parse(remaining)?; |
| 8431 | let mode = mode.into(); |
| 8432 | let _ = remaining; |
| 8433 | let (window, remaining) = Window::try_parse(value)?; |
| 8434 | let _ = remaining; |
| 8435 | Ok(ChangeSaveSetRequest { |
| 8436 | mode, |
| 8437 | window, |
| 8438 | }) |
| 8439 | } |
| 8440 | } |
| 8441 | impl Request for ChangeSaveSetRequest { |
| 8442 | const EXTENSION_NAME: Option<&'static str> = None; |
| 8443 | |
| 8444 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 8445 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 8446 | // Flatten the buffers into a single vector |
| 8447 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 8448 | (buf, fds) |
| 8449 | } |
| 8450 | } |
| 8451 | impl crate::x11_utils::VoidRequest for ChangeSaveSetRequest { |
| 8452 | } |
| 8453 | |
| 8454 | /// Opcode for the ReparentWindow request |
| 8455 | pub const REPARENT_WINDOW_REQUEST: u8 = 7; |
| 8456 | /// Reparents a window. |
| 8457 | /// |
| 8458 | /// Makes the specified window a child of the specified parent window. If the |
| 8459 | /// window is mapped, it will automatically be unmapped before reparenting and |
| 8460 | /// re-mapped after reparenting. The window is placed in the stacking order on top |
| 8461 | /// with respect to sibling windows. |
| 8462 | /// |
| 8463 | /// After reparenting, a ReparentNotify event is generated. |
| 8464 | /// |
| 8465 | /// # Fields |
| 8466 | /// |
| 8467 | /// * `window` - The window to reparent. |
| 8468 | /// * `parent` - The new parent of the window. |
| 8469 | /// * `x` - The X position of the window within its new parent. |
| 8470 | /// * `y` - The Y position of the window within its new parent. |
| 8471 | /// |
| 8472 | /// # Errors |
| 8473 | /// |
| 8474 | /// * `Match` - The new parent window is not on the same screen as the old parent window. |
| 8475 | /// |
| 8476 | /// The new parent window is the specified window or an inferior of the specified window. |
| 8477 | /// |
| 8478 | /// The new parent is InputOnly and the window is not. |
| 8479 | /// |
| 8480 | /// The specified window has a ParentRelative background and the new parent window is not the same depth as the specified window. |
| 8481 | /// * `Window` - The specified window does not exist. |
| 8482 | /// |
| 8483 | /// # See |
| 8484 | /// |
| 8485 | /// * `ReparentNotify`: event |
| 8486 | /// * `MapWindow`: request |
| 8487 | /// * `UnmapWindow`: request |
| 8488 | #[derive (Clone, Copy, Default)] |
| 8489 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 8490 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8491 | pub struct ReparentWindowRequest { |
| 8492 | pub window: Window, |
| 8493 | pub parent: Window, |
| 8494 | pub x: i16, |
| 8495 | pub y: i16, |
| 8496 | } |
| 8497 | impl_debug_if_no_extra_traits!(ReparentWindowRequest, "ReparentWindowRequest" ); |
| 8498 | impl ReparentWindowRequest { |
| 8499 | /// Serialize this request into bytes for the provided connection |
| 8500 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 8501 | let length_so_far = 0; |
| 8502 | let window_bytes = self.window.serialize(); |
| 8503 | let parent_bytes = self.parent.serialize(); |
| 8504 | let x_bytes = self.x.serialize(); |
| 8505 | let y_bytes = self.y.serialize(); |
| 8506 | let mut request0 = vec![ |
| 8507 | REPARENT_WINDOW_REQUEST, |
| 8508 | 0, |
| 8509 | 0, |
| 8510 | 0, |
| 8511 | window_bytes[0], |
| 8512 | window_bytes[1], |
| 8513 | window_bytes[2], |
| 8514 | window_bytes[3], |
| 8515 | parent_bytes[0], |
| 8516 | parent_bytes[1], |
| 8517 | parent_bytes[2], |
| 8518 | parent_bytes[3], |
| 8519 | x_bytes[0], |
| 8520 | x_bytes[1], |
| 8521 | y_bytes[0], |
| 8522 | y_bytes[1], |
| 8523 | ]; |
| 8524 | let length_so_far = length_so_far + request0.len(); |
| 8525 | assert_eq!(length_so_far % 4, 0); |
| 8526 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 8527 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 8528 | ([request0.into()], vec![]) |
| 8529 | } |
| 8530 | /// Parse this request given its header, its body, and any fds that go along with it |
| 8531 | #[cfg (feature = "request-parsing" )] |
| 8532 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 8533 | if header.major_opcode != REPARENT_WINDOW_REQUEST { |
| 8534 | return Err(ParseError::InvalidValue); |
| 8535 | } |
| 8536 | let remaining = &[header.minor_opcode]; |
| 8537 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 8538 | let _ = remaining; |
| 8539 | let (window, remaining) = Window::try_parse(value)?; |
| 8540 | let (parent, remaining) = Window::try_parse(remaining)?; |
| 8541 | let (x, remaining) = i16::try_parse(remaining)?; |
| 8542 | let (y, remaining) = i16::try_parse(remaining)?; |
| 8543 | let _ = remaining; |
| 8544 | Ok(ReparentWindowRequest { |
| 8545 | window, |
| 8546 | parent, |
| 8547 | x, |
| 8548 | y, |
| 8549 | }) |
| 8550 | } |
| 8551 | } |
| 8552 | impl Request for ReparentWindowRequest { |
| 8553 | const EXTENSION_NAME: Option<&'static str> = None; |
| 8554 | |
| 8555 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 8556 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 8557 | // Flatten the buffers into a single vector |
| 8558 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 8559 | (buf, fds) |
| 8560 | } |
| 8561 | } |
| 8562 | impl crate::x11_utils::VoidRequest for ReparentWindowRequest { |
| 8563 | } |
| 8564 | |
| 8565 | /// Opcode for the MapWindow request |
| 8566 | pub const MAP_WINDOW_REQUEST: u8 = 8; |
| 8567 | /// Makes a window visible. |
| 8568 | /// |
| 8569 | /// Maps the specified window. This means making the window visible (as long as its |
| 8570 | /// parent is visible). |
| 8571 | /// |
| 8572 | /// This MapWindow request will be translated to a MapRequest request if a window |
| 8573 | /// manager is running. The window manager then decides to either map the window or |
| 8574 | /// not. Set the override-redirect window attribute to true if you want to bypass |
| 8575 | /// this mechanism. |
| 8576 | /// |
| 8577 | /// If the window manager decides to map the window (or if no window manager is |
| 8578 | /// running), a MapNotify event is generated. |
| 8579 | /// |
| 8580 | /// If the window becomes viewable and no earlier contents for it are remembered, |
| 8581 | /// the X server tiles the window with its background. If the window's background |
| 8582 | /// is undefined, the existing screen contents are not altered, and the X server |
| 8583 | /// generates zero or more Expose events. |
| 8584 | /// |
| 8585 | /// If the window type is InputOutput, an Expose event will be generated when the |
| 8586 | /// window becomes visible. The normal response to an Expose event should be to |
| 8587 | /// repaint the window. |
| 8588 | /// |
| 8589 | /// # Fields |
| 8590 | /// |
| 8591 | /// * `window` - The window to make visible. |
| 8592 | /// |
| 8593 | /// # Errors |
| 8594 | /// |
| 8595 | /// * `Match` - The specified window does not exist. |
| 8596 | /// |
| 8597 | /// # See |
| 8598 | /// |
| 8599 | /// * `MapNotify`: event |
| 8600 | /// * `Expose`: event |
| 8601 | /// * `UnmapWindow`: request |
| 8602 | #[derive (Clone, Copy, Default)] |
| 8603 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 8604 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8605 | pub struct MapWindowRequest { |
| 8606 | pub window: Window, |
| 8607 | } |
| 8608 | impl_debug_if_no_extra_traits!(MapWindowRequest, "MapWindowRequest" ); |
| 8609 | impl MapWindowRequest { |
| 8610 | /// Serialize this request into bytes for the provided connection |
| 8611 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 8612 | let length_so_far = 0; |
| 8613 | let window_bytes = self.window.serialize(); |
| 8614 | let mut request0 = vec![ |
| 8615 | MAP_WINDOW_REQUEST, |
| 8616 | 0, |
| 8617 | 0, |
| 8618 | 0, |
| 8619 | window_bytes[0], |
| 8620 | window_bytes[1], |
| 8621 | window_bytes[2], |
| 8622 | window_bytes[3], |
| 8623 | ]; |
| 8624 | let length_so_far = length_so_far + request0.len(); |
| 8625 | assert_eq!(length_so_far % 4, 0); |
| 8626 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 8627 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 8628 | ([request0.into()], vec![]) |
| 8629 | } |
| 8630 | /// Parse this request given its header, its body, and any fds that go along with it |
| 8631 | #[cfg (feature = "request-parsing" )] |
| 8632 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 8633 | if header.major_opcode != MAP_WINDOW_REQUEST { |
| 8634 | return Err(ParseError::InvalidValue); |
| 8635 | } |
| 8636 | let remaining = &[header.minor_opcode]; |
| 8637 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 8638 | let _ = remaining; |
| 8639 | let (window, remaining) = Window::try_parse(value)?; |
| 8640 | let _ = remaining; |
| 8641 | Ok(MapWindowRequest { |
| 8642 | window, |
| 8643 | }) |
| 8644 | } |
| 8645 | } |
| 8646 | impl Request for MapWindowRequest { |
| 8647 | const EXTENSION_NAME: Option<&'static str> = None; |
| 8648 | |
| 8649 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 8650 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 8651 | // Flatten the buffers into a single vector |
| 8652 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 8653 | (buf, fds) |
| 8654 | } |
| 8655 | } |
| 8656 | impl crate::x11_utils::VoidRequest for MapWindowRequest { |
| 8657 | } |
| 8658 | |
| 8659 | /// Opcode for the MapSubwindows request |
| 8660 | pub const MAP_SUBWINDOWS_REQUEST: u8 = 9; |
| 8661 | #[derive (Clone, Copy, Default)] |
| 8662 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 8663 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8664 | pub struct MapSubwindowsRequest { |
| 8665 | pub window: Window, |
| 8666 | } |
| 8667 | impl_debug_if_no_extra_traits!(MapSubwindowsRequest, "MapSubwindowsRequest" ); |
| 8668 | impl MapSubwindowsRequest { |
| 8669 | /// Serialize this request into bytes for the provided connection |
| 8670 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 8671 | let length_so_far = 0; |
| 8672 | let window_bytes = self.window.serialize(); |
| 8673 | let mut request0 = vec![ |
| 8674 | MAP_SUBWINDOWS_REQUEST, |
| 8675 | 0, |
| 8676 | 0, |
| 8677 | 0, |
| 8678 | window_bytes[0], |
| 8679 | window_bytes[1], |
| 8680 | window_bytes[2], |
| 8681 | window_bytes[3], |
| 8682 | ]; |
| 8683 | let length_so_far = length_so_far + request0.len(); |
| 8684 | assert_eq!(length_so_far % 4, 0); |
| 8685 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 8686 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 8687 | ([request0.into()], vec![]) |
| 8688 | } |
| 8689 | /// Parse this request given its header, its body, and any fds that go along with it |
| 8690 | #[cfg (feature = "request-parsing" )] |
| 8691 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 8692 | if header.major_opcode != MAP_SUBWINDOWS_REQUEST { |
| 8693 | return Err(ParseError::InvalidValue); |
| 8694 | } |
| 8695 | let remaining = &[header.minor_opcode]; |
| 8696 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 8697 | let _ = remaining; |
| 8698 | let (window, remaining) = Window::try_parse(value)?; |
| 8699 | let _ = remaining; |
| 8700 | Ok(MapSubwindowsRequest { |
| 8701 | window, |
| 8702 | }) |
| 8703 | } |
| 8704 | } |
| 8705 | impl Request for MapSubwindowsRequest { |
| 8706 | const EXTENSION_NAME: Option<&'static str> = None; |
| 8707 | |
| 8708 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 8709 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 8710 | // Flatten the buffers into a single vector |
| 8711 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 8712 | (buf, fds) |
| 8713 | } |
| 8714 | } |
| 8715 | impl crate::x11_utils::VoidRequest for MapSubwindowsRequest { |
| 8716 | } |
| 8717 | |
| 8718 | /// Opcode for the UnmapWindow request |
| 8719 | pub const UNMAP_WINDOW_REQUEST: u8 = 10; |
| 8720 | /// Makes a window invisible. |
| 8721 | /// |
| 8722 | /// Unmaps the specified window. This means making the window invisible (and all |
| 8723 | /// its child windows). |
| 8724 | /// |
| 8725 | /// Unmapping a window leads to the `UnmapNotify` event being generated. Also, |
| 8726 | /// `Expose` events are generated for formerly obscured windows. |
| 8727 | /// |
| 8728 | /// # Fields |
| 8729 | /// |
| 8730 | /// * `window` - The window to make invisible. |
| 8731 | /// |
| 8732 | /// # Errors |
| 8733 | /// |
| 8734 | /// * `Window` - The specified window does not exist. |
| 8735 | /// |
| 8736 | /// # See |
| 8737 | /// |
| 8738 | /// * `UnmapNotify`: event |
| 8739 | /// * `Expose`: event |
| 8740 | /// * `MapWindow`: request |
| 8741 | #[derive (Clone, Copy, Default)] |
| 8742 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 8743 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8744 | pub struct UnmapWindowRequest { |
| 8745 | pub window: Window, |
| 8746 | } |
| 8747 | impl_debug_if_no_extra_traits!(UnmapWindowRequest, "UnmapWindowRequest" ); |
| 8748 | impl UnmapWindowRequest { |
| 8749 | /// Serialize this request into bytes for the provided connection |
| 8750 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 8751 | let length_so_far = 0; |
| 8752 | let window_bytes = self.window.serialize(); |
| 8753 | let mut request0 = vec![ |
| 8754 | UNMAP_WINDOW_REQUEST, |
| 8755 | 0, |
| 8756 | 0, |
| 8757 | 0, |
| 8758 | window_bytes[0], |
| 8759 | window_bytes[1], |
| 8760 | window_bytes[2], |
| 8761 | window_bytes[3], |
| 8762 | ]; |
| 8763 | let length_so_far = length_so_far + request0.len(); |
| 8764 | assert_eq!(length_so_far % 4, 0); |
| 8765 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 8766 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 8767 | ([request0.into()], vec![]) |
| 8768 | } |
| 8769 | /// Parse this request given its header, its body, and any fds that go along with it |
| 8770 | #[cfg (feature = "request-parsing" )] |
| 8771 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 8772 | if header.major_opcode != UNMAP_WINDOW_REQUEST { |
| 8773 | return Err(ParseError::InvalidValue); |
| 8774 | } |
| 8775 | let remaining = &[header.minor_opcode]; |
| 8776 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 8777 | let _ = remaining; |
| 8778 | let (window, remaining) = Window::try_parse(value)?; |
| 8779 | let _ = remaining; |
| 8780 | Ok(UnmapWindowRequest { |
| 8781 | window, |
| 8782 | }) |
| 8783 | } |
| 8784 | } |
| 8785 | impl Request for UnmapWindowRequest { |
| 8786 | const EXTENSION_NAME: Option<&'static str> = None; |
| 8787 | |
| 8788 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 8789 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 8790 | // Flatten the buffers into a single vector |
| 8791 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 8792 | (buf, fds) |
| 8793 | } |
| 8794 | } |
| 8795 | impl crate::x11_utils::VoidRequest for UnmapWindowRequest { |
| 8796 | } |
| 8797 | |
| 8798 | /// Opcode for the UnmapSubwindows request |
| 8799 | pub const UNMAP_SUBWINDOWS_REQUEST: u8 = 11; |
| 8800 | #[derive (Clone, Copy, Default)] |
| 8801 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 8802 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8803 | pub struct UnmapSubwindowsRequest { |
| 8804 | pub window: Window, |
| 8805 | } |
| 8806 | impl_debug_if_no_extra_traits!(UnmapSubwindowsRequest, "UnmapSubwindowsRequest" ); |
| 8807 | impl UnmapSubwindowsRequest { |
| 8808 | /// Serialize this request into bytes for the provided connection |
| 8809 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 8810 | let length_so_far = 0; |
| 8811 | let window_bytes = self.window.serialize(); |
| 8812 | let mut request0 = vec![ |
| 8813 | UNMAP_SUBWINDOWS_REQUEST, |
| 8814 | 0, |
| 8815 | 0, |
| 8816 | 0, |
| 8817 | window_bytes[0], |
| 8818 | window_bytes[1], |
| 8819 | window_bytes[2], |
| 8820 | window_bytes[3], |
| 8821 | ]; |
| 8822 | let length_so_far = length_so_far + request0.len(); |
| 8823 | assert_eq!(length_so_far % 4, 0); |
| 8824 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 8825 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 8826 | ([request0.into()], vec![]) |
| 8827 | } |
| 8828 | /// Parse this request given its header, its body, and any fds that go along with it |
| 8829 | #[cfg (feature = "request-parsing" )] |
| 8830 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 8831 | if header.major_opcode != UNMAP_SUBWINDOWS_REQUEST { |
| 8832 | return Err(ParseError::InvalidValue); |
| 8833 | } |
| 8834 | let remaining = &[header.minor_opcode]; |
| 8835 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 8836 | let _ = remaining; |
| 8837 | let (window, remaining) = Window::try_parse(value)?; |
| 8838 | let _ = remaining; |
| 8839 | Ok(UnmapSubwindowsRequest { |
| 8840 | window, |
| 8841 | }) |
| 8842 | } |
| 8843 | } |
| 8844 | impl Request for UnmapSubwindowsRequest { |
| 8845 | const EXTENSION_NAME: Option<&'static str> = None; |
| 8846 | |
| 8847 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 8848 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 8849 | // Flatten the buffers into a single vector |
| 8850 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 8851 | (buf, fds) |
| 8852 | } |
| 8853 | } |
| 8854 | impl crate::x11_utils::VoidRequest for UnmapSubwindowsRequest { |
| 8855 | } |
| 8856 | |
| 8857 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 8858 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8859 | pub struct ConfigWindow(u16); |
| 8860 | impl ConfigWindow { |
| 8861 | pub const X: Self = Self(1 << 0); |
| 8862 | pub const Y: Self = Self(1 << 1); |
| 8863 | pub const WIDTH: Self = Self(1 << 2); |
| 8864 | pub const HEIGHT: Self = Self(1 << 3); |
| 8865 | pub const BORDER_WIDTH: Self = Self(1 << 4); |
| 8866 | pub const SIBLING: Self = Self(1 << 5); |
| 8867 | pub const STACK_MODE: Self = Self(1 << 6); |
| 8868 | } |
| 8869 | impl From<ConfigWindow> for u16 { |
| 8870 | #[inline ] |
| 8871 | fn from(input: ConfigWindow) -> Self { |
| 8872 | input.0 |
| 8873 | } |
| 8874 | } |
| 8875 | impl From<ConfigWindow> for Option<u16> { |
| 8876 | #[inline ] |
| 8877 | fn from(input: ConfigWindow) -> Self { |
| 8878 | Some(input.0) |
| 8879 | } |
| 8880 | } |
| 8881 | impl From<ConfigWindow> for u32 { |
| 8882 | #[inline ] |
| 8883 | fn from(input: ConfigWindow) -> Self { |
| 8884 | u32::from(input.0) |
| 8885 | } |
| 8886 | } |
| 8887 | impl From<ConfigWindow> for Option<u32> { |
| 8888 | #[inline ] |
| 8889 | fn from(input: ConfigWindow) -> Self { |
| 8890 | Some(u32::from(input.0)) |
| 8891 | } |
| 8892 | } |
| 8893 | impl From<u8> for ConfigWindow { |
| 8894 | #[inline ] |
| 8895 | fn from(value: u8) -> Self { |
| 8896 | Self(value.into()) |
| 8897 | } |
| 8898 | } |
| 8899 | impl From<u16> for ConfigWindow { |
| 8900 | #[inline ] |
| 8901 | fn from(value: u16) -> Self { |
| 8902 | Self(value) |
| 8903 | } |
| 8904 | } |
| 8905 | impl core::fmt::Debug for ConfigWindow { |
| 8906 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 8907 | let variants: [(u32, &'static str, &'static …); 7] = [ |
| 8908 | (Self::X.0.into(), "X" , "X" ), |
| 8909 | (Self::Y.0.into(), "Y" , "Y" ), |
| 8910 | (Self::WIDTH.0.into(), "WIDTH" , "Width" ), |
| 8911 | (Self::HEIGHT.0.into(), "HEIGHT" , "Height" ), |
| 8912 | (Self::BORDER_WIDTH.0.into(), "BORDER_WIDTH" , "BorderWidth" ), |
| 8913 | (Self::SIBLING.0.into(), "SIBLING" , "Sibling" ), |
| 8914 | (Self::STACK_MODE.0.into(), "STACK_MODE" , "StackMode" ), |
| 8915 | ]; |
| 8916 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 8917 | } |
| 8918 | } |
| 8919 | bitmask_binop!(ConfigWindow, u16); |
| 8920 | |
| 8921 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 8922 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8923 | pub struct StackMode(u32); |
| 8924 | impl StackMode { |
| 8925 | pub const ABOVE: Self = Self(0); |
| 8926 | pub const BELOW: Self = Self(1); |
| 8927 | pub const TOP_IF: Self = Self(2); |
| 8928 | pub const BOTTOM_IF: Self = Self(3); |
| 8929 | pub const OPPOSITE: Self = Self(4); |
| 8930 | } |
| 8931 | impl From<StackMode> for u32 { |
| 8932 | #[inline ] |
| 8933 | fn from(input: StackMode) -> Self { |
| 8934 | input.0 |
| 8935 | } |
| 8936 | } |
| 8937 | impl From<StackMode> for Option<u32> { |
| 8938 | #[inline ] |
| 8939 | fn from(input: StackMode) -> Self { |
| 8940 | Some(input.0) |
| 8941 | } |
| 8942 | } |
| 8943 | impl From<u8> for StackMode { |
| 8944 | #[inline ] |
| 8945 | fn from(value: u8) -> Self { |
| 8946 | Self(value.into()) |
| 8947 | } |
| 8948 | } |
| 8949 | impl From<u16> for StackMode { |
| 8950 | #[inline ] |
| 8951 | fn from(value: u16) -> Self { |
| 8952 | Self(value.into()) |
| 8953 | } |
| 8954 | } |
| 8955 | impl From<u32> for StackMode { |
| 8956 | #[inline ] |
| 8957 | fn from(value: u32) -> Self { |
| 8958 | Self(value) |
| 8959 | } |
| 8960 | } |
| 8961 | impl core::fmt::Debug for StackMode { |
| 8962 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 8963 | let variants: [(u32, &'static str, &'static …); 5] = [ |
| 8964 | (Self::ABOVE.0, "ABOVE" , "Above" ), |
| 8965 | (Self::BELOW.0, "BELOW" , "Below" ), |
| 8966 | (Self::TOP_IF.0, "TOP_IF" , "TopIf" ), |
| 8967 | (Self::BOTTOM_IF.0, "BOTTOM_IF" , "BottomIf" ), |
| 8968 | (Self::OPPOSITE.0, "OPPOSITE" , "Opposite" ), |
| 8969 | ]; |
| 8970 | pretty_print_enum(fmt, self.0, &variants) |
| 8971 | } |
| 8972 | } |
| 8973 | |
| 8974 | /// Auxiliary and optional information for the `configure_window` function |
| 8975 | #[derive (Clone, Copy, Default)] |
| 8976 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 8977 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8978 | pub struct ConfigureWindowAux { |
| 8979 | pub x: Option<i32>, |
| 8980 | pub y: Option<i32>, |
| 8981 | pub width: Option<u32>, |
| 8982 | pub height: Option<u32>, |
| 8983 | pub border_width: Option<u32>, |
| 8984 | pub sibling: Option<Window>, |
| 8985 | pub stack_mode: Option<StackMode>, |
| 8986 | } |
| 8987 | impl_debug_if_no_extra_traits!(ConfigureWindowAux, "ConfigureWindowAux" ); |
| 8988 | impl ConfigureWindowAux { |
| 8989 | #[cfg_attr (not(feature = "request-parsing" ), allow(dead_code))] |
| 8990 | fn try_parse(value: &[u8], value_mask: u16) -> Result<(Self, &[u8]), ParseError> { |
| 8991 | let switch_expr = u16::from(value_mask); |
| 8992 | let mut outer_remaining = value; |
| 8993 | let x = if switch_expr & u16::from(ConfigWindow::X) != 0 { |
| 8994 | let remaining = outer_remaining; |
| 8995 | let (x, remaining) = i32::try_parse(remaining)?; |
| 8996 | outer_remaining = remaining; |
| 8997 | Some(x) |
| 8998 | } else { |
| 8999 | None |
| 9000 | }; |
| 9001 | let y = if switch_expr & u16::from(ConfigWindow::Y) != 0 { |
| 9002 | let remaining = outer_remaining; |
| 9003 | let (y, remaining) = i32::try_parse(remaining)?; |
| 9004 | outer_remaining = remaining; |
| 9005 | Some(y) |
| 9006 | } else { |
| 9007 | None |
| 9008 | }; |
| 9009 | let width = if switch_expr & u16::from(ConfigWindow::WIDTH) != 0 { |
| 9010 | let remaining = outer_remaining; |
| 9011 | let (width, remaining) = u32::try_parse(remaining)?; |
| 9012 | outer_remaining = remaining; |
| 9013 | Some(width) |
| 9014 | } else { |
| 9015 | None |
| 9016 | }; |
| 9017 | let height = if switch_expr & u16::from(ConfigWindow::HEIGHT) != 0 { |
| 9018 | let remaining = outer_remaining; |
| 9019 | let (height, remaining) = u32::try_parse(remaining)?; |
| 9020 | outer_remaining = remaining; |
| 9021 | Some(height) |
| 9022 | } else { |
| 9023 | None |
| 9024 | }; |
| 9025 | let border_width = if switch_expr & u16::from(ConfigWindow::BORDER_WIDTH) != 0 { |
| 9026 | let remaining = outer_remaining; |
| 9027 | let (border_width, remaining) = u32::try_parse(remaining)?; |
| 9028 | outer_remaining = remaining; |
| 9029 | Some(border_width) |
| 9030 | } else { |
| 9031 | None |
| 9032 | }; |
| 9033 | let sibling = if switch_expr & u16::from(ConfigWindow::SIBLING) != 0 { |
| 9034 | let remaining = outer_remaining; |
| 9035 | let (sibling, remaining) = Window::try_parse(remaining)?; |
| 9036 | outer_remaining = remaining; |
| 9037 | Some(sibling) |
| 9038 | } else { |
| 9039 | None |
| 9040 | }; |
| 9041 | let stack_mode = if switch_expr & u16::from(ConfigWindow::STACK_MODE) != 0 { |
| 9042 | let remaining = outer_remaining; |
| 9043 | let (stack_mode, remaining) = u32::try_parse(remaining)?; |
| 9044 | let stack_mode = stack_mode.into(); |
| 9045 | outer_remaining = remaining; |
| 9046 | Some(stack_mode) |
| 9047 | } else { |
| 9048 | None |
| 9049 | }; |
| 9050 | let result = ConfigureWindowAux { x, y, width, height, border_width, sibling, stack_mode }; |
| 9051 | Ok((result, outer_remaining)) |
| 9052 | } |
| 9053 | } |
| 9054 | impl ConfigureWindowAux { |
| 9055 | #[allow (dead_code)] |
| 9056 | fn serialize(&self, value_mask: u16) -> Vec<u8> { |
| 9057 | let mut result = Vec::new(); |
| 9058 | self.serialize_into(&mut result, u16::from(value_mask)); |
| 9059 | result |
| 9060 | } |
| 9061 | fn serialize_into(&self, bytes: &mut Vec<u8>, value_mask: u16) { |
| 9062 | assert_eq!(self.switch_expr(), u16::from(value_mask), "switch `value_list` has an inconsistent discriminant" ); |
| 9063 | if let Some(x) = self.x { |
| 9064 | x.serialize_into(bytes); |
| 9065 | } |
| 9066 | if let Some(y) = self.y { |
| 9067 | y.serialize_into(bytes); |
| 9068 | } |
| 9069 | if let Some(width) = self.width { |
| 9070 | width.serialize_into(bytes); |
| 9071 | } |
| 9072 | if let Some(height) = self.height { |
| 9073 | height.serialize_into(bytes); |
| 9074 | } |
| 9075 | if let Some(border_width) = self.border_width { |
| 9076 | border_width.serialize_into(bytes); |
| 9077 | } |
| 9078 | if let Some(sibling) = self.sibling { |
| 9079 | sibling.serialize_into(bytes); |
| 9080 | } |
| 9081 | if let Some(stack_mode) = self.stack_mode { |
| 9082 | u32::from(stack_mode).serialize_into(bytes); |
| 9083 | } |
| 9084 | } |
| 9085 | } |
| 9086 | impl ConfigureWindowAux { |
| 9087 | fn switch_expr(&self) -> u16 { |
| 9088 | let mut expr_value = 0; |
| 9089 | if self.x.is_some() { |
| 9090 | expr_value |= u16::from(ConfigWindow::X); |
| 9091 | } |
| 9092 | if self.y.is_some() { |
| 9093 | expr_value |= u16::from(ConfigWindow::Y); |
| 9094 | } |
| 9095 | if self.width.is_some() { |
| 9096 | expr_value |= u16::from(ConfigWindow::WIDTH); |
| 9097 | } |
| 9098 | if self.height.is_some() { |
| 9099 | expr_value |= u16::from(ConfigWindow::HEIGHT); |
| 9100 | } |
| 9101 | if self.border_width.is_some() { |
| 9102 | expr_value |= u16::from(ConfigWindow::BORDER_WIDTH); |
| 9103 | } |
| 9104 | if self.sibling.is_some() { |
| 9105 | expr_value |= u16::from(ConfigWindow::SIBLING); |
| 9106 | } |
| 9107 | if self.stack_mode.is_some() { |
| 9108 | expr_value |= u16::from(ConfigWindow::STACK_MODE); |
| 9109 | } |
| 9110 | expr_value |
| 9111 | } |
| 9112 | } |
| 9113 | impl ConfigureWindowAux { |
| 9114 | /// Create a new instance with all fields unset / not present. |
| 9115 | pub fn new() -> Self { |
| 9116 | Default::default() |
| 9117 | } |
| 9118 | /// Set the `x` field of this structure. |
| 9119 | #[must_use ] |
| 9120 | pub fn x<I>(mut self, value: I) -> Self where I: Into<Option<i32>> { |
| 9121 | self.x = value.into(); |
| 9122 | self |
| 9123 | } |
| 9124 | /// Set the `y` field of this structure. |
| 9125 | #[must_use ] |
| 9126 | pub fn y<I>(mut self, value: I) -> Self where I: Into<Option<i32>> { |
| 9127 | self.y = value.into(); |
| 9128 | self |
| 9129 | } |
| 9130 | /// Set the `width` field of this structure. |
| 9131 | #[must_use ] |
| 9132 | pub fn width<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 9133 | self.width = value.into(); |
| 9134 | self |
| 9135 | } |
| 9136 | /// Set the `height` field of this structure. |
| 9137 | #[must_use ] |
| 9138 | pub fn height<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 9139 | self.height = value.into(); |
| 9140 | self |
| 9141 | } |
| 9142 | /// Set the `border_width` field of this structure. |
| 9143 | #[must_use ] |
| 9144 | pub fn border_width<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 9145 | self.border_width = value.into(); |
| 9146 | self |
| 9147 | } |
| 9148 | /// Set the `sibling` field of this structure. |
| 9149 | #[must_use ] |
| 9150 | pub fn sibling<I>(mut self, value: I) -> Self where I: Into<Option<Window>> { |
| 9151 | self.sibling = value.into(); |
| 9152 | self |
| 9153 | } |
| 9154 | /// Set the `stack_mode` field of this structure. |
| 9155 | #[must_use ] |
| 9156 | pub fn stack_mode<I>(mut self, value: I) -> Self where I: Into<Option<StackMode>> { |
| 9157 | self.stack_mode = value.into(); |
| 9158 | self |
| 9159 | } |
| 9160 | } |
| 9161 | impl ConfigureWindowAux { |
| 9162 | /// Construct from a [`ConfigureRequestEvent`]. |
| 9163 | /// |
| 9164 | /// This function construct a new `ConfigureWindowAux` instance by accepting all requested |
| 9165 | /// changes from a `ConfigureRequestEvent`. This function is useful for window managers that want |
| 9166 | /// to handle `ConfigureRequestEvent`s. |
| 9167 | pub fn from_configure_request(event: &ConfigureRequestEvent) -> Self { |
| 9168 | let mut result = Self::new(); |
| 9169 | let value_mask = u16::from(event.value_mask); |
| 9170 | if value_mask & u16::from(ConfigWindow::X) != 0 { |
| 9171 | result = result.x(i32::from(event.x)); |
| 9172 | } |
| 9173 | if value_mask & u16::from(ConfigWindow::Y) != 0 { |
| 9174 | result = result.y(i32::from(event.y)); |
| 9175 | } |
| 9176 | if value_mask & u16::from(ConfigWindow::WIDTH) != 0 { |
| 9177 | result = result.width(u32::from(event.width)); |
| 9178 | } |
| 9179 | if value_mask & u16::from(ConfigWindow::HEIGHT) != 0 { |
| 9180 | result = result.height(u32::from(event.height)); |
| 9181 | } |
| 9182 | if value_mask & u16::from(ConfigWindow::BORDER_WIDTH) != 0 { |
| 9183 | result = result.border_width(u32::from(event.border_width)); |
| 9184 | } |
| 9185 | if value_mask & u16::from(ConfigWindow::SIBLING) != 0 { |
| 9186 | result = result.sibling(event.sibling); |
| 9187 | } |
| 9188 | if value_mask & u16::from(ConfigWindow::STACK_MODE) != 0 { |
| 9189 | result = result.stack_mode(event.stack_mode); |
| 9190 | } |
| 9191 | result |
| 9192 | } |
| 9193 | } |
| 9194 | |
| 9195 | /// Opcode for the ConfigureWindow request |
| 9196 | pub const CONFIGURE_WINDOW_REQUEST: u8 = 12; |
| 9197 | /// Configures window attributes. |
| 9198 | /// |
| 9199 | /// Configures a window's size, position, border width and stacking order. |
| 9200 | /// |
| 9201 | /// # Fields |
| 9202 | /// |
| 9203 | /// * `window` - The window to configure. |
| 9204 | /// * `value_list` - New values, corresponding to the attributes in value_mask. The order has to |
| 9205 | /// correspond to the order of possible `value_mask` bits. See the example. |
| 9206 | /// |
| 9207 | /// # Errors |
| 9208 | /// |
| 9209 | /// * `Match` - You specified a Sibling without also specifying StackMode or the window is not |
| 9210 | /// actually a Sibling. |
| 9211 | /// * `Window` - The specified window does not exist. TODO: any other reason? |
| 9212 | /// * `Value` - TODO: reasons? |
| 9213 | /// |
| 9214 | /// # See |
| 9215 | /// |
| 9216 | /// * `MapNotify`: event |
| 9217 | /// * `Expose`: event |
| 9218 | /// |
| 9219 | /// # Example |
| 9220 | /// |
| 9221 | /// ```text |
| 9222 | /// /* |
| 9223 | /// * Configures the given window to the left upper corner |
| 9224 | /// * with a size of 1024x768 pixels. |
| 9225 | /// * |
| 9226 | /// */ |
| 9227 | /// void my_example(xcb_connection_t *c, xcb_window_t window) { |
| 9228 | /// uint16_t mask = 0; |
| 9229 | /// |
| 9230 | /// mask |= XCB_CONFIG_WINDOW_X; |
| 9231 | /// mask |= XCB_CONFIG_WINDOW_Y; |
| 9232 | /// mask |= XCB_CONFIG_WINDOW_WIDTH; |
| 9233 | /// mask |= XCB_CONFIG_WINDOW_HEIGHT; |
| 9234 | /// |
| 9235 | /// const uint32_t values[] = { |
| 9236 | /// 0, /* x */ |
| 9237 | /// 0, /* y */ |
| 9238 | /// 1024, /* width */ |
| 9239 | /// 768 /* height */ |
| 9240 | /// }; |
| 9241 | /// |
| 9242 | /// xcb_configure_window(c, window, mask, values); |
| 9243 | /// xcb_flush(c); |
| 9244 | /// } |
| 9245 | /// ``` |
| 9246 | #[derive (Clone, Default)] |
| 9247 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9248 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9249 | pub struct ConfigureWindowRequest<'input> { |
| 9250 | pub window: Window, |
| 9251 | pub value_list: Cow<'input, ConfigureWindowAux>, |
| 9252 | } |
| 9253 | impl_debug_if_no_extra_traits!(ConfigureWindowRequest<'_>, "ConfigureWindowRequest" ); |
| 9254 | impl<'input> ConfigureWindowRequest<'input> { |
| 9255 | /// Serialize this request into bytes for the provided connection |
| 9256 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 9257 | let length_so_far = 0; |
| 9258 | let window_bytes = self.window.serialize(); |
| 9259 | let value_mask: u16 = self.value_list.switch_expr(); |
| 9260 | let value_mask_bytes = value_mask.serialize(); |
| 9261 | let mut request0 = vec![ |
| 9262 | CONFIGURE_WINDOW_REQUEST, |
| 9263 | 0, |
| 9264 | 0, |
| 9265 | 0, |
| 9266 | window_bytes[0], |
| 9267 | window_bytes[1], |
| 9268 | window_bytes[2], |
| 9269 | window_bytes[3], |
| 9270 | value_mask_bytes[0], |
| 9271 | value_mask_bytes[1], |
| 9272 | 0, |
| 9273 | 0, |
| 9274 | ]; |
| 9275 | let length_so_far = length_so_far + request0.len(); |
| 9276 | let value_list_bytes = self.value_list.serialize(u16::from(value_mask)); |
| 9277 | let length_so_far = length_so_far + value_list_bytes.len(); |
| 9278 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 9279 | let length_so_far = length_so_far + padding0.len(); |
| 9280 | assert_eq!(length_so_far % 4, 0); |
| 9281 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 9282 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 9283 | ([request0.into(), value_list_bytes.into(), padding0.into()], vec![]) |
| 9284 | } |
| 9285 | /// Parse this request given its header, its body, and any fds that go along with it |
| 9286 | #[cfg (feature = "request-parsing" )] |
| 9287 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 9288 | if header.major_opcode != CONFIGURE_WINDOW_REQUEST { |
| 9289 | return Err(ParseError::InvalidValue); |
| 9290 | } |
| 9291 | let remaining = &[header.minor_opcode]; |
| 9292 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 9293 | let _ = remaining; |
| 9294 | let (window, remaining) = Window::try_parse(value)?; |
| 9295 | let (value_mask, remaining) = u16::try_parse(remaining)?; |
| 9296 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 9297 | let (value_list, remaining) = ConfigureWindowAux::try_parse(remaining, u16::from(value_mask))?; |
| 9298 | let _ = remaining; |
| 9299 | Ok(ConfigureWindowRequest { |
| 9300 | window, |
| 9301 | value_list: Cow::Owned(value_list), |
| 9302 | }) |
| 9303 | } |
| 9304 | /// Clone all borrowed data in this ConfigureWindowRequest. |
| 9305 | pub fn into_owned(self) -> ConfigureWindowRequest<'static> { |
| 9306 | ConfigureWindowRequest { |
| 9307 | window: self.window, |
| 9308 | value_list: Cow::Owned(self.value_list.into_owned()), |
| 9309 | } |
| 9310 | } |
| 9311 | } |
| 9312 | impl<'input> Request for ConfigureWindowRequest<'input> { |
| 9313 | const EXTENSION_NAME: Option<&'static str> = None; |
| 9314 | |
| 9315 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 9316 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 9317 | // Flatten the buffers into a single vector |
| 9318 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 9319 | (buf, fds) |
| 9320 | } |
| 9321 | } |
| 9322 | impl<'input> crate::x11_utils::VoidRequest for ConfigureWindowRequest<'input> { |
| 9323 | } |
| 9324 | |
| 9325 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 9326 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9327 | pub struct Circulate(u8); |
| 9328 | impl Circulate { |
| 9329 | pub const RAISE_LOWEST: Self = Self(0); |
| 9330 | pub const LOWER_HIGHEST: Self = Self(1); |
| 9331 | } |
| 9332 | impl From<Circulate> for u8 { |
| 9333 | #[inline ] |
| 9334 | fn from(input: Circulate) -> Self { |
| 9335 | input.0 |
| 9336 | } |
| 9337 | } |
| 9338 | impl From<Circulate> for Option<u8> { |
| 9339 | #[inline ] |
| 9340 | fn from(input: Circulate) -> Self { |
| 9341 | Some(input.0) |
| 9342 | } |
| 9343 | } |
| 9344 | impl From<Circulate> for u16 { |
| 9345 | #[inline ] |
| 9346 | fn from(input: Circulate) -> Self { |
| 9347 | u16::from(input.0) |
| 9348 | } |
| 9349 | } |
| 9350 | impl From<Circulate> for Option<u16> { |
| 9351 | #[inline ] |
| 9352 | fn from(input: Circulate) -> Self { |
| 9353 | Some(u16::from(input.0)) |
| 9354 | } |
| 9355 | } |
| 9356 | impl From<Circulate> for u32 { |
| 9357 | #[inline ] |
| 9358 | fn from(input: Circulate) -> Self { |
| 9359 | u32::from(input.0) |
| 9360 | } |
| 9361 | } |
| 9362 | impl From<Circulate> for Option<u32> { |
| 9363 | #[inline ] |
| 9364 | fn from(input: Circulate) -> Self { |
| 9365 | Some(u32::from(input.0)) |
| 9366 | } |
| 9367 | } |
| 9368 | impl From<u8> for Circulate { |
| 9369 | #[inline ] |
| 9370 | fn from(value: u8) -> Self { |
| 9371 | Self(value) |
| 9372 | } |
| 9373 | } |
| 9374 | impl core::fmt::Debug for Circulate { |
| 9375 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 9376 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 9377 | (Self::RAISE_LOWEST.0.into(), "RAISE_LOWEST" , "RaiseLowest" ), |
| 9378 | (Self::LOWER_HIGHEST.0.into(), "LOWER_HIGHEST" , "LowerHighest" ), |
| 9379 | ]; |
| 9380 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 9381 | } |
| 9382 | } |
| 9383 | |
| 9384 | /// Opcode for the CirculateWindow request |
| 9385 | pub const CIRCULATE_WINDOW_REQUEST: u8 = 13; |
| 9386 | /// Change window stacking order. |
| 9387 | /// |
| 9388 | /// If `direction` is `XCB_CIRCULATE_RAISE_LOWEST`, the lowest mapped child (if |
| 9389 | /// any) will be raised to the top of the stack. |
| 9390 | /// |
| 9391 | /// If `direction` is `XCB_CIRCULATE_LOWER_HIGHEST`, the highest mapped child will |
| 9392 | /// be lowered to the bottom of the stack. |
| 9393 | /// |
| 9394 | /// # Fields |
| 9395 | /// |
| 9396 | /// * `direction` - |
| 9397 | /// * `window` - The window to raise/lower (depending on `direction`). |
| 9398 | /// |
| 9399 | /// # Errors |
| 9400 | /// |
| 9401 | /// * `Window` - The specified `window` does not exist. |
| 9402 | /// * `Value` - The specified `direction` is invalid. |
| 9403 | #[derive (Clone, Copy, Default)] |
| 9404 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9405 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9406 | pub struct CirculateWindowRequest { |
| 9407 | pub direction: Circulate, |
| 9408 | pub window: Window, |
| 9409 | } |
| 9410 | impl_debug_if_no_extra_traits!(CirculateWindowRequest, "CirculateWindowRequest" ); |
| 9411 | impl CirculateWindowRequest { |
| 9412 | /// Serialize this request into bytes for the provided connection |
| 9413 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 9414 | let length_so_far = 0; |
| 9415 | let direction_bytes = u8::from(self.direction).serialize(); |
| 9416 | let window_bytes = self.window.serialize(); |
| 9417 | let mut request0 = vec![ |
| 9418 | CIRCULATE_WINDOW_REQUEST, |
| 9419 | direction_bytes[0], |
| 9420 | 0, |
| 9421 | 0, |
| 9422 | window_bytes[0], |
| 9423 | window_bytes[1], |
| 9424 | window_bytes[2], |
| 9425 | window_bytes[3], |
| 9426 | ]; |
| 9427 | let length_so_far = length_so_far + request0.len(); |
| 9428 | assert_eq!(length_so_far % 4, 0); |
| 9429 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 9430 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 9431 | ([request0.into()], vec![]) |
| 9432 | } |
| 9433 | /// Parse this request given its header, its body, and any fds that go along with it |
| 9434 | #[cfg (feature = "request-parsing" )] |
| 9435 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 9436 | if header.major_opcode != CIRCULATE_WINDOW_REQUEST { |
| 9437 | return Err(ParseError::InvalidValue); |
| 9438 | } |
| 9439 | let remaining = &[header.minor_opcode]; |
| 9440 | let (direction, remaining) = u8::try_parse(remaining)?; |
| 9441 | let direction = direction.into(); |
| 9442 | let _ = remaining; |
| 9443 | let (window, remaining) = Window::try_parse(value)?; |
| 9444 | let _ = remaining; |
| 9445 | Ok(CirculateWindowRequest { |
| 9446 | direction, |
| 9447 | window, |
| 9448 | }) |
| 9449 | } |
| 9450 | } |
| 9451 | impl Request for CirculateWindowRequest { |
| 9452 | const EXTENSION_NAME: Option<&'static str> = None; |
| 9453 | |
| 9454 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 9455 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 9456 | // Flatten the buffers into a single vector |
| 9457 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 9458 | (buf, fds) |
| 9459 | } |
| 9460 | } |
| 9461 | impl crate::x11_utils::VoidRequest for CirculateWindowRequest { |
| 9462 | } |
| 9463 | |
| 9464 | /// Opcode for the GetGeometry request |
| 9465 | pub const GET_GEOMETRY_REQUEST: u8 = 14; |
| 9466 | /// Get current window geometry. |
| 9467 | /// |
| 9468 | /// Gets the current geometry of the specified drawable (either `Window` or `Pixmap`). |
| 9469 | /// |
| 9470 | /// # Fields |
| 9471 | /// |
| 9472 | /// * `drawable` - The drawable (`Window` or `Pixmap`) of which the geometry will be received. |
| 9473 | /// |
| 9474 | /// # Errors |
| 9475 | /// |
| 9476 | /// * `Drawable` - TODO: reasons? |
| 9477 | /// * `Window` - TODO: reasons? |
| 9478 | /// |
| 9479 | /// # See |
| 9480 | /// |
| 9481 | /// * `xwininfo`: program |
| 9482 | /// |
| 9483 | /// # Example |
| 9484 | /// |
| 9485 | /// ```text |
| 9486 | /// /* |
| 9487 | /// * Displays the x and y position of the given window. |
| 9488 | /// * |
| 9489 | /// */ |
| 9490 | /// void my_example(xcb_connection_t *c, xcb_window_t window) { |
| 9491 | /// xcb_get_geometry_cookie_t cookie; |
| 9492 | /// xcb_get_geometry_reply_t *reply; |
| 9493 | /// |
| 9494 | /// cookie = xcb_get_geometry(c, window); |
| 9495 | /// /* ... do other work here if possible ... */ |
| 9496 | /// if ((reply = xcb_get_geometry_reply(c, cookie, NULL))) { |
| 9497 | /// printf("This window is at %d, %d\\n", reply->x, reply->y); |
| 9498 | /// } |
| 9499 | /// free(reply); |
| 9500 | /// } |
| 9501 | /// ``` |
| 9502 | #[derive (Clone, Copy, Default)] |
| 9503 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9504 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9505 | pub struct GetGeometryRequest { |
| 9506 | pub drawable: Drawable, |
| 9507 | } |
| 9508 | impl_debug_if_no_extra_traits!(GetGeometryRequest, "GetGeometryRequest" ); |
| 9509 | impl GetGeometryRequest { |
| 9510 | /// Serialize this request into bytes for the provided connection |
| 9511 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 9512 | let length_so_far = 0; |
| 9513 | let drawable_bytes = self.drawable.serialize(); |
| 9514 | let mut request0 = vec![ |
| 9515 | GET_GEOMETRY_REQUEST, |
| 9516 | 0, |
| 9517 | 0, |
| 9518 | 0, |
| 9519 | drawable_bytes[0], |
| 9520 | drawable_bytes[1], |
| 9521 | drawable_bytes[2], |
| 9522 | drawable_bytes[3], |
| 9523 | ]; |
| 9524 | let length_so_far = length_so_far + request0.len(); |
| 9525 | assert_eq!(length_so_far % 4, 0); |
| 9526 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 9527 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 9528 | ([request0.into()], vec![]) |
| 9529 | } |
| 9530 | /// Parse this request given its header, its body, and any fds that go along with it |
| 9531 | #[cfg (feature = "request-parsing" )] |
| 9532 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 9533 | if header.major_opcode != GET_GEOMETRY_REQUEST { |
| 9534 | return Err(ParseError::InvalidValue); |
| 9535 | } |
| 9536 | let remaining = &[header.minor_opcode]; |
| 9537 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 9538 | let _ = remaining; |
| 9539 | let (drawable, remaining) = Drawable::try_parse(value)?; |
| 9540 | let _ = remaining; |
| 9541 | Ok(GetGeometryRequest { |
| 9542 | drawable, |
| 9543 | }) |
| 9544 | } |
| 9545 | } |
| 9546 | impl Request for GetGeometryRequest { |
| 9547 | const EXTENSION_NAME: Option<&'static str> = None; |
| 9548 | |
| 9549 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 9550 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 9551 | // Flatten the buffers into a single vector |
| 9552 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 9553 | (buf, fds) |
| 9554 | } |
| 9555 | } |
| 9556 | impl crate::x11_utils::ReplyRequest for GetGeometryRequest { |
| 9557 | type Reply = GetGeometryReply; |
| 9558 | } |
| 9559 | |
| 9560 | /// # Fields |
| 9561 | /// |
| 9562 | /// * `root` - Root window of the screen containing `drawable`. |
| 9563 | /// * `x` - The X coordinate of `drawable`. If `drawable` is a window, the coordinate |
| 9564 | /// specifies the upper-left outer corner relative to its parent's origin. If |
| 9565 | /// `drawable` is a pixmap, the X coordinate is always 0. |
| 9566 | /// * `y` - The Y coordinate of `drawable`. If `drawable` is a window, the coordinate |
| 9567 | /// specifies the upper-left outer corner relative to its parent's origin. If |
| 9568 | /// `drawable` is a pixmap, the Y coordinate is always 0. |
| 9569 | /// * `width` - The width of `drawable`. |
| 9570 | /// * `height` - The height of `drawable`. |
| 9571 | /// * `border_width` - The border width (in pixels). |
| 9572 | /// * `depth` - The depth of the drawable (bits per pixel for the object). |
| 9573 | #[derive (Clone, Copy, Default)] |
| 9574 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9575 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9576 | pub struct GetGeometryReply { |
| 9577 | pub depth: u8, |
| 9578 | pub sequence: u16, |
| 9579 | pub length: u32, |
| 9580 | pub root: Window, |
| 9581 | pub x: i16, |
| 9582 | pub y: i16, |
| 9583 | pub width: u16, |
| 9584 | pub height: u16, |
| 9585 | pub border_width: u16, |
| 9586 | } |
| 9587 | impl_debug_if_no_extra_traits!(GetGeometryReply, "GetGeometryReply" ); |
| 9588 | impl TryParse for GetGeometryReply { |
| 9589 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 9590 | let remaining: &[u8] = initial_value; |
| 9591 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 9592 | let (depth: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 9593 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 9594 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 9595 | let (root: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 9596 | let (x: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 9597 | let (y: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 9598 | let (width: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 9599 | let (height: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 9600 | let (border_width: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 9601 | let remaining: &[u8] = remaining.get(2..).ok_or(err:ParseError::InsufficientData)?; |
| 9602 | if response_type != 1 { |
| 9603 | return Err(ParseError::InvalidValue); |
| 9604 | } |
| 9605 | let result: GetGeometryReply = GetGeometryReply { depth, sequence, length, root, x, y, width, height, border_width }; |
| 9606 | let _ = remaining; |
| 9607 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 9608 | .ok_or(err:ParseError::InsufficientData)?; |
| 9609 | Ok((result, remaining)) |
| 9610 | } |
| 9611 | } |
| 9612 | impl Serialize for GetGeometryReply { |
| 9613 | type Bytes = [u8; 24]; |
| 9614 | fn serialize(&self) -> [u8; 24] { |
| 9615 | let response_type_bytes = &[1]; |
| 9616 | let depth_bytes = self.depth.serialize(); |
| 9617 | let sequence_bytes = self.sequence.serialize(); |
| 9618 | let length_bytes = self.length.serialize(); |
| 9619 | let root_bytes = self.root.serialize(); |
| 9620 | let x_bytes = self.x.serialize(); |
| 9621 | let y_bytes = self.y.serialize(); |
| 9622 | let width_bytes = self.width.serialize(); |
| 9623 | let height_bytes = self.height.serialize(); |
| 9624 | let border_width_bytes = self.border_width.serialize(); |
| 9625 | [ |
| 9626 | response_type_bytes[0], |
| 9627 | depth_bytes[0], |
| 9628 | sequence_bytes[0], |
| 9629 | sequence_bytes[1], |
| 9630 | length_bytes[0], |
| 9631 | length_bytes[1], |
| 9632 | length_bytes[2], |
| 9633 | length_bytes[3], |
| 9634 | root_bytes[0], |
| 9635 | root_bytes[1], |
| 9636 | root_bytes[2], |
| 9637 | root_bytes[3], |
| 9638 | x_bytes[0], |
| 9639 | x_bytes[1], |
| 9640 | y_bytes[0], |
| 9641 | y_bytes[1], |
| 9642 | width_bytes[0], |
| 9643 | width_bytes[1], |
| 9644 | height_bytes[0], |
| 9645 | height_bytes[1], |
| 9646 | border_width_bytes[0], |
| 9647 | border_width_bytes[1], |
| 9648 | 0, |
| 9649 | 0, |
| 9650 | ] |
| 9651 | } |
| 9652 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 9653 | bytes.reserve(24); |
| 9654 | let response_type_bytes = &[1]; |
| 9655 | bytes.push(response_type_bytes[0]); |
| 9656 | self.depth.serialize_into(bytes); |
| 9657 | self.sequence.serialize_into(bytes); |
| 9658 | self.length.serialize_into(bytes); |
| 9659 | self.root.serialize_into(bytes); |
| 9660 | self.x.serialize_into(bytes); |
| 9661 | self.y.serialize_into(bytes); |
| 9662 | self.width.serialize_into(bytes); |
| 9663 | self.height.serialize_into(bytes); |
| 9664 | self.border_width.serialize_into(bytes); |
| 9665 | bytes.extend_from_slice(&[0; 2]); |
| 9666 | } |
| 9667 | } |
| 9668 | |
| 9669 | /// Opcode for the QueryTree request |
| 9670 | pub const QUERY_TREE_REQUEST: u8 = 15; |
| 9671 | /// query the window tree. |
| 9672 | /// |
| 9673 | /// Gets the root window ID, parent window ID and list of children windows for the |
| 9674 | /// specified `window`. The children are listed in bottom-to-top stacking order. |
| 9675 | /// |
| 9676 | /// # Fields |
| 9677 | /// |
| 9678 | /// * `window` - The `window` to query. |
| 9679 | /// |
| 9680 | /// # See |
| 9681 | /// |
| 9682 | /// * `xwininfo`: program |
| 9683 | /// |
| 9684 | /// # Example |
| 9685 | /// |
| 9686 | /// ```text |
| 9687 | /// /* |
| 9688 | /// * Displays the root, parent and children of the specified window. |
| 9689 | /// * |
| 9690 | /// */ |
| 9691 | /// void my_example(xcb_connection_t *conn, xcb_window_t window) { |
| 9692 | /// xcb_query_tree_cookie_t cookie; |
| 9693 | /// xcb_query_tree_reply_t *reply; |
| 9694 | /// |
| 9695 | /// cookie = xcb_query_tree(conn, window); |
| 9696 | /// if ((reply = xcb_query_tree_reply(conn, cookie, NULL))) { |
| 9697 | /// printf("root = 0x%08x\\n", reply->root); |
| 9698 | /// printf("parent = 0x%08x\\n", reply->parent); |
| 9699 | /// |
| 9700 | /// xcb_window_t *children = xcb_query_tree_children(reply); |
| 9701 | /// for (int i = 0; i < xcb_query_tree_children_length(reply); i++) |
| 9702 | /// printf("child window = 0x%08x\\n", children[i]); |
| 9703 | /// |
| 9704 | /// free(reply); |
| 9705 | /// } |
| 9706 | /// } |
| 9707 | /// ``` |
| 9708 | #[derive (Clone, Copy, Default)] |
| 9709 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9710 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9711 | pub struct QueryTreeRequest { |
| 9712 | pub window: Window, |
| 9713 | } |
| 9714 | impl_debug_if_no_extra_traits!(QueryTreeRequest, "QueryTreeRequest" ); |
| 9715 | impl QueryTreeRequest { |
| 9716 | /// Serialize this request into bytes for the provided connection |
| 9717 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 9718 | let length_so_far = 0; |
| 9719 | let window_bytes = self.window.serialize(); |
| 9720 | let mut request0 = vec![ |
| 9721 | QUERY_TREE_REQUEST, |
| 9722 | 0, |
| 9723 | 0, |
| 9724 | 0, |
| 9725 | window_bytes[0], |
| 9726 | window_bytes[1], |
| 9727 | window_bytes[2], |
| 9728 | window_bytes[3], |
| 9729 | ]; |
| 9730 | let length_so_far = length_so_far + request0.len(); |
| 9731 | assert_eq!(length_so_far % 4, 0); |
| 9732 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 9733 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 9734 | ([request0.into()], vec![]) |
| 9735 | } |
| 9736 | /// Parse this request given its header, its body, and any fds that go along with it |
| 9737 | #[cfg (feature = "request-parsing" )] |
| 9738 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 9739 | if header.major_opcode != QUERY_TREE_REQUEST { |
| 9740 | return Err(ParseError::InvalidValue); |
| 9741 | } |
| 9742 | let remaining = &[header.minor_opcode]; |
| 9743 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 9744 | let _ = remaining; |
| 9745 | let (window, remaining) = Window::try_parse(value)?; |
| 9746 | let _ = remaining; |
| 9747 | Ok(QueryTreeRequest { |
| 9748 | window, |
| 9749 | }) |
| 9750 | } |
| 9751 | } |
| 9752 | impl Request for QueryTreeRequest { |
| 9753 | const EXTENSION_NAME: Option<&'static str> = None; |
| 9754 | |
| 9755 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 9756 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 9757 | // Flatten the buffers into a single vector |
| 9758 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 9759 | (buf, fds) |
| 9760 | } |
| 9761 | } |
| 9762 | impl crate::x11_utils::ReplyRequest for QueryTreeRequest { |
| 9763 | type Reply = QueryTreeReply; |
| 9764 | } |
| 9765 | |
| 9766 | /// # Fields |
| 9767 | /// |
| 9768 | /// * `root` - The root window of `window`. |
| 9769 | /// * `parent` - The parent window of `window`. |
| 9770 | #[derive (Clone, Default)] |
| 9771 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9772 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9773 | pub struct QueryTreeReply { |
| 9774 | pub sequence: u16, |
| 9775 | pub length: u32, |
| 9776 | pub root: Window, |
| 9777 | pub parent: Window, |
| 9778 | pub children: Vec<Window>, |
| 9779 | } |
| 9780 | impl_debug_if_no_extra_traits!(QueryTreeReply, "QueryTreeReply" ); |
| 9781 | impl TryParse for QueryTreeReply { |
| 9782 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 9783 | let remaining: &[u8] = initial_value; |
| 9784 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 9785 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 9786 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 9787 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 9788 | let (root: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 9789 | let (parent: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 9790 | let (children_len: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 9791 | let remaining: &[u8] = remaining.get(14..).ok_or(err:ParseError::InsufficientData)?; |
| 9792 | let (children: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<Window>(data:remaining, list_length:children_len.try_to_usize()?)?; |
| 9793 | if response_type != 1 { |
| 9794 | return Err(ParseError::InvalidValue); |
| 9795 | } |
| 9796 | let result: QueryTreeReply = QueryTreeReply { sequence, length, root, parent, children }; |
| 9797 | let _ = remaining; |
| 9798 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 9799 | .ok_or(err:ParseError::InsufficientData)?; |
| 9800 | Ok((result, remaining)) |
| 9801 | } |
| 9802 | } |
| 9803 | impl Serialize for QueryTreeReply { |
| 9804 | type Bytes = Vec<u8>; |
| 9805 | fn serialize(&self) -> Vec<u8> { |
| 9806 | let mut result: Vec = Vec::new(); |
| 9807 | self.serialize_into(&mut result); |
| 9808 | result |
| 9809 | } |
| 9810 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 9811 | bytes.reserve(additional:32); |
| 9812 | let response_type_bytes: &[u8; 1] = &[1]; |
| 9813 | bytes.push(response_type_bytes[0]); |
| 9814 | bytes.extend_from_slice(&[0; 1]); |
| 9815 | self.sequence.serialize_into(bytes); |
| 9816 | self.length.serialize_into(bytes); |
| 9817 | self.root.serialize_into(bytes); |
| 9818 | self.parent.serialize_into(bytes); |
| 9819 | let children_len: u16 = u16::try_from(self.children.len()).expect(msg:"`children` has too many elements" ); |
| 9820 | children_len.serialize_into(bytes); |
| 9821 | bytes.extend_from_slice(&[0; 14]); |
| 9822 | self.children.serialize_into(bytes); |
| 9823 | } |
| 9824 | } |
| 9825 | impl QueryTreeReply { |
| 9826 | /// Get the value of the `children_len` field. |
| 9827 | /// |
| 9828 | /// The `children_len` field is used as the length field of the `children` field. |
| 9829 | /// This function computes the field's value again based on the length of the list. |
| 9830 | /// |
| 9831 | /// # Panics |
| 9832 | /// |
| 9833 | /// Panics if the value cannot be represented in the target type. This |
| 9834 | /// cannot happen with values of the struct received from the X11 server. |
| 9835 | pub fn children_len(&self) -> u16 { |
| 9836 | self.children.len() |
| 9837 | .try_into().unwrap() |
| 9838 | } |
| 9839 | } |
| 9840 | |
| 9841 | /// Opcode for the InternAtom request |
| 9842 | pub const INTERN_ATOM_REQUEST: u8 = 16; |
| 9843 | /// Get atom identifier by name. |
| 9844 | /// |
| 9845 | /// Retrieves the identifier (xcb_atom_t TODO) for the atom with the specified |
| 9846 | /// name. Atoms are used in protocols like EWMH, for example to store window titles |
| 9847 | /// (`_NET_WM_NAME` atom) as property of a window. |
| 9848 | /// |
| 9849 | /// If `only_if_exists` is 0, the atom will be created if it does not already exist. |
| 9850 | /// If `only_if_exists` is 1, `XCB_ATOM_NONE` will be returned if the atom does |
| 9851 | /// not yet exist. |
| 9852 | /// |
| 9853 | /// # Fields |
| 9854 | /// |
| 9855 | /// * `name` - The name of the atom. |
| 9856 | /// * `only_if_exists` - Return a valid atom id only if the atom already exists. |
| 9857 | /// |
| 9858 | /// # Errors |
| 9859 | /// |
| 9860 | /// * `Alloc` - TODO: reasons? |
| 9861 | /// * `Value` - A value other than 0 or 1 was specified for `only_if_exists`. |
| 9862 | /// |
| 9863 | /// # See |
| 9864 | /// |
| 9865 | /// * `xlsatoms`: program |
| 9866 | /// * `GetAtomName`: request |
| 9867 | /// |
| 9868 | /// # Example |
| 9869 | /// |
| 9870 | /// ```text |
| 9871 | /// /* |
| 9872 | /// * Resolves the _NET_WM_NAME atom. |
| 9873 | /// * |
| 9874 | /// */ |
| 9875 | /// void my_example(xcb_connection_t *c) { |
| 9876 | /// xcb_intern_atom_cookie_t cookie; |
| 9877 | /// xcb_intern_atom_reply_t *reply; |
| 9878 | /// |
| 9879 | /// cookie = xcb_intern_atom(c, 0, strlen("_NET_WM_NAME"), "_NET_WM_NAME"); |
| 9880 | /// /* ... do other work here if possible ... */ |
| 9881 | /// if ((reply = xcb_intern_atom_reply(c, cookie, NULL))) { |
| 9882 | /// printf("The _NET_WM_NAME atom has ID %u\n", reply->atom); |
| 9883 | /// free(reply); |
| 9884 | /// } |
| 9885 | /// } |
| 9886 | /// ``` |
| 9887 | #[derive (Clone, Default)] |
| 9888 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9889 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9890 | pub struct InternAtomRequest<'input> { |
| 9891 | pub only_if_exists: bool, |
| 9892 | pub name: Cow<'input, [u8]>, |
| 9893 | } |
| 9894 | impl_debug_if_no_extra_traits!(InternAtomRequest<'_>, "InternAtomRequest" ); |
| 9895 | impl<'input> InternAtomRequest<'input> { |
| 9896 | /// Serialize this request into bytes for the provided connection |
| 9897 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 9898 | let length_so_far = 0; |
| 9899 | let only_if_exists_bytes = self.only_if_exists.serialize(); |
| 9900 | let name_len = u16::try_from(self.name.len()).expect("`name` has too many elements" ); |
| 9901 | let name_len_bytes = name_len.serialize(); |
| 9902 | let mut request0 = vec![ |
| 9903 | INTERN_ATOM_REQUEST, |
| 9904 | only_if_exists_bytes[0], |
| 9905 | 0, |
| 9906 | 0, |
| 9907 | name_len_bytes[0], |
| 9908 | name_len_bytes[1], |
| 9909 | 0, |
| 9910 | 0, |
| 9911 | ]; |
| 9912 | let length_so_far = length_so_far + request0.len(); |
| 9913 | let length_so_far = length_so_far + self.name.len(); |
| 9914 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 9915 | let length_so_far = length_so_far + padding0.len(); |
| 9916 | assert_eq!(length_so_far % 4, 0); |
| 9917 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 9918 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 9919 | ([request0.into(), self.name, padding0.into()], vec![]) |
| 9920 | } |
| 9921 | /// Parse this request given its header, its body, and any fds that go along with it |
| 9922 | #[cfg (feature = "request-parsing" )] |
| 9923 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 9924 | if header.major_opcode != INTERN_ATOM_REQUEST { |
| 9925 | return Err(ParseError::InvalidValue); |
| 9926 | } |
| 9927 | let remaining = &[header.minor_opcode]; |
| 9928 | let (only_if_exists, remaining) = bool::try_parse(remaining)?; |
| 9929 | let _ = remaining; |
| 9930 | let (name_len, remaining) = u16::try_parse(value)?; |
| 9931 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 9932 | let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; |
| 9933 | let _ = remaining; |
| 9934 | Ok(InternAtomRequest { |
| 9935 | only_if_exists, |
| 9936 | name: Cow::Borrowed(name), |
| 9937 | }) |
| 9938 | } |
| 9939 | /// Clone all borrowed data in this InternAtomRequest. |
| 9940 | pub fn into_owned(self) -> InternAtomRequest<'static> { |
| 9941 | InternAtomRequest { |
| 9942 | only_if_exists: self.only_if_exists, |
| 9943 | name: Cow::Owned(self.name.into_owned()), |
| 9944 | } |
| 9945 | } |
| 9946 | } |
| 9947 | impl<'input> Request for InternAtomRequest<'input> { |
| 9948 | const EXTENSION_NAME: Option<&'static str> = None; |
| 9949 | |
| 9950 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 9951 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 9952 | // Flatten the buffers into a single vector |
| 9953 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 9954 | (buf, fds) |
| 9955 | } |
| 9956 | } |
| 9957 | impl<'input> crate::x11_utils::ReplyRequest for InternAtomRequest<'input> { |
| 9958 | type Reply = InternAtomReply; |
| 9959 | } |
| 9960 | |
| 9961 | #[derive (Clone, Copy, Default)] |
| 9962 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9963 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9964 | pub struct InternAtomReply { |
| 9965 | pub sequence: u16, |
| 9966 | pub length: u32, |
| 9967 | pub atom: Atom, |
| 9968 | } |
| 9969 | impl_debug_if_no_extra_traits!(InternAtomReply, "InternAtomReply" ); |
| 9970 | impl TryParse for InternAtomReply { |
| 9971 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 9972 | let remaining: &[u8] = initial_value; |
| 9973 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 9974 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 9975 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 9976 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 9977 | let (atom: u32, remaining: &[u8]) = Atom::try_parse(remaining)?; |
| 9978 | if response_type != 1 { |
| 9979 | return Err(ParseError::InvalidValue); |
| 9980 | } |
| 9981 | let result: InternAtomReply = InternAtomReply { sequence, length, atom }; |
| 9982 | let _ = remaining; |
| 9983 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 9984 | .ok_or(err:ParseError::InsufficientData)?; |
| 9985 | Ok((result, remaining)) |
| 9986 | } |
| 9987 | } |
| 9988 | impl Serialize for InternAtomReply { |
| 9989 | type Bytes = [u8; 12]; |
| 9990 | fn serialize(&self) -> [u8; 12] { |
| 9991 | let response_type_bytes = &[1]; |
| 9992 | let sequence_bytes = self.sequence.serialize(); |
| 9993 | let length_bytes = self.length.serialize(); |
| 9994 | let atom_bytes = self.atom.serialize(); |
| 9995 | [ |
| 9996 | response_type_bytes[0], |
| 9997 | 0, |
| 9998 | sequence_bytes[0], |
| 9999 | sequence_bytes[1], |
| 10000 | length_bytes[0], |
| 10001 | length_bytes[1], |
| 10002 | length_bytes[2], |
| 10003 | length_bytes[3], |
| 10004 | atom_bytes[0], |
| 10005 | atom_bytes[1], |
| 10006 | atom_bytes[2], |
| 10007 | atom_bytes[3], |
| 10008 | ] |
| 10009 | } |
| 10010 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 10011 | bytes.reserve(12); |
| 10012 | let response_type_bytes = &[1]; |
| 10013 | bytes.push(response_type_bytes[0]); |
| 10014 | bytes.extend_from_slice(&[0; 1]); |
| 10015 | self.sequence.serialize_into(bytes); |
| 10016 | self.length.serialize_into(bytes); |
| 10017 | self.atom.serialize_into(bytes); |
| 10018 | } |
| 10019 | } |
| 10020 | |
| 10021 | /// Opcode for the GetAtomName request |
| 10022 | pub const GET_ATOM_NAME_REQUEST: u8 = 17; |
| 10023 | #[derive (Clone, Copy, Default)] |
| 10024 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 10025 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 10026 | pub struct GetAtomNameRequest { |
| 10027 | pub atom: Atom, |
| 10028 | } |
| 10029 | impl_debug_if_no_extra_traits!(GetAtomNameRequest, "GetAtomNameRequest" ); |
| 10030 | impl GetAtomNameRequest { |
| 10031 | /// Serialize this request into bytes for the provided connection |
| 10032 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 10033 | let length_so_far = 0; |
| 10034 | let atom_bytes = self.atom.serialize(); |
| 10035 | let mut request0 = vec![ |
| 10036 | GET_ATOM_NAME_REQUEST, |
| 10037 | 0, |
| 10038 | 0, |
| 10039 | 0, |
| 10040 | atom_bytes[0], |
| 10041 | atom_bytes[1], |
| 10042 | atom_bytes[2], |
| 10043 | atom_bytes[3], |
| 10044 | ]; |
| 10045 | let length_so_far = length_so_far + request0.len(); |
| 10046 | assert_eq!(length_so_far % 4, 0); |
| 10047 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 10048 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 10049 | ([request0.into()], vec![]) |
| 10050 | } |
| 10051 | /// Parse this request given its header, its body, and any fds that go along with it |
| 10052 | #[cfg (feature = "request-parsing" )] |
| 10053 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 10054 | if header.major_opcode != GET_ATOM_NAME_REQUEST { |
| 10055 | return Err(ParseError::InvalidValue); |
| 10056 | } |
| 10057 | let remaining = &[header.minor_opcode]; |
| 10058 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 10059 | let _ = remaining; |
| 10060 | let (atom, remaining) = Atom::try_parse(value)?; |
| 10061 | let _ = remaining; |
| 10062 | Ok(GetAtomNameRequest { |
| 10063 | atom, |
| 10064 | }) |
| 10065 | } |
| 10066 | } |
| 10067 | impl Request for GetAtomNameRequest { |
| 10068 | const EXTENSION_NAME: Option<&'static str> = None; |
| 10069 | |
| 10070 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 10071 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 10072 | // Flatten the buffers into a single vector |
| 10073 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 10074 | (buf, fds) |
| 10075 | } |
| 10076 | } |
| 10077 | impl crate::x11_utils::ReplyRequest for GetAtomNameRequest { |
| 10078 | type Reply = GetAtomNameReply; |
| 10079 | } |
| 10080 | |
| 10081 | #[derive (Clone, Default)] |
| 10082 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 10083 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 10084 | pub struct GetAtomNameReply { |
| 10085 | pub sequence: u16, |
| 10086 | pub length: u32, |
| 10087 | pub name: Vec<u8>, |
| 10088 | } |
| 10089 | impl_debug_if_no_extra_traits!(GetAtomNameReply, "GetAtomNameReply" ); |
| 10090 | impl TryParse for GetAtomNameReply { |
| 10091 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 10092 | let remaining: &[u8] = initial_value; |
| 10093 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 10094 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 10095 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 10096 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 10097 | let (name_len: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 10098 | let remaining: &[u8] = remaining.get(22..).ok_or(err:ParseError::InsufficientData)?; |
| 10099 | let (name: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data:remaining, list_length:name_len.try_to_usize()?)?; |
| 10100 | let name: Vec = name.to_vec(); |
| 10101 | if response_type != 1 { |
| 10102 | return Err(ParseError::InvalidValue); |
| 10103 | } |
| 10104 | let result: GetAtomNameReply = GetAtomNameReply { sequence, length, name }; |
| 10105 | let _ = remaining; |
| 10106 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 10107 | .ok_or(err:ParseError::InsufficientData)?; |
| 10108 | Ok((result, remaining)) |
| 10109 | } |
| 10110 | } |
| 10111 | impl Serialize for GetAtomNameReply { |
| 10112 | type Bytes = Vec<u8>; |
| 10113 | fn serialize(&self) -> Vec<u8> { |
| 10114 | let mut result: Vec = Vec::new(); |
| 10115 | self.serialize_into(&mut result); |
| 10116 | result |
| 10117 | } |
| 10118 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 10119 | bytes.reserve(additional:32); |
| 10120 | let response_type_bytes: &[u8; 1] = &[1]; |
| 10121 | bytes.push(response_type_bytes[0]); |
| 10122 | bytes.extend_from_slice(&[0; 1]); |
| 10123 | self.sequence.serialize_into(bytes); |
| 10124 | self.length.serialize_into(bytes); |
| 10125 | let name_len: u16 = u16::try_from(self.name.len()).expect(msg:"`name` has too many elements" ); |
| 10126 | name_len.serialize_into(bytes); |
| 10127 | bytes.extend_from_slice(&[0; 22]); |
| 10128 | bytes.extend_from_slice(&self.name); |
| 10129 | } |
| 10130 | } |
| 10131 | impl GetAtomNameReply { |
| 10132 | /// Get the value of the `name_len` field. |
| 10133 | /// |
| 10134 | /// The `name_len` field is used as the length field of the `name` field. |
| 10135 | /// This function computes the field's value again based on the length of the list. |
| 10136 | /// |
| 10137 | /// # Panics |
| 10138 | /// |
| 10139 | /// Panics if the value cannot be represented in the target type. This |
| 10140 | /// cannot happen with values of the struct received from the X11 server. |
| 10141 | pub fn name_len(&self) -> u16 { |
| 10142 | self.name.len() |
| 10143 | .try_into().unwrap() |
| 10144 | } |
| 10145 | } |
| 10146 | |
| 10147 | /// # Fields |
| 10148 | /// |
| 10149 | /// * `Replace` - Discard the previous property value and store the new data. |
| 10150 | /// * `Prepend` - Insert the new data before the beginning of existing data. The `format` must |
| 10151 | /// match existing property value. If the property is undefined, it is treated as |
| 10152 | /// defined with the correct type and format with zero-length data. |
| 10153 | /// * `Append` - Insert the new data after the beginning of existing data. The `format` must |
| 10154 | /// match existing property value. If the property is undefined, it is treated as |
| 10155 | /// defined with the correct type and format with zero-length data. |
| 10156 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 10157 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 10158 | pub struct PropMode(u8); |
| 10159 | impl PropMode { |
| 10160 | pub const REPLACE: Self = Self(0); |
| 10161 | pub const PREPEND: Self = Self(1); |
| 10162 | pub const APPEND: Self = Self(2); |
| 10163 | } |
| 10164 | impl From<PropMode> for u8 { |
| 10165 | #[inline ] |
| 10166 | fn from(input: PropMode) -> Self { |
| 10167 | input.0 |
| 10168 | } |
| 10169 | } |
| 10170 | impl From<PropMode> for Option<u8> { |
| 10171 | #[inline ] |
| 10172 | fn from(input: PropMode) -> Self { |
| 10173 | Some(input.0) |
| 10174 | } |
| 10175 | } |
| 10176 | impl From<PropMode> for u16 { |
| 10177 | #[inline ] |
| 10178 | fn from(input: PropMode) -> Self { |
| 10179 | u16::from(input.0) |
| 10180 | } |
| 10181 | } |
| 10182 | impl From<PropMode> for Option<u16> { |
| 10183 | #[inline ] |
| 10184 | fn from(input: PropMode) -> Self { |
| 10185 | Some(u16::from(input.0)) |
| 10186 | } |
| 10187 | } |
| 10188 | impl From<PropMode> for u32 { |
| 10189 | #[inline ] |
| 10190 | fn from(input: PropMode) -> Self { |
| 10191 | u32::from(input.0) |
| 10192 | } |
| 10193 | } |
| 10194 | impl From<PropMode> for Option<u32> { |
| 10195 | #[inline ] |
| 10196 | fn from(input: PropMode) -> Self { |
| 10197 | Some(u32::from(input.0)) |
| 10198 | } |
| 10199 | } |
| 10200 | impl From<u8> for PropMode { |
| 10201 | #[inline ] |
| 10202 | fn from(value: u8) -> Self { |
| 10203 | Self(value) |
| 10204 | } |
| 10205 | } |
| 10206 | impl core::fmt::Debug for PropMode { |
| 10207 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 10208 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 10209 | (Self::REPLACE.0.into(), "REPLACE" , "Replace" ), |
| 10210 | (Self::PREPEND.0.into(), "PREPEND" , "Prepend" ), |
| 10211 | (Self::APPEND.0.into(), "APPEND" , "Append" ), |
| 10212 | ]; |
| 10213 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 10214 | } |
| 10215 | } |
| 10216 | |
| 10217 | /// Opcode for the ChangeProperty request |
| 10218 | pub const CHANGE_PROPERTY_REQUEST: u8 = 18; |
| 10219 | /// Changes a window property. |
| 10220 | /// |
| 10221 | /// Sets or updates a property on the specified `window`. Properties are for |
| 10222 | /// example the window title (`WM_NAME`) or its minimum size (`WM_NORMAL_HINTS`). |
| 10223 | /// Protocols such as EWMH also use properties - for example EWMH defines the |
| 10224 | /// window title, encoded as UTF-8 string, in the `_NET_WM_NAME` property. |
| 10225 | /// |
| 10226 | /// # Fields |
| 10227 | /// |
| 10228 | /// * `window` - The window whose property you want to change. |
| 10229 | /// * `mode` - |
| 10230 | /// * `property` - The property you want to change (an atom). |
| 10231 | /// * `type` - The type of the property you want to change (an atom). |
| 10232 | /// * `format` - Specifies whether the data should be viewed as a list of 8-bit, 16-bit or |
| 10233 | /// 32-bit quantities. Possible values are 8, 16 and 32. This information allows |
| 10234 | /// the X server to correctly perform byte-swap operations as necessary. |
| 10235 | /// * `data_len` - Specifies the number of elements (see `format`). |
| 10236 | /// * `data` - The property data. |
| 10237 | /// |
| 10238 | /// # Errors |
| 10239 | /// |
| 10240 | /// * `Match` - TODO: reasons? |
| 10241 | /// * `Value` - TODO: reasons? |
| 10242 | /// * `Window` - The specified `window` does not exist. |
| 10243 | /// * `Atom` - `property` or `type` do not refer to a valid atom. |
| 10244 | /// * `Alloc` - The X server could not store the property (no memory?). |
| 10245 | /// |
| 10246 | /// # See |
| 10247 | /// |
| 10248 | /// * `InternAtom`: request |
| 10249 | /// * `xprop`: program |
| 10250 | /// |
| 10251 | /// # Example |
| 10252 | /// |
| 10253 | /// ```text |
| 10254 | /// /* |
| 10255 | /// * Sets the WM_NAME property of the window to "XCB Example". |
| 10256 | /// * |
| 10257 | /// */ |
| 10258 | /// void my_example(xcb_connection_t *conn, xcb_window_t window) { |
| 10259 | /// xcb_change_property(conn, |
| 10260 | /// XCB_PROP_MODE_REPLACE, |
| 10261 | /// window, |
| 10262 | /// XCB_ATOM_WM_NAME, |
| 10263 | /// XCB_ATOM_STRING, |
| 10264 | /// 8, |
| 10265 | /// strlen("XCB Example"), |
| 10266 | /// "XCB Example"); |
| 10267 | /// xcb_flush(conn); |
| 10268 | /// } |
| 10269 | /// ``` |
| 10270 | #[derive (Clone, Default)] |
| 10271 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 10272 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 10273 | pub struct ChangePropertyRequest<'input> { |
| 10274 | pub mode: PropMode, |
| 10275 | pub window: Window, |
| 10276 | pub property: Atom, |
| 10277 | pub type_: Atom, |
| 10278 | pub format: u8, |
| 10279 | pub data_len: u32, |
| 10280 | pub data: Cow<'input, [u8]>, |
| 10281 | } |
| 10282 | impl_debug_if_no_extra_traits!(ChangePropertyRequest<'_>, "ChangePropertyRequest" ); |
| 10283 | impl<'input> ChangePropertyRequest<'input> { |
| 10284 | /// Serialize this request into bytes for the provided connection |
| 10285 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 10286 | let length_so_far = 0; |
| 10287 | let mode_bytes = u8::from(self.mode).serialize(); |
| 10288 | let window_bytes = self.window.serialize(); |
| 10289 | let property_bytes = self.property.serialize(); |
| 10290 | let type_bytes = self.type_.serialize(); |
| 10291 | let format_bytes = self.format.serialize(); |
| 10292 | let data_len_bytes = self.data_len.serialize(); |
| 10293 | let mut request0 = vec![ |
| 10294 | CHANGE_PROPERTY_REQUEST, |
| 10295 | mode_bytes[0], |
| 10296 | 0, |
| 10297 | 0, |
| 10298 | window_bytes[0], |
| 10299 | window_bytes[1], |
| 10300 | window_bytes[2], |
| 10301 | window_bytes[3], |
| 10302 | property_bytes[0], |
| 10303 | property_bytes[1], |
| 10304 | property_bytes[2], |
| 10305 | property_bytes[3], |
| 10306 | type_bytes[0], |
| 10307 | type_bytes[1], |
| 10308 | type_bytes[2], |
| 10309 | type_bytes[3], |
| 10310 | format_bytes[0], |
| 10311 | 0, |
| 10312 | 0, |
| 10313 | 0, |
| 10314 | data_len_bytes[0], |
| 10315 | data_len_bytes[1], |
| 10316 | data_len_bytes[2], |
| 10317 | data_len_bytes[3], |
| 10318 | ]; |
| 10319 | let length_so_far = length_so_far + request0.len(); |
| 10320 | assert_eq!(self.data.len(), usize::try_from(u32::from(self.data_len).checked_mul(u32::from(self.format)).unwrap().checked_div(8u32).unwrap()).unwrap(), "`data` has an incorrect length" ); |
| 10321 | let length_so_far = length_so_far + self.data.len(); |
| 10322 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 10323 | let length_so_far = length_so_far + padding0.len(); |
| 10324 | assert_eq!(length_so_far % 4, 0); |
| 10325 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 10326 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 10327 | ([request0.into(), self.data, padding0.into()], vec![]) |
| 10328 | } |
| 10329 | /// Parse this request given its header, its body, and any fds that go along with it |
| 10330 | #[cfg (feature = "request-parsing" )] |
| 10331 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 10332 | if header.major_opcode != CHANGE_PROPERTY_REQUEST { |
| 10333 | return Err(ParseError::InvalidValue); |
| 10334 | } |
| 10335 | let remaining = &[header.minor_opcode]; |
| 10336 | let (mode, remaining) = u8::try_parse(remaining)?; |
| 10337 | let mode = mode.into(); |
| 10338 | let _ = remaining; |
| 10339 | let (window, remaining) = Window::try_parse(value)?; |
| 10340 | let (property, remaining) = Atom::try_parse(remaining)?; |
| 10341 | let (type_, remaining) = Atom::try_parse(remaining)?; |
| 10342 | let (format, remaining) = u8::try_parse(remaining)?; |
| 10343 | let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; |
| 10344 | let (data_len, remaining) = u32::try_parse(remaining)?; |
| 10345 | let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, u32::from(data_len).checked_mul(u32::from(format)).ok_or(ParseError::InvalidExpression)?.checked_div(8u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; |
| 10346 | let _ = remaining; |
| 10347 | Ok(ChangePropertyRequest { |
| 10348 | mode, |
| 10349 | window, |
| 10350 | property, |
| 10351 | type_, |
| 10352 | format, |
| 10353 | data_len, |
| 10354 | data: Cow::Borrowed(data), |
| 10355 | }) |
| 10356 | } |
| 10357 | /// Clone all borrowed data in this ChangePropertyRequest. |
| 10358 | pub fn into_owned(self) -> ChangePropertyRequest<'static> { |
| 10359 | ChangePropertyRequest { |
| 10360 | mode: self.mode, |
| 10361 | window: self.window, |
| 10362 | property: self.property, |
| 10363 | type_: self.type_, |
| 10364 | format: self.format, |
| 10365 | data_len: self.data_len, |
| 10366 | data: Cow::Owned(self.data.into_owned()), |
| 10367 | } |
| 10368 | } |
| 10369 | } |
| 10370 | impl<'input> Request for ChangePropertyRequest<'input> { |
| 10371 | const EXTENSION_NAME: Option<&'static str> = None; |
| 10372 | |
| 10373 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 10374 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 10375 | // Flatten the buffers into a single vector |
| 10376 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 10377 | (buf, fds) |
| 10378 | } |
| 10379 | } |
| 10380 | impl<'input> crate::x11_utils::VoidRequest for ChangePropertyRequest<'input> { |
| 10381 | } |
| 10382 | |
| 10383 | /// Opcode for the DeleteProperty request |
| 10384 | pub const DELETE_PROPERTY_REQUEST: u8 = 19; |
| 10385 | #[derive (Clone, Copy, Default)] |
| 10386 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 10387 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 10388 | pub struct DeletePropertyRequest { |
| 10389 | pub window: Window, |
| 10390 | pub property: Atom, |
| 10391 | } |
| 10392 | impl_debug_if_no_extra_traits!(DeletePropertyRequest, "DeletePropertyRequest" ); |
| 10393 | impl DeletePropertyRequest { |
| 10394 | /// Serialize this request into bytes for the provided connection |
| 10395 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 10396 | let length_so_far = 0; |
| 10397 | let window_bytes = self.window.serialize(); |
| 10398 | let property_bytes = self.property.serialize(); |
| 10399 | let mut request0 = vec![ |
| 10400 | DELETE_PROPERTY_REQUEST, |
| 10401 | 0, |
| 10402 | 0, |
| 10403 | 0, |
| 10404 | window_bytes[0], |
| 10405 | window_bytes[1], |
| 10406 | window_bytes[2], |
| 10407 | window_bytes[3], |
| 10408 | property_bytes[0], |
| 10409 | property_bytes[1], |
| 10410 | property_bytes[2], |
| 10411 | property_bytes[3], |
| 10412 | ]; |
| 10413 | let length_so_far = length_so_far + request0.len(); |
| 10414 | assert_eq!(length_so_far % 4, 0); |
| 10415 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 10416 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 10417 | ([request0.into()], vec![]) |
| 10418 | } |
| 10419 | /// Parse this request given its header, its body, and any fds that go along with it |
| 10420 | #[cfg (feature = "request-parsing" )] |
| 10421 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 10422 | if header.major_opcode != DELETE_PROPERTY_REQUEST { |
| 10423 | return Err(ParseError::InvalidValue); |
| 10424 | } |
| 10425 | let remaining = &[header.minor_opcode]; |
| 10426 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 10427 | let _ = remaining; |
| 10428 | let (window, remaining) = Window::try_parse(value)?; |
| 10429 | let (property, remaining) = Atom::try_parse(remaining)?; |
| 10430 | let _ = remaining; |
| 10431 | Ok(DeletePropertyRequest { |
| 10432 | window, |
| 10433 | property, |
| 10434 | }) |
| 10435 | } |
| 10436 | } |
| 10437 | impl Request for DeletePropertyRequest { |
| 10438 | const EXTENSION_NAME: Option<&'static str> = None; |
| 10439 | |
| 10440 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 10441 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 10442 | // Flatten the buffers into a single vector |
| 10443 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 10444 | (buf, fds) |
| 10445 | } |
| 10446 | } |
| 10447 | impl crate::x11_utils::VoidRequest for DeletePropertyRequest { |
| 10448 | } |
| 10449 | |
| 10450 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 10451 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 10452 | pub struct GetPropertyType(u8); |
| 10453 | impl GetPropertyType { |
| 10454 | pub const ANY: Self = Self(0); |
| 10455 | } |
| 10456 | impl From<GetPropertyType> for u8 { |
| 10457 | #[inline ] |
| 10458 | fn from(input: GetPropertyType) -> Self { |
| 10459 | input.0 |
| 10460 | } |
| 10461 | } |
| 10462 | impl From<GetPropertyType> for Option<u8> { |
| 10463 | #[inline ] |
| 10464 | fn from(input: GetPropertyType) -> Self { |
| 10465 | Some(input.0) |
| 10466 | } |
| 10467 | } |
| 10468 | impl From<GetPropertyType> for u16 { |
| 10469 | #[inline ] |
| 10470 | fn from(input: GetPropertyType) -> Self { |
| 10471 | u16::from(input.0) |
| 10472 | } |
| 10473 | } |
| 10474 | impl From<GetPropertyType> for Option<u16> { |
| 10475 | #[inline ] |
| 10476 | fn from(input: GetPropertyType) -> Self { |
| 10477 | Some(u16::from(input.0)) |
| 10478 | } |
| 10479 | } |
| 10480 | impl From<GetPropertyType> for u32 { |
| 10481 | #[inline ] |
| 10482 | fn from(input: GetPropertyType) -> Self { |
| 10483 | u32::from(input.0) |
| 10484 | } |
| 10485 | } |
| 10486 | impl From<GetPropertyType> for Option<u32> { |
| 10487 | #[inline ] |
| 10488 | fn from(input: GetPropertyType) -> Self { |
| 10489 | Some(u32::from(input.0)) |
| 10490 | } |
| 10491 | } |
| 10492 | impl From<u8> for GetPropertyType { |
| 10493 | #[inline ] |
| 10494 | fn from(value: u8) -> Self { |
| 10495 | Self(value) |
| 10496 | } |
| 10497 | } |
| 10498 | impl core::fmt::Debug for GetPropertyType { |
| 10499 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 10500 | let variants: [(u32, &'static str, &'static …); 1] = [ |
| 10501 | (Self::ANY.0.into(), "ANY" , "Any" ), |
| 10502 | ]; |
| 10503 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 10504 | } |
| 10505 | } |
| 10506 | |
| 10507 | /// Opcode for the GetProperty request |
| 10508 | pub const GET_PROPERTY_REQUEST: u8 = 20; |
| 10509 | /// Gets a window property. |
| 10510 | /// |
| 10511 | /// Gets the specified `property` from the specified `window`. Properties are for |
| 10512 | /// example the window title (`WM_NAME`) or its minimum size (`WM_NORMAL_HINTS`). |
| 10513 | /// Protocols such as EWMH also use properties - for example EWMH defines the |
| 10514 | /// window title, encoded as UTF-8 string, in the `_NET_WM_NAME` property. |
| 10515 | /// |
| 10516 | /// TODO: talk about `type` |
| 10517 | /// |
| 10518 | /// TODO: talk about `delete` |
| 10519 | /// |
| 10520 | /// TODO: talk about the offset/length thing. what's a valid use case? |
| 10521 | /// |
| 10522 | /// # Fields |
| 10523 | /// |
| 10524 | /// * `window` - The window whose property you want to get. |
| 10525 | /// * `delete` - Whether the property should actually be deleted. For deleting a property, the |
| 10526 | /// specified `type` has to match the actual property type. |
| 10527 | /// * `property` - The property you want to get (an atom). |
| 10528 | /// * `type` - The type of the property you want to get (an atom). |
| 10529 | /// * `long_offset` - Specifies the offset (in 32-bit multiples) in the specified property where the |
| 10530 | /// data is to be retrieved. |
| 10531 | /// * `long_length` - Specifies how many 32-bit multiples of data should be retrieved (e.g. if you |
| 10532 | /// set `long_length` to 4, you will receive 16 bytes of data). |
| 10533 | /// |
| 10534 | /// # Errors |
| 10535 | /// |
| 10536 | /// * `Window` - The specified `window` does not exist. |
| 10537 | /// * `Atom` - `property` or `type` do not refer to a valid atom. |
| 10538 | /// * `Value` - The specified `long_offset` is beyond the actual property length (e.g. the |
| 10539 | /// property has a length of 3 bytes and you are setting `long_offset` to 1, |
| 10540 | /// resulting in a byte offset of 4). |
| 10541 | /// |
| 10542 | /// # See |
| 10543 | /// |
| 10544 | /// * `InternAtom`: request |
| 10545 | /// * `xprop`: program |
| 10546 | /// |
| 10547 | /// # Example |
| 10548 | /// |
| 10549 | /// ```text |
| 10550 | /// /* |
| 10551 | /// * Prints the WM_NAME property of the window. |
| 10552 | /// * |
| 10553 | /// */ |
| 10554 | /// void my_example(xcb_connection_t *c, xcb_window_t window) { |
| 10555 | /// xcb_get_property_cookie_t cookie; |
| 10556 | /// xcb_get_property_reply_t *reply; |
| 10557 | /// |
| 10558 | /// /* These atoms are predefined in the X11 protocol. */ |
| 10559 | /// xcb_atom_t property = XCB_ATOM_WM_NAME; |
| 10560 | /// xcb_atom_t type = XCB_ATOM_STRING; |
| 10561 | /// |
| 10562 | /// // TODO: a reasonable long_length for WM_NAME? |
| 10563 | /// cookie = xcb_get_property(c, 0, window, property, type, 0, 0); |
| 10564 | /// if ((reply = xcb_get_property_reply(c, cookie, NULL))) { |
| 10565 | /// int len = xcb_get_property_value_length(reply); |
| 10566 | /// if (len == 0) { |
| 10567 | /// printf("TODO\\n"); |
| 10568 | /// free(reply); |
| 10569 | /// return; |
| 10570 | /// } |
| 10571 | /// printf("WM_NAME is %.*s\\n", len, |
| 10572 | /// (char*)xcb_get_property_value(reply)); |
| 10573 | /// } |
| 10574 | /// free(reply); |
| 10575 | /// } |
| 10576 | /// ``` |
| 10577 | #[derive (Clone, Copy, Default)] |
| 10578 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 10579 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 10580 | pub struct GetPropertyRequest { |
| 10581 | pub delete: bool, |
| 10582 | pub window: Window, |
| 10583 | pub property: Atom, |
| 10584 | pub type_: Atom, |
| 10585 | pub long_offset: u32, |
| 10586 | pub long_length: u32, |
| 10587 | } |
| 10588 | impl_debug_if_no_extra_traits!(GetPropertyRequest, "GetPropertyRequest" ); |
| 10589 | impl GetPropertyRequest { |
| 10590 | /// Serialize this request into bytes for the provided connection |
| 10591 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 10592 | let length_so_far = 0; |
| 10593 | let delete_bytes = self.delete.serialize(); |
| 10594 | let window_bytes = self.window.serialize(); |
| 10595 | let property_bytes = self.property.serialize(); |
| 10596 | let type_bytes = self.type_.serialize(); |
| 10597 | let long_offset_bytes = self.long_offset.serialize(); |
| 10598 | let long_length_bytes = self.long_length.serialize(); |
| 10599 | let mut request0 = vec![ |
| 10600 | GET_PROPERTY_REQUEST, |
| 10601 | delete_bytes[0], |
| 10602 | 0, |
| 10603 | 0, |
| 10604 | window_bytes[0], |
| 10605 | window_bytes[1], |
| 10606 | window_bytes[2], |
| 10607 | window_bytes[3], |
| 10608 | property_bytes[0], |
| 10609 | property_bytes[1], |
| 10610 | property_bytes[2], |
| 10611 | property_bytes[3], |
| 10612 | type_bytes[0], |
| 10613 | type_bytes[1], |
| 10614 | type_bytes[2], |
| 10615 | type_bytes[3], |
| 10616 | long_offset_bytes[0], |
| 10617 | long_offset_bytes[1], |
| 10618 | long_offset_bytes[2], |
| 10619 | long_offset_bytes[3], |
| 10620 | long_length_bytes[0], |
| 10621 | long_length_bytes[1], |
| 10622 | long_length_bytes[2], |
| 10623 | long_length_bytes[3], |
| 10624 | ]; |
| 10625 | let length_so_far = length_so_far + request0.len(); |
| 10626 | assert_eq!(length_so_far % 4, 0); |
| 10627 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 10628 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 10629 | ([request0.into()], vec![]) |
| 10630 | } |
| 10631 | /// Parse this request given its header, its body, and any fds that go along with it |
| 10632 | #[cfg (feature = "request-parsing" )] |
| 10633 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 10634 | if header.major_opcode != GET_PROPERTY_REQUEST { |
| 10635 | return Err(ParseError::InvalidValue); |
| 10636 | } |
| 10637 | let remaining = &[header.minor_opcode]; |
| 10638 | let (delete, remaining) = bool::try_parse(remaining)?; |
| 10639 | let _ = remaining; |
| 10640 | let (window, remaining) = Window::try_parse(value)?; |
| 10641 | let (property, remaining) = Atom::try_parse(remaining)?; |
| 10642 | let (type_, remaining) = Atom::try_parse(remaining)?; |
| 10643 | let (long_offset, remaining) = u32::try_parse(remaining)?; |
| 10644 | let (long_length, remaining) = u32::try_parse(remaining)?; |
| 10645 | let _ = remaining; |
| 10646 | Ok(GetPropertyRequest { |
| 10647 | delete, |
| 10648 | window, |
| 10649 | property, |
| 10650 | type_, |
| 10651 | long_offset, |
| 10652 | long_length, |
| 10653 | }) |
| 10654 | } |
| 10655 | } |
| 10656 | impl Request for GetPropertyRequest { |
| 10657 | const EXTENSION_NAME: Option<&'static str> = None; |
| 10658 | |
| 10659 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 10660 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 10661 | // Flatten the buffers into a single vector |
| 10662 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 10663 | (buf, fds) |
| 10664 | } |
| 10665 | } |
| 10666 | impl crate::x11_utils::ReplyRequest for GetPropertyRequest { |
| 10667 | type Reply = GetPropertyReply; |
| 10668 | } |
| 10669 | impl GetPropertyReply { |
| 10670 | /// Iterate over the contained value if its format is 8. |
| 10671 | /// |
| 10672 | /// This function checks if the `format` member of the reply |
| 10673 | /// is 8. If it it is not, `None` is returned. Otherwise |
| 10674 | /// and iterator is returned that interprets the value in |
| 10675 | /// this reply as type `u8`. |
| 10676 | /// |
| 10677 | /// # Examples |
| 10678 | /// |
| 10679 | /// Successfully iterate over the value: |
| 10680 | /// ``` |
| 10681 | /// // First, we have to 'invent' a GetPropertyReply. |
| 10682 | /// let reply = x11rb_protocol::protocol::xproto::GetPropertyReply { |
| 10683 | /// format: 8, |
| 10684 | /// sequence: 0, |
| 10685 | /// length: 0, // This value is incorrect |
| 10686 | /// type_: 0, // This value is incorrect |
| 10687 | /// bytes_after: 0, |
| 10688 | /// value_len: 4, |
| 10689 | /// value: vec![1, 2, 3, 4], |
| 10690 | /// }; |
| 10691 | /// |
| 10692 | /// // This is the actual example: Iterate over the value. |
| 10693 | /// let mut iter = reply.value8().unwrap(); |
| 10694 | /// assert_eq!(iter.next(), Some(1)); |
| 10695 | /// assert_eq!(iter.next(), Some(2)); |
| 10696 | /// assert_eq!(iter.next(), Some(3)); |
| 10697 | /// assert_eq!(iter.next(), Some(4)); |
| 10698 | /// assert_eq!(iter.next(), None); |
| 10699 | /// ``` |
| 10700 | /// |
| 10701 | /// An iterator is only returned when the `format` is correct. |
| 10702 | /// The following example shows this. |
| 10703 | /// ``` |
| 10704 | /// // First, we have to 'invent' a GetPropertyReply. |
| 10705 | /// let reply = x11rb_protocol::protocol::xproto::GetPropertyReply { |
| 10706 | /// format: 42, // Not allowed in X11, but used for the example |
| 10707 | /// sequence: 0, |
| 10708 | /// length: 0, // This value is incorrect |
| 10709 | /// type_: 0, // This value is incorrect |
| 10710 | /// bytes_after: 0, |
| 10711 | /// value_len: 4, |
| 10712 | /// value: vec![1, 2, 3, 4], |
| 10713 | /// }; |
| 10714 | /// assert!(reply.value8().is_none()); |
| 10715 | /// ``` |
| 10716 | pub fn value8(&self) -> Option<impl Iterator<Item=u8> + '_> { |
| 10717 | if self.format == 8 { |
| 10718 | Some(crate::wrapper::PropertyIterator::new(&self.value)) |
| 10719 | } else { |
| 10720 | None |
| 10721 | } |
| 10722 | } |
| 10723 | /// Iterate over the contained value if its format is 16. |
| 10724 | /// |
| 10725 | /// This function checks if the `format` member of the reply |
| 10726 | /// is 16. If it it is not, `None` is returned. Otherwise |
| 10727 | /// and iterator is returned that interprets the value in |
| 10728 | /// this reply as type `u16`. |
| 10729 | /// |
| 10730 | /// # Examples |
| 10731 | /// |
| 10732 | /// Successfully iterate over the value: |
| 10733 | /// ``` |
| 10734 | /// // First, we have to 'invent' a GetPropertyReply. |
| 10735 | /// let reply = x11rb_protocol::protocol::xproto::GetPropertyReply { |
| 10736 | /// format: 16, |
| 10737 | /// sequence: 0, |
| 10738 | /// length: 0, // This value is incorrect |
| 10739 | /// type_: 0, // This value is incorrect |
| 10740 | /// bytes_after: 0, |
| 10741 | /// value_len: 4, |
| 10742 | /// value: vec![1, 1, 2, 2], |
| 10743 | /// }; |
| 10744 | /// |
| 10745 | /// // This is the actual example: Iterate over the value. |
| 10746 | /// let mut iter = reply.value16().unwrap(); |
| 10747 | /// assert_eq!(iter.next(), Some(257)); |
| 10748 | /// assert_eq!(iter.next(), Some(514)); |
| 10749 | /// assert_eq!(iter.next(), None); |
| 10750 | /// ``` |
| 10751 | /// |
| 10752 | /// An iterator is only returned when the `format` is correct. |
| 10753 | /// The following example shows this. |
| 10754 | /// ``` |
| 10755 | /// // First, we have to 'invent' a GetPropertyReply. |
| 10756 | /// let reply = x11rb_protocol::protocol::xproto::GetPropertyReply { |
| 10757 | /// format: 42, // Not allowed in X11, but used for the example |
| 10758 | /// sequence: 0, |
| 10759 | /// length: 0, // This value is incorrect |
| 10760 | /// type_: 0, // This value is incorrect |
| 10761 | /// bytes_after: 0, |
| 10762 | /// value_len: 4, |
| 10763 | /// value: vec![1, 2, 3, 4], |
| 10764 | /// }; |
| 10765 | /// assert!(reply.value16().is_none()); |
| 10766 | /// ``` |
| 10767 | pub fn value16(&self) -> Option<impl Iterator<Item=u16> + '_> { |
| 10768 | if self.format == 16 { |
| 10769 | Some(crate::wrapper::PropertyIterator::new(&self.value)) |
| 10770 | } else { |
| 10771 | None |
| 10772 | } |
| 10773 | } |
| 10774 | /// Iterate over the contained value if its format is 32. |
| 10775 | /// |
| 10776 | /// This function checks if the `format` member of the reply |
| 10777 | /// is 32. If it it is not, `None` is returned. Otherwise |
| 10778 | /// and iterator is returned that interprets the value in |
| 10779 | /// this reply as type `u32`. |
| 10780 | /// |
| 10781 | /// # Examples |
| 10782 | /// |
| 10783 | /// Successfully iterate over the value: |
| 10784 | /// ``` |
| 10785 | /// // First, we have to 'invent' a GetPropertyReply. |
| 10786 | /// let reply = x11rb_protocol::protocol::xproto::GetPropertyReply { |
| 10787 | /// format: 32, |
| 10788 | /// sequence: 0, |
| 10789 | /// length: 0, // This value is incorrect |
| 10790 | /// type_: 0, // This value is incorrect |
| 10791 | /// bytes_after: 0, |
| 10792 | /// value_len: 4, |
| 10793 | /// value: vec![1, 2, 2, 1], |
| 10794 | /// }; |
| 10795 | /// |
| 10796 | /// // This is the actual example: Iterate over the value. |
| 10797 | /// let mut iter = reply.value32().unwrap(); |
| 10798 | /// assert_eq!(iter.next(), Some(16908801)); |
| 10799 | /// assert_eq!(iter.next(), None); |
| 10800 | /// ``` |
| 10801 | /// |
| 10802 | /// An iterator is only returned when the `format` is correct. |
| 10803 | /// The following example shows this. |
| 10804 | /// ``` |
| 10805 | /// // First, we have to 'invent' a GetPropertyReply. |
| 10806 | /// let reply = x11rb_protocol::protocol::xproto::GetPropertyReply { |
| 10807 | /// format: 42, // Not allowed in X11, but used for the example |
| 10808 | /// sequence: 0, |
| 10809 | /// length: 0, // This value is incorrect |
| 10810 | /// type_: 0, // This value is incorrect |
| 10811 | /// bytes_after: 0, |
| 10812 | /// value_len: 4, |
| 10813 | /// value: vec![1, 2, 3, 4], |
| 10814 | /// }; |
| 10815 | /// assert!(reply.value32().is_none()); |
| 10816 | /// ``` |
| 10817 | pub fn value32(&self) -> Option<impl Iterator<Item=u32> + '_> { |
| 10818 | if self.format == 32 { |
| 10819 | Some(crate::wrapper::PropertyIterator::new(&self.value)) |
| 10820 | } else { |
| 10821 | None |
| 10822 | } |
| 10823 | } |
| 10824 | } |
| 10825 | |
| 10826 | |
| 10827 | /// # Fields |
| 10828 | /// |
| 10829 | /// * `format` - Specifies whether the data should be viewed as a list of 8-bit, 16-bit, or |
| 10830 | /// 32-bit quantities. Possible values are 8, 16, and 32. This information allows |
| 10831 | /// the X server to correctly perform byte-swap operations as necessary. |
| 10832 | /// * `type` - The actual type of the property (an atom). |
| 10833 | /// * `bytes_after` - The number of bytes remaining to be read in the property if a partial read was |
| 10834 | /// performed. |
| 10835 | /// * `value_len` - The length of value. You should use the corresponding accessor instead of this |
| 10836 | /// field. |
| 10837 | #[derive (Clone, Default)] |
| 10838 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 10839 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 10840 | pub struct GetPropertyReply { |
| 10841 | pub format: u8, |
| 10842 | pub sequence: u16, |
| 10843 | pub length: u32, |
| 10844 | pub type_: Atom, |
| 10845 | pub bytes_after: u32, |
| 10846 | pub value_len: u32, |
| 10847 | pub value: Vec<u8>, |
| 10848 | } |
| 10849 | impl_debug_if_no_extra_traits!(GetPropertyReply, "GetPropertyReply" ); |
| 10850 | impl TryParse for GetPropertyReply { |
| 10851 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 10852 | let remaining: &[u8] = initial_value; |
| 10853 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 10854 | let (format: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 10855 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 10856 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 10857 | let (type_: u32, remaining: &[u8]) = Atom::try_parse(remaining)?; |
| 10858 | let (bytes_after: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 10859 | let (value_len: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 10860 | let remaining: &[u8] = remaining.get(12..).ok_or(err:ParseError::InsufficientData)?; |
| 10861 | let (value: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data:remaining, list_length:u32::from(value_len).checked_mul(u32::from(format).checked_div(8u32).ok_or(ParseError::InvalidExpression)?).ok_or(err:ParseError::InvalidExpression)?.try_to_usize()?)?; |
| 10862 | let value: Vec = value.to_vec(); |
| 10863 | if response_type != 1 { |
| 10864 | return Err(ParseError::InvalidValue); |
| 10865 | } |
| 10866 | let result: GetPropertyReply = GetPropertyReply { format, sequence, length, type_, bytes_after, value_len, value }; |
| 10867 | let _ = remaining; |
| 10868 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 10869 | .ok_or(err:ParseError::InsufficientData)?; |
| 10870 | Ok((result, remaining)) |
| 10871 | } |
| 10872 | } |
| 10873 | impl Serialize for GetPropertyReply { |
| 10874 | type Bytes = Vec<u8>; |
| 10875 | fn serialize(&self) -> Vec<u8> { |
| 10876 | let mut result: Vec = Vec::new(); |
| 10877 | self.serialize_into(&mut result); |
| 10878 | result |
| 10879 | } |
| 10880 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 10881 | bytes.reserve(additional:32); |
| 10882 | let response_type_bytes: &[u8; 1] = &[1]; |
| 10883 | bytes.push(response_type_bytes[0]); |
| 10884 | self.format.serialize_into(bytes); |
| 10885 | self.sequence.serialize_into(bytes); |
| 10886 | self.length.serialize_into(bytes); |
| 10887 | self.type_.serialize_into(bytes); |
| 10888 | self.bytes_after.serialize_into(bytes); |
| 10889 | self.value_len.serialize_into(bytes); |
| 10890 | bytes.extend_from_slice(&[0; 12]); |
| 10891 | assert_eq!(self.value.len(), usize::try_from(u32::from(self.value_len).checked_mul(u32::from(self.format).checked_div(8u32).unwrap()).unwrap()).unwrap(), "`value` has an incorrect length" ); |
| 10892 | bytes.extend_from_slice(&self.value); |
| 10893 | } |
| 10894 | } |
| 10895 | |
| 10896 | /// Opcode for the ListProperties request |
| 10897 | pub const LIST_PROPERTIES_REQUEST: u8 = 21; |
| 10898 | #[derive (Clone, Copy, Default)] |
| 10899 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 10900 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 10901 | pub struct ListPropertiesRequest { |
| 10902 | pub window: Window, |
| 10903 | } |
| 10904 | impl_debug_if_no_extra_traits!(ListPropertiesRequest, "ListPropertiesRequest" ); |
| 10905 | impl ListPropertiesRequest { |
| 10906 | /// Serialize this request into bytes for the provided connection |
| 10907 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 10908 | let length_so_far = 0; |
| 10909 | let window_bytes = self.window.serialize(); |
| 10910 | let mut request0 = vec![ |
| 10911 | LIST_PROPERTIES_REQUEST, |
| 10912 | 0, |
| 10913 | 0, |
| 10914 | 0, |
| 10915 | window_bytes[0], |
| 10916 | window_bytes[1], |
| 10917 | window_bytes[2], |
| 10918 | window_bytes[3], |
| 10919 | ]; |
| 10920 | let length_so_far = length_so_far + request0.len(); |
| 10921 | assert_eq!(length_so_far % 4, 0); |
| 10922 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 10923 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 10924 | ([request0.into()], vec![]) |
| 10925 | } |
| 10926 | /// Parse this request given its header, its body, and any fds that go along with it |
| 10927 | #[cfg (feature = "request-parsing" )] |
| 10928 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 10929 | if header.major_opcode != LIST_PROPERTIES_REQUEST { |
| 10930 | return Err(ParseError::InvalidValue); |
| 10931 | } |
| 10932 | let remaining = &[header.minor_opcode]; |
| 10933 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 10934 | let _ = remaining; |
| 10935 | let (window, remaining) = Window::try_parse(value)?; |
| 10936 | let _ = remaining; |
| 10937 | Ok(ListPropertiesRequest { |
| 10938 | window, |
| 10939 | }) |
| 10940 | } |
| 10941 | } |
| 10942 | impl Request for ListPropertiesRequest { |
| 10943 | const EXTENSION_NAME: Option<&'static str> = None; |
| 10944 | |
| 10945 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 10946 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 10947 | // Flatten the buffers into a single vector |
| 10948 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 10949 | (buf, fds) |
| 10950 | } |
| 10951 | } |
| 10952 | impl crate::x11_utils::ReplyRequest for ListPropertiesRequest { |
| 10953 | type Reply = ListPropertiesReply; |
| 10954 | } |
| 10955 | |
| 10956 | #[derive (Clone, Default)] |
| 10957 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 10958 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 10959 | pub struct ListPropertiesReply { |
| 10960 | pub sequence: u16, |
| 10961 | pub length: u32, |
| 10962 | pub atoms: Vec<Atom>, |
| 10963 | } |
| 10964 | impl_debug_if_no_extra_traits!(ListPropertiesReply, "ListPropertiesReply" ); |
| 10965 | impl TryParse for ListPropertiesReply { |
| 10966 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 10967 | let remaining: &[u8] = initial_value; |
| 10968 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 10969 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 10970 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 10971 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 10972 | let (atoms_len: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 10973 | let remaining: &[u8] = remaining.get(22..).ok_or(err:ParseError::InsufficientData)?; |
| 10974 | let (atoms: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<Atom>(data:remaining, list_length:atoms_len.try_to_usize()?)?; |
| 10975 | if response_type != 1 { |
| 10976 | return Err(ParseError::InvalidValue); |
| 10977 | } |
| 10978 | let result: ListPropertiesReply = ListPropertiesReply { sequence, length, atoms }; |
| 10979 | let _ = remaining; |
| 10980 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 10981 | .ok_or(err:ParseError::InsufficientData)?; |
| 10982 | Ok((result, remaining)) |
| 10983 | } |
| 10984 | } |
| 10985 | impl Serialize for ListPropertiesReply { |
| 10986 | type Bytes = Vec<u8>; |
| 10987 | fn serialize(&self) -> Vec<u8> { |
| 10988 | let mut result: Vec = Vec::new(); |
| 10989 | self.serialize_into(&mut result); |
| 10990 | result |
| 10991 | } |
| 10992 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 10993 | bytes.reserve(additional:32); |
| 10994 | let response_type_bytes: &[u8; 1] = &[1]; |
| 10995 | bytes.push(response_type_bytes[0]); |
| 10996 | bytes.extend_from_slice(&[0; 1]); |
| 10997 | self.sequence.serialize_into(bytes); |
| 10998 | self.length.serialize_into(bytes); |
| 10999 | let atoms_len: u16 = u16::try_from(self.atoms.len()).expect(msg:"`atoms` has too many elements" ); |
| 11000 | atoms_len.serialize_into(bytes); |
| 11001 | bytes.extend_from_slice(&[0; 22]); |
| 11002 | self.atoms.serialize_into(bytes); |
| 11003 | } |
| 11004 | } |
| 11005 | impl ListPropertiesReply { |
| 11006 | /// Get the value of the `atoms_len` field. |
| 11007 | /// |
| 11008 | /// The `atoms_len` field is used as the length field of the `atoms` field. |
| 11009 | /// This function computes the field's value again based on the length of the list. |
| 11010 | /// |
| 11011 | /// # Panics |
| 11012 | /// |
| 11013 | /// Panics if the value cannot be represented in the target type. This |
| 11014 | /// cannot happen with values of the struct received from the X11 server. |
| 11015 | pub fn atoms_len(&self) -> u16 { |
| 11016 | self.atoms.len() |
| 11017 | .try_into().unwrap() |
| 11018 | } |
| 11019 | } |
| 11020 | |
| 11021 | /// Opcode for the SetSelectionOwner request |
| 11022 | pub const SET_SELECTION_OWNER_REQUEST: u8 = 22; |
| 11023 | /// Sets the owner of a selection. |
| 11024 | /// |
| 11025 | /// Makes `window` the owner of the selection `selection` and updates the |
| 11026 | /// last-change time of the specified selection. |
| 11027 | /// |
| 11028 | /// TODO: briefly explain what a selection is. |
| 11029 | /// |
| 11030 | /// # Fields |
| 11031 | /// |
| 11032 | /// * `selection` - The selection. |
| 11033 | /// * `owner` - The new owner of the selection. |
| 11034 | /// |
| 11035 | /// The special value `XCB_NONE` means that the selection will have no owner. |
| 11036 | /// * `time` - Timestamp to avoid race conditions when running X over the network. |
| 11037 | /// |
| 11038 | /// The selection will not be changed if `time` is earlier than the current |
| 11039 | /// last-change time of the `selection` or is later than the current X server time. |
| 11040 | /// Otherwise, the last-change time is set to the specified time. |
| 11041 | /// |
| 11042 | /// The special value `XCB_CURRENT_TIME` will be replaced with the current server |
| 11043 | /// time. |
| 11044 | /// |
| 11045 | /// # Errors |
| 11046 | /// |
| 11047 | /// * `Atom` - `selection` does not refer to a valid atom. |
| 11048 | /// |
| 11049 | /// # See |
| 11050 | /// |
| 11051 | /// * `SetSelectionOwner`: request |
| 11052 | #[derive (Clone, Copy, Default)] |
| 11053 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 11054 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11055 | pub struct SetSelectionOwnerRequest { |
| 11056 | pub owner: Window, |
| 11057 | pub selection: Atom, |
| 11058 | pub time: Timestamp, |
| 11059 | } |
| 11060 | impl_debug_if_no_extra_traits!(SetSelectionOwnerRequest, "SetSelectionOwnerRequest" ); |
| 11061 | impl SetSelectionOwnerRequest { |
| 11062 | /// Serialize this request into bytes for the provided connection |
| 11063 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 11064 | let length_so_far = 0; |
| 11065 | let owner_bytes = self.owner.serialize(); |
| 11066 | let selection_bytes = self.selection.serialize(); |
| 11067 | let time_bytes = self.time.serialize(); |
| 11068 | let mut request0 = vec![ |
| 11069 | SET_SELECTION_OWNER_REQUEST, |
| 11070 | 0, |
| 11071 | 0, |
| 11072 | 0, |
| 11073 | owner_bytes[0], |
| 11074 | owner_bytes[1], |
| 11075 | owner_bytes[2], |
| 11076 | owner_bytes[3], |
| 11077 | selection_bytes[0], |
| 11078 | selection_bytes[1], |
| 11079 | selection_bytes[2], |
| 11080 | selection_bytes[3], |
| 11081 | time_bytes[0], |
| 11082 | time_bytes[1], |
| 11083 | time_bytes[2], |
| 11084 | time_bytes[3], |
| 11085 | ]; |
| 11086 | let length_so_far = length_so_far + request0.len(); |
| 11087 | assert_eq!(length_so_far % 4, 0); |
| 11088 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 11089 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 11090 | ([request0.into()], vec![]) |
| 11091 | } |
| 11092 | /// Parse this request given its header, its body, and any fds that go along with it |
| 11093 | #[cfg (feature = "request-parsing" )] |
| 11094 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 11095 | if header.major_opcode != SET_SELECTION_OWNER_REQUEST { |
| 11096 | return Err(ParseError::InvalidValue); |
| 11097 | } |
| 11098 | let remaining = &[header.minor_opcode]; |
| 11099 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 11100 | let _ = remaining; |
| 11101 | let (owner, remaining) = Window::try_parse(value)?; |
| 11102 | let (selection, remaining) = Atom::try_parse(remaining)?; |
| 11103 | let (time, remaining) = Timestamp::try_parse(remaining)?; |
| 11104 | let _ = remaining; |
| 11105 | Ok(SetSelectionOwnerRequest { |
| 11106 | owner, |
| 11107 | selection, |
| 11108 | time, |
| 11109 | }) |
| 11110 | } |
| 11111 | } |
| 11112 | impl Request for SetSelectionOwnerRequest { |
| 11113 | const EXTENSION_NAME: Option<&'static str> = None; |
| 11114 | |
| 11115 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 11116 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 11117 | // Flatten the buffers into a single vector |
| 11118 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 11119 | (buf, fds) |
| 11120 | } |
| 11121 | } |
| 11122 | impl crate::x11_utils::VoidRequest for SetSelectionOwnerRequest { |
| 11123 | } |
| 11124 | |
| 11125 | /// Opcode for the GetSelectionOwner request |
| 11126 | pub const GET_SELECTION_OWNER_REQUEST: u8 = 23; |
| 11127 | /// Gets the owner of a selection. |
| 11128 | /// |
| 11129 | /// Gets the owner of the specified selection. |
| 11130 | /// |
| 11131 | /// TODO: briefly explain what a selection is. |
| 11132 | /// |
| 11133 | /// # Fields |
| 11134 | /// |
| 11135 | /// * `selection` - The selection. |
| 11136 | /// |
| 11137 | /// # Errors |
| 11138 | /// |
| 11139 | /// * `Atom` - `selection` does not refer to a valid atom. |
| 11140 | /// |
| 11141 | /// # See |
| 11142 | /// |
| 11143 | /// * `SetSelectionOwner`: request |
| 11144 | #[derive (Clone, Copy, Default)] |
| 11145 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 11146 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11147 | pub struct GetSelectionOwnerRequest { |
| 11148 | pub selection: Atom, |
| 11149 | } |
| 11150 | impl_debug_if_no_extra_traits!(GetSelectionOwnerRequest, "GetSelectionOwnerRequest" ); |
| 11151 | impl GetSelectionOwnerRequest { |
| 11152 | /// Serialize this request into bytes for the provided connection |
| 11153 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 11154 | let length_so_far = 0; |
| 11155 | let selection_bytes = self.selection.serialize(); |
| 11156 | let mut request0 = vec![ |
| 11157 | GET_SELECTION_OWNER_REQUEST, |
| 11158 | 0, |
| 11159 | 0, |
| 11160 | 0, |
| 11161 | selection_bytes[0], |
| 11162 | selection_bytes[1], |
| 11163 | selection_bytes[2], |
| 11164 | selection_bytes[3], |
| 11165 | ]; |
| 11166 | let length_so_far = length_so_far + request0.len(); |
| 11167 | assert_eq!(length_so_far % 4, 0); |
| 11168 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 11169 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 11170 | ([request0.into()], vec![]) |
| 11171 | } |
| 11172 | /// Parse this request given its header, its body, and any fds that go along with it |
| 11173 | #[cfg (feature = "request-parsing" )] |
| 11174 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 11175 | if header.major_opcode != GET_SELECTION_OWNER_REQUEST { |
| 11176 | return Err(ParseError::InvalidValue); |
| 11177 | } |
| 11178 | let remaining = &[header.minor_opcode]; |
| 11179 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 11180 | let _ = remaining; |
| 11181 | let (selection, remaining) = Atom::try_parse(value)?; |
| 11182 | let _ = remaining; |
| 11183 | Ok(GetSelectionOwnerRequest { |
| 11184 | selection, |
| 11185 | }) |
| 11186 | } |
| 11187 | } |
| 11188 | impl Request for GetSelectionOwnerRequest { |
| 11189 | const EXTENSION_NAME: Option<&'static str> = None; |
| 11190 | |
| 11191 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 11192 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 11193 | // Flatten the buffers into a single vector |
| 11194 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 11195 | (buf, fds) |
| 11196 | } |
| 11197 | } |
| 11198 | impl crate::x11_utils::ReplyRequest for GetSelectionOwnerRequest { |
| 11199 | type Reply = GetSelectionOwnerReply; |
| 11200 | } |
| 11201 | |
| 11202 | /// # Fields |
| 11203 | /// |
| 11204 | /// * `owner` - The current selection owner window. |
| 11205 | #[derive (Clone, Copy, Default)] |
| 11206 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 11207 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11208 | pub struct GetSelectionOwnerReply { |
| 11209 | pub sequence: u16, |
| 11210 | pub length: u32, |
| 11211 | pub owner: Window, |
| 11212 | } |
| 11213 | impl_debug_if_no_extra_traits!(GetSelectionOwnerReply, "GetSelectionOwnerReply" ); |
| 11214 | impl TryParse for GetSelectionOwnerReply { |
| 11215 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 11216 | let remaining: &[u8] = initial_value; |
| 11217 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 11218 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 11219 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 11220 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 11221 | let (owner: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 11222 | if response_type != 1 { |
| 11223 | return Err(ParseError::InvalidValue); |
| 11224 | } |
| 11225 | let result: GetSelectionOwnerReply = GetSelectionOwnerReply { sequence, length, owner }; |
| 11226 | let _ = remaining; |
| 11227 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 11228 | .ok_or(err:ParseError::InsufficientData)?; |
| 11229 | Ok((result, remaining)) |
| 11230 | } |
| 11231 | } |
| 11232 | impl Serialize for GetSelectionOwnerReply { |
| 11233 | type Bytes = [u8; 12]; |
| 11234 | fn serialize(&self) -> [u8; 12] { |
| 11235 | let response_type_bytes = &[1]; |
| 11236 | let sequence_bytes = self.sequence.serialize(); |
| 11237 | let length_bytes = self.length.serialize(); |
| 11238 | let owner_bytes = self.owner.serialize(); |
| 11239 | [ |
| 11240 | response_type_bytes[0], |
| 11241 | 0, |
| 11242 | sequence_bytes[0], |
| 11243 | sequence_bytes[1], |
| 11244 | length_bytes[0], |
| 11245 | length_bytes[1], |
| 11246 | length_bytes[2], |
| 11247 | length_bytes[3], |
| 11248 | owner_bytes[0], |
| 11249 | owner_bytes[1], |
| 11250 | owner_bytes[2], |
| 11251 | owner_bytes[3], |
| 11252 | ] |
| 11253 | } |
| 11254 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 11255 | bytes.reserve(12); |
| 11256 | let response_type_bytes = &[1]; |
| 11257 | bytes.push(response_type_bytes[0]); |
| 11258 | bytes.extend_from_slice(&[0; 1]); |
| 11259 | self.sequence.serialize_into(bytes); |
| 11260 | self.length.serialize_into(bytes); |
| 11261 | self.owner.serialize_into(bytes); |
| 11262 | } |
| 11263 | } |
| 11264 | |
| 11265 | /// Opcode for the ConvertSelection request |
| 11266 | pub const CONVERT_SELECTION_REQUEST: u8 = 24; |
| 11267 | #[derive (Clone, Copy, Default)] |
| 11268 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 11269 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11270 | pub struct ConvertSelectionRequest { |
| 11271 | pub requestor: Window, |
| 11272 | pub selection: Atom, |
| 11273 | pub target: Atom, |
| 11274 | pub property: Atom, |
| 11275 | pub time: Timestamp, |
| 11276 | } |
| 11277 | impl_debug_if_no_extra_traits!(ConvertSelectionRequest, "ConvertSelectionRequest" ); |
| 11278 | impl ConvertSelectionRequest { |
| 11279 | /// Serialize this request into bytes for the provided connection |
| 11280 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 11281 | let length_so_far = 0; |
| 11282 | let requestor_bytes = self.requestor.serialize(); |
| 11283 | let selection_bytes = self.selection.serialize(); |
| 11284 | let target_bytes = self.target.serialize(); |
| 11285 | let property_bytes = self.property.serialize(); |
| 11286 | let time_bytes = self.time.serialize(); |
| 11287 | let mut request0 = vec![ |
| 11288 | CONVERT_SELECTION_REQUEST, |
| 11289 | 0, |
| 11290 | 0, |
| 11291 | 0, |
| 11292 | requestor_bytes[0], |
| 11293 | requestor_bytes[1], |
| 11294 | requestor_bytes[2], |
| 11295 | requestor_bytes[3], |
| 11296 | selection_bytes[0], |
| 11297 | selection_bytes[1], |
| 11298 | selection_bytes[2], |
| 11299 | selection_bytes[3], |
| 11300 | target_bytes[0], |
| 11301 | target_bytes[1], |
| 11302 | target_bytes[2], |
| 11303 | target_bytes[3], |
| 11304 | property_bytes[0], |
| 11305 | property_bytes[1], |
| 11306 | property_bytes[2], |
| 11307 | property_bytes[3], |
| 11308 | time_bytes[0], |
| 11309 | time_bytes[1], |
| 11310 | time_bytes[2], |
| 11311 | time_bytes[3], |
| 11312 | ]; |
| 11313 | let length_so_far = length_so_far + request0.len(); |
| 11314 | assert_eq!(length_so_far % 4, 0); |
| 11315 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 11316 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 11317 | ([request0.into()], vec![]) |
| 11318 | } |
| 11319 | /// Parse this request given its header, its body, and any fds that go along with it |
| 11320 | #[cfg (feature = "request-parsing" )] |
| 11321 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 11322 | if header.major_opcode != CONVERT_SELECTION_REQUEST { |
| 11323 | return Err(ParseError::InvalidValue); |
| 11324 | } |
| 11325 | let remaining = &[header.minor_opcode]; |
| 11326 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 11327 | let _ = remaining; |
| 11328 | let (requestor, remaining) = Window::try_parse(value)?; |
| 11329 | let (selection, remaining) = Atom::try_parse(remaining)?; |
| 11330 | let (target, remaining) = Atom::try_parse(remaining)?; |
| 11331 | let (property, remaining) = Atom::try_parse(remaining)?; |
| 11332 | let (time, remaining) = Timestamp::try_parse(remaining)?; |
| 11333 | let _ = remaining; |
| 11334 | Ok(ConvertSelectionRequest { |
| 11335 | requestor, |
| 11336 | selection, |
| 11337 | target, |
| 11338 | property, |
| 11339 | time, |
| 11340 | }) |
| 11341 | } |
| 11342 | } |
| 11343 | impl Request for ConvertSelectionRequest { |
| 11344 | const EXTENSION_NAME: Option<&'static str> = None; |
| 11345 | |
| 11346 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 11347 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 11348 | // Flatten the buffers into a single vector |
| 11349 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 11350 | (buf, fds) |
| 11351 | } |
| 11352 | } |
| 11353 | impl crate::x11_utils::VoidRequest for ConvertSelectionRequest { |
| 11354 | } |
| 11355 | |
| 11356 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 11357 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11358 | pub struct SendEventDest(bool); |
| 11359 | impl SendEventDest { |
| 11360 | pub const POINTER_WINDOW: Self = Self(false); |
| 11361 | pub const ITEM_FOCUS: Self = Self(true); |
| 11362 | } |
| 11363 | impl From<SendEventDest> for bool { |
| 11364 | #[inline ] |
| 11365 | fn from(input: SendEventDest) -> Self { |
| 11366 | input.0 |
| 11367 | } |
| 11368 | } |
| 11369 | impl From<SendEventDest> for Option<bool> { |
| 11370 | #[inline ] |
| 11371 | fn from(input: SendEventDest) -> Self { |
| 11372 | Some(input.0) |
| 11373 | } |
| 11374 | } |
| 11375 | impl From<SendEventDest> for u8 { |
| 11376 | #[inline ] |
| 11377 | fn from(input: SendEventDest) -> Self { |
| 11378 | u8::from(input.0) |
| 11379 | } |
| 11380 | } |
| 11381 | impl From<SendEventDest> for Option<u8> { |
| 11382 | #[inline ] |
| 11383 | fn from(input: SendEventDest) -> Self { |
| 11384 | Some(u8::from(input.0)) |
| 11385 | } |
| 11386 | } |
| 11387 | impl From<SendEventDest> for u16 { |
| 11388 | #[inline ] |
| 11389 | fn from(input: SendEventDest) -> Self { |
| 11390 | u16::from(input.0) |
| 11391 | } |
| 11392 | } |
| 11393 | impl From<SendEventDest> for Option<u16> { |
| 11394 | #[inline ] |
| 11395 | fn from(input: SendEventDest) -> Self { |
| 11396 | Some(u16::from(input.0)) |
| 11397 | } |
| 11398 | } |
| 11399 | impl From<SendEventDest> for u32 { |
| 11400 | #[inline ] |
| 11401 | fn from(input: SendEventDest) -> Self { |
| 11402 | u32::from(input.0) |
| 11403 | } |
| 11404 | } |
| 11405 | impl From<SendEventDest> for Option<u32> { |
| 11406 | #[inline ] |
| 11407 | fn from(input: SendEventDest) -> Self { |
| 11408 | Some(u32::from(input.0)) |
| 11409 | } |
| 11410 | } |
| 11411 | impl From<bool> for SendEventDest { |
| 11412 | #[inline ] |
| 11413 | fn from(value: bool) -> Self { |
| 11414 | Self(value) |
| 11415 | } |
| 11416 | } |
| 11417 | impl core::fmt::Debug for SendEventDest { |
| 11418 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 11419 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 11420 | (Self::POINTER_WINDOW.0.into(), "POINTER_WINDOW" , "PointerWindow" ), |
| 11421 | (Self::ITEM_FOCUS.0.into(), "ITEM_FOCUS" , "ItemFocus" ), |
| 11422 | ]; |
| 11423 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 11424 | } |
| 11425 | } |
| 11426 | |
| 11427 | /// Opcode for the SendEvent request |
| 11428 | pub const SEND_EVENT_REQUEST: u8 = 25; |
| 11429 | /// send an event. |
| 11430 | /// |
| 11431 | /// Identifies the `destination` window, determines which clients should receive |
| 11432 | /// the specified event and ignores any active grabs. |
| 11433 | /// |
| 11434 | /// The `event` must be one of the core events or an event defined by an extension, |
| 11435 | /// so that the X server can correctly byte-swap the contents as necessary. The |
| 11436 | /// contents of `event` are otherwise unaltered and unchecked except for the |
| 11437 | /// `send_event` field which is forced to 'true'. |
| 11438 | /// |
| 11439 | /// # Fields |
| 11440 | /// |
| 11441 | /// * `destination` - The window to send this event to. Every client which selects any event within |
| 11442 | /// `event_mask` on `destination` will get the event. |
| 11443 | /// |
| 11444 | /// The special value `XCB_SEND_EVENT_DEST_POINTER_WINDOW` refers to the window |
| 11445 | /// that contains the mouse pointer. |
| 11446 | /// |
| 11447 | /// The special value `XCB_SEND_EVENT_DEST_ITEM_FOCUS` refers to the window which |
| 11448 | /// has the keyboard focus. |
| 11449 | /// * `event_mask` - Event_mask for determining which clients should receive the specified event. |
| 11450 | /// See `destination` and `propagate`. |
| 11451 | /// * `propagate` - If `propagate` is true and no clients have selected any event on `destination`, |
| 11452 | /// the destination is replaced with the closest ancestor of `destination` for |
| 11453 | /// which some client has selected a type in `event_mask` and for which no |
| 11454 | /// intervening window has that type in its do-not-propagate-mask. If no such |
| 11455 | /// window exists or if the window is an ancestor of the focus window and |
| 11456 | /// `InputFocus` was originally specified as the destination, the event is not sent |
| 11457 | /// to any clients. Otherwise, the event is reported to every client selecting on |
| 11458 | /// the final destination any of the types specified in `event_mask`. |
| 11459 | /// * `event` - The event to send to the specified `destination`. |
| 11460 | /// |
| 11461 | /// # Errors |
| 11462 | /// |
| 11463 | /// * `Window` - The specified `destination` window does not exist. |
| 11464 | /// * `Value` - The given `event` is neither a core event nor an event defined by an extension. |
| 11465 | /// |
| 11466 | /// # See |
| 11467 | /// |
| 11468 | /// * `ConfigureNotify`: event |
| 11469 | /// |
| 11470 | /// # Example |
| 11471 | /// |
| 11472 | /// ```text |
| 11473 | /// /* |
| 11474 | /// * Tell the given window that it was configured to a size of 800x600 pixels. |
| 11475 | /// * |
| 11476 | /// */ |
| 11477 | /// void my_example(xcb_connection_t *conn, xcb_window_t window) { |
| 11478 | /// /* Every X11 event is 32 bytes long. Therefore, XCB will copy 32 bytes. |
| 11479 | /// * In order to properly initialize these bytes, we allocate 32 bytes even |
| 11480 | /// * though we only need less for an xcb_configure_notify_event_t */ |
| 11481 | /// xcb_configure_notify_event_t *event = calloc(32, 1); |
| 11482 | /// |
| 11483 | /// event->event = window; |
| 11484 | /// event->window = window; |
| 11485 | /// event->response_type = XCB_CONFIGURE_NOTIFY; |
| 11486 | /// |
| 11487 | /// event->x = 0; |
| 11488 | /// event->y = 0; |
| 11489 | /// event->width = 800; |
| 11490 | /// event->height = 600; |
| 11491 | /// |
| 11492 | /// event->border_width = 0; |
| 11493 | /// event->above_sibling = XCB_NONE; |
| 11494 | /// event->override_redirect = false; |
| 11495 | /// |
| 11496 | /// xcb_send_event(conn, false, window, XCB_EVENT_MASK_STRUCTURE_NOTIFY, |
| 11497 | /// (char*)event); |
| 11498 | /// xcb_flush(conn); |
| 11499 | /// free(event); |
| 11500 | /// } |
| 11501 | /// ``` |
| 11502 | #[derive (Clone, Default)] |
| 11503 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 11504 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11505 | pub struct SendEventRequest<'input> { |
| 11506 | pub propagate: bool, |
| 11507 | pub destination: Window, |
| 11508 | pub event_mask: EventMask, |
| 11509 | pub event: Cow<'input, [u8; 32]>, |
| 11510 | } |
| 11511 | impl_debug_if_no_extra_traits!(SendEventRequest<'_>, "SendEventRequest" ); |
| 11512 | impl<'input> SendEventRequest<'input> { |
| 11513 | /// Serialize this request into bytes for the provided connection |
| 11514 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 2]> { |
| 11515 | let length_so_far = 0; |
| 11516 | let propagate_bytes = self.propagate.serialize(); |
| 11517 | let destination_bytes = self.destination.serialize(); |
| 11518 | let event_mask_bytes = u32::from(self.event_mask).serialize(); |
| 11519 | let mut request0 = vec![ |
| 11520 | SEND_EVENT_REQUEST, |
| 11521 | propagate_bytes[0], |
| 11522 | 0, |
| 11523 | 0, |
| 11524 | destination_bytes[0], |
| 11525 | destination_bytes[1], |
| 11526 | destination_bytes[2], |
| 11527 | destination_bytes[3], |
| 11528 | event_mask_bytes[0], |
| 11529 | event_mask_bytes[1], |
| 11530 | event_mask_bytes[2], |
| 11531 | event_mask_bytes[3], |
| 11532 | ]; |
| 11533 | let length_so_far = length_so_far + request0.len(); |
| 11534 | let length_so_far = length_so_far + self.event.len(); |
| 11535 | assert_eq!(length_so_far % 4, 0); |
| 11536 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 11537 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 11538 | ([request0.into(), Cow::Owned(self.event.to_vec())], vec![]) |
| 11539 | } |
| 11540 | /// Parse this request given its header, its body, and any fds that go along with it |
| 11541 | #[cfg (feature = "request-parsing" )] |
| 11542 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 11543 | if header.major_opcode != SEND_EVENT_REQUEST { |
| 11544 | return Err(ParseError::InvalidValue); |
| 11545 | } |
| 11546 | let remaining = &[header.minor_opcode]; |
| 11547 | let (propagate, remaining) = bool::try_parse(remaining)?; |
| 11548 | let _ = remaining; |
| 11549 | let (destination, remaining) = Window::try_parse(value)?; |
| 11550 | let (event_mask, remaining) = u32::try_parse(remaining)?; |
| 11551 | let event_mask = event_mask.into(); |
| 11552 | let (event, remaining) = crate::x11_utils::parse_u8_array_ref::<32>(remaining)?; |
| 11553 | let _ = remaining; |
| 11554 | Ok(SendEventRequest { |
| 11555 | propagate, |
| 11556 | destination, |
| 11557 | event_mask, |
| 11558 | event: Cow::Borrowed(event), |
| 11559 | }) |
| 11560 | } |
| 11561 | /// Clone all borrowed data in this SendEventRequest. |
| 11562 | pub fn into_owned(self) -> SendEventRequest<'static> { |
| 11563 | SendEventRequest { |
| 11564 | propagate: self.propagate, |
| 11565 | destination: self.destination, |
| 11566 | event_mask: self.event_mask, |
| 11567 | event: Cow::Owned(self.event.into_owned()), |
| 11568 | } |
| 11569 | } |
| 11570 | } |
| 11571 | impl<'input> Request for SendEventRequest<'input> { |
| 11572 | const EXTENSION_NAME: Option<&'static str> = None; |
| 11573 | |
| 11574 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 11575 | let (bufs: [Cow<'_, [u8]>; 2], fds: Vec) = self.serialize(); |
| 11576 | // Flatten the buffers into a single vector |
| 11577 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 11578 | (buf, fds) |
| 11579 | } |
| 11580 | } |
| 11581 | impl<'input> crate::x11_utils::VoidRequest for SendEventRequest<'input> { |
| 11582 | } |
| 11583 | |
| 11584 | /// # Fields |
| 11585 | /// |
| 11586 | /// * `Sync` - The state of the keyboard appears to freeze: No further keyboard events are |
| 11587 | /// generated by the server until the grabbing client issues a releasing |
| 11588 | /// `AllowEvents` request or until the keyboard grab is released. |
| 11589 | /// * `Async` - Keyboard event processing continues normally. |
| 11590 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 11591 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11592 | pub struct GrabMode(u8); |
| 11593 | impl GrabMode { |
| 11594 | pub const SYNC: Self = Self(0); |
| 11595 | pub const ASYNC: Self = Self(1); |
| 11596 | } |
| 11597 | impl From<GrabMode> for u8 { |
| 11598 | #[inline ] |
| 11599 | fn from(input: GrabMode) -> Self { |
| 11600 | input.0 |
| 11601 | } |
| 11602 | } |
| 11603 | impl From<GrabMode> for Option<u8> { |
| 11604 | #[inline ] |
| 11605 | fn from(input: GrabMode) -> Self { |
| 11606 | Some(input.0) |
| 11607 | } |
| 11608 | } |
| 11609 | impl From<GrabMode> for u16 { |
| 11610 | #[inline ] |
| 11611 | fn from(input: GrabMode) -> Self { |
| 11612 | u16::from(input.0) |
| 11613 | } |
| 11614 | } |
| 11615 | impl From<GrabMode> for Option<u16> { |
| 11616 | #[inline ] |
| 11617 | fn from(input: GrabMode) -> Self { |
| 11618 | Some(u16::from(input.0)) |
| 11619 | } |
| 11620 | } |
| 11621 | impl From<GrabMode> for u32 { |
| 11622 | #[inline ] |
| 11623 | fn from(input: GrabMode) -> Self { |
| 11624 | u32::from(input.0) |
| 11625 | } |
| 11626 | } |
| 11627 | impl From<GrabMode> for Option<u32> { |
| 11628 | #[inline ] |
| 11629 | fn from(input: GrabMode) -> Self { |
| 11630 | Some(u32::from(input.0)) |
| 11631 | } |
| 11632 | } |
| 11633 | impl From<u8> for GrabMode { |
| 11634 | #[inline ] |
| 11635 | fn from(value: u8) -> Self { |
| 11636 | Self(value) |
| 11637 | } |
| 11638 | } |
| 11639 | impl core::fmt::Debug for GrabMode { |
| 11640 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 11641 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 11642 | (Self::SYNC.0.into(), "SYNC" , "Sync" ), |
| 11643 | (Self::ASYNC.0.into(), "ASYNC" , "Async" ), |
| 11644 | ]; |
| 11645 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 11646 | } |
| 11647 | } |
| 11648 | |
| 11649 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 11650 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11651 | pub struct GrabStatus(u8); |
| 11652 | impl GrabStatus { |
| 11653 | pub const SUCCESS: Self = Self(0); |
| 11654 | pub const ALREADY_GRABBED: Self = Self(1); |
| 11655 | pub const INVALID_TIME: Self = Self(2); |
| 11656 | pub const NOT_VIEWABLE: Self = Self(3); |
| 11657 | pub const FROZEN: Self = Self(4); |
| 11658 | } |
| 11659 | impl From<GrabStatus> for u8 { |
| 11660 | #[inline ] |
| 11661 | fn from(input: GrabStatus) -> Self { |
| 11662 | input.0 |
| 11663 | } |
| 11664 | } |
| 11665 | impl From<GrabStatus> for Option<u8> { |
| 11666 | #[inline ] |
| 11667 | fn from(input: GrabStatus) -> Self { |
| 11668 | Some(input.0) |
| 11669 | } |
| 11670 | } |
| 11671 | impl From<GrabStatus> for u16 { |
| 11672 | #[inline ] |
| 11673 | fn from(input: GrabStatus) -> Self { |
| 11674 | u16::from(input.0) |
| 11675 | } |
| 11676 | } |
| 11677 | impl From<GrabStatus> for Option<u16> { |
| 11678 | #[inline ] |
| 11679 | fn from(input: GrabStatus) -> Self { |
| 11680 | Some(u16::from(input.0)) |
| 11681 | } |
| 11682 | } |
| 11683 | impl From<GrabStatus> for u32 { |
| 11684 | #[inline ] |
| 11685 | fn from(input: GrabStatus) -> Self { |
| 11686 | u32::from(input.0) |
| 11687 | } |
| 11688 | } |
| 11689 | impl From<GrabStatus> for Option<u32> { |
| 11690 | #[inline ] |
| 11691 | fn from(input: GrabStatus) -> Self { |
| 11692 | Some(u32::from(input.0)) |
| 11693 | } |
| 11694 | } |
| 11695 | impl From<u8> for GrabStatus { |
| 11696 | #[inline ] |
| 11697 | fn from(value: u8) -> Self { |
| 11698 | Self(value) |
| 11699 | } |
| 11700 | } |
| 11701 | impl core::fmt::Debug for GrabStatus { |
| 11702 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 11703 | let variants: [(u32, &'static str, &'static …); 5] = [ |
| 11704 | (Self::SUCCESS.0.into(), "SUCCESS" , "Success" ), |
| 11705 | (Self::ALREADY_GRABBED.0.into(), "ALREADY_GRABBED" , "AlreadyGrabbed" ), |
| 11706 | (Self::INVALID_TIME.0.into(), "INVALID_TIME" , "InvalidTime" ), |
| 11707 | (Self::NOT_VIEWABLE.0.into(), "NOT_VIEWABLE" , "NotViewable" ), |
| 11708 | (Self::FROZEN.0.into(), "FROZEN" , "Frozen" ), |
| 11709 | ]; |
| 11710 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 11711 | } |
| 11712 | } |
| 11713 | |
| 11714 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 11715 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11716 | pub struct CursorEnum(u8); |
| 11717 | impl CursorEnum { |
| 11718 | pub const NONE: Self = Self(0); |
| 11719 | } |
| 11720 | impl From<CursorEnum> for u8 { |
| 11721 | #[inline ] |
| 11722 | fn from(input: CursorEnum) -> Self { |
| 11723 | input.0 |
| 11724 | } |
| 11725 | } |
| 11726 | impl From<CursorEnum> for Option<u8> { |
| 11727 | #[inline ] |
| 11728 | fn from(input: CursorEnum) -> Self { |
| 11729 | Some(input.0) |
| 11730 | } |
| 11731 | } |
| 11732 | impl From<CursorEnum> for u16 { |
| 11733 | #[inline ] |
| 11734 | fn from(input: CursorEnum) -> Self { |
| 11735 | u16::from(input.0) |
| 11736 | } |
| 11737 | } |
| 11738 | impl From<CursorEnum> for Option<u16> { |
| 11739 | #[inline ] |
| 11740 | fn from(input: CursorEnum) -> Self { |
| 11741 | Some(u16::from(input.0)) |
| 11742 | } |
| 11743 | } |
| 11744 | impl From<CursorEnum> for u32 { |
| 11745 | #[inline ] |
| 11746 | fn from(input: CursorEnum) -> Self { |
| 11747 | u32::from(input.0) |
| 11748 | } |
| 11749 | } |
| 11750 | impl From<CursorEnum> for Option<u32> { |
| 11751 | #[inline ] |
| 11752 | fn from(input: CursorEnum) -> Self { |
| 11753 | Some(u32::from(input.0)) |
| 11754 | } |
| 11755 | } |
| 11756 | impl From<u8> for CursorEnum { |
| 11757 | #[inline ] |
| 11758 | fn from(value: u8) -> Self { |
| 11759 | Self(value) |
| 11760 | } |
| 11761 | } |
| 11762 | impl core::fmt::Debug for CursorEnum { |
| 11763 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 11764 | let variants: [(u32, &'static str, &'static …); 1] = [ |
| 11765 | (Self::NONE.0.into(), "NONE" , "None" ), |
| 11766 | ]; |
| 11767 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 11768 | } |
| 11769 | } |
| 11770 | |
| 11771 | /// Opcode for the GrabPointer request |
| 11772 | pub const GRAB_POINTER_REQUEST: u8 = 26; |
| 11773 | /// Grab the pointer. |
| 11774 | /// |
| 11775 | /// Actively grabs control of the pointer. Further pointer events are reported only to the grabbing client. Overrides any active pointer grab by this client. |
| 11776 | /// |
| 11777 | /// # Fields |
| 11778 | /// |
| 11779 | /// * `event_mask` - Specifies which pointer events are reported to the client. |
| 11780 | /// |
| 11781 | /// TODO: which values? |
| 11782 | /// * `confine_to` - Specifies the window to confine the pointer in (the user will not be able to |
| 11783 | /// move the pointer out of that window). |
| 11784 | /// |
| 11785 | /// The special value `XCB_NONE` means don't confine the pointer. |
| 11786 | /// * `cursor` - Specifies the cursor that should be displayed or `XCB_NONE` to not change the |
| 11787 | /// cursor. |
| 11788 | /// * `owner_events` - If 1, the `grab_window` will still get the pointer events. If 0, events are not |
| 11789 | /// reported to the `grab_window`. |
| 11790 | /// * `grab_window` - Specifies the window on which the pointer should be grabbed. |
| 11791 | /// * `time` - The time argument allows you to avoid certain circumstances that come up if |
| 11792 | /// applications take a long time to respond or if there are long network delays. |
| 11793 | /// Consider a situation where you have two applications, both of which normally |
| 11794 | /// grab the pointer when clicked on. If both applications specify the timestamp |
| 11795 | /// from the event, the second application may wake up faster and successfully grab |
| 11796 | /// the pointer before the first application. The first application then will get |
| 11797 | /// an indication that the other application grabbed the pointer before its request |
| 11798 | /// was processed. |
| 11799 | /// |
| 11800 | /// The special value `XCB_CURRENT_TIME` will be replaced with the current server |
| 11801 | /// time. |
| 11802 | /// * `pointer_mode` - |
| 11803 | /// * `keyboard_mode` - |
| 11804 | /// |
| 11805 | /// # Errors |
| 11806 | /// |
| 11807 | /// * `Value` - TODO: reasons? |
| 11808 | /// * `Window` - The specified `window` does not exist. |
| 11809 | /// |
| 11810 | /// # See |
| 11811 | /// |
| 11812 | /// * `GrabKeyboard`: request |
| 11813 | /// |
| 11814 | /// # Example |
| 11815 | /// |
| 11816 | /// ```text |
| 11817 | /// /* |
| 11818 | /// * Grabs the pointer actively |
| 11819 | /// * |
| 11820 | /// */ |
| 11821 | /// void my_example(xcb_connection_t *conn, xcb_screen_t *screen, xcb_cursor_t cursor) { |
| 11822 | /// xcb_grab_pointer_cookie_t cookie; |
| 11823 | /// xcb_grab_pointer_reply_t *reply; |
| 11824 | /// |
| 11825 | /// cookie = xcb_grab_pointer( |
| 11826 | /// conn, |
| 11827 | /// false, /* get all pointer events specified by the following mask */ |
| 11828 | /// screen->root, /* grab the root window */ |
| 11829 | /// XCB_NONE, /* which events to let through */ |
| 11830 | /// XCB_GRAB_MODE_ASYNC, /* pointer events should continue as normal */ |
| 11831 | /// XCB_GRAB_MODE_ASYNC, /* keyboard mode */ |
| 11832 | /// XCB_NONE, /* confine_to = in which window should the cursor stay */ |
| 11833 | /// cursor, /* we change the cursor to whatever the user wanted */ |
| 11834 | /// XCB_CURRENT_TIME |
| 11835 | /// ); |
| 11836 | /// |
| 11837 | /// if ((reply = xcb_grab_pointer_reply(conn, cookie, NULL))) { |
| 11838 | /// if (reply->status == XCB_GRAB_STATUS_SUCCESS) |
| 11839 | /// printf("successfully grabbed the pointer\\n"); |
| 11840 | /// free(reply); |
| 11841 | /// } |
| 11842 | /// } |
| 11843 | /// ``` |
| 11844 | #[derive (Clone, Copy, Default)] |
| 11845 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 11846 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11847 | pub struct GrabPointerRequest { |
| 11848 | pub owner_events: bool, |
| 11849 | pub grab_window: Window, |
| 11850 | pub event_mask: EventMask, |
| 11851 | pub pointer_mode: GrabMode, |
| 11852 | pub keyboard_mode: GrabMode, |
| 11853 | pub confine_to: Window, |
| 11854 | pub cursor: Cursor, |
| 11855 | pub time: Timestamp, |
| 11856 | } |
| 11857 | impl_debug_if_no_extra_traits!(GrabPointerRequest, "GrabPointerRequest" ); |
| 11858 | impl GrabPointerRequest { |
| 11859 | /// Serialize this request into bytes for the provided connection |
| 11860 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 11861 | let length_so_far = 0; |
| 11862 | let owner_events_bytes = self.owner_events.serialize(); |
| 11863 | let grab_window_bytes = self.grab_window.serialize(); |
| 11864 | let event_mask_bytes = (u32::from(self.event_mask) as u16).serialize(); |
| 11865 | let pointer_mode_bytes = u8::from(self.pointer_mode).serialize(); |
| 11866 | let keyboard_mode_bytes = u8::from(self.keyboard_mode).serialize(); |
| 11867 | let confine_to_bytes = self.confine_to.serialize(); |
| 11868 | let cursor_bytes = self.cursor.serialize(); |
| 11869 | let time_bytes = self.time.serialize(); |
| 11870 | let mut request0 = vec![ |
| 11871 | GRAB_POINTER_REQUEST, |
| 11872 | owner_events_bytes[0], |
| 11873 | 0, |
| 11874 | 0, |
| 11875 | grab_window_bytes[0], |
| 11876 | grab_window_bytes[1], |
| 11877 | grab_window_bytes[2], |
| 11878 | grab_window_bytes[3], |
| 11879 | event_mask_bytes[0], |
| 11880 | event_mask_bytes[1], |
| 11881 | pointer_mode_bytes[0], |
| 11882 | keyboard_mode_bytes[0], |
| 11883 | confine_to_bytes[0], |
| 11884 | confine_to_bytes[1], |
| 11885 | confine_to_bytes[2], |
| 11886 | confine_to_bytes[3], |
| 11887 | cursor_bytes[0], |
| 11888 | cursor_bytes[1], |
| 11889 | cursor_bytes[2], |
| 11890 | cursor_bytes[3], |
| 11891 | time_bytes[0], |
| 11892 | time_bytes[1], |
| 11893 | time_bytes[2], |
| 11894 | time_bytes[3], |
| 11895 | ]; |
| 11896 | let length_so_far = length_so_far + request0.len(); |
| 11897 | assert_eq!(length_so_far % 4, 0); |
| 11898 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 11899 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 11900 | ([request0.into()], vec![]) |
| 11901 | } |
| 11902 | /// Parse this request given its header, its body, and any fds that go along with it |
| 11903 | #[cfg (feature = "request-parsing" )] |
| 11904 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 11905 | if header.major_opcode != GRAB_POINTER_REQUEST { |
| 11906 | return Err(ParseError::InvalidValue); |
| 11907 | } |
| 11908 | let remaining = &[header.minor_opcode]; |
| 11909 | let (owner_events, remaining) = bool::try_parse(remaining)?; |
| 11910 | let _ = remaining; |
| 11911 | let (grab_window, remaining) = Window::try_parse(value)?; |
| 11912 | let (event_mask, remaining) = u16::try_parse(remaining)?; |
| 11913 | let event_mask = event_mask.into(); |
| 11914 | let (pointer_mode, remaining) = u8::try_parse(remaining)?; |
| 11915 | let pointer_mode = pointer_mode.into(); |
| 11916 | let (keyboard_mode, remaining) = u8::try_parse(remaining)?; |
| 11917 | let keyboard_mode = keyboard_mode.into(); |
| 11918 | let (confine_to, remaining) = Window::try_parse(remaining)?; |
| 11919 | let (cursor, remaining) = Cursor::try_parse(remaining)?; |
| 11920 | let (time, remaining) = Timestamp::try_parse(remaining)?; |
| 11921 | let _ = remaining; |
| 11922 | Ok(GrabPointerRequest { |
| 11923 | owner_events, |
| 11924 | grab_window, |
| 11925 | event_mask, |
| 11926 | pointer_mode, |
| 11927 | keyboard_mode, |
| 11928 | confine_to, |
| 11929 | cursor, |
| 11930 | time, |
| 11931 | }) |
| 11932 | } |
| 11933 | } |
| 11934 | impl Request for GrabPointerRequest { |
| 11935 | const EXTENSION_NAME: Option<&'static str> = None; |
| 11936 | |
| 11937 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 11938 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 11939 | // Flatten the buffers into a single vector |
| 11940 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 11941 | (buf, fds) |
| 11942 | } |
| 11943 | } |
| 11944 | impl crate::x11_utils::ReplyRequest for GrabPointerRequest { |
| 11945 | type Reply = GrabPointerReply; |
| 11946 | } |
| 11947 | |
| 11948 | #[derive (Clone, Copy, Default)] |
| 11949 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 11950 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11951 | pub struct GrabPointerReply { |
| 11952 | pub status: GrabStatus, |
| 11953 | pub sequence: u16, |
| 11954 | pub length: u32, |
| 11955 | } |
| 11956 | impl_debug_if_no_extra_traits!(GrabPointerReply, "GrabPointerReply" ); |
| 11957 | impl TryParse for GrabPointerReply { |
| 11958 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 11959 | let remaining: &[u8] = initial_value; |
| 11960 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 11961 | let (status: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 11962 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 11963 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 11964 | if response_type != 1 { |
| 11965 | return Err(ParseError::InvalidValue); |
| 11966 | } |
| 11967 | let status: GrabStatus = status.into(); |
| 11968 | let result: GrabPointerReply = GrabPointerReply { status, sequence, length }; |
| 11969 | let _ = remaining; |
| 11970 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 11971 | .ok_or(err:ParseError::InsufficientData)?; |
| 11972 | Ok((result, remaining)) |
| 11973 | } |
| 11974 | } |
| 11975 | impl Serialize for GrabPointerReply { |
| 11976 | type Bytes = [u8; 8]; |
| 11977 | fn serialize(&self) -> [u8; 8] { |
| 11978 | let response_type_bytes = &[1]; |
| 11979 | let status_bytes = u8::from(self.status).serialize(); |
| 11980 | let sequence_bytes = self.sequence.serialize(); |
| 11981 | let length_bytes = self.length.serialize(); |
| 11982 | [ |
| 11983 | response_type_bytes[0], |
| 11984 | status_bytes[0], |
| 11985 | sequence_bytes[0], |
| 11986 | sequence_bytes[1], |
| 11987 | length_bytes[0], |
| 11988 | length_bytes[1], |
| 11989 | length_bytes[2], |
| 11990 | length_bytes[3], |
| 11991 | ] |
| 11992 | } |
| 11993 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 11994 | bytes.reserve(8); |
| 11995 | let response_type_bytes = &[1]; |
| 11996 | bytes.push(response_type_bytes[0]); |
| 11997 | u8::from(self.status).serialize_into(bytes); |
| 11998 | self.sequence.serialize_into(bytes); |
| 11999 | self.length.serialize_into(bytes); |
| 12000 | } |
| 12001 | } |
| 12002 | |
| 12003 | /// Opcode for the UngrabPointer request |
| 12004 | pub const UNGRAB_POINTER_REQUEST: u8 = 27; |
| 12005 | /// release the pointer. |
| 12006 | /// |
| 12007 | /// Releases the pointer and any queued events if you actively grabbed the pointer |
| 12008 | /// before using `xcb_grab_pointer`, `xcb_grab_button` or within a normal button |
| 12009 | /// press. |
| 12010 | /// |
| 12011 | /// EnterNotify and LeaveNotify events are generated. |
| 12012 | /// |
| 12013 | /// # Fields |
| 12014 | /// |
| 12015 | /// * `time` - Timestamp to avoid race conditions when running X over the network. |
| 12016 | /// |
| 12017 | /// The pointer will not be released if `time` is earlier than the |
| 12018 | /// last-pointer-grab time or later than the current X server time. |
| 12019 | /// * `name_len` - Length (in bytes) of `name`. |
| 12020 | /// * `name` - A pattern describing an X core font. |
| 12021 | /// |
| 12022 | /// # See |
| 12023 | /// |
| 12024 | /// * `GrabPointer`: request |
| 12025 | /// * `GrabButton`: request |
| 12026 | /// * `EnterNotify`: event |
| 12027 | /// * `LeaveNotify`: event |
| 12028 | #[derive (Clone, Copy, Default)] |
| 12029 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 12030 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12031 | pub struct UngrabPointerRequest { |
| 12032 | pub time: Timestamp, |
| 12033 | } |
| 12034 | impl_debug_if_no_extra_traits!(UngrabPointerRequest, "UngrabPointerRequest" ); |
| 12035 | impl UngrabPointerRequest { |
| 12036 | /// Serialize this request into bytes for the provided connection |
| 12037 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 12038 | let length_so_far = 0; |
| 12039 | let time_bytes = self.time.serialize(); |
| 12040 | let mut request0 = vec![ |
| 12041 | UNGRAB_POINTER_REQUEST, |
| 12042 | 0, |
| 12043 | 0, |
| 12044 | 0, |
| 12045 | time_bytes[0], |
| 12046 | time_bytes[1], |
| 12047 | time_bytes[2], |
| 12048 | time_bytes[3], |
| 12049 | ]; |
| 12050 | let length_so_far = length_so_far + request0.len(); |
| 12051 | assert_eq!(length_so_far % 4, 0); |
| 12052 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 12053 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 12054 | ([request0.into()], vec![]) |
| 12055 | } |
| 12056 | /// Parse this request given its header, its body, and any fds that go along with it |
| 12057 | #[cfg (feature = "request-parsing" )] |
| 12058 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 12059 | if header.major_opcode != UNGRAB_POINTER_REQUEST { |
| 12060 | return Err(ParseError::InvalidValue); |
| 12061 | } |
| 12062 | let remaining = &[header.minor_opcode]; |
| 12063 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 12064 | let _ = remaining; |
| 12065 | let (time, remaining) = Timestamp::try_parse(value)?; |
| 12066 | let _ = remaining; |
| 12067 | Ok(UngrabPointerRequest { |
| 12068 | time, |
| 12069 | }) |
| 12070 | } |
| 12071 | } |
| 12072 | impl Request for UngrabPointerRequest { |
| 12073 | const EXTENSION_NAME: Option<&'static str> = None; |
| 12074 | |
| 12075 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 12076 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 12077 | // Flatten the buffers into a single vector |
| 12078 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 12079 | (buf, fds) |
| 12080 | } |
| 12081 | } |
| 12082 | impl crate::x11_utils::VoidRequest for UngrabPointerRequest { |
| 12083 | } |
| 12084 | |
| 12085 | /// # Fields |
| 12086 | /// |
| 12087 | /// * `Any` - Any of the following (or none): |
| 12088 | /// * `1` - The left mouse button. |
| 12089 | /// * `2` - The right mouse button. |
| 12090 | /// * `3` - The middle mouse button. |
| 12091 | /// * `4` - Scroll wheel. TODO: direction? |
| 12092 | /// * `5` - Scroll wheel. TODO: direction? |
| 12093 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 12094 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12095 | pub struct ButtonIndex(u8); |
| 12096 | impl ButtonIndex { |
| 12097 | pub const ANY: Self = Self(0); |
| 12098 | pub const M1: Self = Self(1); |
| 12099 | pub const M2: Self = Self(2); |
| 12100 | pub const M3: Self = Self(3); |
| 12101 | pub const M4: Self = Self(4); |
| 12102 | pub const M5: Self = Self(5); |
| 12103 | } |
| 12104 | impl From<ButtonIndex> for u8 { |
| 12105 | #[inline ] |
| 12106 | fn from(input: ButtonIndex) -> Self { |
| 12107 | input.0 |
| 12108 | } |
| 12109 | } |
| 12110 | impl From<ButtonIndex> for Option<u8> { |
| 12111 | #[inline ] |
| 12112 | fn from(input: ButtonIndex) -> Self { |
| 12113 | Some(input.0) |
| 12114 | } |
| 12115 | } |
| 12116 | impl From<ButtonIndex> for u16 { |
| 12117 | #[inline ] |
| 12118 | fn from(input: ButtonIndex) -> Self { |
| 12119 | u16::from(input.0) |
| 12120 | } |
| 12121 | } |
| 12122 | impl From<ButtonIndex> for Option<u16> { |
| 12123 | #[inline ] |
| 12124 | fn from(input: ButtonIndex) -> Self { |
| 12125 | Some(u16::from(input.0)) |
| 12126 | } |
| 12127 | } |
| 12128 | impl From<ButtonIndex> for u32 { |
| 12129 | #[inline ] |
| 12130 | fn from(input: ButtonIndex) -> Self { |
| 12131 | u32::from(input.0) |
| 12132 | } |
| 12133 | } |
| 12134 | impl From<ButtonIndex> for Option<u32> { |
| 12135 | #[inline ] |
| 12136 | fn from(input: ButtonIndex) -> Self { |
| 12137 | Some(u32::from(input.0)) |
| 12138 | } |
| 12139 | } |
| 12140 | impl From<u8> for ButtonIndex { |
| 12141 | #[inline ] |
| 12142 | fn from(value: u8) -> Self { |
| 12143 | Self(value) |
| 12144 | } |
| 12145 | } |
| 12146 | impl core::fmt::Debug for ButtonIndex { |
| 12147 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 12148 | let variants: [(u32, &'static str, &'static …); 6] = [ |
| 12149 | (Self::ANY.0.into(), "ANY" , "Any" ), |
| 12150 | (Self::M1.0.into(), "M1" , "M1" ), |
| 12151 | (Self::M2.0.into(), "M2" , "M2" ), |
| 12152 | (Self::M3.0.into(), "M3" , "M3" ), |
| 12153 | (Self::M4.0.into(), "M4" , "M4" ), |
| 12154 | (Self::M5.0.into(), "M5" , "M5" ), |
| 12155 | ]; |
| 12156 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 12157 | } |
| 12158 | } |
| 12159 | |
| 12160 | /// Opcode for the GrabButton request |
| 12161 | pub const GRAB_BUTTON_REQUEST: u8 = 28; |
| 12162 | /// Grab pointer button(s). |
| 12163 | /// |
| 12164 | /// This request establishes a passive grab. The pointer is actively grabbed as |
| 12165 | /// described in GrabPointer, the last-pointer-grab time is set to the time at |
| 12166 | /// which the button was pressed (as transmitted in the ButtonPress event), and the |
| 12167 | /// ButtonPress event is reported if all of the following conditions are true: |
| 12168 | /// |
| 12169 | /// The pointer is not grabbed and the specified button is logically pressed when |
| 12170 | /// the specified modifier keys are logically down, and no other buttons or |
| 12171 | /// modifier keys are logically down. |
| 12172 | /// |
| 12173 | /// The grab-window contains the pointer. |
| 12174 | /// |
| 12175 | /// The confine-to window (if any) is viewable. |
| 12176 | /// |
| 12177 | /// A passive grab on the same button/key combination does not exist on any |
| 12178 | /// ancestor of grab-window. |
| 12179 | /// |
| 12180 | /// The interpretation of the remaining arguments is the same as for GrabPointer. |
| 12181 | /// The active grab is terminated automatically when the logical state of the |
| 12182 | /// pointer has all buttons released, independent of the logical state of modifier |
| 12183 | /// keys. Note that the logical state of a device (as seen by means of the |
| 12184 | /// protocol) may lag the physical state if device event processing is frozen. This |
| 12185 | /// request overrides all previous passive grabs by the same client on the same |
| 12186 | /// button/key combinations on the same window. A modifier of AnyModifier is |
| 12187 | /// equivalent to issuing the request for all possible modifier combinations |
| 12188 | /// (including the combination of no modifiers). It is not required that all |
| 12189 | /// specified modifiers have currently assigned keycodes. A button of AnyButton is |
| 12190 | /// equivalent to issuing the request for all possible buttons. Otherwise, it is |
| 12191 | /// not required that the button specified currently be assigned to a physical |
| 12192 | /// button. |
| 12193 | /// |
| 12194 | /// An Access error is generated if some other client has already issued a |
| 12195 | /// GrabButton request with the same button/key combination on the same window. |
| 12196 | /// When using AnyModifier or AnyButton, the request fails completely (no grabs are |
| 12197 | /// established), and an Access error is generated if there is a conflicting grab |
| 12198 | /// for any combination. The request has no effect on an active grab. |
| 12199 | /// |
| 12200 | /// # Fields |
| 12201 | /// |
| 12202 | /// * `owner_events` - If 1, the `grab_window` will still get the pointer events. If 0, events are not |
| 12203 | /// reported to the `grab_window`. |
| 12204 | /// * `grab_window` - Specifies the window on which the pointer should be grabbed. |
| 12205 | /// * `event_mask` - Specifies which pointer events are reported to the client. |
| 12206 | /// |
| 12207 | /// TODO: which values? |
| 12208 | /// * `confine_to` - Specifies the window to confine the pointer in (the user will not be able to |
| 12209 | /// move the pointer out of that window). |
| 12210 | /// |
| 12211 | /// The special value `XCB_NONE` means don't confine the pointer. |
| 12212 | /// * `cursor` - Specifies the cursor that should be displayed or `XCB_NONE` to not change the |
| 12213 | /// cursor. |
| 12214 | /// * `modifiers` - The modifiers to grab. |
| 12215 | /// |
| 12216 | /// Using the special value `XCB_MOD_MASK_ANY` means grab the pointer with all |
| 12217 | /// possible modifier combinations. |
| 12218 | /// * `pointer_mode` - |
| 12219 | /// * `keyboard_mode` - |
| 12220 | /// * `button` - |
| 12221 | /// |
| 12222 | /// # Errors |
| 12223 | /// |
| 12224 | /// * `Access` - Another client has already issued a GrabButton with the same button/key |
| 12225 | /// combination on the same window. |
| 12226 | /// * `Value` - TODO: reasons? |
| 12227 | /// * `Cursor` - The specified `cursor` does not exist. |
| 12228 | /// * `Window` - The specified `window` does not exist. |
| 12229 | #[derive (Clone, Copy, Default)] |
| 12230 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 12231 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12232 | pub struct GrabButtonRequest { |
| 12233 | pub owner_events: bool, |
| 12234 | pub grab_window: Window, |
| 12235 | pub event_mask: EventMask, |
| 12236 | pub pointer_mode: GrabMode, |
| 12237 | pub keyboard_mode: GrabMode, |
| 12238 | pub confine_to: Window, |
| 12239 | pub cursor: Cursor, |
| 12240 | pub button: ButtonIndex, |
| 12241 | pub modifiers: ModMask, |
| 12242 | } |
| 12243 | impl_debug_if_no_extra_traits!(GrabButtonRequest, "GrabButtonRequest" ); |
| 12244 | impl GrabButtonRequest { |
| 12245 | /// Serialize this request into bytes for the provided connection |
| 12246 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 12247 | let length_so_far = 0; |
| 12248 | let owner_events_bytes = self.owner_events.serialize(); |
| 12249 | let grab_window_bytes = self.grab_window.serialize(); |
| 12250 | let event_mask_bytes = (u32::from(self.event_mask) as u16).serialize(); |
| 12251 | let pointer_mode_bytes = u8::from(self.pointer_mode).serialize(); |
| 12252 | let keyboard_mode_bytes = u8::from(self.keyboard_mode).serialize(); |
| 12253 | let confine_to_bytes = self.confine_to.serialize(); |
| 12254 | let cursor_bytes = self.cursor.serialize(); |
| 12255 | let button_bytes = u8::from(self.button).serialize(); |
| 12256 | let modifiers_bytes = u16::from(self.modifiers).serialize(); |
| 12257 | let mut request0 = vec![ |
| 12258 | GRAB_BUTTON_REQUEST, |
| 12259 | owner_events_bytes[0], |
| 12260 | 0, |
| 12261 | 0, |
| 12262 | grab_window_bytes[0], |
| 12263 | grab_window_bytes[1], |
| 12264 | grab_window_bytes[2], |
| 12265 | grab_window_bytes[3], |
| 12266 | event_mask_bytes[0], |
| 12267 | event_mask_bytes[1], |
| 12268 | pointer_mode_bytes[0], |
| 12269 | keyboard_mode_bytes[0], |
| 12270 | confine_to_bytes[0], |
| 12271 | confine_to_bytes[1], |
| 12272 | confine_to_bytes[2], |
| 12273 | confine_to_bytes[3], |
| 12274 | cursor_bytes[0], |
| 12275 | cursor_bytes[1], |
| 12276 | cursor_bytes[2], |
| 12277 | cursor_bytes[3], |
| 12278 | button_bytes[0], |
| 12279 | 0, |
| 12280 | modifiers_bytes[0], |
| 12281 | modifiers_bytes[1], |
| 12282 | ]; |
| 12283 | let length_so_far = length_so_far + request0.len(); |
| 12284 | assert_eq!(length_so_far % 4, 0); |
| 12285 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 12286 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 12287 | ([request0.into()], vec![]) |
| 12288 | } |
| 12289 | /// Parse this request given its header, its body, and any fds that go along with it |
| 12290 | #[cfg (feature = "request-parsing" )] |
| 12291 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 12292 | if header.major_opcode != GRAB_BUTTON_REQUEST { |
| 12293 | return Err(ParseError::InvalidValue); |
| 12294 | } |
| 12295 | let remaining = &[header.minor_opcode]; |
| 12296 | let (owner_events, remaining) = bool::try_parse(remaining)?; |
| 12297 | let _ = remaining; |
| 12298 | let (grab_window, remaining) = Window::try_parse(value)?; |
| 12299 | let (event_mask, remaining) = u16::try_parse(remaining)?; |
| 12300 | let event_mask = event_mask.into(); |
| 12301 | let (pointer_mode, remaining) = u8::try_parse(remaining)?; |
| 12302 | let pointer_mode = pointer_mode.into(); |
| 12303 | let (keyboard_mode, remaining) = u8::try_parse(remaining)?; |
| 12304 | let keyboard_mode = keyboard_mode.into(); |
| 12305 | let (confine_to, remaining) = Window::try_parse(remaining)?; |
| 12306 | let (cursor, remaining) = Cursor::try_parse(remaining)?; |
| 12307 | let (button, remaining) = u8::try_parse(remaining)?; |
| 12308 | let button = button.into(); |
| 12309 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 12310 | let (modifiers, remaining) = u16::try_parse(remaining)?; |
| 12311 | let modifiers = modifiers.into(); |
| 12312 | let _ = remaining; |
| 12313 | Ok(GrabButtonRequest { |
| 12314 | owner_events, |
| 12315 | grab_window, |
| 12316 | event_mask, |
| 12317 | pointer_mode, |
| 12318 | keyboard_mode, |
| 12319 | confine_to, |
| 12320 | cursor, |
| 12321 | button, |
| 12322 | modifiers, |
| 12323 | }) |
| 12324 | } |
| 12325 | } |
| 12326 | impl Request for GrabButtonRequest { |
| 12327 | const EXTENSION_NAME: Option<&'static str> = None; |
| 12328 | |
| 12329 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 12330 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 12331 | // Flatten the buffers into a single vector |
| 12332 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 12333 | (buf, fds) |
| 12334 | } |
| 12335 | } |
| 12336 | impl crate::x11_utils::VoidRequest for GrabButtonRequest { |
| 12337 | } |
| 12338 | |
| 12339 | /// Opcode for the UngrabButton request |
| 12340 | pub const UNGRAB_BUTTON_REQUEST: u8 = 29; |
| 12341 | #[derive (Clone, Copy, Default)] |
| 12342 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 12343 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12344 | pub struct UngrabButtonRequest { |
| 12345 | pub button: ButtonIndex, |
| 12346 | pub grab_window: Window, |
| 12347 | pub modifiers: ModMask, |
| 12348 | } |
| 12349 | impl_debug_if_no_extra_traits!(UngrabButtonRequest, "UngrabButtonRequest" ); |
| 12350 | impl UngrabButtonRequest { |
| 12351 | /// Serialize this request into bytes for the provided connection |
| 12352 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 12353 | let length_so_far = 0; |
| 12354 | let button_bytes = u8::from(self.button).serialize(); |
| 12355 | let grab_window_bytes = self.grab_window.serialize(); |
| 12356 | let modifiers_bytes = u16::from(self.modifiers).serialize(); |
| 12357 | let mut request0 = vec![ |
| 12358 | UNGRAB_BUTTON_REQUEST, |
| 12359 | button_bytes[0], |
| 12360 | 0, |
| 12361 | 0, |
| 12362 | grab_window_bytes[0], |
| 12363 | grab_window_bytes[1], |
| 12364 | grab_window_bytes[2], |
| 12365 | grab_window_bytes[3], |
| 12366 | modifiers_bytes[0], |
| 12367 | modifiers_bytes[1], |
| 12368 | 0, |
| 12369 | 0, |
| 12370 | ]; |
| 12371 | let length_so_far = length_so_far + request0.len(); |
| 12372 | assert_eq!(length_so_far % 4, 0); |
| 12373 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 12374 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 12375 | ([request0.into()], vec![]) |
| 12376 | } |
| 12377 | /// Parse this request given its header, its body, and any fds that go along with it |
| 12378 | #[cfg (feature = "request-parsing" )] |
| 12379 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 12380 | if header.major_opcode != UNGRAB_BUTTON_REQUEST { |
| 12381 | return Err(ParseError::InvalidValue); |
| 12382 | } |
| 12383 | let remaining = &[header.minor_opcode]; |
| 12384 | let (button, remaining) = u8::try_parse(remaining)?; |
| 12385 | let button = button.into(); |
| 12386 | let _ = remaining; |
| 12387 | let (grab_window, remaining) = Window::try_parse(value)?; |
| 12388 | let (modifiers, remaining) = u16::try_parse(remaining)?; |
| 12389 | let modifiers = modifiers.into(); |
| 12390 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 12391 | let _ = remaining; |
| 12392 | Ok(UngrabButtonRequest { |
| 12393 | button, |
| 12394 | grab_window, |
| 12395 | modifiers, |
| 12396 | }) |
| 12397 | } |
| 12398 | } |
| 12399 | impl Request for UngrabButtonRequest { |
| 12400 | const EXTENSION_NAME: Option<&'static str> = None; |
| 12401 | |
| 12402 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 12403 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 12404 | // Flatten the buffers into a single vector |
| 12405 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 12406 | (buf, fds) |
| 12407 | } |
| 12408 | } |
| 12409 | impl crate::x11_utils::VoidRequest for UngrabButtonRequest { |
| 12410 | } |
| 12411 | |
| 12412 | /// Opcode for the ChangeActivePointerGrab request |
| 12413 | pub const CHANGE_ACTIVE_POINTER_GRAB_REQUEST: u8 = 30; |
| 12414 | #[derive (Clone, Copy, Default)] |
| 12415 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 12416 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12417 | pub struct ChangeActivePointerGrabRequest { |
| 12418 | pub cursor: Cursor, |
| 12419 | pub time: Timestamp, |
| 12420 | pub event_mask: EventMask, |
| 12421 | } |
| 12422 | impl_debug_if_no_extra_traits!(ChangeActivePointerGrabRequest, "ChangeActivePointerGrabRequest" ); |
| 12423 | impl ChangeActivePointerGrabRequest { |
| 12424 | /// Serialize this request into bytes for the provided connection |
| 12425 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 12426 | let length_so_far = 0; |
| 12427 | let cursor_bytes = self.cursor.serialize(); |
| 12428 | let time_bytes = self.time.serialize(); |
| 12429 | let event_mask_bytes = (u32::from(self.event_mask) as u16).serialize(); |
| 12430 | let mut request0 = vec![ |
| 12431 | CHANGE_ACTIVE_POINTER_GRAB_REQUEST, |
| 12432 | 0, |
| 12433 | 0, |
| 12434 | 0, |
| 12435 | cursor_bytes[0], |
| 12436 | cursor_bytes[1], |
| 12437 | cursor_bytes[2], |
| 12438 | cursor_bytes[3], |
| 12439 | time_bytes[0], |
| 12440 | time_bytes[1], |
| 12441 | time_bytes[2], |
| 12442 | time_bytes[3], |
| 12443 | event_mask_bytes[0], |
| 12444 | event_mask_bytes[1], |
| 12445 | 0, |
| 12446 | 0, |
| 12447 | ]; |
| 12448 | let length_so_far = length_so_far + request0.len(); |
| 12449 | assert_eq!(length_so_far % 4, 0); |
| 12450 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 12451 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 12452 | ([request0.into()], vec![]) |
| 12453 | } |
| 12454 | /// Parse this request given its header, its body, and any fds that go along with it |
| 12455 | #[cfg (feature = "request-parsing" )] |
| 12456 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 12457 | if header.major_opcode != CHANGE_ACTIVE_POINTER_GRAB_REQUEST { |
| 12458 | return Err(ParseError::InvalidValue); |
| 12459 | } |
| 12460 | let remaining = &[header.minor_opcode]; |
| 12461 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 12462 | let _ = remaining; |
| 12463 | let (cursor, remaining) = Cursor::try_parse(value)?; |
| 12464 | let (time, remaining) = Timestamp::try_parse(remaining)?; |
| 12465 | let (event_mask, remaining) = u16::try_parse(remaining)?; |
| 12466 | let event_mask = event_mask.into(); |
| 12467 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 12468 | let _ = remaining; |
| 12469 | Ok(ChangeActivePointerGrabRequest { |
| 12470 | cursor, |
| 12471 | time, |
| 12472 | event_mask, |
| 12473 | }) |
| 12474 | } |
| 12475 | } |
| 12476 | impl Request for ChangeActivePointerGrabRequest { |
| 12477 | const EXTENSION_NAME: Option<&'static str> = None; |
| 12478 | |
| 12479 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 12480 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 12481 | // Flatten the buffers into a single vector |
| 12482 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 12483 | (buf, fds) |
| 12484 | } |
| 12485 | } |
| 12486 | impl crate::x11_utils::VoidRequest for ChangeActivePointerGrabRequest { |
| 12487 | } |
| 12488 | |
| 12489 | /// Opcode for the GrabKeyboard request |
| 12490 | pub const GRAB_KEYBOARD_REQUEST: u8 = 31; |
| 12491 | /// Grab the keyboard. |
| 12492 | /// |
| 12493 | /// Actively grabs control of the keyboard and generates FocusIn and FocusOut |
| 12494 | /// events. Further key events are reported only to the grabbing client. |
| 12495 | /// |
| 12496 | /// Any active keyboard grab by this client is overridden. If the keyboard is |
| 12497 | /// actively grabbed by some other client, `AlreadyGrabbed` is returned. If |
| 12498 | /// `grab_window` is not viewable, `GrabNotViewable` is returned. If the keyboard |
| 12499 | /// is frozen by an active grab of another client, `GrabFrozen` is returned. If the |
| 12500 | /// specified `time` is earlier than the last-keyboard-grab time or later than the |
| 12501 | /// current X server time, `GrabInvalidTime` is returned. Otherwise, the |
| 12502 | /// last-keyboard-grab time is set to the specified time. |
| 12503 | /// |
| 12504 | /// # Fields |
| 12505 | /// |
| 12506 | /// * `owner_events` - If 1, the `grab_window` will still get the pointer events. If 0, events are not |
| 12507 | /// reported to the `grab_window`. |
| 12508 | /// * `grab_window` - Specifies the window on which the pointer should be grabbed. |
| 12509 | /// * `time` - Timestamp to avoid race conditions when running X over the network. |
| 12510 | /// |
| 12511 | /// The special value `XCB_CURRENT_TIME` will be replaced with the current server |
| 12512 | /// time. |
| 12513 | /// * `pointer_mode` - |
| 12514 | /// * `keyboard_mode` - |
| 12515 | /// |
| 12516 | /// # Errors |
| 12517 | /// |
| 12518 | /// * `Value` - TODO: reasons? |
| 12519 | /// * `Window` - The specified `window` does not exist. |
| 12520 | /// |
| 12521 | /// # See |
| 12522 | /// |
| 12523 | /// * `GrabPointer`: request |
| 12524 | /// |
| 12525 | /// # Example |
| 12526 | /// |
| 12527 | /// ```text |
| 12528 | /// /* |
| 12529 | /// * Grabs the keyboard actively |
| 12530 | /// * |
| 12531 | /// */ |
| 12532 | /// void my_example(xcb_connection_t *conn, xcb_screen_t *screen) { |
| 12533 | /// xcb_grab_keyboard_cookie_t cookie; |
| 12534 | /// xcb_grab_keyboard_reply_t *reply; |
| 12535 | /// |
| 12536 | /// cookie = xcb_grab_keyboard( |
| 12537 | /// conn, |
| 12538 | /// true, /* report events */ |
| 12539 | /// screen->root, /* grab the root window */ |
| 12540 | /// XCB_CURRENT_TIME, |
| 12541 | /// XCB_GRAB_MODE_ASYNC, /* process events as normal, do not require sync */ |
| 12542 | /// XCB_GRAB_MODE_ASYNC |
| 12543 | /// ); |
| 12544 | /// |
| 12545 | /// if ((reply = xcb_grab_keyboard_reply(conn, cookie, NULL))) { |
| 12546 | /// if (reply->status == XCB_GRAB_STATUS_SUCCESS) |
| 12547 | /// printf("successfully grabbed the keyboard\\n"); |
| 12548 | /// |
| 12549 | /// free(reply); |
| 12550 | /// } |
| 12551 | /// } |
| 12552 | /// ``` |
| 12553 | #[derive (Clone, Copy, Default)] |
| 12554 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 12555 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12556 | pub struct GrabKeyboardRequest { |
| 12557 | pub owner_events: bool, |
| 12558 | pub grab_window: Window, |
| 12559 | pub time: Timestamp, |
| 12560 | pub pointer_mode: GrabMode, |
| 12561 | pub keyboard_mode: GrabMode, |
| 12562 | } |
| 12563 | impl_debug_if_no_extra_traits!(GrabKeyboardRequest, "GrabKeyboardRequest" ); |
| 12564 | impl GrabKeyboardRequest { |
| 12565 | /// Serialize this request into bytes for the provided connection |
| 12566 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 12567 | let length_so_far = 0; |
| 12568 | let owner_events_bytes = self.owner_events.serialize(); |
| 12569 | let grab_window_bytes = self.grab_window.serialize(); |
| 12570 | let time_bytes = self.time.serialize(); |
| 12571 | let pointer_mode_bytes = u8::from(self.pointer_mode).serialize(); |
| 12572 | let keyboard_mode_bytes = u8::from(self.keyboard_mode).serialize(); |
| 12573 | let mut request0 = vec![ |
| 12574 | GRAB_KEYBOARD_REQUEST, |
| 12575 | owner_events_bytes[0], |
| 12576 | 0, |
| 12577 | 0, |
| 12578 | grab_window_bytes[0], |
| 12579 | grab_window_bytes[1], |
| 12580 | grab_window_bytes[2], |
| 12581 | grab_window_bytes[3], |
| 12582 | time_bytes[0], |
| 12583 | time_bytes[1], |
| 12584 | time_bytes[2], |
| 12585 | time_bytes[3], |
| 12586 | pointer_mode_bytes[0], |
| 12587 | keyboard_mode_bytes[0], |
| 12588 | 0, |
| 12589 | 0, |
| 12590 | ]; |
| 12591 | let length_so_far = length_so_far + request0.len(); |
| 12592 | assert_eq!(length_so_far % 4, 0); |
| 12593 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 12594 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 12595 | ([request0.into()], vec![]) |
| 12596 | } |
| 12597 | /// Parse this request given its header, its body, and any fds that go along with it |
| 12598 | #[cfg (feature = "request-parsing" )] |
| 12599 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 12600 | if header.major_opcode != GRAB_KEYBOARD_REQUEST { |
| 12601 | return Err(ParseError::InvalidValue); |
| 12602 | } |
| 12603 | let remaining = &[header.minor_opcode]; |
| 12604 | let (owner_events, remaining) = bool::try_parse(remaining)?; |
| 12605 | let _ = remaining; |
| 12606 | let (grab_window, remaining) = Window::try_parse(value)?; |
| 12607 | let (time, remaining) = Timestamp::try_parse(remaining)?; |
| 12608 | let (pointer_mode, remaining) = u8::try_parse(remaining)?; |
| 12609 | let pointer_mode = pointer_mode.into(); |
| 12610 | let (keyboard_mode, remaining) = u8::try_parse(remaining)?; |
| 12611 | let keyboard_mode = keyboard_mode.into(); |
| 12612 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 12613 | let _ = remaining; |
| 12614 | Ok(GrabKeyboardRequest { |
| 12615 | owner_events, |
| 12616 | grab_window, |
| 12617 | time, |
| 12618 | pointer_mode, |
| 12619 | keyboard_mode, |
| 12620 | }) |
| 12621 | } |
| 12622 | } |
| 12623 | impl Request for GrabKeyboardRequest { |
| 12624 | const EXTENSION_NAME: Option<&'static str> = None; |
| 12625 | |
| 12626 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 12627 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 12628 | // Flatten the buffers into a single vector |
| 12629 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 12630 | (buf, fds) |
| 12631 | } |
| 12632 | } |
| 12633 | impl crate::x11_utils::ReplyRequest for GrabKeyboardRequest { |
| 12634 | type Reply = GrabKeyboardReply; |
| 12635 | } |
| 12636 | |
| 12637 | #[derive (Clone, Copy, Default)] |
| 12638 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 12639 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12640 | pub struct GrabKeyboardReply { |
| 12641 | pub status: GrabStatus, |
| 12642 | pub sequence: u16, |
| 12643 | pub length: u32, |
| 12644 | } |
| 12645 | impl_debug_if_no_extra_traits!(GrabKeyboardReply, "GrabKeyboardReply" ); |
| 12646 | impl TryParse for GrabKeyboardReply { |
| 12647 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 12648 | let remaining: &[u8] = initial_value; |
| 12649 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 12650 | let (status: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 12651 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 12652 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 12653 | if response_type != 1 { |
| 12654 | return Err(ParseError::InvalidValue); |
| 12655 | } |
| 12656 | let status: GrabStatus = status.into(); |
| 12657 | let result: GrabKeyboardReply = GrabKeyboardReply { status, sequence, length }; |
| 12658 | let _ = remaining; |
| 12659 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 12660 | .ok_or(err:ParseError::InsufficientData)?; |
| 12661 | Ok((result, remaining)) |
| 12662 | } |
| 12663 | } |
| 12664 | impl Serialize for GrabKeyboardReply { |
| 12665 | type Bytes = [u8; 8]; |
| 12666 | fn serialize(&self) -> [u8; 8] { |
| 12667 | let response_type_bytes = &[1]; |
| 12668 | let status_bytes = u8::from(self.status).serialize(); |
| 12669 | let sequence_bytes = self.sequence.serialize(); |
| 12670 | let length_bytes = self.length.serialize(); |
| 12671 | [ |
| 12672 | response_type_bytes[0], |
| 12673 | status_bytes[0], |
| 12674 | sequence_bytes[0], |
| 12675 | sequence_bytes[1], |
| 12676 | length_bytes[0], |
| 12677 | length_bytes[1], |
| 12678 | length_bytes[2], |
| 12679 | length_bytes[3], |
| 12680 | ] |
| 12681 | } |
| 12682 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 12683 | bytes.reserve(8); |
| 12684 | let response_type_bytes = &[1]; |
| 12685 | bytes.push(response_type_bytes[0]); |
| 12686 | u8::from(self.status).serialize_into(bytes); |
| 12687 | self.sequence.serialize_into(bytes); |
| 12688 | self.length.serialize_into(bytes); |
| 12689 | } |
| 12690 | } |
| 12691 | |
| 12692 | /// Opcode for the UngrabKeyboard request |
| 12693 | pub const UNGRAB_KEYBOARD_REQUEST: u8 = 32; |
| 12694 | #[derive (Clone, Copy, Default)] |
| 12695 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 12696 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12697 | pub struct UngrabKeyboardRequest { |
| 12698 | pub time: Timestamp, |
| 12699 | } |
| 12700 | impl_debug_if_no_extra_traits!(UngrabKeyboardRequest, "UngrabKeyboardRequest" ); |
| 12701 | impl UngrabKeyboardRequest { |
| 12702 | /// Serialize this request into bytes for the provided connection |
| 12703 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 12704 | let length_so_far = 0; |
| 12705 | let time_bytes = self.time.serialize(); |
| 12706 | let mut request0 = vec![ |
| 12707 | UNGRAB_KEYBOARD_REQUEST, |
| 12708 | 0, |
| 12709 | 0, |
| 12710 | 0, |
| 12711 | time_bytes[0], |
| 12712 | time_bytes[1], |
| 12713 | time_bytes[2], |
| 12714 | time_bytes[3], |
| 12715 | ]; |
| 12716 | let length_so_far = length_so_far + request0.len(); |
| 12717 | assert_eq!(length_so_far % 4, 0); |
| 12718 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 12719 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 12720 | ([request0.into()], vec![]) |
| 12721 | } |
| 12722 | /// Parse this request given its header, its body, and any fds that go along with it |
| 12723 | #[cfg (feature = "request-parsing" )] |
| 12724 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 12725 | if header.major_opcode != UNGRAB_KEYBOARD_REQUEST { |
| 12726 | return Err(ParseError::InvalidValue); |
| 12727 | } |
| 12728 | let remaining = &[header.minor_opcode]; |
| 12729 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 12730 | let _ = remaining; |
| 12731 | let (time, remaining) = Timestamp::try_parse(value)?; |
| 12732 | let _ = remaining; |
| 12733 | Ok(UngrabKeyboardRequest { |
| 12734 | time, |
| 12735 | }) |
| 12736 | } |
| 12737 | } |
| 12738 | impl Request for UngrabKeyboardRequest { |
| 12739 | const EXTENSION_NAME: Option<&'static str> = None; |
| 12740 | |
| 12741 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 12742 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 12743 | // Flatten the buffers into a single vector |
| 12744 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 12745 | (buf, fds) |
| 12746 | } |
| 12747 | } |
| 12748 | impl crate::x11_utils::VoidRequest for UngrabKeyboardRequest { |
| 12749 | } |
| 12750 | |
| 12751 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 12752 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12753 | pub struct Grab(u8); |
| 12754 | impl Grab { |
| 12755 | pub const ANY: Self = Self(0); |
| 12756 | } |
| 12757 | impl From<Grab> for u8 { |
| 12758 | #[inline ] |
| 12759 | fn from(input: Grab) -> Self { |
| 12760 | input.0 |
| 12761 | } |
| 12762 | } |
| 12763 | impl From<Grab> for Option<u8> { |
| 12764 | #[inline ] |
| 12765 | fn from(input: Grab) -> Self { |
| 12766 | Some(input.0) |
| 12767 | } |
| 12768 | } |
| 12769 | impl From<Grab> for u16 { |
| 12770 | #[inline ] |
| 12771 | fn from(input: Grab) -> Self { |
| 12772 | u16::from(input.0) |
| 12773 | } |
| 12774 | } |
| 12775 | impl From<Grab> for Option<u16> { |
| 12776 | #[inline ] |
| 12777 | fn from(input: Grab) -> Self { |
| 12778 | Some(u16::from(input.0)) |
| 12779 | } |
| 12780 | } |
| 12781 | impl From<Grab> for u32 { |
| 12782 | #[inline ] |
| 12783 | fn from(input: Grab) -> Self { |
| 12784 | u32::from(input.0) |
| 12785 | } |
| 12786 | } |
| 12787 | impl From<Grab> for Option<u32> { |
| 12788 | #[inline ] |
| 12789 | fn from(input: Grab) -> Self { |
| 12790 | Some(u32::from(input.0)) |
| 12791 | } |
| 12792 | } |
| 12793 | impl From<u8> for Grab { |
| 12794 | #[inline ] |
| 12795 | fn from(value: u8) -> Self { |
| 12796 | Self(value) |
| 12797 | } |
| 12798 | } |
| 12799 | impl core::fmt::Debug for Grab { |
| 12800 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 12801 | let variants: [(u32, &'static str, &'static …); 1] = [ |
| 12802 | (Self::ANY.0.into(), "ANY" , "Any" ), |
| 12803 | ]; |
| 12804 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 12805 | } |
| 12806 | } |
| 12807 | |
| 12808 | /// Opcode for the GrabKey request |
| 12809 | pub const GRAB_KEY_REQUEST: u8 = 33; |
| 12810 | /// Grab keyboard key(s). |
| 12811 | /// |
| 12812 | /// Establishes a passive grab on the keyboard. In the future, the keyboard is |
| 12813 | /// actively grabbed (as for `GrabKeyboard`), the last-keyboard-grab time is set to |
| 12814 | /// the time at which the key was pressed (as transmitted in the KeyPress event), |
| 12815 | /// and the KeyPress event is reported if all of the following conditions are true: |
| 12816 | /// |
| 12817 | /// The keyboard is not grabbed and the specified key (which can itself be a |
| 12818 | /// modifier key) is logically pressed when the specified modifier keys are |
| 12819 | /// logically down, and no other modifier keys are logically down. |
| 12820 | /// |
| 12821 | /// Either the grab_window is an ancestor of (or is) the focus window, or the |
| 12822 | /// grab_window is a descendant of the focus window and contains the pointer. |
| 12823 | /// |
| 12824 | /// A passive grab on the same key combination does not exist on any ancestor of |
| 12825 | /// grab_window. |
| 12826 | /// |
| 12827 | /// The interpretation of the remaining arguments is as for XGrabKeyboard. The active grab is terminated |
| 12828 | /// automatically when the logical state of the keyboard has the specified key released (independent of the |
| 12829 | /// logical state of the modifier keys), at which point a KeyRelease event is reported to the grabbing window. |
| 12830 | /// |
| 12831 | /// Note that the logical state of a device (as seen by client applications) may lag the physical state if |
| 12832 | /// device event processing is frozen. |
| 12833 | /// |
| 12834 | /// A modifiers argument of AnyModifier is equivalent to issuing the request for all possible modifier combinations (including the combination of no modifiers). It is not required that all modifiers specified |
| 12835 | /// have currently assigned KeyCodes. A keycode argument of AnyKey is equivalent to issuing the request for |
| 12836 | /// all possible KeyCodes. Otherwise, the specified keycode must be in the range specified by min_keycode |
| 12837 | /// and max_keycode in the connection setup, or a BadValue error results. |
| 12838 | /// |
| 12839 | /// If some other client has issued a XGrabKey with the same key combination on the same window, a BadAccess |
| 12840 | /// error results. When using AnyModifier or AnyKey, the request fails completely, and a BadAccess error |
| 12841 | /// results (no grabs are established) if there is a conflicting grab for any combination. |
| 12842 | /// |
| 12843 | /// # Fields |
| 12844 | /// |
| 12845 | /// * `owner_events` - If 1, the `grab_window` will still get the key events. If 0, events are not |
| 12846 | /// reported to the `grab_window`. |
| 12847 | /// * `grab_window` - Specifies the window on which the key should be grabbed. |
| 12848 | /// * `key` - The keycode of the key to grab. |
| 12849 | /// |
| 12850 | /// The special value `XCB_GRAB_ANY` means grab any key. |
| 12851 | /// * `modifiers` - The modifiers to grab. |
| 12852 | /// |
| 12853 | /// Using the special value `XCB_MOD_MASK_ANY` means grab the key with all |
| 12854 | /// possible modifier combinations. |
| 12855 | /// * `pointer_mode` - |
| 12856 | /// * `keyboard_mode` - |
| 12857 | /// |
| 12858 | /// # Errors |
| 12859 | /// |
| 12860 | /// * `Access` - Another client has already issued a GrabKey with the same button/key |
| 12861 | /// combination on the same window. |
| 12862 | /// * `Value` - The key is not `XCB_GRAB_ANY` and not in the range specified by `min_keycode` |
| 12863 | /// and `max_keycode` in the connection setup. |
| 12864 | /// * `Window` - The specified `window` does not exist. |
| 12865 | /// |
| 12866 | /// # See |
| 12867 | /// |
| 12868 | /// * `GrabKeyboard`: request |
| 12869 | #[derive (Clone, Copy, Default)] |
| 12870 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 12871 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12872 | pub struct GrabKeyRequest { |
| 12873 | pub owner_events: bool, |
| 12874 | pub grab_window: Window, |
| 12875 | pub modifiers: ModMask, |
| 12876 | pub key: Keycode, |
| 12877 | pub pointer_mode: GrabMode, |
| 12878 | pub keyboard_mode: GrabMode, |
| 12879 | } |
| 12880 | impl_debug_if_no_extra_traits!(GrabKeyRequest, "GrabKeyRequest" ); |
| 12881 | impl GrabKeyRequest { |
| 12882 | /// Serialize this request into bytes for the provided connection |
| 12883 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 12884 | let length_so_far = 0; |
| 12885 | let owner_events_bytes = self.owner_events.serialize(); |
| 12886 | let grab_window_bytes = self.grab_window.serialize(); |
| 12887 | let modifiers_bytes = u16::from(self.modifiers).serialize(); |
| 12888 | let key_bytes = self.key.serialize(); |
| 12889 | let pointer_mode_bytes = u8::from(self.pointer_mode).serialize(); |
| 12890 | let keyboard_mode_bytes = u8::from(self.keyboard_mode).serialize(); |
| 12891 | let mut request0 = vec![ |
| 12892 | GRAB_KEY_REQUEST, |
| 12893 | owner_events_bytes[0], |
| 12894 | 0, |
| 12895 | 0, |
| 12896 | grab_window_bytes[0], |
| 12897 | grab_window_bytes[1], |
| 12898 | grab_window_bytes[2], |
| 12899 | grab_window_bytes[3], |
| 12900 | modifiers_bytes[0], |
| 12901 | modifiers_bytes[1], |
| 12902 | key_bytes[0], |
| 12903 | pointer_mode_bytes[0], |
| 12904 | keyboard_mode_bytes[0], |
| 12905 | 0, |
| 12906 | 0, |
| 12907 | 0, |
| 12908 | ]; |
| 12909 | let length_so_far = length_so_far + request0.len(); |
| 12910 | assert_eq!(length_so_far % 4, 0); |
| 12911 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 12912 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 12913 | ([request0.into()], vec![]) |
| 12914 | } |
| 12915 | /// Parse this request given its header, its body, and any fds that go along with it |
| 12916 | #[cfg (feature = "request-parsing" )] |
| 12917 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 12918 | if header.major_opcode != GRAB_KEY_REQUEST { |
| 12919 | return Err(ParseError::InvalidValue); |
| 12920 | } |
| 12921 | let remaining = &[header.minor_opcode]; |
| 12922 | let (owner_events, remaining) = bool::try_parse(remaining)?; |
| 12923 | let _ = remaining; |
| 12924 | let (grab_window, remaining) = Window::try_parse(value)?; |
| 12925 | let (modifiers, remaining) = u16::try_parse(remaining)?; |
| 12926 | let modifiers = modifiers.into(); |
| 12927 | let (key, remaining) = Keycode::try_parse(remaining)?; |
| 12928 | let (pointer_mode, remaining) = u8::try_parse(remaining)?; |
| 12929 | let pointer_mode = pointer_mode.into(); |
| 12930 | let (keyboard_mode, remaining) = u8::try_parse(remaining)?; |
| 12931 | let keyboard_mode = keyboard_mode.into(); |
| 12932 | let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; |
| 12933 | let _ = remaining; |
| 12934 | Ok(GrabKeyRequest { |
| 12935 | owner_events, |
| 12936 | grab_window, |
| 12937 | modifiers, |
| 12938 | key, |
| 12939 | pointer_mode, |
| 12940 | keyboard_mode, |
| 12941 | }) |
| 12942 | } |
| 12943 | } |
| 12944 | impl Request for GrabKeyRequest { |
| 12945 | const EXTENSION_NAME: Option<&'static str> = None; |
| 12946 | |
| 12947 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 12948 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 12949 | // Flatten the buffers into a single vector |
| 12950 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 12951 | (buf, fds) |
| 12952 | } |
| 12953 | } |
| 12954 | impl crate::x11_utils::VoidRequest for GrabKeyRequest { |
| 12955 | } |
| 12956 | |
| 12957 | /// Opcode for the UngrabKey request |
| 12958 | pub const UNGRAB_KEY_REQUEST: u8 = 34; |
| 12959 | /// release a key combination. |
| 12960 | /// |
| 12961 | /// Releases the key combination on `grab_window` if you grabbed it using |
| 12962 | /// `xcb_grab_key` before. |
| 12963 | /// |
| 12964 | /// # Fields |
| 12965 | /// |
| 12966 | /// * `key` - The keycode of the specified key combination. |
| 12967 | /// |
| 12968 | /// Using the special value `XCB_GRAB_ANY` means releasing all possible key codes. |
| 12969 | /// * `grab_window` - The window on which the grabbed key combination will be released. |
| 12970 | /// * `modifiers` - The modifiers of the specified key combination. |
| 12971 | /// |
| 12972 | /// Using the special value `XCB_MOD_MASK_ANY` means releasing the key combination |
| 12973 | /// with every possible modifier combination. |
| 12974 | /// |
| 12975 | /// # Errors |
| 12976 | /// |
| 12977 | /// * `Window` - The specified `grab_window` does not exist. |
| 12978 | /// * `Value` - TODO: reasons? |
| 12979 | /// |
| 12980 | /// # See |
| 12981 | /// |
| 12982 | /// * `GrabKey`: request |
| 12983 | /// * `xev`: program |
| 12984 | #[derive (Clone, Copy, Default)] |
| 12985 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 12986 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12987 | pub struct UngrabKeyRequest { |
| 12988 | pub key: Keycode, |
| 12989 | pub grab_window: Window, |
| 12990 | pub modifiers: ModMask, |
| 12991 | } |
| 12992 | impl_debug_if_no_extra_traits!(UngrabKeyRequest, "UngrabKeyRequest" ); |
| 12993 | impl UngrabKeyRequest { |
| 12994 | /// Serialize this request into bytes for the provided connection |
| 12995 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 12996 | let length_so_far = 0; |
| 12997 | let key_bytes = self.key.serialize(); |
| 12998 | let grab_window_bytes = self.grab_window.serialize(); |
| 12999 | let modifiers_bytes = u16::from(self.modifiers).serialize(); |
| 13000 | let mut request0 = vec![ |
| 13001 | UNGRAB_KEY_REQUEST, |
| 13002 | key_bytes[0], |
| 13003 | 0, |
| 13004 | 0, |
| 13005 | grab_window_bytes[0], |
| 13006 | grab_window_bytes[1], |
| 13007 | grab_window_bytes[2], |
| 13008 | grab_window_bytes[3], |
| 13009 | modifiers_bytes[0], |
| 13010 | modifiers_bytes[1], |
| 13011 | 0, |
| 13012 | 0, |
| 13013 | ]; |
| 13014 | let length_so_far = length_so_far + request0.len(); |
| 13015 | assert_eq!(length_so_far % 4, 0); |
| 13016 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 13017 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 13018 | ([request0.into()], vec![]) |
| 13019 | } |
| 13020 | /// Parse this request given its header, its body, and any fds that go along with it |
| 13021 | #[cfg (feature = "request-parsing" )] |
| 13022 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 13023 | if header.major_opcode != UNGRAB_KEY_REQUEST { |
| 13024 | return Err(ParseError::InvalidValue); |
| 13025 | } |
| 13026 | let remaining = &[header.minor_opcode]; |
| 13027 | let (key, remaining) = Keycode::try_parse(remaining)?; |
| 13028 | let _ = remaining; |
| 13029 | let (grab_window, remaining) = Window::try_parse(value)?; |
| 13030 | let (modifiers, remaining) = u16::try_parse(remaining)?; |
| 13031 | let modifiers = modifiers.into(); |
| 13032 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 13033 | let _ = remaining; |
| 13034 | Ok(UngrabKeyRequest { |
| 13035 | key, |
| 13036 | grab_window, |
| 13037 | modifiers, |
| 13038 | }) |
| 13039 | } |
| 13040 | } |
| 13041 | impl Request for UngrabKeyRequest { |
| 13042 | const EXTENSION_NAME: Option<&'static str> = None; |
| 13043 | |
| 13044 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 13045 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 13046 | // Flatten the buffers into a single vector |
| 13047 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 13048 | (buf, fds) |
| 13049 | } |
| 13050 | } |
| 13051 | impl crate::x11_utils::VoidRequest for UngrabKeyRequest { |
| 13052 | } |
| 13053 | |
| 13054 | /// # Fields |
| 13055 | /// |
| 13056 | /// * `AsyncPointer` - For AsyncPointer, if the pointer is frozen by the client, pointer event |
| 13057 | /// processing continues normally. If the pointer is frozen twice by the client on |
| 13058 | /// behalf of two separate grabs, AsyncPointer thaws for both. AsyncPointer has no |
| 13059 | /// effect if the pointer is not frozen by the client, but the pointer need not be |
| 13060 | /// grabbed by the client. |
| 13061 | /// |
| 13062 | /// TODO: rewrite this in more understandable terms. |
| 13063 | /// * `SyncPointer` - For SyncPointer, if the pointer is frozen and actively grabbed by the client, |
| 13064 | /// pointer event processing continues normally until the next ButtonPress or |
| 13065 | /// ButtonRelease event is reported to the client, at which time the pointer again |
| 13066 | /// appears to freeze. However, if the reported event causes the pointer grab to be |
| 13067 | /// released, then the pointer does not freeze. SyncPointer has no effect if the |
| 13068 | /// pointer is not frozen by the client or if the pointer is not grabbed by the |
| 13069 | /// client. |
| 13070 | /// * `ReplayPointer` - For ReplayPointer, if the pointer is actively grabbed by the client and is |
| 13071 | /// frozen as the result of an event having been sent to the client (either from |
| 13072 | /// the activation of a GrabButton or from a previous AllowEvents with mode |
| 13073 | /// SyncPointer but not from a GrabPointer), then the pointer grab is released and |
| 13074 | /// that event is completely reprocessed, this time ignoring any passive grabs at |
| 13075 | /// or above (towards the root) the grab-window of the grab just released. The |
| 13076 | /// request has no effect if the pointer is not grabbed by the client or if the |
| 13077 | /// pointer is not frozen as the result of an event. |
| 13078 | /// * `AsyncKeyboard` - For AsyncKeyboard, if the keyboard is frozen by the client, keyboard event |
| 13079 | /// processing continues normally. If the keyboard is frozen twice by the client on |
| 13080 | /// behalf of two separate grabs, AsyncKeyboard thaws for both. AsyncKeyboard has |
| 13081 | /// no effect if the keyboard is not frozen by the client, but the keyboard need |
| 13082 | /// not be grabbed by the client. |
| 13083 | /// * `SyncKeyboard` - For SyncKeyboard, if the keyboard is frozen and actively grabbed by the client, |
| 13084 | /// keyboard event processing continues normally until the next KeyPress or |
| 13085 | /// KeyRelease event is reported to the client, at which time the keyboard again |
| 13086 | /// appears to freeze. However, if the reported event causes the keyboard grab to |
| 13087 | /// be released, then the keyboard does not freeze. SyncKeyboard has no effect if |
| 13088 | /// the keyboard is not frozen by the client or if the keyboard is not grabbed by |
| 13089 | /// the client. |
| 13090 | /// * `ReplayKeyboard` - For ReplayKeyboard, if the keyboard is actively grabbed by the client and is |
| 13091 | /// frozen as the result of an event having been sent to the client (either from |
| 13092 | /// the activation of a GrabKey or from a previous AllowEvents with mode |
| 13093 | /// SyncKeyboard but not from a GrabKeyboard), then the keyboard grab is released |
| 13094 | /// and that event is completely reprocessed, this time ignoring any passive grabs |
| 13095 | /// at or above (towards the root) the grab-window of the grab just released. The |
| 13096 | /// request has no effect if the keyboard is not grabbed by the client or if the |
| 13097 | /// keyboard is not frozen as the result of an event. |
| 13098 | /// * `SyncBoth` - For SyncBoth, if both pointer and keyboard are frozen by the client, event |
| 13099 | /// processing (for both devices) continues normally until the next ButtonPress, |
| 13100 | /// ButtonRelease, KeyPress, or KeyRelease event is reported to the client for a |
| 13101 | /// grabbed device (button event for the pointer, key event for the keyboard), at |
| 13102 | /// which time the devices again appear to freeze. However, if the reported event |
| 13103 | /// causes the grab to be released, then the devices do not freeze (but if the |
| 13104 | /// other device is still grabbed, then a subsequent event for it will still cause |
| 13105 | /// both devices to freeze). SyncBoth has no effect unless both pointer and |
| 13106 | /// keyboard are frozen by the client. If the pointer or keyboard is frozen twice |
| 13107 | /// by the client on behalf of two separate grabs, SyncBoth thaws for both (but a |
| 13108 | /// subsequent freeze for SyncBoth will only freeze each device once). |
| 13109 | /// * `AsyncBoth` - For AsyncBoth, if the pointer and the keyboard are frozen by the client, event |
| 13110 | /// processing for both devices continues normally. If a device is frozen twice by |
| 13111 | /// the client on behalf of two separate grabs, AsyncBoth thaws for both. AsyncBoth |
| 13112 | /// has no effect unless both pointer and keyboard are frozen by the client. |
| 13113 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 13114 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 13115 | pub struct Allow(u8); |
| 13116 | impl Allow { |
| 13117 | pub const ASYNC_POINTER: Self = Self(0); |
| 13118 | pub const SYNC_POINTER: Self = Self(1); |
| 13119 | pub const REPLAY_POINTER: Self = Self(2); |
| 13120 | pub const ASYNC_KEYBOARD: Self = Self(3); |
| 13121 | pub const SYNC_KEYBOARD: Self = Self(4); |
| 13122 | pub const REPLAY_KEYBOARD: Self = Self(5); |
| 13123 | pub const ASYNC_BOTH: Self = Self(6); |
| 13124 | pub const SYNC_BOTH: Self = Self(7); |
| 13125 | } |
| 13126 | impl From<Allow> for u8 { |
| 13127 | #[inline ] |
| 13128 | fn from(input: Allow) -> Self { |
| 13129 | input.0 |
| 13130 | } |
| 13131 | } |
| 13132 | impl From<Allow> for Option<u8> { |
| 13133 | #[inline ] |
| 13134 | fn from(input: Allow) -> Self { |
| 13135 | Some(input.0) |
| 13136 | } |
| 13137 | } |
| 13138 | impl From<Allow> for u16 { |
| 13139 | #[inline ] |
| 13140 | fn from(input: Allow) -> Self { |
| 13141 | u16::from(input.0) |
| 13142 | } |
| 13143 | } |
| 13144 | impl From<Allow> for Option<u16> { |
| 13145 | #[inline ] |
| 13146 | fn from(input: Allow) -> Self { |
| 13147 | Some(u16::from(input.0)) |
| 13148 | } |
| 13149 | } |
| 13150 | impl From<Allow> for u32 { |
| 13151 | #[inline ] |
| 13152 | fn from(input: Allow) -> Self { |
| 13153 | u32::from(input.0) |
| 13154 | } |
| 13155 | } |
| 13156 | impl From<Allow> for Option<u32> { |
| 13157 | #[inline ] |
| 13158 | fn from(input: Allow) -> Self { |
| 13159 | Some(u32::from(input.0)) |
| 13160 | } |
| 13161 | } |
| 13162 | impl From<u8> for Allow { |
| 13163 | #[inline ] |
| 13164 | fn from(value: u8) -> Self { |
| 13165 | Self(value) |
| 13166 | } |
| 13167 | } |
| 13168 | impl core::fmt::Debug for Allow { |
| 13169 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 13170 | let variants: [(u32, &'static str, &'static …); 8] = [ |
| 13171 | (Self::ASYNC_POINTER.0.into(), "ASYNC_POINTER" , "AsyncPointer" ), |
| 13172 | (Self::SYNC_POINTER.0.into(), "SYNC_POINTER" , "SyncPointer" ), |
| 13173 | (Self::REPLAY_POINTER.0.into(), "REPLAY_POINTER" , "ReplayPointer" ), |
| 13174 | (Self::ASYNC_KEYBOARD.0.into(), "ASYNC_KEYBOARD" , "AsyncKeyboard" ), |
| 13175 | (Self::SYNC_KEYBOARD.0.into(), "SYNC_KEYBOARD" , "SyncKeyboard" ), |
| 13176 | (Self::REPLAY_KEYBOARD.0.into(), "REPLAY_KEYBOARD" , "ReplayKeyboard" ), |
| 13177 | (Self::ASYNC_BOTH.0.into(), "ASYNC_BOTH" , "AsyncBoth" ), |
| 13178 | (Self::SYNC_BOTH.0.into(), "SYNC_BOTH" , "SyncBoth" ), |
| 13179 | ]; |
| 13180 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 13181 | } |
| 13182 | } |
| 13183 | |
| 13184 | /// Opcode for the AllowEvents request |
| 13185 | pub const ALLOW_EVENTS_REQUEST: u8 = 35; |
| 13186 | /// release queued events. |
| 13187 | /// |
| 13188 | /// Releases queued events if the client has caused a device (pointer/keyboard) to |
| 13189 | /// freeze due to grabbing it actively. This request has no effect if `time` is |
| 13190 | /// earlier than the last-grab time of the most recent active grab for this client |
| 13191 | /// or if `time` is later than the current X server time. |
| 13192 | /// |
| 13193 | /// # Fields |
| 13194 | /// |
| 13195 | /// * `mode` - |
| 13196 | /// * `time` - Timestamp to avoid race conditions when running X over the network. |
| 13197 | /// |
| 13198 | /// The special value `XCB_CURRENT_TIME` will be replaced with the current server |
| 13199 | /// time. |
| 13200 | /// |
| 13201 | /// # Errors |
| 13202 | /// |
| 13203 | /// * `Value` - You specified an invalid `mode`. |
| 13204 | #[derive (Clone, Copy, Default)] |
| 13205 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 13206 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 13207 | pub struct AllowEventsRequest { |
| 13208 | pub mode: Allow, |
| 13209 | pub time: Timestamp, |
| 13210 | } |
| 13211 | impl_debug_if_no_extra_traits!(AllowEventsRequest, "AllowEventsRequest" ); |
| 13212 | impl AllowEventsRequest { |
| 13213 | /// Serialize this request into bytes for the provided connection |
| 13214 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 13215 | let length_so_far = 0; |
| 13216 | let mode_bytes = u8::from(self.mode).serialize(); |
| 13217 | let time_bytes = self.time.serialize(); |
| 13218 | let mut request0 = vec![ |
| 13219 | ALLOW_EVENTS_REQUEST, |
| 13220 | mode_bytes[0], |
| 13221 | 0, |
| 13222 | 0, |
| 13223 | time_bytes[0], |
| 13224 | time_bytes[1], |
| 13225 | time_bytes[2], |
| 13226 | time_bytes[3], |
| 13227 | ]; |
| 13228 | let length_so_far = length_so_far + request0.len(); |
| 13229 | assert_eq!(length_so_far % 4, 0); |
| 13230 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 13231 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 13232 | ([request0.into()], vec![]) |
| 13233 | } |
| 13234 | /// Parse this request given its header, its body, and any fds that go along with it |
| 13235 | #[cfg (feature = "request-parsing" )] |
| 13236 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 13237 | if header.major_opcode != ALLOW_EVENTS_REQUEST { |
| 13238 | return Err(ParseError::InvalidValue); |
| 13239 | } |
| 13240 | let remaining = &[header.minor_opcode]; |
| 13241 | let (mode, remaining) = u8::try_parse(remaining)?; |
| 13242 | let mode = mode.into(); |
| 13243 | let _ = remaining; |
| 13244 | let (time, remaining) = Timestamp::try_parse(value)?; |
| 13245 | let _ = remaining; |
| 13246 | Ok(AllowEventsRequest { |
| 13247 | mode, |
| 13248 | time, |
| 13249 | }) |
| 13250 | } |
| 13251 | } |
| 13252 | impl Request for AllowEventsRequest { |
| 13253 | const EXTENSION_NAME: Option<&'static str> = None; |
| 13254 | |
| 13255 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 13256 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 13257 | // Flatten the buffers into a single vector |
| 13258 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 13259 | (buf, fds) |
| 13260 | } |
| 13261 | } |
| 13262 | impl crate::x11_utils::VoidRequest for AllowEventsRequest { |
| 13263 | } |
| 13264 | |
| 13265 | /// Opcode for the GrabServer request |
| 13266 | pub const GRAB_SERVER_REQUEST: u8 = 36; |
| 13267 | #[derive (Clone, Copy, Default)] |
| 13268 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 13269 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 13270 | pub struct GrabServerRequest; |
| 13271 | impl_debug_if_no_extra_traits!(GrabServerRequest, "GrabServerRequest" ); |
| 13272 | impl GrabServerRequest { |
| 13273 | /// Serialize this request into bytes for the provided connection |
| 13274 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 13275 | let length_so_far = 0; |
| 13276 | let mut request0 = vec![ |
| 13277 | GRAB_SERVER_REQUEST, |
| 13278 | 0, |
| 13279 | 0, |
| 13280 | 0, |
| 13281 | ]; |
| 13282 | let length_so_far = length_so_far + request0.len(); |
| 13283 | assert_eq!(length_so_far % 4, 0); |
| 13284 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 13285 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 13286 | ([request0.into()], vec![]) |
| 13287 | } |
| 13288 | /// Parse this request given its header, its body, and any fds that go along with it |
| 13289 | #[cfg (feature = "request-parsing" )] |
| 13290 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 13291 | if header.major_opcode != GRAB_SERVER_REQUEST { |
| 13292 | return Err(ParseError::InvalidValue); |
| 13293 | } |
| 13294 | let remaining = &[header.minor_opcode]; |
| 13295 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 13296 | let _ = remaining; |
| 13297 | let _ = value; |
| 13298 | Ok(GrabServerRequest |
| 13299 | ) |
| 13300 | } |
| 13301 | } |
| 13302 | impl Request for GrabServerRequest { |
| 13303 | const EXTENSION_NAME: Option<&'static str> = None; |
| 13304 | |
| 13305 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 13306 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 13307 | // Flatten the buffers into a single vector |
| 13308 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 13309 | (buf, fds) |
| 13310 | } |
| 13311 | } |
| 13312 | impl crate::x11_utils::VoidRequest for GrabServerRequest { |
| 13313 | } |
| 13314 | |
| 13315 | /// Opcode for the UngrabServer request |
| 13316 | pub const UNGRAB_SERVER_REQUEST: u8 = 37; |
| 13317 | #[derive (Clone, Copy, Default)] |
| 13318 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 13319 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 13320 | pub struct UngrabServerRequest; |
| 13321 | impl_debug_if_no_extra_traits!(UngrabServerRequest, "UngrabServerRequest" ); |
| 13322 | impl UngrabServerRequest { |
| 13323 | /// Serialize this request into bytes for the provided connection |
| 13324 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 13325 | let length_so_far = 0; |
| 13326 | let mut request0 = vec![ |
| 13327 | UNGRAB_SERVER_REQUEST, |
| 13328 | 0, |
| 13329 | 0, |
| 13330 | 0, |
| 13331 | ]; |
| 13332 | let length_so_far = length_so_far + request0.len(); |
| 13333 | assert_eq!(length_so_far % 4, 0); |
| 13334 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 13335 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 13336 | ([request0.into()], vec![]) |
| 13337 | } |
| 13338 | /// Parse this request given its header, its body, and any fds that go along with it |
| 13339 | #[cfg (feature = "request-parsing" )] |
| 13340 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 13341 | if header.major_opcode != UNGRAB_SERVER_REQUEST { |
| 13342 | return Err(ParseError::InvalidValue); |
| 13343 | } |
| 13344 | let remaining = &[header.minor_opcode]; |
| 13345 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 13346 | let _ = remaining; |
| 13347 | let _ = value; |
| 13348 | Ok(UngrabServerRequest |
| 13349 | ) |
| 13350 | } |
| 13351 | } |
| 13352 | impl Request for UngrabServerRequest { |
| 13353 | const EXTENSION_NAME: Option<&'static str> = None; |
| 13354 | |
| 13355 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 13356 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 13357 | // Flatten the buffers into a single vector |
| 13358 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 13359 | (buf, fds) |
| 13360 | } |
| 13361 | } |
| 13362 | impl crate::x11_utils::VoidRequest for UngrabServerRequest { |
| 13363 | } |
| 13364 | |
| 13365 | /// Opcode for the QueryPointer request |
| 13366 | pub const QUERY_POINTER_REQUEST: u8 = 38; |
| 13367 | /// get pointer coordinates. |
| 13368 | /// |
| 13369 | /// Gets the root window the pointer is logically on and the pointer coordinates |
| 13370 | /// relative to the root window's origin. |
| 13371 | /// |
| 13372 | /// # Fields |
| 13373 | /// |
| 13374 | /// * `window` - A window to check if the pointer is on the same screen as `window` (see the |
| 13375 | /// `same_screen` field in the reply). |
| 13376 | /// |
| 13377 | /// # Errors |
| 13378 | /// |
| 13379 | /// * `Window` - The specified `window` does not exist. |
| 13380 | #[derive (Clone, Copy, Default)] |
| 13381 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 13382 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 13383 | pub struct QueryPointerRequest { |
| 13384 | pub window: Window, |
| 13385 | } |
| 13386 | impl_debug_if_no_extra_traits!(QueryPointerRequest, "QueryPointerRequest" ); |
| 13387 | impl QueryPointerRequest { |
| 13388 | /// Serialize this request into bytes for the provided connection |
| 13389 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 13390 | let length_so_far = 0; |
| 13391 | let window_bytes = self.window.serialize(); |
| 13392 | let mut request0 = vec![ |
| 13393 | QUERY_POINTER_REQUEST, |
| 13394 | 0, |
| 13395 | 0, |
| 13396 | 0, |
| 13397 | window_bytes[0], |
| 13398 | window_bytes[1], |
| 13399 | window_bytes[2], |
| 13400 | window_bytes[3], |
| 13401 | ]; |
| 13402 | let length_so_far = length_so_far + request0.len(); |
| 13403 | assert_eq!(length_so_far % 4, 0); |
| 13404 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 13405 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 13406 | ([request0.into()], vec![]) |
| 13407 | } |
| 13408 | /// Parse this request given its header, its body, and any fds that go along with it |
| 13409 | #[cfg (feature = "request-parsing" )] |
| 13410 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 13411 | if header.major_opcode != QUERY_POINTER_REQUEST { |
| 13412 | return Err(ParseError::InvalidValue); |
| 13413 | } |
| 13414 | let remaining = &[header.minor_opcode]; |
| 13415 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 13416 | let _ = remaining; |
| 13417 | let (window, remaining) = Window::try_parse(value)?; |
| 13418 | let _ = remaining; |
| 13419 | Ok(QueryPointerRequest { |
| 13420 | window, |
| 13421 | }) |
| 13422 | } |
| 13423 | } |
| 13424 | impl Request for QueryPointerRequest { |
| 13425 | const EXTENSION_NAME: Option<&'static str> = None; |
| 13426 | |
| 13427 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 13428 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 13429 | // Flatten the buffers into a single vector |
| 13430 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 13431 | (buf, fds) |
| 13432 | } |
| 13433 | } |
| 13434 | impl crate::x11_utils::ReplyRequest for QueryPointerRequest { |
| 13435 | type Reply = QueryPointerReply; |
| 13436 | } |
| 13437 | |
| 13438 | /// # Fields |
| 13439 | /// |
| 13440 | /// * `same_screen` - If `same_screen` is False, then the pointer is not on the same screen as the |
| 13441 | /// argument window, `child` is None, and `win_x` and `win_y` are zero. If |
| 13442 | /// `same_screen` is True, then `win_x` and `win_y` are the pointer coordinates |
| 13443 | /// relative to the argument window's origin, and child is the child containing the |
| 13444 | /// pointer, if any. |
| 13445 | /// * `root` - The root window the pointer is logically on. |
| 13446 | /// * `child` - The child window containing the pointer, if any, if `same_screen` is true. If |
| 13447 | /// `same_screen` is false, `XCB_NONE` is returned. |
| 13448 | /// * `root_x` - The pointer X position, relative to `root`. |
| 13449 | /// * `root_y` - The pointer Y position, relative to `root`. |
| 13450 | /// * `win_x` - The pointer X coordinate, relative to `child`, if `same_screen` is true. Zero |
| 13451 | /// otherwise. |
| 13452 | /// * `win_y` - The pointer Y coordinate, relative to `child`, if `same_screen` is true. Zero |
| 13453 | /// otherwise. |
| 13454 | /// * `mask` - The current logical state of the modifier keys and the buttons. Note that the |
| 13455 | /// logical state of a device (as seen by means of the protocol) may lag the |
| 13456 | /// physical state if device event processing is frozen. |
| 13457 | #[derive (Clone, Copy, Default)] |
| 13458 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 13459 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 13460 | pub struct QueryPointerReply { |
| 13461 | pub same_screen: bool, |
| 13462 | pub sequence: u16, |
| 13463 | pub length: u32, |
| 13464 | pub root: Window, |
| 13465 | pub child: Window, |
| 13466 | pub root_x: i16, |
| 13467 | pub root_y: i16, |
| 13468 | pub win_x: i16, |
| 13469 | pub win_y: i16, |
| 13470 | pub mask: KeyButMask, |
| 13471 | } |
| 13472 | impl_debug_if_no_extra_traits!(QueryPointerReply, "QueryPointerReply" ); |
| 13473 | impl TryParse for QueryPointerReply { |
| 13474 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 13475 | let remaining = initial_value; |
| 13476 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 13477 | let (same_screen, remaining) = bool::try_parse(remaining)?; |
| 13478 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 13479 | let (length, remaining) = u32::try_parse(remaining)?; |
| 13480 | let (root, remaining) = Window::try_parse(remaining)?; |
| 13481 | let (child, remaining) = Window::try_parse(remaining)?; |
| 13482 | let (root_x, remaining) = i16::try_parse(remaining)?; |
| 13483 | let (root_y, remaining) = i16::try_parse(remaining)?; |
| 13484 | let (win_x, remaining) = i16::try_parse(remaining)?; |
| 13485 | let (win_y, remaining) = i16::try_parse(remaining)?; |
| 13486 | let (mask, remaining) = u16::try_parse(remaining)?; |
| 13487 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 13488 | if response_type != 1 { |
| 13489 | return Err(ParseError::InvalidValue); |
| 13490 | } |
| 13491 | let mask = mask.into(); |
| 13492 | let result = QueryPointerReply { same_screen, sequence, length, root, child, root_x, root_y, win_x, win_y, mask }; |
| 13493 | let _ = remaining; |
| 13494 | let remaining = initial_value.get(32 + length as usize * 4..) |
| 13495 | .ok_or(ParseError::InsufficientData)?; |
| 13496 | Ok((result, remaining)) |
| 13497 | } |
| 13498 | } |
| 13499 | impl Serialize for QueryPointerReply { |
| 13500 | type Bytes = [u8; 28]; |
| 13501 | fn serialize(&self) -> [u8; 28] { |
| 13502 | let response_type_bytes = &[1]; |
| 13503 | let same_screen_bytes = self.same_screen.serialize(); |
| 13504 | let sequence_bytes = self.sequence.serialize(); |
| 13505 | let length_bytes = self.length.serialize(); |
| 13506 | let root_bytes = self.root.serialize(); |
| 13507 | let child_bytes = self.child.serialize(); |
| 13508 | let root_x_bytes = self.root_x.serialize(); |
| 13509 | let root_y_bytes = self.root_y.serialize(); |
| 13510 | let win_x_bytes = self.win_x.serialize(); |
| 13511 | let win_y_bytes = self.win_y.serialize(); |
| 13512 | let mask_bytes = u16::from(self.mask).serialize(); |
| 13513 | [ |
| 13514 | response_type_bytes[0], |
| 13515 | same_screen_bytes[0], |
| 13516 | sequence_bytes[0], |
| 13517 | sequence_bytes[1], |
| 13518 | length_bytes[0], |
| 13519 | length_bytes[1], |
| 13520 | length_bytes[2], |
| 13521 | length_bytes[3], |
| 13522 | root_bytes[0], |
| 13523 | root_bytes[1], |
| 13524 | root_bytes[2], |
| 13525 | root_bytes[3], |
| 13526 | child_bytes[0], |
| 13527 | child_bytes[1], |
| 13528 | child_bytes[2], |
| 13529 | child_bytes[3], |
| 13530 | root_x_bytes[0], |
| 13531 | root_x_bytes[1], |
| 13532 | root_y_bytes[0], |
| 13533 | root_y_bytes[1], |
| 13534 | win_x_bytes[0], |
| 13535 | win_x_bytes[1], |
| 13536 | win_y_bytes[0], |
| 13537 | win_y_bytes[1], |
| 13538 | mask_bytes[0], |
| 13539 | mask_bytes[1], |
| 13540 | 0, |
| 13541 | 0, |
| 13542 | ] |
| 13543 | } |
| 13544 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 13545 | bytes.reserve(28); |
| 13546 | let response_type_bytes = &[1]; |
| 13547 | bytes.push(response_type_bytes[0]); |
| 13548 | self.same_screen.serialize_into(bytes); |
| 13549 | self.sequence.serialize_into(bytes); |
| 13550 | self.length.serialize_into(bytes); |
| 13551 | self.root.serialize_into(bytes); |
| 13552 | self.child.serialize_into(bytes); |
| 13553 | self.root_x.serialize_into(bytes); |
| 13554 | self.root_y.serialize_into(bytes); |
| 13555 | self.win_x.serialize_into(bytes); |
| 13556 | self.win_y.serialize_into(bytes); |
| 13557 | u16::from(self.mask).serialize_into(bytes); |
| 13558 | bytes.extend_from_slice(&[0; 2]); |
| 13559 | } |
| 13560 | } |
| 13561 | |
| 13562 | #[derive (Clone, Copy, Default)] |
| 13563 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 13564 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 13565 | pub struct Timecoord { |
| 13566 | pub time: Timestamp, |
| 13567 | pub x: i16, |
| 13568 | pub y: i16, |
| 13569 | } |
| 13570 | impl_debug_if_no_extra_traits!(Timecoord, "Timecoord" ); |
| 13571 | impl TryParse for Timecoord { |
| 13572 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 13573 | let (time: u32, remaining: &[u8]) = Timestamp::try_parse(remaining)?; |
| 13574 | let (x: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 13575 | let (y: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 13576 | let result: Timecoord = Timecoord { time, x, y }; |
| 13577 | Ok((result, remaining)) |
| 13578 | } |
| 13579 | } |
| 13580 | impl Serialize for Timecoord { |
| 13581 | type Bytes = [u8; 8]; |
| 13582 | fn serialize(&self) -> [u8; 8] { |
| 13583 | let time_bytes: [u8; 4] = self.time.serialize(); |
| 13584 | let x_bytes: [u8; 2] = self.x.serialize(); |
| 13585 | let y_bytes: [u8; 2] = self.y.serialize(); |
| 13586 | [ |
| 13587 | time_bytes[0], |
| 13588 | time_bytes[1], |
| 13589 | time_bytes[2], |
| 13590 | time_bytes[3], |
| 13591 | x_bytes[0], |
| 13592 | x_bytes[1], |
| 13593 | y_bytes[0], |
| 13594 | y_bytes[1], |
| 13595 | ] |
| 13596 | } |
| 13597 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 13598 | bytes.reserve(additional:8); |
| 13599 | self.time.serialize_into(bytes); |
| 13600 | self.x.serialize_into(bytes); |
| 13601 | self.y.serialize_into(bytes); |
| 13602 | } |
| 13603 | } |
| 13604 | |
| 13605 | /// Opcode for the GetMotionEvents request |
| 13606 | pub const GET_MOTION_EVENTS_REQUEST: u8 = 39; |
| 13607 | #[derive (Clone, Copy, Default)] |
| 13608 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 13609 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 13610 | pub struct GetMotionEventsRequest { |
| 13611 | pub window: Window, |
| 13612 | pub start: Timestamp, |
| 13613 | pub stop: Timestamp, |
| 13614 | } |
| 13615 | impl_debug_if_no_extra_traits!(GetMotionEventsRequest, "GetMotionEventsRequest" ); |
| 13616 | impl GetMotionEventsRequest { |
| 13617 | /// Serialize this request into bytes for the provided connection |
| 13618 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 13619 | let length_so_far = 0; |
| 13620 | let window_bytes = self.window.serialize(); |
| 13621 | let start_bytes = self.start.serialize(); |
| 13622 | let stop_bytes = self.stop.serialize(); |
| 13623 | let mut request0 = vec![ |
| 13624 | GET_MOTION_EVENTS_REQUEST, |
| 13625 | 0, |
| 13626 | 0, |
| 13627 | 0, |
| 13628 | window_bytes[0], |
| 13629 | window_bytes[1], |
| 13630 | window_bytes[2], |
| 13631 | window_bytes[3], |
| 13632 | start_bytes[0], |
| 13633 | start_bytes[1], |
| 13634 | start_bytes[2], |
| 13635 | start_bytes[3], |
| 13636 | stop_bytes[0], |
| 13637 | stop_bytes[1], |
| 13638 | stop_bytes[2], |
| 13639 | stop_bytes[3], |
| 13640 | ]; |
| 13641 | let length_so_far = length_so_far + request0.len(); |
| 13642 | assert_eq!(length_so_far % 4, 0); |
| 13643 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 13644 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 13645 | ([request0.into()], vec![]) |
| 13646 | } |
| 13647 | /// Parse this request given its header, its body, and any fds that go along with it |
| 13648 | #[cfg (feature = "request-parsing" )] |
| 13649 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 13650 | if header.major_opcode != GET_MOTION_EVENTS_REQUEST { |
| 13651 | return Err(ParseError::InvalidValue); |
| 13652 | } |
| 13653 | let remaining = &[header.minor_opcode]; |
| 13654 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 13655 | let _ = remaining; |
| 13656 | let (window, remaining) = Window::try_parse(value)?; |
| 13657 | let (start, remaining) = Timestamp::try_parse(remaining)?; |
| 13658 | let (stop, remaining) = Timestamp::try_parse(remaining)?; |
| 13659 | let _ = remaining; |
| 13660 | Ok(GetMotionEventsRequest { |
| 13661 | window, |
| 13662 | start, |
| 13663 | stop, |
| 13664 | }) |
| 13665 | } |
| 13666 | } |
| 13667 | impl Request for GetMotionEventsRequest { |
| 13668 | const EXTENSION_NAME: Option<&'static str> = None; |
| 13669 | |
| 13670 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 13671 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 13672 | // Flatten the buffers into a single vector |
| 13673 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 13674 | (buf, fds) |
| 13675 | } |
| 13676 | } |
| 13677 | impl crate::x11_utils::ReplyRequest for GetMotionEventsRequest { |
| 13678 | type Reply = GetMotionEventsReply; |
| 13679 | } |
| 13680 | |
| 13681 | #[derive (Clone, Default)] |
| 13682 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 13683 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 13684 | pub struct GetMotionEventsReply { |
| 13685 | pub sequence: u16, |
| 13686 | pub length: u32, |
| 13687 | pub events: Vec<Timecoord>, |
| 13688 | } |
| 13689 | impl_debug_if_no_extra_traits!(GetMotionEventsReply, "GetMotionEventsReply" ); |
| 13690 | impl TryParse for GetMotionEventsReply { |
| 13691 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 13692 | let remaining: &[u8] = initial_value; |
| 13693 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 13694 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 13695 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 13696 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 13697 | let (events_len: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 13698 | let remaining: &[u8] = remaining.get(20..).ok_or(err:ParseError::InsufficientData)?; |
| 13699 | let (events: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<Timecoord>(data:remaining, list_length:events_len.try_to_usize()?)?; |
| 13700 | if response_type != 1 { |
| 13701 | return Err(ParseError::InvalidValue); |
| 13702 | } |
| 13703 | let result: GetMotionEventsReply = GetMotionEventsReply { sequence, length, events }; |
| 13704 | let _ = remaining; |
| 13705 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 13706 | .ok_or(err:ParseError::InsufficientData)?; |
| 13707 | Ok((result, remaining)) |
| 13708 | } |
| 13709 | } |
| 13710 | impl Serialize for GetMotionEventsReply { |
| 13711 | type Bytes = Vec<u8>; |
| 13712 | fn serialize(&self) -> Vec<u8> { |
| 13713 | let mut result: Vec = Vec::new(); |
| 13714 | self.serialize_into(&mut result); |
| 13715 | result |
| 13716 | } |
| 13717 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 13718 | bytes.reserve(additional:32); |
| 13719 | let response_type_bytes: &[u8; 1] = &[1]; |
| 13720 | bytes.push(response_type_bytes[0]); |
| 13721 | bytes.extend_from_slice(&[0; 1]); |
| 13722 | self.sequence.serialize_into(bytes); |
| 13723 | self.length.serialize_into(bytes); |
| 13724 | let events_len: u32 = u32::try_from(self.events.len()).expect(msg:"`events` has too many elements" ); |
| 13725 | events_len.serialize_into(bytes); |
| 13726 | bytes.extend_from_slice(&[0; 20]); |
| 13727 | self.events.serialize_into(bytes); |
| 13728 | } |
| 13729 | } |
| 13730 | impl GetMotionEventsReply { |
| 13731 | /// Get the value of the `events_len` field. |
| 13732 | /// |
| 13733 | /// The `events_len` field is used as the length field of the `events` field. |
| 13734 | /// This function computes the field's value again based on the length of the list. |
| 13735 | /// |
| 13736 | /// # Panics |
| 13737 | /// |
| 13738 | /// Panics if the value cannot be represented in the target type. This |
| 13739 | /// cannot happen with values of the struct received from the X11 server. |
| 13740 | pub fn events_len(&self) -> u32 { |
| 13741 | self.events.len() |
| 13742 | .try_into().unwrap() |
| 13743 | } |
| 13744 | } |
| 13745 | |
| 13746 | /// Opcode for the TranslateCoordinates request |
| 13747 | pub const TRANSLATE_COORDINATES_REQUEST: u8 = 40; |
| 13748 | #[derive (Clone, Copy, Default)] |
| 13749 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 13750 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 13751 | pub struct TranslateCoordinatesRequest { |
| 13752 | pub src_window: Window, |
| 13753 | pub dst_window: Window, |
| 13754 | pub src_x: i16, |
| 13755 | pub src_y: i16, |
| 13756 | } |
| 13757 | impl_debug_if_no_extra_traits!(TranslateCoordinatesRequest, "TranslateCoordinatesRequest" ); |
| 13758 | impl TranslateCoordinatesRequest { |
| 13759 | /// Serialize this request into bytes for the provided connection |
| 13760 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 13761 | let length_so_far = 0; |
| 13762 | let src_window_bytes = self.src_window.serialize(); |
| 13763 | let dst_window_bytes = self.dst_window.serialize(); |
| 13764 | let src_x_bytes = self.src_x.serialize(); |
| 13765 | let src_y_bytes = self.src_y.serialize(); |
| 13766 | let mut request0 = vec![ |
| 13767 | TRANSLATE_COORDINATES_REQUEST, |
| 13768 | 0, |
| 13769 | 0, |
| 13770 | 0, |
| 13771 | src_window_bytes[0], |
| 13772 | src_window_bytes[1], |
| 13773 | src_window_bytes[2], |
| 13774 | src_window_bytes[3], |
| 13775 | dst_window_bytes[0], |
| 13776 | dst_window_bytes[1], |
| 13777 | dst_window_bytes[2], |
| 13778 | dst_window_bytes[3], |
| 13779 | src_x_bytes[0], |
| 13780 | src_x_bytes[1], |
| 13781 | src_y_bytes[0], |
| 13782 | src_y_bytes[1], |
| 13783 | ]; |
| 13784 | let length_so_far = length_so_far + request0.len(); |
| 13785 | assert_eq!(length_so_far % 4, 0); |
| 13786 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 13787 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 13788 | ([request0.into()], vec![]) |
| 13789 | } |
| 13790 | /// Parse this request given its header, its body, and any fds that go along with it |
| 13791 | #[cfg (feature = "request-parsing" )] |
| 13792 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 13793 | if header.major_opcode != TRANSLATE_COORDINATES_REQUEST { |
| 13794 | return Err(ParseError::InvalidValue); |
| 13795 | } |
| 13796 | let remaining = &[header.minor_opcode]; |
| 13797 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 13798 | let _ = remaining; |
| 13799 | let (src_window, remaining) = Window::try_parse(value)?; |
| 13800 | let (dst_window, remaining) = Window::try_parse(remaining)?; |
| 13801 | let (src_x, remaining) = i16::try_parse(remaining)?; |
| 13802 | let (src_y, remaining) = i16::try_parse(remaining)?; |
| 13803 | let _ = remaining; |
| 13804 | Ok(TranslateCoordinatesRequest { |
| 13805 | src_window, |
| 13806 | dst_window, |
| 13807 | src_x, |
| 13808 | src_y, |
| 13809 | }) |
| 13810 | } |
| 13811 | } |
| 13812 | impl Request for TranslateCoordinatesRequest { |
| 13813 | const EXTENSION_NAME: Option<&'static str> = None; |
| 13814 | |
| 13815 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 13816 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 13817 | // Flatten the buffers into a single vector |
| 13818 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 13819 | (buf, fds) |
| 13820 | } |
| 13821 | } |
| 13822 | impl crate::x11_utils::ReplyRequest for TranslateCoordinatesRequest { |
| 13823 | type Reply = TranslateCoordinatesReply; |
| 13824 | } |
| 13825 | |
| 13826 | #[derive (Clone, Copy, Default)] |
| 13827 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 13828 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 13829 | pub struct TranslateCoordinatesReply { |
| 13830 | pub same_screen: bool, |
| 13831 | pub sequence: u16, |
| 13832 | pub length: u32, |
| 13833 | pub child: Window, |
| 13834 | pub dst_x: i16, |
| 13835 | pub dst_y: i16, |
| 13836 | } |
| 13837 | impl_debug_if_no_extra_traits!(TranslateCoordinatesReply, "TranslateCoordinatesReply" ); |
| 13838 | impl TryParse for TranslateCoordinatesReply { |
| 13839 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 13840 | let remaining: &[u8] = initial_value; |
| 13841 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 13842 | let (same_screen: bool, remaining: &[u8]) = bool::try_parse(remaining)?; |
| 13843 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 13844 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 13845 | let (child: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 13846 | let (dst_x: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 13847 | let (dst_y: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 13848 | if response_type != 1 { |
| 13849 | return Err(ParseError::InvalidValue); |
| 13850 | } |
| 13851 | let result: TranslateCoordinatesReply = TranslateCoordinatesReply { same_screen, sequence, length, child, dst_x, dst_y }; |
| 13852 | let _ = remaining; |
| 13853 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 13854 | .ok_or(err:ParseError::InsufficientData)?; |
| 13855 | Ok((result, remaining)) |
| 13856 | } |
| 13857 | } |
| 13858 | impl Serialize for TranslateCoordinatesReply { |
| 13859 | type Bytes = [u8; 16]; |
| 13860 | fn serialize(&self) -> [u8; 16] { |
| 13861 | let response_type_bytes = &[1]; |
| 13862 | let same_screen_bytes = self.same_screen.serialize(); |
| 13863 | let sequence_bytes = self.sequence.serialize(); |
| 13864 | let length_bytes = self.length.serialize(); |
| 13865 | let child_bytes = self.child.serialize(); |
| 13866 | let dst_x_bytes = self.dst_x.serialize(); |
| 13867 | let dst_y_bytes = self.dst_y.serialize(); |
| 13868 | [ |
| 13869 | response_type_bytes[0], |
| 13870 | same_screen_bytes[0], |
| 13871 | sequence_bytes[0], |
| 13872 | sequence_bytes[1], |
| 13873 | length_bytes[0], |
| 13874 | length_bytes[1], |
| 13875 | length_bytes[2], |
| 13876 | length_bytes[3], |
| 13877 | child_bytes[0], |
| 13878 | child_bytes[1], |
| 13879 | child_bytes[2], |
| 13880 | child_bytes[3], |
| 13881 | dst_x_bytes[0], |
| 13882 | dst_x_bytes[1], |
| 13883 | dst_y_bytes[0], |
| 13884 | dst_y_bytes[1], |
| 13885 | ] |
| 13886 | } |
| 13887 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 13888 | bytes.reserve(16); |
| 13889 | let response_type_bytes = &[1]; |
| 13890 | bytes.push(response_type_bytes[0]); |
| 13891 | self.same_screen.serialize_into(bytes); |
| 13892 | self.sequence.serialize_into(bytes); |
| 13893 | self.length.serialize_into(bytes); |
| 13894 | self.child.serialize_into(bytes); |
| 13895 | self.dst_x.serialize_into(bytes); |
| 13896 | self.dst_y.serialize_into(bytes); |
| 13897 | } |
| 13898 | } |
| 13899 | |
| 13900 | /// Opcode for the WarpPointer request |
| 13901 | pub const WARP_POINTER_REQUEST: u8 = 41; |
| 13902 | /// move mouse pointer. |
| 13903 | /// |
| 13904 | /// Moves the mouse pointer to the specified position. |
| 13905 | /// |
| 13906 | /// If `src_window` is not `XCB_NONE` (TODO), the move will only take place if the |
| 13907 | /// pointer is inside `src_window` and within the rectangle specified by (`src_x`, |
| 13908 | /// `src_y`, `src_width`, `src_height`). The rectangle coordinates are relative to |
| 13909 | /// `src_window`. |
| 13910 | /// |
| 13911 | /// If `dst_window` is not `XCB_NONE` (TODO), the pointer will be moved to the |
| 13912 | /// offsets (`dst_x`, `dst_y`) relative to `dst_window`. If `dst_window` is |
| 13913 | /// `XCB_NONE` (TODO), the pointer will be moved by the offsets (`dst_x`, `dst_y`) |
| 13914 | /// relative to the current position of the pointer. |
| 13915 | /// |
| 13916 | /// # Fields |
| 13917 | /// |
| 13918 | /// * `src_window` - If `src_window` is not `XCB_NONE` (TODO), the move will only take place if the |
| 13919 | /// pointer is inside `src_window` and within the rectangle specified by (`src_x`, |
| 13920 | /// `src_y`, `src_width`, `src_height`). The rectangle coordinates are relative to |
| 13921 | /// `src_window`. |
| 13922 | /// * `dst_window` - If `dst_window` is not `XCB_NONE` (TODO), the pointer will be moved to the |
| 13923 | /// offsets (`dst_x`, `dst_y`) relative to `dst_window`. If `dst_window` is |
| 13924 | /// `XCB_NONE` (TODO), the pointer will be moved by the offsets (`dst_x`, `dst_y`) |
| 13925 | /// relative to the current position of the pointer. |
| 13926 | /// |
| 13927 | /// # Errors |
| 13928 | /// |
| 13929 | /// * `Window` - TODO: reasons? |
| 13930 | /// |
| 13931 | /// # See |
| 13932 | /// |
| 13933 | /// * `SetInputFocus`: request |
| 13934 | #[derive (Clone, Copy, Default)] |
| 13935 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 13936 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 13937 | pub struct WarpPointerRequest { |
| 13938 | pub src_window: Window, |
| 13939 | pub dst_window: Window, |
| 13940 | pub src_x: i16, |
| 13941 | pub src_y: i16, |
| 13942 | pub src_width: u16, |
| 13943 | pub src_height: u16, |
| 13944 | pub dst_x: i16, |
| 13945 | pub dst_y: i16, |
| 13946 | } |
| 13947 | impl_debug_if_no_extra_traits!(WarpPointerRequest, "WarpPointerRequest" ); |
| 13948 | impl WarpPointerRequest { |
| 13949 | /// Serialize this request into bytes for the provided connection |
| 13950 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 13951 | let length_so_far = 0; |
| 13952 | let src_window_bytes = self.src_window.serialize(); |
| 13953 | let dst_window_bytes = self.dst_window.serialize(); |
| 13954 | let src_x_bytes = self.src_x.serialize(); |
| 13955 | let src_y_bytes = self.src_y.serialize(); |
| 13956 | let src_width_bytes = self.src_width.serialize(); |
| 13957 | let src_height_bytes = self.src_height.serialize(); |
| 13958 | let dst_x_bytes = self.dst_x.serialize(); |
| 13959 | let dst_y_bytes = self.dst_y.serialize(); |
| 13960 | let mut request0 = vec![ |
| 13961 | WARP_POINTER_REQUEST, |
| 13962 | 0, |
| 13963 | 0, |
| 13964 | 0, |
| 13965 | src_window_bytes[0], |
| 13966 | src_window_bytes[1], |
| 13967 | src_window_bytes[2], |
| 13968 | src_window_bytes[3], |
| 13969 | dst_window_bytes[0], |
| 13970 | dst_window_bytes[1], |
| 13971 | dst_window_bytes[2], |
| 13972 | dst_window_bytes[3], |
| 13973 | src_x_bytes[0], |
| 13974 | src_x_bytes[1], |
| 13975 | src_y_bytes[0], |
| 13976 | src_y_bytes[1], |
| 13977 | src_width_bytes[0], |
| 13978 | src_width_bytes[1], |
| 13979 | src_height_bytes[0], |
| 13980 | src_height_bytes[1], |
| 13981 | dst_x_bytes[0], |
| 13982 | dst_x_bytes[1], |
| 13983 | dst_y_bytes[0], |
| 13984 | dst_y_bytes[1], |
| 13985 | ]; |
| 13986 | let length_so_far = length_so_far + request0.len(); |
| 13987 | assert_eq!(length_so_far % 4, 0); |
| 13988 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 13989 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 13990 | ([request0.into()], vec![]) |
| 13991 | } |
| 13992 | /// Parse this request given its header, its body, and any fds that go along with it |
| 13993 | #[cfg (feature = "request-parsing" )] |
| 13994 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 13995 | if header.major_opcode != WARP_POINTER_REQUEST { |
| 13996 | return Err(ParseError::InvalidValue); |
| 13997 | } |
| 13998 | let remaining = &[header.minor_opcode]; |
| 13999 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 14000 | let _ = remaining; |
| 14001 | let (src_window, remaining) = Window::try_parse(value)?; |
| 14002 | let (dst_window, remaining) = Window::try_parse(remaining)?; |
| 14003 | let (src_x, remaining) = i16::try_parse(remaining)?; |
| 14004 | let (src_y, remaining) = i16::try_parse(remaining)?; |
| 14005 | let (src_width, remaining) = u16::try_parse(remaining)?; |
| 14006 | let (src_height, remaining) = u16::try_parse(remaining)?; |
| 14007 | let (dst_x, remaining) = i16::try_parse(remaining)?; |
| 14008 | let (dst_y, remaining) = i16::try_parse(remaining)?; |
| 14009 | let _ = remaining; |
| 14010 | Ok(WarpPointerRequest { |
| 14011 | src_window, |
| 14012 | dst_window, |
| 14013 | src_x, |
| 14014 | src_y, |
| 14015 | src_width, |
| 14016 | src_height, |
| 14017 | dst_x, |
| 14018 | dst_y, |
| 14019 | }) |
| 14020 | } |
| 14021 | } |
| 14022 | impl Request for WarpPointerRequest { |
| 14023 | const EXTENSION_NAME: Option<&'static str> = None; |
| 14024 | |
| 14025 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 14026 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 14027 | // Flatten the buffers into a single vector |
| 14028 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 14029 | (buf, fds) |
| 14030 | } |
| 14031 | } |
| 14032 | impl crate::x11_utils::VoidRequest for WarpPointerRequest { |
| 14033 | } |
| 14034 | |
| 14035 | /// # Fields |
| 14036 | /// |
| 14037 | /// * `None` - The focus reverts to `XCB_NONE`, so no window will have the input focus. |
| 14038 | /// * `PointerRoot` - The focus reverts to `XCB_POINTER_ROOT` respectively. When the focus reverts, |
| 14039 | /// FocusIn and FocusOut events are generated, but the last-focus-change time is |
| 14040 | /// not changed. |
| 14041 | /// * `Parent` - The focus reverts to the parent (or closest viewable ancestor) and the new |
| 14042 | /// revert_to value is `XCB_INPUT_FOCUS_NONE`. |
| 14043 | /// * `FollowKeyboard` - NOT YET DOCUMENTED. Only relevant for the xinput extension. |
| 14044 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 14045 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 14046 | pub struct InputFocus(u8); |
| 14047 | impl InputFocus { |
| 14048 | pub const NONE: Self = Self(0); |
| 14049 | pub const POINTER_ROOT: Self = Self(1); |
| 14050 | pub const PARENT: Self = Self(2); |
| 14051 | pub const FOLLOW_KEYBOARD: Self = Self(3); |
| 14052 | } |
| 14053 | impl From<InputFocus> for u8 { |
| 14054 | #[inline ] |
| 14055 | fn from(input: InputFocus) -> Self { |
| 14056 | input.0 |
| 14057 | } |
| 14058 | } |
| 14059 | impl From<InputFocus> for Option<u8> { |
| 14060 | #[inline ] |
| 14061 | fn from(input: InputFocus) -> Self { |
| 14062 | Some(input.0) |
| 14063 | } |
| 14064 | } |
| 14065 | impl From<InputFocus> for u16 { |
| 14066 | #[inline ] |
| 14067 | fn from(input: InputFocus) -> Self { |
| 14068 | u16::from(input.0) |
| 14069 | } |
| 14070 | } |
| 14071 | impl From<InputFocus> for Option<u16> { |
| 14072 | #[inline ] |
| 14073 | fn from(input: InputFocus) -> Self { |
| 14074 | Some(u16::from(input.0)) |
| 14075 | } |
| 14076 | } |
| 14077 | impl From<InputFocus> for u32 { |
| 14078 | #[inline ] |
| 14079 | fn from(input: InputFocus) -> Self { |
| 14080 | u32::from(input.0) |
| 14081 | } |
| 14082 | } |
| 14083 | impl From<InputFocus> for Option<u32> { |
| 14084 | #[inline ] |
| 14085 | fn from(input: InputFocus) -> Self { |
| 14086 | Some(u32::from(input.0)) |
| 14087 | } |
| 14088 | } |
| 14089 | impl From<u8> for InputFocus { |
| 14090 | #[inline ] |
| 14091 | fn from(value: u8) -> Self { |
| 14092 | Self(value) |
| 14093 | } |
| 14094 | } |
| 14095 | impl core::fmt::Debug for InputFocus { |
| 14096 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 14097 | let variants: [(u32, &'static str, &'static …); 4] = [ |
| 14098 | (Self::NONE.0.into(), "NONE" , "None" ), |
| 14099 | (Self::POINTER_ROOT.0.into(), "POINTER_ROOT" , "PointerRoot" ), |
| 14100 | (Self::PARENT.0.into(), "PARENT" , "Parent" ), |
| 14101 | (Self::FOLLOW_KEYBOARD.0.into(), "FOLLOW_KEYBOARD" , "FollowKeyboard" ), |
| 14102 | ]; |
| 14103 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 14104 | } |
| 14105 | } |
| 14106 | |
| 14107 | /// Opcode for the SetInputFocus request |
| 14108 | pub const SET_INPUT_FOCUS_REQUEST: u8 = 42; |
| 14109 | /// Sets input focus. |
| 14110 | /// |
| 14111 | /// Changes the input focus and the last-focus-change time. If the specified `time` |
| 14112 | /// is earlier than the current last-focus-change time, the request is ignored (to |
| 14113 | /// avoid race conditions when running X over the network). |
| 14114 | /// |
| 14115 | /// A FocusIn and FocusOut event is generated when focus is changed. |
| 14116 | /// |
| 14117 | /// # Fields |
| 14118 | /// |
| 14119 | /// * `focus` - The window to focus. All keyboard events will be reported to this window. The |
| 14120 | /// window must be viewable (TODO), or a `xcb_match_error_t` occurs (TODO). |
| 14121 | /// |
| 14122 | /// If `focus` is `XCB_NONE` (TODO), all keyboard events are |
| 14123 | /// discarded until a new focus window is set. |
| 14124 | /// |
| 14125 | /// If `focus` is `XCB_POINTER_ROOT` (TODO), focus is on the root window of the |
| 14126 | /// screen on which the pointer is on currently. |
| 14127 | /// * `time` - Timestamp to avoid race conditions when running X over the network. |
| 14128 | /// |
| 14129 | /// The special value `XCB_CURRENT_TIME` will be replaced with the current server |
| 14130 | /// time. |
| 14131 | /// * `revert_to` - Specifies what happens when the `focus` window becomes unviewable (if `focus` |
| 14132 | /// is neither `XCB_NONE` nor `XCB_POINTER_ROOT`). |
| 14133 | /// |
| 14134 | /// # Errors |
| 14135 | /// |
| 14136 | /// * `Window` - The specified `focus` window does not exist. |
| 14137 | /// * `Match` - The specified `focus` window is not viewable. |
| 14138 | /// * `Value` - TODO: Reasons? |
| 14139 | /// |
| 14140 | /// # See |
| 14141 | /// |
| 14142 | /// * `FocusIn`: event |
| 14143 | /// * `FocusOut`: event |
| 14144 | #[derive (Clone, Copy, Default)] |
| 14145 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 14146 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 14147 | pub struct SetInputFocusRequest { |
| 14148 | pub revert_to: InputFocus, |
| 14149 | pub focus: Window, |
| 14150 | pub time: Timestamp, |
| 14151 | } |
| 14152 | impl_debug_if_no_extra_traits!(SetInputFocusRequest, "SetInputFocusRequest" ); |
| 14153 | impl SetInputFocusRequest { |
| 14154 | /// Serialize this request into bytes for the provided connection |
| 14155 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 14156 | let length_so_far = 0; |
| 14157 | let revert_to_bytes = u8::from(self.revert_to).serialize(); |
| 14158 | let focus_bytes = self.focus.serialize(); |
| 14159 | let time_bytes = self.time.serialize(); |
| 14160 | let mut request0 = vec![ |
| 14161 | SET_INPUT_FOCUS_REQUEST, |
| 14162 | revert_to_bytes[0], |
| 14163 | 0, |
| 14164 | 0, |
| 14165 | focus_bytes[0], |
| 14166 | focus_bytes[1], |
| 14167 | focus_bytes[2], |
| 14168 | focus_bytes[3], |
| 14169 | time_bytes[0], |
| 14170 | time_bytes[1], |
| 14171 | time_bytes[2], |
| 14172 | time_bytes[3], |
| 14173 | ]; |
| 14174 | let length_so_far = length_so_far + request0.len(); |
| 14175 | assert_eq!(length_so_far % 4, 0); |
| 14176 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 14177 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 14178 | ([request0.into()], vec![]) |
| 14179 | } |
| 14180 | /// Parse this request given its header, its body, and any fds that go along with it |
| 14181 | #[cfg (feature = "request-parsing" )] |
| 14182 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 14183 | if header.major_opcode != SET_INPUT_FOCUS_REQUEST { |
| 14184 | return Err(ParseError::InvalidValue); |
| 14185 | } |
| 14186 | let remaining = &[header.minor_opcode]; |
| 14187 | let (revert_to, remaining) = u8::try_parse(remaining)?; |
| 14188 | let revert_to = revert_to.into(); |
| 14189 | let _ = remaining; |
| 14190 | let (focus, remaining) = Window::try_parse(value)?; |
| 14191 | let (time, remaining) = Timestamp::try_parse(remaining)?; |
| 14192 | let _ = remaining; |
| 14193 | Ok(SetInputFocusRequest { |
| 14194 | revert_to, |
| 14195 | focus, |
| 14196 | time, |
| 14197 | }) |
| 14198 | } |
| 14199 | } |
| 14200 | impl Request for SetInputFocusRequest { |
| 14201 | const EXTENSION_NAME: Option<&'static str> = None; |
| 14202 | |
| 14203 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 14204 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 14205 | // Flatten the buffers into a single vector |
| 14206 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 14207 | (buf, fds) |
| 14208 | } |
| 14209 | } |
| 14210 | impl crate::x11_utils::VoidRequest for SetInputFocusRequest { |
| 14211 | } |
| 14212 | |
| 14213 | /// Opcode for the GetInputFocus request |
| 14214 | pub const GET_INPUT_FOCUS_REQUEST: u8 = 43; |
| 14215 | #[derive (Clone, Copy, Default)] |
| 14216 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 14217 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 14218 | pub struct GetInputFocusRequest; |
| 14219 | impl_debug_if_no_extra_traits!(GetInputFocusRequest, "GetInputFocusRequest" ); |
| 14220 | impl GetInputFocusRequest { |
| 14221 | /// Serialize this request into bytes for the provided connection |
| 14222 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 14223 | let length_so_far = 0; |
| 14224 | let mut request0 = vec![ |
| 14225 | GET_INPUT_FOCUS_REQUEST, |
| 14226 | 0, |
| 14227 | 0, |
| 14228 | 0, |
| 14229 | ]; |
| 14230 | let length_so_far = length_so_far + request0.len(); |
| 14231 | assert_eq!(length_so_far % 4, 0); |
| 14232 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 14233 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 14234 | ([request0.into()], vec![]) |
| 14235 | } |
| 14236 | /// Parse this request given its header, its body, and any fds that go along with it |
| 14237 | #[cfg (feature = "request-parsing" )] |
| 14238 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 14239 | if header.major_opcode != GET_INPUT_FOCUS_REQUEST { |
| 14240 | return Err(ParseError::InvalidValue); |
| 14241 | } |
| 14242 | let remaining = &[header.minor_opcode]; |
| 14243 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 14244 | let _ = remaining; |
| 14245 | let _ = value; |
| 14246 | Ok(GetInputFocusRequest |
| 14247 | ) |
| 14248 | } |
| 14249 | } |
| 14250 | impl Request for GetInputFocusRequest { |
| 14251 | const EXTENSION_NAME: Option<&'static str> = None; |
| 14252 | |
| 14253 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 14254 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 14255 | // Flatten the buffers into a single vector |
| 14256 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 14257 | (buf, fds) |
| 14258 | } |
| 14259 | } |
| 14260 | impl crate::x11_utils::ReplyRequest for GetInputFocusRequest { |
| 14261 | type Reply = GetInputFocusReply; |
| 14262 | } |
| 14263 | |
| 14264 | #[derive (Clone, Copy, Default)] |
| 14265 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 14266 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 14267 | pub struct GetInputFocusReply { |
| 14268 | pub revert_to: InputFocus, |
| 14269 | pub sequence: u16, |
| 14270 | pub length: u32, |
| 14271 | pub focus: Window, |
| 14272 | } |
| 14273 | impl_debug_if_no_extra_traits!(GetInputFocusReply, "GetInputFocusReply" ); |
| 14274 | impl TryParse for GetInputFocusReply { |
| 14275 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 14276 | let remaining: &[u8] = initial_value; |
| 14277 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 14278 | let (revert_to: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 14279 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 14280 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 14281 | let (focus: u32, remaining: &[u8]) = Window::try_parse(remaining)?; |
| 14282 | if response_type != 1 { |
| 14283 | return Err(ParseError::InvalidValue); |
| 14284 | } |
| 14285 | let revert_to: InputFocus = revert_to.into(); |
| 14286 | let result: GetInputFocusReply = GetInputFocusReply { revert_to, sequence, length, focus }; |
| 14287 | let _ = remaining; |
| 14288 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 14289 | .ok_or(err:ParseError::InsufficientData)?; |
| 14290 | Ok((result, remaining)) |
| 14291 | } |
| 14292 | } |
| 14293 | impl Serialize for GetInputFocusReply { |
| 14294 | type Bytes = [u8; 12]; |
| 14295 | fn serialize(&self) -> [u8; 12] { |
| 14296 | let response_type_bytes = &[1]; |
| 14297 | let revert_to_bytes = u8::from(self.revert_to).serialize(); |
| 14298 | let sequence_bytes = self.sequence.serialize(); |
| 14299 | let length_bytes = self.length.serialize(); |
| 14300 | let focus_bytes = self.focus.serialize(); |
| 14301 | [ |
| 14302 | response_type_bytes[0], |
| 14303 | revert_to_bytes[0], |
| 14304 | sequence_bytes[0], |
| 14305 | sequence_bytes[1], |
| 14306 | length_bytes[0], |
| 14307 | length_bytes[1], |
| 14308 | length_bytes[2], |
| 14309 | length_bytes[3], |
| 14310 | focus_bytes[0], |
| 14311 | focus_bytes[1], |
| 14312 | focus_bytes[2], |
| 14313 | focus_bytes[3], |
| 14314 | ] |
| 14315 | } |
| 14316 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 14317 | bytes.reserve(12); |
| 14318 | let response_type_bytes = &[1]; |
| 14319 | bytes.push(response_type_bytes[0]); |
| 14320 | u8::from(self.revert_to).serialize_into(bytes); |
| 14321 | self.sequence.serialize_into(bytes); |
| 14322 | self.length.serialize_into(bytes); |
| 14323 | self.focus.serialize_into(bytes); |
| 14324 | } |
| 14325 | } |
| 14326 | |
| 14327 | /// Opcode for the QueryKeymap request |
| 14328 | pub const QUERY_KEYMAP_REQUEST: u8 = 44; |
| 14329 | #[derive (Clone, Copy, Default)] |
| 14330 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 14331 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 14332 | pub struct QueryKeymapRequest; |
| 14333 | impl_debug_if_no_extra_traits!(QueryKeymapRequest, "QueryKeymapRequest" ); |
| 14334 | impl QueryKeymapRequest { |
| 14335 | /// Serialize this request into bytes for the provided connection |
| 14336 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 14337 | let length_so_far = 0; |
| 14338 | let mut request0 = vec![ |
| 14339 | QUERY_KEYMAP_REQUEST, |
| 14340 | 0, |
| 14341 | 0, |
| 14342 | 0, |
| 14343 | ]; |
| 14344 | let length_so_far = length_so_far + request0.len(); |
| 14345 | assert_eq!(length_so_far % 4, 0); |
| 14346 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 14347 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 14348 | ([request0.into()], vec![]) |
| 14349 | } |
| 14350 | /// Parse this request given its header, its body, and any fds that go along with it |
| 14351 | #[cfg (feature = "request-parsing" )] |
| 14352 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 14353 | if header.major_opcode != QUERY_KEYMAP_REQUEST { |
| 14354 | return Err(ParseError::InvalidValue); |
| 14355 | } |
| 14356 | let remaining = &[header.minor_opcode]; |
| 14357 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 14358 | let _ = remaining; |
| 14359 | let _ = value; |
| 14360 | Ok(QueryKeymapRequest |
| 14361 | ) |
| 14362 | } |
| 14363 | } |
| 14364 | impl Request for QueryKeymapRequest { |
| 14365 | const EXTENSION_NAME: Option<&'static str> = None; |
| 14366 | |
| 14367 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 14368 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 14369 | // Flatten the buffers into a single vector |
| 14370 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 14371 | (buf, fds) |
| 14372 | } |
| 14373 | } |
| 14374 | impl crate::x11_utils::ReplyRequest for QueryKeymapRequest { |
| 14375 | type Reply = QueryKeymapReply; |
| 14376 | } |
| 14377 | |
| 14378 | #[derive (Clone, Copy, Default)] |
| 14379 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 14380 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 14381 | pub struct QueryKeymapReply { |
| 14382 | pub sequence: u16, |
| 14383 | pub length: u32, |
| 14384 | pub keys: [u8; 32], |
| 14385 | } |
| 14386 | impl_debug_if_no_extra_traits!(QueryKeymapReply, "QueryKeymapReply" ); |
| 14387 | impl TryParse for QueryKeymapReply { |
| 14388 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 14389 | let remaining: &[u8] = initial_value; |
| 14390 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 14391 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 14392 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 14393 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 14394 | let (keys: [u8; 32], remaining: &[u8]) = crate::x11_utils::parse_u8_array::<32>(data:remaining)?; |
| 14395 | if response_type != 1 { |
| 14396 | return Err(ParseError::InvalidValue); |
| 14397 | } |
| 14398 | let result: QueryKeymapReply = QueryKeymapReply { sequence, length, keys }; |
| 14399 | let _ = remaining; |
| 14400 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 14401 | .ok_or(err:ParseError::InsufficientData)?; |
| 14402 | Ok((result, remaining)) |
| 14403 | } |
| 14404 | } |
| 14405 | impl Serialize for QueryKeymapReply { |
| 14406 | type Bytes = [u8; 40]; |
| 14407 | fn serialize(&self) -> [u8; 40] { |
| 14408 | let response_type_bytes = &[1]; |
| 14409 | let sequence_bytes = self.sequence.serialize(); |
| 14410 | let length_bytes = self.length.serialize(); |
| 14411 | [ |
| 14412 | response_type_bytes[0], |
| 14413 | 0, |
| 14414 | sequence_bytes[0], |
| 14415 | sequence_bytes[1], |
| 14416 | length_bytes[0], |
| 14417 | length_bytes[1], |
| 14418 | length_bytes[2], |
| 14419 | length_bytes[3], |
| 14420 | self.keys[0], |
| 14421 | self.keys[1], |
| 14422 | self.keys[2], |
| 14423 | self.keys[3], |
| 14424 | self.keys[4], |
| 14425 | self.keys[5], |
| 14426 | self.keys[6], |
| 14427 | self.keys[7], |
| 14428 | self.keys[8], |
| 14429 | self.keys[9], |
| 14430 | self.keys[10], |
| 14431 | self.keys[11], |
| 14432 | self.keys[12], |
| 14433 | self.keys[13], |
| 14434 | self.keys[14], |
| 14435 | self.keys[15], |
| 14436 | self.keys[16], |
| 14437 | self.keys[17], |
| 14438 | self.keys[18], |
| 14439 | self.keys[19], |
| 14440 | self.keys[20], |
| 14441 | self.keys[21], |
| 14442 | self.keys[22], |
| 14443 | self.keys[23], |
| 14444 | self.keys[24], |
| 14445 | self.keys[25], |
| 14446 | self.keys[26], |
| 14447 | self.keys[27], |
| 14448 | self.keys[28], |
| 14449 | self.keys[29], |
| 14450 | self.keys[30], |
| 14451 | self.keys[31], |
| 14452 | ] |
| 14453 | } |
| 14454 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 14455 | bytes.reserve(40); |
| 14456 | let response_type_bytes = &[1]; |
| 14457 | bytes.push(response_type_bytes[0]); |
| 14458 | bytes.extend_from_slice(&[0; 1]); |
| 14459 | self.sequence.serialize_into(bytes); |
| 14460 | self.length.serialize_into(bytes); |
| 14461 | bytes.extend_from_slice(&self.keys); |
| 14462 | } |
| 14463 | } |
| 14464 | |
| 14465 | /// Opcode for the OpenFont request |
| 14466 | pub const OPEN_FONT_REQUEST: u8 = 45; |
| 14467 | /// opens a font. |
| 14468 | /// |
| 14469 | /// Opens any X core font matching the given `name` (for example "-misc-fixed-*"). |
| 14470 | /// |
| 14471 | /// Note that X core fonts are deprecated (but still supported) in favor of |
| 14472 | /// client-side rendering using Xft. |
| 14473 | /// |
| 14474 | /// # Fields |
| 14475 | /// |
| 14476 | /// * `fid` - The ID with which you will refer to the font, created by `xcb_generate_id`. |
| 14477 | /// * `name` - A pattern describing an X core font. |
| 14478 | /// |
| 14479 | /// # Errors |
| 14480 | /// |
| 14481 | /// * `Name` - No font matches the given `name`. |
| 14482 | /// |
| 14483 | /// # See |
| 14484 | /// |
| 14485 | /// * `xcb_generate_id`: function |
| 14486 | #[derive (Clone, Default)] |
| 14487 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 14488 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 14489 | pub struct OpenFontRequest<'input> { |
| 14490 | pub fid: Font, |
| 14491 | pub name: Cow<'input, [u8]>, |
| 14492 | } |
| 14493 | impl_debug_if_no_extra_traits!(OpenFontRequest<'_>, "OpenFontRequest" ); |
| 14494 | impl<'input> OpenFontRequest<'input> { |
| 14495 | /// Serialize this request into bytes for the provided connection |
| 14496 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 14497 | let length_so_far = 0; |
| 14498 | let fid_bytes = self.fid.serialize(); |
| 14499 | let name_len = u16::try_from(self.name.len()).expect("`name` has too many elements" ); |
| 14500 | let name_len_bytes = name_len.serialize(); |
| 14501 | let mut request0 = vec![ |
| 14502 | OPEN_FONT_REQUEST, |
| 14503 | 0, |
| 14504 | 0, |
| 14505 | 0, |
| 14506 | fid_bytes[0], |
| 14507 | fid_bytes[1], |
| 14508 | fid_bytes[2], |
| 14509 | fid_bytes[3], |
| 14510 | name_len_bytes[0], |
| 14511 | name_len_bytes[1], |
| 14512 | 0, |
| 14513 | 0, |
| 14514 | ]; |
| 14515 | let length_so_far = length_so_far + request0.len(); |
| 14516 | let length_so_far = length_so_far + self.name.len(); |
| 14517 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 14518 | let length_so_far = length_so_far + padding0.len(); |
| 14519 | assert_eq!(length_so_far % 4, 0); |
| 14520 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 14521 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 14522 | ([request0.into(), self.name, padding0.into()], vec![]) |
| 14523 | } |
| 14524 | /// Parse this request given its header, its body, and any fds that go along with it |
| 14525 | #[cfg (feature = "request-parsing" )] |
| 14526 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 14527 | if header.major_opcode != OPEN_FONT_REQUEST { |
| 14528 | return Err(ParseError::InvalidValue); |
| 14529 | } |
| 14530 | let remaining = &[header.minor_opcode]; |
| 14531 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 14532 | let _ = remaining; |
| 14533 | let (fid, remaining) = Font::try_parse(value)?; |
| 14534 | let (name_len, remaining) = u16::try_parse(remaining)?; |
| 14535 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 14536 | let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; |
| 14537 | let _ = remaining; |
| 14538 | Ok(OpenFontRequest { |
| 14539 | fid, |
| 14540 | name: Cow::Borrowed(name), |
| 14541 | }) |
| 14542 | } |
| 14543 | /// Clone all borrowed data in this OpenFontRequest. |
| 14544 | pub fn into_owned(self) -> OpenFontRequest<'static> { |
| 14545 | OpenFontRequest { |
| 14546 | fid: self.fid, |
| 14547 | name: Cow::Owned(self.name.into_owned()), |
| 14548 | } |
| 14549 | } |
| 14550 | } |
| 14551 | impl<'input> Request for OpenFontRequest<'input> { |
| 14552 | const EXTENSION_NAME: Option<&'static str> = None; |
| 14553 | |
| 14554 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 14555 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 14556 | // Flatten the buffers into a single vector |
| 14557 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 14558 | (buf, fds) |
| 14559 | } |
| 14560 | } |
| 14561 | impl<'input> crate::x11_utils::VoidRequest for OpenFontRequest<'input> { |
| 14562 | } |
| 14563 | |
| 14564 | /// Opcode for the CloseFont request |
| 14565 | pub const CLOSE_FONT_REQUEST: u8 = 46; |
| 14566 | #[derive (Clone, Copy, Default)] |
| 14567 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 14568 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 14569 | pub struct CloseFontRequest { |
| 14570 | pub font: Font, |
| 14571 | } |
| 14572 | impl_debug_if_no_extra_traits!(CloseFontRequest, "CloseFontRequest" ); |
| 14573 | impl CloseFontRequest { |
| 14574 | /// Serialize this request into bytes for the provided connection |
| 14575 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 14576 | let length_so_far = 0; |
| 14577 | let font_bytes = self.font.serialize(); |
| 14578 | let mut request0 = vec![ |
| 14579 | CLOSE_FONT_REQUEST, |
| 14580 | 0, |
| 14581 | 0, |
| 14582 | 0, |
| 14583 | font_bytes[0], |
| 14584 | font_bytes[1], |
| 14585 | font_bytes[2], |
| 14586 | font_bytes[3], |
| 14587 | ]; |
| 14588 | let length_so_far = length_so_far + request0.len(); |
| 14589 | assert_eq!(length_so_far % 4, 0); |
| 14590 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 14591 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 14592 | ([request0.into()], vec![]) |
| 14593 | } |
| 14594 | /// Parse this request given its header, its body, and any fds that go along with it |
| 14595 | #[cfg (feature = "request-parsing" )] |
| 14596 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 14597 | if header.major_opcode != CLOSE_FONT_REQUEST { |
| 14598 | return Err(ParseError::InvalidValue); |
| 14599 | } |
| 14600 | let remaining = &[header.minor_opcode]; |
| 14601 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 14602 | let _ = remaining; |
| 14603 | let (font, remaining) = Font::try_parse(value)?; |
| 14604 | let _ = remaining; |
| 14605 | Ok(CloseFontRequest { |
| 14606 | font, |
| 14607 | }) |
| 14608 | } |
| 14609 | } |
| 14610 | impl Request for CloseFontRequest { |
| 14611 | const EXTENSION_NAME: Option<&'static str> = None; |
| 14612 | |
| 14613 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 14614 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 14615 | // Flatten the buffers into a single vector |
| 14616 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 14617 | (buf, fds) |
| 14618 | } |
| 14619 | } |
| 14620 | impl crate::x11_utils::VoidRequest for CloseFontRequest { |
| 14621 | } |
| 14622 | |
| 14623 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 14624 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 14625 | pub struct FontDraw(u8); |
| 14626 | impl FontDraw { |
| 14627 | pub const LEFT_TO_RIGHT: Self = Self(0); |
| 14628 | pub const RIGHT_TO_LEFT: Self = Self(1); |
| 14629 | } |
| 14630 | impl From<FontDraw> for u8 { |
| 14631 | #[inline ] |
| 14632 | fn from(input: FontDraw) -> Self { |
| 14633 | input.0 |
| 14634 | } |
| 14635 | } |
| 14636 | impl From<FontDraw> for Option<u8> { |
| 14637 | #[inline ] |
| 14638 | fn from(input: FontDraw) -> Self { |
| 14639 | Some(input.0) |
| 14640 | } |
| 14641 | } |
| 14642 | impl From<FontDraw> for u16 { |
| 14643 | #[inline ] |
| 14644 | fn from(input: FontDraw) -> Self { |
| 14645 | u16::from(input.0) |
| 14646 | } |
| 14647 | } |
| 14648 | impl From<FontDraw> for Option<u16> { |
| 14649 | #[inline ] |
| 14650 | fn from(input: FontDraw) -> Self { |
| 14651 | Some(u16::from(input.0)) |
| 14652 | } |
| 14653 | } |
| 14654 | impl From<FontDraw> for u32 { |
| 14655 | #[inline ] |
| 14656 | fn from(input: FontDraw) -> Self { |
| 14657 | u32::from(input.0) |
| 14658 | } |
| 14659 | } |
| 14660 | impl From<FontDraw> for Option<u32> { |
| 14661 | #[inline ] |
| 14662 | fn from(input: FontDraw) -> Self { |
| 14663 | Some(u32::from(input.0)) |
| 14664 | } |
| 14665 | } |
| 14666 | impl From<u8> for FontDraw { |
| 14667 | #[inline ] |
| 14668 | fn from(value: u8) -> Self { |
| 14669 | Self(value) |
| 14670 | } |
| 14671 | } |
| 14672 | impl core::fmt::Debug for FontDraw { |
| 14673 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 14674 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 14675 | (Self::LEFT_TO_RIGHT.0.into(), "LEFT_TO_RIGHT" , "LeftToRight" ), |
| 14676 | (Self::RIGHT_TO_LEFT.0.into(), "RIGHT_TO_LEFT" , "RightToLeft" ), |
| 14677 | ]; |
| 14678 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 14679 | } |
| 14680 | } |
| 14681 | |
| 14682 | #[derive (Clone, Copy, Default)] |
| 14683 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 14684 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 14685 | pub struct Fontprop { |
| 14686 | pub name: Atom, |
| 14687 | pub value: u32, |
| 14688 | } |
| 14689 | impl_debug_if_no_extra_traits!(Fontprop, "Fontprop" ); |
| 14690 | impl TryParse for Fontprop { |
| 14691 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 14692 | let (name: u32, remaining: &[u8]) = Atom::try_parse(remaining)?; |
| 14693 | let (value: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 14694 | let result: Fontprop = Fontprop { name, value }; |
| 14695 | Ok((result, remaining)) |
| 14696 | } |
| 14697 | } |
| 14698 | impl Serialize for Fontprop { |
| 14699 | type Bytes = [u8; 8]; |
| 14700 | fn serialize(&self) -> [u8; 8] { |
| 14701 | let name_bytes: [u8; 4] = self.name.serialize(); |
| 14702 | let value_bytes: [u8; 4] = self.value.serialize(); |
| 14703 | [ |
| 14704 | name_bytes[0], |
| 14705 | name_bytes[1], |
| 14706 | name_bytes[2], |
| 14707 | name_bytes[3], |
| 14708 | value_bytes[0], |
| 14709 | value_bytes[1], |
| 14710 | value_bytes[2], |
| 14711 | value_bytes[3], |
| 14712 | ] |
| 14713 | } |
| 14714 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 14715 | bytes.reserve(additional:8); |
| 14716 | self.name.serialize_into(bytes); |
| 14717 | self.value.serialize_into(bytes); |
| 14718 | } |
| 14719 | } |
| 14720 | |
| 14721 | #[derive (Clone, Copy, Default)] |
| 14722 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 14723 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 14724 | pub struct Charinfo { |
| 14725 | pub left_side_bearing: i16, |
| 14726 | pub right_side_bearing: i16, |
| 14727 | pub character_width: i16, |
| 14728 | pub ascent: i16, |
| 14729 | pub descent: i16, |
| 14730 | pub attributes: u16, |
| 14731 | } |
| 14732 | impl_debug_if_no_extra_traits!(Charinfo, "Charinfo" ); |
| 14733 | impl TryParse for Charinfo { |
| 14734 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 14735 | let (left_side_bearing: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 14736 | let (right_side_bearing: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 14737 | let (character_width: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 14738 | let (ascent: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 14739 | let (descent: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 14740 | let (attributes: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 14741 | let result: Charinfo = Charinfo { left_side_bearing, right_side_bearing, character_width, ascent, descent, attributes }; |
| 14742 | Ok((result, remaining)) |
| 14743 | } |
| 14744 | } |
| 14745 | impl Serialize for Charinfo { |
| 14746 | type Bytes = [u8; 12]; |
| 14747 | fn serialize(&self) -> [u8; 12] { |
| 14748 | let left_side_bearing_bytes = self.left_side_bearing.serialize(); |
| 14749 | let right_side_bearing_bytes = self.right_side_bearing.serialize(); |
| 14750 | let character_width_bytes = self.character_width.serialize(); |
| 14751 | let ascent_bytes = self.ascent.serialize(); |
| 14752 | let descent_bytes = self.descent.serialize(); |
| 14753 | let attributes_bytes = self.attributes.serialize(); |
| 14754 | [ |
| 14755 | left_side_bearing_bytes[0], |
| 14756 | left_side_bearing_bytes[1], |
| 14757 | right_side_bearing_bytes[0], |
| 14758 | right_side_bearing_bytes[1], |
| 14759 | character_width_bytes[0], |
| 14760 | character_width_bytes[1], |
| 14761 | ascent_bytes[0], |
| 14762 | ascent_bytes[1], |
| 14763 | descent_bytes[0], |
| 14764 | descent_bytes[1], |
| 14765 | attributes_bytes[0], |
| 14766 | attributes_bytes[1], |
| 14767 | ] |
| 14768 | } |
| 14769 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 14770 | bytes.reserve(12); |
| 14771 | self.left_side_bearing.serialize_into(bytes); |
| 14772 | self.right_side_bearing.serialize_into(bytes); |
| 14773 | self.character_width.serialize_into(bytes); |
| 14774 | self.ascent.serialize_into(bytes); |
| 14775 | self.descent.serialize_into(bytes); |
| 14776 | self.attributes.serialize_into(bytes); |
| 14777 | } |
| 14778 | } |
| 14779 | |
| 14780 | /// Opcode for the QueryFont request |
| 14781 | pub const QUERY_FONT_REQUEST: u8 = 47; |
| 14782 | /// query font metrics. |
| 14783 | /// |
| 14784 | /// Queries information associated with the font. |
| 14785 | /// |
| 14786 | /// # Fields |
| 14787 | /// |
| 14788 | /// * `font` - The fontable (Font or Graphics Context) to query. |
| 14789 | #[derive (Clone, Copy, Default)] |
| 14790 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 14791 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 14792 | pub struct QueryFontRequest { |
| 14793 | pub font: Fontable, |
| 14794 | } |
| 14795 | impl_debug_if_no_extra_traits!(QueryFontRequest, "QueryFontRequest" ); |
| 14796 | impl QueryFontRequest { |
| 14797 | /// Serialize this request into bytes for the provided connection |
| 14798 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 14799 | let length_so_far = 0; |
| 14800 | let font_bytes = self.font.serialize(); |
| 14801 | let mut request0 = vec![ |
| 14802 | QUERY_FONT_REQUEST, |
| 14803 | 0, |
| 14804 | 0, |
| 14805 | 0, |
| 14806 | font_bytes[0], |
| 14807 | font_bytes[1], |
| 14808 | font_bytes[2], |
| 14809 | font_bytes[3], |
| 14810 | ]; |
| 14811 | let length_so_far = length_so_far + request0.len(); |
| 14812 | assert_eq!(length_so_far % 4, 0); |
| 14813 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 14814 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 14815 | ([request0.into()], vec![]) |
| 14816 | } |
| 14817 | /// Parse this request given its header, its body, and any fds that go along with it |
| 14818 | #[cfg (feature = "request-parsing" )] |
| 14819 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 14820 | if header.major_opcode != QUERY_FONT_REQUEST { |
| 14821 | return Err(ParseError::InvalidValue); |
| 14822 | } |
| 14823 | let remaining = &[header.minor_opcode]; |
| 14824 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 14825 | let _ = remaining; |
| 14826 | let (font, remaining) = Fontable::try_parse(value)?; |
| 14827 | let _ = remaining; |
| 14828 | Ok(QueryFontRequest { |
| 14829 | font, |
| 14830 | }) |
| 14831 | } |
| 14832 | } |
| 14833 | impl Request for QueryFontRequest { |
| 14834 | const EXTENSION_NAME: Option<&'static str> = None; |
| 14835 | |
| 14836 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 14837 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 14838 | // Flatten the buffers into a single vector |
| 14839 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 14840 | (buf, fds) |
| 14841 | } |
| 14842 | } |
| 14843 | impl crate::x11_utils::ReplyRequest for QueryFontRequest { |
| 14844 | type Reply = QueryFontReply; |
| 14845 | } |
| 14846 | |
| 14847 | /// # Fields |
| 14848 | /// |
| 14849 | /// * `min_bounds` - minimum bounds over all existing char |
| 14850 | /// * `max_bounds` - maximum bounds over all existing char |
| 14851 | /// * `min_char_or_byte2` - first character |
| 14852 | /// * `max_char_or_byte2` - last character |
| 14853 | /// * `default_char` - char to print for undefined character |
| 14854 | /// * `all_chars_exist` - flag if all characters have nonzero size |
| 14855 | /// * `font_ascent` - baseline to top edge of raster |
| 14856 | /// * `font_descent` - baseline to bottom edge of raster |
| 14857 | /// * `draw_direction` - |
| 14858 | #[derive (Clone, Default)] |
| 14859 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 14860 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 14861 | pub struct QueryFontReply { |
| 14862 | pub sequence: u16, |
| 14863 | pub length: u32, |
| 14864 | pub min_bounds: Charinfo, |
| 14865 | pub max_bounds: Charinfo, |
| 14866 | pub min_char_or_byte2: u16, |
| 14867 | pub max_char_or_byte2: u16, |
| 14868 | pub default_char: u16, |
| 14869 | pub draw_direction: FontDraw, |
| 14870 | pub min_byte1: u8, |
| 14871 | pub max_byte1: u8, |
| 14872 | pub all_chars_exist: bool, |
| 14873 | pub font_ascent: i16, |
| 14874 | pub font_descent: i16, |
| 14875 | pub properties: Vec<Fontprop>, |
| 14876 | pub char_infos: Vec<Charinfo>, |
| 14877 | } |
| 14878 | impl_debug_if_no_extra_traits!(QueryFontReply, "QueryFontReply" ); |
| 14879 | impl TryParse for QueryFontReply { |
| 14880 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 14881 | let remaining = initial_value; |
| 14882 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 14883 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 14884 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 14885 | let (length, remaining) = u32::try_parse(remaining)?; |
| 14886 | let (min_bounds, remaining) = Charinfo::try_parse(remaining)?; |
| 14887 | let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; |
| 14888 | let (max_bounds, remaining) = Charinfo::try_parse(remaining)?; |
| 14889 | let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; |
| 14890 | let (min_char_or_byte2, remaining) = u16::try_parse(remaining)?; |
| 14891 | let (max_char_or_byte2, remaining) = u16::try_parse(remaining)?; |
| 14892 | let (default_char, remaining) = u16::try_parse(remaining)?; |
| 14893 | let (properties_len, remaining) = u16::try_parse(remaining)?; |
| 14894 | let (draw_direction, remaining) = u8::try_parse(remaining)?; |
| 14895 | let (min_byte1, remaining) = u8::try_parse(remaining)?; |
| 14896 | let (max_byte1, remaining) = u8::try_parse(remaining)?; |
| 14897 | let (all_chars_exist, remaining) = bool::try_parse(remaining)?; |
| 14898 | let (font_ascent, remaining) = i16::try_parse(remaining)?; |
| 14899 | let (font_descent, remaining) = i16::try_parse(remaining)?; |
| 14900 | let (char_infos_len, remaining) = u32::try_parse(remaining)?; |
| 14901 | let (properties, remaining) = crate::x11_utils::parse_list::<Fontprop>(remaining, properties_len.try_to_usize()?)?; |
| 14902 | let (char_infos, remaining) = crate::x11_utils::parse_list::<Charinfo>(remaining, char_infos_len.try_to_usize()?)?; |
| 14903 | if response_type != 1 { |
| 14904 | return Err(ParseError::InvalidValue); |
| 14905 | } |
| 14906 | let draw_direction = draw_direction.into(); |
| 14907 | let result = QueryFontReply { sequence, length, min_bounds, max_bounds, min_char_or_byte2, max_char_or_byte2, default_char, draw_direction, min_byte1, max_byte1, all_chars_exist, font_ascent, font_descent, properties, char_infos }; |
| 14908 | let _ = remaining; |
| 14909 | let remaining = initial_value.get(32 + length as usize * 4..) |
| 14910 | .ok_or(ParseError::InsufficientData)?; |
| 14911 | Ok((result, remaining)) |
| 14912 | } |
| 14913 | } |
| 14914 | impl Serialize for QueryFontReply { |
| 14915 | type Bytes = Vec<u8>; |
| 14916 | fn serialize(&self) -> Vec<u8> { |
| 14917 | let mut result = Vec::new(); |
| 14918 | self.serialize_into(&mut result); |
| 14919 | result |
| 14920 | } |
| 14921 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 14922 | bytes.reserve(60); |
| 14923 | let response_type_bytes = &[1]; |
| 14924 | bytes.push(response_type_bytes[0]); |
| 14925 | bytes.extend_from_slice(&[0; 1]); |
| 14926 | self.sequence.serialize_into(bytes); |
| 14927 | self.length.serialize_into(bytes); |
| 14928 | self.min_bounds.serialize_into(bytes); |
| 14929 | bytes.extend_from_slice(&[0; 4]); |
| 14930 | self.max_bounds.serialize_into(bytes); |
| 14931 | bytes.extend_from_slice(&[0; 4]); |
| 14932 | self.min_char_or_byte2.serialize_into(bytes); |
| 14933 | self.max_char_or_byte2.serialize_into(bytes); |
| 14934 | self.default_char.serialize_into(bytes); |
| 14935 | let properties_len = u16::try_from(self.properties.len()).expect("`properties` has too many elements" ); |
| 14936 | properties_len.serialize_into(bytes); |
| 14937 | u8::from(self.draw_direction).serialize_into(bytes); |
| 14938 | self.min_byte1.serialize_into(bytes); |
| 14939 | self.max_byte1.serialize_into(bytes); |
| 14940 | self.all_chars_exist.serialize_into(bytes); |
| 14941 | self.font_ascent.serialize_into(bytes); |
| 14942 | self.font_descent.serialize_into(bytes); |
| 14943 | let char_infos_len = u32::try_from(self.char_infos.len()).expect("`char_infos` has too many elements" ); |
| 14944 | char_infos_len.serialize_into(bytes); |
| 14945 | self.properties.serialize_into(bytes); |
| 14946 | self.char_infos.serialize_into(bytes); |
| 14947 | } |
| 14948 | } |
| 14949 | impl QueryFontReply { |
| 14950 | /// Get the value of the `properties_len` field. |
| 14951 | /// |
| 14952 | /// The `properties_len` field is used as the length field of the `properties` field. |
| 14953 | /// This function computes the field's value again based on the length of the list. |
| 14954 | /// |
| 14955 | /// # Panics |
| 14956 | /// |
| 14957 | /// Panics if the value cannot be represented in the target type. This |
| 14958 | /// cannot happen with values of the struct received from the X11 server. |
| 14959 | pub fn properties_len(&self) -> u16 { |
| 14960 | self.properties.len() |
| 14961 | .try_into().unwrap() |
| 14962 | } |
| 14963 | /// Get the value of the `char_infos_len` field. |
| 14964 | /// |
| 14965 | /// The `char_infos_len` field is used as the length field of the `char_infos` field. |
| 14966 | /// This function computes the field's value again based on the length of the list. |
| 14967 | /// |
| 14968 | /// # Panics |
| 14969 | /// |
| 14970 | /// Panics if the value cannot be represented in the target type. This |
| 14971 | /// cannot happen with values of the struct received from the X11 server. |
| 14972 | pub fn char_infos_len(&self) -> u32 { |
| 14973 | self.char_infos.len() |
| 14974 | .try_into().unwrap() |
| 14975 | } |
| 14976 | } |
| 14977 | |
| 14978 | /// Opcode for the QueryTextExtents request |
| 14979 | pub const QUERY_TEXT_EXTENTS_REQUEST: u8 = 48; |
| 14980 | /// get text extents. |
| 14981 | /// |
| 14982 | /// Query text extents from the X11 server. This request returns the bounding box |
| 14983 | /// of the specified 16-bit character string in the specified `font` or the font |
| 14984 | /// contained in the specified graphics context. |
| 14985 | /// |
| 14986 | /// `font_ascent` is set to the maximum of the ascent metrics of all characters in |
| 14987 | /// the string. `font_descent` is set to the maximum of the descent metrics. |
| 14988 | /// `overall_width` is set to the sum of the character-width metrics of all |
| 14989 | /// characters in the string. For each character in the string, let W be the sum of |
| 14990 | /// the character-width metrics of all characters preceding it in the string. Let L |
| 14991 | /// be the left-side-bearing metric of the character plus W. Let R be the |
| 14992 | /// right-side-bearing metric of the character plus W. The lbearing member is set |
| 14993 | /// to the minimum L of all characters in the string. The rbearing member is set to |
| 14994 | /// the maximum R. |
| 14995 | /// |
| 14996 | /// For fonts defined with linear indexing rather than 2-byte matrix indexing, each |
| 14997 | /// `xcb_char2b_t` structure is interpreted as a 16-bit number with byte1 as the |
| 14998 | /// most significant byte. If the font has no defined default character, undefined |
| 14999 | /// characters in the string are taken to have all zero metrics. |
| 15000 | /// |
| 15001 | /// Characters with all zero metrics are ignored. If the font has no defined |
| 15002 | /// default_char, the undefined characters in the string are also ignored. |
| 15003 | /// |
| 15004 | /// # Fields |
| 15005 | /// |
| 15006 | /// * `font` - The `font` to calculate text extents in. You can also pass a graphics context. |
| 15007 | /// * `string_len` - The number of characters in `string`. |
| 15008 | /// * `string` - The text to get text extents for. |
| 15009 | /// |
| 15010 | /// # Errors |
| 15011 | /// |
| 15012 | /// * `GContext` - The specified graphics context does not exist. |
| 15013 | /// * `Font` - The specified `font` does not exist. |
| 15014 | #[derive (Clone, Default)] |
| 15015 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 15016 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 15017 | pub struct QueryTextExtentsRequest<'input> { |
| 15018 | pub font: Fontable, |
| 15019 | pub string: Cow<'input, [Char2b]>, |
| 15020 | } |
| 15021 | impl_debug_if_no_extra_traits!(QueryTextExtentsRequest<'_>, "QueryTextExtentsRequest" ); |
| 15022 | impl<'input> QueryTextExtentsRequest<'input> { |
| 15023 | /// Serialize this request into bytes for the provided connection |
| 15024 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 15025 | let string_len = u32::try_from(self.string.len()).unwrap(); |
| 15026 | let length_so_far = 0; |
| 15027 | let odd_length = (u32::from(string_len) & 1u32) != 0; |
| 15028 | let odd_length_bytes = odd_length.serialize(); |
| 15029 | let font_bytes = self.font.serialize(); |
| 15030 | let mut request0 = vec![ |
| 15031 | QUERY_TEXT_EXTENTS_REQUEST, |
| 15032 | odd_length_bytes[0], |
| 15033 | 0, |
| 15034 | 0, |
| 15035 | font_bytes[0], |
| 15036 | font_bytes[1], |
| 15037 | font_bytes[2], |
| 15038 | font_bytes[3], |
| 15039 | ]; |
| 15040 | let length_so_far = length_so_far + request0.len(); |
| 15041 | let string_bytes = self.string.serialize(); |
| 15042 | let length_so_far = length_so_far + string_bytes.len(); |
| 15043 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 15044 | let length_so_far = length_so_far + padding0.len(); |
| 15045 | assert_eq!(length_so_far % 4, 0); |
| 15046 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 15047 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 15048 | ([request0.into(), string_bytes.into(), padding0.into()], vec![]) |
| 15049 | } |
| 15050 | /// Parse this request given its header, its body, and any fds that go along with it |
| 15051 | #[cfg (feature = "request-parsing" )] |
| 15052 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 15053 | if header.major_opcode != QUERY_TEXT_EXTENTS_REQUEST { |
| 15054 | return Err(ParseError::InvalidValue); |
| 15055 | } |
| 15056 | let remaining = &[header.minor_opcode]; |
| 15057 | let (odd_length, remaining) = bool::try_parse(remaining)?; |
| 15058 | let _ = remaining; |
| 15059 | let (font, remaining) = Fontable::try_parse(value)?; |
| 15060 | let mut remaining = remaining; |
| 15061 | // Length is 'everything left in the input' |
| 15062 | let mut string = Vec::new(); |
| 15063 | while !remaining.is_empty() { |
| 15064 | let (v, new_remaining) = Char2b::try_parse(remaining)?; |
| 15065 | remaining = new_remaining; |
| 15066 | string.push(v); |
| 15067 | } |
| 15068 | let _ = remaining; |
| 15069 | if odd_length { |
| 15070 | if string.is_empty() { |
| 15071 | return Err(ParseError::InvalidValue); |
| 15072 | } |
| 15073 | string.truncate(string.len() - 1); |
| 15074 | } |
| 15075 | Ok(QueryTextExtentsRequest { |
| 15076 | font, |
| 15077 | string: Cow::Owned(string), |
| 15078 | }) |
| 15079 | } |
| 15080 | /// Clone all borrowed data in this QueryTextExtentsRequest. |
| 15081 | pub fn into_owned(self) -> QueryTextExtentsRequest<'static> { |
| 15082 | QueryTextExtentsRequest { |
| 15083 | font: self.font, |
| 15084 | string: Cow::Owned(self.string.into_owned()), |
| 15085 | } |
| 15086 | } |
| 15087 | } |
| 15088 | impl<'input> Request for QueryTextExtentsRequest<'input> { |
| 15089 | const EXTENSION_NAME: Option<&'static str> = None; |
| 15090 | |
| 15091 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 15092 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 15093 | // Flatten the buffers into a single vector |
| 15094 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 15095 | (buf, fds) |
| 15096 | } |
| 15097 | } |
| 15098 | impl<'input> crate::x11_utils::ReplyRequest for QueryTextExtentsRequest<'input> { |
| 15099 | type Reply = QueryTextExtentsReply; |
| 15100 | } |
| 15101 | |
| 15102 | #[derive (Clone, Copy, Default)] |
| 15103 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 15104 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 15105 | pub struct QueryTextExtentsReply { |
| 15106 | pub draw_direction: FontDraw, |
| 15107 | pub sequence: u16, |
| 15108 | pub length: u32, |
| 15109 | pub font_ascent: i16, |
| 15110 | pub font_descent: i16, |
| 15111 | pub overall_ascent: i16, |
| 15112 | pub overall_descent: i16, |
| 15113 | pub overall_width: i32, |
| 15114 | pub overall_left: i32, |
| 15115 | pub overall_right: i32, |
| 15116 | } |
| 15117 | impl_debug_if_no_extra_traits!(QueryTextExtentsReply, "QueryTextExtentsReply" ); |
| 15118 | impl TryParse for QueryTextExtentsReply { |
| 15119 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 15120 | let remaining = initial_value; |
| 15121 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 15122 | let (draw_direction, remaining) = u8::try_parse(remaining)?; |
| 15123 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 15124 | let (length, remaining) = u32::try_parse(remaining)?; |
| 15125 | let (font_ascent, remaining) = i16::try_parse(remaining)?; |
| 15126 | let (font_descent, remaining) = i16::try_parse(remaining)?; |
| 15127 | let (overall_ascent, remaining) = i16::try_parse(remaining)?; |
| 15128 | let (overall_descent, remaining) = i16::try_parse(remaining)?; |
| 15129 | let (overall_width, remaining) = i32::try_parse(remaining)?; |
| 15130 | let (overall_left, remaining) = i32::try_parse(remaining)?; |
| 15131 | let (overall_right, remaining) = i32::try_parse(remaining)?; |
| 15132 | if response_type != 1 { |
| 15133 | return Err(ParseError::InvalidValue); |
| 15134 | } |
| 15135 | let draw_direction = draw_direction.into(); |
| 15136 | let result = QueryTextExtentsReply { draw_direction, sequence, length, font_ascent, font_descent, overall_ascent, overall_descent, overall_width, overall_left, overall_right }; |
| 15137 | let _ = remaining; |
| 15138 | let remaining = initial_value.get(32 + length as usize * 4..) |
| 15139 | .ok_or(ParseError::InsufficientData)?; |
| 15140 | Ok((result, remaining)) |
| 15141 | } |
| 15142 | } |
| 15143 | impl Serialize for QueryTextExtentsReply { |
| 15144 | type Bytes = [u8; 28]; |
| 15145 | fn serialize(&self) -> [u8; 28] { |
| 15146 | let response_type_bytes = &[1]; |
| 15147 | let draw_direction_bytes = u8::from(self.draw_direction).serialize(); |
| 15148 | let sequence_bytes = self.sequence.serialize(); |
| 15149 | let length_bytes = self.length.serialize(); |
| 15150 | let font_ascent_bytes = self.font_ascent.serialize(); |
| 15151 | let font_descent_bytes = self.font_descent.serialize(); |
| 15152 | let overall_ascent_bytes = self.overall_ascent.serialize(); |
| 15153 | let overall_descent_bytes = self.overall_descent.serialize(); |
| 15154 | let overall_width_bytes = self.overall_width.serialize(); |
| 15155 | let overall_left_bytes = self.overall_left.serialize(); |
| 15156 | let overall_right_bytes = self.overall_right.serialize(); |
| 15157 | [ |
| 15158 | response_type_bytes[0], |
| 15159 | draw_direction_bytes[0], |
| 15160 | sequence_bytes[0], |
| 15161 | sequence_bytes[1], |
| 15162 | length_bytes[0], |
| 15163 | length_bytes[1], |
| 15164 | length_bytes[2], |
| 15165 | length_bytes[3], |
| 15166 | font_ascent_bytes[0], |
| 15167 | font_ascent_bytes[1], |
| 15168 | font_descent_bytes[0], |
| 15169 | font_descent_bytes[1], |
| 15170 | overall_ascent_bytes[0], |
| 15171 | overall_ascent_bytes[1], |
| 15172 | overall_descent_bytes[0], |
| 15173 | overall_descent_bytes[1], |
| 15174 | overall_width_bytes[0], |
| 15175 | overall_width_bytes[1], |
| 15176 | overall_width_bytes[2], |
| 15177 | overall_width_bytes[3], |
| 15178 | overall_left_bytes[0], |
| 15179 | overall_left_bytes[1], |
| 15180 | overall_left_bytes[2], |
| 15181 | overall_left_bytes[3], |
| 15182 | overall_right_bytes[0], |
| 15183 | overall_right_bytes[1], |
| 15184 | overall_right_bytes[2], |
| 15185 | overall_right_bytes[3], |
| 15186 | ] |
| 15187 | } |
| 15188 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 15189 | bytes.reserve(28); |
| 15190 | let response_type_bytes = &[1]; |
| 15191 | bytes.push(response_type_bytes[0]); |
| 15192 | u8::from(self.draw_direction).serialize_into(bytes); |
| 15193 | self.sequence.serialize_into(bytes); |
| 15194 | self.length.serialize_into(bytes); |
| 15195 | self.font_ascent.serialize_into(bytes); |
| 15196 | self.font_descent.serialize_into(bytes); |
| 15197 | self.overall_ascent.serialize_into(bytes); |
| 15198 | self.overall_descent.serialize_into(bytes); |
| 15199 | self.overall_width.serialize_into(bytes); |
| 15200 | self.overall_left.serialize_into(bytes); |
| 15201 | self.overall_right.serialize_into(bytes); |
| 15202 | } |
| 15203 | } |
| 15204 | |
| 15205 | #[derive (Clone, Default)] |
| 15206 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 15207 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 15208 | pub struct Str { |
| 15209 | pub name: Vec<u8>, |
| 15210 | } |
| 15211 | impl_debug_if_no_extra_traits!(Str, "Str" ); |
| 15212 | impl TryParse for Str { |
| 15213 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 15214 | let (name_len: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 15215 | let (name: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data:remaining, list_length:name_len.try_to_usize()?)?; |
| 15216 | let name: Vec = name.to_vec(); |
| 15217 | let result: Str = Str { name }; |
| 15218 | Ok((result, remaining)) |
| 15219 | } |
| 15220 | } |
| 15221 | impl Serialize for Str { |
| 15222 | type Bytes = Vec<u8>; |
| 15223 | fn serialize(&self) -> Vec<u8> { |
| 15224 | let mut result: Vec = Vec::new(); |
| 15225 | self.serialize_into(&mut result); |
| 15226 | result |
| 15227 | } |
| 15228 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 15229 | let name_len: u8 = u8::try_from(self.name.len()).expect(msg:"`name` has too many elements" ); |
| 15230 | name_len.serialize_into(bytes); |
| 15231 | bytes.extend_from_slice(&self.name); |
| 15232 | } |
| 15233 | } |
| 15234 | impl Str { |
| 15235 | /// Get the value of the `name_len` field. |
| 15236 | /// |
| 15237 | /// The `name_len` field is used as the length field of the `name` field. |
| 15238 | /// This function computes the field's value again based on the length of the list. |
| 15239 | /// |
| 15240 | /// # Panics |
| 15241 | /// |
| 15242 | /// Panics if the value cannot be represented in the target type. This |
| 15243 | /// cannot happen with values of the struct received from the X11 server. |
| 15244 | pub fn name_len(&self) -> u8 { |
| 15245 | self.name.len() |
| 15246 | .try_into().unwrap() |
| 15247 | } |
| 15248 | } |
| 15249 | |
| 15250 | /// Opcode for the ListFonts request |
| 15251 | pub const LIST_FONTS_REQUEST: u8 = 49; |
| 15252 | /// get matching font names. |
| 15253 | /// |
| 15254 | /// Gets a list of available font names which match the given `pattern`. |
| 15255 | /// |
| 15256 | /// # Fields |
| 15257 | /// |
| 15258 | /// * `pattern` - A font pattern, for example "-misc-fixed-*". |
| 15259 | /// |
| 15260 | /// The asterisk (*) is a wildcard for any number of characters. The question mark |
| 15261 | /// (?) is a wildcard for a single character. Use of uppercase or lowercase does |
| 15262 | /// not matter. |
| 15263 | /// * `max_names` - The maximum number of fonts to be returned. |
| 15264 | #[derive (Clone, Default)] |
| 15265 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 15266 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 15267 | pub struct ListFontsRequest<'input> { |
| 15268 | pub max_names: u16, |
| 15269 | pub pattern: Cow<'input, [u8]>, |
| 15270 | } |
| 15271 | impl_debug_if_no_extra_traits!(ListFontsRequest<'_>, "ListFontsRequest" ); |
| 15272 | impl<'input> ListFontsRequest<'input> { |
| 15273 | /// Serialize this request into bytes for the provided connection |
| 15274 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 15275 | let length_so_far = 0; |
| 15276 | let max_names_bytes = self.max_names.serialize(); |
| 15277 | let pattern_len = u16::try_from(self.pattern.len()).expect("`pattern` has too many elements" ); |
| 15278 | let pattern_len_bytes = pattern_len.serialize(); |
| 15279 | let mut request0 = vec![ |
| 15280 | LIST_FONTS_REQUEST, |
| 15281 | 0, |
| 15282 | 0, |
| 15283 | 0, |
| 15284 | max_names_bytes[0], |
| 15285 | max_names_bytes[1], |
| 15286 | pattern_len_bytes[0], |
| 15287 | pattern_len_bytes[1], |
| 15288 | ]; |
| 15289 | let length_so_far = length_so_far + request0.len(); |
| 15290 | let length_so_far = length_so_far + self.pattern.len(); |
| 15291 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 15292 | let length_so_far = length_so_far + padding0.len(); |
| 15293 | assert_eq!(length_so_far % 4, 0); |
| 15294 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 15295 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 15296 | ([request0.into(), self.pattern, padding0.into()], vec![]) |
| 15297 | } |
| 15298 | /// Parse this request given its header, its body, and any fds that go along with it |
| 15299 | #[cfg (feature = "request-parsing" )] |
| 15300 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 15301 | if header.major_opcode != LIST_FONTS_REQUEST { |
| 15302 | return Err(ParseError::InvalidValue); |
| 15303 | } |
| 15304 | let remaining = &[header.minor_opcode]; |
| 15305 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 15306 | let _ = remaining; |
| 15307 | let (max_names, remaining) = u16::try_parse(value)?; |
| 15308 | let (pattern_len, remaining) = u16::try_parse(remaining)?; |
| 15309 | let (pattern, remaining) = crate::x11_utils::parse_u8_list(remaining, pattern_len.try_to_usize()?)?; |
| 15310 | let _ = remaining; |
| 15311 | Ok(ListFontsRequest { |
| 15312 | max_names, |
| 15313 | pattern: Cow::Borrowed(pattern), |
| 15314 | }) |
| 15315 | } |
| 15316 | /// Clone all borrowed data in this ListFontsRequest. |
| 15317 | pub fn into_owned(self) -> ListFontsRequest<'static> { |
| 15318 | ListFontsRequest { |
| 15319 | max_names: self.max_names, |
| 15320 | pattern: Cow::Owned(self.pattern.into_owned()), |
| 15321 | } |
| 15322 | } |
| 15323 | } |
| 15324 | impl<'input> Request for ListFontsRequest<'input> { |
| 15325 | const EXTENSION_NAME: Option<&'static str> = None; |
| 15326 | |
| 15327 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 15328 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 15329 | // Flatten the buffers into a single vector |
| 15330 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 15331 | (buf, fds) |
| 15332 | } |
| 15333 | } |
| 15334 | impl<'input> crate::x11_utils::ReplyRequest for ListFontsRequest<'input> { |
| 15335 | type Reply = ListFontsReply; |
| 15336 | } |
| 15337 | |
| 15338 | /// # Fields |
| 15339 | /// |
| 15340 | #[derive (Clone, Default)] |
| 15341 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 15342 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 15343 | pub struct ListFontsReply { |
| 15344 | pub sequence: u16, |
| 15345 | pub length: u32, |
| 15346 | pub names: Vec<Str>, |
| 15347 | } |
| 15348 | impl_debug_if_no_extra_traits!(ListFontsReply, "ListFontsReply" ); |
| 15349 | impl TryParse for ListFontsReply { |
| 15350 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 15351 | let remaining: &[u8] = initial_value; |
| 15352 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 15353 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 15354 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 15355 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 15356 | let (names_len: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 15357 | let remaining: &[u8] = remaining.get(22..).ok_or(err:ParseError::InsufficientData)?; |
| 15358 | let (names: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<Str>(data:remaining, list_length:names_len.try_to_usize()?)?; |
| 15359 | if response_type != 1 { |
| 15360 | return Err(ParseError::InvalidValue); |
| 15361 | } |
| 15362 | let result: ListFontsReply = ListFontsReply { sequence, length, names }; |
| 15363 | let _ = remaining; |
| 15364 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 15365 | .ok_or(err:ParseError::InsufficientData)?; |
| 15366 | Ok((result, remaining)) |
| 15367 | } |
| 15368 | } |
| 15369 | impl Serialize for ListFontsReply { |
| 15370 | type Bytes = Vec<u8>; |
| 15371 | fn serialize(&self) -> Vec<u8> { |
| 15372 | let mut result: Vec = Vec::new(); |
| 15373 | self.serialize_into(&mut result); |
| 15374 | result |
| 15375 | } |
| 15376 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 15377 | bytes.reserve(additional:32); |
| 15378 | let response_type_bytes: &[u8; 1] = &[1]; |
| 15379 | bytes.push(response_type_bytes[0]); |
| 15380 | bytes.extend_from_slice(&[0; 1]); |
| 15381 | self.sequence.serialize_into(bytes); |
| 15382 | self.length.serialize_into(bytes); |
| 15383 | let names_len: u16 = u16::try_from(self.names.len()).expect(msg:"`names` has too many elements" ); |
| 15384 | names_len.serialize_into(bytes); |
| 15385 | bytes.extend_from_slice(&[0; 22]); |
| 15386 | self.names.serialize_into(bytes); |
| 15387 | } |
| 15388 | } |
| 15389 | impl ListFontsReply { |
| 15390 | /// Get the value of the `names_len` field. |
| 15391 | /// |
| 15392 | /// The `names_len` field is used as the length field of the `names` field. |
| 15393 | /// This function computes the field's value again based on the length of the list. |
| 15394 | /// |
| 15395 | /// # Panics |
| 15396 | /// |
| 15397 | /// Panics if the value cannot be represented in the target type. This |
| 15398 | /// cannot happen with values of the struct received from the X11 server. |
| 15399 | pub fn names_len(&self) -> u16 { |
| 15400 | self.names.len() |
| 15401 | .try_into().unwrap() |
| 15402 | } |
| 15403 | } |
| 15404 | |
| 15405 | /// Opcode for the ListFontsWithInfo request |
| 15406 | pub const LIST_FONTS_WITH_INFO_REQUEST: u8 = 50; |
| 15407 | /// get matching font names and information. |
| 15408 | /// |
| 15409 | /// Gets a list of available font names which match the given `pattern`. |
| 15410 | /// |
| 15411 | /// # Fields |
| 15412 | /// |
| 15413 | /// * `pattern` - A font pattern, for example "-misc-fixed-*". |
| 15414 | /// |
| 15415 | /// The asterisk (*) is a wildcard for any number of characters. The question mark |
| 15416 | /// (?) is a wildcard for a single character. Use of uppercase or lowercase does |
| 15417 | /// not matter. |
| 15418 | /// * `max_names` - The maximum number of fonts to be returned. |
| 15419 | #[derive (Clone, Default)] |
| 15420 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 15421 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 15422 | pub struct ListFontsWithInfoRequest<'input> { |
| 15423 | pub max_names: u16, |
| 15424 | pub pattern: Cow<'input, [u8]>, |
| 15425 | } |
| 15426 | impl_debug_if_no_extra_traits!(ListFontsWithInfoRequest<'_>, "ListFontsWithInfoRequest" ); |
| 15427 | impl<'input> ListFontsWithInfoRequest<'input> { |
| 15428 | /// Serialize this request into bytes for the provided connection |
| 15429 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 15430 | let length_so_far = 0; |
| 15431 | let max_names_bytes = self.max_names.serialize(); |
| 15432 | let pattern_len = u16::try_from(self.pattern.len()).expect("`pattern` has too many elements" ); |
| 15433 | let pattern_len_bytes = pattern_len.serialize(); |
| 15434 | let mut request0 = vec![ |
| 15435 | LIST_FONTS_WITH_INFO_REQUEST, |
| 15436 | 0, |
| 15437 | 0, |
| 15438 | 0, |
| 15439 | max_names_bytes[0], |
| 15440 | max_names_bytes[1], |
| 15441 | pattern_len_bytes[0], |
| 15442 | pattern_len_bytes[1], |
| 15443 | ]; |
| 15444 | let length_so_far = length_so_far + request0.len(); |
| 15445 | let length_so_far = length_so_far + self.pattern.len(); |
| 15446 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 15447 | let length_so_far = length_so_far + padding0.len(); |
| 15448 | assert_eq!(length_so_far % 4, 0); |
| 15449 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 15450 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 15451 | ([request0.into(), self.pattern, padding0.into()], vec![]) |
| 15452 | } |
| 15453 | /// Parse this request given its header, its body, and any fds that go along with it |
| 15454 | #[cfg (feature = "request-parsing" )] |
| 15455 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 15456 | if header.major_opcode != LIST_FONTS_WITH_INFO_REQUEST { |
| 15457 | return Err(ParseError::InvalidValue); |
| 15458 | } |
| 15459 | let remaining = &[header.minor_opcode]; |
| 15460 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 15461 | let _ = remaining; |
| 15462 | let (max_names, remaining) = u16::try_parse(value)?; |
| 15463 | let (pattern_len, remaining) = u16::try_parse(remaining)?; |
| 15464 | let (pattern, remaining) = crate::x11_utils::parse_u8_list(remaining, pattern_len.try_to_usize()?)?; |
| 15465 | let _ = remaining; |
| 15466 | Ok(ListFontsWithInfoRequest { |
| 15467 | max_names, |
| 15468 | pattern: Cow::Borrowed(pattern), |
| 15469 | }) |
| 15470 | } |
| 15471 | /// Clone all borrowed data in this ListFontsWithInfoRequest. |
| 15472 | pub fn into_owned(self) -> ListFontsWithInfoRequest<'static> { |
| 15473 | ListFontsWithInfoRequest { |
| 15474 | max_names: self.max_names, |
| 15475 | pattern: Cow::Owned(self.pattern.into_owned()), |
| 15476 | } |
| 15477 | } |
| 15478 | } |
| 15479 | impl<'input> Request for ListFontsWithInfoRequest<'input> { |
| 15480 | const EXTENSION_NAME: Option<&'static str> = None; |
| 15481 | |
| 15482 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 15483 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 15484 | // Flatten the buffers into a single vector |
| 15485 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 15486 | (buf, fds) |
| 15487 | } |
| 15488 | } |
| 15489 | impl<'input> crate::x11_utils::ReplyRequest for ListFontsWithInfoRequest<'input> { |
| 15490 | type Reply = ListFontsWithInfoReply; |
| 15491 | } |
| 15492 | |
| 15493 | /// # Fields |
| 15494 | /// |
| 15495 | /// * `min_bounds` - minimum bounds over all existing char |
| 15496 | /// * `max_bounds` - maximum bounds over all existing char |
| 15497 | /// * `min_char_or_byte2` - first character |
| 15498 | /// * `max_char_or_byte2` - last character |
| 15499 | /// * `default_char` - char to print for undefined character |
| 15500 | /// * `all_chars_exist` - flag if all characters have nonzero size |
| 15501 | /// * `font_ascent` - baseline to top edge of raster |
| 15502 | /// * `font_descent` - baseline to bottom edge of raster |
| 15503 | /// * `replies_hint` - An indication of how many more fonts will be returned. This is only a hint and |
| 15504 | /// may be larger or smaller than the number of fonts actually returned. A zero |
| 15505 | /// value does not guarantee that no more fonts will be returned. |
| 15506 | /// * `draw_direction` - |
| 15507 | #[derive (Clone, Default)] |
| 15508 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 15509 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 15510 | pub struct ListFontsWithInfoReply { |
| 15511 | pub sequence: u16, |
| 15512 | pub length: u32, |
| 15513 | pub min_bounds: Charinfo, |
| 15514 | pub max_bounds: Charinfo, |
| 15515 | pub min_char_or_byte2: u16, |
| 15516 | pub max_char_or_byte2: u16, |
| 15517 | pub default_char: u16, |
| 15518 | pub draw_direction: FontDraw, |
| 15519 | pub min_byte1: u8, |
| 15520 | pub max_byte1: u8, |
| 15521 | pub all_chars_exist: bool, |
| 15522 | pub font_ascent: i16, |
| 15523 | pub font_descent: i16, |
| 15524 | pub replies_hint: u32, |
| 15525 | pub properties: Vec<Fontprop>, |
| 15526 | pub name: Vec<u8>, |
| 15527 | } |
| 15528 | impl_debug_if_no_extra_traits!(ListFontsWithInfoReply, "ListFontsWithInfoReply" ); |
| 15529 | impl TryParse for ListFontsWithInfoReply { |
| 15530 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 15531 | let remaining = initial_value; |
| 15532 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 15533 | let (name_len, remaining) = u8::try_parse(remaining)?; |
| 15534 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 15535 | let (length, remaining) = u32::try_parse(remaining)?; |
| 15536 | let (min_bounds, remaining) = Charinfo::try_parse(remaining)?; |
| 15537 | let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; |
| 15538 | let (max_bounds, remaining) = Charinfo::try_parse(remaining)?; |
| 15539 | let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; |
| 15540 | let (min_char_or_byte2, remaining) = u16::try_parse(remaining)?; |
| 15541 | let (max_char_or_byte2, remaining) = u16::try_parse(remaining)?; |
| 15542 | let (default_char, remaining) = u16::try_parse(remaining)?; |
| 15543 | let (properties_len, remaining) = u16::try_parse(remaining)?; |
| 15544 | let (draw_direction, remaining) = u8::try_parse(remaining)?; |
| 15545 | let (min_byte1, remaining) = u8::try_parse(remaining)?; |
| 15546 | let (max_byte1, remaining) = u8::try_parse(remaining)?; |
| 15547 | let (all_chars_exist, remaining) = bool::try_parse(remaining)?; |
| 15548 | let (font_ascent, remaining) = i16::try_parse(remaining)?; |
| 15549 | let (font_descent, remaining) = i16::try_parse(remaining)?; |
| 15550 | let (replies_hint, remaining) = u32::try_parse(remaining)?; |
| 15551 | let (properties, remaining) = crate::x11_utils::parse_list::<Fontprop>(remaining, properties_len.try_to_usize()?)?; |
| 15552 | let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; |
| 15553 | let name = name.to_vec(); |
| 15554 | if response_type != 1 { |
| 15555 | return Err(ParseError::InvalidValue); |
| 15556 | } |
| 15557 | let draw_direction = draw_direction.into(); |
| 15558 | let result = ListFontsWithInfoReply { sequence, length, min_bounds, max_bounds, min_char_or_byte2, max_char_or_byte2, default_char, draw_direction, min_byte1, max_byte1, all_chars_exist, font_ascent, font_descent, replies_hint, properties, name }; |
| 15559 | let _ = remaining; |
| 15560 | let remaining = initial_value.get(32 + length as usize * 4..) |
| 15561 | .ok_or(ParseError::InsufficientData)?; |
| 15562 | Ok((result, remaining)) |
| 15563 | } |
| 15564 | } |
| 15565 | impl Serialize for ListFontsWithInfoReply { |
| 15566 | type Bytes = Vec<u8>; |
| 15567 | fn serialize(&self) -> Vec<u8> { |
| 15568 | let mut result = Vec::new(); |
| 15569 | self.serialize_into(&mut result); |
| 15570 | result |
| 15571 | } |
| 15572 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 15573 | bytes.reserve(60); |
| 15574 | let response_type_bytes = &[1]; |
| 15575 | bytes.push(response_type_bytes[0]); |
| 15576 | let name_len = u8::try_from(self.name.len()).expect("`name` has too many elements" ); |
| 15577 | name_len.serialize_into(bytes); |
| 15578 | self.sequence.serialize_into(bytes); |
| 15579 | self.length.serialize_into(bytes); |
| 15580 | self.min_bounds.serialize_into(bytes); |
| 15581 | bytes.extend_from_slice(&[0; 4]); |
| 15582 | self.max_bounds.serialize_into(bytes); |
| 15583 | bytes.extend_from_slice(&[0; 4]); |
| 15584 | self.min_char_or_byte2.serialize_into(bytes); |
| 15585 | self.max_char_or_byte2.serialize_into(bytes); |
| 15586 | self.default_char.serialize_into(bytes); |
| 15587 | let properties_len = u16::try_from(self.properties.len()).expect("`properties` has too many elements" ); |
| 15588 | properties_len.serialize_into(bytes); |
| 15589 | u8::from(self.draw_direction).serialize_into(bytes); |
| 15590 | self.min_byte1.serialize_into(bytes); |
| 15591 | self.max_byte1.serialize_into(bytes); |
| 15592 | self.all_chars_exist.serialize_into(bytes); |
| 15593 | self.font_ascent.serialize_into(bytes); |
| 15594 | self.font_descent.serialize_into(bytes); |
| 15595 | self.replies_hint.serialize_into(bytes); |
| 15596 | self.properties.serialize_into(bytes); |
| 15597 | bytes.extend_from_slice(&self.name); |
| 15598 | } |
| 15599 | } |
| 15600 | impl ListFontsWithInfoReply { |
| 15601 | /// Get the value of the `name_len` field. |
| 15602 | /// |
| 15603 | /// The `name_len` field is used as the length field of the `name` field. |
| 15604 | /// This function computes the field's value again based on the length of the list. |
| 15605 | /// |
| 15606 | /// # Panics |
| 15607 | /// |
| 15608 | /// Panics if the value cannot be represented in the target type. This |
| 15609 | /// cannot happen with values of the struct received from the X11 server. |
| 15610 | pub fn name_len(&self) -> u8 { |
| 15611 | self.name.len() |
| 15612 | .try_into().unwrap() |
| 15613 | } |
| 15614 | /// Get the value of the `properties_len` field. |
| 15615 | /// |
| 15616 | /// The `properties_len` field is used as the length field of the `properties` field. |
| 15617 | /// This function computes the field's value again based on the length of the list. |
| 15618 | /// |
| 15619 | /// # Panics |
| 15620 | /// |
| 15621 | /// Panics if the value cannot be represented in the target type. This |
| 15622 | /// cannot happen with values of the struct received from the X11 server. |
| 15623 | pub fn properties_len(&self) -> u16 { |
| 15624 | self.properties.len() |
| 15625 | .try_into().unwrap() |
| 15626 | } |
| 15627 | } |
| 15628 | |
| 15629 | /// Opcode for the SetFontPath request |
| 15630 | pub const SET_FONT_PATH_REQUEST: u8 = 51; |
| 15631 | #[derive (Clone, Default)] |
| 15632 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 15633 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 15634 | pub struct SetFontPathRequest<'input> { |
| 15635 | pub font: Cow<'input, [Str]>, |
| 15636 | } |
| 15637 | impl_debug_if_no_extra_traits!(SetFontPathRequest<'_>, "SetFontPathRequest" ); |
| 15638 | impl<'input> SetFontPathRequest<'input> { |
| 15639 | /// Serialize this request into bytes for the provided connection |
| 15640 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 15641 | let length_so_far = 0; |
| 15642 | let font_qty = u16::try_from(self.font.len()).expect("`font` has too many elements" ); |
| 15643 | let font_qty_bytes = font_qty.serialize(); |
| 15644 | let mut request0 = vec![ |
| 15645 | SET_FONT_PATH_REQUEST, |
| 15646 | 0, |
| 15647 | 0, |
| 15648 | 0, |
| 15649 | font_qty_bytes[0], |
| 15650 | font_qty_bytes[1], |
| 15651 | 0, |
| 15652 | 0, |
| 15653 | ]; |
| 15654 | let length_so_far = length_so_far + request0.len(); |
| 15655 | let font_bytes = self.font.serialize(); |
| 15656 | let length_so_far = length_so_far + font_bytes.len(); |
| 15657 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 15658 | let length_so_far = length_so_far + padding0.len(); |
| 15659 | assert_eq!(length_so_far % 4, 0); |
| 15660 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 15661 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 15662 | ([request0.into(), font_bytes.into(), padding0.into()], vec![]) |
| 15663 | } |
| 15664 | /// Parse this request given its header, its body, and any fds that go along with it |
| 15665 | #[cfg (feature = "request-parsing" )] |
| 15666 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 15667 | if header.major_opcode != SET_FONT_PATH_REQUEST { |
| 15668 | return Err(ParseError::InvalidValue); |
| 15669 | } |
| 15670 | let remaining = &[header.minor_opcode]; |
| 15671 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 15672 | let _ = remaining; |
| 15673 | let (font_qty, remaining) = u16::try_parse(value)?; |
| 15674 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 15675 | let (font, remaining) = crate::x11_utils::parse_list::<Str>(remaining, font_qty.try_to_usize()?)?; |
| 15676 | let _ = remaining; |
| 15677 | Ok(SetFontPathRequest { |
| 15678 | font: Cow::Owned(font), |
| 15679 | }) |
| 15680 | } |
| 15681 | /// Clone all borrowed data in this SetFontPathRequest. |
| 15682 | pub fn into_owned(self) -> SetFontPathRequest<'static> { |
| 15683 | SetFontPathRequest { |
| 15684 | font: Cow::Owned(self.font.into_owned()), |
| 15685 | } |
| 15686 | } |
| 15687 | } |
| 15688 | impl<'input> Request for SetFontPathRequest<'input> { |
| 15689 | const EXTENSION_NAME: Option<&'static str> = None; |
| 15690 | |
| 15691 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 15692 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 15693 | // Flatten the buffers into a single vector |
| 15694 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 15695 | (buf, fds) |
| 15696 | } |
| 15697 | } |
| 15698 | impl<'input> crate::x11_utils::VoidRequest for SetFontPathRequest<'input> { |
| 15699 | } |
| 15700 | |
| 15701 | /// Opcode for the GetFontPath request |
| 15702 | pub const GET_FONT_PATH_REQUEST: u8 = 52; |
| 15703 | #[derive (Clone, Copy, Default)] |
| 15704 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 15705 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 15706 | pub struct GetFontPathRequest; |
| 15707 | impl_debug_if_no_extra_traits!(GetFontPathRequest, "GetFontPathRequest" ); |
| 15708 | impl GetFontPathRequest { |
| 15709 | /// Serialize this request into bytes for the provided connection |
| 15710 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 15711 | let length_so_far = 0; |
| 15712 | let mut request0 = vec![ |
| 15713 | GET_FONT_PATH_REQUEST, |
| 15714 | 0, |
| 15715 | 0, |
| 15716 | 0, |
| 15717 | ]; |
| 15718 | let length_so_far = length_so_far + request0.len(); |
| 15719 | assert_eq!(length_so_far % 4, 0); |
| 15720 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 15721 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 15722 | ([request0.into()], vec![]) |
| 15723 | } |
| 15724 | /// Parse this request given its header, its body, and any fds that go along with it |
| 15725 | #[cfg (feature = "request-parsing" )] |
| 15726 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 15727 | if header.major_opcode != GET_FONT_PATH_REQUEST { |
| 15728 | return Err(ParseError::InvalidValue); |
| 15729 | } |
| 15730 | let remaining = &[header.minor_opcode]; |
| 15731 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 15732 | let _ = remaining; |
| 15733 | let _ = value; |
| 15734 | Ok(GetFontPathRequest |
| 15735 | ) |
| 15736 | } |
| 15737 | } |
| 15738 | impl Request for GetFontPathRequest { |
| 15739 | const EXTENSION_NAME: Option<&'static str> = None; |
| 15740 | |
| 15741 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 15742 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 15743 | // Flatten the buffers into a single vector |
| 15744 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 15745 | (buf, fds) |
| 15746 | } |
| 15747 | } |
| 15748 | impl crate::x11_utils::ReplyRequest for GetFontPathRequest { |
| 15749 | type Reply = GetFontPathReply; |
| 15750 | } |
| 15751 | |
| 15752 | #[derive (Clone, Default)] |
| 15753 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 15754 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 15755 | pub struct GetFontPathReply { |
| 15756 | pub sequence: u16, |
| 15757 | pub length: u32, |
| 15758 | pub path: Vec<Str>, |
| 15759 | } |
| 15760 | impl_debug_if_no_extra_traits!(GetFontPathReply, "GetFontPathReply" ); |
| 15761 | impl TryParse for GetFontPathReply { |
| 15762 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 15763 | let remaining: &[u8] = initial_value; |
| 15764 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 15765 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 15766 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 15767 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 15768 | let (path_len: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 15769 | let remaining: &[u8] = remaining.get(22..).ok_or(err:ParseError::InsufficientData)?; |
| 15770 | let (path: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<Str>(data:remaining, list_length:path_len.try_to_usize()?)?; |
| 15771 | if response_type != 1 { |
| 15772 | return Err(ParseError::InvalidValue); |
| 15773 | } |
| 15774 | let result: GetFontPathReply = GetFontPathReply { sequence, length, path }; |
| 15775 | let _ = remaining; |
| 15776 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 15777 | .ok_or(err:ParseError::InsufficientData)?; |
| 15778 | Ok((result, remaining)) |
| 15779 | } |
| 15780 | } |
| 15781 | impl Serialize for GetFontPathReply { |
| 15782 | type Bytes = Vec<u8>; |
| 15783 | fn serialize(&self) -> Vec<u8> { |
| 15784 | let mut result: Vec = Vec::new(); |
| 15785 | self.serialize_into(&mut result); |
| 15786 | result |
| 15787 | } |
| 15788 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 15789 | bytes.reserve(additional:32); |
| 15790 | let response_type_bytes: &[u8; 1] = &[1]; |
| 15791 | bytes.push(response_type_bytes[0]); |
| 15792 | bytes.extend_from_slice(&[0; 1]); |
| 15793 | self.sequence.serialize_into(bytes); |
| 15794 | self.length.serialize_into(bytes); |
| 15795 | let path_len: u16 = u16::try_from(self.path.len()).expect(msg:"`path` has too many elements" ); |
| 15796 | path_len.serialize_into(bytes); |
| 15797 | bytes.extend_from_slice(&[0; 22]); |
| 15798 | self.path.serialize_into(bytes); |
| 15799 | } |
| 15800 | } |
| 15801 | impl GetFontPathReply { |
| 15802 | /// Get the value of the `path_len` field. |
| 15803 | /// |
| 15804 | /// The `path_len` field is used as the length field of the `path` field. |
| 15805 | /// This function computes the field's value again based on the length of the list. |
| 15806 | /// |
| 15807 | /// # Panics |
| 15808 | /// |
| 15809 | /// Panics if the value cannot be represented in the target type. This |
| 15810 | /// cannot happen with values of the struct received from the X11 server. |
| 15811 | pub fn path_len(&self) -> u16 { |
| 15812 | self.path.len() |
| 15813 | .try_into().unwrap() |
| 15814 | } |
| 15815 | } |
| 15816 | |
| 15817 | /// Opcode for the CreatePixmap request |
| 15818 | pub const CREATE_PIXMAP_REQUEST: u8 = 53; |
| 15819 | /// Creates a pixmap. |
| 15820 | /// |
| 15821 | /// Creates a pixmap. The pixmap can only be used on the same screen as `drawable` |
| 15822 | /// is on and only with drawables of the same `depth`. |
| 15823 | /// |
| 15824 | /// # Fields |
| 15825 | /// |
| 15826 | /// * `depth` - TODO |
| 15827 | /// * `pid` - The ID with which you will refer to the new pixmap, created by |
| 15828 | /// `xcb_generate_id`. |
| 15829 | /// * `drawable` - Drawable to get the screen from. |
| 15830 | /// * `width` - The width of the new pixmap. |
| 15831 | /// * `height` - The height of the new pixmap. |
| 15832 | /// |
| 15833 | /// # Errors |
| 15834 | /// |
| 15835 | /// * `Value` - TODO: reasons? |
| 15836 | /// * `Drawable` - The specified `drawable` (Window or Pixmap) does not exist. |
| 15837 | /// * `Alloc` - The X server could not allocate the requested resources (no memory?). |
| 15838 | /// |
| 15839 | /// # See |
| 15840 | /// |
| 15841 | /// * `xcb_generate_id`: function |
| 15842 | #[derive (Clone, Copy, Default)] |
| 15843 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 15844 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 15845 | pub struct CreatePixmapRequest { |
| 15846 | pub depth: u8, |
| 15847 | pub pid: Pixmap, |
| 15848 | pub drawable: Drawable, |
| 15849 | pub width: u16, |
| 15850 | pub height: u16, |
| 15851 | } |
| 15852 | impl_debug_if_no_extra_traits!(CreatePixmapRequest, "CreatePixmapRequest" ); |
| 15853 | impl CreatePixmapRequest { |
| 15854 | /// Serialize this request into bytes for the provided connection |
| 15855 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 15856 | let length_so_far = 0; |
| 15857 | let depth_bytes = self.depth.serialize(); |
| 15858 | let pid_bytes = self.pid.serialize(); |
| 15859 | let drawable_bytes = self.drawable.serialize(); |
| 15860 | let width_bytes = self.width.serialize(); |
| 15861 | let height_bytes = self.height.serialize(); |
| 15862 | let mut request0 = vec![ |
| 15863 | CREATE_PIXMAP_REQUEST, |
| 15864 | depth_bytes[0], |
| 15865 | 0, |
| 15866 | 0, |
| 15867 | pid_bytes[0], |
| 15868 | pid_bytes[1], |
| 15869 | pid_bytes[2], |
| 15870 | pid_bytes[3], |
| 15871 | drawable_bytes[0], |
| 15872 | drawable_bytes[1], |
| 15873 | drawable_bytes[2], |
| 15874 | drawable_bytes[3], |
| 15875 | width_bytes[0], |
| 15876 | width_bytes[1], |
| 15877 | height_bytes[0], |
| 15878 | height_bytes[1], |
| 15879 | ]; |
| 15880 | let length_so_far = length_so_far + request0.len(); |
| 15881 | assert_eq!(length_so_far % 4, 0); |
| 15882 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 15883 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 15884 | ([request0.into()], vec![]) |
| 15885 | } |
| 15886 | /// Parse this request given its header, its body, and any fds that go along with it |
| 15887 | #[cfg (feature = "request-parsing" )] |
| 15888 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 15889 | if header.major_opcode != CREATE_PIXMAP_REQUEST { |
| 15890 | return Err(ParseError::InvalidValue); |
| 15891 | } |
| 15892 | let remaining = &[header.minor_opcode]; |
| 15893 | let (depth, remaining) = u8::try_parse(remaining)?; |
| 15894 | let _ = remaining; |
| 15895 | let (pid, remaining) = Pixmap::try_parse(value)?; |
| 15896 | let (drawable, remaining) = Drawable::try_parse(remaining)?; |
| 15897 | let (width, remaining) = u16::try_parse(remaining)?; |
| 15898 | let (height, remaining) = u16::try_parse(remaining)?; |
| 15899 | let _ = remaining; |
| 15900 | Ok(CreatePixmapRequest { |
| 15901 | depth, |
| 15902 | pid, |
| 15903 | drawable, |
| 15904 | width, |
| 15905 | height, |
| 15906 | }) |
| 15907 | } |
| 15908 | } |
| 15909 | impl Request for CreatePixmapRequest { |
| 15910 | const EXTENSION_NAME: Option<&'static str> = None; |
| 15911 | |
| 15912 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 15913 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 15914 | // Flatten the buffers into a single vector |
| 15915 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 15916 | (buf, fds) |
| 15917 | } |
| 15918 | } |
| 15919 | impl crate::x11_utils::VoidRequest for CreatePixmapRequest { |
| 15920 | } |
| 15921 | |
| 15922 | /// Opcode for the FreePixmap request |
| 15923 | pub const FREE_PIXMAP_REQUEST: u8 = 54; |
| 15924 | /// Destroys a pixmap. |
| 15925 | /// |
| 15926 | /// Deletes the association between the pixmap ID and the pixmap. The pixmap |
| 15927 | /// storage will be freed when there are no more references to it. |
| 15928 | /// |
| 15929 | /// # Fields |
| 15930 | /// |
| 15931 | /// * `pixmap` - The pixmap to destroy. |
| 15932 | /// |
| 15933 | /// # Errors |
| 15934 | /// |
| 15935 | /// * `Pixmap` - The specified pixmap does not exist. |
| 15936 | #[derive (Clone, Copy, Default)] |
| 15937 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 15938 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 15939 | pub struct FreePixmapRequest { |
| 15940 | pub pixmap: Pixmap, |
| 15941 | } |
| 15942 | impl_debug_if_no_extra_traits!(FreePixmapRequest, "FreePixmapRequest" ); |
| 15943 | impl FreePixmapRequest { |
| 15944 | /// Serialize this request into bytes for the provided connection |
| 15945 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 15946 | let length_so_far = 0; |
| 15947 | let pixmap_bytes = self.pixmap.serialize(); |
| 15948 | let mut request0 = vec![ |
| 15949 | FREE_PIXMAP_REQUEST, |
| 15950 | 0, |
| 15951 | 0, |
| 15952 | 0, |
| 15953 | pixmap_bytes[0], |
| 15954 | pixmap_bytes[1], |
| 15955 | pixmap_bytes[2], |
| 15956 | pixmap_bytes[3], |
| 15957 | ]; |
| 15958 | let length_so_far = length_so_far + request0.len(); |
| 15959 | assert_eq!(length_so_far % 4, 0); |
| 15960 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 15961 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 15962 | ([request0.into()], vec![]) |
| 15963 | } |
| 15964 | /// Parse this request given its header, its body, and any fds that go along with it |
| 15965 | #[cfg (feature = "request-parsing" )] |
| 15966 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 15967 | if header.major_opcode != FREE_PIXMAP_REQUEST { |
| 15968 | return Err(ParseError::InvalidValue); |
| 15969 | } |
| 15970 | let remaining = &[header.minor_opcode]; |
| 15971 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 15972 | let _ = remaining; |
| 15973 | let (pixmap, remaining) = Pixmap::try_parse(value)?; |
| 15974 | let _ = remaining; |
| 15975 | Ok(FreePixmapRequest { |
| 15976 | pixmap, |
| 15977 | }) |
| 15978 | } |
| 15979 | } |
| 15980 | impl Request for FreePixmapRequest { |
| 15981 | const EXTENSION_NAME: Option<&'static str> = None; |
| 15982 | |
| 15983 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 15984 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 15985 | // Flatten the buffers into a single vector |
| 15986 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 15987 | (buf, fds) |
| 15988 | } |
| 15989 | } |
| 15990 | impl crate::x11_utils::VoidRequest for FreePixmapRequest { |
| 15991 | } |
| 15992 | |
| 15993 | /// # Fields |
| 15994 | /// |
| 15995 | /// * `Function` - TODO: Refer to GX |
| 15996 | /// * `PlaneMask` - In graphics operations, given a source and destination pixel, the result is |
| 15997 | /// computed bitwise on corresponding bits of the pixels; that is, a Boolean |
| 15998 | /// operation is performed in each bit plane. The plane-mask restricts the |
| 15999 | /// operation to a subset of planes, so the result is: |
| 16000 | /// |
| 16001 | /// ((src FUNC dst) AND plane-mask) OR (dst AND (NOT plane-mask)) |
| 16002 | /// * `Foreground` - Foreground colorpixel. |
| 16003 | /// * `Background` - Background colorpixel. |
| 16004 | /// * `LineWidth` - The line-width is measured in pixels and can be greater than or equal to one, a wide line, or the |
| 16005 | /// special value zero, a thin line. |
| 16006 | /// * `LineStyle` - The line-style defines which sections of a line are drawn: |
| 16007 | /// Solid The full path of the line is drawn. |
| 16008 | /// DoubleDash The full path of the line is drawn, but the even dashes are filled differently |
| 16009 | /// than the odd dashes (see fill-style), with Butt cap-style used where even and |
| 16010 | /// odd dashes meet. |
| 16011 | /// OnOffDash Only the even dashes are drawn, and cap-style applies to all internal ends of |
| 16012 | /// the individual dashes (except NotLast is treated as Butt). |
| 16013 | /// * `CapStyle` - The cap-style defines how the endpoints of a path are drawn: |
| 16014 | /// NotLast The result is equivalent to Butt, except that for a line-width of zero the final |
| 16015 | /// endpoint is not drawn. |
| 16016 | /// Butt The result is square at the endpoint (perpendicular to the slope of the line) |
| 16017 | /// with no projection beyond. |
| 16018 | /// Round The result is a circular arc with its diameter equal to the line-width, centered |
| 16019 | /// on the endpoint; it is equivalent to Butt for line-width zero. |
| 16020 | /// Projecting The result is square at the end, but the path continues beyond the endpoint for |
| 16021 | /// a distance equal to half the line-width; it is equivalent to Butt for line-width |
| 16022 | /// zero. |
| 16023 | /// * `JoinStyle` - The join-style defines how corners are drawn for wide lines: |
| 16024 | /// Miter The outer edges of the two lines extend to meet at an angle. However, if the |
| 16025 | /// angle is less than 11 degrees, a Bevel join-style is used instead. |
| 16026 | /// Round The result is a circular arc with a diameter equal to the line-width, centered |
| 16027 | /// on the joinpoint. |
| 16028 | /// Bevel The result is Butt endpoint styles, and then the triangular notch is filled. |
| 16029 | /// * `FillStyle` - The fill-style defines the contents of the source for line, text, and fill requests. For all text and fill |
| 16030 | /// requests (for example, PolyText8, PolyText16, PolyFillRectangle, FillPoly, and PolyFillArc) |
| 16031 | /// as well as for line requests with line-style Solid, (for example, PolyLine, PolySegment, |
| 16032 | /// PolyRectangle, PolyArc) and for the even dashes for line requests with line-style OnOffDash |
| 16033 | /// or DoubleDash: |
| 16034 | /// Solid Foreground |
| 16035 | /// Tiled Tile |
| 16036 | /// OpaqueStippled A tile with the same width and height as stipple but with background |
| 16037 | /// everywhere stipple has a zero and with foreground everywhere stipple |
| 16038 | /// has a one |
| 16039 | /// Stippled Foreground masked by stipple |
| 16040 | /// For the odd dashes for line requests with line-style DoubleDash: |
| 16041 | /// Solid Background |
| 16042 | /// Tiled Same as for even dashes |
| 16043 | /// OpaqueStippled Same as for even dashes |
| 16044 | /// Stippled Background masked by stipple |
| 16045 | /// * `FillRule` - |
| 16046 | /// * `Tile` - The tile/stipple represents an infinite two-dimensional plane with the tile/stipple replicated in all |
| 16047 | /// dimensions. When that plane is superimposed on the drawable for use in a graphics operation, |
| 16048 | /// the upper-left corner of some instance of the tile/stipple is at the coordinates within the drawable |
| 16049 | /// specified by the tile/stipple origin. The tile/stipple and clip origins are interpreted relative to the |
| 16050 | /// origin of whatever destination drawable is specified in a graphics request. |
| 16051 | /// The tile pixmap must have the same root and depth as the gcontext (or a Match error results). |
| 16052 | /// The stipple pixmap must have depth one and must have the same root as the gcontext (or a |
| 16053 | /// Match error results). For fill-style Stippled (but not fill-style |
| 16054 | /// OpaqueStippled), the stipple pattern is tiled in a single plane and acts as an |
| 16055 | /// additional clip mask to be ANDed with the clip-mask. |
| 16056 | /// Any size pixmap can be used for tiling or stippling, although some sizes may be faster to use than |
| 16057 | /// others. |
| 16058 | /// * `Stipple` - The tile/stipple represents an infinite two-dimensional plane with the tile/stipple replicated in all |
| 16059 | /// dimensions. When that plane is superimposed on the drawable for use in a graphics operation, |
| 16060 | /// the upper-left corner of some instance of the tile/stipple is at the coordinates within the drawable |
| 16061 | /// specified by the tile/stipple origin. The tile/stipple and clip origins are interpreted relative to the |
| 16062 | /// origin of whatever destination drawable is specified in a graphics request. |
| 16063 | /// The tile pixmap must have the same root and depth as the gcontext (or a Match error results). |
| 16064 | /// The stipple pixmap must have depth one and must have the same root as the gcontext (or a |
| 16065 | /// Match error results). For fill-style Stippled (but not fill-style |
| 16066 | /// OpaqueStippled), the stipple pattern is tiled in a single plane and acts as an |
| 16067 | /// additional clip mask to be ANDed with the clip-mask. |
| 16068 | /// Any size pixmap can be used for tiling or stippling, although some sizes may be faster to use than |
| 16069 | /// others. |
| 16070 | /// * `TileStippleOriginX` - TODO |
| 16071 | /// * `TileStippleOriginY` - TODO |
| 16072 | /// * `Font` - Which font to use for the `ImageText8` and `ImageText16` requests. |
| 16073 | /// * `SubwindowMode` - For ClipByChildren, both source and destination windows are additionally |
| 16074 | /// clipped by all viewable InputOutput children. For IncludeInferiors, neither |
| 16075 | /// source nor destination window is |
| 16076 | /// clipped by inferiors. This will result in including subwindow contents in the source and drawing |
| 16077 | /// through subwindow boundaries of the destination. The use of IncludeInferiors with a source or |
| 16078 | /// destination window of one depth with mapped inferiors of differing depth is not illegal, but the |
| 16079 | /// semantics is undefined by the core protocol. |
| 16080 | /// * `GraphicsExposures` - Whether ExposureEvents should be generated (1) or not (0). |
| 16081 | /// |
| 16082 | /// The default is 1. |
| 16083 | /// * `ClipOriginX` - TODO |
| 16084 | /// * `ClipOriginY` - TODO |
| 16085 | /// * `ClipMask` - The clip-mask restricts writes to the destination drawable. Only pixels where the clip-mask has |
| 16086 | /// bits set to 1 are drawn. Pixels are not drawn outside the area covered by the clip-mask or where |
| 16087 | /// the clip-mask has bits set to 0. The clip-mask affects all graphics requests, but it does not clip |
| 16088 | /// sources. The clip-mask origin is interpreted relative to the origin of whatever destination drawable is specified in a graphics request. If a pixmap is specified as the clip-mask, it must have |
| 16089 | /// depth 1 and have the same root as the gcontext (or a Match error results). If clip-mask is None, |
| 16090 | /// then pixels are always drawn, regardless of the clip origin. The clip-mask can also be set with the |
| 16091 | /// SetClipRectangles request. |
| 16092 | /// * `DashOffset` - TODO |
| 16093 | /// * `DashList` - TODO |
| 16094 | /// * `ArcMode` - TODO |
| 16095 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 16096 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 16097 | pub struct GC(u32); |
| 16098 | impl GC { |
| 16099 | pub const FUNCTION: Self = Self(1 << 0); |
| 16100 | pub const PLANE_MASK: Self = Self(1 << 1); |
| 16101 | pub const FOREGROUND: Self = Self(1 << 2); |
| 16102 | pub const BACKGROUND: Self = Self(1 << 3); |
| 16103 | pub const LINE_WIDTH: Self = Self(1 << 4); |
| 16104 | pub const LINE_STYLE: Self = Self(1 << 5); |
| 16105 | pub const CAP_STYLE: Self = Self(1 << 6); |
| 16106 | pub const JOIN_STYLE: Self = Self(1 << 7); |
| 16107 | pub const FILL_STYLE: Self = Self(1 << 8); |
| 16108 | pub const FILL_RULE: Self = Self(1 << 9); |
| 16109 | pub const TILE: Self = Self(1 << 10); |
| 16110 | pub const STIPPLE: Self = Self(1 << 11); |
| 16111 | pub const TILE_STIPPLE_ORIGIN_X: Self = Self(1 << 12); |
| 16112 | pub const TILE_STIPPLE_ORIGIN_Y: Self = Self(1 << 13); |
| 16113 | pub const FONT: Self = Self(1 << 14); |
| 16114 | pub const SUBWINDOW_MODE: Self = Self(1 << 15); |
| 16115 | pub const GRAPHICS_EXPOSURES: Self = Self(1 << 16); |
| 16116 | pub const CLIP_ORIGIN_X: Self = Self(1 << 17); |
| 16117 | pub const CLIP_ORIGIN_Y: Self = Self(1 << 18); |
| 16118 | pub const CLIP_MASK: Self = Self(1 << 19); |
| 16119 | pub const DASH_OFFSET: Self = Self(1 << 20); |
| 16120 | pub const DASH_LIST: Self = Self(1 << 21); |
| 16121 | pub const ARC_MODE: Self = Self(1 << 22); |
| 16122 | } |
| 16123 | impl From<GC> for u32 { |
| 16124 | #[inline ] |
| 16125 | fn from(input: GC) -> Self { |
| 16126 | input.0 |
| 16127 | } |
| 16128 | } |
| 16129 | impl From<GC> for Option<u32> { |
| 16130 | #[inline ] |
| 16131 | fn from(input: GC) -> Self { |
| 16132 | Some(input.0) |
| 16133 | } |
| 16134 | } |
| 16135 | impl From<u8> for GC { |
| 16136 | #[inline ] |
| 16137 | fn from(value: u8) -> Self { |
| 16138 | Self(value.into()) |
| 16139 | } |
| 16140 | } |
| 16141 | impl From<u16> for GC { |
| 16142 | #[inline ] |
| 16143 | fn from(value: u16) -> Self { |
| 16144 | Self(value.into()) |
| 16145 | } |
| 16146 | } |
| 16147 | impl From<u32> for GC { |
| 16148 | #[inline ] |
| 16149 | fn from(value: u32) -> Self { |
| 16150 | Self(value) |
| 16151 | } |
| 16152 | } |
| 16153 | impl core::fmt::Debug for GC { |
| 16154 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 16155 | let variants = [ |
| 16156 | (Self::FUNCTION.0, "FUNCTION" , "Function" ), |
| 16157 | (Self::PLANE_MASK.0, "PLANE_MASK" , "PlaneMask" ), |
| 16158 | (Self::FOREGROUND.0, "FOREGROUND" , "Foreground" ), |
| 16159 | (Self::BACKGROUND.0, "BACKGROUND" , "Background" ), |
| 16160 | (Self::LINE_WIDTH.0, "LINE_WIDTH" , "LineWidth" ), |
| 16161 | (Self::LINE_STYLE.0, "LINE_STYLE" , "LineStyle" ), |
| 16162 | (Self::CAP_STYLE.0, "CAP_STYLE" , "CapStyle" ), |
| 16163 | (Self::JOIN_STYLE.0, "JOIN_STYLE" , "JoinStyle" ), |
| 16164 | (Self::FILL_STYLE.0, "FILL_STYLE" , "FillStyle" ), |
| 16165 | (Self::FILL_RULE.0, "FILL_RULE" , "FillRule" ), |
| 16166 | (Self::TILE.0, "TILE" , "Tile" ), |
| 16167 | (Self::STIPPLE.0, "STIPPLE" , "Stipple" ), |
| 16168 | (Self::TILE_STIPPLE_ORIGIN_X.0, "TILE_STIPPLE_ORIGIN_X" , "TileStippleOriginX" ), |
| 16169 | (Self::TILE_STIPPLE_ORIGIN_Y.0, "TILE_STIPPLE_ORIGIN_Y" , "TileStippleOriginY" ), |
| 16170 | (Self::FONT.0, "FONT" , "Font" ), |
| 16171 | (Self::SUBWINDOW_MODE.0, "SUBWINDOW_MODE" , "SubwindowMode" ), |
| 16172 | (Self::GRAPHICS_EXPOSURES.0, "GRAPHICS_EXPOSURES" , "GraphicsExposures" ), |
| 16173 | (Self::CLIP_ORIGIN_X.0, "CLIP_ORIGIN_X" , "ClipOriginX" ), |
| 16174 | (Self::CLIP_ORIGIN_Y.0, "CLIP_ORIGIN_Y" , "ClipOriginY" ), |
| 16175 | (Self::CLIP_MASK.0, "CLIP_MASK" , "ClipMask" ), |
| 16176 | (Self::DASH_OFFSET.0, "DASH_OFFSET" , "DashOffset" ), |
| 16177 | (Self::DASH_LIST.0, "DASH_LIST" , "DashList" ), |
| 16178 | (Self::ARC_MODE.0, "ARC_MODE" , "ArcMode" ), |
| 16179 | ]; |
| 16180 | pretty_print_bitmask(fmt, self.0, &variants) |
| 16181 | } |
| 16182 | } |
| 16183 | bitmask_binop!(GC, u32); |
| 16184 | |
| 16185 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 16186 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 16187 | pub struct GX(u32); |
| 16188 | impl GX { |
| 16189 | pub const CLEAR: Self = Self(0); |
| 16190 | pub const AND: Self = Self(1); |
| 16191 | pub const AND_REVERSE: Self = Self(2); |
| 16192 | pub const COPY: Self = Self(3); |
| 16193 | pub const AND_INVERTED: Self = Self(4); |
| 16194 | pub const NOOP: Self = Self(5); |
| 16195 | pub const XOR: Self = Self(6); |
| 16196 | pub const OR: Self = Self(7); |
| 16197 | pub const NOR: Self = Self(8); |
| 16198 | pub const EQUIV: Self = Self(9); |
| 16199 | pub const INVERT: Self = Self(10); |
| 16200 | pub const OR_REVERSE: Self = Self(11); |
| 16201 | pub const COPY_INVERTED: Self = Self(12); |
| 16202 | pub const OR_INVERTED: Self = Self(13); |
| 16203 | pub const NAND: Self = Self(14); |
| 16204 | pub const SET: Self = Self(15); |
| 16205 | } |
| 16206 | impl From<GX> for u32 { |
| 16207 | #[inline ] |
| 16208 | fn from(input: GX) -> Self { |
| 16209 | input.0 |
| 16210 | } |
| 16211 | } |
| 16212 | impl From<GX> for Option<u32> { |
| 16213 | #[inline ] |
| 16214 | fn from(input: GX) -> Self { |
| 16215 | Some(input.0) |
| 16216 | } |
| 16217 | } |
| 16218 | impl From<u8> for GX { |
| 16219 | #[inline ] |
| 16220 | fn from(value: u8) -> Self { |
| 16221 | Self(value.into()) |
| 16222 | } |
| 16223 | } |
| 16224 | impl From<u16> for GX { |
| 16225 | #[inline ] |
| 16226 | fn from(value: u16) -> Self { |
| 16227 | Self(value.into()) |
| 16228 | } |
| 16229 | } |
| 16230 | impl From<u32> for GX { |
| 16231 | #[inline ] |
| 16232 | fn from(value: u32) -> Self { |
| 16233 | Self(value) |
| 16234 | } |
| 16235 | } |
| 16236 | impl core::fmt::Debug for GX { |
| 16237 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 16238 | let variants: [(u32, &'static str, &'static …); 16] = [ |
| 16239 | (Self::CLEAR.0, "CLEAR" , "Clear" ), |
| 16240 | (Self::AND.0, "AND" , "And" ), |
| 16241 | (Self::AND_REVERSE.0, "AND_REVERSE" , "AndReverse" ), |
| 16242 | (Self::COPY.0, "COPY" , "Copy" ), |
| 16243 | (Self::AND_INVERTED.0, "AND_INVERTED" , "AndInverted" ), |
| 16244 | (Self::NOOP.0, "NOOP" , "Noop" ), |
| 16245 | (Self::XOR.0, "XOR" , "Xor" ), |
| 16246 | (Self::OR.0, "OR" , "Or" ), |
| 16247 | (Self::NOR.0, "NOR" , "Nor" ), |
| 16248 | (Self::EQUIV.0, "EQUIV" , "Equiv" ), |
| 16249 | (Self::INVERT.0, "INVERT" , "Invert" ), |
| 16250 | (Self::OR_REVERSE.0, "OR_REVERSE" , "OrReverse" ), |
| 16251 | (Self::COPY_INVERTED.0, "COPY_INVERTED" , "CopyInverted" ), |
| 16252 | (Self::OR_INVERTED.0, "OR_INVERTED" , "OrInverted" ), |
| 16253 | (Self::NAND.0, "NAND" , "Nand" ), |
| 16254 | (Self::SET.0, "SET" , "Set" ), |
| 16255 | ]; |
| 16256 | pretty_print_enum(fmt, self.0, &variants) |
| 16257 | } |
| 16258 | } |
| 16259 | |
| 16260 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 16261 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 16262 | pub struct LineStyle(u32); |
| 16263 | impl LineStyle { |
| 16264 | pub const SOLID: Self = Self(0); |
| 16265 | pub const ON_OFF_DASH: Self = Self(1); |
| 16266 | pub const DOUBLE_DASH: Self = Self(2); |
| 16267 | } |
| 16268 | impl From<LineStyle> for u32 { |
| 16269 | #[inline ] |
| 16270 | fn from(input: LineStyle) -> Self { |
| 16271 | input.0 |
| 16272 | } |
| 16273 | } |
| 16274 | impl From<LineStyle> for Option<u32> { |
| 16275 | #[inline ] |
| 16276 | fn from(input: LineStyle) -> Self { |
| 16277 | Some(input.0) |
| 16278 | } |
| 16279 | } |
| 16280 | impl From<u8> for LineStyle { |
| 16281 | #[inline ] |
| 16282 | fn from(value: u8) -> Self { |
| 16283 | Self(value.into()) |
| 16284 | } |
| 16285 | } |
| 16286 | impl From<u16> for LineStyle { |
| 16287 | #[inline ] |
| 16288 | fn from(value: u16) -> Self { |
| 16289 | Self(value.into()) |
| 16290 | } |
| 16291 | } |
| 16292 | impl From<u32> for LineStyle { |
| 16293 | #[inline ] |
| 16294 | fn from(value: u32) -> Self { |
| 16295 | Self(value) |
| 16296 | } |
| 16297 | } |
| 16298 | impl core::fmt::Debug for LineStyle { |
| 16299 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 16300 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 16301 | (Self::SOLID.0, "SOLID" , "Solid" ), |
| 16302 | (Self::ON_OFF_DASH.0, "ON_OFF_DASH" , "OnOffDash" ), |
| 16303 | (Self::DOUBLE_DASH.0, "DOUBLE_DASH" , "DoubleDash" ), |
| 16304 | ]; |
| 16305 | pretty_print_enum(fmt, self.0, &variants) |
| 16306 | } |
| 16307 | } |
| 16308 | |
| 16309 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 16310 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 16311 | pub struct CapStyle(u32); |
| 16312 | impl CapStyle { |
| 16313 | pub const NOT_LAST: Self = Self(0); |
| 16314 | pub const BUTT: Self = Self(1); |
| 16315 | pub const ROUND: Self = Self(2); |
| 16316 | pub const PROJECTING: Self = Self(3); |
| 16317 | } |
| 16318 | impl From<CapStyle> for u32 { |
| 16319 | #[inline ] |
| 16320 | fn from(input: CapStyle) -> Self { |
| 16321 | input.0 |
| 16322 | } |
| 16323 | } |
| 16324 | impl From<CapStyle> for Option<u32> { |
| 16325 | #[inline ] |
| 16326 | fn from(input: CapStyle) -> Self { |
| 16327 | Some(input.0) |
| 16328 | } |
| 16329 | } |
| 16330 | impl From<u8> for CapStyle { |
| 16331 | #[inline ] |
| 16332 | fn from(value: u8) -> Self { |
| 16333 | Self(value.into()) |
| 16334 | } |
| 16335 | } |
| 16336 | impl From<u16> for CapStyle { |
| 16337 | #[inline ] |
| 16338 | fn from(value: u16) -> Self { |
| 16339 | Self(value.into()) |
| 16340 | } |
| 16341 | } |
| 16342 | impl From<u32> for CapStyle { |
| 16343 | #[inline ] |
| 16344 | fn from(value: u32) -> Self { |
| 16345 | Self(value) |
| 16346 | } |
| 16347 | } |
| 16348 | impl core::fmt::Debug for CapStyle { |
| 16349 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 16350 | let variants: [(u32, &'static str, &'static …); 4] = [ |
| 16351 | (Self::NOT_LAST.0, "NOT_LAST" , "NotLast" ), |
| 16352 | (Self::BUTT.0, "BUTT" , "Butt" ), |
| 16353 | (Self::ROUND.0, "ROUND" , "Round" ), |
| 16354 | (Self::PROJECTING.0, "PROJECTING" , "Projecting" ), |
| 16355 | ]; |
| 16356 | pretty_print_enum(fmt, self.0, &variants) |
| 16357 | } |
| 16358 | } |
| 16359 | |
| 16360 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 16361 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 16362 | pub struct JoinStyle(u32); |
| 16363 | impl JoinStyle { |
| 16364 | pub const MITER: Self = Self(0); |
| 16365 | pub const ROUND: Self = Self(1); |
| 16366 | pub const BEVEL: Self = Self(2); |
| 16367 | } |
| 16368 | impl From<JoinStyle> for u32 { |
| 16369 | #[inline ] |
| 16370 | fn from(input: JoinStyle) -> Self { |
| 16371 | input.0 |
| 16372 | } |
| 16373 | } |
| 16374 | impl From<JoinStyle> for Option<u32> { |
| 16375 | #[inline ] |
| 16376 | fn from(input: JoinStyle) -> Self { |
| 16377 | Some(input.0) |
| 16378 | } |
| 16379 | } |
| 16380 | impl From<u8> for JoinStyle { |
| 16381 | #[inline ] |
| 16382 | fn from(value: u8) -> Self { |
| 16383 | Self(value.into()) |
| 16384 | } |
| 16385 | } |
| 16386 | impl From<u16> for JoinStyle { |
| 16387 | #[inline ] |
| 16388 | fn from(value: u16) -> Self { |
| 16389 | Self(value.into()) |
| 16390 | } |
| 16391 | } |
| 16392 | impl From<u32> for JoinStyle { |
| 16393 | #[inline ] |
| 16394 | fn from(value: u32) -> Self { |
| 16395 | Self(value) |
| 16396 | } |
| 16397 | } |
| 16398 | impl core::fmt::Debug for JoinStyle { |
| 16399 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 16400 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 16401 | (Self::MITER.0, "MITER" , "Miter" ), |
| 16402 | (Self::ROUND.0, "ROUND" , "Round" ), |
| 16403 | (Self::BEVEL.0, "BEVEL" , "Bevel" ), |
| 16404 | ]; |
| 16405 | pretty_print_enum(fmt, self.0, &variants) |
| 16406 | } |
| 16407 | } |
| 16408 | |
| 16409 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 16410 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 16411 | pub struct FillStyle(u32); |
| 16412 | impl FillStyle { |
| 16413 | pub const SOLID: Self = Self(0); |
| 16414 | pub const TILED: Self = Self(1); |
| 16415 | pub const STIPPLED: Self = Self(2); |
| 16416 | pub const OPAQUE_STIPPLED: Self = Self(3); |
| 16417 | } |
| 16418 | impl From<FillStyle> for u32 { |
| 16419 | #[inline ] |
| 16420 | fn from(input: FillStyle) -> Self { |
| 16421 | input.0 |
| 16422 | } |
| 16423 | } |
| 16424 | impl From<FillStyle> for Option<u32> { |
| 16425 | #[inline ] |
| 16426 | fn from(input: FillStyle) -> Self { |
| 16427 | Some(input.0) |
| 16428 | } |
| 16429 | } |
| 16430 | impl From<u8> for FillStyle { |
| 16431 | #[inline ] |
| 16432 | fn from(value: u8) -> Self { |
| 16433 | Self(value.into()) |
| 16434 | } |
| 16435 | } |
| 16436 | impl From<u16> for FillStyle { |
| 16437 | #[inline ] |
| 16438 | fn from(value: u16) -> Self { |
| 16439 | Self(value.into()) |
| 16440 | } |
| 16441 | } |
| 16442 | impl From<u32> for FillStyle { |
| 16443 | #[inline ] |
| 16444 | fn from(value: u32) -> Self { |
| 16445 | Self(value) |
| 16446 | } |
| 16447 | } |
| 16448 | impl core::fmt::Debug for FillStyle { |
| 16449 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 16450 | let variants: [(u32, &'static str, &'static …); 4] = [ |
| 16451 | (Self::SOLID.0, "SOLID" , "Solid" ), |
| 16452 | (Self::TILED.0, "TILED" , "Tiled" ), |
| 16453 | (Self::STIPPLED.0, "STIPPLED" , "Stippled" ), |
| 16454 | (Self::OPAQUE_STIPPLED.0, "OPAQUE_STIPPLED" , "OpaqueStippled" ), |
| 16455 | ]; |
| 16456 | pretty_print_enum(fmt, self.0, &variants) |
| 16457 | } |
| 16458 | } |
| 16459 | |
| 16460 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 16461 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 16462 | pub struct FillRule(u32); |
| 16463 | impl FillRule { |
| 16464 | pub const EVEN_ODD: Self = Self(0); |
| 16465 | pub const WINDING: Self = Self(1); |
| 16466 | } |
| 16467 | impl From<FillRule> for u32 { |
| 16468 | #[inline ] |
| 16469 | fn from(input: FillRule) -> Self { |
| 16470 | input.0 |
| 16471 | } |
| 16472 | } |
| 16473 | impl From<FillRule> for Option<u32> { |
| 16474 | #[inline ] |
| 16475 | fn from(input: FillRule) -> Self { |
| 16476 | Some(input.0) |
| 16477 | } |
| 16478 | } |
| 16479 | impl From<u8> for FillRule { |
| 16480 | #[inline ] |
| 16481 | fn from(value: u8) -> Self { |
| 16482 | Self(value.into()) |
| 16483 | } |
| 16484 | } |
| 16485 | impl From<u16> for FillRule { |
| 16486 | #[inline ] |
| 16487 | fn from(value: u16) -> Self { |
| 16488 | Self(value.into()) |
| 16489 | } |
| 16490 | } |
| 16491 | impl From<u32> for FillRule { |
| 16492 | #[inline ] |
| 16493 | fn from(value: u32) -> Self { |
| 16494 | Self(value) |
| 16495 | } |
| 16496 | } |
| 16497 | impl core::fmt::Debug for FillRule { |
| 16498 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 16499 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 16500 | (Self::EVEN_ODD.0, "EVEN_ODD" , "EvenOdd" ), |
| 16501 | (Self::WINDING.0, "WINDING" , "Winding" ), |
| 16502 | ]; |
| 16503 | pretty_print_enum(fmt, self.0, &variants) |
| 16504 | } |
| 16505 | } |
| 16506 | |
| 16507 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 16508 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 16509 | pub struct SubwindowMode(u32); |
| 16510 | impl SubwindowMode { |
| 16511 | pub const CLIP_BY_CHILDREN: Self = Self(0); |
| 16512 | pub const INCLUDE_INFERIORS: Self = Self(1); |
| 16513 | } |
| 16514 | impl From<SubwindowMode> for u32 { |
| 16515 | #[inline ] |
| 16516 | fn from(input: SubwindowMode) -> Self { |
| 16517 | input.0 |
| 16518 | } |
| 16519 | } |
| 16520 | impl From<SubwindowMode> for Option<u32> { |
| 16521 | #[inline ] |
| 16522 | fn from(input: SubwindowMode) -> Self { |
| 16523 | Some(input.0) |
| 16524 | } |
| 16525 | } |
| 16526 | impl From<u8> for SubwindowMode { |
| 16527 | #[inline ] |
| 16528 | fn from(value: u8) -> Self { |
| 16529 | Self(value.into()) |
| 16530 | } |
| 16531 | } |
| 16532 | impl From<u16> for SubwindowMode { |
| 16533 | #[inline ] |
| 16534 | fn from(value: u16) -> Self { |
| 16535 | Self(value.into()) |
| 16536 | } |
| 16537 | } |
| 16538 | impl From<u32> for SubwindowMode { |
| 16539 | #[inline ] |
| 16540 | fn from(value: u32) -> Self { |
| 16541 | Self(value) |
| 16542 | } |
| 16543 | } |
| 16544 | impl core::fmt::Debug for SubwindowMode { |
| 16545 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 16546 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 16547 | (Self::CLIP_BY_CHILDREN.0, "CLIP_BY_CHILDREN" , "ClipByChildren" ), |
| 16548 | (Self::INCLUDE_INFERIORS.0, "INCLUDE_INFERIORS" , "IncludeInferiors" ), |
| 16549 | ]; |
| 16550 | pretty_print_enum(fmt, self.0, &variants) |
| 16551 | } |
| 16552 | } |
| 16553 | |
| 16554 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 16555 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 16556 | pub struct ArcMode(u32); |
| 16557 | impl ArcMode { |
| 16558 | pub const CHORD: Self = Self(0); |
| 16559 | pub const PIE_SLICE: Self = Self(1); |
| 16560 | } |
| 16561 | impl From<ArcMode> for u32 { |
| 16562 | #[inline ] |
| 16563 | fn from(input: ArcMode) -> Self { |
| 16564 | input.0 |
| 16565 | } |
| 16566 | } |
| 16567 | impl From<ArcMode> for Option<u32> { |
| 16568 | #[inline ] |
| 16569 | fn from(input: ArcMode) -> Self { |
| 16570 | Some(input.0) |
| 16571 | } |
| 16572 | } |
| 16573 | impl From<u8> for ArcMode { |
| 16574 | #[inline ] |
| 16575 | fn from(value: u8) -> Self { |
| 16576 | Self(value.into()) |
| 16577 | } |
| 16578 | } |
| 16579 | impl From<u16> for ArcMode { |
| 16580 | #[inline ] |
| 16581 | fn from(value: u16) -> Self { |
| 16582 | Self(value.into()) |
| 16583 | } |
| 16584 | } |
| 16585 | impl From<u32> for ArcMode { |
| 16586 | #[inline ] |
| 16587 | fn from(value: u32) -> Self { |
| 16588 | Self(value) |
| 16589 | } |
| 16590 | } |
| 16591 | impl core::fmt::Debug for ArcMode { |
| 16592 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 16593 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 16594 | (Self::CHORD.0, "CHORD" , "Chord" ), |
| 16595 | (Self::PIE_SLICE.0, "PIE_SLICE" , "PieSlice" ), |
| 16596 | ]; |
| 16597 | pretty_print_enum(fmt, self.0, &variants) |
| 16598 | } |
| 16599 | } |
| 16600 | |
| 16601 | /// Auxiliary and optional information for the `create_gc` function |
| 16602 | #[derive (Clone, Copy, Default)] |
| 16603 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 16604 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 16605 | pub struct CreateGCAux { |
| 16606 | pub function: Option<GX>, |
| 16607 | pub plane_mask: Option<u32>, |
| 16608 | pub foreground: Option<u32>, |
| 16609 | pub background: Option<u32>, |
| 16610 | pub line_width: Option<u32>, |
| 16611 | pub line_style: Option<LineStyle>, |
| 16612 | pub cap_style: Option<CapStyle>, |
| 16613 | pub join_style: Option<JoinStyle>, |
| 16614 | pub fill_style: Option<FillStyle>, |
| 16615 | pub fill_rule: Option<FillRule>, |
| 16616 | pub tile: Option<Pixmap>, |
| 16617 | pub stipple: Option<Pixmap>, |
| 16618 | pub tile_stipple_x_origin: Option<i32>, |
| 16619 | pub tile_stipple_y_origin: Option<i32>, |
| 16620 | pub font: Option<Font>, |
| 16621 | pub subwindow_mode: Option<SubwindowMode>, |
| 16622 | pub graphics_exposures: Option<Bool32>, |
| 16623 | pub clip_x_origin: Option<i32>, |
| 16624 | pub clip_y_origin: Option<i32>, |
| 16625 | pub clip_mask: Option<Pixmap>, |
| 16626 | pub dash_offset: Option<u32>, |
| 16627 | pub dashes: Option<u32>, |
| 16628 | pub arc_mode: Option<ArcMode>, |
| 16629 | } |
| 16630 | impl_debug_if_no_extra_traits!(CreateGCAux, "CreateGCAux" ); |
| 16631 | impl CreateGCAux { |
| 16632 | #[cfg_attr (not(feature = "request-parsing" ), allow(dead_code))] |
| 16633 | fn try_parse(value: &[u8], value_mask: u32) -> Result<(Self, &[u8]), ParseError> { |
| 16634 | let switch_expr = u32::from(value_mask); |
| 16635 | let mut outer_remaining = value; |
| 16636 | let function = if switch_expr & u32::from(GC::FUNCTION) != 0 { |
| 16637 | let remaining = outer_remaining; |
| 16638 | let (function, remaining) = u32::try_parse(remaining)?; |
| 16639 | let function = function.into(); |
| 16640 | outer_remaining = remaining; |
| 16641 | Some(function) |
| 16642 | } else { |
| 16643 | None |
| 16644 | }; |
| 16645 | let plane_mask = if switch_expr & u32::from(GC::PLANE_MASK) != 0 { |
| 16646 | let remaining = outer_remaining; |
| 16647 | let (plane_mask, remaining) = u32::try_parse(remaining)?; |
| 16648 | outer_remaining = remaining; |
| 16649 | Some(plane_mask) |
| 16650 | } else { |
| 16651 | None |
| 16652 | }; |
| 16653 | let foreground = if switch_expr & u32::from(GC::FOREGROUND) != 0 { |
| 16654 | let remaining = outer_remaining; |
| 16655 | let (foreground, remaining) = u32::try_parse(remaining)?; |
| 16656 | outer_remaining = remaining; |
| 16657 | Some(foreground) |
| 16658 | } else { |
| 16659 | None |
| 16660 | }; |
| 16661 | let background = if switch_expr & u32::from(GC::BACKGROUND) != 0 { |
| 16662 | let remaining = outer_remaining; |
| 16663 | let (background, remaining) = u32::try_parse(remaining)?; |
| 16664 | outer_remaining = remaining; |
| 16665 | Some(background) |
| 16666 | } else { |
| 16667 | None |
| 16668 | }; |
| 16669 | let line_width = if switch_expr & u32::from(GC::LINE_WIDTH) != 0 { |
| 16670 | let remaining = outer_remaining; |
| 16671 | let (line_width, remaining) = u32::try_parse(remaining)?; |
| 16672 | outer_remaining = remaining; |
| 16673 | Some(line_width) |
| 16674 | } else { |
| 16675 | None |
| 16676 | }; |
| 16677 | let line_style = if switch_expr & u32::from(GC::LINE_STYLE) != 0 { |
| 16678 | let remaining = outer_remaining; |
| 16679 | let (line_style, remaining) = u32::try_parse(remaining)?; |
| 16680 | let line_style = line_style.into(); |
| 16681 | outer_remaining = remaining; |
| 16682 | Some(line_style) |
| 16683 | } else { |
| 16684 | None |
| 16685 | }; |
| 16686 | let cap_style = if switch_expr & u32::from(GC::CAP_STYLE) != 0 { |
| 16687 | let remaining = outer_remaining; |
| 16688 | let (cap_style, remaining) = u32::try_parse(remaining)?; |
| 16689 | let cap_style = cap_style.into(); |
| 16690 | outer_remaining = remaining; |
| 16691 | Some(cap_style) |
| 16692 | } else { |
| 16693 | None |
| 16694 | }; |
| 16695 | let join_style = if switch_expr & u32::from(GC::JOIN_STYLE) != 0 { |
| 16696 | let remaining = outer_remaining; |
| 16697 | let (join_style, remaining) = u32::try_parse(remaining)?; |
| 16698 | let join_style = join_style.into(); |
| 16699 | outer_remaining = remaining; |
| 16700 | Some(join_style) |
| 16701 | } else { |
| 16702 | None |
| 16703 | }; |
| 16704 | let fill_style = if switch_expr & u32::from(GC::FILL_STYLE) != 0 { |
| 16705 | let remaining = outer_remaining; |
| 16706 | let (fill_style, remaining) = u32::try_parse(remaining)?; |
| 16707 | let fill_style = fill_style.into(); |
| 16708 | outer_remaining = remaining; |
| 16709 | Some(fill_style) |
| 16710 | } else { |
| 16711 | None |
| 16712 | }; |
| 16713 | let fill_rule = if switch_expr & u32::from(GC::FILL_RULE) != 0 { |
| 16714 | let remaining = outer_remaining; |
| 16715 | let (fill_rule, remaining) = u32::try_parse(remaining)?; |
| 16716 | let fill_rule = fill_rule.into(); |
| 16717 | outer_remaining = remaining; |
| 16718 | Some(fill_rule) |
| 16719 | } else { |
| 16720 | None |
| 16721 | }; |
| 16722 | let tile = if switch_expr & u32::from(GC::TILE) != 0 { |
| 16723 | let remaining = outer_remaining; |
| 16724 | let (tile, remaining) = Pixmap::try_parse(remaining)?; |
| 16725 | outer_remaining = remaining; |
| 16726 | Some(tile) |
| 16727 | } else { |
| 16728 | None |
| 16729 | }; |
| 16730 | let stipple = if switch_expr & u32::from(GC::STIPPLE) != 0 { |
| 16731 | let remaining = outer_remaining; |
| 16732 | let (stipple, remaining) = Pixmap::try_parse(remaining)?; |
| 16733 | outer_remaining = remaining; |
| 16734 | Some(stipple) |
| 16735 | } else { |
| 16736 | None |
| 16737 | }; |
| 16738 | let tile_stipple_x_origin = if switch_expr & u32::from(GC::TILE_STIPPLE_ORIGIN_X) != 0 { |
| 16739 | let remaining = outer_remaining; |
| 16740 | let (tile_stipple_x_origin, remaining) = i32::try_parse(remaining)?; |
| 16741 | outer_remaining = remaining; |
| 16742 | Some(tile_stipple_x_origin) |
| 16743 | } else { |
| 16744 | None |
| 16745 | }; |
| 16746 | let tile_stipple_y_origin = if switch_expr & u32::from(GC::TILE_STIPPLE_ORIGIN_Y) != 0 { |
| 16747 | let remaining = outer_remaining; |
| 16748 | let (tile_stipple_y_origin, remaining) = i32::try_parse(remaining)?; |
| 16749 | outer_remaining = remaining; |
| 16750 | Some(tile_stipple_y_origin) |
| 16751 | } else { |
| 16752 | None |
| 16753 | }; |
| 16754 | let font = if switch_expr & u32::from(GC::FONT) != 0 { |
| 16755 | let remaining = outer_remaining; |
| 16756 | let (font, remaining) = Font::try_parse(remaining)?; |
| 16757 | outer_remaining = remaining; |
| 16758 | Some(font) |
| 16759 | } else { |
| 16760 | None |
| 16761 | }; |
| 16762 | let subwindow_mode = if switch_expr & u32::from(GC::SUBWINDOW_MODE) != 0 { |
| 16763 | let remaining = outer_remaining; |
| 16764 | let (subwindow_mode, remaining) = u32::try_parse(remaining)?; |
| 16765 | let subwindow_mode = subwindow_mode.into(); |
| 16766 | outer_remaining = remaining; |
| 16767 | Some(subwindow_mode) |
| 16768 | } else { |
| 16769 | None |
| 16770 | }; |
| 16771 | let graphics_exposures = if switch_expr & u32::from(GC::GRAPHICS_EXPOSURES) != 0 { |
| 16772 | let remaining = outer_remaining; |
| 16773 | let (graphics_exposures, remaining) = Bool32::try_parse(remaining)?; |
| 16774 | outer_remaining = remaining; |
| 16775 | Some(graphics_exposures) |
| 16776 | } else { |
| 16777 | None |
| 16778 | }; |
| 16779 | let clip_x_origin = if switch_expr & u32::from(GC::CLIP_ORIGIN_X) != 0 { |
| 16780 | let remaining = outer_remaining; |
| 16781 | let (clip_x_origin, remaining) = i32::try_parse(remaining)?; |
| 16782 | outer_remaining = remaining; |
| 16783 | Some(clip_x_origin) |
| 16784 | } else { |
| 16785 | None |
| 16786 | }; |
| 16787 | let clip_y_origin = if switch_expr & u32::from(GC::CLIP_ORIGIN_Y) != 0 { |
| 16788 | let remaining = outer_remaining; |
| 16789 | let (clip_y_origin, remaining) = i32::try_parse(remaining)?; |
| 16790 | outer_remaining = remaining; |
| 16791 | Some(clip_y_origin) |
| 16792 | } else { |
| 16793 | None |
| 16794 | }; |
| 16795 | let clip_mask = if switch_expr & u32::from(GC::CLIP_MASK) != 0 { |
| 16796 | let remaining = outer_remaining; |
| 16797 | let (clip_mask, remaining) = Pixmap::try_parse(remaining)?; |
| 16798 | outer_remaining = remaining; |
| 16799 | Some(clip_mask) |
| 16800 | } else { |
| 16801 | None |
| 16802 | }; |
| 16803 | let dash_offset = if switch_expr & u32::from(GC::DASH_OFFSET) != 0 { |
| 16804 | let remaining = outer_remaining; |
| 16805 | let (dash_offset, remaining) = u32::try_parse(remaining)?; |
| 16806 | outer_remaining = remaining; |
| 16807 | Some(dash_offset) |
| 16808 | } else { |
| 16809 | None |
| 16810 | }; |
| 16811 | let dashes = if switch_expr & u32::from(GC::DASH_LIST) != 0 { |
| 16812 | let remaining = outer_remaining; |
| 16813 | let (dashes, remaining) = u32::try_parse(remaining)?; |
| 16814 | outer_remaining = remaining; |
| 16815 | Some(dashes) |
| 16816 | } else { |
| 16817 | None |
| 16818 | }; |
| 16819 | let arc_mode = if switch_expr & u32::from(GC::ARC_MODE) != 0 { |
| 16820 | let remaining = outer_remaining; |
| 16821 | let (arc_mode, remaining) = u32::try_parse(remaining)?; |
| 16822 | let arc_mode = arc_mode.into(); |
| 16823 | outer_remaining = remaining; |
| 16824 | Some(arc_mode) |
| 16825 | } else { |
| 16826 | None |
| 16827 | }; |
| 16828 | let result = CreateGCAux { function, plane_mask, foreground, background, line_width, line_style, cap_style, join_style, fill_style, fill_rule, tile, stipple, tile_stipple_x_origin, tile_stipple_y_origin, font, subwindow_mode, graphics_exposures, clip_x_origin, clip_y_origin, clip_mask, dash_offset, dashes, arc_mode }; |
| 16829 | Ok((result, outer_remaining)) |
| 16830 | } |
| 16831 | } |
| 16832 | impl CreateGCAux { |
| 16833 | #[allow (dead_code)] |
| 16834 | fn serialize(&self, value_mask: u32) -> Vec<u8> { |
| 16835 | let mut result = Vec::new(); |
| 16836 | self.serialize_into(&mut result, u32::from(value_mask)); |
| 16837 | result |
| 16838 | } |
| 16839 | fn serialize_into(&self, bytes: &mut Vec<u8>, value_mask: u32) { |
| 16840 | assert_eq!(self.switch_expr(), u32::from(value_mask), "switch `value_list` has an inconsistent discriminant" ); |
| 16841 | if let Some(function) = self.function { |
| 16842 | u32::from(function).serialize_into(bytes); |
| 16843 | } |
| 16844 | if let Some(plane_mask) = self.plane_mask { |
| 16845 | plane_mask.serialize_into(bytes); |
| 16846 | } |
| 16847 | if let Some(foreground) = self.foreground { |
| 16848 | foreground.serialize_into(bytes); |
| 16849 | } |
| 16850 | if let Some(background) = self.background { |
| 16851 | background.serialize_into(bytes); |
| 16852 | } |
| 16853 | if let Some(line_width) = self.line_width { |
| 16854 | line_width.serialize_into(bytes); |
| 16855 | } |
| 16856 | if let Some(line_style) = self.line_style { |
| 16857 | u32::from(line_style).serialize_into(bytes); |
| 16858 | } |
| 16859 | if let Some(cap_style) = self.cap_style { |
| 16860 | u32::from(cap_style).serialize_into(bytes); |
| 16861 | } |
| 16862 | if let Some(join_style) = self.join_style { |
| 16863 | u32::from(join_style).serialize_into(bytes); |
| 16864 | } |
| 16865 | if let Some(fill_style) = self.fill_style { |
| 16866 | u32::from(fill_style).serialize_into(bytes); |
| 16867 | } |
| 16868 | if let Some(fill_rule) = self.fill_rule { |
| 16869 | u32::from(fill_rule).serialize_into(bytes); |
| 16870 | } |
| 16871 | if let Some(tile) = self.tile { |
| 16872 | tile.serialize_into(bytes); |
| 16873 | } |
| 16874 | if let Some(stipple) = self.stipple { |
| 16875 | stipple.serialize_into(bytes); |
| 16876 | } |
| 16877 | if let Some(tile_stipple_x_origin) = self.tile_stipple_x_origin { |
| 16878 | tile_stipple_x_origin.serialize_into(bytes); |
| 16879 | } |
| 16880 | if let Some(tile_stipple_y_origin) = self.tile_stipple_y_origin { |
| 16881 | tile_stipple_y_origin.serialize_into(bytes); |
| 16882 | } |
| 16883 | if let Some(font) = self.font { |
| 16884 | font.serialize_into(bytes); |
| 16885 | } |
| 16886 | if let Some(subwindow_mode) = self.subwindow_mode { |
| 16887 | u32::from(subwindow_mode).serialize_into(bytes); |
| 16888 | } |
| 16889 | if let Some(graphics_exposures) = self.graphics_exposures { |
| 16890 | graphics_exposures.serialize_into(bytes); |
| 16891 | } |
| 16892 | if let Some(clip_x_origin) = self.clip_x_origin { |
| 16893 | clip_x_origin.serialize_into(bytes); |
| 16894 | } |
| 16895 | if let Some(clip_y_origin) = self.clip_y_origin { |
| 16896 | clip_y_origin.serialize_into(bytes); |
| 16897 | } |
| 16898 | if let Some(clip_mask) = self.clip_mask { |
| 16899 | clip_mask.serialize_into(bytes); |
| 16900 | } |
| 16901 | if let Some(dash_offset) = self.dash_offset { |
| 16902 | dash_offset.serialize_into(bytes); |
| 16903 | } |
| 16904 | if let Some(dashes) = self.dashes { |
| 16905 | dashes.serialize_into(bytes); |
| 16906 | } |
| 16907 | if let Some(arc_mode) = self.arc_mode { |
| 16908 | u32::from(arc_mode).serialize_into(bytes); |
| 16909 | } |
| 16910 | } |
| 16911 | } |
| 16912 | impl CreateGCAux { |
| 16913 | fn switch_expr(&self) -> u32 { |
| 16914 | let mut expr_value = 0; |
| 16915 | if self.function.is_some() { |
| 16916 | expr_value |= u32::from(GC::FUNCTION); |
| 16917 | } |
| 16918 | if self.plane_mask.is_some() { |
| 16919 | expr_value |= u32::from(GC::PLANE_MASK); |
| 16920 | } |
| 16921 | if self.foreground.is_some() { |
| 16922 | expr_value |= u32::from(GC::FOREGROUND); |
| 16923 | } |
| 16924 | if self.background.is_some() { |
| 16925 | expr_value |= u32::from(GC::BACKGROUND); |
| 16926 | } |
| 16927 | if self.line_width.is_some() { |
| 16928 | expr_value |= u32::from(GC::LINE_WIDTH); |
| 16929 | } |
| 16930 | if self.line_style.is_some() { |
| 16931 | expr_value |= u32::from(GC::LINE_STYLE); |
| 16932 | } |
| 16933 | if self.cap_style.is_some() { |
| 16934 | expr_value |= u32::from(GC::CAP_STYLE); |
| 16935 | } |
| 16936 | if self.join_style.is_some() { |
| 16937 | expr_value |= u32::from(GC::JOIN_STYLE); |
| 16938 | } |
| 16939 | if self.fill_style.is_some() { |
| 16940 | expr_value |= u32::from(GC::FILL_STYLE); |
| 16941 | } |
| 16942 | if self.fill_rule.is_some() { |
| 16943 | expr_value |= u32::from(GC::FILL_RULE); |
| 16944 | } |
| 16945 | if self.tile.is_some() { |
| 16946 | expr_value |= u32::from(GC::TILE); |
| 16947 | } |
| 16948 | if self.stipple.is_some() { |
| 16949 | expr_value |= u32::from(GC::STIPPLE); |
| 16950 | } |
| 16951 | if self.tile_stipple_x_origin.is_some() { |
| 16952 | expr_value |= u32::from(GC::TILE_STIPPLE_ORIGIN_X); |
| 16953 | } |
| 16954 | if self.tile_stipple_y_origin.is_some() { |
| 16955 | expr_value |= u32::from(GC::TILE_STIPPLE_ORIGIN_Y); |
| 16956 | } |
| 16957 | if self.font.is_some() { |
| 16958 | expr_value |= u32::from(GC::FONT); |
| 16959 | } |
| 16960 | if self.subwindow_mode.is_some() { |
| 16961 | expr_value |= u32::from(GC::SUBWINDOW_MODE); |
| 16962 | } |
| 16963 | if self.graphics_exposures.is_some() { |
| 16964 | expr_value |= u32::from(GC::GRAPHICS_EXPOSURES); |
| 16965 | } |
| 16966 | if self.clip_x_origin.is_some() { |
| 16967 | expr_value |= u32::from(GC::CLIP_ORIGIN_X); |
| 16968 | } |
| 16969 | if self.clip_y_origin.is_some() { |
| 16970 | expr_value |= u32::from(GC::CLIP_ORIGIN_Y); |
| 16971 | } |
| 16972 | if self.clip_mask.is_some() { |
| 16973 | expr_value |= u32::from(GC::CLIP_MASK); |
| 16974 | } |
| 16975 | if self.dash_offset.is_some() { |
| 16976 | expr_value |= u32::from(GC::DASH_OFFSET); |
| 16977 | } |
| 16978 | if self.dashes.is_some() { |
| 16979 | expr_value |= u32::from(GC::DASH_LIST); |
| 16980 | } |
| 16981 | if self.arc_mode.is_some() { |
| 16982 | expr_value |= u32::from(GC::ARC_MODE); |
| 16983 | } |
| 16984 | expr_value |
| 16985 | } |
| 16986 | } |
| 16987 | impl CreateGCAux { |
| 16988 | /// Create a new instance with all fields unset / not present. |
| 16989 | pub fn new() -> Self { |
| 16990 | Default::default() |
| 16991 | } |
| 16992 | /// Set the `function` field of this structure. |
| 16993 | #[must_use ] |
| 16994 | pub fn function<I>(mut self, value: I) -> Self where I: Into<Option<GX>> { |
| 16995 | self.function = value.into(); |
| 16996 | self |
| 16997 | } |
| 16998 | /// Set the `plane_mask` field of this structure. |
| 16999 | #[must_use ] |
| 17000 | pub fn plane_mask<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 17001 | self.plane_mask = value.into(); |
| 17002 | self |
| 17003 | } |
| 17004 | /// Set the `foreground` field of this structure. |
| 17005 | #[must_use ] |
| 17006 | pub fn foreground<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 17007 | self.foreground = value.into(); |
| 17008 | self |
| 17009 | } |
| 17010 | /// Set the `background` field of this structure. |
| 17011 | #[must_use ] |
| 17012 | pub fn background<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 17013 | self.background = value.into(); |
| 17014 | self |
| 17015 | } |
| 17016 | /// Set the `line_width` field of this structure. |
| 17017 | #[must_use ] |
| 17018 | pub fn line_width<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 17019 | self.line_width = value.into(); |
| 17020 | self |
| 17021 | } |
| 17022 | /// Set the `line_style` field of this structure. |
| 17023 | #[must_use ] |
| 17024 | pub fn line_style<I>(mut self, value: I) -> Self where I: Into<Option<LineStyle>> { |
| 17025 | self.line_style = value.into(); |
| 17026 | self |
| 17027 | } |
| 17028 | /// Set the `cap_style` field of this structure. |
| 17029 | #[must_use ] |
| 17030 | pub fn cap_style<I>(mut self, value: I) -> Self where I: Into<Option<CapStyle>> { |
| 17031 | self.cap_style = value.into(); |
| 17032 | self |
| 17033 | } |
| 17034 | /// Set the `join_style` field of this structure. |
| 17035 | #[must_use ] |
| 17036 | pub fn join_style<I>(mut self, value: I) -> Self where I: Into<Option<JoinStyle>> { |
| 17037 | self.join_style = value.into(); |
| 17038 | self |
| 17039 | } |
| 17040 | /// Set the `fill_style` field of this structure. |
| 17041 | #[must_use ] |
| 17042 | pub fn fill_style<I>(mut self, value: I) -> Self where I: Into<Option<FillStyle>> { |
| 17043 | self.fill_style = value.into(); |
| 17044 | self |
| 17045 | } |
| 17046 | /// Set the `fill_rule` field of this structure. |
| 17047 | #[must_use ] |
| 17048 | pub fn fill_rule<I>(mut self, value: I) -> Self where I: Into<Option<FillRule>> { |
| 17049 | self.fill_rule = value.into(); |
| 17050 | self |
| 17051 | } |
| 17052 | /// Set the `tile` field of this structure. |
| 17053 | #[must_use ] |
| 17054 | pub fn tile<I>(mut self, value: I) -> Self where I: Into<Option<Pixmap>> { |
| 17055 | self.tile = value.into(); |
| 17056 | self |
| 17057 | } |
| 17058 | /// Set the `stipple` field of this structure. |
| 17059 | #[must_use ] |
| 17060 | pub fn stipple<I>(mut self, value: I) -> Self where I: Into<Option<Pixmap>> { |
| 17061 | self.stipple = value.into(); |
| 17062 | self |
| 17063 | } |
| 17064 | /// Set the `tile_stipple_x_origin` field of this structure. |
| 17065 | #[must_use ] |
| 17066 | pub fn tile_stipple_x_origin<I>(mut self, value: I) -> Self where I: Into<Option<i32>> { |
| 17067 | self.tile_stipple_x_origin = value.into(); |
| 17068 | self |
| 17069 | } |
| 17070 | /// Set the `tile_stipple_y_origin` field of this structure. |
| 17071 | #[must_use ] |
| 17072 | pub fn tile_stipple_y_origin<I>(mut self, value: I) -> Self where I: Into<Option<i32>> { |
| 17073 | self.tile_stipple_y_origin = value.into(); |
| 17074 | self |
| 17075 | } |
| 17076 | /// Set the `font` field of this structure. |
| 17077 | #[must_use ] |
| 17078 | pub fn font<I>(mut self, value: I) -> Self where I: Into<Option<Font>> { |
| 17079 | self.font = value.into(); |
| 17080 | self |
| 17081 | } |
| 17082 | /// Set the `subwindow_mode` field of this structure. |
| 17083 | #[must_use ] |
| 17084 | pub fn subwindow_mode<I>(mut self, value: I) -> Self where I: Into<Option<SubwindowMode>> { |
| 17085 | self.subwindow_mode = value.into(); |
| 17086 | self |
| 17087 | } |
| 17088 | /// Set the `graphics_exposures` field of this structure. |
| 17089 | #[must_use ] |
| 17090 | pub fn graphics_exposures<I>(mut self, value: I) -> Self where I: Into<Option<Bool32>> { |
| 17091 | self.graphics_exposures = value.into(); |
| 17092 | self |
| 17093 | } |
| 17094 | /// Set the `clip_x_origin` field of this structure. |
| 17095 | #[must_use ] |
| 17096 | pub fn clip_x_origin<I>(mut self, value: I) -> Self where I: Into<Option<i32>> { |
| 17097 | self.clip_x_origin = value.into(); |
| 17098 | self |
| 17099 | } |
| 17100 | /// Set the `clip_y_origin` field of this structure. |
| 17101 | #[must_use ] |
| 17102 | pub fn clip_y_origin<I>(mut self, value: I) -> Self where I: Into<Option<i32>> { |
| 17103 | self.clip_y_origin = value.into(); |
| 17104 | self |
| 17105 | } |
| 17106 | /// Set the `clip_mask` field of this structure. |
| 17107 | #[must_use ] |
| 17108 | pub fn clip_mask<I>(mut self, value: I) -> Self where I: Into<Option<Pixmap>> { |
| 17109 | self.clip_mask = value.into(); |
| 17110 | self |
| 17111 | } |
| 17112 | /// Set the `dash_offset` field of this structure. |
| 17113 | #[must_use ] |
| 17114 | pub fn dash_offset<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 17115 | self.dash_offset = value.into(); |
| 17116 | self |
| 17117 | } |
| 17118 | /// Set the `dashes` field of this structure. |
| 17119 | #[must_use ] |
| 17120 | pub fn dashes<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 17121 | self.dashes = value.into(); |
| 17122 | self |
| 17123 | } |
| 17124 | /// Set the `arc_mode` field of this structure. |
| 17125 | #[must_use ] |
| 17126 | pub fn arc_mode<I>(mut self, value: I) -> Self where I: Into<Option<ArcMode>> { |
| 17127 | self.arc_mode = value.into(); |
| 17128 | self |
| 17129 | } |
| 17130 | } |
| 17131 | |
| 17132 | /// Opcode for the CreateGC request |
| 17133 | pub const CREATE_GC_REQUEST: u8 = 55; |
| 17134 | /// Creates a graphics context. |
| 17135 | /// |
| 17136 | /// Creates a graphics context. The graphics context can be used with any drawable |
| 17137 | /// that has the same root and depth as the specified drawable. |
| 17138 | /// |
| 17139 | /// # Fields |
| 17140 | /// |
| 17141 | /// * `cid` - The ID with which you will refer to the graphics context, created by |
| 17142 | /// `xcb_generate_id`. |
| 17143 | /// * `drawable` - Drawable to get the root/depth from. |
| 17144 | /// |
| 17145 | /// # Errors |
| 17146 | /// |
| 17147 | /// * `Drawable` - The specified `drawable` (Window or Pixmap) does not exist. |
| 17148 | /// * `Match` - TODO: reasons? |
| 17149 | /// * `Font` - TODO: reasons? |
| 17150 | /// * `Pixmap` - TODO: reasons? |
| 17151 | /// * `Value` - TODO: reasons? |
| 17152 | /// * `Alloc` - The X server could not allocate the requested resources (no memory?). |
| 17153 | /// |
| 17154 | /// # See |
| 17155 | /// |
| 17156 | /// * `xcb_generate_id`: function |
| 17157 | #[derive (Clone, Default)] |
| 17158 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 17159 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 17160 | pub struct CreateGCRequest<'input> { |
| 17161 | pub cid: Gcontext, |
| 17162 | pub drawable: Drawable, |
| 17163 | pub value_list: Cow<'input, CreateGCAux>, |
| 17164 | } |
| 17165 | impl_debug_if_no_extra_traits!(CreateGCRequest<'_>, "CreateGCRequest" ); |
| 17166 | impl<'input> CreateGCRequest<'input> { |
| 17167 | /// Serialize this request into bytes for the provided connection |
| 17168 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 17169 | let length_so_far = 0; |
| 17170 | let cid_bytes = self.cid.serialize(); |
| 17171 | let drawable_bytes = self.drawable.serialize(); |
| 17172 | let value_mask: u32 = self.value_list.switch_expr(); |
| 17173 | let value_mask_bytes = value_mask.serialize(); |
| 17174 | let mut request0 = vec![ |
| 17175 | CREATE_GC_REQUEST, |
| 17176 | 0, |
| 17177 | 0, |
| 17178 | 0, |
| 17179 | cid_bytes[0], |
| 17180 | cid_bytes[1], |
| 17181 | cid_bytes[2], |
| 17182 | cid_bytes[3], |
| 17183 | drawable_bytes[0], |
| 17184 | drawable_bytes[1], |
| 17185 | drawable_bytes[2], |
| 17186 | drawable_bytes[3], |
| 17187 | value_mask_bytes[0], |
| 17188 | value_mask_bytes[1], |
| 17189 | value_mask_bytes[2], |
| 17190 | value_mask_bytes[3], |
| 17191 | ]; |
| 17192 | let length_so_far = length_so_far + request0.len(); |
| 17193 | let value_list_bytes = self.value_list.serialize(u32::from(value_mask)); |
| 17194 | let length_so_far = length_so_far + value_list_bytes.len(); |
| 17195 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 17196 | let length_so_far = length_so_far + padding0.len(); |
| 17197 | assert_eq!(length_so_far % 4, 0); |
| 17198 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 17199 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 17200 | ([request0.into(), value_list_bytes.into(), padding0.into()], vec![]) |
| 17201 | } |
| 17202 | /// Parse this request given its header, its body, and any fds that go along with it |
| 17203 | #[cfg (feature = "request-parsing" )] |
| 17204 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 17205 | if header.major_opcode != CREATE_GC_REQUEST { |
| 17206 | return Err(ParseError::InvalidValue); |
| 17207 | } |
| 17208 | let remaining = &[header.minor_opcode]; |
| 17209 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 17210 | let _ = remaining; |
| 17211 | let (cid, remaining) = Gcontext::try_parse(value)?; |
| 17212 | let (drawable, remaining) = Drawable::try_parse(remaining)?; |
| 17213 | let (value_mask, remaining) = u32::try_parse(remaining)?; |
| 17214 | let (value_list, remaining) = CreateGCAux::try_parse(remaining, u32::from(value_mask))?; |
| 17215 | let _ = remaining; |
| 17216 | Ok(CreateGCRequest { |
| 17217 | cid, |
| 17218 | drawable, |
| 17219 | value_list: Cow::Owned(value_list), |
| 17220 | }) |
| 17221 | } |
| 17222 | /// Clone all borrowed data in this CreateGCRequest. |
| 17223 | pub fn into_owned(self) -> CreateGCRequest<'static> { |
| 17224 | CreateGCRequest { |
| 17225 | cid: self.cid, |
| 17226 | drawable: self.drawable, |
| 17227 | value_list: Cow::Owned(self.value_list.into_owned()), |
| 17228 | } |
| 17229 | } |
| 17230 | } |
| 17231 | impl<'input> Request for CreateGCRequest<'input> { |
| 17232 | const EXTENSION_NAME: Option<&'static str> = None; |
| 17233 | |
| 17234 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 17235 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 17236 | // Flatten the buffers into a single vector |
| 17237 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 17238 | (buf, fds) |
| 17239 | } |
| 17240 | } |
| 17241 | impl<'input> crate::x11_utils::VoidRequest for CreateGCRequest<'input> { |
| 17242 | } |
| 17243 | |
| 17244 | /// Auxiliary and optional information for the `change_gc` function |
| 17245 | #[derive (Clone, Copy, Default)] |
| 17246 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 17247 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 17248 | pub struct ChangeGCAux { |
| 17249 | pub function: Option<GX>, |
| 17250 | pub plane_mask: Option<u32>, |
| 17251 | pub foreground: Option<u32>, |
| 17252 | pub background: Option<u32>, |
| 17253 | pub line_width: Option<u32>, |
| 17254 | pub line_style: Option<LineStyle>, |
| 17255 | pub cap_style: Option<CapStyle>, |
| 17256 | pub join_style: Option<JoinStyle>, |
| 17257 | pub fill_style: Option<FillStyle>, |
| 17258 | pub fill_rule: Option<FillRule>, |
| 17259 | pub tile: Option<Pixmap>, |
| 17260 | pub stipple: Option<Pixmap>, |
| 17261 | pub tile_stipple_x_origin: Option<i32>, |
| 17262 | pub tile_stipple_y_origin: Option<i32>, |
| 17263 | pub font: Option<Font>, |
| 17264 | pub subwindow_mode: Option<SubwindowMode>, |
| 17265 | pub graphics_exposures: Option<Bool32>, |
| 17266 | pub clip_x_origin: Option<i32>, |
| 17267 | pub clip_y_origin: Option<i32>, |
| 17268 | pub clip_mask: Option<Pixmap>, |
| 17269 | pub dash_offset: Option<u32>, |
| 17270 | pub dashes: Option<u32>, |
| 17271 | pub arc_mode: Option<ArcMode>, |
| 17272 | } |
| 17273 | impl_debug_if_no_extra_traits!(ChangeGCAux, "ChangeGCAux" ); |
| 17274 | impl ChangeGCAux { |
| 17275 | #[cfg_attr (not(feature = "request-parsing" ), allow(dead_code))] |
| 17276 | fn try_parse(value: &[u8], value_mask: u32) -> Result<(Self, &[u8]), ParseError> { |
| 17277 | let switch_expr = u32::from(value_mask); |
| 17278 | let mut outer_remaining = value; |
| 17279 | let function = if switch_expr & u32::from(GC::FUNCTION) != 0 { |
| 17280 | let remaining = outer_remaining; |
| 17281 | let (function, remaining) = u32::try_parse(remaining)?; |
| 17282 | let function = function.into(); |
| 17283 | outer_remaining = remaining; |
| 17284 | Some(function) |
| 17285 | } else { |
| 17286 | None |
| 17287 | }; |
| 17288 | let plane_mask = if switch_expr & u32::from(GC::PLANE_MASK) != 0 { |
| 17289 | let remaining = outer_remaining; |
| 17290 | let (plane_mask, remaining) = u32::try_parse(remaining)?; |
| 17291 | outer_remaining = remaining; |
| 17292 | Some(plane_mask) |
| 17293 | } else { |
| 17294 | None |
| 17295 | }; |
| 17296 | let foreground = if switch_expr & u32::from(GC::FOREGROUND) != 0 { |
| 17297 | let remaining = outer_remaining; |
| 17298 | let (foreground, remaining) = u32::try_parse(remaining)?; |
| 17299 | outer_remaining = remaining; |
| 17300 | Some(foreground) |
| 17301 | } else { |
| 17302 | None |
| 17303 | }; |
| 17304 | let background = if switch_expr & u32::from(GC::BACKGROUND) != 0 { |
| 17305 | let remaining = outer_remaining; |
| 17306 | let (background, remaining) = u32::try_parse(remaining)?; |
| 17307 | outer_remaining = remaining; |
| 17308 | Some(background) |
| 17309 | } else { |
| 17310 | None |
| 17311 | }; |
| 17312 | let line_width = if switch_expr & u32::from(GC::LINE_WIDTH) != 0 { |
| 17313 | let remaining = outer_remaining; |
| 17314 | let (line_width, remaining) = u32::try_parse(remaining)?; |
| 17315 | outer_remaining = remaining; |
| 17316 | Some(line_width) |
| 17317 | } else { |
| 17318 | None |
| 17319 | }; |
| 17320 | let line_style = if switch_expr & u32::from(GC::LINE_STYLE) != 0 { |
| 17321 | let remaining = outer_remaining; |
| 17322 | let (line_style, remaining) = u32::try_parse(remaining)?; |
| 17323 | let line_style = line_style.into(); |
| 17324 | outer_remaining = remaining; |
| 17325 | Some(line_style) |
| 17326 | } else { |
| 17327 | None |
| 17328 | }; |
| 17329 | let cap_style = if switch_expr & u32::from(GC::CAP_STYLE) != 0 { |
| 17330 | let remaining = outer_remaining; |
| 17331 | let (cap_style, remaining) = u32::try_parse(remaining)?; |
| 17332 | let cap_style = cap_style.into(); |
| 17333 | outer_remaining = remaining; |
| 17334 | Some(cap_style) |
| 17335 | } else { |
| 17336 | None |
| 17337 | }; |
| 17338 | let join_style = if switch_expr & u32::from(GC::JOIN_STYLE) != 0 { |
| 17339 | let remaining = outer_remaining; |
| 17340 | let (join_style, remaining) = u32::try_parse(remaining)?; |
| 17341 | let join_style = join_style.into(); |
| 17342 | outer_remaining = remaining; |
| 17343 | Some(join_style) |
| 17344 | } else { |
| 17345 | None |
| 17346 | }; |
| 17347 | let fill_style = if switch_expr & u32::from(GC::FILL_STYLE) != 0 { |
| 17348 | let remaining = outer_remaining; |
| 17349 | let (fill_style, remaining) = u32::try_parse(remaining)?; |
| 17350 | let fill_style = fill_style.into(); |
| 17351 | outer_remaining = remaining; |
| 17352 | Some(fill_style) |
| 17353 | } else { |
| 17354 | None |
| 17355 | }; |
| 17356 | let fill_rule = if switch_expr & u32::from(GC::FILL_RULE) != 0 { |
| 17357 | let remaining = outer_remaining; |
| 17358 | let (fill_rule, remaining) = u32::try_parse(remaining)?; |
| 17359 | let fill_rule = fill_rule.into(); |
| 17360 | outer_remaining = remaining; |
| 17361 | Some(fill_rule) |
| 17362 | } else { |
| 17363 | None |
| 17364 | }; |
| 17365 | let tile = if switch_expr & u32::from(GC::TILE) != 0 { |
| 17366 | let remaining = outer_remaining; |
| 17367 | let (tile, remaining) = Pixmap::try_parse(remaining)?; |
| 17368 | outer_remaining = remaining; |
| 17369 | Some(tile) |
| 17370 | } else { |
| 17371 | None |
| 17372 | }; |
| 17373 | let stipple = if switch_expr & u32::from(GC::STIPPLE) != 0 { |
| 17374 | let remaining = outer_remaining; |
| 17375 | let (stipple, remaining) = Pixmap::try_parse(remaining)?; |
| 17376 | outer_remaining = remaining; |
| 17377 | Some(stipple) |
| 17378 | } else { |
| 17379 | None |
| 17380 | }; |
| 17381 | let tile_stipple_x_origin = if switch_expr & u32::from(GC::TILE_STIPPLE_ORIGIN_X) != 0 { |
| 17382 | let remaining = outer_remaining; |
| 17383 | let (tile_stipple_x_origin, remaining) = i32::try_parse(remaining)?; |
| 17384 | outer_remaining = remaining; |
| 17385 | Some(tile_stipple_x_origin) |
| 17386 | } else { |
| 17387 | None |
| 17388 | }; |
| 17389 | let tile_stipple_y_origin = if switch_expr & u32::from(GC::TILE_STIPPLE_ORIGIN_Y) != 0 { |
| 17390 | let remaining = outer_remaining; |
| 17391 | let (tile_stipple_y_origin, remaining) = i32::try_parse(remaining)?; |
| 17392 | outer_remaining = remaining; |
| 17393 | Some(tile_stipple_y_origin) |
| 17394 | } else { |
| 17395 | None |
| 17396 | }; |
| 17397 | let font = if switch_expr & u32::from(GC::FONT) != 0 { |
| 17398 | let remaining = outer_remaining; |
| 17399 | let (font, remaining) = Font::try_parse(remaining)?; |
| 17400 | outer_remaining = remaining; |
| 17401 | Some(font) |
| 17402 | } else { |
| 17403 | None |
| 17404 | }; |
| 17405 | let subwindow_mode = if switch_expr & u32::from(GC::SUBWINDOW_MODE) != 0 { |
| 17406 | let remaining = outer_remaining; |
| 17407 | let (subwindow_mode, remaining) = u32::try_parse(remaining)?; |
| 17408 | let subwindow_mode = subwindow_mode.into(); |
| 17409 | outer_remaining = remaining; |
| 17410 | Some(subwindow_mode) |
| 17411 | } else { |
| 17412 | None |
| 17413 | }; |
| 17414 | let graphics_exposures = if switch_expr & u32::from(GC::GRAPHICS_EXPOSURES) != 0 { |
| 17415 | let remaining = outer_remaining; |
| 17416 | let (graphics_exposures, remaining) = Bool32::try_parse(remaining)?; |
| 17417 | outer_remaining = remaining; |
| 17418 | Some(graphics_exposures) |
| 17419 | } else { |
| 17420 | None |
| 17421 | }; |
| 17422 | let clip_x_origin = if switch_expr & u32::from(GC::CLIP_ORIGIN_X) != 0 { |
| 17423 | let remaining = outer_remaining; |
| 17424 | let (clip_x_origin, remaining) = i32::try_parse(remaining)?; |
| 17425 | outer_remaining = remaining; |
| 17426 | Some(clip_x_origin) |
| 17427 | } else { |
| 17428 | None |
| 17429 | }; |
| 17430 | let clip_y_origin = if switch_expr & u32::from(GC::CLIP_ORIGIN_Y) != 0 { |
| 17431 | let remaining = outer_remaining; |
| 17432 | let (clip_y_origin, remaining) = i32::try_parse(remaining)?; |
| 17433 | outer_remaining = remaining; |
| 17434 | Some(clip_y_origin) |
| 17435 | } else { |
| 17436 | None |
| 17437 | }; |
| 17438 | let clip_mask = if switch_expr & u32::from(GC::CLIP_MASK) != 0 { |
| 17439 | let remaining = outer_remaining; |
| 17440 | let (clip_mask, remaining) = Pixmap::try_parse(remaining)?; |
| 17441 | outer_remaining = remaining; |
| 17442 | Some(clip_mask) |
| 17443 | } else { |
| 17444 | None |
| 17445 | }; |
| 17446 | let dash_offset = if switch_expr & u32::from(GC::DASH_OFFSET) != 0 { |
| 17447 | let remaining = outer_remaining; |
| 17448 | let (dash_offset, remaining) = u32::try_parse(remaining)?; |
| 17449 | outer_remaining = remaining; |
| 17450 | Some(dash_offset) |
| 17451 | } else { |
| 17452 | None |
| 17453 | }; |
| 17454 | let dashes = if switch_expr & u32::from(GC::DASH_LIST) != 0 { |
| 17455 | let remaining = outer_remaining; |
| 17456 | let (dashes, remaining) = u32::try_parse(remaining)?; |
| 17457 | outer_remaining = remaining; |
| 17458 | Some(dashes) |
| 17459 | } else { |
| 17460 | None |
| 17461 | }; |
| 17462 | let arc_mode = if switch_expr & u32::from(GC::ARC_MODE) != 0 { |
| 17463 | let remaining = outer_remaining; |
| 17464 | let (arc_mode, remaining) = u32::try_parse(remaining)?; |
| 17465 | let arc_mode = arc_mode.into(); |
| 17466 | outer_remaining = remaining; |
| 17467 | Some(arc_mode) |
| 17468 | } else { |
| 17469 | None |
| 17470 | }; |
| 17471 | let result = ChangeGCAux { function, plane_mask, foreground, background, line_width, line_style, cap_style, join_style, fill_style, fill_rule, tile, stipple, tile_stipple_x_origin, tile_stipple_y_origin, font, subwindow_mode, graphics_exposures, clip_x_origin, clip_y_origin, clip_mask, dash_offset, dashes, arc_mode }; |
| 17472 | Ok((result, outer_remaining)) |
| 17473 | } |
| 17474 | } |
| 17475 | impl ChangeGCAux { |
| 17476 | #[allow (dead_code)] |
| 17477 | fn serialize(&self, value_mask: u32) -> Vec<u8> { |
| 17478 | let mut result = Vec::new(); |
| 17479 | self.serialize_into(&mut result, u32::from(value_mask)); |
| 17480 | result |
| 17481 | } |
| 17482 | fn serialize_into(&self, bytes: &mut Vec<u8>, value_mask: u32) { |
| 17483 | assert_eq!(self.switch_expr(), u32::from(value_mask), "switch `value_list` has an inconsistent discriminant" ); |
| 17484 | if let Some(function) = self.function { |
| 17485 | u32::from(function).serialize_into(bytes); |
| 17486 | } |
| 17487 | if let Some(plane_mask) = self.plane_mask { |
| 17488 | plane_mask.serialize_into(bytes); |
| 17489 | } |
| 17490 | if let Some(foreground) = self.foreground { |
| 17491 | foreground.serialize_into(bytes); |
| 17492 | } |
| 17493 | if let Some(background) = self.background { |
| 17494 | background.serialize_into(bytes); |
| 17495 | } |
| 17496 | if let Some(line_width) = self.line_width { |
| 17497 | line_width.serialize_into(bytes); |
| 17498 | } |
| 17499 | if let Some(line_style) = self.line_style { |
| 17500 | u32::from(line_style).serialize_into(bytes); |
| 17501 | } |
| 17502 | if let Some(cap_style) = self.cap_style { |
| 17503 | u32::from(cap_style).serialize_into(bytes); |
| 17504 | } |
| 17505 | if let Some(join_style) = self.join_style { |
| 17506 | u32::from(join_style).serialize_into(bytes); |
| 17507 | } |
| 17508 | if let Some(fill_style) = self.fill_style { |
| 17509 | u32::from(fill_style).serialize_into(bytes); |
| 17510 | } |
| 17511 | if let Some(fill_rule) = self.fill_rule { |
| 17512 | u32::from(fill_rule).serialize_into(bytes); |
| 17513 | } |
| 17514 | if let Some(tile) = self.tile { |
| 17515 | tile.serialize_into(bytes); |
| 17516 | } |
| 17517 | if let Some(stipple) = self.stipple { |
| 17518 | stipple.serialize_into(bytes); |
| 17519 | } |
| 17520 | if let Some(tile_stipple_x_origin) = self.tile_stipple_x_origin { |
| 17521 | tile_stipple_x_origin.serialize_into(bytes); |
| 17522 | } |
| 17523 | if let Some(tile_stipple_y_origin) = self.tile_stipple_y_origin { |
| 17524 | tile_stipple_y_origin.serialize_into(bytes); |
| 17525 | } |
| 17526 | if let Some(font) = self.font { |
| 17527 | font.serialize_into(bytes); |
| 17528 | } |
| 17529 | if let Some(subwindow_mode) = self.subwindow_mode { |
| 17530 | u32::from(subwindow_mode).serialize_into(bytes); |
| 17531 | } |
| 17532 | if let Some(graphics_exposures) = self.graphics_exposures { |
| 17533 | graphics_exposures.serialize_into(bytes); |
| 17534 | } |
| 17535 | if let Some(clip_x_origin) = self.clip_x_origin { |
| 17536 | clip_x_origin.serialize_into(bytes); |
| 17537 | } |
| 17538 | if let Some(clip_y_origin) = self.clip_y_origin { |
| 17539 | clip_y_origin.serialize_into(bytes); |
| 17540 | } |
| 17541 | if let Some(clip_mask) = self.clip_mask { |
| 17542 | clip_mask.serialize_into(bytes); |
| 17543 | } |
| 17544 | if let Some(dash_offset) = self.dash_offset { |
| 17545 | dash_offset.serialize_into(bytes); |
| 17546 | } |
| 17547 | if let Some(dashes) = self.dashes { |
| 17548 | dashes.serialize_into(bytes); |
| 17549 | } |
| 17550 | if let Some(arc_mode) = self.arc_mode { |
| 17551 | u32::from(arc_mode).serialize_into(bytes); |
| 17552 | } |
| 17553 | } |
| 17554 | } |
| 17555 | impl ChangeGCAux { |
| 17556 | fn switch_expr(&self) -> u32 { |
| 17557 | let mut expr_value = 0; |
| 17558 | if self.function.is_some() { |
| 17559 | expr_value |= u32::from(GC::FUNCTION); |
| 17560 | } |
| 17561 | if self.plane_mask.is_some() { |
| 17562 | expr_value |= u32::from(GC::PLANE_MASK); |
| 17563 | } |
| 17564 | if self.foreground.is_some() { |
| 17565 | expr_value |= u32::from(GC::FOREGROUND); |
| 17566 | } |
| 17567 | if self.background.is_some() { |
| 17568 | expr_value |= u32::from(GC::BACKGROUND); |
| 17569 | } |
| 17570 | if self.line_width.is_some() { |
| 17571 | expr_value |= u32::from(GC::LINE_WIDTH); |
| 17572 | } |
| 17573 | if self.line_style.is_some() { |
| 17574 | expr_value |= u32::from(GC::LINE_STYLE); |
| 17575 | } |
| 17576 | if self.cap_style.is_some() { |
| 17577 | expr_value |= u32::from(GC::CAP_STYLE); |
| 17578 | } |
| 17579 | if self.join_style.is_some() { |
| 17580 | expr_value |= u32::from(GC::JOIN_STYLE); |
| 17581 | } |
| 17582 | if self.fill_style.is_some() { |
| 17583 | expr_value |= u32::from(GC::FILL_STYLE); |
| 17584 | } |
| 17585 | if self.fill_rule.is_some() { |
| 17586 | expr_value |= u32::from(GC::FILL_RULE); |
| 17587 | } |
| 17588 | if self.tile.is_some() { |
| 17589 | expr_value |= u32::from(GC::TILE); |
| 17590 | } |
| 17591 | if self.stipple.is_some() { |
| 17592 | expr_value |= u32::from(GC::STIPPLE); |
| 17593 | } |
| 17594 | if self.tile_stipple_x_origin.is_some() { |
| 17595 | expr_value |= u32::from(GC::TILE_STIPPLE_ORIGIN_X); |
| 17596 | } |
| 17597 | if self.tile_stipple_y_origin.is_some() { |
| 17598 | expr_value |= u32::from(GC::TILE_STIPPLE_ORIGIN_Y); |
| 17599 | } |
| 17600 | if self.font.is_some() { |
| 17601 | expr_value |= u32::from(GC::FONT); |
| 17602 | } |
| 17603 | if self.subwindow_mode.is_some() { |
| 17604 | expr_value |= u32::from(GC::SUBWINDOW_MODE); |
| 17605 | } |
| 17606 | if self.graphics_exposures.is_some() { |
| 17607 | expr_value |= u32::from(GC::GRAPHICS_EXPOSURES); |
| 17608 | } |
| 17609 | if self.clip_x_origin.is_some() { |
| 17610 | expr_value |= u32::from(GC::CLIP_ORIGIN_X); |
| 17611 | } |
| 17612 | if self.clip_y_origin.is_some() { |
| 17613 | expr_value |= u32::from(GC::CLIP_ORIGIN_Y); |
| 17614 | } |
| 17615 | if self.clip_mask.is_some() { |
| 17616 | expr_value |= u32::from(GC::CLIP_MASK); |
| 17617 | } |
| 17618 | if self.dash_offset.is_some() { |
| 17619 | expr_value |= u32::from(GC::DASH_OFFSET); |
| 17620 | } |
| 17621 | if self.dashes.is_some() { |
| 17622 | expr_value |= u32::from(GC::DASH_LIST); |
| 17623 | } |
| 17624 | if self.arc_mode.is_some() { |
| 17625 | expr_value |= u32::from(GC::ARC_MODE); |
| 17626 | } |
| 17627 | expr_value |
| 17628 | } |
| 17629 | } |
| 17630 | impl ChangeGCAux { |
| 17631 | /// Create a new instance with all fields unset / not present. |
| 17632 | pub fn new() -> Self { |
| 17633 | Default::default() |
| 17634 | } |
| 17635 | /// Set the `function` field of this structure. |
| 17636 | #[must_use ] |
| 17637 | pub fn function<I>(mut self, value: I) -> Self where I: Into<Option<GX>> { |
| 17638 | self.function = value.into(); |
| 17639 | self |
| 17640 | } |
| 17641 | /// Set the `plane_mask` field of this structure. |
| 17642 | #[must_use ] |
| 17643 | pub fn plane_mask<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 17644 | self.plane_mask = value.into(); |
| 17645 | self |
| 17646 | } |
| 17647 | /// Set the `foreground` field of this structure. |
| 17648 | #[must_use ] |
| 17649 | pub fn foreground<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 17650 | self.foreground = value.into(); |
| 17651 | self |
| 17652 | } |
| 17653 | /// Set the `background` field of this structure. |
| 17654 | #[must_use ] |
| 17655 | pub fn background<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 17656 | self.background = value.into(); |
| 17657 | self |
| 17658 | } |
| 17659 | /// Set the `line_width` field of this structure. |
| 17660 | #[must_use ] |
| 17661 | pub fn line_width<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 17662 | self.line_width = value.into(); |
| 17663 | self |
| 17664 | } |
| 17665 | /// Set the `line_style` field of this structure. |
| 17666 | #[must_use ] |
| 17667 | pub fn line_style<I>(mut self, value: I) -> Self where I: Into<Option<LineStyle>> { |
| 17668 | self.line_style = value.into(); |
| 17669 | self |
| 17670 | } |
| 17671 | /// Set the `cap_style` field of this structure. |
| 17672 | #[must_use ] |
| 17673 | pub fn cap_style<I>(mut self, value: I) -> Self where I: Into<Option<CapStyle>> { |
| 17674 | self.cap_style = value.into(); |
| 17675 | self |
| 17676 | } |
| 17677 | /// Set the `join_style` field of this structure. |
| 17678 | #[must_use ] |
| 17679 | pub fn join_style<I>(mut self, value: I) -> Self where I: Into<Option<JoinStyle>> { |
| 17680 | self.join_style = value.into(); |
| 17681 | self |
| 17682 | } |
| 17683 | /// Set the `fill_style` field of this structure. |
| 17684 | #[must_use ] |
| 17685 | pub fn fill_style<I>(mut self, value: I) -> Self where I: Into<Option<FillStyle>> { |
| 17686 | self.fill_style = value.into(); |
| 17687 | self |
| 17688 | } |
| 17689 | /// Set the `fill_rule` field of this structure. |
| 17690 | #[must_use ] |
| 17691 | pub fn fill_rule<I>(mut self, value: I) -> Self where I: Into<Option<FillRule>> { |
| 17692 | self.fill_rule = value.into(); |
| 17693 | self |
| 17694 | } |
| 17695 | /// Set the `tile` field of this structure. |
| 17696 | #[must_use ] |
| 17697 | pub fn tile<I>(mut self, value: I) -> Self where I: Into<Option<Pixmap>> { |
| 17698 | self.tile = value.into(); |
| 17699 | self |
| 17700 | } |
| 17701 | /// Set the `stipple` field of this structure. |
| 17702 | #[must_use ] |
| 17703 | pub fn stipple<I>(mut self, value: I) -> Self where I: Into<Option<Pixmap>> { |
| 17704 | self.stipple = value.into(); |
| 17705 | self |
| 17706 | } |
| 17707 | /// Set the `tile_stipple_x_origin` field of this structure. |
| 17708 | #[must_use ] |
| 17709 | pub fn tile_stipple_x_origin<I>(mut self, value: I) -> Self where I: Into<Option<i32>> { |
| 17710 | self.tile_stipple_x_origin = value.into(); |
| 17711 | self |
| 17712 | } |
| 17713 | /// Set the `tile_stipple_y_origin` field of this structure. |
| 17714 | #[must_use ] |
| 17715 | pub fn tile_stipple_y_origin<I>(mut self, value: I) -> Self where I: Into<Option<i32>> { |
| 17716 | self.tile_stipple_y_origin = value.into(); |
| 17717 | self |
| 17718 | } |
| 17719 | /// Set the `font` field of this structure. |
| 17720 | #[must_use ] |
| 17721 | pub fn font<I>(mut self, value: I) -> Self where I: Into<Option<Font>> { |
| 17722 | self.font = value.into(); |
| 17723 | self |
| 17724 | } |
| 17725 | /// Set the `subwindow_mode` field of this structure. |
| 17726 | #[must_use ] |
| 17727 | pub fn subwindow_mode<I>(mut self, value: I) -> Self where I: Into<Option<SubwindowMode>> { |
| 17728 | self.subwindow_mode = value.into(); |
| 17729 | self |
| 17730 | } |
| 17731 | /// Set the `graphics_exposures` field of this structure. |
| 17732 | #[must_use ] |
| 17733 | pub fn graphics_exposures<I>(mut self, value: I) -> Self where I: Into<Option<Bool32>> { |
| 17734 | self.graphics_exposures = value.into(); |
| 17735 | self |
| 17736 | } |
| 17737 | /// Set the `clip_x_origin` field of this structure. |
| 17738 | #[must_use ] |
| 17739 | pub fn clip_x_origin<I>(mut self, value: I) -> Self where I: Into<Option<i32>> { |
| 17740 | self.clip_x_origin = value.into(); |
| 17741 | self |
| 17742 | } |
| 17743 | /// Set the `clip_y_origin` field of this structure. |
| 17744 | #[must_use ] |
| 17745 | pub fn clip_y_origin<I>(mut self, value: I) -> Self where I: Into<Option<i32>> { |
| 17746 | self.clip_y_origin = value.into(); |
| 17747 | self |
| 17748 | } |
| 17749 | /// Set the `clip_mask` field of this structure. |
| 17750 | #[must_use ] |
| 17751 | pub fn clip_mask<I>(mut self, value: I) -> Self where I: Into<Option<Pixmap>> { |
| 17752 | self.clip_mask = value.into(); |
| 17753 | self |
| 17754 | } |
| 17755 | /// Set the `dash_offset` field of this structure. |
| 17756 | #[must_use ] |
| 17757 | pub fn dash_offset<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 17758 | self.dash_offset = value.into(); |
| 17759 | self |
| 17760 | } |
| 17761 | /// Set the `dashes` field of this structure. |
| 17762 | #[must_use ] |
| 17763 | pub fn dashes<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 17764 | self.dashes = value.into(); |
| 17765 | self |
| 17766 | } |
| 17767 | /// Set the `arc_mode` field of this structure. |
| 17768 | #[must_use ] |
| 17769 | pub fn arc_mode<I>(mut self, value: I) -> Self where I: Into<Option<ArcMode>> { |
| 17770 | self.arc_mode = value.into(); |
| 17771 | self |
| 17772 | } |
| 17773 | } |
| 17774 | |
| 17775 | /// Opcode for the ChangeGC request |
| 17776 | pub const CHANGE_GC_REQUEST: u8 = 56; |
| 17777 | /// change graphics context components. |
| 17778 | /// |
| 17779 | /// Changes the components specified by `value_mask` for the specified graphics context. |
| 17780 | /// |
| 17781 | /// # Fields |
| 17782 | /// |
| 17783 | /// * `gc` - The graphics context to change. |
| 17784 | /// * `value_list` - Values for each of the components specified in the bitmask `value_mask`. The |
| 17785 | /// order has to correspond to the order of possible `value_mask` bits. See the |
| 17786 | /// example. |
| 17787 | /// |
| 17788 | /// # Errors |
| 17789 | /// |
| 17790 | /// * `Font` - TODO: reasons? |
| 17791 | /// * `GContext` - TODO: reasons? |
| 17792 | /// * `Match` - TODO: reasons? |
| 17793 | /// * `Pixmap` - TODO: reasons? |
| 17794 | /// * `Value` - TODO: reasons? |
| 17795 | /// * `Alloc` - The X server could not allocate the requested resources (no memory?). |
| 17796 | /// |
| 17797 | /// # Example |
| 17798 | /// |
| 17799 | /// ```text |
| 17800 | /// /* |
| 17801 | /// * Changes the foreground color component of the specified graphics context. |
| 17802 | /// * |
| 17803 | /// */ |
| 17804 | /// void my_example(xcb_connection_t *conn, xcb_gcontext_t gc, uint32_t fg, uint32_t bg) { |
| 17805 | /// /* C99 allows us to use a compact way of changing a single component: */ |
| 17806 | /// xcb_change_gc(conn, gc, XCB_GC_FOREGROUND, (uint32_t[]){ fg }); |
| 17807 | /// |
| 17808 | /// /* The more explicit way. Beware that the order of values is important! */ |
| 17809 | /// uint32_t mask = 0; |
| 17810 | /// mask |= XCB_GC_FOREGROUND; |
| 17811 | /// mask |= XCB_GC_BACKGROUND; |
| 17812 | /// |
| 17813 | /// uint32_t values[] = { |
| 17814 | /// fg, |
| 17815 | /// bg |
| 17816 | /// }; |
| 17817 | /// xcb_change_gc(conn, gc, mask, values); |
| 17818 | /// xcb_flush(conn); |
| 17819 | /// } |
| 17820 | /// ``` |
| 17821 | #[derive (Clone, Default)] |
| 17822 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 17823 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 17824 | pub struct ChangeGCRequest<'input> { |
| 17825 | pub gc: Gcontext, |
| 17826 | pub value_list: Cow<'input, ChangeGCAux>, |
| 17827 | } |
| 17828 | impl_debug_if_no_extra_traits!(ChangeGCRequest<'_>, "ChangeGCRequest" ); |
| 17829 | impl<'input> ChangeGCRequest<'input> { |
| 17830 | /// Serialize this request into bytes for the provided connection |
| 17831 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 17832 | let length_so_far = 0; |
| 17833 | let gc_bytes = self.gc.serialize(); |
| 17834 | let value_mask: u32 = self.value_list.switch_expr(); |
| 17835 | let value_mask_bytes = value_mask.serialize(); |
| 17836 | let mut request0 = vec![ |
| 17837 | CHANGE_GC_REQUEST, |
| 17838 | 0, |
| 17839 | 0, |
| 17840 | 0, |
| 17841 | gc_bytes[0], |
| 17842 | gc_bytes[1], |
| 17843 | gc_bytes[2], |
| 17844 | gc_bytes[3], |
| 17845 | value_mask_bytes[0], |
| 17846 | value_mask_bytes[1], |
| 17847 | value_mask_bytes[2], |
| 17848 | value_mask_bytes[3], |
| 17849 | ]; |
| 17850 | let length_so_far = length_so_far + request0.len(); |
| 17851 | let value_list_bytes = self.value_list.serialize(u32::from(value_mask)); |
| 17852 | let length_so_far = length_so_far + value_list_bytes.len(); |
| 17853 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 17854 | let length_so_far = length_so_far + padding0.len(); |
| 17855 | assert_eq!(length_so_far % 4, 0); |
| 17856 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 17857 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 17858 | ([request0.into(), value_list_bytes.into(), padding0.into()], vec![]) |
| 17859 | } |
| 17860 | /// Parse this request given its header, its body, and any fds that go along with it |
| 17861 | #[cfg (feature = "request-parsing" )] |
| 17862 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 17863 | if header.major_opcode != CHANGE_GC_REQUEST { |
| 17864 | return Err(ParseError::InvalidValue); |
| 17865 | } |
| 17866 | let remaining = &[header.minor_opcode]; |
| 17867 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 17868 | let _ = remaining; |
| 17869 | let (gc, remaining) = Gcontext::try_parse(value)?; |
| 17870 | let (value_mask, remaining) = u32::try_parse(remaining)?; |
| 17871 | let (value_list, remaining) = ChangeGCAux::try_parse(remaining, u32::from(value_mask))?; |
| 17872 | let _ = remaining; |
| 17873 | Ok(ChangeGCRequest { |
| 17874 | gc, |
| 17875 | value_list: Cow::Owned(value_list), |
| 17876 | }) |
| 17877 | } |
| 17878 | /// Clone all borrowed data in this ChangeGCRequest. |
| 17879 | pub fn into_owned(self) -> ChangeGCRequest<'static> { |
| 17880 | ChangeGCRequest { |
| 17881 | gc: self.gc, |
| 17882 | value_list: Cow::Owned(self.value_list.into_owned()), |
| 17883 | } |
| 17884 | } |
| 17885 | } |
| 17886 | impl<'input> Request for ChangeGCRequest<'input> { |
| 17887 | const EXTENSION_NAME: Option<&'static str> = None; |
| 17888 | |
| 17889 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 17890 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 17891 | // Flatten the buffers into a single vector |
| 17892 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 17893 | (buf, fds) |
| 17894 | } |
| 17895 | } |
| 17896 | impl<'input> crate::x11_utils::VoidRequest for ChangeGCRequest<'input> { |
| 17897 | } |
| 17898 | |
| 17899 | /// Opcode for the CopyGC request |
| 17900 | pub const COPY_GC_REQUEST: u8 = 57; |
| 17901 | #[derive (Clone, Copy, Default)] |
| 17902 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 17903 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 17904 | pub struct CopyGCRequest { |
| 17905 | pub src_gc: Gcontext, |
| 17906 | pub dst_gc: Gcontext, |
| 17907 | pub value_mask: GC, |
| 17908 | } |
| 17909 | impl_debug_if_no_extra_traits!(CopyGCRequest, "CopyGCRequest" ); |
| 17910 | impl CopyGCRequest { |
| 17911 | /// Serialize this request into bytes for the provided connection |
| 17912 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 17913 | let length_so_far = 0; |
| 17914 | let src_gc_bytes = self.src_gc.serialize(); |
| 17915 | let dst_gc_bytes = self.dst_gc.serialize(); |
| 17916 | let value_mask_bytes = u32::from(self.value_mask).serialize(); |
| 17917 | let mut request0 = vec![ |
| 17918 | COPY_GC_REQUEST, |
| 17919 | 0, |
| 17920 | 0, |
| 17921 | 0, |
| 17922 | src_gc_bytes[0], |
| 17923 | src_gc_bytes[1], |
| 17924 | src_gc_bytes[2], |
| 17925 | src_gc_bytes[3], |
| 17926 | dst_gc_bytes[0], |
| 17927 | dst_gc_bytes[1], |
| 17928 | dst_gc_bytes[2], |
| 17929 | dst_gc_bytes[3], |
| 17930 | value_mask_bytes[0], |
| 17931 | value_mask_bytes[1], |
| 17932 | value_mask_bytes[2], |
| 17933 | value_mask_bytes[3], |
| 17934 | ]; |
| 17935 | let length_so_far = length_so_far + request0.len(); |
| 17936 | assert_eq!(length_so_far % 4, 0); |
| 17937 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 17938 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 17939 | ([request0.into()], vec![]) |
| 17940 | } |
| 17941 | /// Parse this request given its header, its body, and any fds that go along with it |
| 17942 | #[cfg (feature = "request-parsing" )] |
| 17943 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 17944 | if header.major_opcode != COPY_GC_REQUEST { |
| 17945 | return Err(ParseError::InvalidValue); |
| 17946 | } |
| 17947 | let remaining = &[header.minor_opcode]; |
| 17948 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 17949 | let _ = remaining; |
| 17950 | let (src_gc, remaining) = Gcontext::try_parse(value)?; |
| 17951 | let (dst_gc, remaining) = Gcontext::try_parse(remaining)?; |
| 17952 | let (value_mask, remaining) = u32::try_parse(remaining)?; |
| 17953 | let value_mask = value_mask.into(); |
| 17954 | let _ = remaining; |
| 17955 | Ok(CopyGCRequest { |
| 17956 | src_gc, |
| 17957 | dst_gc, |
| 17958 | value_mask, |
| 17959 | }) |
| 17960 | } |
| 17961 | } |
| 17962 | impl Request for CopyGCRequest { |
| 17963 | const EXTENSION_NAME: Option<&'static str> = None; |
| 17964 | |
| 17965 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 17966 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 17967 | // Flatten the buffers into a single vector |
| 17968 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 17969 | (buf, fds) |
| 17970 | } |
| 17971 | } |
| 17972 | impl crate::x11_utils::VoidRequest for CopyGCRequest { |
| 17973 | } |
| 17974 | |
| 17975 | /// Opcode for the SetDashes request |
| 17976 | pub const SET_DASHES_REQUEST: u8 = 58; |
| 17977 | #[derive (Clone, Default)] |
| 17978 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 17979 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 17980 | pub struct SetDashesRequest<'input> { |
| 17981 | pub gc: Gcontext, |
| 17982 | pub dash_offset: u16, |
| 17983 | pub dashes: Cow<'input, [u8]>, |
| 17984 | } |
| 17985 | impl_debug_if_no_extra_traits!(SetDashesRequest<'_>, "SetDashesRequest" ); |
| 17986 | impl<'input> SetDashesRequest<'input> { |
| 17987 | /// Serialize this request into bytes for the provided connection |
| 17988 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 17989 | let length_so_far = 0; |
| 17990 | let gc_bytes = self.gc.serialize(); |
| 17991 | let dash_offset_bytes = self.dash_offset.serialize(); |
| 17992 | let dashes_len = u16::try_from(self.dashes.len()).expect("`dashes` has too many elements" ); |
| 17993 | let dashes_len_bytes = dashes_len.serialize(); |
| 17994 | let mut request0 = vec![ |
| 17995 | SET_DASHES_REQUEST, |
| 17996 | 0, |
| 17997 | 0, |
| 17998 | 0, |
| 17999 | gc_bytes[0], |
| 18000 | gc_bytes[1], |
| 18001 | gc_bytes[2], |
| 18002 | gc_bytes[3], |
| 18003 | dash_offset_bytes[0], |
| 18004 | dash_offset_bytes[1], |
| 18005 | dashes_len_bytes[0], |
| 18006 | dashes_len_bytes[1], |
| 18007 | ]; |
| 18008 | let length_so_far = length_so_far + request0.len(); |
| 18009 | let length_so_far = length_so_far + self.dashes.len(); |
| 18010 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 18011 | let length_so_far = length_so_far + padding0.len(); |
| 18012 | assert_eq!(length_so_far % 4, 0); |
| 18013 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 18014 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 18015 | ([request0.into(), self.dashes, padding0.into()], vec![]) |
| 18016 | } |
| 18017 | /// Parse this request given its header, its body, and any fds that go along with it |
| 18018 | #[cfg (feature = "request-parsing" )] |
| 18019 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 18020 | if header.major_opcode != SET_DASHES_REQUEST { |
| 18021 | return Err(ParseError::InvalidValue); |
| 18022 | } |
| 18023 | let remaining = &[header.minor_opcode]; |
| 18024 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 18025 | let _ = remaining; |
| 18026 | let (gc, remaining) = Gcontext::try_parse(value)?; |
| 18027 | let (dash_offset, remaining) = u16::try_parse(remaining)?; |
| 18028 | let (dashes_len, remaining) = u16::try_parse(remaining)?; |
| 18029 | let (dashes, remaining) = crate::x11_utils::parse_u8_list(remaining, dashes_len.try_to_usize()?)?; |
| 18030 | let _ = remaining; |
| 18031 | Ok(SetDashesRequest { |
| 18032 | gc, |
| 18033 | dash_offset, |
| 18034 | dashes: Cow::Borrowed(dashes), |
| 18035 | }) |
| 18036 | } |
| 18037 | /// Clone all borrowed data in this SetDashesRequest. |
| 18038 | pub fn into_owned(self) -> SetDashesRequest<'static> { |
| 18039 | SetDashesRequest { |
| 18040 | gc: self.gc, |
| 18041 | dash_offset: self.dash_offset, |
| 18042 | dashes: Cow::Owned(self.dashes.into_owned()), |
| 18043 | } |
| 18044 | } |
| 18045 | } |
| 18046 | impl<'input> Request for SetDashesRequest<'input> { |
| 18047 | const EXTENSION_NAME: Option<&'static str> = None; |
| 18048 | |
| 18049 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 18050 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 18051 | // Flatten the buffers into a single vector |
| 18052 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 18053 | (buf, fds) |
| 18054 | } |
| 18055 | } |
| 18056 | impl<'input> crate::x11_utils::VoidRequest for SetDashesRequest<'input> { |
| 18057 | } |
| 18058 | |
| 18059 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 18060 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 18061 | pub struct ClipOrdering(u8); |
| 18062 | impl ClipOrdering { |
| 18063 | pub const UNSORTED: Self = Self(0); |
| 18064 | pub const Y_SORTED: Self = Self(1); |
| 18065 | pub const YX_SORTED: Self = Self(2); |
| 18066 | pub const YX_BANDED: Self = Self(3); |
| 18067 | } |
| 18068 | impl From<ClipOrdering> for u8 { |
| 18069 | #[inline ] |
| 18070 | fn from(input: ClipOrdering) -> Self { |
| 18071 | input.0 |
| 18072 | } |
| 18073 | } |
| 18074 | impl From<ClipOrdering> for Option<u8> { |
| 18075 | #[inline ] |
| 18076 | fn from(input: ClipOrdering) -> Self { |
| 18077 | Some(input.0) |
| 18078 | } |
| 18079 | } |
| 18080 | impl From<ClipOrdering> for u16 { |
| 18081 | #[inline ] |
| 18082 | fn from(input: ClipOrdering) -> Self { |
| 18083 | u16::from(input.0) |
| 18084 | } |
| 18085 | } |
| 18086 | impl From<ClipOrdering> for Option<u16> { |
| 18087 | #[inline ] |
| 18088 | fn from(input: ClipOrdering) -> Self { |
| 18089 | Some(u16::from(input.0)) |
| 18090 | } |
| 18091 | } |
| 18092 | impl From<ClipOrdering> for u32 { |
| 18093 | #[inline ] |
| 18094 | fn from(input: ClipOrdering) -> Self { |
| 18095 | u32::from(input.0) |
| 18096 | } |
| 18097 | } |
| 18098 | impl From<ClipOrdering> for Option<u32> { |
| 18099 | #[inline ] |
| 18100 | fn from(input: ClipOrdering) -> Self { |
| 18101 | Some(u32::from(input.0)) |
| 18102 | } |
| 18103 | } |
| 18104 | impl From<u8> for ClipOrdering { |
| 18105 | #[inline ] |
| 18106 | fn from(value: u8) -> Self { |
| 18107 | Self(value) |
| 18108 | } |
| 18109 | } |
| 18110 | impl core::fmt::Debug for ClipOrdering { |
| 18111 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 18112 | let variants: [(u32, &'static str, &'static …); 4] = [ |
| 18113 | (Self::UNSORTED.0.into(), "UNSORTED" , "Unsorted" ), |
| 18114 | (Self::Y_SORTED.0.into(), "Y_SORTED" , "YSorted" ), |
| 18115 | (Self::YX_SORTED.0.into(), "YX_SORTED" , "YXSorted" ), |
| 18116 | (Self::YX_BANDED.0.into(), "YX_BANDED" , "YXBanded" ), |
| 18117 | ]; |
| 18118 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 18119 | } |
| 18120 | } |
| 18121 | |
| 18122 | /// Opcode for the SetClipRectangles request |
| 18123 | pub const SET_CLIP_RECTANGLES_REQUEST: u8 = 59; |
| 18124 | #[derive (Clone, Default)] |
| 18125 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 18126 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 18127 | pub struct SetClipRectanglesRequest<'input> { |
| 18128 | pub ordering: ClipOrdering, |
| 18129 | pub gc: Gcontext, |
| 18130 | pub clip_x_origin: i16, |
| 18131 | pub clip_y_origin: i16, |
| 18132 | pub rectangles: Cow<'input, [Rectangle]>, |
| 18133 | } |
| 18134 | impl_debug_if_no_extra_traits!(SetClipRectanglesRequest<'_>, "SetClipRectanglesRequest" ); |
| 18135 | impl<'input> SetClipRectanglesRequest<'input> { |
| 18136 | /// Serialize this request into bytes for the provided connection |
| 18137 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 18138 | let length_so_far = 0; |
| 18139 | let ordering_bytes = u8::from(self.ordering).serialize(); |
| 18140 | let gc_bytes = self.gc.serialize(); |
| 18141 | let clip_x_origin_bytes = self.clip_x_origin.serialize(); |
| 18142 | let clip_y_origin_bytes = self.clip_y_origin.serialize(); |
| 18143 | let mut request0 = vec![ |
| 18144 | SET_CLIP_RECTANGLES_REQUEST, |
| 18145 | ordering_bytes[0], |
| 18146 | 0, |
| 18147 | 0, |
| 18148 | gc_bytes[0], |
| 18149 | gc_bytes[1], |
| 18150 | gc_bytes[2], |
| 18151 | gc_bytes[3], |
| 18152 | clip_x_origin_bytes[0], |
| 18153 | clip_x_origin_bytes[1], |
| 18154 | clip_y_origin_bytes[0], |
| 18155 | clip_y_origin_bytes[1], |
| 18156 | ]; |
| 18157 | let length_so_far = length_so_far + request0.len(); |
| 18158 | let rectangles_bytes = self.rectangles.serialize(); |
| 18159 | let length_so_far = length_so_far + rectangles_bytes.len(); |
| 18160 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 18161 | let length_so_far = length_so_far + padding0.len(); |
| 18162 | assert_eq!(length_so_far % 4, 0); |
| 18163 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 18164 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 18165 | ([request0.into(), rectangles_bytes.into(), padding0.into()], vec![]) |
| 18166 | } |
| 18167 | /// Parse this request given its header, its body, and any fds that go along with it |
| 18168 | #[cfg (feature = "request-parsing" )] |
| 18169 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 18170 | if header.major_opcode != SET_CLIP_RECTANGLES_REQUEST { |
| 18171 | return Err(ParseError::InvalidValue); |
| 18172 | } |
| 18173 | let remaining = &[header.minor_opcode]; |
| 18174 | let (ordering, remaining) = u8::try_parse(remaining)?; |
| 18175 | let ordering = ordering.into(); |
| 18176 | let _ = remaining; |
| 18177 | let (gc, remaining) = Gcontext::try_parse(value)?; |
| 18178 | let (clip_x_origin, remaining) = i16::try_parse(remaining)?; |
| 18179 | let (clip_y_origin, remaining) = i16::try_parse(remaining)?; |
| 18180 | let mut remaining = remaining; |
| 18181 | // Length is 'everything left in the input' |
| 18182 | let mut rectangles = Vec::new(); |
| 18183 | while !remaining.is_empty() { |
| 18184 | let (v, new_remaining) = Rectangle::try_parse(remaining)?; |
| 18185 | remaining = new_remaining; |
| 18186 | rectangles.push(v); |
| 18187 | } |
| 18188 | let _ = remaining; |
| 18189 | Ok(SetClipRectanglesRequest { |
| 18190 | ordering, |
| 18191 | gc, |
| 18192 | clip_x_origin, |
| 18193 | clip_y_origin, |
| 18194 | rectangles: Cow::Owned(rectangles), |
| 18195 | }) |
| 18196 | } |
| 18197 | /// Clone all borrowed data in this SetClipRectanglesRequest. |
| 18198 | pub fn into_owned(self) -> SetClipRectanglesRequest<'static> { |
| 18199 | SetClipRectanglesRequest { |
| 18200 | ordering: self.ordering, |
| 18201 | gc: self.gc, |
| 18202 | clip_x_origin: self.clip_x_origin, |
| 18203 | clip_y_origin: self.clip_y_origin, |
| 18204 | rectangles: Cow::Owned(self.rectangles.into_owned()), |
| 18205 | } |
| 18206 | } |
| 18207 | } |
| 18208 | impl<'input> Request for SetClipRectanglesRequest<'input> { |
| 18209 | const EXTENSION_NAME: Option<&'static str> = None; |
| 18210 | |
| 18211 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 18212 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 18213 | // Flatten the buffers into a single vector |
| 18214 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 18215 | (buf, fds) |
| 18216 | } |
| 18217 | } |
| 18218 | impl<'input> crate::x11_utils::VoidRequest for SetClipRectanglesRequest<'input> { |
| 18219 | } |
| 18220 | |
| 18221 | /// Opcode for the FreeGC request |
| 18222 | pub const FREE_GC_REQUEST: u8 = 60; |
| 18223 | /// Destroys a graphics context. |
| 18224 | /// |
| 18225 | /// Destroys the specified `gc` and all associated storage. |
| 18226 | /// |
| 18227 | /// # Fields |
| 18228 | /// |
| 18229 | /// * `gc` - The graphics context to destroy. |
| 18230 | /// |
| 18231 | /// # Errors |
| 18232 | /// |
| 18233 | /// * `GContext` - The specified graphics context does not exist. |
| 18234 | #[derive (Clone, Copy, Default)] |
| 18235 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 18236 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 18237 | pub struct FreeGCRequest { |
| 18238 | pub gc: Gcontext, |
| 18239 | } |
| 18240 | impl_debug_if_no_extra_traits!(FreeGCRequest, "FreeGCRequest" ); |
| 18241 | impl FreeGCRequest { |
| 18242 | /// Serialize this request into bytes for the provided connection |
| 18243 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 18244 | let length_so_far = 0; |
| 18245 | let gc_bytes = self.gc.serialize(); |
| 18246 | let mut request0 = vec![ |
| 18247 | FREE_GC_REQUEST, |
| 18248 | 0, |
| 18249 | 0, |
| 18250 | 0, |
| 18251 | gc_bytes[0], |
| 18252 | gc_bytes[1], |
| 18253 | gc_bytes[2], |
| 18254 | gc_bytes[3], |
| 18255 | ]; |
| 18256 | let length_so_far = length_so_far + request0.len(); |
| 18257 | assert_eq!(length_so_far % 4, 0); |
| 18258 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 18259 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 18260 | ([request0.into()], vec![]) |
| 18261 | } |
| 18262 | /// Parse this request given its header, its body, and any fds that go along with it |
| 18263 | #[cfg (feature = "request-parsing" )] |
| 18264 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 18265 | if header.major_opcode != FREE_GC_REQUEST { |
| 18266 | return Err(ParseError::InvalidValue); |
| 18267 | } |
| 18268 | let remaining = &[header.minor_opcode]; |
| 18269 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 18270 | let _ = remaining; |
| 18271 | let (gc, remaining) = Gcontext::try_parse(value)?; |
| 18272 | let _ = remaining; |
| 18273 | Ok(FreeGCRequest { |
| 18274 | gc, |
| 18275 | }) |
| 18276 | } |
| 18277 | } |
| 18278 | impl Request for FreeGCRequest { |
| 18279 | const EXTENSION_NAME: Option<&'static str> = None; |
| 18280 | |
| 18281 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 18282 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 18283 | // Flatten the buffers into a single vector |
| 18284 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 18285 | (buf, fds) |
| 18286 | } |
| 18287 | } |
| 18288 | impl crate::x11_utils::VoidRequest for FreeGCRequest { |
| 18289 | } |
| 18290 | |
| 18291 | /// Opcode for the ClearArea request |
| 18292 | pub const CLEAR_AREA_REQUEST: u8 = 61; |
| 18293 | #[derive (Clone, Copy, Default)] |
| 18294 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 18295 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 18296 | pub struct ClearAreaRequest { |
| 18297 | pub exposures: bool, |
| 18298 | pub window: Window, |
| 18299 | pub x: i16, |
| 18300 | pub y: i16, |
| 18301 | pub width: u16, |
| 18302 | pub height: u16, |
| 18303 | } |
| 18304 | impl_debug_if_no_extra_traits!(ClearAreaRequest, "ClearAreaRequest" ); |
| 18305 | impl ClearAreaRequest { |
| 18306 | /// Serialize this request into bytes for the provided connection |
| 18307 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 18308 | let length_so_far = 0; |
| 18309 | let exposures_bytes = self.exposures.serialize(); |
| 18310 | let window_bytes = self.window.serialize(); |
| 18311 | let x_bytes = self.x.serialize(); |
| 18312 | let y_bytes = self.y.serialize(); |
| 18313 | let width_bytes = self.width.serialize(); |
| 18314 | let height_bytes = self.height.serialize(); |
| 18315 | let mut request0 = vec![ |
| 18316 | CLEAR_AREA_REQUEST, |
| 18317 | exposures_bytes[0], |
| 18318 | 0, |
| 18319 | 0, |
| 18320 | window_bytes[0], |
| 18321 | window_bytes[1], |
| 18322 | window_bytes[2], |
| 18323 | window_bytes[3], |
| 18324 | x_bytes[0], |
| 18325 | x_bytes[1], |
| 18326 | y_bytes[0], |
| 18327 | y_bytes[1], |
| 18328 | width_bytes[0], |
| 18329 | width_bytes[1], |
| 18330 | height_bytes[0], |
| 18331 | height_bytes[1], |
| 18332 | ]; |
| 18333 | let length_so_far = length_so_far + request0.len(); |
| 18334 | assert_eq!(length_so_far % 4, 0); |
| 18335 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 18336 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 18337 | ([request0.into()], vec![]) |
| 18338 | } |
| 18339 | /// Parse this request given its header, its body, and any fds that go along with it |
| 18340 | #[cfg (feature = "request-parsing" )] |
| 18341 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 18342 | if header.major_opcode != CLEAR_AREA_REQUEST { |
| 18343 | return Err(ParseError::InvalidValue); |
| 18344 | } |
| 18345 | let remaining = &[header.minor_opcode]; |
| 18346 | let (exposures, remaining) = bool::try_parse(remaining)?; |
| 18347 | let _ = remaining; |
| 18348 | let (window, remaining) = Window::try_parse(value)?; |
| 18349 | let (x, remaining) = i16::try_parse(remaining)?; |
| 18350 | let (y, remaining) = i16::try_parse(remaining)?; |
| 18351 | let (width, remaining) = u16::try_parse(remaining)?; |
| 18352 | let (height, remaining) = u16::try_parse(remaining)?; |
| 18353 | let _ = remaining; |
| 18354 | Ok(ClearAreaRequest { |
| 18355 | exposures, |
| 18356 | window, |
| 18357 | x, |
| 18358 | y, |
| 18359 | width, |
| 18360 | height, |
| 18361 | }) |
| 18362 | } |
| 18363 | } |
| 18364 | impl Request for ClearAreaRequest { |
| 18365 | const EXTENSION_NAME: Option<&'static str> = None; |
| 18366 | |
| 18367 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 18368 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 18369 | // Flatten the buffers into a single vector |
| 18370 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 18371 | (buf, fds) |
| 18372 | } |
| 18373 | } |
| 18374 | impl crate::x11_utils::VoidRequest for ClearAreaRequest { |
| 18375 | } |
| 18376 | |
| 18377 | /// Opcode for the CopyArea request |
| 18378 | pub const COPY_AREA_REQUEST: u8 = 62; |
| 18379 | /// copy areas. |
| 18380 | /// |
| 18381 | /// Copies the specified rectangle from `src_drawable` to `dst_drawable`. |
| 18382 | /// |
| 18383 | /// # Fields |
| 18384 | /// |
| 18385 | /// * `dst_drawable` - The destination drawable (Window or Pixmap). |
| 18386 | /// * `src_drawable` - The source drawable (Window or Pixmap). |
| 18387 | /// * `gc` - The graphics context to use. |
| 18388 | /// * `src_x` - The source X coordinate. |
| 18389 | /// * `src_y` - The source Y coordinate. |
| 18390 | /// * `dst_x` - The destination X coordinate. |
| 18391 | /// * `dst_y` - The destination Y coordinate. |
| 18392 | /// * `width` - The width of the area to copy (in pixels). |
| 18393 | /// * `height` - The height of the area to copy (in pixels). |
| 18394 | /// |
| 18395 | /// # Errors |
| 18396 | /// |
| 18397 | /// * `Drawable` - The specified `drawable` (Window or Pixmap) does not exist. |
| 18398 | /// * `GContext` - The specified graphics context does not exist. |
| 18399 | /// * `Match` - `src_drawable` has a different root or depth than `dst_drawable`. |
| 18400 | #[derive (Clone, Copy, Default)] |
| 18401 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 18402 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 18403 | pub struct CopyAreaRequest { |
| 18404 | pub src_drawable: Drawable, |
| 18405 | pub dst_drawable: Drawable, |
| 18406 | pub gc: Gcontext, |
| 18407 | pub src_x: i16, |
| 18408 | pub src_y: i16, |
| 18409 | pub dst_x: i16, |
| 18410 | pub dst_y: i16, |
| 18411 | pub width: u16, |
| 18412 | pub height: u16, |
| 18413 | } |
| 18414 | impl_debug_if_no_extra_traits!(CopyAreaRequest, "CopyAreaRequest" ); |
| 18415 | impl CopyAreaRequest { |
| 18416 | /// Serialize this request into bytes for the provided connection |
| 18417 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 18418 | let length_so_far = 0; |
| 18419 | let src_drawable_bytes = self.src_drawable.serialize(); |
| 18420 | let dst_drawable_bytes = self.dst_drawable.serialize(); |
| 18421 | let gc_bytes = self.gc.serialize(); |
| 18422 | let src_x_bytes = self.src_x.serialize(); |
| 18423 | let src_y_bytes = self.src_y.serialize(); |
| 18424 | let dst_x_bytes = self.dst_x.serialize(); |
| 18425 | let dst_y_bytes = self.dst_y.serialize(); |
| 18426 | let width_bytes = self.width.serialize(); |
| 18427 | let height_bytes = self.height.serialize(); |
| 18428 | let mut request0 = vec![ |
| 18429 | COPY_AREA_REQUEST, |
| 18430 | 0, |
| 18431 | 0, |
| 18432 | 0, |
| 18433 | src_drawable_bytes[0], |
| 18434 | src_drawable_bytes[1], |
| 18435 | src_drawable_bytes[2], |
| 18436 | src_drawable_bytes[3], |
| 18437 | dst_drawable_bytes[0], |
| 18438 | dst_drawable_bytes[1], |
| 18439 | dst_drawable_bytes[2], |
| 18440 | dst_drawable_bytes[3], |
| 18441 | gc_bytes[0], |
| 18442 | gc_bytes[1], |
| 18443 | gc_bytes[2], |
| 18444 | gc_bytes[3], |
| 18445 | src_x_bytes[0], |
| 18446 | src_x_bytes[1], |
| 18447 | src_y_bytes[0], |
| 18448 | src_y_bytes[1], |
| 18449 | dst_x_bytes[0], |
| 18450 | dst_x_bytes[1], |
| 18451 | dst_y_bytes[0], |
| 18452 | dst_y_bytes[1], |
| 18453 | width_bytes[0], |
| 18454 | width_bytes[1], |
| 18455 | height_bytes[0], |
| 18456 | height_bytes[1], |
| 18457 | ]; |
| 18458 | let length_so_far = length_so_far + request0.len(); |
| 18459 | assert_eq!(length_so_far % 4, 0); |
| 18460 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 18461 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 18462 | ([request0.into()], vec![]) |
| 18463 | } |
| 18464 | /// Parse this request given its header, its body, and any fds that go along with it |
| 18465 | #[cfg (feature = "request-parsing" )] |
| 18466 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 18467 | if header.major_opcode != COPY_AREA_REQUEST { |
| 18468 | return Err(ParseError::InvalidValue); |
| 18469 | } |
| 18470 | let remaining = &[header.minor_opcode]; |
| 18471 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 18472 | let _ = remaining; |
| 18473 | let (src_drawable, remaining) = Drawable::try_parse(value)?; |
| 18474 | let (dst_drawable, remaining) = Drawable::try_parse(remaining)?; |
| 18475 | let (gc, remaining) = Gcontext::try_parse(remaining)?; |
| 18476 | let (src_x, remaining) = i16::try_parse(remaining)?; |
| 18477 | let (src_y, remaining) = i16::try_parse(remaining)?; |
| 18478 | let (dst_x, remaining) = i16::try_parse(remaining)?; |
| 18479 | let (dst_y, remaining) = i16::try_parse(remaining)?; |
| 18480 | let (width, remaining) = u16::try_parse(remaining)?; |
| 18481 | let (height, remaining) = u16::try_parse(remaining)?; |
| 18482 | let _ = remaining; |
| 18483 | Ok(CopyAreaRequest { |
| 18484 | src_drawable, |
| 18485 | dst_drawable, |
| 18486 | gc, |
| 18487 | src_x, |
| 18488 | src_y, |
| 18489 | dst_x, |
| 18490 | dst_y, |
| 18491 | width, |
| 18492 | height, |
| 18493 | }) |
| 18494 | } |
| 18495 | } |
| 18496 | impl Request for CopyAreaRequest { |
| 18497 | const EXTENSION_NAME: Option<&'static str> = None; |
| 18498 | |
| 18499 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 18500 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 18501 | // Flatten the buffers into a single vector |
| 18502 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 18503 | (buf, fds) |
| 18504 | } |
| 18505 | } |
| 18506 | impl crate::x11_utils::VoidRequest for CopyAreaRequest { |
| 18507 | } |
| 18508 | |
| 18509 | /// Opcode for the CopyPlane request |
| 18510 | pub const COPY_PLANE_REQUEST: u8 = 63; |
| 18511 | #[derive (Clone, Copy, Default)] |
| 18512 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 18513 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 18514 | pub struct CopyPlaneRequest { |
| 18515 | pub src_drawable: Drawable, |
| 18516 | pub dst_drawable: Drawable, |
| 18517 | pub gc: Gcontext, |
| 18518 | pub src_x: i16, |
| 18519 | pub src_y: i16, |
| 18520 | pub dst_x: i16, |
| 18521 | pub dst_y: i16, |
| 18522 | pub width: u16, |
| 18523 | pub height: u16, |
| 18524 | pub bit_plane: u32, |
| 18525 | } |
| 18526 | impl_debug_if_no_extra_traits!(CopyPlaneRequest, "CopyPlaneRequest" ); |
| 18527 | impl CopyPlaneRequest { |
| 18528 | /// Serialize this request into bytes for the provided connection |
| 18529 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 18530 | let length_so_far = 0; |
| 18531 | let src_drawable_bytes = self.src_drawable.serialize(); |
| 18532 | let dst_drawable_bytes = self.dst_drawable.serialize(); |
| 18533 | let gc_bytes = self.gc.serialize(); |
| 18534 | let src_x_bytes = self.src_x.serialize(); |
| 18535 | let src_y_bytes = self.src_y.serialize(); |
| 18536 | let dst_x_bytes = self.dst_x.serialize(); |
| 18537 | let dst_y_bytes = self.dst_y.serialize(); |
| 18538 | let width_bytes = self.width.serialize(); |
| 18539 | let height_bytes = self.height.serialize(); |
| 18540 | let bit_plane_bytes = self.bit_plane.serialize(); |
| 18541 | let mut request0 = vec![ |
| 18542 | COPY_PLANE_REQUEST, |
| 18543 | 0, |
| 18544 | 0, |
| 18545 | 0, |
| 18546 | src_drawable_bytes[0], |
| 18547 | src_drawable_bytes[1], |
| 18548 | src_drawable_bytes[2], |
| 18549 | src_drawable_bytes[3], |
| 18550 | dst_drawable_bytes[0], |
| 18551 | dst_drawable_bytes[1], |
| 18552 | dst_drawable_bytes[2], |
| 18553 | dst_drawable_bytes[3], |
| 18554 | gc_bytes[0], |
| 18555 | gc_bytes[1], |
| 18556 | gc_bytes[2], |
| 18557 | gc_bytes[3], |
| 18558 | src_x_bytes[0], |
| 18559 | src_x_bytes[1], |
| 18560 | src_y_bytes[0], |
| 18561 | src_y_bytes[1], |
| 18562 | dst_x_bytes[0], |
| 18563 | dst_x_bytes[1], |
| 18564 | dst_y_bytes[0], |
| 18565 | dst_y_bytes[1], |
| 18566 | width_bytes[0], |
| 18567 | width_bytes[1], |
| 18568 | height_bytes[0], |
| 18569 | height_bytes[1], |
| 18570 | bit_plane_bytes[0], |
| 18571 | bit_plane_bytes[1], |
| 18572 | bit_plane_bytes[2], |
| 18573 | bit_plane_bytes[3], |
| 18574 | ]; |
| 18575 | let length_so_far = length_so_far + request0.len(); |
| 18576 | assert_eq!(length_so_far % 4, 0); |
| 18577 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 18578 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 18579 | ([request0.into()], vec![]) |
| 18580 | } |
| 18581 | /// Parse this request given its header, its body, and any fds that go along with it |
| 18582 | #[cfg (feature = "request-parsing" )] |
| 18583 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 18584 | if header.major_opcode != COPY_PLANE_REQUEST { |
| 18585 | return Err(ParseError::InvalidValue); |
| 18586 | } |
| 18587 | let remaining = &[header.minor_opcode]; |
| 18588 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 18589 | let _ = remaining; |
| 18590 | let (src_drawable, remaining) = Drawable::try_parse(value)?; |
| 18591 | let (dst_drawable, remaining) = Drawable::try_parse(remaining)?; |
| 18592 | let (gc, remaining) = Gcontext::try_parse(remaining)?; |
| 18593 | let (src_x, remaining) = i16::try_parse(remaining)?; |
| 18594 | let (src_y, remaining) = i16::try_parse(remaining)?; |
| 18595 | let (dst_x, remaining) = i16::try_parse(remaining)?; |
| 18596 | let (dst_y, remaining) = i16::try_parse(remaining)?; |
| 18597 | let (width, remaining) = u16::try_parse(remaining)?; |
| 18598 | let (height, remaining) = u16::try_parse(remaining)?; |
| 18599 | let (bit_plane, remaining) = u32::try_parse(remaining)?; |
| 18600 | let _ = remaining; |
| 18601 | Ok(CopyPlaneRequest { |
| 18602 | src_drawable, |
| 18603 | dst_drawable, |
| 18604 | gc, |
| 18605 | src_x, |
| 18606 | src_y, |
| 18607 | dst_x, |
| 18608 | dst_y, |
| 18609 | width, |
| 18610 | height, |
| 18611 | bit_plane, |
| 18612 | }) |
| 18613 | } |
| 18614 | } |
| 18615 | impl Request for CopyPlaneRequest { |
| 18616 | const EXTENSION_NAME: Option<&'static str> = None; |
| 18617 | |
| 18618 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 18619 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 18620 | // Flatten the buffers into a single vector |
| 18621 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 18622 | (buf, fds) |
| 18623 | } |
| 18624 | } |
| 18625 | impl crate::x11_utils::VoidRequest for CopyPlaneRequest { |
| 18626 | } |
| 18627 | |
| 18628 | /// # Fields |
| 18629 | /// |
| 18630 | /// * `Origin` - Treats all coordinates as relative to the origin. |
| 18631 | /// * `Previous` - Treats all coordinates after the first as relative to the previous coordinate. |
| 18632 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 18633 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 18634 | pub struct CoordMode(u8); |
| 18635 | impl CoordMode { |
| 18636 | pub const ORIGIN: Self = Self(0); |
| 18637 | pub const PREVIOUS: Self = Self(1); |
| 18638 | } |
| 18639 | impl From<CoordMode> for u8 { |
| 18640 | #[inline ] |
| 18641 | fn from(input: CoordMode) -> Self { |
| 18642 | input.0 |
| 18643 | } |
| 18644 | } |
| 18645 | impl From<CoordMode> for Option<u8> { |
| 18646 | #[inline ] |
| 18647 | fn from(input: CoordMode) -> Self { |
| 18648 | Some(input.0) |
| 18649 | } |
| 18650 | } |
| 18651 | impl From<CoordMode> for u16 { |
| 18652 | #[inline ] |
| 18653 | fn from(input: CoordMode) -> Self { |
| 18654 | u16::from(input.0) |
| 18655 | } |
| 18656 | } |
| 18657 | impl From<CoordMode> for Option<u16> { |
| 18658 | #[inline ] |
| 18659 | fn from(input: CoordMode) -> Self { |
| 18660 | Some(u16::from(input.0)) |
| 18661 | } |
| 18662 | } |
| 18663 | impl From<CoordMode> for u32 { |
| 18664 | #[inline ] |
| 18665 | fn from(input: CoordMode) -> Self { |
| 18666 | u32::from(input.0) |
| 18667 | } |
| 18668 | } |
| 18669 | impl From<CoordMode> for Option<u32> { |
| 18670 | #[inline ] |
| 18671 | fn from(input: CoordMode) -> Self { |
| 18672 | Some(u32::from(input.0)) |
| 18673 | } |
| 18674 | } |
| 18675 | impl From<u8> for CoordMode { |
| 18676 | #[inline ] |
| 18677 | fn from(value: u8) -> Self { |
| 18678 | Self(value) |
| 18679 | } |
| 18680 | } |
| 18681 | impl core::fmt::Debug for CoordMode { |
| 18682 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 18683 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 18684 | (Self::ORIGIN.0.into(), "ORIGIN" , "Origin" ), |
| 18685 | (Self::PREVIOUS.0.into(), "PREVIOUS" , "Previous" ), |
| 18686 | ]; |
| 18687 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 18688 | } |
| 18689 | } |
| 18690 | |
| 18691 | /// Opcode for the PolyPoint request |
| 18692 | pub const POLY_POINT_REQUEST: u8 = 64; |
| 18693 | #[derive (Clone, Default)] |
| 18694 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 18695 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 18696 | pub struct PolyPointRequest<'input> { |
| 18697 | pub coordinate_mode: CoordMode, |
| 18698 | pub drawable: Drawable, |
| 18699 | pub gc: Gcontext, |
| 18700 | pub points: Cow<'input, [Point]>, |
| 18701 | } |
| 18702 | impl_debug_if_no_extra_traits!(PolyPointRequest<'_>, "PolyPointRequest" ); |
| 18703 | impl<'input> PolyPointRequest<'input> { |
| 18704 | /// Serialize this request into bytes for the provided connection |
| 18705 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 18706 | let length_so_far = 0; |
| 18707 | let coordinate_mode_bytes = u8::from(self.coordinate_mode).serialize(); |
| 18708 | let drawable_bytes = self.drawable.serialize(); |
| 18709 | let gc_bytes = self.gc.serialize(); |
| 18710 | let mut request0 = vec![ |
| 18711 | POLY_POINT_REQUEST, |
| 18712 | coordinate_mode_bytes[0], |
| 18713 | 0, |
| 18714 | 0, |
| 18715 | drawable_bytes[0], |
| 18716 | drawable_bytes[1], |
| 18717 | drawable_bytes[2], |
| 18718 | drawable_bytes[3], |
| 18719 | gc_bytes[0], |
| 18720 | gc_bytes[1], |
| 18721 | gc_bytes[2], |
| 18722 | gc_bytes[3], |
| 18723 | ]; |
| 18724 | let length_so_far = length_so_far + request0.len(); |
| 18725 | let points_bytes = self.points.serialize(); |
| 18726 | let length_so_far = length_so_far + points_bytes.len(); |
| 18727 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 18728 | let length_so_far = length_so_far + padding0.len(); |
| 18729 | assert_eq!(length_so_far % 4, 0); |
| 18730 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 18731 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 18732 | ([request0.into(), points_bytes.into(), padding0.into()], vec![]) |
| 18733 | } |
| 18734 | /// Parse this request given its header, its body, and any fds that go along with it |
| 18735 | #[cfg (feature = "request-parsing" )] |
| 18736 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 18737 | if header.major_opcode != POLY_POINT_REQUEST { |
| 18738 | return Err(ParseError::InvalidValue); |
| 18739 | } |
| 18740 | let remaining = &[header.minor_opcode]; |
| 18741 | let (coordinate_mode, remaining) = u8::try_parse(remaining)?; |
| 18742 | let coordinate_mode = coordinate_mode.into(); |
| 18743 | let _ = remaining; |
| 18744 | let (drawable, remaining) = Drawable::try_parse(value)?; |
| 18745 | let (gc, remaining) = Gcontext::try_parse(remaining)?; |
| 18746 | let mut remaining = remaining; |
| 18747 | // Length is 'everything left in the input' |
| 18748 | let mut points = Vec::new(); |
| 18749 | while !remaining.is_empty() { |
| 18750 | let (v, new_remaining) = Point::try_parse(remaining)?; |
| 18751 | remaining = new_remaining; |
| 18752 | points.push(v); |
| 18753 | } |
| 18754 | let _ = remaining; |
| 18755 | Ok(PolyPointRequest { |
| 18756 | coordinate_mode, |
| 18757 | drawable, |
| 18758 | gc, |
| 18759 | points: Cow::Owned(points), |
| 18760 | }) |
| 18761 | } |
| 18762 | /// Clone all borrowed data in this PolyPointRequest. |
| 18763 | pub fn into_owned(self) -> PolyPointRequest<'static> { |
| 18764 | PolyPointRequest { |
| 18765 | coordinate_mode: self.coordinate_mode, |
| 18766 | drawable: self.drawable, |
| 18767 | gc: self.gc, |
| 18768 | points: Cow::Owned(self.points.into_owned()), |
| 18769 | } |
| 18770 | } |
| 18771 | } |
| 18772 | impl<'input> Request for PolyPointRequest<'input> { |
| 18773 | const EXTENSION_NAME: Option<&'static str> = None; |
| 18774 | |
| 18775 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 18776 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 18777 | // Flatten the buffers into a single vector |
| 18778 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 18779 | (buf, fds) |
| 18780 | } |
| 18781 | } |
| 18782 | impl<'input> crate::x11_utils::VoidRequest for PolyPointRequest<'input> { |
| 18783 | } |
| 18784 | |
| 18785 | /// Opcode for the PolyLine request |
| 18786 | pub const POLY_LINE_REQUEST: u8 = 65; |
| 18787 | /// draw lines. |
| 18788 | /// |
| 18789 | /// Draws `points_len`-1 lines between each pair of points (point[i], point[i+1]) |
| 18790 | /// in the `points` array. The lines are drawn in the order listed in the array. |
| 18791 | /// They join correctly at all intermediate points, and if the first and last |
| 18792 | /// points coincide, the first and last lines also join correctly. For any given |
| 18793 | /// line, a pixel is not drawn more than once. If thin (zero line-width) lines |
| 18794 | /// intersect, the intersecting pixels are drawn multiple times. If wide lines |
| 18795 | /// intersect, the intersecting pixels are drawn only once, as though the entire |
| 18796 | /// request were a single, filled shape. |
| 18797 | /// |
| 18798 | /// # Fields |
| 18799 | /// |
| 18800 | /// * `drawable` - The drawable to draw the line(s) on. |
| 18801 | /// * `gc` - The graphics context to use. |
| 18802 | /// * `points_len` - The number of `xcb_point_t` structures in `points`. |
| 18803 | /// * `points` - An array of points. |
| 18804 | /// * `coordinate_mode` - |
| 18805 | /// |
| 18806 | /// # Errors |
| 18807 | /// |
| 18808 | /// * `Drawable` - TODO: reasons? |
| 18809 | /// * `GContext` - TODO: reasons? |
| 18810 | /// * `Match` - TODO: reasons? |
| 18811 | /// * `Value` - TODO: reasons? |
| 18812 | /// |
| 18813 | /// # Example |
| 18814 | /// |
| 18815 | /// ```text |
| 18816 | /// /* |
| 18817 | /// * Draw a straight line. |
| 18818 | /// * |
| 18819 | /// */ |
| 18820 | /// void my_example(xcb_connection_t *conn, xcb_drawable_t drawable, xcb_gcontext_t gc) { |
| 18821 | /// xcb_poly_line(conn, XCB_COORD_MODE_ORIGIN, drawable, gc, 2, |
| 18822 | /// (xcb_point_t[]) { {10, 10}, {100, 10} }); |
| 18823 | /// xcb_flush(conn); |
| 18824 | /// } |
| 18825 | /// ``` |
| 18826 | #[derive (Clone, Default)] |
| 18827 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 18828 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 18829 | pub struct PolyLineRequest<'input> { |
| 18830 | pub coordinate_mode: CoordMode, |
| 18831 | pub drawable: Drawable, |
| 18832 | pub gc: Gcontext, |
| 18833 | pub points: Cow<'input, [Point]>, |
| 18834 | } |
| 18835 | impl_debug_if_no_extra_traits!(PolyLineRequest<'_>, "PolyLineRequest" ); |
| 18836 | impl<'input> PolyLineRequest<'input> { |
| 18837 | /// Serialize this request into bytes for the provided connection |
| 18838 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 18839 | let length_so_far = 0; |
| 18840 | let coordinate_mode_bytes = u8::from(self.coordinate_mode).serialize(); |
| 18841 | let drawable_bytes = self.drawable.serialize(); |
| 18842 | let gc_bytes = self.gc.serialize(); |
| 18843 | let mut request0 = vec![ |
| 18844 | POLY_LINE_REQUEST, |
| 18845 | coordinate_mode_bytes[0], |
| 18846 | 0, |
| 18847 | 0, |
| 18848 | drawable_bytes[0], |
| 18849 | drawable_bytes[1], |
| 18850 | drawable_bytes[2], |
| 18851 | drawable_bytes[3], |
| 18852 | gc_bytes[0], |
| 18853 | gc_bytes[1], |
| 18854 | gc_bytes[2], |
| 18855 | gc_bytes[3], |
| 18856 | ]; |
| 18857 | let length_so_far = length_so_far + request0.len(); |
| 18858 | let points_bytes = self.points.serialize(); |
| 18859 | let length_so_far = length_so_far + points_bytes.len(); |
| 18860 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 18861 | let length_so_far = length_so_far + padding0.len(); |
| 18862 | assert_eq!(length_so_far % 4, 0); |
| 18863 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 18864 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 18865 | ([request0.into(), points_bytes.into(), padding0.into()], vec![]) |
| 18866 | } |
| 18867 | /// Parse this request given its header, its body, and any fds that go along with it |
| 18868 | #[cfg (feature = "request-parsing" )] |
| 18869 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 18870 | if header.major_opcode != POLY_LINE_REQUEST { |
| 18871 | return Err(ParseError::InvalidValue); |
| 18872 | } |
| 18873 | let remaining = &[header.minor_opcode]; |
| 18874 | let (coordinate_mode, remaining) = u8::try_parse(remaining)?; |
| 18875 | let coordinate_mode = coordinate_mode.into(); |
| 18876 | let _ = remaining; |
| 18877 | let (drawable, remaining) = Drawable::try_parse(value)?; |
| 18878 | let (gc, remaining) = Gcontext::try_parse(remaining)?; |
| 18879 | let mut remaining = remaining; |
| 18880 | // Length is 'everything left in the input' |
| 18881 | let mut points = Vec::new(); |
| 18882 | while !remaining.is_empty() { |
| 18883 | let (v, new_remaining) = Point::try_parse(remaining)?; |
| 18884 | remaining = new_remaining; |
| 18885 | points.push(v); |
| 18886 | } |
| 18887 | let _ = remaining; |
| 18888 | Ok(PolyLineRequest { |
| 18889 | coordinate_mode, |
| 18890 | drawable, |
| 18891 | gc, |
| 18892 | points: Cow::Owned(points), |
| 18893 | }) |
| 18894 | } |
| 18895 | /// Clone all borrowed data in this PolyLineRequest. |
| 18896 | pub fn into_owned(self) -> PolyLineRequest<'static> { |
| 18897 | PolyLineRequest { |
| 18898 | coordinate_mode: self.coordinate_mode, |
| 18899 | drawable: self.drawable, |
| 18900 | gc: self.gc, |
| 18901 | points: Cow::Owned(self.points.into_owned()), |
| 18902 | } |
| 18903 | } |
| 18904 | } |
| 18905 | impl<'input> Request for PolyLineRequest<'input> { |
| 18906 | const EXTENSION_NAME: Option<&'static str> = None; |
| 18907 | |
| 18908 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 18909 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 18910 | // Flatten the buffers into a single vector |
| 18911 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 18912 | (buf, fds) |
| 18913 | } |
| 18914 | } |
| 18915 | impl<'input> crate::x11_utils::VoidRequest for PolyLineRequest<'input> { |
| 18916 | } |
| 18917 | |
| 18918 | #[derive (Clone, Copy, Default)] |
| 18919 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 18920 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 18921 | pub struct Segment { |
| 18922 | pub x1: i16, |
| 18923 | pub y1: i16, |
| 18924 | pub x2: i16, |
| 18925 | pub y2: i16, |
| 18926 | } |
| 18927 | impl_debug_if_no_extra_traits!(Segment, "Segment" ); |
| 18928 | impl TryParse for Segment { |
| 18929 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 18930 | let (x1: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 18931 | let (y1: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 18932 | let (x2: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 18933 | let (y2: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 18934 | let result: Segment = Segment { x1, y1, x2, y2 }; |
| 18935 | Ok((result, remaining)) |
| 18936 | } |
| 18937 | } |
| 18938 | impl Serialize for Segment { |
| 18939 | type Bytes = [u8; 8]; |
| 18940 | fn serialize(&self) -> [u8; 8] { |
| 18941 | let x1_bytes = self.x1.serialize(); |
| 18942 | let y1_bytes = self.y1.serialize(); |
| 18943 | let x2_bytes = self.x2.serialize(); |
| 18944 | let y2_bytes = self.y2.serialize(); |
| 18945 | [ |
| 18946 | x1_bytes[0], |
| 18947 | x1_bytes[1], |
| 18948 | y1_bytes[0], |
| 18949 | y1_bytes[1], |
| 18950 | x2_bytes[0], |
| 18951 | x2_bytes[1], |
| 18952 | y2_bytes[0], |
| 18953 | y2_bytes[1], |
| 18954 | ] |
| 18955 | } |
| 18956 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 18957 | bytes.reserve(8); |
| 18958 | self.x1.serialize_into(bytes); |
| 18959 | self.y1.serialize_into(bytes); |
| 18960 | self.x2.serialize_into(bytes); |
| 18961 | self.y2.serialize_into(bytes); |
| 18962 | } |
| 18963 | } |
| 18964 | |
| 18965 | /// Opcode for the PolySegment request |
| 18966 | pub const POLY_SEGMENT_REQUEST: u8 = 66; |
| 18967 | /// draw lines. |
| 18968 | /// |
| 18969 | /// Draws multiple, unconnected lines. For each segment, a line is drawn between |
| 18970 | /// (x1, y1) and (x2, y2). The lines are drawn in the order listed in the array of |
| 18971 | /// `xcb_segment_t` structures and does not perform joining at coincident |
| 18972 | /// endpoints. For any given line, a pixel is not drawn more than once. If lines |
| 18973 | /// intersect, the intersecting pixels are drawn multiple times. |
| 18974 | /// |
| 18975 | /// TODO: include the xcb_segment_t data structure |
| 18976 | /// |
| 18977 | /// TODO: an example |
| 18978 | /// |
| 18979 | /// # Fields |
| 18980 | /// |
| 18981 | /// * `drawable` - A drawable (Window or Pixmap) to draw on. |
| 18982 | /// * `gc` - The graphics context to use. |
| 18983 | /// |
| 18984 | /// TODO: document which attributes of a gc are used |
| 18985 | /// * `segments_len` - The number of `xcb_segment_t` structures in `segments`. |
| 18986 | /// * `segments` - An array of `xcb_segment_t` structures. |
| 18987 | /// |
| 18988 | /// # Errors |
| 18989 | /// |
| 18990 | /// * `Drawable` - The specified `drawable` does not exist. |
| 18991 | /// * `GContext` - The specified `gc` does not exist. |
| 18992 | /// * `Match` - TODO: reasons? |
| 18993 | #[derive (Clone, Default)] |
| 18994 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 18995 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 18996 | pub struct PolySegmentRequest<'input> { |
| 18997 | pub drawable: Drawable, |
| 18998 | pub gc: Gcontext, |
| 18999 | pub segments: Cow<'input, [Segment]>, |
| 19000 | } |
| 19001 | impl_debug_if_no_extra_traits!(PolySegmentRequest<'_>, "PolySegmentRequest" ); |
| 19002 | impl<'input> PolySegmentRequest<'input> { |
| 19003 | /// Serialize this request into bytes for the provided connection |
| 19004 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 19005 | let length_so_far = 0; |
| 19006 | let drawable_bytes = self.drawable.serialize(); |
| 19007 | let gc_bytes = self.gc.serialize(); |
| 19008 | let mut request0 = vec![ |
| 19009 | POLY_SEGMENT_REQUEST, |
| 19010 | 0, |
| 19011 | 0, |
| 19012 | 0, |
| 19013 | drawable_bytes[0], |
| 19014 | drawable_bytes[1], |
| 19015 | drawable_bytes[2], |
| 19016 | drawable_bytes[3], |
| 19017 | gc_bytes[0], |
| 19018 | gc_bytes[1], |
| 19019 | gc_bytes[2], |
| 19020 | gc_bytes[3], |
| 19021 | ]; |
| 19022 | let length_so_far = length_so_far + request0.len(); |
| 19023 | let segments_bytes = self.segments.serialize(); |
| 19024 | let length_so_far = length_so_far + segments_bytes.len(); |
| 19025 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 19026 | let length_so_far = length_so_far + padding0.len(); |
| 19027 | assert_eq!(length_so_far % 4, 0); |
| 19028 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 19029 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 19030 | ([request0.into(), segments_bytes.into(), padding0.into()], vec![]) |
| 19031 | } |
| 19032 | /// Parse this request given its header, its body, and any fds that go along with it |
| 19033 | #[cfg (feature = "request-parsing" )] |
| 19034 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 19035 | if header.major_opcode != POLY_SEGMENT_REQUEST { |
| 19036 | return Err(ParseError::InvalidValue); |
| 19037 | } |
| 19038 | let remaining = &[header.minor_opcode]; |
| 19039 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 19040 | let _ = remaining; |
| 19041 | let (drawable, remaining) = Drawable::try_parse(value)?; |
| 19042 | let (gc, remaining) = Gcontext::try_parse(remaining)?; |
| 19043 | let mut remaining = remaining; |
| 19044 | // Length is 'everything left in the input' |
| 19045 | let mut segments = Vec::new(); |
| 19046 | while !remaining.is_empty() { |
| 19047 | let (v, new_remaining) = Segment::try_parse(remaining)?; |
| 19048 | remaining = new_remaining; |
| 19049 | segments.push(v); |
| 19050 | } |
| 19051 | let _ = remaining; |
| 19052 | Ok(PolySegmentRequest { |
| 19053 | drawable, |
| 19054 | gc, |
| 19055 | segments: Cow::Owned(segments), |
| 19056 | }) |
| 19057 | } |
| 19058 | /// Clone all borrowed data in this PolySegmentRequest. |
| 19059 | pub fn into_owned(self) -> PolySegmentRequest<'static> { |
| 19060 | PolySegmentRequest { |
| 19061 | drawable: self.drawable, |
| 19062 | gc: self.gc, |
| 19063 | segments: Cow::Owned(self.segments.into_owned()), |
| 19064 | } |
| 19065 | } |
| 19066 | } |
| 19067 | impl<'input> Request for PolySegmentRequest<'input> { |
| 19068 | const EXTENSION_NAME: Option<&'static str> = None; |
| 19069 | |
| 19070 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 19071 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 19072 | // Flatten the buffers into a single vector |
| 19073 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 19074 | (buf, fds) |
| 19075 | } |
| 19076 | } |
| 19077 | impl<'input> crate::x11_utils::VoidRequest for PolySegmentRequest<'input> { |
| 19078 | } |
| 19079 | |
| 19080 | /// Opcode for the PolyRectangle request |
| 19081 | pub const POLY_RECTANGLE_REQUEST: u8 = 67; |
| 19082 | #[derive (Clone, Default)] |
| 19083 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 19084 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 19085 | pub struct PolyRectangleRequest<'input> { |
| 19086 | pub drawable: Drawable, |
| 19087 | pub gc: Gcontext, |
| 19088 | pub rectangles: Cow<'input, [Rectangle]>, |
| 19089 | } |
| 19090 | impl_debug_if_no_extra_traits!(PolyRectangleRequest<'_>, "PolyRectangleRequest" ); |
| 19091 | impl<'input> PolyRectangleRequest<'input> { |
| 19092 | /// Serialize this request into bytes for the provided connection |
| 19093 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 19094 | let length_so_far = 0; |
| 19095 | let drawable_bytes = self.drawable.serialize(); |
| 19096 | let gc_bytes = self.gc.serialize(); |
| 19097 | let mut request0 = vec![ |
| 19098 | POLY_RECTANGLE_REQUEST, |
| 19099 | 0, |
| 19100 | 0, |
| 19101 | 0, |
| 19102 | drawable_bytes[0], |
| 19103 | drawable_bytes[1], |
| 19104 | drawable_bytes[2], |
| 19105 | drawable_bytes[3], |
| 19106 | gc_bytes[0], |
| 19107 | gc_bytes[1], |
| 19108 | gc_bytes[2], |
| 19109 | gc_bytes[3], |
| 19110 | ]; |
| 19111 | let length_so_far = length_so_far + request0.len(); |
| 19112 | let rectangles_bytes = self.rectangles.serialize(); |
| 19113 | let length_so_far = length_so_far + rectangles_bytes.len(); |
| 19114 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 19115 | let length_so_far = length_so_far + padding0.len(); |
| 19116 | assert_eq!(length_so_far % 4, 0); |
| 19117 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 19118 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 19119 | ([request0.into(), rectangles_bytes.into(), padding0.into()], vec![]) |
| 19120 | } |
| 19121 | /// Parse this request given its header, its body, and any fds that go along with it |
| 19122 | #[cfg (feature = "request-parsing" )] |
| 19123 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 19124 | if header.major_opcode != POLY_RECTANGLE_REQUEST { |
| 19125 | return Err(ParseError::InvalidValue); |
| 19126 | } |
| 19127 | let remaining = &[header.minor_opcode]; |
| 19128 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 19129 | let _ = remaining; |
| 19130 | let (drawable, remaining) = Drawable::try_parse(value)?; |
| 19131 | let (gc, remaining) = Gcontext::try_parse(remaining)?; |
| 19132 | let mut remaining = remaining; |
| 19133 | // Length is 'everything left in the input' |
| 19134 | let mut rectangles = Vec::new(); |
| 19135 | while !remaining.is_empty() { |
| 19136 | let (v, new_remaining) = Rectangle::try_parse(remaining)?; |
| 19137 | remaining = new_remaining; |
| 19138 | rectangles.push(v); |
| 19139 | } |
| 19140 | let _ = remaining; |
| 19141 | Ok(PolyRectangleRequest { |
| 19142 | drawable, |
| 19143 | gc, |
| 19144 | rectangles: Cow::Owned(rectangles), |
| 19145 | }) |
| 19146 | } |
| 19147 | /// Clone all borrowed data in this PolyRectangleRequest. |
| 19148 | pub fn into_owned(self) -> PolyRectangleRequest<'static> { |
| 19149 | PolyRectangleRequest { |
| 19150 | drawable: self.drawable, |
| 19151 | gc: self.gc, |
| 19152 | rectangles: Cow::Owned(self.rectangles.into_owned()), |
| 19153 | } |
| 19154 | } |
| 19155 | } |
| 19156 | impl<'input> Request for PolyRectangleRequest<'input> { |
| 19157 | const EXTENSION_NAME: Option<&'static str> = None; |
| 19158 | |
| 19159 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 19160 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 19161 | // Flatten the buffers into a single vector |
| 19162 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 19163 | (buf, fds) |
| 19164 | } |
| 19165 | } |
| 19166 | impl<'input> crate::x11_utils::VoidRequest for PolyRectangleRequest<'input> { |
| 19167 | } |
| 19168 | |
| 19169 | /// Opcode for the PolyArc request |
| 19170 | pub const POLY_ARC_REQUEST: u8 = 68; |
| 19171 | #[derive (Clone, Default)] |
| 19172 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 19173 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 19174 | pub struct PolyArcRequest<'input> { |
| 19175 | pub drawable: Drawable, |
| 19176 | pub gc: Gcontext, |
| 19177 | pub arcs: Cow<'input, [Arc]>, |
| 19178 | } |
| 19179 | impl_debug_if_no_extra_traits!(PolyArcRequest<'_>, "PolyArcRequest" ); |
| 19180 | impl<'input> PolyArcRequest<'input> { |
| 19181 | /// Serialize this request into bytes for the provided connection |
| 19182 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 19183 | let length_so_far = 0; |
| 19184 | let drawable_bytes = self.drawable.serialize(); |
| 19185 | let gc_bytes = self.gc.serialize(); |
| 19186 | let mut request0 = vec![ |
| 19187 | POLY_ARC_REQUEST, |
| 19188 | 0, |
| 19189 | 0, |
| 19190 | 0, |
| 19191 | drawable_bytes[0], |
| 19192 | drawable_bytes[1], |
| 19193 | drawable_bytes[2], |
| 19194 | drawable_bytes[3], |
| 19195 | gc_bytes[0], |
| 19196 | gc_bytes[1], |
| 19197 | gc_bytes[2], |
| 19198 | gc_bytes[3], |
| 19199 | ]; |
| 19200 | let length_so_far = length_so_far + request0.len(); |
| 19201 | let arcs_bytes = self.arcs.serialize(); |
| 19202 | let length_so_far = length_so_far + arcs_bytes.len(); |
| 19203 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 19204 | let length_so_far = length_so_far + padding0.len(); |
| 19205 | assert_eq!(length_so_far % 4, 0); |
| 19206 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 19207 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 19208 | ([request0.into(), arcs_bytes.into(), padding0.into()], vec![]) |
| 19209 | } |
| 19210 | /// Parse this request given its header, its body, and any fds that go along with it |
| 19211 | #[cfg (feature = "request-parsing" )] |
| 19212 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 19213 | if header.major_opcode != POLY_ARC_REQUEST { |
| 19214 | return Err(ParseError::InvalidValue); |
| 19215 | } |
| 19216 | let remaining = &[header.minor_opcode]; |
| 19217 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 19218 | let _ = remaining; |
| 19219 | let (drawable, remaining) = Drawable::try_parse(value)?; |
| 19220 | let (gc, remaining) = Gcontext::try_parse(remaining)?; |
| 19221 | let mut remaining = remaining; |
| 19222 | // Length is 'everything left in the input' |
| 19223 | let mut arcs = Vec::new(); |
| 19224 | while !remaining.is_empty() { |
| 19225 | let (v, new_remaining) = Arc::try_parse(remaining)?; |
| 19226 | remaining = new_remaining; |
| 19227 | arcs.push(v); |
| 19228 | } |
| 19229 | let _ = remaining; |
| 19230 | Ok(PolyArcRequest { |
| 19231 | drawable, |
| 19232 | gc, |
| 19233 | arcs: Cow::Owned(arcs), |
| 19234 | }) |
| 19235 | } |
| 19236 | /// Clone all borrowed data in this PolyArcRequest. |
| 19237 | pub fn into_owned(self) -> PolyArcRequest<'static> { |
| 19238 | PolyArcRequest { |
| 19239 | drawable: self.drawable, |
| 19240 | gc: self.gc, |
| 19241 | arcs: Cow::Owned(self.arcs.into_owned()), |
| 19242 | } |
| 19243 | } |
| 19244 | } |
| 19245 | impl<'input> Request for PolyArcRequest<'input> { |
| 19246 | const EXTENSION_NAME: Option<&'static str> = None; |
| 19247 | |
| 19248 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 19249 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 19250 | // Flatten the buffers into a single vector |
| 19251 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 19252 | (buf, fds) |
| 19253 | } |
| 19254 | } |
| 19255 | impl<'input> crate::x11_utils::VoidRequest for PolyArcRequest<'input> { |
| 19256 | } |
| 19257 | |
| 19258 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 19259 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 19260 | pub struct PolyShape(u8); |
| 19261 | impl PolyShape { |
| 19262 | pub const COMPLEX: Self = Self(0); |
| 19263 | pub const NONCONVEX: Self = Self(1); |
| 19264 | pub const CONVEX: Self = Self(2); |
| 19265 | } |
| 19266 | impl From<PolyShape> for u8 { |
| 19267 | #[inline ] |
| 19268 | fn from(input: PolyShape) -> Self { |
| 19269 | input.0 |
| 19270 | } |
| 19271 | } |
| 19272 | impl From<PolyShape> for Option<u8> { |
| 19273 | #[inline ] |
| 19274 | fn from(input: PolyShape) -> Self { |
| 19275 | Some(input.0) |
| 19276 | } |
| 19277 | } |
| 19278 | impl From<PolyShape> for u16 { |
| 19279 | #[inline ] |
| 19280 | fn from(input: PolyShape) -> Self { |
| 19281 | u16::from(input.0) |
| 19282 | } |
| 19283 | } |
| 19284 | impl From<PolyShape> for Option<u16> { |
| 19285 | #[inline ] |
| 19286 | fn from(input: PolyShape) -> Self { |
| 19287 | Some(u16::from(input.0)) |
| 19288 | } |
| 19289 | } |
| 19290 | impl From<PolyShape> for u32 { |
| 19291 | #[inline ] |
| 19292 | fn from(input: PolyShape) -> Self { |
| 19293 | u32::from(input.0) |
| 19294 | } |
| 19295 | } |
| 19296 | impl From<PolyShape> for Option<u32> { |
| 19297 | #[inline ] |
| 19298 | fn from(input: PolyShape) -> Self { |
| 19299 | Some(u32::from(input.0)) |
| 19300 | } |
| 19301 | } |
| 19302 | impl From<u8> for PolyShape { |
| 19303 | #[inline ] |
| 19304 | fn from(value: u8) -> Self { |
| 19305 | Self(value) |
| 19306 | } |
| 19307 | } |
| 19308 | impl core::fmt::Debug for PolyShape { |
| 19309 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 19310 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 19311 | (Self::COMPLEX.0.into(), "COMPLEX" , "Complex" ), |
| 19312 | (Self::NONCONVEX.0.into(), "NONCONVEX" , "Nonconvex" ), |
| 19313 | (Self::CONVEX.0.into(), "CONVEX" , "Convex" ), |
| 19314 | ]; |
| 19315 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 19316 | } |
| 19317 | } |
| 19318 | |
| 19319 | /// Opcode for the FillPoly request |
| 19320 | pub const FILL_POLY_REQUEST: u8 = 69; |
| 19321 | #[derive (Clone, Default)] |
| 19322 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 19323 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 19324 | pub struct FillPolyRequest<'input> { |
| 19325 | pub drawable: Drawable, |
| 19326 | pub gc: Gcontext, |
| 19327 | pub shape: PolyShape, |
| 19328 | pub coordinate_mode: CoordMode, |
| 19329 | pub points: Cow<'input, [Point]>, |
| 19330 | } |
| 19331 | impl_debug_if_no_extra_traits!(FillPolyRequest<'_>, "FillPolyRequest" ); |
| 19332 | impl<'input> FillPolyRequest<'input> { |
| 19333 | /// Serialize this request into bytes for the provided connection |
| 19334 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 19335 | let length_so_far = 0; |
| 19336 | let drawable_bytes = self.drawable.serialize(); |
| 19337 | let gc_bytes = self.gc.serialize(); |
| 19338 | let shape_bytes = u8::from(self.shape).serialize(); |
| 19339 | let coordinate_mode_bytes = u8::from(self.coordinate_mode).serialize(); |
| 19340 | let mut request0 = vec![ |
| 19341 | FILL_POLY_REQUEST, |
| 19342 | 0, |
| 19343 | 0, |
| 19344 | 0, |
| 19345 | drawable_bytes[0], |
| 19346 | drawable_bytes[1], |
| 19347 | drawable_bytes[2], |
| 19348 | drawable_bytes[3], |
| 19349 | gc_bytes[0], |
| 19350 | gc_bytes[1], |
| 19351 | gc_bytes[2], |
| 19352 | gc_bytes[3], |
| 19353 | shape_bytes[0], |
| 19354 | coordinate_mode_bytes[0], |
| 19355 | 0, |
| 19356 | 0, |
| 19357 | ]; |
| 19358 | let length_so_far = length_so_far + request0.len(); |
| 19359 | let points_bytes = self.points.serialize(); |
| 19360 | let length_so_far = length_so_far + points_bytes.len(); |
| 19361 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 19362 | let length_so_far = length_so_far + padding0.len(); |
| 19363 | assert_eq!(length_so_far % 4, 0); |
| 19364 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 19365 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 19366 | ([request0.into(), points_bytes.into(), padding0.into()], vec![]) |
| 19367 | } |
| 19368 | /// Parse this request given its header, its body, and any fds that go along with it |
| 19369 | #[cfg (feature = "request-parsing" )] |
| 19370 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 19371 | if header.major_opcode != FILL_POLY_REQUEST { |
| 19372 | return Err(ParseError::InvalidValue); |
| 19373 | } |
| 19374 | let remaining = &[header.minor_opcode]; |
| 19375 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 19376 | let _ = remaining; |
| 19377 | let (drawable, remaining) = Drawable::try_parse(value)?; |
| 19378 | let (gc, remaining) = Gcontext::try_parse(remaining)?; |
| 19379 | let (shape, remaining) = u8::try_parse(remaining)?; |
| 19380 | let shape = shape.into(); |
| 19381 | let (coordinate_mode, remaining) = u8::try_parse(remaining)?; |
| 19382 | let coordinate_mode = coordinate_mode.into(); |
| 19383 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 19384 | let mut remaining = remaining; |
| 19385 | // Length is 'everything left in the input' |
| 19386 | let mut points = Vec::new(); |
| 19387 | while !remaining.is_empty() { |
| 19388 | let (v, new_remaining) = Point::try_parse(remaining)?; |
| 19389 | remaining = new_remaining; |
| 19390 | points.push(v); |
| 19391 | } |
| 19392 | let _ = remaining; |
| 19393 | Ok(FillPolyRequest { |
| 19394 | drawable, |
| 19395 | gc, |
| 19396 | shape, |
| 19397 | coordinate_mode, |
| 19398 | points: Cow::Owned(points), |
| 19399 | }) |
| 19400 | } |
| 19401 | /// Clone all borrowed data in this FillPolyRequest. |
| 19402 | pub fn into_owned(self) -> FillPolyRequest<'static> { |
| 19403 | FillPolyRequest { |
| 19404 | drawable: self.drawable, |
| 19405 | gc: self.gc, |
| 19406 | shape: self.shape, |
| 19407 | coordinate_mode: self.coordinate_mode, |
| 19408 | points: Cow::Owned(self.points.into_owned()), |
| 19409 | } |
| 19410 | } |
| 19411 | } |
| 19412 | impl<'input> Request for FillPolyRequest<'input> { |
| 19413 | const EXTENSION_NAME: Option<&'static str> = None; |
| 19414 | |
| 19415 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 19416 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 19417 | // Flatten the buffers into a single vector |
| 19418 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 19419 | (buf, fds) |
| 19420 | } |
| 19421 | } |
| 19422 | impl<'input> crate::x11_utils::VoidRequest for FillPolyRequest<'input> { |
| 19423 | } |
| 19424 | |
| 19425 | /// Opcode for the PolyFillRectangle request |
| 19426 | pub const POLY_FILL_RECTANGLE_REQUEST: u8 = 70; |
| 19427 | /// Fills rectangles. |
| 19428 | /// |
| 19429 | /// Fills the specified rectangle(s) in the order listed in the array. For any |
| 19430 | /// given rectangle, each pixel is not drawn more than once. If rectangles |
| 19431 | /// intersect, the intersecting pixels are drawn multiple times. |
| 19432 | /// |
| 19433 | /// # Fields |
| 19434 | /// |
| 19435 | /// * `drawable` - The drawable (Window or Pixmap) to draw on. |
| 19436 | /// * `gc` - The graphics context to use. |
| 19437 | /// |
| 19438 | /// The following graphics context components are used: function, plane-mask, |
| 19439 | /// fill-style, subwindow-mode, clip-x-origin, clip-y-origin, and clip-mask. |
| 19440 | /// |
| 19441 | /// The following graphics context mode-dependent components are used: |
| 19442 | /// foreground, background, tile, stipple, tile-stipple-x-origin, and |
| 19443 | /// tile-stipple-y-origin. |
| 19444 | /// * `rectangles_len` - The number of `xcb_rectangle_t` structures in `rectangles`. |
| 19445 | /// * `rectangles` - The rectangles to fill. |
| 19446 | /// |
| 19447 | /// # Errors |
| 19448 | /// |
| 19449 | /// * `Drawable` - The specified `drawable` (Window or Pixmap) does not exist. |
| 19450 | /// * `GContext` - The specified graphics context does not exist. |
| 19451 | /// * `Match` - TODO: reasons? |
| 19452 | #[derive (Clone, Default)] |
| 19453 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 19454 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 19455 | pub struct PolyFillRectangleRequest<'input> { |
| 19456 | pub drawable: Drawable, |
| 19457 | pub gc: Gcontext, |
| 19458 | pub rectangles: Cow<'input, [Rectangle]>, |
| 19459 | } |
| 19460 | impl_debug_if_no_extra_traits!(PolyFillRectangleRequest<'_>, "PolyFillRectangleRequest" ); |
| 19461 | impl<'input> PolyFillRectangleRequest<'input> { |
| 19462 | /// Serialize this request into bytes for the provided connection |
| 19463 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 19464 | let length_so_far = 0; |
| 19465 | let drawable_bytes = self.drawable.serialize(); |
| 19466 | let gc_bytes = self.gc.serialize(); |
| 19467 | let mut request0 = vec![ |
| 19468 | POLY_FILL_RECTANGLE_REQUEST, |
| 19469 | 0, |
| 19470 | 0, |
| 19471 | 0, |
| 19472 | drawable_bytes[0], |
| 19473 | drawable_bytes[1], |
| 19474 | drawable_bytes[2], |
| 19475 | drawable_bytes[3], |
| 19476 | gc_bytes[0], |
| 19477 | gc_bytes[1], |
| 19478 | gc_bytes[2], |
| 19479 | gc_bytes[3], |
| 19480 | ]; |
| 19481 | let length_so_far = length_so_far + request0.len(); |
| 19482 | let rectangles_bytes = self.rectangles.serialize(); |
| 19483 | let length_so_far = length_so_far + rectangles_bytes.len(); |
| 19484 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 19485 | let length_so_far = length_so_far + padding0.len(); |
| 19486 | assert_eq!(length_so_far % 4, 0); |
| 19487 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 19488 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 19489 | ([request0.into(), rectangles_bytes.into(), padding0.into()], vec![]) |
| 19490 | } |
| 19491 | /// Parse this request given its header, its body, and any fds that go along with it |
| 19492 | #[cfg (feature = "request-parsing" )] |
| 19493 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 19494 | if header.major_opcode != POLY_FILL_RECTANGLE_REQUEST { |
| 19495 | return Err(ParseError::InvalidValue); |
| 19496 | } |
| 19497 | let remaining = &[header.minor_opcode]; |
| 19498 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 19499 | let _ = remaining; |
| 19500 | let (drawable, remaining) = Drawable::try_parse(value)?; |
| 19501 | let (gc, remaining) = Gcontext::try_parse(remaining)?; |
| 19502 | let mut remaining = remaining; |
| 19503 | // Length is 'everything left in the input' |
| 19504 | let mut rectangles = Vec::new(); |
| 19505 | while !remaining.is_empty() { |
| 19506 | let (v, new_remaining) = Rectangle::try_parse(remaining)?; |
| 19507 | remaining = new_remaining; |
| 19508 | rectangles.push(v); |
| 19509 | } |
| 19510 | let _ = remaining; |
| 19511 | Ok(PolyFillRectangleRequest { |
| 19512 | drawable, |
| 19513 | gc, |
| 19514 | rectangles: Cow::Owned(rectangles), |
| 19515 | }) |
| 19516 | } |
| 19517 | /// Clone all borrowed data in this PolyFillRectangleRequest. |
| 19518 | pub fn into_owned(self) -> PolyFillRectangleRequest<'static> { |
| 19519 | PolyFillRectangleRequest { |
| 19520 | drawable: self.drawable, |
| 19521 | gc: self.gc, |
| 19522 | rectangles: Cow::Owned(self.rectangles.into_owned()), |
| 19523 | } |
| 19524 | } |
| 19525 | } |
| 19526 | impl<'input> Request for PolyFillRectangleRequest<'input> { |
| 19527 | const EXTENSION_NAME: Option<&'static str> = None; |
| 19528 | |
| 19529 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 19530 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 19531 | // Flatten the buffers into a single vector |
| 19532 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 19533 | (buf, fds) |
| 19534 | } |
| 19535 | } |
| 19536 | impl<'input> crate::x11_utils::VoidRequest for PolyFillRectangleRequest<'input> { |
| 19537 | } |
| 19538 | |
| 19539 | /// Opcode for the PolyFillArc request |
| 19540 | pub const POLY_FILL_ARC_REQUEST: u8 = 71; |
| 19541 | #[derive (Clone, Default)] |
| 19542 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 19543 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 19544 | pub struct PolyFillArcRequest<'input> { |
| 19545 | pub drawable: Drawable, |
| 19546 | pub gc: Gcontext, |
| 19547 | pub arcs: Cow<'input, [Arc]>, |
| 19548 | } |
| 19549 | impl_debug_if_no_extra_traits!(PolyFillArcRequest<'_>, "PolyFillArcRequest" ); |
| 19550 | impl<'input> PolyFillArcRequest<'input> { |
| 19551 | /// Serialize this request into bytes for the provided connection |
| 19552 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 19553 | let length_so_far = 0; |
| 19554 | let drawable_bytes = self.drawable.serialize(); |
| 19555 | let gc_bytes = self.gc.serialize(); |
| 19556 | let mut request0 = vec![ |
| 19557 | POLY_FILL_ARC_REQUEST, |
| 19558 | 0, |
| 19559 | 0, |
| 19560 | 0, |
| 19561 | drawable_bytes[0], |
| 19562 | drawable_bytes[1], |
| 19563 | drawable_bytes[2], |
| 19564 | drawable_bytes[3], |
| 19565 | gc_bytes[0], |
| 19566 | gc_bytes[1], |
| 19567 | gc_bytes[2], |
| 19568 | gc_bytes[3], |
| 19569 | ]; |
| 19570 | let length_so_far = length_so_far + request0.len(); |
| 19571 | let arcs_bytes = self.arcs.serialize(); |
| 19572 | let length_so_far = length_so_far + arcs_bytes.len(); |
| 19573 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 19574 | let length_so_far = length_so_far + padding0.len(); |
| 19575 | assert_eq!(length_so_far % 4, 0); |
| 19576 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 19577 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 19578 | ([request0.into(), arcs_bytes.into(), padding0.into()], vec![]) |
| 19579 | } |
| 19580 | /// Parse this request given its header, its body, and any fds that go along with it |
| 19581 | #[cfg (feature = "request-parsing" )] |
| 19582 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 19583 | if header.major_opcode != POLY_FILL_ARC_REQUEST { |
| 19584 | return Err(ParseError::InvalidValue); |
| 19585 | } |
| 19586 | let remaining = &[header.minor_opcode]; |
| 19587 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 19588 | let _ = remaining; |
| 19589 | let (drawable, remaining) = Drawable::try_parse(value)?; |
| 19590 | let (gc, remaining) = Gcontext::try_parse(remaining)?; |
| 19591 | let mut remaining = remaining; |
| 19592 | // Length is 'everything left in the input' |
| 19593 | let mut arcs = Vec::new(); |
| 19594 | while !remaining.is_empty() { |
| 19595 | let (v, new_remaining) = Arc::try_parse(remaining)?; |
| 19596 | remaining = new_remaining; |
| 19597 | arcs.push(v); |
| 19598 | } |
| 19599 | let _ = remaining; |
| 19600 | Ok(PolyFillArcRequest { |
| 19601 | drawable, |
| 19602 | gc, |
| 19603 | arcs: Cow::Owned(arcs), |
| 19604 | }) |
| 19605 | } |
| 19606 | /// Clone all borrowed data in this PolyFillArcRequest. |
| 19607 | pub fn into_owned(self) -> PolyFillArcRequest<'static> { |
| 19608 | PolyFillArcRequest { |
| 19609 | drawable: self.drawable, |
| 19610 | gc: self.gc, |
| 19611 | arcs: Cow::Owned(self.arcs.into_owned()), |
| 19612 | } |
| 19613 | } |
| 19614 | } |
| 19615 | impl<'input> Request for PolyFillArcRequest<'input> { |
| 19616 | const EXTENSION_NAME: Option<&'static str> = None; |
| 19617 | |
| 19618 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 19619 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 19620 | // Flatten the buffers into a single vector |
| 19621 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 19622 | (buf, fds) |
| 19623 | } |
| 19624 | } |
| 19625 | impl<'input> crate::x11_utils::VoidRequest for PolyFillArcRequest<'input> { |
| 19626 | } |
| 19627 | |
| 19628 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 19629 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 19630 | pub struct ImageFormat(u8); |
| 19631 | impl ImageFormat { |
| 19632 | pub const XY_BITMAP: Self = Self(0); |
| 19633 | pub const XY_PIXMAP: Self = Self(1); |
| 19634 | pub const Z_PIXMAP: Self = Self(2); |
| 19635 | } |
| 19636 | impl From<ImageFormat> for u8 { |
| 19637 | #[inline ] |
| 19638 | fn from(input: ImageFormat) -> Self { |
| 19639 | input.0 |
| 19640 | } |
| 19641 | } |
| 19642 | impl From<ImageFormat> for Option<u8> { |
| 19643 | #[inline ] |
| 19644 | fn from(input: ImageFormat) -> Self { |
| 19645 | Some(input.0) |
| 19646 | } |
| 19647 | } |
| 19648 | impl From<ImageFormat> for u16 { |
| 19649 | #[inline ] |
| 19650 | fn from(input: ImageFormat) -> Self { |
| 19651 | u16::from(input.0) |
| 19652 | } |
| 19653 | } |
| 19654 | impl From<ImageFormat> for Option<u16> { |
| 19655 | #[inline ] |
| 19656 | fn from(input: ImageFormat) -> Self { |
| 19657 | Some(u16::from(input.0)) |
| 19658 | } |
| 19659 | } |
| 19660 | impl From<ImageFormat> for u32 { |
| 19661 | #[inline ] |
| 19662 | fn from(input: ImageFormat) -> Self { |
| 19663 | u32::from(input.0) |
| 19664 | } |
| 19665 | } |
| 19666 | impl From<ImageFormat> for Option<u32> { |
| 19667 | #[inline ] |
| 19668 | fn from(input: ImageFormat) -> Self { |
| 19669 | Some(u32::from(input.0)) |
| 19670 | } |
| 19671 | } |
| 19672 | impl From<u8> for ImageFormat { |
| 19673 | #[inline ] |
| 19674 | fn from(value: u8) -> Self { |
| 19675 | Self(value) |
| 19676 | } |
| 19677 | } |
| 19678 | impl core::fmt::Debug for ImageFormat { |
| 19679 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 19680 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 19681 | (Self::XY_BITMAP.0.into(), "XY_BITMAP" , "XYBitmap" ), |
| 19682 | (Self::XY_PIXMAP.0.into(), "XY_PIXMAP" , "XYPixmap" ), |
| 19683 | (Self::Z_PIXMAP.0.into(), "Z_PIXMAP" , "ZPixmap" ), |
| 19684 | ]; |
| 19685 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 19686 | } |
| 19687 | } |
| 19688 | |
| 19689 | /// Opcode for the PutImage request |
| 19690 | pub const PUT_IMAGE_REQUEST: u8 = 72; |
| 19691 | #[derive (Clone, Default)] |
| 19692 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 19693 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 19694 | pub struct PutImageRequest<'input> { |
| 19695 | pub format: ImageFormat, |
| 19696 | pub drawable: Drawable, |
| 19697 | pub gc: Gcontext, |
| 19698 | pub width: u16, |
| 19699 | pub height: u16, |
| 19700 | pub dst_x: i16, |
| 19701 | pub dst_y: i16, |
| 19702 | pub left_pad: u8, |
| 19703 | pub depth: u8, |
| 19704 | pub data: Cow<'input, [u8]>, |
| 19705 | } |
| 19706 | impl_debug_if_no_extra_traits!(PutImageRequest<'_>, "PutImageRequest" ); |
| 19707 | impl<'input> PutImageRequest<'input> { |
| 19708 | /// Serialize this request into bytes for the provided connection |
| 19709 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 19710 | let length_so_far = 0; |
| 19711 | let format_bytes = u8::from(self.format).serialize(); |
| 19712 | let drawable_bytes = self.drawable.serialize(); |
| 19713 | let gc_bytes = self.gc.serialize(); |
| 19714 | let width_bytes = self.width.serialize(); |
| 19715 | let height_bytes = self.height.serialize(); |
| 19716 | let dst_x_bytes = self.dst_x.serialize(); |
| 19717 | let dst_y_bytes = self.dst_y.serialize(); |
| 19718 | let left_pad_bytes = self.left_pad.serialize(); |
| 19719 | let depth_bytes = self.depth.serialize(); |
| 19720 | let mut request0 = vec![ |
| 19721 | PUT_IMAGE_REQUEST, |
| 19722 | format_bytes[0], |
| 19723 | 0, |
| 19724 | 0, |
| 19725 | drawable_bytes[0], |
| 19726 | drawable_bytes[1], |
| 19727 | drawable_bytes[2], |
| 19728 | drawable_bytes[3], |
| 19729 | gc_bytes[0], |
| 19730 | gc_bytes[1], |
| 19731 | gc_bytes[2], |
| 19732 | gc_bytes[3], |
| 19733 | width_bytes[0], |
| 19734 | width_bytes[1], |
| 19735 | height_bytes[0], |
| 19736 | height_bytes[1], |
| 19737 | dst_x_bytes[0], |
| 19738 | dst_x_bytes[1], |
| 19739 | dst_y_bytes[0], |
| 19740 | dst_y_bytes[1], |
| 19741 | left_pad_bytes[0], |
| 19742 | depth_bytes[0], |
| 19743 | 0, |
| 19744 | 0, |
| 19745 | ]; |
| 19746 | let length_so_far = length_so_far + request0.len(); |
| 19747 | let length_so_far = length_so_far + self.data.len(); |
| 19748 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 19749 | let length_so_far = length_so_far + padding0.len(); |
| 19750 | assert_eq!(length_so_far % 4, 0); |
| 19751 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 19752 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 19753 | ([request0.into(), self.data, padding0.into()], vec![]) |
| 19754 | } |
| 19755 | /// Parse this request given its header, its body, and any fds that go along with it |
| 19756 | #[cfg (feature = "request-parsing" )] |
| 19757 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 19758 | if header.major_opcode != PUT_IMAGE_REQUEST { |
| 19759 | return Err(ParseError::InvalidValue); |
| 19760 | } |
| 19761 | let remaining = &[header.minor_opcode]; |
| 19762 | let (format, remaining) = u8::try_parse(remaining)?; |
| 19763 | let format = format.into(); |
| 19764 | let _ = remaining; |
| 19765 | let (drawable, remaining) = Drawable::try_parse(value)?; |
| 19766 | let (gc, remaining) = Gcontext::try_parse(remaining)?; |
| 19767 | let (width, remaining) = u16::try_parse(remaining)?; |
| 19768 | let (height, remaining) = u16::try_parse(remaining)?; |
| 19769 | let (dst_x, remaining) = i16::try_parse(remaining)?; |
| 19770 | let (dst_y, remaining) = i16::try_parse(remaining)?; |
| 19771 | let (left_pad, remaining) = u8::try_parse(remaining)?; |
| 19772 | let (depth, remaining) = u8::try_parse(remaining)?; |
| 19773 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 19774 | let (data, remaining) = remaining.split_at(remaining.len()); |
| 19775 | let _ = remaining; |
| 19776 | Ok(PutImageRequest { |
| 19777 | format, |
| 19778 | drawable, |
| 19779 | gc, |
| 19780 | width, |
| 19781 | height, |
| 19782 | dst_x, |
| 19783 | dst_y, |
| 19784 | left_pad, |
| 19785 | depth, |
| 19786 | data: Cow::Borrowed(data), |
| 19787 | }) |
| 19788 | } |
| 19789 | /// Clone all borrowed data in this PutImageRequest. |
| 19790 | pub fn into_owned(self) -> PutImageRequest<'static> { |
| 19791 | PutImageRequest { |
| 19792 | format: self.format, |
| 19793 | drawable: self.drawable, |
| 19794 | gc: self.gc, |
| 19795 | width: self.width, |
| 19796 | height: self.height, |
| 19797 | dst_x: self.dst_x, |
| 19798 | dst_y: self.dst_y, |
| 19799 | left_pad: self.left_pad, |
| 19800 | depth: self.depth, |
| 19801 | data: Cow::Owned(self.data.into_owned()), |
| 19802 | } |
| 19803 | } |
| 19804 | } |
| 19805 | impl<'input> Request for PutImageRequest<'input> { |
| 19806 | const EXTENSION_NAME: Option<&'static str> = None; |
| 19807 | |
| 19808 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 19809 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 19810 | // Flatten the buffers into a single vector |
| 19811 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 19812 | (buf, fds) |
| 19813 | } |
| 19814 | } |
| 19815 | impl<'input> crate::x11_utils::VoidRequest for PutImageRequest<'input> { |
| 19816 | } |
| 19817 | |
| 19818 | /// Opcode for the GetImage request |
| 19819 | pub const GET_IMAGE_REQUEST: u8 = 73; |
| 19820 | #[derive (Clone, Copy, Default)] |
| 19821 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 19822 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 19823 | pub struct GetImageRequest { |
| 19824 | pub format: ImageFormat, |
| 19825 | pub drawable: Drawable, |
| 19826 | pub x: i16, |
| 19827 | pub y: i16, |
| 19828 | pub width: u16, |
| 19829 | pub height: u16, |
| 19830 | pub plane_mask: u32, |
| 19831 | } |
| 19832 | impl_debug_if_no_extra_traits!(GetImageRequest, "GetImageRequest" ); |
| 19833 | impl GetImageRequest { |
| 19834 | /// Serialize this request into bytes for the provided connection |
| 19835 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 19836 | let length_so_far = 0; |
| 19837 | let format_bytes = u8::from(self.format).serialize(); |
| 19838 | let drawable_bytes = self.drawable.serialize(); |
| 19839 | let x_bytes = self.x.serialize(); |
| 19840 | let y_bytes = self.y.serialize(); |
| 19841 | let width_bytes = self.width.serialize(); |
| 19842 | let height_bytes = self.height.serialize(); |
| 19843 | let plane_mask_bytes = self.plane_mask.serialize(); |
| 19844 | let mut request0 = vec![ |
| 19845 | GET_IMAGE_REQUEST, |
| 19846 | format_bytes[0], |
| 19847 | 0, |
| 19848 | 0, |
| 19849 | drawable_bytes[0], |
| 19850 | drawable_bytes[1], |
| 19851 | drawable_bytes[2], |
| 19852 | drawable_bytes[3], |
| 19853 | x_bytes[0], |
| 19854 | x_bytes[1], |
| 19855 | y_bytes[0], |
| 19856 | y_bytes[1], |
| 19857 | width_bytes[0], |
| 19858 | width_bytes[1], |
| 19859 | height_bytes[0], |
| 19860 | height_bytes[1], |
| 19861 | plane_mask_bytes[0], |
| 19862 | plane_mask_bytes[1], |
| 19863 | plane_mask_bytes[2], |
| 19864 | plane_mask_bytes[3], |
| 19865 | ]; |
| 19866 | let length_so_far = length_so_far + request0.len(); |
| 19867 | assert_eq!(length_so_far % 4, 0); |
| 19868 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 19869 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 19870 | ([request0.into()], vec![]) |
| 19871 | } |
| 19872 | /// Parse this request given its header, its body, and any fds that go along with it |
| 19873 | #[cfg (feature = "request-parsing" )] |
| 19874 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 19875 | if header.major_opcode != GET_IMAGE_REQUEST { |
| 19876 | return Err(ParseError::InvalidValue); |
| 19877 | } |
| 19878 | let remaining = &[header.minor_opcode]; |
| 19879 | let (format, remaining) = u8::try_parse(remaining)?; |
| 19880 | let format = format.into(); |
| 19881 | let _ = remaining; |
| 19882 | let (drawable, remaining) = Drawable::try_parse(value)?; |
| 19883 | let (x, remaining) = i16::try_parse(remaining)?; |
| 19884 | let (y, remaining) = i16::try_parse(remaining)?; |
| 19885 | let (width, remaining) = u16::try_parse(remaining)?; |
| 19886 | let (height, remaining) = u16::try_parse(remaining)?; |
| 19887 | let (plane_mask, remaining) = u32::try_parse(remaining)?; |
| 19888 | let _ = remaining; |
| 19889 | Ok(GetImageRequest { |
| 19890 | format, |
| 19891 | drawable, |
| 19892 | x, |
| 19893 | y, |
| 19894 | width, |
| 19895 | height, |
| 19896 | plane_mask, |
| 19897 | }) |
| 19898 | } |
| 19899 | } |
| 19900 | impl Request for GetImageRequest { |
| 19901 | const EXTENSION_NAME: Option<&'static str> = None; |
| 19902 | |
| 19903 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 19904 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 19905 | // Flatten the buffers into a single vector |
| 19906 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 19907 | (buf, fds) |
| 19908 | } |
| 19909 | } |
| 19910 | impl crate::x11_utils::ReplyRequest for GetImageRequest { |
| 19911 | type Reply = GetImageReply; |
| 19912 | } |
| 19913 | |
| 19914 | #[derive (Clone, Default)] |
| 19915 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 19916 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 19917 | pub struct GetImageReply { |
| 19918 | pub depth: u8, |
| 19919 | pub sequence: u16, |
| 19920 | pub visual: Visualid, |
| 19921 | pub data: Vec<u8>, |
| 19922 | } |
| 19923 | impl_debug_if_no_extra_traits!(GetImageReply, "GetImageReply" ); |
| 19924 | impl TryParse for GetImageReply { |
| 19925 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 19926 | let remaining: &[u8] = initial_value; |
| 19927 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 19928 | let (depth: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 19929 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 19930 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 19931 | let (visual: u32, remaining: &[u8]) = Visualid::try_parse(remaining)?; |
| 19932 | let remaining: &[u8] = remaining.get(20..).ok_or(err:ParseError::InsufficientData)?; |
| 19933 | let (data: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data:remaining, list_length:u32::from(length).checked_mul(4u32).ok_or(err:ParseError::InvalidExpression)?.try_to_usize()?)?; |
| 19934 | let data: Vec = data.to_vec(); |
| 19935 | if response_type != 1 { |
| 19936 | return Err(ParseError::InvalidValue); |
| 19937 | } |
| 19938 | let result: GetImageReply = GetImageReply { depth, sequence, visual, data }; |
| 19939 | let _ = remaining; |
| 19940 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 19941 | .ok_or(err:ParseError::InsufficientData)?; |
| 19942 | Ok((result, remaining)) |
| 19943 | } |
| 19944 | } |
| 19945 | impl Serialize for GetImageReply { |
| 19946 | type Bytes = Vec<u8>; |
| 19947 | fn serialize(&self) -> Vec<u8> { |
| 19948 | let mut result: Vec = Vec::new(); |
| 19949 | self.serialize_into(&mut result); |
| 19950 | result |
| 19951 | } |
| 19952 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 19953 | bytes.reserve(additional:32); |
| 19954 | let response_type_bytes: &[u8; 1] = &[1]; |
| 19955 | bytes.push(response_type_bytes[0]); |
| 19956 | self.depth.serialize_into(bytes); |
| 19957 | self.sequence.serialize_into(bytes); |
| 19958 | assert_eq!(self.data.len() % 4, 0, "`data` has an incorrect length, must be a multiple of 4" ); |
| 19959 | let length: u32 = u32::try_from(self.data.len() / 4).expect(msg:"`data` has too many elements" ); |
| 19960 | length.serialize_into(bytes); |
| 19961 | self.visual.serialize_into(bytes); |
| 19962 | bytes.extend_from_slice(&[0; 20]); |
| 19963 | bytes.extend_from_slice(&self.data); |
| 19964 | } |
| 19965 | } |
| 19966 | impl GetImageReply { |
| 19967 | /// Get the value of the `length` field. |
| 19968 | /// |
| 19969 | /// The `length` field is used as the length field of the `data` field. |
| 19970 | /// This function computes the field's value again based on the length of the list. |
| 19971 | /// |
| 19972 | /// # Panics |
| 19973 | /// |
| 19974 | /// Panics if the value cannot be represented in the target type. This |
| 19975 | /// cannot happen with values of the struct received from the X11 server. |
| 19976 | pub fn length(&self) -> u32 { |
| 19977 | self.data.len() |
| 19978 | .checked_div(4).unwrap() |
| 19979 | .try_into().unwrap() |
| 19980 | } |
| 19981 | } |
| 19982 | |
| 19983 | /// Opcode for the PolyText8 request |
| 19984 | pub const POLY_TEXT8_REQUEST: u8 = 74; |
| 19985 | #[derive (Clone, Default)] |
| 19986 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 19987 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 19988 | pub struct PolyText8Request<'input> { |
| 19989 | pub drawable: Drawable, |
| 19990 | pub gc: Gcontext, |
| 19991 | pub x: i16, |
| 19992 | pub y: i16, |
| 19993 | pub items: Cow<'input, [u8]>, |
| 19994 | } |
| 19995 | impl_debug_if_no_extra_traits!(PolyText8Request<'_>, "PolyText8Request" ); |
| 19996 | impl<'input> PolyText8Request<'input> { |
| 19997 | /// Serialize this request into bytes for the provided connection |
| 19998 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 19999 | let length_so_far = 0; |
| 20000 | let drawable_bytes = self.drawable.serialize(); |
| 20001 | let gc_bytes = self.gc.serialize(); |
| 20002 | let x_bytes = self.x.serialize(); |
| 20003 | let y_bytes = self.y.serialize(); |
| 20004 | let mut request0 = vec![ |
| 20005 | POLY_TEXT8_REQUEST, |
| 20006 | 0, |
| 20007 | 0, |
| 20008 | 0, |
| 20009 | drawable_bytes[0], |
| 20010 | drawable_bytes[1], |
| 20011 | drawable_bytes[2], |
| 20012 | drawable_bytes[3], |
| 20013 | gc_bytes[0], |
| 20014 | gc_bytes[1], |
| 20015 | gc_bytes[2], |
| 20016 | gc_bytes[3], |
| 20017 | x_bytes[0], |
| 20018 | x_bytes[1], |
| 20019 | y_bytes[0], |
| 20020 | y_bytes[1], |
| 20021 | ]; |
| 20022 | let length_so_far = length_so_far + request0.len(); |
| 20023 | let length_so_far = length_so_far + self.items.len(); |
| 20024 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 20025 | let length_so_far = length_so_far + padding0.len(); |
| 20026 | assert_eq!(length_so_far % 4, 0); |
| 20027 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 20028 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 20029 | ([request0.into(), self.items, padding0.into()], vec![]) |
| 20030 | } |
| 20031 | /// Parse this request given its header, its body, and any fds that go along with it |
| 20032 | #[cfg (feature = "request-parsing" )] |
| 20033 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 20034 | if header.major_opcode != POLY_TEXT8_REQUEST { |
| 20035 | return Err(ParseError::InvalidValue); |
| 20036 | } |
| 20037 | let remaining = &[header.minor_opcode]; |
| 20038 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 20039 | let _ = remaining; |
| 20040 | let (drawable, remaining) = Drawable::try_parse(value)?; |
| 20041 | let (gc, remaining) = Gcontext::try_parse(remaining)?; |
| 20042 | let (x, remaining) = i16::try_parse(remaining)?; |
| 20043 | let (y, remaining) = i16::try_parse(remaining)?; |
| 20044 | let (items, remaining) = remaining.split_at(remaining.len()); |
| 20045 | let _ = remaining; |
| 20046 | Ok(PolyText8Request { |
| 20047 | drawable, |
| 20048 | gc, |
| 20049 | x, |
| 20050 | y, |
| 20051 | items: Cow::Borrowed(items), |
| 20052 | }) |
| 20053 | } |
| 20054 | /// Clone all borrowed data in this PolyText8Request. |
| 20055 | pub fn into_owned(self) -> PolyText8Request<'static> { |
| 20056 | PolyText8Request { |
| 20057 | drawable: self.drawable, |
| 20058 | gc: self.gc, |
| 20059 | x: self.x, |
| 20060 | y: self.y, |
| 20061 | items: Cow::Owned(self.items.into_owned()), |
| 20062 | } |
| 20063 | } |
| 20064 | } |
| 20065 | impl<'input> Request for PolyText8Request<'input> { |
| 20066 | const EXTENSION_NAME: Option<&'static str> = None; |
| 20067 | |
| 20068 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 20069 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 20070 | // Flatten the buffers into a single vector |
| 20071 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 20072 | (buf, fds) |
| 20073 | } |
| 20074 | } |
| 20075 | impl<'input> crate::x11_utils::VoidRequest for PolyText8Request<'input> { |
| 20076 | } |
| 20077 | |
| 20078 | /// Opcode for the PolyText16 request |
| 20079 | pub const POLY_TEXT16_REQUEST: u8 = 75; |
| 20080 | #[derive (Clone, Default)] |
| 20081 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 20082 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 20083 | pub struct PolyText16Request<'input> { |
| 20084 | pub drawable: Drawable, |
| 20085 | pub gc: Gcontext, |
| 20086 | pub x: i16, |
| 20087 | pub y: i16, |
| 20088 | pub items: Cow<'input, [u8]>, |
| 20089 | } |
| 20090 | impl_debug_if_no_extra_traits!(PolyText16Request<'_>, "PolyText16Request" ); |
| 20091 | impl<'input> PolyText16Request<'input> { |
| 20092 | /// Serialize this request into bytes for the provided connection |
| 20093 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 20094 | let length_so_far = 0; |
| 20095 | let drawable_bytes = self.drawable.serialize(); |
| 20096 | let gc_bytes = self.gc.serialize(); |
| 20097 | let x_bytes = self.x.serialize(); |
| 20098 | let y_bytes = self.y.serialize(); |
| 20099 | let mut request0 = vec![ |
| 20100 | POLY_TEXT16_REQUEST, |
| 20101 | 0, |
| 20102 | 0, |
| 20103 | 0, |
| 20104 | drawable_bytes[0], |
| 20105 | drawable_bytes[1], |
| 20106 | drawable_bytes[2], |
| 20107 | drawable_bytes[3], |
| 20108 | gc_bytes[0], |
| 20109 | gc_bytes[1], |
| 20110 | gc_bytes[2], |
| 20111 | gc_bytes[3], |
| 20112 | x_bytes[0], |
| 20113 | x_bytes[1], |
| 20114 | y_bytes[0], |
| 20115 | y_bytes[1], |
| 20116 | ]; |
| 20117 | let length_so_far = length_so_far + request0.len(); |
| 20118 | let length_so_far = length_so_far + self.items.len(); |
| 20119 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 20120 | let length_so_far = length_so_far + padding0.len(); |
| 20121 | assert_eq!(length_so_far % 4, 0); |
| 20122 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 20123 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 20124 | ([request0.into(), self.items, padding0.into()], vec![]) |
| 20125 | } |
| 20126 | /// Parse this request given its header, its body, and any fds that go along with it |
| 20127 | #[cfg (feature = "request-parsing" )] |
| 20128 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 20129 | if header.major_opcode != POLY_TEXT16_REQUEST { |
| 20130 | return Err(ParseError::InvalidValue); |
| 20131 | } |
| 20132 | let remaining = &[header.minor_opcode]; |
| 20133 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 20134 | let _ = remaining; |
| 20135 | let (drawable, remaining) = Drawable::try_parse(value)?; |
| 20136 | let (gc, remaining) = Gcontext::try_parse(remaining)?; |
| 20137 | let (x, remaining) = i16::try_parse(remaining)?; |
| 20138 | let (y, remaining) = i16::try_parse(remaining)?; |
| 20139 | let (items, remaining) = remaining.split_at(remaining.len()); |
| 20140 | let _ = remaining; |
| 20141 | Ok(PolyText16Request { |
| 20142 | drawable, |
| 20143 | gc, |
| 20144 | x, |
| 20145 | y, |
| 20146 | items: Cow::Borrowed(items), |
| 20147 | }) |
| 20148 | } |
| 20149 | /// Clone all borrowed data in this PolyText16Request. |
| 20150 | pub fn into_owned(self) -> PolyText16Request<'static> { |
| 20151 | PolyText16Request { |
| 20152 | drawable: self.drawable, |
| 20153 | gc: self.gc, |
| 20154 | x: self.x, |
| 20155 | y: self.y, |
| 20156 | items: Cow::Owned(self.items.into_owned()), |
| 20157 | } |
| 20158 | } |
| 20159 | } |
| 20160 | impl<'input> Request for PolyText16Request<'input> { |
| 20161 | const EXTENSION_NAME: Option<&'static str> = None; |
| 20162 | |
| 20163 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 20164 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 20165 | // Flatten the buffers into a single vector |
| 20166 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 20167 | (buf, fds) |
| 20168 | } |
| 20169 | } |
| 20170 | impl<'input> crate::x11_utils::VoidRequest for PolyText16Request<'input> { |
| 20171 | } |
| 20172 | |
| 20173 | /// Opcode for the ImageText8 request |
| 20174 | pub const IMAGE_TEXT8_REQUEST: u8 = 76; |
| 20175 | /// Draws text. |
| 20176 | /// |
| 20177 | /// Fills the destination rectangle with the background pixel from `gc`, then |
| 20178 | /// paints the text with the foreground pixel from `gc`. The upper-left corner of |
| 20179 | /// the filled rectangle is at [x, y - font-ascent]. The width is overall-width, |
| 20180 | /// the height is font-ascent + font-descent. The overall-width, font-ascent and |
| 20181 | /// font-descent are as returned by `xcb_query_text_extents` (TODO). |
| 20182 | /// |
| 20183 | /// Note that using X core fonts is deprecated (but still supported) in favor of |
| 20184 | /// client-side rendering using Xft. |
| 20185 | /// |
| 20186 | /// # Fields |
| 20187 | /// |
| 20188 | /// * `drawable` - The drawable (Window or Pixmap) to draw text on. |
| 20189 | /// * `string` - The string to draw. Only the first 255 characters are relevant due to the data |
| 20190 | /// type of `string_len`. |
| 20191 | /// * `x` - The x coordinate of the first character, relative to the origin of `drawable`. |
| 20192 | /// * `y` - The y coordinate of the first character, relative to the origin of `drawable`. |
| 20193 | /// * `gc` - The graphics context to use. |
| 20194 | /// |
| 20195 | /// The following graphics context components are used: plane-mask, foreground, |
| 20196 | /// background, font, subwindow-mode, clip-x-origin, clip-y-origin, and clip-mask. |
| 20197 | /// |
| 20198 | /// # Errors |
| 20199 | /// |
| 20200 | /// * `Drawable` - The specified `drawable` (Window or Pixmap) does not exist. |
| 20201 | /// * `GContext` - The specified graphics context does not exist. |
| 20202 | /// * `Match` - TODO: reasons? |
| 20203 | /// |
| 20204 | /// # See |
| 20205 | /// |
| 20206 | /// * `ImageText16`: request |
| 20207 | #[derive (Clone, Default)] |
| 20208 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 20209 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 20210 | pub struct ImageText8Request<'input> { |
| 20211 | pub drawable: Drawable, |
| 20212 | pub gc: Gcontext, |
| 20213 | pub x: i16, |
| 20214 | pub y: i16, |
| 20215 | pub string: Cow<'input, [u8]>, |
| 20216 | } |
| 20217 | impl_debug_if_no_extra_traits!(ImageText8Request<'_>, "ImageText8Request" ); |
| 20218 | impl<'input> ImageText8Request<'input> { |
| 20219 | /// Serialize this request into bytes for the provided connection |
| 20220 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 20221 | let length_so_far = 0; |
| 20222 | let string_len = u8::try_from(self.string.len()).expect("`string` has too many elements" ); |
| 20223 | let string_len_bytes = string_len.serialize(); |
| 20224 | let drawable_bytes = self.drawable.serialize(); |
| 20225 | let gc_bytes = self.gc.serialize(); |
| 20226 | let x_bytes = self.x.serialize(); |
| 20227 | let y_bytes = self.y.serialize(); |
| 20228 | let mut request0 = vec![ |
| 20229 | IMAGE_TEXT8_REQUEST, |
| 20230 | string_len_bytes[0], |
| 20231 | 0, |
| 20232 | 0, |
| 20233 | drawable_bytes[0], |
| 20234 | drawable_bytes[1], |
| 20235 | drawable_bytes[2], |
| 20236 | drawable_bytes[3], |
| 20237 | gc_bytes[0], |
| 20238 | gc_bytes[1], |
| 20239 | gc_bytes[2], |
| 20240 | gc_bytes[3], |
| 20241 | x_bytes[0], |
| 20242 | x_bytes[1], |
| 20243 | y_bytes[0], |
| 20244 | y_bytes[1], |
| 20245 | ]; |
| 20246 | let length_so_far = length_so_far + request0.len(); |
| 20247 | let length_so_far = length_so_far + self.string.len(); |
| 20248 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 20249 | let length_so_far = length_so_far + padding0.len(); |
| 20250 | assert_eq!(length_so_far % 4, 0); |
| 20251 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 20252 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 20253 | ([request0.into(), self.string, padding0.into()], vec![]) |
| 20254 | } |
| 20255 | /// Parse this request given its header, its body, and any fds that go along with it |
| 20256 | #[cfg (feature = "request-parsing" )] |
| 20257 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 20258 | if header.major_opcode != IMAGE_TEXT8_REQUEST { |
| 20259 | return Err(ParseError::InvalidValue); |
| 20260 | } |
| 20261 | let remaining = &[header.minor_opcode]; |
| 20262 | let (string_len, remaining) = u8::try_parse(remaining)?; |
| 20263 | let _ = remaining; |
| 20264 | let (drawable, remaining) = Drawable::try_parse(value)?; |
| 20265 | let (gc, remaining) = Gcontext::try_parse(remaining)?; |
| 20266 | let (x, remaining) = i16::try_parse(remaining)?; |
| 20267 | let (y, remaining) = i16::try_parse(remaining)?; |
| 20268 | let (string, remaining) = crate::x11_utils::parse_u8_list(remaining, string_len.try_to_usize()?)?; |
| 20269 | let _ = remaining; |
| 20270 | Ok(ImageText8Request { |
| 20271 | drawable, |
| 20272 | gc, |
| 20273 | x, |
| 20274 | y, |
| 20275 | string: Cow::Borrowed(string), |
| 20276 | }) |
| 20277 | } |
| 20278 | /// Clone all borrowed data in this ImageText8Request. |
| 20279 | pub fn into_owned(self) -> ImageText8Request<'static> { |
| 20280 | ImageText8Request { |
| 20281 | drawable: self.drawable, |
| 20282 | gc: self.gc, |
| 20283 | x: self.x, |
| 20284 | y: self.y, |
| 20285 | string: Cow::Owned(self.string.into_owned()), |
| 20286 | } |
| 20287 | } |
| 20288 | } |
| 20289 | impl<'input> Request for ImageText8Request<'input> { |
| 20290 | const EXTENSION_NAME: Option<&'static str> = None; |
| 20291 | |
| 20292 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 20293 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 20294 | // Flatten the buffers into a single vector |
| 20295 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 20296 | (buf, fds) |
| 20297 | } |
| 20298 | } |
| 20299 | impl<'input> crate::x11_utils::VoidRequest for ImageText8Request<'input> { |
| 20300 | } |
| 20301 | |
| 20302 | /// Opcode for the ImageText16 request |
| 20303 | pub const IMAGE_TEXT16_REQUEST: u8 = 77; |
| 20304 | /// Draws text. |
| 20305 | /// |
| 20306 | /// Fills the destination rectangle with the background pixel from `gc`, then |
| 20307 | /// paints the text with the foreground pixel from `gc`. The upper-left corner of |
| 20308 | /// the filled rectangle is at [x, y - font-ascent]. The width is overall-width, |
| 20309 | /// the height is font-ascent + font-descent. The overall-width, font-ascent and |
| 20310 | /// font-descent are as returned by `xcb_query_text_extents` (TODO). |
| 20311 | /// |
| 20312 | /// Note that using X core fonts is deprecated (but still supported) in favor of |
| 20313 | /// client-side rendering using Xft. |
| 20314 | /// |
| 20315 | /// # Fields |
| 20316 | /// |
| 20317 | /// * `drawable` - The drawable (Window or Pixmap) to draw text on. |
| 20318 | /// * `string` - The string to draw. Only the first 255 characters are relevant due to the data |
| 20319 | /// type of `string_len`. Every character uses 2 bytes (hence the 16 in this |
| 20320 | /// request's name). |
| 20321 | /// * `x` - The x coordinate of the first character, relative to the origin of `drawable`. |
| 20322 | /// * `y` - The y coordinate of the first character, relative to the origin of `drawable`. |
| 20323 | /// * `gc` - The graphics context to use. |
| 20324 | /// |
| 20325 | /// The following graphics context components are used: plane-mask, foreground, |
| 20326 | /// background, font, subwindow-mode, clip-x-origin, clip-y-origin, and clip-mask. |
| 20327 | /// |
| 20328 | /// # Errors |
| 20329 | /// |
| 20330 | /// * `Drawable` - The specified `drawable` (Window or Pixmap) does not exist. |
| 20331 | /// * `GContext` - The specified graphics context does not exist. |
| 20332 | /// * `Match` - TODO: reasons? |
| 20333 | /// |
| 20334 | /// # See |
| 20335 | /// |
| 20336 | /// * `ImageText8`: request |
| 20337 | #[derive (Clone, Default)] |
| 20338 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 20339 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 20340 | pub struct ImageText16Request<'input> { |
| 20341 | pub drawable: Drawable, |
| 20342 | pub gc: Gcontext, |
| 20343 | pub x: i16, |
| 20344 | pub y: i16, |
| 20345 | pub string: Cow<'input, [Char2b]>, |
| 20346 | } |
| 20347 | impl_debug_if_no_extra_traits!(ImageText16Request<'_>, "ImageText16Request" ); |
| 20348 | impl<'input> ImageText16Request<'input> { |
| 20349 | /// Serialize this request into bytes for the provided connection |
| 20350 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 20351 | let length_so_far = 0; |
| 20352 | let string_len = u8::try_from(self.string.len()).expect("`string` has too many elements" ); |
| 20353 | let string_len_bytes = string_len.serialize(); |
| 20354 | let drawable_bytes = self.drawable.serialize(); |
| 20355 | let gc_bytes = self.gc.serialize(); |
| 20356 | let x_bytes = self.x.serialize(); |
| 20357 | let y_bytes = self.y.serialize(); |
| 20358 | let mut request0 = vec![ |
| 20359 | IMAGE_TEXT16_REQUEST, |
| 20360 | string_len_bytes[0], |
| 20361 | 0, |
| 20362 | 0, |
| 20363 | drawable_bytes[0], |
| 20364 | drawable_bytes[1], |
| 20365 | drawable_bytes[2], |
| 20366 | drawable_bytes[3], |
| 20367 | gc_bytes[0], |
| 20368 | gc_bytes[1], |
| 20369 | gc_bytes[2], |
| 20370 | gc_bytes[3], |
| 20371 | x_bytes[0], |
| 20372 | x_bytes[1], |
| 20373 | y_bytes[0], |
| 20374 | y_bytes[1], |
| 20375 | ]; |
| 20376 | let length_so_far = length_so_far + request0.len(); |
| 20377 | let string_bytes = self.string.serialize(); |
| 20378 | let length_so_far = length_so_far + string_bytes.len(); |
| 20379 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 20380 | let length_so_far = length_so_far + padding0.len(); |
| 20381 | assert_eq!(length_so_far % 4, 0); |
| 20382 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 20383 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 20384 | ([request0.into(), string_bytes.into(), padding0.into()], vec![]) |
| 20385 | } |
| 20386 | /// Parse this request given its header, its body, and any fds that go along with it |
| 20387 | #[cfg (feature = "request-parsing" )] |
| 20388 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 20389 | if header.major_opcode != IMAGE_TEXT16_REQUEST { |
| 20390 | return Err(ParseError::InvalidValue); |
| 20391 | } |
| 20392 | let remaining = &[header.minor_opcode]; |
| 20393 | let (string_len, remaining) = u8::try_parse(remaining)?; |
| 20394 | let _ = remaining; |
| 20395 | let (drawable, remaining) = Drawable::try_parse(value)?; |
| 20396 | let (gc, remaining) = Gcontext::try_parse(remaining)?; |
| 20397 | let (x, remaining) = i16::try_parse(remaining)?; |
| 20398 | let (y, remaining) = i16::try_parse(remaining)?; |
| 20399 | let (string, remaining) = crate::x11_utils::parse_list::<Char2b>(remaining, string_len.try_to_usize()?)?; |
| 20400 | let _ = remaining; |
| 20401 | Ok(ImageText16Request { |
| 20402 | drawable, |
| 20403 | gc, |
| 20404 | x, |
| 20405 | y, |
| 20406 | string: Cow::Owned(string), |
| 20407 | }) |
| 20408 | } |
| 20409 | /// Clone all borrowed data in this ImageText16Request. |
| 20410 | pub fn into_owned(self) -> ImageText16Request<'static> { |
| 20411 | ImageText16Request { |
| 20412 | drawable: self.drawable, |
| 20413 | gc: self.gc, |
| 20414 | x: self.x, |
| 20415 | y: self.y, |
| 20416 | string: Cow::Owned(self.string.into_owned()), |
| 20417 | } |
| 20418 | } |
| 20419 | } |
| 20420 | impl<'input> Request for ImageText16Request<'input> { |
| 20421 | const EXTENSION_NAME: Option<&'static str> = None; |
| 20422 | |
| 20423 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 20424 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 20425 | // Flatten the buffers into a single vector |
| 20426 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 20427 | (buf, fds) |
| 20428 | } |
| 20429 | } |
| 20430 | impl<'input> crate::x11_utils::VoidRequest for ImageText16Request<'input> { |
| 20431 | } |
| 20432 | |
| 20433 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 20434 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 20435 | pub struct ColormapAlloc(u8); |
| 20436 | impl ColormapAlloc { |
| 20437 | pub const NONE: Self = Self(0); |
| 20438 | pub const ALL: Self = Self(1); |
| 20439 | } |
| 20440 | impl From<ColormapAlloc> for u8 { |
| 20441 | #[inline ] |
| 20442 | fn from(input: ColormapAlloc) -> Self { |
| 20443 | input.0 |
| 20444 | } |
| 20445 | } |
| 20446 | impl From<ColormapAlloc> for Option<u8> { |
| 20447 | #[inline ] |
| 20448 | fn from(input: ColormapAlloc) -> Self { |
| 20449 | Some(input.0) |
| 20450 | } |
| 20451 | } |
| 20452 | impl From<ColormapAlloc> for u16 { |
| 20453 | #[inline ] |
| 20454 | fn from(input: ColormapAlloc) -> Self { |
| 20455 | u16::from(input.0) |
| 20456 | } |
| 20457 | } |
| 20458 | impl From<ColormapAlloc> for Option<u16> { |
| 20459 | #[inline ] |
| 20460 | fn from(input: ColormapAlloc) -> Self { |
| 20461 | Some(u16::from(input.0)) |
| 20462 | } |
| 20463 | } |
| 20464 | impl From<ColormapAlloc> for u32 { |
| 20465 | #[inline ] |
| 20466 | fn from(input: ColormapAlloc) -> Self { |
| 20467 | u32::from(input.0) |
| 20468 | } |
| 20469 | } |
| 20470 | impl From<ColormapAlloc> for Option<u32> { |
| 20471 | #[inline ] |
| 20472 | fn from(input: ColormapAlloc) -> Self { |
| 20473 | Some(u32::from(input.0)) |
| 20474 | } |
| 20475 | } |
| 20476 | impl From<u8> for ColormapAlloc { |
| 20477 | #[inline ] |
| 20478 | fn from(value: u8) -> Self { |
| 20479 | Self(value) |
| 20480 | } |
| 20481 | } |
| 20482 | impl core::fmt::Debug for ColormapAlloc { |
| 20483 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 20484 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 20485 | (Self::NONE.0.into(), "NONE" , "None" ), |
| 20486 | (Self::ALL.0.into(), "ALL" , "All" ), |
| 20487 | ]; |
| 20488 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 20489 | } |
| 20490 | } |
| 20491 | |
| 20492 | /// Opcode for the CreateColormap request |
| 20493 | pub const CREATE_COLORMAP_REQUEST: u8 = 78; |
| 20494 | #[derive (Clone, Copy, Default)] |
| 20495 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 20496 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 20497 | pub struct CreateColormapRequest { |
| 20498 | pub alloc: ColormapAlloc, |
| 20499 | pub mid: Colormap, |
| 20500 | pub window: Window, |
| 20501 | pub visual: Visualid, |
| 20502 | } |
| 20503 | impl_debug_if_no_extra_traits!(CreateColormapRequest, "CreateColormapRequest" ); |
| 20504 | impl CreateColormapRequest { |
| 20505 | /// Serialize this request into bytes for the provided connection |
| 20506 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 20507 | let length_so_far = 0; |
| 20508 | let alloc_bytes = u8::from(self.alloc).serialize(); |
| 20509 | let mid_bytes = self.mid.serialize(); |
| 20510 | let window_bytes = self.window.serialize(); |
| 20511 | let visual_bytes = self.visual.serialize(); |
| 20512 | let mut request0 = vec![ |
| 20513 | CREATE_COLORMAP_REQUEST, |
| 20514 | alloc_bytes[0], |
| 20515 | 0, |
| 20516 | 0, |
| 20517 | mid_bytes[0], |
| 20518 | mid_bytes[1], |
| 20519 | mid_bytes[2], |
| 20520 | mid_bytes[3], |
| 20521 | window_bytes[0], |
| 20522 | window_bytes[1], |
| 20523 | window_bytes[2], |
| 20524 | window_bytes[3], |
| 20525 | visual_bytes[0], |
| 20526 | visual_bytes[1], |
| 20527 | visual_bytes[2], |
| 20528 | visual_bytes[3], |
| 20529 | ]; |
| 20530 | let length_so_far = length_so_far + request0.len(); |
| 20531 | assert_eq!(length_so_far % 4, 0); |
| 20532 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 20533 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 20534 | ([request0.into()], vec![]) |
| 20535 | } |
| 20536 | /// Parse this request given its header, its body, and any fds that go along with it |
| 20537 | #[cfg (feature = "request-parsing" )] |
| 20538 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 20539 | if header.major_opcode != CREATE_COLORMAP_REQUEST { |
| 20540 | return Err(ParseError::InvalidValue); |
| 20541 | } |
| 20542 | let remaining = &[header.minor_opcode]; |
| 20543 | let (alloc, remaining) = u8::try_parse(remaining)?; |
| 20544 | let alloc = alloc.into(); |
| 20545 | let _ = remaining; |
| 20546 | let (mid, remaining) = Colormap::try_parse(value)?; |
| 20547 | let (window, remaining) = Window::try_parse(remaining)?; |
| 20548 | let (visual, remaining) = Visualid::try_parse(remaining)?; |
| 20549 | let _ = remaining; |
| 20550 | Ok(CreateColormapRequest { |
| 20551 | alloc, |
| 20552 | mid, |
| 20553 | window, |
| 20554 | visual, |
| 20555 | }) |
| 20556 | } |
| 20557 | } |
| 20558 | impl Request for CreateColormapRequest { |
| 20559 | const EXTENSION_NAME: Option<&'static str> = None; |
| 20560 | |
| 20561 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 20562 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 20563 | // Flatten the buffers into a single vector |
| 20564 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 20565 | (buf, fds) |
| 20566 | } |
| 20567 | } |
| 20568 | impl crate::x11_utils::VoidRequest for CreateColormapRequest { |
| 20569 | } |
| 20570 | |
| 20571 | /// Opcode for the FreeColormap request |
| 20572 | pub const FREE_COLORMAP_REQUEST: u8 = 79; |
| 20573 | #[derive (Clone, Copy, Default)] |
| 20574 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 20575 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 20576 | pub struct FreeColormapRequest { |
| 20577 | pub cmap: Colormap, |
| 20578 | } |
| 20579 | impl_debug_if_no_extra_traits!(FreeColormapRequest, "FreeColormapRequest" ); |
| 20580 | impl FreeColormapRequest { |
| 20581 | /// Serialize this request into bytes for the provided connection |
| 20582 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 20583 | let length_so_far = 0; |
| 20584 | let cmap_bytes = self.cmap.serialize(); |
| 20585 | let mut request0 = vec![ |
| 20586 | FREE_COLORMAP_REQUEST, |
| 20587 | 0, |
| 20588 | 0, |
| 20589 | 0, |
| 20590 | cmap_bytes[0], |
| 20591 | cmap_bytes[1], |
| 20592 | cmap_bytes[2], |
| 20593 | cmap_bytes[3], |
| 20594 | ]; |
| 20595 | let length_so_far = length_so_far + request0.len(); |
| 20596 | assert_eq!(length_so_far % 4, 0); |
| 20597 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 20598 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 20599 | ([request0.into()], vec![]) |
| 20600 | } |
| 20601 | /// Parse this request given its header, its body, and any fds that go along with it |
| 20602 | #[cfg (feature = "request-parsing" )] |
| 20603 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 20604 | if header.major_opcode != FREE_COLORMAP_REQUEST { |
| 20605 | return Err(ParseError::InvalidValue); |
| 20606 | } |
| 20607 | let remaining = &[header.minor_opcode]; |
| 20608 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 20609 | let _ = remaining; |
| 20610 | let (cmap, remaining) = Colormap::try_parse(value)?; |
| 20611 | let _ = remaining; |
| 20612 | Ok(FreeColormapRequest { |
| 20613 | cmap, |
| 20614 | }) |
| 20615 | } |
| 20616 | } |
| 20617 | impl Request for FreeColormapRequest { |
| 20618 | const EXTENSION_NAME: Option<&'static str> = None; |
| 20619 | |
| 20620 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 20621 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 20622 | // Flatten the buffers into a single vector |
| 20623 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 20624 | (buf, fds) |
| 20625 | } |
| 20626 | } |
| 20627 | impl crate::x11_utils::VoidRequest for FreeColormapRequest { |
| 20628 | } |
| 20629 | |
| 20630 | /// Opcode for the CopyColormapAndFree request |
| 20631 | pub const COPY_COLORMAP_AND_FREE_REQUEST: u8 = 80; |
| 20632 | #[derive (Clone, Copy, Default)] |
| 20633 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 20634 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 20635 | pub struct CopyColormapAndFreeRequest { |
| 20636 | pub mid: Colormap, |
| 20637 | pub src_cmap: Colormap, |
| 20638 | } |
| 20639 | impl_debug_if_no_extra_traits!(CopyColormapAndFreeRequest, "CopyColormapAndFreeRequest" ); |
| 20640 | impl CopyColormapAndFreeRequest { |
| 20641 | /// Serialize this request into bytes for the provided connection |
| 20642 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 20643 | let length_so_far = 0; |
| 20644 | let mid_bytes = self.mid.serialize(); |
| 20645 | let src_cmap_bytes = self.src_cmap.serialize(); |
| 20646 | let mut request0 = vec![ |
| 20647 | COPY_COLORMAP_AND_FREE_REQUEST, |
| 20648 | 0, |
| 20649 | 0, |
| 20650 | 0, |
| 20651 | mid_bytes[0], |
| 20652 | mid_bytes[1], |
| 20653 | mid_bytes[2], |
| 20654 | mid_bytes[3], |
| 20655 | src_cmap_bytes[0], |
| 20656 | src_cmap_bytes[1], |
| 20657 | src_cmap_bytes[2], |
| 20658 | src_cmap_bytes[3], |
| 20659 | ]; |
| 20660 | let length_so_far = length_so_far + request0.len(); |
| 20661 | assert_eq!(length_so_far % 4, 0); |
| 20662 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 20663 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 20664 | ([request0.into()], vec![]) |
| 20665 | } |
| 20666 | /// Parse this request given its header, its body, and any fds that go along with it |
| 20667 | #[cfg (feature = "request-parsing" )] |
| 20668 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 20669 | if header.major_opcode != COPY_COLORMAP_AND_FREE_REQUEST { |
| 20670 | return Err(ParseError::InvalidValue); |
| 20671 | } |
| 20672 | let remaining = &[header.minor_opcode]; |
| 20673 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 20674 | let _ = remaining; |
| 20675 | let (mid, remaining) = Colormap::try_parse(value)?; |
| 20676 | let (src_cmap, remaining) = Colormap::try_parse(remaining)?; |
| 20677 | let _ = remaining; |
| 20678 | Ok(CopyColormapAndFreeRequest { |
| 20679 | mid, |
| 20680 | src_cmap, |
| 20681 | }) |
| 20682 | } |
| 20683 | } |
| 20684 | impl Request for CopyColormapAndFreeRequest { |
| 20685 | const EXTENSION_NAME: Option<&'static str> = None; |
| 20686 | |
| 20687 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 20688 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 20689 | // Flatten the buffers into a single vector |
| 20690 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 20691 | (buf, fds) |
| 20692 | } |
| 20693 | } |
| 20694 | impl crate::x11_utils::VoidRequest for CopyColormapAndFreeRequest { |
| 20695 | } |
| 20696 | |
| 20697 | /// Opcode for the InstallColormap request |
| 20698 | pub const INSTALL_COLORMAP_REQUEST: u8 = 81; |
| 20699 | #[derive (Clone, Copy, Default)] |
| 20700 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 20701 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 20702 | pub struct InstallColormapRequest { |
| 20703 | pub cmap: Colormap, |
| 20704 | } |
| 20705 | impl_debug_if_no_extra_traits!(InstallColormapRequest, "InstallColormapRequest" ); |
| 20706 | impl InstallColormapRequest { |
| 20707 | /// Serialize this request into bytes for the provided connection |
| 20708 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 20709 | let length_so_far = 0; |
| 20710 | let cmap_bytes = self.cmap.serialize(); |
| 20711 | let mut request0 = vec![ |
| 20712 | INSTALL_COLORMAP_REQUEST, |
| 20713 | 0, |
| 20714 | 0, |
| 20715 | 0, |
| 20716 | cmap_bytes[0], |
| 20717 | cmap_bytes[1], |
| 20718 | cmap_bytes[2], |
| 20719 | cmap_bytes[3], |
| 20720 | ]; |
| 20721 | let length_so_far = length_so_far + request0.len(); |
| 20722 | assert_eq!(length_so_far % 4, 0); |
| 20723 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 20724 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 20725 | ([request0.into()], vec![]) |
| 20726 | } |
| 20727 | /// Parse this request given its header, its body, and any fds that go along with it |
| 20728 | #[cfg (feature = "request-parsing" )] |
| 20729 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 20730 | if header.major_opcode != INSTALL_COLORMAP_REQUEST { |
| 20731 | return Err(ParseError::InvalidValue); |
| 20732 | } |
| 20733 | let remaining = &[header.minor_opcode]; |
| 20734 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 20735 | let _ = remaining; |
| 20736 | let (cmap, remaining) = Colormap::try_parse(value)?; |
| 20737 | let _ = remaining; |
| 20738 | Ok(InstallColormapRequest { |
| 20739 | cmap, |
| 20740 | }) |
| 20741 | } |
| 20742 | } |
| 20743 | impl Request for InstallColormapRequest { |
| 20744 | const EXTENSION_NAME: Option<&'static str> = None; |
| 20745 | |
| 20746 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 20747 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 20748 | // Flatten the buffers into a single vector |
| 20749 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 20750 | (buf, fds) |
| 20751 | } |
| 20752 | } |
| 20753 | impl crate::x11_utils::VoidRequest for InstallColormapRequest { |
| 20754 | } |
| 20755 | |
| 20756 | /// Opcode for the UninstallColormap request |
| 20757 | pub const UNINSTALL_COLORMAP_REQUEST: u8 = 82; |
| 20758 | #[derive (Clone, Copy, Default)] |
| 20759 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 20760 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 20761 | pub struct UninstallColormapRequest { |
| 20762 | pub cmap: Colormap, |
| 20763 | } |
| 20764 | impl_debug_if_no_extra_traits!(UninstallColormapRequest, "UninstallColormapRequest" ); |
| 20765 | impl UninstallColormapRequest { |
| 20766 | /// Serialize this request into bytes for the provided connection |
| 20767 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 20768 | let length_so_far = 0; |
| 20769 | let cmap_bytes = self.cmap.serialize(); |
| 20770 | let mut request0 = vec![ |
| 20771 | UNINSTALL_COLORMAP_REQUEST, |
| 20772 | 0, |
| 20773 | 0, |
| 20774 | 0, |
| 20775 | cmap_bytes[0], |
| 20776 | cmap_bytes[1], |
| 20777 | cmap_bytes[2], |
| 20778 | cmap_bytes[3], |
| 20779 | ]; |
| 20780 | let length_so_far = length_so_far + request0.len(); |
| 20781 | assert_eq!(length_so_far % 4, 0); |
| 20782 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 20783 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 20784 | ([request0.into()], vec![]) |
| 20785 | } |
| 20786 | /// Parse this request given its header, its body, and any fds that go along with it |
| 20787 | #[cfg (feature = "request-parsing" )] |
| 20788 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 20789 | if header.major_opcode != UNINSTALL_COLORMAP_REQUEST { |
| 20790 | return Err(ParseError::InvalidValue); |
| 20791 | } |
| 20792 | let remaining = &[header.minor_opcode]; |
| 20793 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 20794 | let _ = remaining; |
| 20795 | let (cmap, remaining) = Colormap::try_parse(value)?; |
| 20796 | let _ = remaining; |
| 20797 | Ok(UninstallColormapRequest { |
| 20798 | cmap, |
| 20799 | }) |
| 20800 | } |
| 20801 | } |
| 20802 | impl Request for UninstallColormapRequest { |
| 20803 | const EXTENSION_NAME: Option<&'static str> = None; |
| 20804 | |
| 20805 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 20806 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 20807 | // Flatten the buffers into a single vector |
| 20808 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 20809 | (buf, fds) |
| 20810 | } |
| 20811 | } |
| 20812 | impl crate::x11_utils::VoidRequest for UninstallColormapRequest { |
| 20813 | } |
| 20814 | |
| 20815 | /// Opcode for the ListInstalledColormaps request |
| 20816 | pub const LIST_INSTALLED_COLORMAPS_REQUEST: u8 = 83; |
| 20817 | #[derive (Clone, Copy, Default)] |
| 20818 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 20819 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 20820 | pub struct ListInstalledColormapsRequest { |
| 20821 | pub window: Window, |
| 20822 | } |
| 20823 | impl_debug_if_no_extra_traits!(ListInstalledColormapsRequest, "ListInstalledColormapsRequest" ); |
| 20824 | impl ListInstalledColormapsRequest { |
| 20825 | /// Serialize this request into bytes for the provided connection |
| 20826 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 20827 | let length_so_far = 0; |
| 20828 | let window_bytes = self.window.serialize(); |
| 20829 | let mut request0 = vec![ |
| 20830 | LIST_INSTALLED_COLORMAPS_REQUEST, |
| 20831 | 0, |
| 20832 | 0, |
| 20833 | 0, |
| 20834 | window_bytes[0], |
| 20835 | window_bytes[1], |
| 20836 | window_bytes[2], |
| 20837 | window_bytes[3], |
| 20838 | ]; |
| 20839 | let length_so_far = length_so_far + request0.len(); |
| 20840 | assert_eq!(length_so_far % 4, 0); |
| 20841 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 20842 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 20843 | ([request0.into()], vec![]) |
| 20844 | } |
| 20845 | /// Parse this request given its header, its body, and any fds that go along with it |
| 20846 | #[cfg (feature = "request-parsing" )] |
| 20847 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 20848 | if header.major_opcode != LIST_INSTALLED_COLORMAPS_REQUEST { |
| 20849 | return Err(ParseError::InvalidValue); |
| 20850 | } |
| 20851 | let remaining = &[header.minor_opcode]; |
| 20852 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 20853 | let _ = remaining; |
| 20854 | let (window, remaining) = Window::try_parse(value)?; |
| 20855 | let _ = remaining; |
| 20856 | Ok(ListInstalledColormapsRequest { |
| 20857 | window, |
| 20858 | }) |
| 20859 | } |
| 20860 | } |
| 20861 | impl Request for ListInstalledColormapsRequest { |
| 20862 | const EXTENSION_NAME: Option<&'static str> = None; |
| 20863 | |
| 20864 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 20865 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 20866 | // Flatten the buffers into a single vector |
| 20867 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 20868 | (buf, fds) |
| 20869 | } |
| 20870 | } |
| 20871 | impl crate::x11_utils::ReplyRequest for ListInstalledColormapsRequest { |
| 20872 | type Reply = ListInstalledColormapsReply; |
| 20873 | } |
| 20874 | |
| 20875 | #[derive (Clone, Default)] |
| 20876 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 20877 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 20878 | pub struct ListInstalledColormapsReply { |
| 20879 | pub sequence: u16, |
| 20880 | pub length: u32, |
| 20881 | pub cmaps: Vec<Colormap>, |
| 20882 | } |
| 20883 | impl_debug_if_no_extra_traits!(ListInstalledColormapsReply, "ListInstalledColormapsReply" ); |
| 20884 | impl TryParse for ListInstalledColormapsReply { |
| 20885 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 20886 | let remaining: &[u8] = initial_value; |
| 20887 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 20888 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 20889 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 20890 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 20891 | let (cmaps_len: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 20892 | let remaining: &[u8] = remaining.get(22..).ok_or(err:ParseError::InsufficientData)?; |
| 20893 | let (cmaps: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<Colormap>(data:remaining, list_length:cmaps_len.try_to_usize()?)?; |
| 20894 | if response_type != 1 { |
| 20895 | return Err(ParseError::InvalidValue); |
| 20896 | } |
| 20897 | let result: ListInstalledColormapsReply = ListInstalledColormapsReply { sequence, length, cmaps }; |
| 20898 | let _ = remaining; |
| 20899 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 20900 | .ok_or(err:ParseError::InsufficientData)?; |
| 20901 | Ok((result, remaining)) |
| 20902 | } |
| 20903 | } |
| 20904 | impl Serialize for ListInstalledColormapsReply { |
| 20905 | type Bytes = Vec<u8>; |
| 20906 | fn serialize(&self) -> Vec<u8> { |
| 20907 | let mut result: Vec = Vec::new(); |
| 20908 | self.serialize_into(&mut result); |
| 20909 | result |
| 20910 | } |
| 20911 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 20912 | bytes.reserve(additional:32); |
| 20913 | let response_type_bytes: &[u8; 1] = &[1]; |
| 20914 | bytes.push(response_type_bytes[0]); |
| 20915 | bytes.extend_from_slice(&[0; 1]); |
| 20916 | self.sequence.serialize_into(bytes); |
| 20917 | self.length.serialize_into(bytes); |
| 20918 | let cmaps_len: u16 = u16::try_from(self.cmaps.len()).expect(msg:"`cmaps` has too many elements" ); |
| 20919 | cmaps_len.serialize_into(bytes); |
| 20920 | bytes.extend_from_slice(&[0; 22]); |
| 20921 | self.cmaps.serialize_into(bytes); |
| 20922 | } |
| 20923 | } |
| 20924 | impl ListInstalledColormapsReply { |
| 20925 | /// Get the value of the `cmaps_len` field. |
| 20926 | /// |
| 20927 | /// The `cmaps_len` field is used as the length field of the `cmaps` field. |
| 20928 | /// This function computes the field's value again based on the length of the list. |
| 20929 | /// |
| 20930 | /// # Panics |
| 20931 | /// |
| 20932 | /// Panics if the value cannot be represented in the target type. This |
| 20933 | /// cannot happen with values of the struct received from the X11 server. |
| 20934 | pub fn cmaps_len(&self) -> u16 { |
| 20935 | self.cmaps.len() |
| 20936 | .try_into().unwrap() |
| 20937 | } |
| 20938 | } |
| 20939 | |
| 20940 | /// Opcode for the AllocColor request |
| 20941 | pub const ALLOC_COLOR_REQUEST: u8 = 84; |
| 20942 | /// Allocate a color. |
| 20943 | /// |
| 20944 | /// Allocates a read-only colormap entry corresponding to the closest RGB value |
| 20945 | /// supported by the hardware. If you are using TrueColor, you can take a shortcut |
| 20946 | /// and directly calculate the color pixel value to avoid the round trip. But, for |
| 20947 | /// example, on 16-bit color setups (VNC), you can easily get the closest supported |
| 20948 | /// RGB value to the RGB value you are specifying. |
| 20949 | /// |
| 20950 | /// # Fields |
| 20951 | /// |
| 20952 | /// * `cmap` - TODO |
| 20953 | /// * `red` - The red value of your color. |
| 20954 | /// * `green` - The green value of your color. |
| 20955 | /// * `blue` - The blue value of your color. |
| 20956 | /// |
| 20957 | /// # Errors |
| 20958 | /// |
| 20959 | /// * `Colormap` - The specified colormap `cmap` does not exist. |
| 20960 | #[derive (Clone, Copy, Default)] |
| 20961 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 20962 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 20963 | pub struct AllocColorRequest { |
| 20964 | pub cmap: Colormap, |
| 20965 | pub red: u16, |
| 20966 | pub green: u16, |
| 20967 | pub blue: u16, |
| 20968 | } |
| 20969 | impl_debug_if_no_extra_traits!(AllocColorRequest, "AllocColorRequest" ); |
| 20970 | impl AllocColorRequest { |
| 20971 | /// Serialize this request into bytes for the provided connection |
| 20972 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 20973 | let length_so_far = 0; |
| 20974 | let cmap_bytes = self.cmap.serialize(); |
| 20975 | let red_bytes = self.red.serialize(); |
| 20976 | let green_bytes = self.green.serialize(); |
| 20977 | let blue_bytes = self.blue.serialize(); |
| 20978 | let mut request0 = vec![ |
| 20979 | ALLOC_COLOR_REQUEST, |
| 20980 | 0, |
| 20981 | 0, |
| 20982 | 0, |
| 20983 | cmap_bytes[0], |
| 20984 | cmap_bytes[1], |
| 20985 | cmap_bytes[2], |
| 20986 | cmap_bytes[3], |
| 20987 | red_bytes[0], |
| 20988 | red_bytes[1], |
| 20989 | green_bytes[0], |
| 20990 | green_bytes[1], |
| 20991 | blue_bytes[0], |
| 20992 | blue_bytes[1], |
| 20993 | 0, |
| 20994 | 0, |
| 20995 | ]; |
| 20996 | let length_so_far = length_so_far + request0.len(); |
| 20997 | assert_eq!(length_so_far % 4, 0); |
| 20998 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 20999 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 21000 | ([request0.into()], vec![]) |
| 21001 | } |
| 21002 | /// Parse this request given its header, its body, and any fds that go along with it |
| 21003 | #[cfg (feature = "request-parsing" )] |
| 21004 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 21005 | if header.major_opcode != ALLOC_COLOR_REQUEST { |
| 21006 | return Err(ParseError::InvalidValue); |
| 21007 | } |
| 21008 | let remaining = &[header.minor_opcode]; |
| 21009 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 21010 | let _ = remaining; |
| 21011 | let (cmap, remaining) = Colormap::try_parse(value)?; |
| 21012 | let (red, remaining) = u16::try_parse(remaining)?; |
| 21013 | let (green, remaining) = u16::try_parse(remaining)?; |
| 21014 | let (blue, remaining) = u16::try_parse(remaining)?; |
| 21015 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 21016 | let _ = remaining; |
| 21017 | Ok(AllocColorRequest { |
| 21018 | cmap, |
| 21019 | red, |
| 21020 | green, |
| 21021 | blue, |
| 21022 | }) |
| 21023 | } |
| 21024 | } |
| 21025 | impl Request for AllocColorRequest { |
| 21026 | const EXTENSION_NAME: Option<&'static str> = None; |
| 21027 | |
| 21028 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 21029 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 21030 | // Flatten the buffers into a single vector |
| 21031 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 21032 | (buf, fds) |
| 21033 | } |
| 21034 | } |
| 21035 | impl crate::x11_utils::ReplyRequest for AllocColorRequest { |
| 21036 | type Reply = AllocColorReply; |
| 21037 | } |
| 21038 | |
| 21039 | #[derive (Clone, Copy, Default)] |
| 21040 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 21041 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 21042 | pub struct AllocColorReply { |
| 21043 | pub sequence: u16, |
| 21044 | pub length: u32, |
| 21045 | pub red: u16, |
| 21046 | pub green: u16, |
| 21047 | pub blue: u16, |
| 21048 | pub pixel: u32, |
| 21049 | } |
| 21050 | impl_debug_if_no_extra_traits!(AllocColorReply, "AllocColorReply" ); |
| 21051 | impl TryParse for AllocColorReply { |
| 21052 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 21053 | let remaining: &[u8] = initial_value; |
| 21054 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 21055 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 21056 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21057 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 21058 | let (red: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21059 | let (green: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21060 | let (blue: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21061 | let remaining: &[u8] = remaining.get(2..).ok_or(err:ParseError::InsufficientData)?; |
| 21062 | let (pixel: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 21063 | if response_type != 1 { |
| 21064 | return Err(ParseError::InvalidValue); |
| 21065 | } |
| 21066 | let result: AllocColorReply = AllocColorReply { sequence, length, red, green, blue, pixel }; |
| 21067 | let _ = remaining; |
| 21068 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 21069 | .ok_or(err:ParseError::InsufficientData)?; |
| 21070 | Ok((result, remaining)) |
| 21071 | } |
| 21072 | } |
| 21073 | impl Serialize for AllocColorReply { |
| 21074 | type Bytes = [u8; 20]; |
| 21075 | fn serialize(&self) -> [u8; 20] { |
| 21076 | let response_type_bytes = &[1]; |
| 21077 | let sequence_bytes = self.sequence.serialize(); |
| 21078 | let length_bytes = self.length.serialize(); |
| 21079 | let red_bytes = self.red.serialize(); |
| 21080 | let green_bytes = self.green.serialize(); |
| 21081 | let blue_bytes = self.blue.serialize(); |
| 21082 | let pixel_bytes = self.pixel.serialize(); |
| 21083 | [ |
| 21084 | response_type_bytes[0], |
| 21085 | 0, |
| 21086 | sequence_bytes[0], |
| 21087 | sequence_bytes[1], |
| 21088 | length_bytes[0], |
| 21089 | length_bytes[1], |
| 21090 | length_bytes[2], |
| 21091 | length_bytes[3], |
| 21092 | red_bytes[0], |
| 21093 | red_bytes[1], |
| 21094 | green_bytes[0], |
| 21095 | green_bytes[1], |
| 21096 | blue_bytes[0], |
| 21097 | blue_bytes[1], |
| 21098 | 0, |
| 21099 | 0, |
| 21100 | pixel_bytes[0], |
| 21101 | pixel_bytes[1], |
| 21102 | pixel_bytes[2], |
| 21103 | pixel_bytes[3], |
| 21104 | ] |
| 21105 | } |
| 21106 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 21107 | bytes.reserve(20); |
| 21108 | let response_type_bytes = &[1]; |
| 21109 | bytes.push(response_type_bytes[0]); |
| 21110 | bytes.extend_from_slice(&[0; 1]); |
| 21111 | self.sequence.serialize_into(bytes); |
| 21112 | self.length.serialize_into(bytes); |
| 21113 | self.red.serialize_into(bytes); |
| 21114 | self.green.serialize_into(bytes); |
| 21115 | self.blue.serialize_into(bytes); |
| 21116 | bytes.extend_from_slice(&[0; 2]); |
| 21117 | self.pixel.serialize_into(bytes); |
| 21118 | } |
| 21119 | } |
| 21120 | |
| 21121 | /// Opcode for the AllocNamedColor request |
| 21122 | pub const ALLOC_NAMED_COLOR_REQUEST: u8 = 85; |
| 21123 | #[derive (Clone, Default)] |
| 21124 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 21125 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 21126 | pub struct AllocNamedColorRequest<'input> { |
| 21127 | pub cmap: Colormap, |
| 21128 | pub name: Cow<'input, [u8]>, |
| 21129 | } |
| 21130 | impl_debug_if_no_extra_traits!(AllocNamedColorRequest<'_>, "AllocNamedColorRequest" ); |
| 21131 | impl<'input> AllocNamedColorRequest<'input> { |
| 21132 | /// Serialize this request into bytes for the provided connection |
| 21133 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 21134 | let length_so_far = 0; |
| 21135 | let cmap_bytes = self.cmap.serialize(); |
| 21136 | let name_len = u16::try_from(self.name.len()).expect("`name` has too many elements" ); |
| 21137 | let name_len_bytes = name_len.serialize(); |
| 21138 | let mut request0 = vec![ |
| 21139 | ALLOC_NAMED_COLOR_REQUEST, |
| 21140 | 0, |
| 21141 | 0, |
| 21142 | 0, |
| 21143 | cmap_bytes[0], |
| 21144 | cmap_bytes[1], |
| 21145 | cmap_bytes[2], |
| 21146 | cmap_bytes[3], |
| 21147 | name_len_bytes[0], |
| 21148 | name_len_bytes[1], |
| 21149 | 0, |
| 21150 | 0, |
| 21151 | ]; |
| 21152 | let length_so_far = length_so_far + request0.len(); |
| 21153 | let length_so_far = length_so_far + self.name.len(); |
| 21154 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 21155 | let length_so_far = length_so_far + padding0.len(); |
| 21156 | assert_eq!(length_so_far % 4, 0); |
| 21157 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 21158 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 21159 | ([request0.into(), self.name, padding0.into()], vec![]) |
| 21160 | } |
| 21161 | /// Parse this request given its header, its body, and any fds that go along with it |
| 21162 | #[cfg (feature = "request-parsing" )] |
| 21163 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 21164 | if header.major_opcode != ALLOC_NAMED_COLOR_REQUEST { |
| 21165 | return Err(ParseError::InvalidValue); |
| 21166 | } |
| 21167 | let remaining = &[header.minor_opcode]; |
| 21168 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 21169 | let _ = remaining; |
| 21170 | let (cmap, remaining) = Colormap::try_parse(value)?; |
| 21171 | let (name_len, remaining) = u16::try_parse(remaining)?; |
| 21172 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 21173 | let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; |
| 21174 | let _ = remaining; |
| 21175 | Ok(AllocNamedColorRequest { |
| 21176 | cmap, |
| 21177 | name: Cow::Borrowed(name), |
| 21178 | }) |
| 21179 | } |
| 21180 | /// Clone all borrowed data in this AllocNamedColorRequest. |
| 21181 | pub fn into_owned(self) -> AllocNamedColorRequest<'static> { |
| 21182 | AllocNamedColorRequest { |
| 21183 | cmap: self.cmap, |
| 21184 | name: Cow::Owned(self.name.into_owned()), |
| 21185 | } |
| 21186 | } |
| 21187 | } |
| 21188 | impl<'input> Request for AllocNamedColorRequest<'input> { |
| 21189 | const EXTENSION_NAME: Option<&'static str> = None; |
| 21190 | |
| 21191 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 21192 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 21193 | // Flatten the buffers into a single vector |
| 21194 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 21195 | (buf, fds) |
| 21196 | } |
| 21197 | } |
| 21198 | impl<'input> crate::x11_utils::ReplyRequest for AllocNamedColorRequest<'input> { |
| 21199 | type Reply = AllocNamedColorReply; |
| 21200 | } |
| 21201 | |
| 21202 | #[derive (Clone, Copy, Default)] |
| 21203 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 21204 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 21205 | pub struct AllocNamedColorReply { |
| 21206 | pub sequence: u16, |
| 21207 | pub length: u32, |
| 21208 | pub pixel: u32, |
| 21209 | pub exact_red: u16, |
| 21210 | pub exact_green: u16, |
| 21211 | pub exact_blue: u16, |
| 21212 | pub visual_red: u16, |
| 21213 | pub visual_green: u16, |
| 21214 | pub visual_blue: u16, |
| 21215 | } |
| 21216 | impl_debug_if_no_extra_traits!(AllocNamedColorReply, "AllocNamedColorReply" ); |
| 21217 | impl TryParse for AllocNamedColorReply { |
| 21218 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 21219 | let remaining: &[u8] = initial_value; |
| 21220 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 21221 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 21222 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21223 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 21224 | let (pixel: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 21225 | let (exact_red: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21226 | let (exact_green: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21227 | let (exact_blue: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21228 | let (visual_red: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21229 | let (visual_green: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21230 | let (visual_blue: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21231 | if response_type != 1 { |
| 21232 | return Err(ParseError::InvalidValue); |
| 21233 | } |
| 21234 | let result: AllocNamedColorReply = AllocNamedColorReply { sequence, length, pixel, exact_red, exact_green, exact_blue, visual_red, visual_green, visual_blue }; |
| 21235 | let _ = remaining; |
| 21236 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 21237 | .ok_or(err:ParseError::InsufficientData)?; |
| 21238 | Ok((result, remaining)) |
| 21239 | } |
| 21240 | } |
| 21241 | impl Serialize for AllocNamedColorReply { |
| 21242 | type Bytes = [u8; 24]; |
| 21243 | fn serialize(&self) -> [u8; 24] { |
| 21244 | let response_type_bytes = &[1]; |
| 21245 | let sequence_bytes = self.sequence.serialize(); |
| 21246 | let length_bytes = self.length.serialize(); |
| 21247 | let pixel_bytes = self.pixel.serialize(); |
| 21248 | let exact_red_bytes = self.exact_red.serialize(); |
| 21249 | let exact_green_bytes = self.exact_green.serialize(); |
| 21250 | let exact_blue_bytes = self.exact_blue.serialize(); |
| 21251 | let visual_red_bytes = self.visual_red.serialize(); |
| 21252 | let visual_green_bytes = self.visual_green.serialize(); |
| 21253 | let visual_blue_bytes = self.visual_blue.serialize(); |
| 21254 | [ |
| 21255 | response_type_bytes[0], |
| 21256 | 0, |
| 21257 | sequence_bytes[0], |
| 21258 | sequence_bytes[1], |
| 21259 | length_bytes[0], |
| 21260 | length_bytes[1], |
| 21261 | length_bytes[2], |
| 21262 | length_bytes[3], |
| 21263 | pixel_bytes[0], |
| 21264 | pixel_bytes[1], |
| 21265 | pixel_bytes[2], |
| 21266 | pixel_bytes[3], |
| 21267 | exact_red_bytes[0], |
| 21268 | exact_red_bytes[1], |
| 21269 | exact_green_bytes[0], |
| 21270 | exact_green_bytes[1], |
| 21271 | exact_blue_bytes[0], |
| 21272 | exact_blue_bytes[1], |
| 21273 | visual_red_bytes[0], |
| 21274 | visual_red_bytes[1], |
| 21275 | visual_green_bytes[0], |
| 21276 | visual_green_bytes[1], |
| 21277 | visual_blue_bytes[0], |
| 21278 | visual_blue_bytes[1], |
| 21279 | ] |
| 21280 | } |
| 21281 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 21282 | bytes.reserve(24); |
| 21283 | let response_type_bytes = &[1]; |
| 21284 | bytes.push(response_type_bytes[0]); |
| 21285 | bytes.extend_from_slice(&[0; 1]); |
| 21286 | self.sequence.serialize_into(bytes); |
| 21287 | self.length.serialize_into(bytes); |
| 21288 | self.pixel.serialize_into(bytes); |
| 21289 | self.exact_red.serialize_into(bytes); |
| 21290 | self.exact_green.serialize_into(bytes); |
| 21291 | self.exact_blue.serialize_into(bytes); |
| 21292 | self.visual_red.serialize_into(bytes); |
| 21293 | self.visual_green.serialize_into(bytes); |
| 21294 | self.visual_blue.serialize_into(bytes); |
| 21295 | } |
| 21296 | } |
| 21297 | |
| 21298 | /// Opcode for the AllocColorCells request |
| 21299 | pub const ALLOC_COLOR_CELLS_REQUEST: u8 = 86; |
| 21300 | #[derive (Clone, Copy, Default)] |
| 21301 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 21302 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 21303 | pub struct AllocColorCellsRequest { |
| 21304 | pub contiguous: bool, |
| 21305 | pub cmap: Colormap, |
| 21306 | pub colors: u16, |
| 21307 | pub planes: u16, |
| 21308 | } |
| 21309 | impl_debug_if_no_extra_traits!(AllocColorCellsRequest, "AllocColorCellsRequest" ); |
| 21310 | impl AllocColorCellsRequest { |
| 21311 | /// Serialize this request into bytes for the provided connection |
| 21312 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 21313 | let length_so_far = 0; |
| 21314 | let contiguous_bytes = self.contiguous.serialize(); |
| 21315 | let cmap_bytes = self.cmap.serialize(); |
| 21316 | let colors_bytes = self.colors.serialize(); |
| 21317 | let planes_bytes = self.planes.serialize(); |
| 21318 | let mut request0 = vec![ |
| 21319 | ALLOC_COLOR_CELLS_REQUEST, |
| 21320 | contiguous_bytes[0], |
| 21321 | 0, |
| 21322 | 0, |
| 21323 | cmap_bytes[0], |
| 21324 | cmap_bytes[1], |
| 21325 | cmap_bytes[2], |
| 21326 | cmap_bytes[3], |
| 21327 | colors_bytes[0], |
| 21328 | colors_bytes[1], |
| 21329 | planes_bytes[0], |
| 21330 | planes_bytes[1], |
| 21331 | ]; |
| 21332 | let length_so_far = length_so_far + request0.len(); |
| 21333 | assert_eq!(length_so_far % 4, 0); |
| 21334 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 21335 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 21336 | ([request0.into()], vec![]) |
| 21337 | } |
| 21338 | /// Parse this request given its header, its body, and any fds that go along with it |
| 21339 | #[cfg (feature = "request-parsing" )] |
| 21340 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 21341 | if header.major_opcode != ALLOC_COLOR_CELLS_REQUEST { |
| 21342 | return Err(ParseError::InvalidValue); |
| 21343 | } |
| 21344 | let remaining = &[header.minor_opcode]; |
| 21345 | let (contiguous, remaining) = bool::try_parse(remaining)?; |
| 21346 | let _ = remaining; |
| 21347 | let (cmap, remaining) = Colormap::try_parse(value)?; |
| 21348 | let (colors, remaining) = u16::try_parse(remaining)?; |
| 21349 | let (planes, remaining) = u16::try_parse(remaining)?; |
| 21350 | let _ = remaining; |
| 21351 | Ok(AllocColorCellsRequest { |
| 21352 | contiguous, |
| 21353 | cmap, |
| 21354 | colors, |
| 21355 | planes, |
| 21356 | }) |
| 21357 | } |
| 21358 | } |
| 21359 | impl Request for AllocColorCellsRequest { |
| 21360 | const EXTENSION_NAME: Option<&'static str> = None; |
| 21361 | |
| 21362 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 21363 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 21364 | // Flatten the buffers into a single vector |
| 21365 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 21366 | (buf, fds) |
| 21367 | } |
| 21368 | } |
| 21369 | impl crate::x11_utils::ReplyRequest for AllocColorCellsRequest { |
| 21370 | type Reply = AllocColorCellsReply; |
| 21371 | } |
| 21372 | |
| 21373 | #[derive (Clone, Default)] |
| 21374 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 21375 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 21376 | pub struct AllocColorCellsReply { |
| 21377 | pub sequence: u16, |
| 21378 | pub length: u32, |
| 21379 | pub pixels: Vec<u32>, |
| 21380 | pub masks: Vec<u32>, |
| 21381 | } |
| 21382 | impl_debug_if_no_extra_traits!(AllocColorCellsReply, "AllocColorCellsReply" ); |
| 21383 | impl TryParse for AllocColorCellsReply { |
| 21384 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 21385 | let remaining: &[u8] = initial_value; |
| 21386 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 21387 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 21388 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21389 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 21390 | let (pixels_len: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21391 | let (masks_len: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21392 | let remaining: &[u8] = remaining.get(20..).ok_or(err:ParseError::InsufficientData)?; |
| 21393 | let (pixels: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<u32>(data:remaining, list_length:pixels_len.try_to_usize()?)?; |
| 21394 | let (masks: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<u32>(data:remaining, list_length:masks_len.try_to_usize()?)?; |
| 21395 | if response_type != 1 { |
| 21396 | return Err(ParseError::InvalidValue); |
| 21397 | } |
| 21398 | let result: AllocColorCellsReply = AllocColorCellsReply { sequence, length, pixels, masks }; |
| 21399 | let _ = remaining; |
| 21400 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 21401 | .ok_or(err:ParseError::InsufficientData)?; |
| 21402 | Ok((result, remaining)) |
| 21403 | } |
| 21404 | } |
| 21405 | impl Serialize for AllocColorCellsReply { |
| 21406 | type Bytes = Vec<u8>; |
| 21407 | fn serialize(&self) -> Vec<u8> { |
| 21408 | let mut result: Vec = Vec::new(); |
| 21409 | self.serialize_into(&mut result); |
| 21410 | result |
| 21411 | } |
| 21412 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 21413 | bytes.reserve(additional:32); |
| 21414 | let response_type_bytes: &[u8; 1] = &[1]; |
| 21415 | bytes.push(response_type_bytes[0]); |
| 21416 | bytes.extend_from_slice(&[0; 1]); |
| 21417 | self.sequence.serialize_into(bytes); |
| 21418 | self.length.serialize_into(bytes); |
| 21419 | let pixels_len: u16 = u16::try_from(self.pixels.len()).expect(msg:"`pixels` has too many elements" ); |
| 21420 | pixels_len.serialize_into(bytes); |
| 21421 | let masks_len: u16 = u16::try_from(self.masks.len()).expect(msg:"`masks` has too many elements" ); |
| 21422 | masks_len.serialize_into(bytes); |
| 21423 | bytes.extend_from_slice(&[0; 20]); |
| 21424 | self.pixels.serialize_into(bytes); |
| 21425 | self.masks.serialize_into(bytes); |
| 21426 | } |
| 21427 | } |
| 21428 | impl AllocColorCellsReply { |
| 21429 | /// Get the value of the `pixels_len` field. |
| 21430 | /// |
| 21431 | /// The `pixels_len` field is used as the length field of the `pixels` field. |
| 21432 | /// This function computes the field's value again based on the length of the list. |
| 21433 | /// |
| 21434 | /// # Panics |
| 21435 | /// |
| 21436 | /// Panics if the value cannot be represented in the target type. This |
| 21437 | /// cannot happen with values of the struct received from the X11 server. |
| 21438 | pub fn pixels_len(&self) -> u16 { |
| 21439 | self.pixels.len() |
| 21440 | .try_into().unwrap() |
| 21441 | } |
| 21442 | /// Get the value of the `masks_len` field. |
| 21443 | /// |
| 21444 | /// The `masks_len` field is used as the length field of the `masks` field. |
| 21445 | /// This function computes the field's value again based on the length of the list. |
| 21446 | /// |
| 21447 | /// # Panics |
| 21448 | /// |
| 21449 | /// Panics if the value cannot be represented in the target type. This |
| 21450 | /// cannot happen with values of the struct received from the X11 server. |
| 21451 | pub fn masks_len(&self) -> u16 { |
| 21452 | self.masks.len() |
| 21453 | .try_into().unwrap() |
| 21454 | } |
| 21455 | } |
| 21456 | |
| 21457 | /// Opcode for the AllocColorPlanes request |
| 21458 | pub const ALLOC_COLOR_PLANES_REQUEST: u8 = 87; |
| 21459 | #[derive (Clone, Copy, Default)] |
| 21460 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 21461 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 21462 | pub struct AllocColorPlanesRequest { |
| 21463 | pub contiguous: bool, |
| 21464 | pub cmap: Colormap, |
| 21465 | pub colors: u16, |
| 21466 | pub reds: u16, |
| 21467 | pub greens: u16, |
| 21468 | pub blues: u16, |
| 21469 | } |
| 21470 | impl_debug_if_no_extra_traits!(AllocColorPlanesRequest, "AllocColorPlanesRequest" ); |
| 21471 | impl AllocColorPlanesRequest { |
| 21472 | /// Serialize this request into bytes for the provided connection |
| 21473 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 21474 | let length_so_far = 0; |
| 21475 | let contiguous_bytes = self.contiguous.serialize(); |
| 21476 | let cmap_bytes = self.cmap.serialize(); |
| 21477 | let colors_bytes = self.colors.serialize(); |
| 21478 | let reds_bytes = self.reds.serialize(); |
| 21479 | let greens_bytes = self.greens.serialize(); |
| 21480 | let blues_bytes = self.blues.serialize(); |
| 21481 | let mut request0 = vec![ |
| 21482 | ALLOC_COLOR_PLANES_REQUEST, |
| 21483 | contiguous_bytes[0], |
| 21484 | 0, |
| 21485 | 0, |
| 21486 | cmap_bytes[0], |
| 21487 | cmap_bytes[1], |
| 21488 | cmap_bytes[2], |
| 21489 | cmap_bytes[3], |
| 21490 | colors_bytes[0], |
| 21491 | colors_bytes[1], |
| 21492 | reds_bytes[0], |
| 21493 | reds_bytes[1], |
| 21494 | greens_bytes[0], |
| 21495 | greens_bytes[1], |
| 21496 | blues_bytes[0], |
| 21497 | blues_bytes[1], |
| 21498 | ]; |
| 21499 | let length_so_far = length_so_far + request0.len(); |
| 21500 | assert_eq!(length_so_far % 4, 0); |
| 21501 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 21502 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 21503 | ([request0.into()], vec![]) |
| 21504 | } |
| 21505 | /// Parse this request given its header, its body, and any fds that go along with it |
| 21506 | #[cfg (feature = "request-parsing" )] |
| 21507 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 21508 | if header.major_opcode != ALLOC_COLOR_PLANES_REQUEST { |
| 21509 | return Err(ParseError::InvalidValue); |
| 21510 | } |
| 21511 | let remaining = &[header.minor_opcode]; |
| 21512 | let (contiguous, remaining) = bool::try_parse(remaining)?; |
| 21513 | let _ = remaining; |
| 21514 | let (cmap, remaining) = Colormap::try_parse(value)?; |
| 21515 | let (colors, remaining) = u16::try_parse(remaining)?; |
| 21516 | let (reds, remaining) = u16::try_parse(remaining)?; |
| 21517 | let (greens, remaining) = u16::try_parse(remaining)?; |
| 21518 | let (blues, remaining) = u16::try_parse(remaining)?; |
| 21519 | let _ = remaining; |
| 21520 | Ok(AllocColorPlanesRequest { |
| 21521 | contiguous, |
| 21522 | cmap, |
| 21523 | colors, |
| 21524 | reds, |
| 21525 | greens, |
| 21526 | blues, |
| 21527 | }) |
| 21528 | } |
| 21529 | } |
| 21530 | impl Request for AllocColorPlanesRequest { |
| 21531 | const EXTENSION_NAME: Option<&'static str> = None; |
| 21532 | |
| 21533 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 21534 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 21535 | // Flatten the buffers into a single vector |
| 21536 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 21537 | (buf, fds) |
| 21538 | } |
| 21539 | } |
| 21540 | impl crate::x11_utils::ReplyRequest for AllocColorPlanesRequest { |
| 21541 | type Reply = AllocColorPlanesReply; |
| 21542 | } |
| 21543 | |
| 21544 | #[derive (Clone, Default)] |
| 21545 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 21546 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 21547 | pub struct AllocColorPlanesReply { |
| 21548 | pub sequence: u16, |
| 21549 | pub length: u32, |
| 21550 | pub red_mask: u32, |
| 21551 | pub green_mask: u32, |
| 21552 | pub blue_mask: u32, |
| 21553 | pub pixels: Vec<u32>, |
| 21554 | } |
| 21555 | impl_debug_if_no_extra_traits!(AllocColorPlanesReply, "AllocColorPlanesReply" ); |
| 21556 | impl TryParse for AllocColorPlanesReply { |
| 21557 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 21558 | let remaining: &[u8] = initial_value; |
| 21559 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 21560 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 21561 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21562 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 21563 | let (pixels_len: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21564 | let remaining: &[u8] = remaining.get(2..).ok_or(err:ParseError::InsufficientData)?; |
| 21565 | let (red_mask: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 21566 | let (green_mask: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 21567 | let (blue_mask: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 21568 | let remaining: &[u8] = remaining.get(8..).ok_or(err:ParseError::InsufficientData)?; |
| 21569 | let (pixels: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<u32>(data:remaining, list_length:pixels_len.try_to_usize()?)?; |
| 21570 | if response_type != 1 { |
| 21571 | return Err(ParseError::InvalidValue); |
| 21572 | } |
| 21573 | let result: AllocColorPlanesReply = AllocColorPlanesReply { sequence, length, red_mask, green_mask, blue_mask, pixels }; |
| 21574 | let _ = remaining; |
| 21575 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 21576 | .ok_or(err:ParseError::InsufficientData)?; |
| 21577 | Ok((result, remaining)) |
| 21578 | } |
| 21579 | } |
| 21580 | impl Serialize for AllocColorPlanesReply { |
| 21581 | type Bytes = Vec<u8>; |
| 21582 | fn serialize(&self) -> Vec<u8> { |
| 21583 | let mut result: Vec = Vec::new(); |
| 21584 | self.serialize_into(&mut result); |
| 21585 | result |
| 21586 | } |
| 21587 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 21588 | bytes.reserve(additional:32); |
| 21589 | let response_type_bytes: &[u8; 1] = &[1]; |
| 21590 | bytes.push(response_type_bytes[0]); |
| 21591 | bytes.extend_from_slice(&[0; 1]); |
| 21592 | self.sequence.serialize_into(bytes); |
| 21593 | self.length.serialize_into(bytes); |
| 21594 | let pixels_len: u16 = u16::try_from(self.pixels.len()).expect(msg:"`pixels` has too many elements" ); |
| 21595 | pixels_len.serialize_into(bytes); |
| 21596 | bytes.extend_from_slice(&[0; 2]); |
| 21597 | self.red_mask.serialize_into(bytes); |
| 21598 | self.green_mask.serialize_into(bytes); |
| 21599 | self.blue_mask.serialize_into(bytes); |
| 21600 | bytes.extend_from_slice(&[0; 8]); |
| 21601 | self.pixels.serialize_into(bytes); |
| 21602 | } |
| 21603 | } |
| 21604 | impl AllocColorPlanesReply { |
| 21605 | /// Get the value of the `pixels_len` field. |
| 21606 | /// |
| 21607 | /// The `pixels_len` field is used as the length field of the `pixels` field. |
| 21608 | /// This function computes the field's value again based on the length of the list. |
| 21609 | /// |
| 21610 | /// # Panics |
| 21611 | /// |
| 21612 | /// Panics if the value cannot be represented in the target type. This |
| 21613 | /// cannot happen with values of the struct received from the X11 server. |
| 21614 | pub fn pixels_len(&self) -> u16 { |
| 21615 | self.pixels.len() |
| 21616 | .try_into().unwrap() |
| 21617 | } |
| 21618 | } |
| 21619 | |
| 21620 | /// Opcode for the FreeColors request |
| 21621 | pub const FREE_COLORS_REQUEST: u8 = 88; |
| 21622 | #[derive (Clone, Default)] |
| 21623 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 21624 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 21625 | pub struct FreeColorsRequest<'input> { |
| 21626 | pub cmap: Colormap, |
| 21627 | pub plane_mask: u32, |
| 21628 | pub pixels: Cow<'input, [u32]>, |
| 21629 | } |
| 21630 | impl_debug_if_no_extra_traits!(FreeColorsRequest<'_>, "FreeColorsRequest" ); |
| 21631 | impl<'input> FreeColorsRequest<'input> { |
| 21632 | /// Serialize this request into bytes for the provided connection |
| 21633 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 21634 | let length_so_far = 0; |
| 21635 | let cmap_bytes = self.cmap.serialize(); |
| 21636 | let plane_mask_bytes = self.plane_mask.serialize(); |
| 21637 | let mut request0 = vec![ |
| 21638 | FREE_COLORS_REQUEST, |
| 21639 | 0, |
| 21640 | 0, |
| 21641 | 0, |
| 21642 | cmap_bytes[0], |
| 21643 | cmap_bytes[1], |
| 21644 | cmap_bytes[2], |
| 21645 | cmap_bytes[3], |
| 21646 | plane_mask_bytes[0], |
| 21647 | plane_mask_bytes[1], |
| 21648 | plane_mask_bytes[2], |
| 21649 | plane_mask_bytes[3], |
| 21650 | ]; |
| 21651 | let length_so_far = length_so_far + request0.len(); |
| 21652 | let pixels_bytes = self.pixels.serialize(); |
| 21653 | let length_so_far = length_so_far + pixels_bytes.len(); |
| 21654 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 21655 | let length_so_far = length_so_far + padding0.len(); |
| 21656 | assert_eq!(length_so_far % 4, 0); |
| 21657 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 21658 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 21659 | ([request0.into(), pixels_bytes.into(), padding0.into()], vec![]) |
| 21660 | } |
| 21661 | /// Parse this request given its header, its body, and any fds that go along with it |
| 21662 | #[cfg (feature = "request-parsing" )] |
| 21663 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 21664 | if header.major_opcode != FREE_COLORS_REQUEST { |
| 21665 | return Err(ParseError::InvalidValue); |
| 21666 | } |
| 21667 | let remaining = &[header.minor_opcode]; |
| 21668 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 21669 | let _ = remaining; |
| 21670 | let (cmap, remaining) = Colormap::try_parse(value)?; |
| 21671 | let (plane_mask, remaining) = u32::try_parse(remaining)?; |
| 21672 | let mut remaining = remaining; |
| 21673 | // Length is 'everything left in the input' |
| 21674 | let mut pixels = Vec::new(); |
| 21675 | while !remaining.is_empty() { |
| 21676 | let (v, new_remaining) = u32::try_parse(remaining)?; |
| 21677 | remaining = new_remaining; |
| 21678 | pixels.push(v); |
| 21679 | } |
| 21680 | let _ = remaining; |
| 21681 | Ok(FreeColorsRequest { |
| 21682 | cmap, |
| 21683 | plane_mask, |
| 21684 | pixels: Cow::Owned(pixels), |
| 21685 | }) |
| 21686 | } |
| 21687 | /// Clone all borrowed data in this FreeColorsRequest. |
| 21688 | pub fn into_owned(self) -> FreeColorsRequest<'static> { |
| 21689 | FreeColorsRequest { |
| 21690 | cmap: self.cmap, |
| 21691 | plane_mask: self.plane_mask, |
| 21692 | pixels: Cow::Owned(self.pixels.into_owned()), |
| 21693 | } |
| 21694 | } |
| 21695 | } |
| 21696 | impl<'input> Request for FreeColorsRequest<'input> { |
| 21697 | const EXTENSION_NAME: Option<&'static str> = None; |
| 21698 | |
| 21699 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 21700 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 21701 | // Flatten the buffers into a single vector |
| 21702 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 21703 | (buf, fds) |
| 21704 | } |
| 21705 | } |
| 21706 | impl<'input> crate::x11_utils::VoidRequest for FreeColorsRequest<'input> { |
| 21707 | } |
| 21708 | |
| 21709 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 21710 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 21711 | pub struct ColorFlag(u8); |
| 21712 | impl ColorFlag { |
| 21713 | pub const RED: Self = Self(1 << 0); |
| 21714 | pub const GREEN: Self = Self(1 << 1); |
| 21715 | pub const BLUE: Self = Self(1 << 2); |
| 21716 | } |
| 21717 | impl From<ColorFlag> for u8 { |
| 21718 | #[inline ] |
| 21719 | fn from(input: ColorFlag) -> Self { |
| 21720 | input.0 |
| 21721 | } |
| 21722 | } |
| 21723 | impl From<ColorFlag> for Option<u8> { |
| 21724 | #[inline ] |
| 21725 | fn from(input: ColorFlag) -> Self { |
| 21726 | Some(input.0) |
| 21727 | } |
| 21728 | } |
| 21729 | impl From<ColorFlag> for u16 { |
| 21730 | #[inline ] |
| 21731 | fn from(input: ColorFlag) -> Self { |
| 21732 | u16::from(input.0) |
| 21733 | } |
| 21734 | } |
| 21735 | impl From<ColorFlag> for Option<u16> { |
| 21736 | #[inline ] |
| 21737 | fn from(input: ColorFlag) -> Self { |
| 21738 | Some(u16::from(input.0)) |
| 21739 | } |
| 21740 | } |
| 21741 | impl From<ColorFlag> for u32 { |
| 21742 | #[inline ] |
| 21743 | fn from(input: ColorFlag) -> Self { |
| 21744 | u32::from(input.0) |
| 21745 | } |
| 21746 | } |
| 21747 | impl From<ColorFlag> for Option<u32> { |
| 21748 | #[inline ] |
| 21749 | fn from(input: ColorFlag) -> Self { |
| 21750 | Some(u32::from(input.0)) |
| 21751 | } |
| 21752 | } |
| 21753 | impl From<u8> for ColorFlag { |
| 21754 | #[inline ] |
| 21755 | fn from(value: u8) -> Self { |
| 21756 | Self(value) |
| 21757 | } |
| 21758 | } |
| 21759 | impl core::fmt::Debug for ColorFlag { |
| 21760 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 21761 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 21762 | (Self::RED.0.into(), "RED" , "Red" ), |
| 21763 | (Self::GREEN.0.into(), "GREEN" , "Green" ), |
| 21764 | (Self::BLUE.0.into(), "BLUE" , "Blue" ), |
| 21765 | ]; |
| 21766 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 21767 | } |
| 21768 | } |
| 21769 | bitmask_binop!(ColorFlag, u8); |
| 21770 | |
| 21771 | #[derive (Clone, Copy, Default)] |
| 21772 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 21773 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 21774 | pub struct Coloritem { |
| 21775 | pub pixel: u32, |
| 21776 | pub red: u16, |
| 21777 | pub green: u16, |
| 21778 | pub blue: u16, |
| 21779 | pub flags: ColorFlag, |
| 21780 | } |
| 21781 | impl_debug_if_no_extra_traits!(Coloritem, "Coloritem" ); |
| 21782 | impl TryParse for Coloritem { |
| 21783 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 21784 | let (pixel: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 21785 | let (red: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21786 | let (green: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21787 | let (blue: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 21788 | let (flags: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 21789 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 21790 | let flags: ColorFlag = flags.into(); |
| 21791 | let result: Coloritem = Coloritem { pixel, red, green, blue, flags }; |
| 21792 | Ok((result, remaining)) |
| 21793 | } |
| 21794 | } |
| 21795 | impl Serialize for Coloritem { |
| 21796 | type Bytes = [u8; 12]; |
| 21797 | fn serialize(&self) -> [u8; 12] { |
| 21798 | let pixel_bytes = self.pixel.serialize(); |
| 21799 | let red_bytes = self.red.serialize(); |
| 21800 | let green_bytes = self.green.serialize(); |
| 21801 | let blue_bytes = self.blue.serialize(); |
| 21802 | let flags_bytes = u8::from(self.flags).serialize(); |
| 21803 | [ |
| 21804 | pixel_bytes[0], |
| 21805 | pixel_bytes[1], |
| 21806 | pixel_bytes[2], |
| 21807 | pixel_bytes[3], |
| 21808 | red_bytes[0], |
| 21809 | red_bytes[1], |
| 21810 | green_bytes[0], |
| 21811 | green_bytes[1], |
| 21812 | blue_bytes[0], |
| 21813 | blue_bytes[1], |
| 21814 | flags_bytes[0], |
| 21815 | 0, |
| 21816 | ] |
| 21817 | } |
| 21818 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 21819 | bytes.reserve(12); |
| 21820 | self.pixel.serialize_into(bytes); |
| 21821 | self.red.serialize_into(bytes); |
| 21822 | self.green.serialize_into(bytes); |
| 21823 | self.blue.serialize_into(bytes); |
| 21824 | u8::from(self.flags).serialize_into(bytes); |
| 21825 | bytes.extend_from_slice(&[0; 1]); |
| 21826 | } |
| 21827 | } |
| 21828 | |
| 21829 | /// Opcode for the StoreColors request |
| 21830 | pub const STORE_COLORS_REQUEST: u8 = 89; |
| 21831 | #[derive (Clone, Default)] |
| 21832 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 21833 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 21834 | pub struct StoreColorsRequest<'input> { |
| 21835 | pub cmap: Colormap, |
| 21836 | pub items: Cow<'input, [Coloritem]>, |
| 21837 | } |
| 21838 | impl_debug_if_no_extra_traits!(StoreColorsRequest<'_>, "StoreColorsRequest" ); |
| 21839 | impl<'input> StoreColorsRequest<'input> { |
| 21840 | /// Serialize this request into bytes for the provided connection |
| 21841 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 21842 | let length_so_far = 0; |
| 21843 | let cmap_bytes = self.cmap.serialize(); |
| 21844 | let mut request0 = vec![ |
| 21845 | STORE_COLORS_REQUEST, |
| 21846 | 0, |
| 21847 | 0, |
| 21848 | 0, |
| 21849 | cmap_bytes[0], |
| 21850 | cmap_bytes[1], |
| 21851 | cmap_bytes[2], |
| 21852 | cmap_bytes[3], |
| 21853 | ]; |
| 21854 | let length_so_far = length_so_far + request0.len(); |
| 21855 | let items_bytes = self.items.serialize(); |
| 21856 | let length_so_far = length_so_far + items_bytes.len(); |
| 21857 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 21858 | let length_so_far = length_so_far + padding0.len(); |
| 21859 | assert_eq!(length_so_far % 4, 0); |
| 21860 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 21861 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 21862 | ([request0.into(), items_bytes.into(), padding0.into()], vec![]) |
| 21863 | } |
| 21864 | /// Parse this request given its header, its body, and any fds that go along with it |
| 21865 | #[cfg (feature = "request-parsing" )] |
| 21866 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 21867 | if header.major_opcode != STORE_COLORS_REQUEST { |
| 21868 | return Err(ParseError::InvalidValue); |
| 21869 | } |
| 21870 | let remaining = &[header.minor_opcode]; |
| 21871 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 21872 | let _ = remaining; |
| 21873 | let (cmap, remaining) = Colormap::try_parse(value)?; |
| 21874 | let mut remaining = remaining; |
| 21875 | // Length is 'everything left in the input' |
| 21876 | let mut items = Vec::new(); |
| 21877 | while !remaining.is_empty() { |
| 21878 | let (v, new_remaining) = Coloritem::try_parse(remaining)?; |
| 21879 | remaining = new_remaining; |
| 21880 | items.push(v); |
| 21881 | } |
| 21882 | let _ = remaining; |
| 21883 | Ok(StoreColorsRequest { |
| 21884 | cmap, |
| 21885 | items: Cow::Owned(items), |
| 21886 | }) |
| 21887 | } |
| 21888 | /// Clone all borrowed data in this StoreColorsRequest. |
| 21889 | pub fn into_owned(self) -> StoreColorsRequest<'static> { |
| 21890 | StoreColorsRequest { |
| 21891 | cmap: self.cmap, |
| 21892 | items: Cow::Owned(self.items.into_owned()), |
| 21893 | } |
| 21894 | } |
| 21895 | } |
| 21896 | impl<'input> Request for StoreColorsRequest<'input> { |
| 21897 | const EXTENSION_NAME: Option<&'static str> = None; |
| 21898 | |
| 21899 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 21900 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 21901 | // Flatten the buffers into a single vector |
| 21902 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 21903 | (buf, fds) |
| 21904 | } |
| 21905 | } |
| 21906 | impl<'input> crate::x11_utils::VoidRequest for StoreColorsRequest<'input> { |
| 21907 | } |
| 21908 | |
| 21909 | /// Opcode for the StoreNamedColor request |
| 21910 | pub const STORE_NAMED_COLOR_REQUEST: u8 = 90; |
| 21911 | #[derive (Clone, Default)] |
| 21912 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 21913 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 21914 | pub struct StoreNamedColorRequest<'input> { |
| 21915 | pub flags: ColorFlag, |
| 21916 | pub cmap: Colormap, |
| 21917 | pub pixel: u32, |
| 21918 | pub name: Cow<'input, [u8]>, |
| 21919 | } |
| 21920 | impl_debug_if_no_extra_traits!(StoreNamedColorRequest<'_>, "StoreNamedColorRequest" ); |
| 21921 | impl<'input> StoreNamedColorRequest<'input> { |
| 21922 | /// Serialize this request into bytes for the provided connection |
| 21923 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 21924 | let length_so_far = 0; |
| 21925 | let flags_bytes = u8::from(self.flags).serialize(); |
| 21926 | let cmap_bytes = self.cmap.serialize(); |
| 21927 | let pixel_bytes = self.pixel.serialize(); |
| 21928 | let name_len = u16::try_from(self.name.len()).expect("`name` has too many elements" ); |
| 21929 | let name_len_bytes = name_len.serialize(); |
| 21930 | let mut request0 = vec![ |
| 21931 | STORE_NAMED_COLOR_REQUEST, |
| 21932 | flags_bytes[0], |
| 21933 | 0, |
| 21934 | 0, |
| 21935 | cmap_bytes[0], |
| 21936 | cmap_bytes[1], |
| 21937 | cmap_bytes[2], |
| 21938 | cmap_bytes[3], |
| 21939 | pixel_bytes[0], |
| 21940 | pixel_bytes[1], |
| 21941 | pixel_bytes[2], |
| 21942 | pixel_bytes[3], |
| 21943 | name_len_bytes[0], |
| 21944 | name_len_bytes[1], |
| 21945 | 0, |
| 21946 | 0, |
| 21947 | ]; |
| 21948 | let length_so_far = length_so_far + request0.len(); |
| 21949 | let length_so_far = length_so_far + self.name.len(); |
| 21950 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 21951 | let length_so_far = length_so_far + padding0.len(); |
| 21952 | assert_eq!(length_so_far % 4, 0); |
| 21953 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 21954 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 21955 | ([request0.into(), self.name, padding0.into()], vec![]) |
| 21956 | } |
| 21957 | /// Parse this request given its header, its body, and any fds that go along with it |
| 21958 | #[cfg (feature = "request-parsing" )] |
| 21959 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 21960 | if header.major_opcode != STORE_NAMED_COLOR_REQUEST { |
| 21961 | return Err(ParseError::InvalidValue); |
| 21962 | } |
| 21963 | let remaining = &[header.minor_opcode]; |
| 21964 | let (flags, remaining) = u8::try_parse(remaining)?; |
| 21965 | let flags = flags.into(); |
| 21966 | let _ = remaining; |
| 21967 | let (cmap, remaining) = Colormap::try_parse(value)?; |
| 21968 | let (pixel, remaining) = u32::try_parse(remaining)?; |
| 21969 | let (name_len, remaining) = u16::try_parse(remaining)?; |
| 21970 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 21971 | let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; |
| 21972 | let _ = remaining; |
| 21973 | Ok(StoreNamedColorRequest { |
| 21974 | flags, |
| 21975 | cmap, |
| 21976 | pixel, |
| 21977 | name: Cow::Borrowed(name), |
| 21978 | }) |
| 21979 | } |
| 21980 | /// Clone all borrowed data in this StoreNamedColorRequest. |
| 21981 | pub fn into_owned(self) -> StoreNamedColorRequest<'static> { |
| 21982 | StoreNamedColorRequest { |
| 21983 | flags: self.flags, |
| 21984 | cmap: self.cmap, |
| 21985 | pixel: self.pixel, |
| 21986 | name: Cow::Owned(self.name.into_owned()), |
| 21987 | } |
| 21988 | } |
| 21989 | } |
| 21990 | impl<'input> Request for StoreNamedColorRequest<'input> { |
| 21991 | const EXTENSION_NAME: Option<&'static str> = None; |
| 21992 | |
| 21993 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 21994 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 21995 | // Flatten the buffers into a single vector |
| 21996 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 21997 | (buf, fds) |
| 21998 | } |
| 21999 | } |
| 22000 | impl<'input> crate::x11_utils::VoidRequest for StoreNamedColorRequest<'input> { |
| 22001 | } |
| 22002 | |
| 22003 | #[derive (Clone, Copy, Default)] |
| 22004 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 22005 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 22006 | pub struct Rgb { |
| 22007 | pub red: u16, |
| 22008 | pub green: u16, |
| 22009 | pub blue: u16, |
| 22010 | } |
| 22011 | impl_debug_if_no_extra_traits!(Rgb, "Rgb" ); |
| 22012 | impl TryParse for Rgb { |
| 22013 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 22014 | let (red: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 22015 | let (green: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 22016 | let (blue: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 22017 | let remaining: &[u8] = remaining.get(2..).ok_or(err:ParseError::InsufficientData)?; |
| 22018 | let result: Rgb = Rgb { red, green, blue }; |
| 22019 | Ok((result, remaining)) |
| 22020 | } |
| 22021 | } |
| 22022 | impl Serialize for Rgb { |
| 22023 | type Bytes = [u8; 8]; |
| 22024 | fn serialize(&self) -> [u8; 8] { |
| 22025 | let red_bytes = self.red.serialize(); |
| 22026 | let green_bytes = self.green.serialize(); |
| 22027 | let blue_bytes = self.blue.serialize(); |
| 22028 | [ |
| 22029 | red_bytes[0], |
| 22030 | red_bytes[1], |
| 22031 | green_bytes[0], |
| 22032 | green_bytes[1], |
| 22033 | blue_bytes[0], |
| 22034 | blue_bytes[1], |
| 22035 | 0, |
| 22036 | 0, |
| 22037 | ] |
| 22038 | } |
| 22039 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 22040 | bytes.reserve(8); |
| 22041 | self.red.serialize_into(bytes); |
| 22042 | self.green.serialize_into(bytes); |
| 22043 | self.blue.serialize_into(bytes); |
| 22044 | bytes.extend_from_slice(&[0; 2]); |
| 22045 | } |
| 22046 | } |
| 22047 | |
| 22048 | /// Opcode for the QueryColors request |
| 22049 | pub const QUERY_COLORS_REQUEST: u8 = 91; |
| 22050 | #[derive (Clone, Default)] |
| 22051 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 22052 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 22053 | pub struct QueryColorsRequest<'input> { |
| 22054 | pub cmap: Colormap, |
| 22055 | pub pixels: Cow<'input, [u32]>, |
| 22056 | } |
| 22057 | impl_debug_if_no_extra_traits!(QueryColorsRequest<'_>, "QueryColorsRequest" ); |
| 22058 | impl<'input> QueryColorsRequest<'input> { |
| 22059 | /// Serialize this request into bytes for the provided connection |
| 22060 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 22061 | let length_so_far = 0; |
| 22062 | let cmap_bytes = self.cmap.serialize(); |
| 22063 | let mut request0 = vec![ |
| 22064 | QUERY_COLORS_REQUEST, |
| 22065 | 0, |
| 22066 | 0, |
| 22067 | 0, |
| 22068 | cmap_bytes[0], |
| 22069 | cmap_bytes[1], |
| 22070 | cmap_bytes[2], |
| 22071 | cmap_bytes[3], |
| 22072 | ]; |
| 22073 | let length_so_far = length_so_far + request0.len(); |
| 22074 | let pixels_bytes = self.pixels.serialize(); |
| 22075 | let length_so_far = length_so_far + pixels_bytes.len(); |
| 22076 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 22077 | let length_so_far = length_so_far + padding0.len(); |
| 22078 | assert_eq!(length_so_far % 4, 0); |
| 22079 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 22080 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 22081 | ([request0.into(), pixels_bytes.into(), padding0.into()], vec![]) |
| 22082 | } |
| 22083 | /// Parse this request given its header, its body, and any fds that go along with it |
| 22084 | #[cfg (feature = "request-parsing" )] |
| 22085 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 22086 | if header.major_opcode != QUERY_COLORS_REQUEST { |
| 22087 | return Err(ParseError::InvalidValue); |
| 22088 | } |
| 22089 | let remaining = &[header.minor_opcode]; |
| 22090 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 22091 | let _ = remaining; |
| 22092 | let (cmap, remaining) = Colormap::try_parse(value)?; |
| 22093 | let mut remaining = remaining; |
| 22094 | // Length is 'everything left in the input' |
| 22095 | let mut pixels = Vec::new(); |
| 22096 | while !remaining.is_empty() { |
| 22097 | let (v, new_remaining) = u32::try_parse(remaining)?; |
| 22098 | remaining = new_remaining; |
| 22099 | pixels.push(v); |
| 22100 | } |
| 22101 | let _ = remaining; |
| 22102 | Ok(QueryColorsRequest { |
| 22103 | cmap, |
| 22104 | pixels: Cow::Owned(pixels), |
| 22105 | }) |
| 22106 | } |
| 22107 | /// Clone all borrowed data in this QueryColorsRequest. |
| 22108 | pub fn into_owned(self) -> QueryColorsRequest<'static> { |
| 22109 | QueryColorsRequest { |
| 22110 | cmap: self.cmap, |
| 22111 | pixels: Cow::Owned(self.pixels.into_owned()), |
| 22112 | } |
| 22113 | } |
| 22114 | } |
| 22115 | impl<'input> Request for QueryColorsRequest<'input> { |
| 22116 | const EXTENSION_NAME: Option<&'static str> = None; |
| 22117 | |
| 22118 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 22119 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 22120 | // Flatten the buffers into a single vector |
| 22121 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 22122 | (buf, fds) |
| 22123 | } |
| 22124 | } |
| 22125 | impl<'input> crate::x11_utils::ReplyRequest for QueryColorsRequest<'input> { |
| 22126 | type Reply = QueryColorsReply; |
| 22127 | } |
| 22128 | |
| 22129 | #[derive (Clone, Default)] |
| 22130 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 22131 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 22132 | pub struct QueryColorsReply { |
| 22133 | pub sequence: u16, |
| 22134 | pub length: u32, |
| 22135 | pub colors: Vec<Rgb>, |
| 22136 | } |
| 22137 | impl_debug_if_no_extra_traits!(QueryColorsReply, "QueryColorsReply" ); |
| 22138 | impl TryParse for QueryColorsReply { |
| 22139 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 22140 | let remaining: &[u8] = initial_value; |
| 22141 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 22142 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 22143 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 22144 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 22145 | let (colors_len: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 22146 | let remaining: &[u8] = remaining.get(22..).ok_or(err:ParseError::InsufficientData)?; |
| 22147 | let (colors: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<Rgb>(data:remaining, list_length:colors_len.try_to_usize()?)?; |
| 22148 | if response_type != 1 { |
| 22149 | return Err(ParseError::InvalidValue); |
| 22150 | } |
| 22151 | let result: QueryColorsReply = QueryColorsReply { sequence, length, colors }; |
| 22152 | let _ = remaining; |
| 22153 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 22154 | .ok_or(err:ParseError::InsufficientData)?; |
| 22155 | Ok((result, remaining)) |
| 22156 | } |
| 22157 | } |
| 22158 | impl Serialize for QueryColorsReply { |
| 22159 | type Bytes = Vec<u8>; |
| 22160 | fn serialize(&self) -> Vec<u8> { |
| 22161 | let mut result: Vec = Vec::new(); |
| 22162 | self.serialize_into(&mut result); |
| 22163 | result |
| 22164 | } |
| 22165 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 22166 | bytes.reserve(additional:32); |
| 22167 | let response_type_bytes: &[u8; 1] = &[1]; |
| 22168 | bytes.push(response_type_bytes[0]); |
| 22169 | bytes.extend_from_slice(&[0; 1]); |
| 22170 | self.sequence.serialize_into(bytes); |
| 22171 | self.length.serialize_into(bytes); |
| 22172 | let colors_len: u16 = u16::try_from(self.colors.len()).expect(msg:"`colors` has too many elements" ); |
| 22173 | colors_len.serialize_into(bytes); |
| 22174 | bytes.extend_from_slice(&[0; 22]); |
| 22175 | self.colors.serialize_into(bytes); |
| 22176 | } |
| 22177 | } |
| 22178 | impl QueryColorsReply { |
| 22179 | /// Get the value of the `colors_len` field. |
| 22180 | /// |
| 22181 | /// The `colors_len` field is used as the length field of the `colors` field. |
| 22182 | /// This function computes the field's value again based on the length of the list. |
| 22183 | /// |
| 22184 | /// # Panics |
| 22185 | /// |
| 22186 | /// Panics if the value cannot be represented in the target type. This |
| 22187 | /// cannot happen with values of the struct received from the X11 server. |
| 22188 | pub fn colors_len(&self) -> u16 { |
| 22189 | self.colors.len() |
| 22190 | .try_into().unwrap() |
| 22191 | } |
| 22192 | } |
| 22193 | |
| 22194 | /// Opcode for the LookupColor request |
| 22195 | pub const LOOKUP_COLOR_REQUEST: u8 = 92; |
| 22196 | #[derive (Clone, Default)] |
| 22197 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 22198 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 22199 | pub struct LookupColorRequest<'input> { |
| 22200 | pub cmap: Colormap, |
| 22201 | pub name: Cow<'input, [u8]>, |
| 22202 | } |
| 22203 | impl_debug_if_no_extra_traits!(LookupColorRequest<'_>, "LookupColorRequest" ); |
| 22204 | impl<'input> LookupColorRequest<'input> { |
| 22205 | /// Serialize this request into bytes for the provided connection |
| 22206 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 22207 | let length_so_far = 0; |
| 22208 | let cmap_bytes = self.cmap.serialize(); |
| 22209 | let name_len = u16::try_from(self.name.len()).expect("`name` has too many elements" ); |
| 22210 | let name_len_bytes = name_len.serialize(); |
| 22211 | let mut request0 = vec![ |
| 22212 | LOOKUP_COLOR_REQUEST, |
| 22213 | 0, |
| 22214 | 0, |
| 22215 | 0, |
| 22216 | cmap_bytes[0], |
| 22217 | cmap_bytes[1], |
| 22218 | cmap_bytes[2], |
| 22219 | cmap_bytes[3], |
| 22220 | name_len_bytes[0], |
| 22221 | name_len_bytes[1], |
| 22222 | 0, |
| 22223 | 0, |
| 22224 | ]; |
| 22225 | let length_so_far = length_so_far + request0.len(); |
| 22226 | let length_so_far = length_so_far + self.name.len(); |
| 22227 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 22228 | let length_so_far = length_so_far + padding0.len(); |
| 22229 | assert_eq!(length_so_far % 4, 0); |
| 22230 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 22231 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 22232 | ([request0.into(), self.name, padding0.into()], vec![]) |
| 22233 | } |
| 22234 | /// Parse this request given its header, its body, and any fds that go along with it |
| 22235 | #[cfg (feature = "request-parsing" )] |
| 22236 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 22237 | if header.major_opcode != LOOKUP_COLOR_REQUEST { |
| 22238 | return Err(ParseError::InvalidValue); |
| 22239 | } |
| 22240 | let remaining = &[header.minor_opcode]; |
| 22241 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 22242 | let _ = remaining; |
| 22243 | let (cmap, remaining) = Colormap::try_parse(value)?; |
| 22244 | let (name_len, remaining) = u16::try_parse(remaining)?; |
| 22245 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 22246 | let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; |
| 22247 | let _ = remaining; |
| 22248 | Ok(LookupColorRequest { |
| 22249 | cmap, |
| 22250 | name: Cow::Borrowed(name), |
| 22251 | }) |
| 22252 | } |
| 22253 | /// Clone all borrowed data in this LookupColorRequest. |
| 22254 | pub fn into_owned(self) -> LookupColorRequest<'static> { |
| 22255 | LookupColorRequest { |
| 22256 | cmap: self.cmap, |
| 22257 | name: Cow::Owned(self.name.into_owned()), |
| 22258 | } |
| 22259 | } |
| 22260 | } |
| 22261 | impl<'input> Request for LookupColorRequest<'input> { |
| 22262 | const EXTENSION_NAME: Option<&'static str> = None; |
| 22263 | |
| 22264 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 22265 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 22266 | // Flatten the buffers into a single vector |
| 22267 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 22268 | (buf, fds) |
| 22269 | } |
| 22270 | } |
| 22271 | impl<'input> crate::x11_utils::ReplyRequest for LookupColorRequest<'input> { |
| 22272 | type Reply = LookupColorReply; |
| 22273 | } |
| 22274 | |
| 22275 | #[derive (Clone, Copy, Default)] |
| 22276 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 22277 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 22278 | pub struct LookupColorReply { |
| 22279 | pub sequence: u16, |
| 22280 | pub length: u32, |
| 22281 | pub exact_red: u16, |
| 22282 | pub exact_green: u16, |
| 22283 | pub exact_blue: u16, |
| 22284 | pub visual_red: u16, |
| 22285 | pub visual_green: u16, |
| 22286 | pub visual_blue: u16, |
| 22287 | } |
| 22288 | impl_debug_if_no_extra_traits!(LookupColorReply, "LookupColorReply" ); |
| 22289 | impl TryParse for LookupColorReply { |
| 22290 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 22291 | let remaining: &[u8] = initial_value; |
| 22292 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 22293 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 22294 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 22295 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 22296 | let (exact_red: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 22297 | let (exact_green: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 22298 | let (exact_blue: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 22299 | let (visual_red: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 22300 | let (visual_green: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 22301 | let (visual_blue: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 22302 | if response_type != 1 { |
| 22303 | return Err(ParseError::InvalidValue); |
| 22304 | } |
| 22305 | let result: LookupColorReply = LookupColorReply { sequence, length, exact_red, exact_green, exact_blue, visual_red, visual_green, visual_blue }; |
| 22306 | let _ = remaining; |
| 22307 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 22308 | .ok_or(err:ParseError::InsufficientData)?; |
| 22309 | Ok((result, remaining)) |
| 22310 | } |
| 22311 | } |
| 22312 | impl Serialize for LookupColorReply { |
| 22313 | type Bytes = [u8; 20]; |
| 22314 | fn serialize(&self) -> [u8; 20] { |
| 22315 | let response_type_bytes = &[1]; |
| 22316 | let sequence_bytes = self.sequence.serialize(); |
| 22317 | let length_bytes = self.length.serialize(); |
| 22318 | let exact_red_bytes = self.exact_red.serialize(); |
| 22319 | let exact_green_bytes = self.exact_green.serialize(); |
| 22320 | let exact_blue_bytes = self.exact_blue.serialize(); |
| 22321 | let visual_red_bytes = self.visual_red.serialize(); |
| 22322 | let visual_green_bytes = self.visual_green.serialize(); |
| 22323 | let visual_blue_bytes = self.visual_blue.serialize(); |
| 22324 | [ |
| 22325 | response_type_bytes[0], |
| 22326 | 0, |
| 22327 | sequence_bytes[0], |
| 22328 | sequence_bytes[1], |
| 22329 | length_bytes[0], |
| 22330 | length_bytes[1], |
| 22331 | length_bytes[2], |
| 22332 | length_bytes[3], |
| 22333 | exact_red_bytes[0], |
| 22334 | exact_red_bytes[1], |
| 22335 | exact_green_bytes[0], |
| 22336 | exact_green_bytes[1], |
| 22337 | exact_blue_bytes[0], |
| 22338 | exact_blue_bytes[1], |
| 22339 | visual_red_bytes[0], |
| 22340 | visual_red_bytes[1], |
| 22341 | visual_green_bytes[0], |
| 22342 | visual_green_bytes[1], |
| 22343 | visual_blue_bytes[0], |
| 22344 | visual_blue_bytes[1], |
| 22345 | ] |
| 22346 | } |
| 22347 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 22348 | bytes.reserve(20); |
| 22349 | let response_type_bytes = &[1]; |
| 22350 | bytes.push(response_type_bytes[0]); |
| 22351 | bytes.extend_from_slice(&[0; 1]); |
| 22352 | self.sequence.serialize_into(bytes); |
| 22353 | self.length.serialize_into(bytes); |
| 22354 | self.exact_red.serialize_into(bytes); |
| 22355 | self.exact_green.serialize_into(bytes); |
| 22356 | self.exact_blue.serialize_into(bytes); |
| 22357 | self.visual_red.serialize_into(bytes); |
| 22358 | self.visual_green.serialize_into(bytes); |
| 22359 | self.visual_blue.serialize_into(bytes); |
| 22360 | } |
| 22361 | } |
| 22362 | |
| 22363 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 22364 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 22365 | pub struct PixmapEnum(u8); |
| 22366 | impl PixmapEnum { |
| 22367 | pub const NONE: Self = Self(0); |
| 22368 | } |
| 22369 | impl From<PixmapEnum> for u8 { |
| 22370 | #[inline ] |
| 22371 | fn from(input: PixmapEnum) -> Self { |
| 22372 | input.0 |
| 22373 | } |
| 22374 | } |
| 22375 | impl From<PixmapEnum> for Option<u8> { |
| 22376 | #[inline ] |
| 22377 | fn from(input: PixmapEnum) -> Self { |
| 22378 | Some(input.0) |
| 22379 | } |
| 22380 | } |
| 22381 | impl From<PixmapEnum> for u16 { |
| 22382 | #[inline ] |
| 22383 | fn from(input: PixmapEnum) -> Self { |
| 22384 | u16::from(input.0) |
| 22385 | } |
| 22386 | } |
| 22387 | impl From<PixmapEnum> for Option<u16> { |
| 22388 | #[inline ] |
| 22389 | fn from(input: PixmapEnum) -> Self { |
| 22390 | Some(u16::from(input.0)) |
| 22391 | } |
| 22392 | } |
| 22393 | impl From<PixmapEnum> for u32 { |
| 22394 | #[inline ] |
| 22395 | fn from(input: PixmapEnum) -> Self { |
| 22396 | u32::from(input.0) |
| 22397 | } |
| 22398 | } |
| 22399 | impl From<PixmapEnum> for Option<u32> { |
| 22400 | #[inline ] |
| 22401 | fn from(input: PixmapEnum) -> Self { |
| 22402 | Some(u32::from(input.0)) |
| 22403 | } |
| 22404 | } |
| 22405 | impl From<u8> for PixmapEnum { |
| 22406 | #[inline ] |
| 22407 | fn from(value: u8) -> Self { |
| 22408 | Self(value) |
| 22409 | } |
| 22410 | } |
| 22411 | impl core::fmt::Debug for PixmapEnum { |
| 22412 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 22413 | let variants: [(u32, &'static str, &'static …); 1] = [ |
| 22414 | (Self::NONE.0.into(), "NONE" , "None" ), |
| 22415 | ]; |
| 22416 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 22417 | } |
| 22418 | } |
| 22419 | |
| 22420 | /// Opcode for the CreateCursor request |
| 22421 | pub const CREATE_CURSOR_REQUEST: u8 = 93; |
| 22422 | #[derive (Clone, Copy, Default)] |
| 22423 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 22424 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 22425 | pub struct CreateCursorRequest { |
| 22426 | pub cid: Cursor, |
| 22427 | pub source: Pixmap, |
| 22428 | pub mask: Pixmap, |
| 22429 | pub fore_red: u16, |
| 22430 | pub fore_green: u16, |
| 22431 | pub fore_blue: u16, |
| 22432 | pub back_red: u16, |
| 22433 | pub back_green: u16, |
| 22434 | pub back_blue: u16, |
| 22435 | pub x: u16, |
| 22436 | pub y: u16, |
| 22437 | } |
| 22438 | impl_debug_if_no_extra_traits!(CreateCursorRequest, "CreateCursorRequest" ); |
| 22439 | impl CreateCursorRequest { |
| 22440 | /// Serialize this request into bytes for the provided connection |
| 22441 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 22442 | let length_so_far = 0; |
| 22443 | let cid_bytes = self.cid.serialize(); |
| 22444 | let source_bytes = self.source.serialize(); |
| 22445 | let mask_bytes = self.mask.serialize(); |
| 22446 | let fore_red_bytes = self.fore_red.serialize(); |
| 22447 | let fore_green_bytes = self.fore_green.serialize(); |
| 22448 | let fore_blue_bytes = self.fore_blue.serialize(); |
| 22449 | let back_red_bytes = self.back_red.serialize(); |
| 22450 | let back_green_bytes = self.back_green.serialize(); |
| 22451 | let back_blue_bytes = self.back_blue.serialize(); |
| 22452 | let x_bytes = self.x.serialize(); |
| 22453 | let y_bytes = self.y.serialize(); |
| 22454 | let mut request0 = vec![ |
| 22455 | CREATE_CURSOR_REQUEST, |
| 22456 | 0, |
| 22457 | 0, |
| 22458 | 0, |
| 22459 | cid_bytes[0], |
| 22460 | cid_bytes[1], |
| 22461 | cid_bytes[2], |
| 22462 | cid_bytes[3], |
| 22463 | source_bytes[0], |
| 22464 | source_bytes[1], |
| 22465 | source_bytes[2], |
| 22466 | source_bytes[3], |
| 22467 | mask_bytes[0], |
| 22468 | mask_bytes[1], |
| 22469 | mask_bytes[2], |
| 22470 | mask_bytes[3], |
| 22471 | fore_red_bytes[0], |
| 22472 | fore_red_bytes[1], |
| 22473 | fore_green_bytes[0], |
| 22474 | fore_green_bytes[1], |
| 22475 | fore_blue_bytes[0], |
| 22476 | fore_blue_bytes[1], |
| 22477 | back_red_bytes[0], |
| 22478 | back_red_bytes[1], |
| 22479 | back_green_bytes[0], |
| 22480 | back_green_bytes[1], |
| 22481 | back_blue_bytes[0], |
| 22482 | back_blue_bytes[1], |
| 22483 | x_bytes[0], |
| 22484 | x_bytes[1], |
| 22485 | y_bytes[0], |
| 22486 | y_bytes[1], |
| 22487 | ]; |
| 22488 | let length_so_far = length_so_far + request0.len(); |
| 22489 | assert_eq!(length_so_far % 4, 0); |
| 22490 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 22491 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 22492 | ([request0.into()], vec![]) |
| 22493 | } |
| 22494 | /// Parse this request given its header, its body, and any fds that go along with it |
| 22495 | #[cfg (feature = "request-parsing" )] |
| 22496 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 22497 | if header.major_opcode != CREATE_CURSOR_REQUEST { |
| 22498 | return Err(ParseError::InvalidValue); |
| 22499 | } |
| 22500 | let remaining = &[header.minor_opcode]; |
| 22501 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 22502 | let _ = remaining; |
| 22503 | let (cid, remaining) = Cursor::try_parse(value)?; |
| 22504 | let (source, remaining) = Pixmap::try_parse(remaining)?; |
| 22505 | let (mask, remaining) = Pixmap::try_parse(remaining)?; |
| 22506 | let (fore_red, remaining) = u16::try_parse(remaining)?; |
| 22507 | let (fore_green, remaining) = u16::try_parse(remaining)?; |
| 22508 | let (fore_blue, remaining) = u16::try_parse(remaining)?; |
| 22509 | let (back_red, remaining) = u16::try_parse(remaining)?; |
| 22510 | let (back_green, remaining) = u16::try_parse(remaining)?; |
| 22511 | let (back_blue, remaining) = u16::try_parse(remaining)?; |
| 22512 | let (x, remaining) = u16::try_parse(remaining)?; |
| 22513 | let (y, remaining) = u16::try_parse(remaining)?; |
| 22514 | let _ = remaining; |
| 22515 | Ok(CreateCursorRequest { |
| 22516 | cid, |
| 22517 | source, |
| 22518 | mask, |
| 22519 | fore_red, |
| 22520 | fore_green, |
| 22521 | fore_blue, |
| 22522 | back_red, |
| 22523 | back_green, |
| 22524 | back_blue, |
| 22525 | x, |
| 22526 | y, |
| 22527 | }) |
| 22528 | } |
| 22529 | } |
| 22530 | impl Request for CreateCursorRequest { |
| 22531 | const EXTENSION_NAME: Option<&'static str> = None; |
| 22532 | |
| 22533 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 22534 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 22535 | // Flatten the buffers into a single vector |
| 22536 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 22537 | (buf, fds) |
| 22538 | } |
| 22539 | } |
| 22540 | impl crate::x11_utils::VoidRequest for CreateCursorRequest { |
| 22541 | } |
| 22542 | |
| 22543 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 22544 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 22545 | pub struct FontEnum(u8); |
| 22546 | impl FontEnum { |
| 22547 | pub const NONE: Self = Self(0); |
| 22548 | } |
| 22549 | impl From<FontEnum> for u8 { |
| 22550 | #[inline ] |
| 22551 | fn from(input: FontEnum) -> Self { |
| 22552 | input.0 |
| 22553 | } |
| 22554 | } |
| 22555 | impl From<FontEnum> for Option<u8> { |
| 22556 | #[inline ] |
| 22557 | fn from(input: FontEnum) -> Self { |
| 22558 | Some(input.0) |
| 22559 | } |
| 22560 | } |
| 22561 | impl From<FontEnum> for u16 { |
| 22562 | #[inline ] |
| 22563 | fn from(input: FontEnum) -> Self { |
| 22564 | u16::from(input.0) |
| 22565 | } |
| 22566 | } |
| 22567 | impl From<FontEnum> for Option<u16> { |
| 22568 | #[inline ] |
| 22569 | fn from(input: FontEnum) -> Self { |
| 22570 | Some(u16::from(input.0)) |
| 22571 | } |
| 22572 | } |
| 22573 | impl From<FontEnum> for u32 { |
| 22574 | #[inline ] |
| 22575 | fn from(input: FontEnum) -> Self { |
| 22576 | u32::from(input.0) |
| 22577 | } |
| 22578 | } |
| 22579 | impl From<FontEnum> for Option<u32> { |
| 22580 | #[inline ] |
| 22581 | fn from(input: FontEnum) -> Self { |
| 22582 | Some(u32::from(input.0)) |
| 22583 | } |
| 22584 | } |
| 22585 | impl From<u8> for FontEnum { |
| 22586 | #[inline ] |
| 22587 | fn from(value: u8) -> Self { |
| 22588 | Self(value) |
| 22589 | } |
| 22590 | } |
| 22591 | impl core::fmt::Debug for FontEnum { |
| 22592 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 22593 | let variants: [(u32, &'static str, &'static …); 1] = [ |
| 22594 | (Self::NONE.0.into(), "NONE" , "None" ), |
| 22595 | ]; |
| 22596 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 22597 | } |
| 22598 | } |
| 22599 | |
| 22600 | /// Opcode for the CreateGlyphCursor request |
| 22601 | pub const CREATE_GLYPH_CURSOR_REQUEST: u8 = 94; |
| 22602 | /// create cursor. |
| 22603 | /// |
| 22604 | /// Creates a cursor from a font glyph. X provides a set of standard cursor shapes |
| 22605 | /// in a special font named cursor. Applications are encouraged to use this |
| 22606 | /// interface for their cursors because the font can be customized for the |
| 22607 | /// individual display type. |
| 22608 | /// |
| 22609 | /// All pixels which are set to 1 in the source will use the foreground color (as |
| 22610 | /// specified by `fore_red`, `fore_green` and `fore_blue`). All pixels set to 0 |
| 22611 | /// will use the background color (as specified by `back_red`, `back_green` and |
| 22612 | /// `back_blue`). |
| 22613 | /// |
| 22614 | /// # Fields |
| 22615 | /// |
| 22616 | /// * `cid` - The ID with which you will refer to the cursor, created by `xcb_generate_id`. |
| 22617 | /// * `source_font` - In which font to look for the cursor glyph. |
| 22618 | /// * `mask_font` - In which font to look for the mask glyph. |
| 22619 | /// * `source_char` - The glyph of `source_font` to use. |
| 22620 | /// * `mask_char` - The glyph of `mask_font` to use as a mask: Pixels which are set to 1 define |
| 22621 | /// which source pixels are displayed. All pixels which are set to 0 are not |
| 22622 | /// displayed. |
| 22623 | /// * `fore_red` - The red value of the foreground color. |
| 22624 | /// * `fore_green` - The green value of the foreground color. |
| 22625 | /// * `fore_blue` - The blue value of the foreground color. |
| 22626 | /// * `back_red` - The red value of the background color. |
| 22627 | /// * `back_green` - The green value of the background color. |
| 22628 | /// * `back_blue` - The blue value of the background color. |
| 22629 | /// |
| 22630 | /// # Errors |
| 22631 | /// |
| 22632 | /// * `Alloc` - The X server could not allocate the requested resources (no memory?). |
| 22633 | /// * `Font` - The specified `source_font` or `mask_font` does not exist. |
| 22634 | /// * `Value` - Either `source_char` or `mask_char` are not defined in `source_font` or `mask_font`, respectively. |
| 22635 | #[derive (Clone, Copy, Default)] |
| 22636 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 22637 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 22638 | pub struct CreateGlyphCursorRequest { |
| 22639 | pub cid: Cursor, |
| 22640 | pub source_font: Font, |
| 22641 | pub mask_font: Font, |
| 22642 | pub source_char: u16, |
| 22643 | pub mask_char: u16, |
| 22644 | pub fore_red: u16, |
| 22645 | pub fore_green: u16, |
| 22646 | pub fore_blue: u16, |
| 22647 | pub back_red: u16, |
| 22648 | pub back_green: u16, |
| 22649 | pub back_blue: u16, |
| 22650 | } |
| 22651 | impl_debug_if_no_extra_traits!(CreateGlyphCursorRequest, "CreateGlyphCursorRequest" ); |
| 22652 | impl CreateGlyphCursorRequest { |
| 22653 | /// Serialize this request into bytes for the provided connection |
| 22654 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 22655 | let length_so_far = 0; |
| 22656 | let cid_bytes = self.cid.serialize(); |
| 22657 | let source_font_bytes = self.source_font.serialize(); |
| 22658 | let mask_font_bytes = self.mask_font.serialize(); |
| 22659 | let source_char_bytes = self.source_char.serialize(); |
| 22660 | let mask_char_bytes = self.mask_char.serialize(); |
| 22661 | let fore_red_bytes = self.fore_red.serialize(); |
| 22662 | let fore_green_bytes = self.fore_green.serialize(); |
| 22663 | let fore_blue_bytes = self.fore_blue.serialize(); |
| 22664 | let back_red_bytes = self.back_red.serialize(); |
| 22665 | let back_green_bytes = self.back_green.serialize(); |
| 22666 | let back_blue_bytes = self.back_blue.serialize(); |
| 22667 | let mut request0 = vec![ |
| 22668 | CREATE_GLYPH_CURSOR_REQUEST, |
| 22669 | 0, |
| 22670 | 0, |
| 22671 | 0, |
| 22672 | cid_bytes[0], |
| 22673 | cid_bytes[1], |
| 22674 | cid_bytes[2], |
| 22675 | cid_bytes[3], |
| 22676 | source_font_bytes[0], |
| 22677 | source_font_bytes[1], |
| 22678 | source_font_bytes[2], |
| 22679 | source_font_bytes[3], |
| 22680 | mask_font_bytes[0], |
| 22681 | mask_font_bytes[1], |
| 22682 | mask_font_bytes[2], |
| 22683 | mask_font_bytes[3], |
| 22684 | source_char_bytes[0], |
| 22685 | source_char_bytes[1], |
| 22686 | mask_char_bytes[0], |
| 22687 | mask_char_bytes[1], |
| 22688 | fore_red_bytes[0], |
| 22689 | fore_red_bytes[1], |
| 22690 | fore_green_bytes[0], |
| 22691 | fore_green_bytes[1], |
| 22692 | fore_blue_bytes[0], |
| 22693 | fore_blue_bytes[1], |
| 22694 | back_red_bytes[0], |
| 22695 | back_red_bytes[1], |
| 22696 | back_green_bytes[0], |
| 22697 | back_green_bytes[1], |
| 22698 | back_blue_bytes[0], |
| 22699 | back_blue_bytes[1], |
| 22700 | ]; |
| 22701 | let length_so_far = length_so_far + request0.len(); |
| 22702 | assert_eq!(length_so_far % 4, 0); |
| 22703 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 22704 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 22705 | ([request0.into()], vec![]) |
| 22706 | } |
| 22707 | /// Parse this request given its header, its body, and any fds that go along with it |
| 22708 | #[cfg (feature = "request-parsing" )] |
| 22709 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 22710 | if header.major_opcode != CREATE_GLYPH_CURSOR_REQUEST { |
| 22711 | return Err(ParseError::InvalidValue); |
| 22712 | } |
| 22713 | let remaining = &[header.minor_opcode]; |
| 22714 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 22715 | let _ = remaining; |
| 22716 | let (cid, remaining) = Cursor::try_parse(value)?; |
| 22717 | let (source_font, remaining) = Font::try_parse(remaining)?; |
| 22718 | let (mask_font, remaining) = Font::try_parse(remaining)?; |
| 22719 | let (source_char, remaining) = u16::try_parse(remaining)?; |
| 22720 | let (mask_char, remaining) = u16::try_parse(remaining)?; |
| 22721 | let (fore_red, remaining) = u16::try_parse(remaining)?; |
| 22722 | let (fore_green, remaining) = u16::try_parse(remaining)?; |
| 22723 | let (fore_blue, remaining) = u16::try_parse(remaining)?; |
| 22724 | let (back_red, remaining) = u16::try_parse(remaining)?; |
| 22725 | let (back_green, remaining) = u16::try_parse(remaining)?; |
| 22726 | let (back_blue, remaining) = u16::try_parse(remaining)?; |
| 22727 | let _ = remaining; |
| 22728 | Ok(CreateGlyphCursorRequest { |
| 22729 | cid, |
| 22730 | source_font, |
| 22731 | mask_font, |
| 22732 | source_char, |
| 22733 | mask_char, |
| 22734 | fore_red, |
| 22735 | fore_green, |
| 22736 | fore_blue, |
| 22737 | back_red, |
| 22738 | back_green, |
| 22739 | back_blue, |
| 22740 | }) |
| 22741 | } |
| 22742 | } |
| 22743 | impl Request for CreateGlyphCursorRequest { |
| 22744 | const EXTENSION_NAME: Option<&'static str> = None; |
| 22745 | |
| 22746 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 22747 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 22748 | // Flatten the buffers into a single vector |
| 22749 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 22750 | (buf, fds) |
| 22751 | } |
| 22752 | } |
| 22753 | impl crate::x11_utils::VoidRequest for CreateGlyphCursorRequest { |
| 22754 | } |
| 22755 | |
| 22756 | /// Opcode for the FreeCursor request |
| 22757 | pub const FREE_CURSOR_REQUEST: u8 = 95; |
| 22758 | /// Deletes a cursor. |
| 22759 | /// |
| 22760 | /// Deletes the association between the cursor resource ID and the specified |
| 22761 | /// cursor. The cursor is freed when no other resource references it. |
| 22762 | /// |
| 22763 | /// # Fields |
| 22764 | /// |
| 22765 | /// * `cursor` - The cursor to destroy. |
| 22766 | /// |
| 22767 | /// # Errors |
| 22768 | /// |
| 22769 | /// * `Cursor` - The specified cursor does not exist. |
| 22770 | #[derive (Clone, Copy, Default)] |
| 22771 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 22772 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 22773 | pub struct FreeCursorRequest { |
| 22774 | pub cursor: Cursor, |
| 22775 | } |
| 22776 | impl_debug_if_no_extra_traits!(FreeCursorRequest, "FreeCursorRequest" ); |
| 22777 | impl FreeCursorRequest { |
| 22778 | /// Serialize this request into bytes for the provided connection |
| 22779 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 22780 | let length_so_far = 0; |
| 22781 | let cursor_bytes = self.cursor.serialize(); |
| 22782 | let mut request0 = vec![ |
| 22783 | FREE_CURSOR_REQUEST, |
| 22784 | 0, |
| 22785 | 0, |
| 22786 | 0, |
| 22787 | cursor_bytes[0], |
| 22788 | cursor_bytes[1], |
| 22789 | cursor_bytes[2], |
| 22790 | cursor_bytes[3], |
| 22791 | ]; |
| 22792 | let length_so_far = length_so_far + request0.len(); |
| 22793 | assert_eq!(length_so_far % 4, 0); |
| 22794 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 22795 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 22796 | ([request0.into()], vec![]) |
| 22797 | } |
| 22798 | /// Parse this request given its header, its body, and any fds that go along with it |
| 22799 | #[cfg (feature = "request-parsing" )] |
| 22800 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 22801 | if header.major_opcode != FREE_CURSOR_REQUEST { |
| 22802 | return Err(ParseError::InvalidValue); |
| 22803 | } |
| 22804 | let remaining = &[header.minor_opcode]; |
| 22805 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 22806 | let _ = remaining; |
| 22807 | let (cursor, remaining) = Cursor::try_parse(value)?; |
| 22808 | let _ = remaining; |
| 22809 | Ok(FreeCursorRequest { |
| 22810 | cursor, |
| 22811 | }) |
| 22812 | } |
| 22813 | } |
| 22814 | impl Request for FreeCursorRequest { |
| 22815 | const EXTENSION_NAME: Option<&'static str> = None; |
| 22816 | |
| 22817 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 22818 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 22819 | // Flatten the buffers into a single vector |
| 22820 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 22821 | (buf, fds) |
| 22822 | } |
| 22823 | } |
| 22824 | impl crate::x11_utils::VoidRequest for FreeCursorRequest { |
| 22825 | } |
| 22826 | |
| 22827 | /// Opcode for the RecolorCursor request |
| 22828 | pub const RECOLOR_CURSOR_REQUEST: u8 = 96; |
| 22829 | #[derive (Clone, Copy, Default)] |
| 22830 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 22831 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 22832 | pub struct RecolorCursorRequest { |
| 22833 | pub cursor: Cursor, |
| 22834 | pub fore_red: u16, |
| 22835 | pub fore_green: u16, |
| 22836 | pub fore_blue: u16, |
| 22837 | pub back_red: u16, |
| 22838 | pub back_green: u16, |
| 22839 | pub back_blue: u16, |
| 22840 | } |
| 22841 | impl_debug_if_no_extra_traits!(RecolorCursorRequest, "RecolorCursorRequest" ); |
| 22842 | impl RecolorCursorRequest { |
| 22843 | /// Serialize this request into bytes for the provided connection |
| 22844 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 22845 | let length_so_far = 0; |
| 22846 | let cursor_bytes = self.cursor.serialize(); |
| 22847 | let fore_red_bytes = self.fore_red.serialize(); |
| 22848 | let fore_green_bytes = self.fore_green.serialize(); |
| 22849 | let fore_blue_bytes = self.fore_blue.serialize(); |
| 22850 | let back_red_bytes = self.back_red.serialize(); |
| 22851 | let back_green_bytes = self.back_green.serialize(); |
| 22852 | let back_blue_bytes = self.back_blue.serialize(); |
| 22853 | let mut request0 = vec![ |
| 22854 | RECOLOR_CURSOR_REQUEST, |
| 22855 | 0, |
| 22856 | 0, |
| 22857 | 0, |
| 22858 | cursor_bytes[0], |
| 22859 | cursor_bytes[1], |
| 22860 | cursor_bytes[2], |
| 22861 | cursor_bytes[3], |
| 22862 | fore_red_bytes[0], |
| 22863 | fore_red_bytes[1], |
| 22864 | fore_green_bytes[0], |
| 22865 | fore_green_bytes[1], |
| 22866 | fore_blue_bytes[0], |
| 22867 | fore_blue_bytes[1], |
| 22868 | back_red_bytes[0], |
| 22869 | back_red_bytes[1], |
| 22870 | back_green_bytes[0], |
| 22871 | back_green_bytes[1], |
| 22872 | back_blue_bytes[0], |
| 22873 | back_blue_bytes[1], |
| 22874 | ]; |
| 22875 | let length_so_far = length_so_far + request0.len(); |
| 22876 | assert_eq!(length_so_far % 4, 0); |
| 22877 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 22878 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 22879 | ([request0.into()], vec![]) |
| 22880 | } |
| 22881 | /// Parse this request given its header, its body, and any fds that go along with it |
| 22882 | #[cfg (feature = "request-parsing" )] |
| 22883 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 22884 | if header.major_opcode != RECOLOR_CURSOR_REQUEST { |
| 22885 | return Err(ParseError::InvalidValue); |
| 22886 | } |
| 22887 | let remaining = &[header.minor_opcode]; |
| 22888 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 22889 | let _ = remaining; |
| 22890 | let (cursor, remaining) = Cursor::try_parse(value)?; |
| 22891 | let (fore_red, remaining) = u16::try_parse(remaining)?; |
| 22892 | let (fore_green, remaining) = u16::try_parse(remaining)?; |
| 22893 | let (fore_blue, remaining) = u16::try_parse(remaining)?; |
| 22894 | let (back_red, remaining) = u16::try_parse(remaining)?; |
| 22895 | let (back_green, remaining) = u16::try_parse(remaining)?; |
| 22896 | let (back_blue, remaining) = u16::try_parse(remaining)?; |
| 22897 | let _ = remaining; |
| 22898 | Ok(RecolorCursorRequest { |
| 22899 | cursor, |
| 22900 | fore_red, |
| 22901 | fore_green, |
| 22902 | fore_blue, |
| 22903 | back_red, |
| 22904 | back_green, |
| 22905 | back_blue, |
| 22906 | }) |
| 22907 | } |
| 22908 | } |
| 22909 | impl Request for RecolorCursorRequest { |
| 22910 | const EXTENSION_NAME: Option<&'static str> = None; |
| 22911 | |
| 22912 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 22913 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 22914 | // Flatten the buffers into a single vector |
| 22915 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 22916 | (buf, fds) |
| 22917 | } |
| 22918 | } |
| 22919 | impl crate::x11_utils::VoidRequest for RecolorCursorRequest { |
| 22920 | } |
| 22921 | |
| 22922 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 22923 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 22924 | pub struct QueryShapeOf(u8); |
| 22925 | impl QueryShapeOf { |
| 22926 | pub const LARGEST_CURSOR: Self = Self(0); |
| 22927 | pub const FASTEST_TILE: Self = Self(1); |
| 22928 | pub const FASTEST_STIPPLE: Self = Self(2); |
| 22929 | } |
| 22930 | impl From<QueryShapeOf> for u8 { |
| 22931 | #[inline ] |
| 22932 | fn from(input: QueryShapeOf) -> Self { |
| 22933 | input.0 |
| 22934 | } |
| 22935 | } |
| 22936 | impl From<QueryShapeOf> for Option<u8> { |
| 22937 | #[inline ] |
| 22938 | fn from(input: QueryShapeOf) -> Self { |
| 22939 | Some(input.0) |
| 22940 | } |
| 22941 | } |
| 22942 | impl From<QueryShapeOf> for u16 { |
| 22943 | #[inline ] |
| 22944 | fn from(input: QueryShapeOf) -> Self { |
| 22945 | u16::from(input.0) |
| 22946 | } |
| 22947 | } |
| 22948 | impl From<QueryShapeOf> for Option<u16> { |
| 22949 | #[inline ] |
| 22950 | fn from(input: QueryShapeOf) -> Self { |
| 22951 | Some(u16::from(input.0)) |
| 22952 | } |
| 22953 | } |
| 22954 | impl From<QueryShapeOf> for u32 { |
| 22955 | #[inline ] |
| 22956 | fn from(input: QueryShapeOf) -> Self { |
| 22957 | u32::from(input.0) |
| 22958 | } |
| 22959 | } |
| 22960 | impl From<QueryShapeOf> for Option<u32> { |
| 22961 | #[inline ] |
| 22962 | fn from(input: QueryShapeOf) -> Self { |
| 22963 | Some(u32::from(input.0)) |
| 22964 | } |
| 22965 | } |
| 22966 | impl From<u8> for QueryShapeOf { |
| 22967 | #[inline ] |
| 22968 | fn from(value: u8) -> Self { |
| 22969 | Self(value) |
| 22970 | } |
| 22971 | } |
| 22972 | impl core::fmt::Debug for QueryShapeOf { |
| 22973 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 22974 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 22975 | (Self::LARGEST_CURSOR.0.into(), "LARGEST_CURSOR" , "LargestCursor" ), |
| 22976 | (Self::FASTEST_TILE.0.into(), "FASTEST_TILE" , "FastestTile" ), |
| 22977 | (Self::FASTEST_STIPPLE.0.into(), "FASTEST_STIPPLE" , "FastestStipple" ), |
| 22978 | ]; |
| 22979 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 22980 | } |
| 22981 | } |
| 22982 | |
| 22983 | /// Opcode for the QueryBestSize request |
| 22984 | pub const QUERY_BEST_SIZE_REQUEST: u8 = 97; |
| 22985 | #[derive (Clone, Copy, Default)] |
| 22986 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 22987 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 22988 | pub struct QueryBestSizeRequest { |
| 22989 | pub class: QueryShapeOf, |
| 22990 | pub drawable: Drawable, |
| 22991 | pub width: u16, |
| 22992 | pub height: u16, |
| 22993 | } |
| 22994 | impl_debug_if_no_extra_traits!(QueryBestSizeRequest, "QueryBestSizeRequest" ); |
| 22995 | impl QueryBestSizeRequest { |
| 22996 | /// Serialize this request into bytes for the provided connection |
| 22997 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 22998 | let length_so_far = 0; |
| 22999 | let class_bytes = u8::from(self.class).serialize(); |
| 23000 | let drawable_bytes = self.drawable.serialize(); |
| 23001 | let width_bytes = self.width.serialize(); |
| 23002 | let height_bytes = self.height.serialize(); |
| 23003 | let mut request0 = vec![ |
| 23004 | QUERY_BEST_SIZE_REQUEST, |
| 23005 | class_bytes[0], |
| 23006 | 0, |
| 23007 | 0, |
| 23008 | drawable_bytes[0], |
| 23009 | drawable_bytes[1], |
| 23010 | drawable_bytes[2], |
| 23011 | drawable_bytes[3], |
| 23012 | width_bytes[0], |
| 23013 | width_bytes[1], |
| 23014 | height_bytes[0], |
| 23015 | height_bytes[1], |
| 23016 | ]; |
| 23017 | let length_so_far = length_so_far + request0.len(); |
| 23018 | assert_eq!(length_so_far % 4, 0); |
| 23019 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 23020 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 23021 | ([request0.into()], vec![]) |
| 23022 | } |
| 23023 | /// Parse this request given its header, its body, and any fds that go along with it |
| 23024 | #[cfg (feature = "request-parsing" )] |
| 23025 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 23026 | if header.major_opcode != QUERY_BEST_SIZE_REQUEST { |
| 23027 | return Err(ParseError::InvalidValue); |
| 23028 | } |
| 23029 | let remaining = &[header.minor_opcode]; |
| 23030 | let (class, remaining) = u8::try_parse(remaining)?; |
| 23031 | let class = class.into(); |
| 23032 | let _ = remaining; |
| 23033 | let (drawable, remaining) = Drawable::try_parse(value)?; |
| 23034 | let (width, remaining) = u16::try_parse(remaining)?; |
| 23035 | let (height, remaining) = u16::try_parse(remaining)?; |
| 23036 | let _ = remaining; |
| 23037 | Ok(QueryBestSizeRequest { |
| 23038 | class, |
| 23039 | drawable, |
| 23040 | width, |
| 23041 | height, |
| 23042 | }) |
| 23043 | } |
| 23044 | } |
| 23045 | impl Request for QueryBestSizeRequest { |
| 23046 | const EXTENSION_NAME: Option<&'static str> = None; |
| 23047 | |
| 23048 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 23049 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 23050 | // Flatten the buffers into a single vector |
| 23051 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 23052 | (buf, fds) |
| 23053 | } |
| 23054 | } |
| 23055 | impl crate::x11_utils::ReplyRequest for QueryBestSizeRequest { |
| 23056 | type Reply = QueryBestSizeReply; |
| 23057 | } |
| 23058 | |
| 23059 | #[derive (Clone, Copy, Default)] |
| 23060 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 23061 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 23062 | pub struct QueryBestSizeReply { |
| 23063 | pub sequence: u16, |
| 23064 | pub length: u32, |
| 23065 | pub width: u16, |
| 23066 | pub height: u16, |
| 23067 | } |
| 23068 | impl_debug_if_no_extra_traits!(QueryBestSizeReply, "QueryBestSizeReply" ); |
| 23069 | impl TryParse for QueryBestSizeReply { |
| 23070 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 23071 | let remaining: &[u8] = initial_value; |
| 23072 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 23073 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 23074 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 23075 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 23076 | let (width: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 23077 | let (height: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 23078 | if response_type != 1 { |
| 23079 | return Err(ParseError::InvalidValue); |
| 23080 | } |
| 23081 | let result: QueryBestSizeReply = QueryBestSizeReply { sequence, length, width, height }; |
| 23082 | let _ = remaining; |
| 23083 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 23084 | .ok_or(err:ParseError::InsufficientData)?; |
| 23085 | Ok((result, remaining)) |
| 23086 | } |
| 23087 | } |
| 23088 | impl Serialize for QueryBestSizeReply { |
| 23089 | type Bytes = [u8; 12]; |
| 23090 | fn serialize(&self) -> [u8; 12] { |
| 23091 | let response_type_bytes = &[1]; |
| 23092 | let sequence_bytes = self.sequence.serialize(); |
| 23093 | let length_bytes = self.length.serialize(); |
| 23094 | let width_bytes = self.width.serialize(); |
| 23095 | let height_bytes = self.height.serialize(); |
| 23096 | [ |
| 23097 | response_type_bytes[0], |
| 23098 | 0, |
| 23099 | sequence_bytes[0], |
| 23100 | sequence_bytes[1], |
| 23101 | length_bytes[0], |
| 23102 | length_bytes[1], |
| 23103 | length_bytes[2], |
| 23104 | length_bytes[3], |
| 23105 | width_bytes[0], |
| 23106 | width_bytes[1], |
| 23107 | height_bytes[0], |
| 23108 | height_bytes[1], |
| 23109 | ] |
| 23110 | } |
| 23111 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 23112 | bytes.reserve(12); |
| 23113 | let response_type_bytes = &[1]; |
| 23114 | bytes.push(response_type_bytes[0]); |
| 23115 | bytes.extend_from_slice(&[0; 1]); |
| 23116 | self.sequence.serialize_into(bytes); |
| 23117 | self.length.serialize_into(bytes); |
| 23118 | self.width.serialize_into(bytes); |
| 23119 | self.height.serialize_into(bytes); |
| 23120 | } |
| 23121 | } |
| 23122 | |
| 23123 | /// Opcode for the QueryExtension request |
| 23124 | pub const QUERY_EXTENSION_REQUEST: u8 = 98; |
| 23125 | /// check if extension is present. |
| 23126 | /// |
| 23127 | /// Determines if the specified extension is present on this X11 server. |
| 23128 | /// |
| 23129 | /// Every extension has a unique `major_opcode` to identify requests, the minor |
| 23130 | /// opcodes and request formats are extension-specific. If the extension provides |
| 23131 | /// events and errors, the `first_event` and `first_error` fields in the reply are |
| 23132 | /// set accordingly. |
| 23133 | /// |
| 23134 | /// There should rarely be a need to use this request directly, XCB provides the |
| 23135 | /// `xcb_get_extension_data` function instead. |
| 23136 | /// |
| 23137 | /// # Fields |
| 23138 | /// |
| 23139 | /// * `name` - The name of the extension to query, for example "RANDR". This is case |
| 23140 | /// sensitive! |
| 23141 | /// |
| 23142 | /// # See |
| 23143 | /// |
| 23144 | /// * `xdpyinfo`: program |
| 23145 | /// * `xcb_get_extension_data`: function |
| 23146 | #[derive (Clone, Default)] |
| 23147 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 23148 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 23149 | pub struct QueryExtensionRequest<'input> { |
| 23150 | pub name: Cow<'input, [u8]>, |
| 23151 | } |
| 23152 | impl_debug_if_no_extra_traits!(QueryExtensionRequest<'_>, "QueryExtensionRequest" ); |
| 23153 | impl<'input> QueryExtensionRequest<'input> { |
| 23154 | /// Serialize this request into bytes for the provided connection |
| 23155 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 23156 | let length_so_far = 0; |
| 23157 | let name_len = u16::try_from(self.name.len()).expect("`name` has too many elements" ); |
| 23158 | let name_len_bytes = name_len.serialize(); |
| 23159 | let mut request0 = vec![ |
| 23160 | QUERY_EXTENSION_REQUEST, |
| 23161 | 0, |
| 23162 | 0, |
| 23163 | 0, |
| 23164 | name_len_bytes[0], |
| 23165 | name_len_bytes[1], |
| 23166 | 0, |
| 23167 | 0, |
| 23168 | ]; |
| 23169 | let length_so_far = length_so_far + request0.len(); |
| 23170 | let length_so_far = length_so_far + self.name.len(); |
| 23171 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 23172 | let length_so_far = length_so_far + padding0.len(); |
| 23173 | assert_eq!(length_so_far % 4, 0); |
| 23174 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 23175 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 23176 | ([request0.into(), self.name, padding0.into()], vec![]) |
| 23177 | } |
| 23178 | /// Parse this request given its header, its body, and any fds that go along with it |
| 23179 | #[cfg (feature = "request-parsing" )] |
| 23180 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 23181 | if header.major_opcode != QUERY_EXTENSION_REQUEST { |
| 23182 | return Err(ParseError::InvalidValue); |
| 23183 | } |
| 23184 | let remaining = &[header.minor_opcode]; |
| 23185 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 23186 | let _ = remaining; |
| 23187 | let (name_len, remaining) = u16::try_parse(value)?; |
| 23188 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 23189 | let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; |
| 23190 | let _ = remaining; |
| 23191 | Ok(QueryExtensionRequest { |
| 23192 | name: Cow::Borrowed(name), |
| 23193 | }) |
| 23194 | } |
| 23195 | /// Clone all borrowed data in this QueryExtensionRequest. |
| 23196 | pub fn into_owned(self) -> QueryExtensionRequest<'static> { |
| 23197 | QueryExtensionRequest { |
| 23198 | name: Cow::Owned(self.name.into_owned()), |
| 23199 | } |
| 23200 | } |
| 23201 | } |
| 23202 | impl<'input> Request for QueryExtensionRequest<'input> { |
| 23203 | const EXTENSION_NAME: Option<&'static str> = None; |
| 23204 | |
| 23205 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 23206 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 23207 | // Flatten the buffers into a single vector |
| 23208 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 23209 | (buf, fds) |
| 23210 | } |
| 23211 | } |
| 23212 | impl<'input> crate::x11_utils::ReplyRequest for QueryExtensionRequest<'input> { |
| 23213 | type Reply = QueryExtensionReply; |
| 23214 | } |
| 23215 | |
| 23216 | /// # Fields |
| 23217 | /// |
| 23218 | /// * `present` - Whether the extension is present on this X11 server. |
| 23219 | /// * `major_opcode` - The major opcode for requests. |
| 23220 | /// * `first_event` - The first event code, if any. |
| 23221 | /// * `first_error` - The first error code, if any. |
| 23222 | #[derive (Clone, Copy, Default)] |
| 23223 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 23224 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 23225 | pub struct QueryExtensionReply { |
| 23226 | pub sequence: u16, |
| 23227 | pub length: u32, |
| 23228 | pub present: bool, |
| 23229 | pub major_opcode: u8, |
| 23230 | pub first_event: u8, |
| 23231 | pub first_error: u8, |
| 23232 | } |
| 23233 | impl_debug_if_no_extra_traits!(QueryExtensionReply, "QueryExtensionReply" ); |
| 23234 | impl TryParse for QueryExtensionReply { |
| 23235 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 23236 | let remaining: &[u8] = initial_value; |
| 23237 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 23238 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 23239 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 23240 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 23241 | let (present: bool, remaining: &[u8]) = bool::try_parse(remaining)?; |
| 23242 | let (major_opcode: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 23243 | let (first_event: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 23244 | let (first_error: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 23245 | if response_type != 1 { |
| 23246 | return Err(ParseError::InvalidValue); |
| 23247 | } |
| 23248 | let result: QueryExtensionReply = QueryExtensionReply { sequence, length, present, major_opcode, first_event, first_error }; |
| 23249 | let _ = remaining; |
| 23250 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 23251 | .ok_or(err:ParseError::InsufficientData)?; |
| 23252 | Ok((result, remaining)) |
| 23253 | } |
| 23254 | } |
| 23255 | impl Serialize for QueryExtensionReply { |
| 23256 | type Bytes = [u8; 12]; |
| 23257 | fn serialize(&self) -> [u8; 12] { |
| 23258 | let response_type_bytes = &[1]; |
| 23259 | let sequence_bytes = self.sequence.serialize(); |
| 23260 | let length_bytes = self.length.serialize(); |
| 23261 | let present_bytes = self.present.serialize(); |
| 23262 | let major_opcode_bytes = self.major_opcode.serialize(); |
| 23263 | let first_event_bytes = self.first_event.serialize(); |
| 23264 | let first_error_bytes = self.first_error.serialize(); |
| 23265 | [ |
| 23266 | response_type_bytes[0], |
| 23267 | 0, |
| 23268 | sequence_bytes[0], |
| 23269 | sequence_bytes[1], |
| 23270 | length_bytes[0], |
| 23271 | length_bytes[1], |
| 23272 | length_bytes[2], |
| 23273 | length_bytes[3], |
| 23274 | present_bytes[0], |
| 23275 | major_opcode_bytes[0], |
| 23276 | first_event_bytes[0], |
| 23277 | first_error_bytes[0], |
| 23278 | ] |
| 23279 | } |
| 23280 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 23281 | bytes.reserve(12); |
| 23282 | let response_type_bytes = &[1]; |
| 23283 | bytes.push(response_type_bytes[0]); |
| 23284 | bytes.extend_from_slice(&[0; 1]); |
| 23285 | self.sequence.serialize_into(bytes); |
| 23286 | self.length.serialize_into(bytes); |
| 23287 | self.present.serialize_into(bytes); |
| 23288 | self.major_opcode.serialize_into(bytes); |
| 23289 | self.first_event.serialize_into(bytes); |
| 23290 | self.first_error.serialize_into(bytes); |
| 23291 | } |
| 23292 | } |
| 23293 | |
| 23294 | /// Opcode for the ListExtensions request |
| 23295 | pub const LIST_EXTENSIONS_REQUEST: u8 = 99; |
| 23296 | #[derive (Clone, Copy, Default)] |
| 23297 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 23298 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 23299 | pub struct ListExtensionsRequest; |
| 23300 | impl_debug_if_no_extra_traits!(ListExtensionsRequest, "ListExtensionsRequest" ); |
| 23301 | impl ListExtensionsRequest { |
| 23302 | /// Serialize this request into bytes for the provided connection |
| 23303 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 23304 | let length_so_far = 0; |
| 23305 | let mut request0 = vec![ |
| 23306 | LIST_EXTENSIONS_REQUEST, |
| 23307 | 0, |
| 23308 | 0, |
| 23309 | 0, |
| 23310 | ]; |
| 23311 | let length_so_far = length_so_far + request0.len(); |
| 23312 | assert_eq!(length_so_far % 4, 0); |
| 23313 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 23314 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 23315 | ([request0.into()], vec![]) |
| 23316 | } |
| 23317 | /// Parse this request given its header, its body, and any fds that go along with it |
| 23318 | #[cfg (feature = "request-parsing" )] |
| 23319 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 23320 | if header.major_opcode != LIST_EXTENSIONS_REQUEST { |
| 23321 | return Err(ParseError::InvalidValue); |
| 23322 | } |
| 23323 | let remaining = &[header.minor_opcode]; |
| 23324 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 23325 | let _ = remaining; |
| 23326 | let _ = value; |
| 23327 | Ok(ListExtensionsRequest |
| 23328 | ) |
| 23329 | } |
| 23330 | } |
| 23331 | impl Request for ListExtensionsRequest { |
| 23332 | const EXTENSION_NAME: Option<&'static str> = None; |
| 23333 | |
| 23334 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 23335 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 23336 | // Flatten the buffers into a single vector |
| 23337 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 23338 | (buf, fds) |
| 23339 | } |
| 23340 | } |
| 23341 | impl crate::x11_utils::ReplyRequest for ListExtensionsRequest { |
| 23342 | type Reply = ListExtensionsReply; |
| 23343 | } |
| 23344 | |
| 23345 | #[derive (Clone, Default)] |
| 23346 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 23347 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 23348 | pub struct ListExtensionsReply { |
| 23349 | pub sequence: u16, |
| 23350 | pub length: u32, |
| 23351 | pub names: Vec<Str>, |
| 23352 | } |
| 23353 | impl_debug_if_no_extra_traits!(ListExtensionsReply, "ListExtensionsReply" ); |
| 23354 | impl TryParse for ListExtensionsReply { |
| 23355 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 23356 | let remaining: &[u8] = initial_value; |
| 23357 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 23358 | let (names_len: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 23359 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 23360 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 23361 | let remaining: &[u8] = remaining.get(24..).ok_or(err:ParseError::InsufficientData)?; |
| 23362 | let (names: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<Str>(data:remaining, list_length:names_len.try_to_usize()?)?; |
| 23363 | if response_type != 1 { |
| 23364 | return Err(ParseError::InvalidValue); |
| 23365 | } |
| 23366 | let result: ListExtensionsReply = ListExtensionsReply { sequence, length, names }; |
| 23367 | let _ = remaining; |
| 23368 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 23369 | .ok_or(err:ParseError::InsufficientData)?; |
| 23370 | Ok((result, remaining)) |
| 23371 | } |
| 23372 | } |
| 23373 | impl Serialize for ListExtensionsReply { |
| 23374 | type Bytes = Vec<u8>; |
| 23375 | fn serialize(&self) -> Vec<u8> { |
| 23376 | let mut result: Vec = Vec::new(); |
| 23377 | self.serialize_into(&mut result); |
| 23378 | result |
| 23379 | } |
| 23380 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 23381 | bytes.reserve(additional:32); |
| 23382 | let response_type_bytes: &[u8; 1] = &[1]; |
| 23383 | bytes.push(response_type_bytes[0]); |
| 23384 | let names_len: u8 = u8::try_from(self.names.len()).expect(msg:"`names` has too many elements" ); |
| 23385 | names_len.serialize_into(bytes); |
| 23386 | self.sequence.serialize_into(bytes); |
| 23387 | self.length.serialize_into(bytes); |
| 23388 | bytes.extend_from_slice(&[0; 24]); |
| 23389 | self.names.serialize_into(bytes); |
| 23390 | } |
| 23391 | } |
| 23392 | impl ListExtensionsReply { |
| 23393 | /// Get the value of the `names_len` field. |
| 23394 | /// |
| 23395 | /// The `names_len` field is used as the length field of the `names` field. |
| 23396 | /// This function computes the field's value again based on the length of the list. |
| 23397 | /// |
| 23398 | /// # Panics |
| 23399 | /// |
| 23400 | /// Panics if the value cannot be represented in the target type. This |
| 23401 | /// cannot happen with values of the struct received from the X11 server. |
| 23402 | pub fn names_len(&self) -> u8 { |
| 23403 | self.names.len() |
| 23404 | .try_into().unwrap() |
| 23405 | } |
| 23406 | } |
| 23407 | |
| 23408 | /// Opcode for the ChangeKeyboardMapping request |
| 23409 | pub const CHANGE_KEYBOARD_MAPPING_REQUEST: u8 = 100; |
| 23410 | #[derive (Clone, Default)] |
| 23411 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 23412 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 23413 | pub struct ChangeKeyboardMappingRequest<'input> { |
| 23414 | pub keycode_count: u8, |
| 23415 | pub first_keycode: Keycode, |
| 23416 | pub keysyms_per_keycode: u8, |
| 23417 | pub keysyms: Cow<'input, [Keysym]>, |
| 23418 | } |
| 23419 | impl_debug_if_no_extra_traits!(ChangeKeyboardMappingRequest<'_>, "ChangeKeyboardMappingRequest" ); |
| 23420 | impl<'input> ChangeKeyboardMappingRequest<'input> { |
| 23421 | /// Serialize this request into bytes for the provided connection |
| 23422 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 23423 | let length_so_far = 0; |
| 23424 | let keycode_count_bytes = self.keycode_count.serialize(); |
| 23425 | let first_keycode_bytes = self.first_keycode.serialize(); |
| 23426 | let keysyms_per_keycode_bytes = self.keysyms_per_keycode.serialize(); |
| 23427 | let mut request0 = vec![ |
| 23428 | CHANGE_KEYBOARD_MAPPING_REQUEST, |
| 23429 | keycode_count_bytes[0], |
| 23430 | 0, |
| 23431 | 0, |
| 23432 | first_keycode_bytes[0], |
| 23433 | keysyms_per_keycode_bytes[0], |
| 23434 | 0, |
| 23435 | 0, |
| 23436 | ]; |
| 23437 | let length_so_far = length_so_far + request0.len(); |
| 23438 | assert_eq!(self.keysyms.len(), usize::try_from(u32::from(self.keycode_count).checked_mul(u32::from(self.keysyms_per_keycode)).unwrap()).unwrap(), "`keysyms` has an incorrect length" ); |
| 23439 | let keysyms_bytes = self.keysyms.serialize(); |
| 23440 | let length_so_far = length_so_far + keysyms_bytes.len(); |
| 23441 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 23442 | let length_so_far = length_so_far + padding0.len(); |
| 23443 | assert_eq!(length_so_far % 4, 0); |
| 23444 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 23445 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 23446 | ([request0.into(), keysyms_bytes.into(), padding0.into()], vec![]) |
| 23447 | } |
| 23448 | /// Parse this request given its header, its body, and any fds that go along with it |
| 23449 | #[cfg (feature = "request-parsing" )] |
| 23450 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 23451 | if header.major_opcode != CHANGE_KEYBOARD_MAPPING_REQUEST { |
| 23452 | return Err(ParseError::InvalidValue); |
| 23453 | } |
| 23454 | let remaining = &[header.minor_opcode]; |
| 23455 | let (keycode_count, remaining) = u8::try_parse(remaining)?; |
| 23456 | let _ = remaining; |
| 23457 | let (first_keycode, remaining) = Keycode::try_parse(value)?; |
| 23458 | let (keysyms_per_keycode, remaining) = u8::try_parse(remaining)?; |
| 23459 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 23460 | let (keysyms, remaining) = crate::x11_utils::parse_list::<Keysym>(remaining, u32::from(keycode_count).checked_mul(u32::from(keysyms_per_keycode)).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; |
| 23461 | let _ = remaining; |
| 23462 | Ok(ChangeKeyboardMappingRequest { |
| 23463 | keycode_count, |
| 23464 | first_keycode, |
| 23465 | keysyms_per_keycode, |
| 23466 | keysyms: Cow::Owned(keysyms), |
| 23467 | }) |
| 23468 | } |
| 23469 | /// Clone all borrowed data in this ChangeKeyboardMappingRequest. |
| 23470 | pub fn into_owned(self) -> ChangeKeyboardMappingRequest<'static> { |
| 23471 | ChangeKeyboardMappingRequest { |
| 23472 | keycode_count: self.keycode_count, |
| 23473 | first_keycode: self.first_keycode, |
| 23474 | keysyms_per_keycode: self.keysyms_per_keycode, |
| 23475 | keysyms: Cow::Owned(self.keysyms.into_owned()), |
| 23476 | } |
| 23477 | } |
| 23478 | } |
| 23479 | impl<'input> Request for ChangeKeyboardMappingRequest<'input> { |
| 23480 | const EXTENSION_NAME: Option<&'static str> = None; |
| 23481 | |
| 23482 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 23483 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 23484 | // Flatten the buffers into a single vector |
| 23485 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 23486 | (buf, fds) |
| 23487 | } |
| 23488 | } |
| 23489 | impl<'input> crate::x11_utils::VoidRequest for ChangeKeyboardMappingRequest<'input> { |
| 23490 | } |
| 23491 | |
| 23492 | /// Opcode for the GetKeyboardMapping request |
| 23493 | pub const GET_KEYBOARD_MAPPING_REQUEST: u8 = 101; |
| 23494 | #[derive (Clone, Copy, Default)] |
| 23495 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 23496 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 23497 | pub struct GetKeyboardMappingRequest { |
| 23498 | pub first_keycode: Keycode, |
| 23499 | pub count: u8, |
| 23500 | } |
| 23501 | impl_debug_if_no_extra_traits!(GetKeyboardMappingRequest, "GetKeyboardMappingRequest" ); |
| 23502 | impl GetKeyboardMappingRequest { |
| 23503 | /// Serialize this request into bytes for the provided connection |
| 23504 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 23505 | let length_so_far = 0; |
| 23506 | let first_keycode_bytes = self.first_keycode.serialize(); |
| 23507 | let count_bytes = self.count.serialize(); |
| 23508 | let mut request0 = vec![ |
| 23509 | GET_KEYBOARD_MAPPING_REQUEST, |
| 23510 | 0, |
| 23511 | 0, |
| 23512 | 0, |
| 23513 | first_keycode_bytes[0], |
| 23514 | count_bytes[0], |
| 23515 | 0, |
| 23516 | 0, |
| 23517 | ]; |
| 23518 | let length_so_far = length_so_far + request0.len(); |
| 23519 | assert_eq!(length_so_far % 4, 0); |
| 23520 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 23521 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 23522 | ([request0.into()], vec![]) |
| 23523 | } |
| 23524 | /// Parse this request given its header, its body, and any fds that go along with it |
| 23525 | #[cfg (feature = "request-parsing" )] |
| 23526 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 23527 | if header.major_opcode != GET_KEYBOARD_MAPPING_REQUEST { |
| 23528 | return Err(ParseError::InvalidValue); |
| 23529 | } |
| 23530 | let remaining = &[header.minor_opcode]; |
| 23531 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 23532 | let _ = remaining; |
| 23533 | let (first_keycode, remaining) = Keycode::try_parse(value)?; |
| 23534 | let (count, remaining) = u8::try_parse(remaining)?; |
| 23535 | let _ = remaining; |
| 23536 | Ok(GetKeyboardMappingRequest { |
| 23537 | first_keycode, |
| 23538 | count, |
| 23539 | }) |
| 23540 | } |
| 23541 | } |
| 23542 | impl Request for GetKeyboardMappingRequest { |
| 23543 | const EXTENSION_NAME: Option<&'static str> = None; |
| 23544 | |
| 23545 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 23546 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 23547 | // Flatten the buffers into a single vector |
| 23548 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 23549 | (buf, fds) |
| 23550 | } |
| 23551 | } |
| 23552 | impl crate::x11_utils::ReplyRequest for GetKeyboardMappingRequest { |
| 23553 | type Reply = GetKeyboardMappingReply; |
| 23554 | } |
| 23555 | |
| 23556 | #[derive (Clone, Default)] |
| 23557 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 23558 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 23559 | pub struct GetKeyboardMappingReply { |
| 23560 | pub keysyms_per_keycode: u8, |
| 23561 | pub sequence: u16, |
| 23562 | pub keysyms: Vec<Keysym>, |
| 23563 | } |
| 23564 | impl_debug_if_no_extra_traits!(GetKeyboardMappingReply, "GetKeyboardMappingReply" ); |
| 23565 | impl TryParse for GetKeyboardMappingReply { |
| 23566 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 23567 | let remaining: &[u8] = initial_value; |
| 23568 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 23569 | let (keysyms_per_keycode: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 23570 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 23571 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 23572 | let remaining: &[u8] = remaining.get(24..).ok_or(err:ParseError::InsufficientData)?; |
| 23573 | let (keysyms: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<Keysym>(data:remaining, list_length:length.try_to_usize()?)?; |
| 23574 | if response_type != 1 { |
| 23575 | return Err(ParseError::InvalidValue); |
| 23576 | } |
| 23577 | let result: GetKeyboardMappingReply = GetKeyboardMappingReply { keysyms_per_keycode, sequence, keysyms }; |
| 23578 | let _ = remaining; |
| 23579 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 23580 | .ok_or(err:ParseError::InsufficientData)?; |
| 23581 | Ok((result, remaining)) |
| 23582 | } |
| 23583 | } |
| 23584 | impl Serialize for GetKeyboardMappingReply { |
| 23585 | type Bytes = Vec<u8>; |
| 23586 | fn serialize(&self) -> Vec<u8> { |
| 23587 | let mut result: Vec = Vec::new(); |
| 23588 | self.serialize_into(&mut result); |
| 23589 | result |
| 23590 | } |
| 23591 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 23592 | bytes.reserve(additional:32); |
| 23593 | let response_type_bytes: &[u8; 1] = &[1]; |
| 23594 | bytes.push(response_type_bytes[0]); |
| 23595 | self.keysyms_per_keycode.serialize_into(bytes); |
| 23596 | self.sequence.serialize_into(bytes); |
| 23597 | let length: u32 = u32::try_from(self.keysyms.len()).expect(msg:"`keysyms` has too many elements" ); |
| 23598 | length.serialize_into(bytes); |
| 23599 | bytes.extend_from_slice(&[0; 24]); |
| 23600 | self.keysyms.serialize_into(bytes); |
| 23601 | } |
| 23602 | } |
| 23603 | impl GetKeyboardMappingReply { |
| 23604 | /// Get the value of the `length` field. |
| 23605 | /// |
| 23606 | /// The `length` field is used as the length field of the `keysyms` field. |
| 23607 | /// This function computes the field's value again based on the length of the list. |
| 23608 | /// |
| 23609 | /// # Panics |
| 23610 | /// |
| 23611 | /// Panics if the value cannot be represented in the target type. This |
| 23612 | /// cannot happen with values of the struct received from the X11 server. |
| 23613 | pub fn length(&self) -> u32 { |
| 23614 | self.keysyms.len() |
| 23615 | .try_into().unwrap() |
| 23616 | } |
| 23617 | } |
| 23618 | |
| 23619 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 23620 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 23621 | pub struct KB(u32); |
| 23622 | impl KB { |
| 23623 | pub const KEY_CLICK_PERCENT: Self = Self(1 << 0); |
| 23624 | pub const BELL_PERCENT: Self = Self(1 << 1); |
| 23625 | pub const BELL_PITCH: Self = Self(1 << 2); |
| 23626 | pub const BELL_DURATION: Self = Self(1 << 3); |
| 23627 | pub const LED: Self = Self(1 << 4); |
| 23628 | pub const LED_MODE: Self = Self(1 << 5); |
| 23629 | pub const KEY: Self = Self(1 << 6); |
| 23630 | pub const AUTO_REPEAT_MODE: Self = Self(1 << 7); |
| 23631 | } |
| 23632 | impl From<KB> for u32 { |
| 23633 | #[inline ] |
| 23634 | fn from(input: KB) -> Self { |
| 23635 | input.0 |
| 23636 | } |
| 23637 | } |
| 23638 | impl From<KB> for Option<u32> { |
| 23639 | #[inline ] |
| 23640 | fn from(input: KB) -> Self { |
| 23641 | Some(input.0) |
| 23642 | } |
| 23643 | } |
| 23644 | impl From<u8> for KB { |
| 23645 | #[inline ] |
| 23646 | fn from(value: u8) -> Self { |
| 23647 | Self(value.into()) |
| 23648 | } |
| 23649 | } |
| 23650 | impl From<u16> for KB { |
| 23651 | #[inline ] |
| 23652 | fn from(value: u16) -> Self { |
| 23653 | Self(value.into()) |
| 23654 | } |
| 23655 | } |
| 23656 | impl From<u32> for KB { |
| 23657 | #[inline ] |
| 23658 | fn from(value: u32) -> Self { |
| 23659 | Self(value) |
| 23660 | } |
| 23661 | } |
| 23662 | impl core::fmt::Debug for KB { |
| 23663 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 23664 | let variants: [(u32, &'static str, &'static …); 8] = [ |
| 23665 | (Self::KEY_CLICK_PERCENT.0, "KEY_CLICK_PERCENT" , "KeyClickPercent" ), |
| 23666 | (Self::BELL_PERCENT.0, "BELL_PERCENT" , "BellPercent" ), |
| 23667 | (Self::BELL_PITCH.0, "BELL_PITCH" , "BellPitch" ), |
| 23668 | (Self::BELL_DURATION.0, "BELL_DURATION" , "BellDuration" ), |
| 23669 | (Self::LED.0, "LED" , "Led" ), |
| 23670 | (Self::LED_MODE.0, "LED_MODE" , "LedMode" ), |
| 23671 | (Self::KEY.0, "KEY" , "Key" ), |
| 23672 | (Self::AUTO_REPEAT_MODE.0, "AUTO_REPEAT_MODE" , "AutoRepeatMode" ), |
| 23673 | ]; |
| 23674 | pretty_print_bitmask(fmt, self.0, &variants) |
| 23675 | } |
| 23676 | } |
| 23677 | bitmask_binop!(KB, u32); |
| 23678 | |
| 23679 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 23680 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 23681 | pub struct LedMode(u32); |
| 23682 | impl LedMode { |
| 23683 | pub const OFF: Self = Self(0); |
| 23684 | pub const ON: Self = Self(1); |
| 23685 | } |
| 23686 | impl From<LedMode> for u32 { |
| 23687 | #[inline ] |
| 23688 | fn from(input: LedMode) -> Self { |
| 23689 | input.0 |
| 23690 | } |
| 23691 | } |
| 23692 | impl From<LedMode> for Option<u32> { |
| 23693 | #[inline ] |
| 23694 | fn from(input: LedMode) -> Self { |
| 23695 | Some(input.0) |
| 23696 | } |
| 23697 | } |
| 23698 | impl From<u8> for LedMode { |
| 23699 | #[inline ] |
| 23700 | fn from(value: u8) -> Self { |
| 23701 | Self(value.into()) |
| 23702 | } |
| 23703 | } |
| 23704 | impl From<u16> for LedMode { |
| 23705 | #[inline ] |
| 23706 | fn from(value: u16) -> Self { |
| 23707 | Self(value.into()) |
| 23708 | } |
| 23709 | } |
| 23710 | impl From<u32> for LedMode { |
| 23711 | #[inline ] |
| 23712 | fn from(value: u32) -> Self { |
| 23713 | Self(value) |
| 23714 | } |
| 23715 | } |
| 23716 | impl core::fmt::Debug for LedMode { |
| 23717 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 23718 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 23719 | (Self::OFF.0, "OFF" , "Off" ), |
| 23720 | (Self::ON.0, "ON" , "On" ), |
| 23721 | ]; |
| 23722 | pretty_print_enum(fmt, self.0, &variants) |
| 23723 | } |
| 23724 | } |
| 23725 | |
| 23726 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 23727 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 23728 | pub struct AutoRepeatMode(u32); |
| 23729 | impl AutoRepeatMode { |
| 23730 | pub const OFF: Self = Self(0); |
| 23731 | pub const ON: Self = Self(1); |
| 23732 | pub const DEFAULT: Self = Self(2); |
| 23733 | } |
| 23734 | impl From<AutoRepeatMode> for u32 { |
| 23735 | #[inline ] |
| 23736 | fn from(input: AutoRepeatMode) -> Self { |
| 23737 | input.0 |
| 23738 | } |
| 23739 | } |
| 23740 | impl From<AutoRepeatMode> for Option<u32> { |
| 23741 | #[inline ] |
| 23742 | fn from(input: AutoRepeatMode) -> Self { |
| 23743 | Some(input.0) |
| 23744 | } |
| 23745 | } |
| 23746 | impl From<u8> for AutoRepeatMode { |
| 23747 | #[inline ] |
| 23748 | fn from(value: u8) -> Self { |
| 23749 | Self(value.into()) |
| 23750 | } |
| 23751 | } |
| 23752 | impl From<u16> for AutoRepeatMode { |
| 23753 | #[inline ] |
| 23754 | fn from(value: u16) -> Self { |
| 23755 | Self(value.into()) |
| 23756 | } |
| 23757 | } |
| 23758 | impl From<u32> for AutoRepeatMode { |
| 23759 | #[inline ] |
| 23760 | fn from(value: u32) -> Self { |
| 23761 | Self(value) |
| 23762 | } |
| 23763 | } |
| 23764 | impl core::fmt::Debug for AutoRepeatMode { |
| 23765 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 23766 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 23767 | (Self::OFF.0, "OFF" , "Off" ), |
| 23768 | (Self::ON.0, "ON" , "On" ), |
| 23769 | (Self::DEFAULT.0, "DEFAULT" , "Default" ), |
| 23770 | ]; |
| 23771 | pretty_print_enum(fmt, self.0, &variants) |
| 23772 | } |
| 23773 | } |
| 23774 | |
| 23775 | /// Auxiliary and optional information for the `change_keyboard_control` function |
| 23776 | #[derive (Clone, Copy, Default)] |
| 23777 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 23778 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 23779 | pub struct ChangeKeyboardControlAux { |
| 23780 | pub key_click_percent: Option<i32>, |
| 23781 | pub bell_percent: Option<i32>, |
| 23782 | pub bell_pitch: Option<i32>, |
| 23783 | pub bell_duration: Option<i32>, |
| 23784 | pub led: Option<u32>, |
| 23785 | pub led_mode: Option<LedMode>, |
| 23786 | pub key: Option<Keycode32>, |
| 23787 | pub auto_repeat_mode: Option<AutoRepeatMode>, |
| 23788 | } |
| 23789 | impl_debug_if_no_extra_traits!(ChangeKeyboardControlAux, "ChangeKeyboardControlAux" ); |
| 23790 | impl ChangeKeyboardControlAux { |
| 23791 | #[cfg_attr (not(feature = "request-parsing" ), allow(dead_code))] |
| 23792 | fn try_parse(value: &[u8], value_mask: u32) -> Result<(Self, &[u8]), ParseError> { |
| 23793 | let switch_expr = u32::from(value_mask); |
| 23794 | let mut outer_remaining = value; |
| 23795 | let key_click_percent = if switch_expr & u32::from(KB::KEY_CLICK_PERCENT) != 0 { |
| 23796 | let remaining = outer_remaining; |
| 23797 | let (key_click_percent, remaining) = i32::try_parse(remaining)?; |
| 23798 | outer_remaining = remaining; |
| 23799 | Some(key_click_percent) |
| 23800 | } else { |
| 23801 | None |
| 23802 | }; |
| 23803 | let bell_percent = if switch_expr & u32::from(KB::BELL_PERCENT) != 0 { |
| 23804 | let remaining = outer_remaining; |
| 23805 | let (bell_percent, remaining) = i32::try_parse(remaining)?; |
| 23806 | outer_remaining = remaining; |
| 23807 | Some(bell_percent) |
| 23808 | } else { |
| 23809 | None |
| 23810 | }; |
| 23811 | let bell_pitch = if switch_expr & u32::from(KB::BELL_PITCH) != 0 { |
| 23812 | let remaining = outer_remaining; |
| 23813 | let (bell_pitch, remaining) = i32::try_parse(remaining)?; |
| 23814 | outer_remaining = remaining; |
| 23815 | Some(bell_pitch) |
| 23816 | } else { |
| 23817 | None |
| 23818 | }; |
| 23819 | let bell_duration = if switch_expr & u32::from(KB::BELL_DURATION) != 0 { |
| 23820 | let remaining = outer_remaining; |
| 23821 | let (bell_duration, remaining) = i32::try_parse(remaining)?; |
| 23822 | outer_remaining = remaining; |
| 23823 | Some(bell_duration) |
| 23824 | } else { |
| 23825 | None |
| 23826 | }; |
| 23827 | let led = if switch_expr & u32::from(KB::LED) != 0 { |
| 23828 | let remaining = outer_remaining; |
| 23829 | let (led, remaining) = u32::try_parse(remaining)?; |
| 23830 | outer_remaining = remaining; |
| 23831 | Some(led) |
| 23832 | } else { |
| 23833 | None |
| 23834 | }; |
| 23835 | let led_mode = if switch_expr & u32::from(KB::LED_MODE) != 0 { |
| 23836 | let remaining = outer_remaining; |
| 23837 | let (led_mode, remaining) = u32::try_parse(remaining)?; |
| 23838 | let led_mode = led_mode.into(); |
| 23839 | outer_remaining = remaining; |
| 23840 | Some(led_mode) |
| 23841 | } else { |
| 23842 | None |
| 23843 | }; |
| 23844 | let key = if switch_expr & u32::from(KB::KEY) != 0 { |
| 23845 | let remaining = outer_remaining; |
| 23846 | let (key, remaining) = Keycode32::try_parse(remaining)?; |
| 23847 | outer_remaining = remaining; |
| 23848 | Some(key) |
| 23849 | } else { |
| 23850 | None |
| 23851 | }; |
| 23852 | let auto_repeat_mode = if switch_expr & u32::from(KB::AUTO_REPEAT_MODE) != 0 { |
| 23853 | let remaining = outer_remaining; |
| 23854 | let (auto_repeat_mode, remaining) = u32::try_parse(remaining)?; |
| 23855 | let auto_repeat_mode = auto_repeat_mode.into(); |
| 23856 | outer_remaining = remaining; |
| 23857 | Some(auto_repeat_mode) |
| 23858 | } else { |
| 23859 | None |
| 23860 | }; |
| 23861 | let result = ChangeKeyboardControlAux { key_click_percent, bell_percent, bell_pitch, bell_duration, led, led_mode, key, auto_repeat_mode }; |
| 23862 | Ok((result, outer_remaining)) |
| 23863 | } |
| 23864 | } |
| 23865 | impl ChangeKeyboardControlAux { |
| 23866 | #[allow (dead_code)] |
| 23867 | fn serialize(&self, value_mask: u32) -> Vec<u8> { |
| 23868 | let mut result = Vec::new(); |
| 23869 | self.serialize_into(&mut result, u32::from(value_mask)); |
| 23870 | result |
| 23871 | } |
| 23872 | fn serialize_into(&self, bytes: &mut Vec<u8>, value_mask: u32) { |
| 23873 | assert_eq!(self.switch_expr(), u32::from(value_mask), "switch `value_list` has an inconsistent discriminant" ); |
| 23874 | if let Some(key_click_percent) = self.key_click_percent { |
| 23875 | key_click_percent.serialize_into(bytes); |
| 23876 | } |
| 23877 | if let Some(bell_percent) = self.bell_percent { |
| 23878 | bell_percent.serialize_into(bytes); |
| 23879 | } |
| 23880 | if let Some(bell_pitch) = self.bell_pitch { |
| 23881 | bell_pitch.serialize_into(bytes); |
| 23882 | } |
| 23883 | if let Some(bell_duration) = self.bell_duration { |
| 23884 | bell_duration.serialize_into(bytes); |
| 23885 | } |
| 23886 | if let Some(led) = self.led { |
| 23887 | led.serialize_into(bytes); |
| 23888 | } |
| 23889 | if let Some(led_mode) = self.led_mode { |
| 23890 | u32::from(led_mode).serialize_into(bytes); |
| 23891 | } |
| 23892 | if let Some(key) = self.key { |
| 23893 | key.serialize_into(bytes); |
| 23894 | } |
| 23895 | if let Some(auto_repeat_mode) = self.auto_repeat_mode { |
| 23896 | u32::from(auto_repeat_mode).serialize_into(bytes); |
| 23897 | } |
| 23898 | } |
| 23899 | } |
| 23900 | impl ChangeKeyboardControlAux { |
| 23901 | fn switch_expr(&self) -> u32 { |
| 23902 | let mut expr_value = 0; |
| 23903 | if self.key_click_percent.is_some() { |
| 23904 | expr_value |= u32::from(KB::KEY_CLICK_PERCENT); |
| 23905 | } |
| 23906 | if self.bell_percent.is_some() { |
| 23907 | expr_value |= u32::from(KB::BELL_PERCENT); |
| 23908 | } |
| 23909 | if self.bell_pitch.is_some() { |
| 23910 | expr_value |= u32::from(KB::BELL_PITCH); |
| 23911 | } |
| 23912 | if self.bell_duration.is_some() { |
| 23913 | expr_value |= u32::from(KB::BELL_DURATION); |
| 23914 | } |
| 23915 | if self.led.is_some() { |
| 23916 | expr_value |= u32::from(KB::LED); |
| 23917 | } |
| 23918 | if self.led_mode.is_some() { |
| 23919 | expr_value |= u32::from(KB::LED_MODE); |
| 23920 | } |
| 23921 | if self.key.is_some() { |
| 23922 | expr_value |= u32::from(KB::KEY); |
| 23923 | } |
| 23924 | if self.auto_repeat_mode.is_some() { |
| 23925 | expr_value |= u32::from(KB::AUTO_REPEAT_MODE); |
| 23926 | } |
| 23927 | expr_value |
| 23928 | } |
| 23929 | } |
| 23930 | impl ChangeKeyboardControlAux { |
| 23931 | /// Create a new instance with all fields unset / not present. |
| 23932 | pub fn new() -> Self { |
| 23933 | Default::default() |
| 23934 | } |
| 23935 | /// Set the `key_click_percent` field of this structure. |
| 23936 | #[must_use ] |
| 23937 | pub fn key_click_percent<I>(mut self, value: I) -> Self where I: Into<Option<i32>> { |
| 23938 | self.key_click_percent = value.into(); |
| 23939 | self |
| 23940 | } |
| 23941 | /// Set the `bell_percent` field of this structure. |
| 23942 | #[must_use ] |
| 23943 | pub fn bell_percent<I>(mut self, value: I) -> Self where I: Into<Option<i32>> { |
| 23944 | self.bell_percent = value.into(); |
| 23945 | self |
| 23946 | } |
| 23947 | /// Set the `bell_pitch` field of this structure. |
| 23948 | #[must_use ] |
| 23949 | pub fn bell_pitch<I>(mut self, value: I) -> Self where I: Into<Option<i32>> { |
| 23950 | self.bell_pitch = value.into(); |
| 23951 | self |
| 23952 | } |
| 23953 | /// Set the `bell_duration` field of this structure. |
| 23954 | #[must_use ] |
| 23955 | pub fn bell_duration<I>(mut self, value: I) -> Self where I: Into<Option<i32>> { |
| 23956 | self.bell_duration = value.into(); |
| 23957 | self |
| 23958 | } |
| 23959 | /// Set the `led` field of this structure. |
| 23960 | #[must_use ] |
| 23961 | pub fn led<I>(mut self, value: I) -> Self where I: Into<Option<u32>> { |
| 23962 | self.led = value.into(); |
| 23963 | self |
| 23964 | } |
| 23965 | /// Set the `led_mode` field of this structure. |
| 23966 | #[must_use ] |
| 23967 | pub fn led_mode<I>(mut self, value: I) -> Self where I: Into<Option<LedMode>> { |
| 23968 | self.led_mode = value.into(); |
| 23969 | self |
| 23970 | } |
| 23971 | /// Set the `key` field of this structure. |
| 23972 | #[must_use ] |
| 23973 | pub fn key<I>(mut self, value: I) -> Self where I: Into<Option<Keycode32>> { |
| 23974 | self.key = value.into(); |
| 23975 | self |
| 23976 | } |
| 23977 | /// Set the `auto_repeat_mode` field of this structure. |
| 23978 | #[must_use ] |
| 23979 | pub fn auto_repeat_mode<I>(mut self, value: I) -> Self where I: Into<Option<AutoRepeatMode>> { |
| 23980 | self.auto_repeat_mode = value.into(); |
| 23981 | self |
| 23982 | } |
| 23983 | } |
| 23984 | |
| 23985 | /// Opcode for the ChangeKeyboardControl request |
| 23986 | pub const CHANGE_KEYBOARD_CONTROL_REQUEST: u8 = 102; |
| 23987 | #[derive (Clone, Default)] |
| 23988 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 23989 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 23990 | pub struct ChangeKeyboardControlRequest<'input> { |
| 23991 | pub value_list: Cow<'input, ChangeKeyboardControlAux>, |
| 23992 | } |
| 23993 | impl_debug_if_no_extra_traits!(ChangeKeyboardControlRequest<'_>, "ChangeKeyboardControlRequest" ); |
| 23994 | impl<'input> ChangeKeyboardControlRequest<'input> { |
| 23995 | /// Serialize this request into bytes for the provided connection |
| 23996 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 23997 | let length_so_far = 0; |
| 23998 | let value_mask: u32 = self.value_list.switch_expr(); |
| 23999 | let value_mask_bytes = value_mask.serialize(); |
| 24000 | let mut request0 = vec![ |
| 24001 | CHANGE_KEYBOARD_CONTROL_REQUEST, |
| 24002 | 0, |
| 24003 | 0, |
| 24004 | 0, |
| 24005 | value_mask_bytes[0], |
| 24006 | value_mask_bytes[1], |
| 24007 | value_mask_bytes[2], |
| 24008 | value_mask_bytes[3], |
| 24009 | ]; |
| 24010 | let length_so_far = length_so_far + request0.len(); |
| 24011 | let value_list_bytes = self.value_list.serialize(u32::from(value_mask)); |
| 24012 | let length_so_far = length_so_far + value_list_bytes.len(); |
| 24013 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 24014 | let length_so_far = length_so_far + padding0.len(); |
| 24015 | assert_eq!(length_so_far % 4, 0); |
| 24016 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 24017 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 24018 | ([request0.into(), value_list_bytes.into(), padding0.into()], vec![]) |
| 24019 | } |
| 24020 | /// Parse this request given its header, its body, and any fds that go along with it |
| 24021 | #[cfg (feature = "request-parsing" )] |
| 24022 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 24023 | if header.major_opcode != CHANGE_KEYBOARD_CONTROL_REQUEST { |
| 24024 | return Err(ParseError::InvalidValue); |
| 24025 | } |
| 24026 | let remaining = &[header.minor_opcode]; |
| 24027 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 24028 | let _ = remaining; |
| 24029 | let (value_mask, remaining) = u32::try_parse(value)?; |
| 24030 | let (value_list, remaining) = ChangeKeyboardControlAux::try_parse(remaining, u32::from(value_mask))?; |
| 24031 | let _ = remaining; |
| 24032 | Ok(ChangeKeyboardControlRequest { |
| 24033 | value_list: Cow::Owned(value_list), |
| 24034 | }) |
| 24035 | } |
| 24036 | /// Clone all borrowed data in this ChangeKeyboardControlRequest. |
| 24037 | pub fn into_owned(self) -> ChangeKeyboardControlRequest<'static> { |
| 24038 | ChangeKeyboardControlRequest { |
| 24039 | value_list: Cow::Owned(self.value_list.into_owned()), |
| 24040 | } |
| 24041 | } |
| 24042 | } |
| 24043 | impl<'input> Request for ChangeKeyboardControlRequest<'input> { |
| 24044 | const EXTENSION_NAME: Option<&'static str> = None; |
| 24045 | |
| 24046 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 24047 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 24048 | // Flatten the buffers into a single vector |
| 24049 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 24050 | (buf, fds) |
| 24051 | } |
| 24052 | } |
| 24053 | impl<'input> crate::x11_utils::VoidRequest for ChangeKeyboardControlRequest<'input> { |
| 24054 | } |
| 24055 | |
| 24056 | /// Opcode for the GetKeyboardControl request |
| 24057 | pub const GET_KEYBOARD_CONTROL_REQUEST: u8 = 103; |
| 24058 | #[derive (Clone, Copy, Default)] |
| 24059 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 24060 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 24061 | pub struct GetKeyboardControlRequest; |
| 24062 | impl_debug_if_no_extra_traits!(GetKeyboardControlRequest, "GetKeyboardControlRequest" ); |
| 24063 | impl GetKeyboardControlRequest { |
| 24064 | /// Serialize this request into bytes for the provided connection |
| 24065 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 24066 | let length_so_far = 0; |
| 24067 | let mut request0 = vec![ |
| 24068 | GET_KEYBOARD_CONTROL_REQUEST, |
| 24069 | 0, |
| 24070 | 0, |
| 24071 | 0, |
| 24072 | ]; |
| 24073 | let length_so_far = length_so_far + request0.len(); |
| 24074 | assert_eq!(length_so_far % 4, 0); |
| 24075 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 24076 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 24077 | ([request0.into()], vec![]) |
| 24078 | } |
| 24079 | /// Parse this request given its header, its body, and any fds that go along with it |
| 24080 | #[cfg (feature = "request-parsing" )] |
| 24081 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 24082 | if header.major_opcode != GET_KEYBOARD_CONTROL_REQUEST { |
| 24083 | return Err(ParseError::InvalidValue); |
| 24084 | } |
| 24085 | let remaining = &[header.minor_opcode]; |
| 24086 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 24087 | let _ = remaining; |
| 24088 | let _ = value; |
| 24089 | Ok(GetKeyboardControlRequest |
| 24090 | ) |
| 24091 | } |
| 24092 | } |
| 24093 | impl Request for GetKeyboardControlRequest { |
| 24094 | const EXTENSION_NAME: Option<&'static str> = None; |
| 24095 | |
| 24096 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 24097 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 24098 | // Flatten the buffers into a single vector |
| 24099 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 24100 | (buf, fds) |
| 24101 | } |
| 24102 | } |
| 24103 | impl crate::x11_utils::ReplyRequest for GetKeyboardControlRequest { |
| 24104 | type Reply = GetKeyboardControlReply; |
| 24105 | } |
| 24106 | |
| 24107 | #[derive (Clone, Copy, Default)] |
| 24108 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 24109 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 24110 | pub struct GetKeyboardControlReply { |
| 24111 | pub global_auto_repeat: AutoRepeatMode, |
| 24112 | pub sequence: u16, |
| 24113 | pub length: u32, |
| 24114 | pub led_mask: u32, |
| 24115 | pub key_click_percent: u8, |
| 24116 | pub bell_percent: u8, |
| 24117 | pub bell_pitch: u16, |
| 24118 | pub bell_duration: u16, |
| 24119 | pub auto_repeats: [u8; 32], |
| 24120 | } |
| 24121 | impl_debug_if_no_extra_traits!(GetKeyboardControlReply, "GetKeyboardControlReply" ); |
| 24122 | impl TryParse for GetKeyboardControlReply { |
| 24123 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 24124 | let remaining = initial_value; |
| 24125 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 24126 | let (global_auto_repeat, remaining) = u8::try_parse(remaining)?; |
| 24127 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 24128 | let (length, remaining) = u32::try_parse(remaining)?; |
| 24129 | let (led_mask, remaining) = u32::try_parse(remaining)?; |
| 24130 | let (key_click_percent, remaining) = u8::try_parse(remaining)?; |
| 24131 | let (bell_percent, remaining) = u8::try_parse(remaining)?; |
| 24132 | let (bell_pitch, remaining) = u16::try_parse(remaining)?; |
| 24133 | let (bell_duration, remaining) = u16::try_parse(remaining)?; |
| 24134 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 24135 | let (auto_repeats, remaining) = crate::x11_utils::parse_u8_array::<32>(remaining)?; |
| 24136 | if response_type != 1 { |
| 24137 | return Err(ParseError::InvalidValue); |
| 24138 | } |
| 24139 | let global_auto_repeat = global_auto_repeat.into(); |
| 24140 | let result = GetKeyboardControlReply { global_auto_repeat, sequence, length, led_mask, key_click_percent, bell_percent, bell_pitch, bell_duration, auto_repeats }; |
| 24141 | let _ = remaining; |
| 24142 | let remaining = initial_value.get(32 + length as usize * 4..) |
| 24143 | .ok_or(ParseError::InsufficientData)?; |
| 24144 | Ok((result, remaining)) |
| 24145 | } |
| 24146 | } |
| 24147 | impl Serialize for GetKeyboardControlReply { |
| 24148 | type Bytes = [u8; 52]; |
| 24149 | fn serialize(&self) -> [u8; 52] { |
| 24150 | let response_type_bytes = &[1]; |
| 24151 | let global_auto_repeat_bytes = (u32::from(self.global_auto_repeat) as u8).serialize(); |
| 24152 | let sequence_bytes = self.sequence.serialize(); |
| 24153 | let length_bytes = self.length.serialize(); |
| 24154 | let led_mask_bytes = self.led_mask.serialize(); |
| 24155 | let key_click_percent_bytes = self.key_click_percent.serialize(); |
| 24156 | let bell_percent_bytes = self.bell_percent.serialize(); |
| 24157 | let bell_pitch_bytes = self.bell_pitch.serialize(); |
| 24158 | let bell_duration_bytes = self.bell_duration.serialize(); |
| 24159 | [ |
| 24160 | response_type_bytes[0], |
| 24161 | global_auto_repeat_bytes[0], |
| 24162 | sequence_bytes[0], |
| 24163 | sequence_bytes[1], |
| 24164 | length_bytes[0], |
| 24165 | length_bytes[1], |
| 24166 | length_bytes[2], |
| 24167 | length_bytes[3], |
| 24168 | led_mask_bytes[0], |
| 24169 | led_mask_bytes[1], |
| 24170 | led_mask_bytes[2], |
| 24171 | led_mask_bytes[3], |
| 24172 | key_click_percent_bytes[0], |
| 24173 | bell_percent_bytes[0], |
| 24174 | bell_pitch_bytes[0], |
| 24175 | bell_pitch_bytes[1], |
| 24176 | bell_duration_bytes[0], |
| 24177 | bell_duration_bytes[1], |
| 24178 | 0, |
| 24179 | 0, |
| 24180 | self.auto_repeats[0], |
| 24181 | self.auto_repeats[1], |
| 24182 | self.auto_repeats[2], |
| 24183 | self.auto_repeats[3], |
| 24184 | self.auto_repeats[4], |
| 24185 | self.auto_repeats[5], |
| 24186 | self.auto_repeats[6], |
| 24187 | self.auto_repeats[7], |
| 24188 | self.auto_repeats[8], |
| 24189 | self.auto_repeats[9], |
| 24190 | self.auto_repeats[10], |
| 24191 | self.auto_repeats[11], |
| 24192 | self.auto_repeats[12], |
| 24193 | self.auto_repeats[13], |
| 24194 | self.auto_repeats[14], |
| 24195 | self.auto_repeats[15], |
| 24196 | self.auto_repeats[16], |
| 24197 | self.auto_repeats[17], |
| 24198 | self.auto_repeats[18], |
| 24199 | self.auto_repeats[19], |
| 24200 | self.auto_repeats[20], |
| 24201 | self.auto_repeats[21], |
| 24202 | self.auto_repeats[22], |
| 24203 | self.auto_repeats[23], |
| 24204 | self.auto_repeats[24], |
| 24205 | self.auto_repeats[25], |
| 24206 | self.auto_repeats[26], |
| 24207 | self.auto_repeats[27], |
| 24208 | self.auto_repeats[28], |
| 24209 | self.auto_repeats[29], |
| 24210 | self.auto_repeats[30], |
| 24211 | self.auto_repeats[31], |
| 24212 | ] |
| 24213 | } |
| 24214 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 24215 | bytes.reserve(52); |
| 24216 | let response_type_bytes = &[1]; |
| 24217 | bytes.push(response_type_bytes[0]); |
| 24218 | (u32::from(self.global_auto_repeat) as u8).serialize_into(bytes); |
| 24219 | self.sequence.serialize_into(bytes); |
| 24220 | self.length.serialize_into(bytes); |
| 24221 | self.led_mask.serialize_into(bytes); |
| 24222 | self.key_click_percent.serialize_into(bytes); |
| 24223 | self.bell_percent.serialize_into(bytes); |
| 24224 | self.bell_pitch.serialize_into(bytes); |
| 24225 | self.bell_duration.serialize_into(bytes); |
| 24226 | bytes.extend_from_slice(&[0; 2]); |
| 24227 | bytes.extend_from_slice(&self.auto_repeats); |
| 24228 | } |
| 24229 | } |
| 24230 | |
| 24231 | /// Opcode for the Bell request |
| 24232 | pub const BELL_REQUEST: u8 = 104; |
| 24233 | #[derive (Clone, Copy, Default)] |
| 24234 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 24235 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 24236 | pub struct BellRequest { |
| 24237 | pub percent: i8, |
| 24238 | } |
| 24239 | impl_debug_if_no_extra_traits!(BellRequest, "BellRequest" ); |
| 24240 | impl BellRequest { |
| 24241 | /// Serialize this request into bytes for the provided connection |
| 24242 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 24243 | let length_so_far = 0; |
| 24244 | let percent_bytes = self.percent.serialize(); |
| 24245 | let mut request0 = vec![ |
| 24246 | BELL_REQUEST, |
| 24247 | percent_bytes[0], |
| 24248 | 0, |
| 24249 | 0, |
| 24250 | ]; |
| 24251 | let length_so_far = length_so_far + request0.len(); |
| 24252 | assert_eq!(length_so_far % 4, 0); |
| 24253 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 24254 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 24255 | ([request0.into()], vec![]) |
| 24256 | } |
| 24257 | /// Parse this request given its header, its body, and any fds that go along with it |
| 24258 | #[cfg (feature = "request-parsing" )] |
| 24259 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 24260 | if header.major_opcode != BELL_REQUEST { |
| 24261 | return Err(ParseError::InvalidValue); |
| 24262 | } |
| 24263 | let remaining = &[header.minor_opcode]; |
| 24264 | let (percent, remaining) = i8::try_parse(remaining)?; |
| 24265 | let _ = remaining; |
| 24266 | let _ = value; |
| 24267 | Ok(BellRequest { |
| 24268 | percent, |
| 24269 | }) |
| 24270 | } |
| 24271 | } |
| 24272 | impl Request for BellRequest { |
| 24273 | const EXTENSION_NAME: Option<&'static str> = None; |
| 24274 | |
| 24275 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 24276 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 24277 | // Flatten the buffers into a single vector |
| 24278 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 24279 | (buf, fds) |
| 24280 | } |
| 24281 | } |
| 24282 | impl crate::x11_utils::VoidRequest for BellRequest { |
| 24283 | } |
| 24284 | |
| 24285 | /// Opcode for the ChangePointerControl request |
| 24286 | pub const CHANGE_POINTER_CONTROL_REQUEST: u8 = 105; |
| 24287 | #[derive (Clone, Copy, Default)] |
| 24288 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 24289 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 24290 | pub struct ChangePointerControlRequest { |
| 24291 | pub acceleration_numerator: i16, |
| 24292 | pub acceleration_denominator: i16, |
| 24293 | pub threshold: i16, |
| 24294 | pub do_acceleration: bool, |
| 24295 | pub do_threshold: bool, |
| 24296 | } |
| 24297 | impl_debug_if_no_extra_traits!(ChangePointerControlRequest, "ChangePointerControlRequest" ); |
| 24298 | impl ChangePointerControlRequest { |
| 24299 | /// Serialize this request into bytes for the provided connection |
| 24300 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 24301 | let length_so_far = 0; |
| 24302 | let acceleration_numerator_bytes = self.acceleration_numerator.serialize(); |
| 24303 | let acceleration_denominator_bytes = self.acceleration_denominator.serialize(); |
| 24304 | let threshold_bytes = self.threshold.serialize(); |
| 24305 | let do_acceleration_bytes = self.do_acceleration.serialize(); |
| 24306 | let do_threshold_bytes = self.do_threshold.serialize(); |
| 24307 | let mut request0 = vec![ |
| 24308 | CHANGE_POINTER_CONTROL_REQUEST, |
| 24309 | 0, |
| 24310 | 0, |
| 24311 | 0, |
| 24312 | acceleration_numerator_bytes[0], |
| 24313 | acceleration_numerator_bytes[1], |
| 24314 | acceleration_denominator_bytes[0], |
| 24315 | acceleration_denominator_bytes[1], |
| 24316 | threshold_bytes[0], |
| 24317 | threshold_bytes[1], |
| 24318 | do_acceleration_bytes[0], |
| 24319 | do_threshold_bytes[0], |
| 24320 | ]; |
| 24321 | let length_so_far = length_so_far + request0.len(); |
| 24322 | assert_eq!(length_so_far % 4, 0); |
| 24323 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 24324 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 24325 | ([request0.into()], vec![]) |
| 24326 | } |
| 24327 | /// Parse this request given its header, its body, and any fds that go along with it |
| 24328 | #[cfg (feature = "request-parsing" )] |
| 24329 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 24330 | if header.major_opcode != CHANGE_POINTER_CONTROL_REQUEST { |
| 24331 | return Err(ParseError::InvalidValue); |
| 24332 | } |
| 24333 | let remaining = &[header.minor_opcode]; |
| 24334 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 24335 | let _ = remaining; |
| 24336 | let (acceleration_numerator, remaining) = i16::try_parse(value)?; |
| 24337 | let (acceleration_denominator, remaining) = i16::try_parse(remaining)?; |
| 24338 | let (threshold, remaining) = i16::try_parse(remaining)?; |
| 24339 | let (do_acceleration, remaining) = bool::try_parse(remaining)?; |
| 24340 | let (do_threshold, remaining) = bool::try_parse(remaining)?; |
| 24341 | let _ = remaining; |
| 24342 | Ok(ChangePointerControlRequest { |
| 24343 | acceleration_numerator, |
| 24344 | acceleration_denominator, |
| 24345 | threshold, |
| 24346 | do_acceleration, |
| 24347 | do_threshold, |
| 24348 | }) |
| 24349 | } |
| 24350 | } |
| 24351 | impl Request for ChangePointerControlRequest { |
| 24352 | const EXTENSION_NAME: Option<&'static str> = None; |
| 24353 | |
| 24354 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 24355 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 24356 | // Flatten the buffers into a single vector |
| 24357 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 24358 | (buf, fds) |
| 24359 | } |
| 24360 | } |
| 24361 | impl crate::x11_utils::VoidRequest for ChangePointerControlRequest { |
| 24362 | } |
| 24363 | |
| 24364 | /// Opcode for the GetPointerControl request |
| 24365 | pub const GET_POINTER_CONTROL_REQUEST: u8 = 106; |
| 24366 | #[derive (Clone, Copy, Default)] |
| 24367 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 24368 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 24369 | pub struct GetPointerControlRequest; |
| 24370 | impl_debug_if_no_extra_traits!(GetPointerControlRequest, "GetPointerControlRequest" ); |
| 24371 | impl GetPointerControlRequest { |
| 24372 | /// Serialize this request into bytes for the provided connection |
| 24373 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 24374 | let length_so_far = 0; |
| 24375 | let mut request0 = vec![ |
| 24376 | GET_POINTER_CONTROL_REQUEST, |
| 24377 | 0, |
| 24378 | 0, |
| 24379 | 0, |
| 24380 | ]; |
| 24381 | let length_so_far = length_so_far + request0.len(); |
| 24382 | assert_eq!(length_so_far % 4, 0); |
| 24383 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 24384 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 24385 | ([request0.into()], vec![]) |
| 24386 | } |
| 24387 | /// Parse this request given its header, its body, and any fds that go along with it |
| 24388 | #[cfg (feature = "request-parsing" )] |
| 24389 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 24390 | if header.major_opcode != GET_POINTER_CONTROL_REQUEST { |
| 24391 | return Err(ParseError::InvalidValue); |
| 24392 | } |
| 24393 | let remaining = &[header.minor_opcode]; |
| 24394 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 24395 | let _ = remaining; |
| 24396 | let _ = value; |
| 24397 | Ok(GetPointerControlRequest |
| 24398 | ) |
| 24399 | } |
| 24400 | } |
| 24401 | impl Request for GetPointerControlRequest { |
| 24402 | const EXTENSION_NAME: Option<&'static str> = None; |
| 24403 | |
| 24404 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 24405 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 24406 | // Flatten the buffers into a single vector |
| 24407 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 24408 | (buf, fds) |
| 24409 | } |
| 24410 | } |
| 24411 | impl crate::x11_utils::ReplyRequest for GetPointerControlRequest { |
| 24412 | type Reply = GetPointerControlReply; |
| 24413 | } |
| 24414 | |
| 24415 | #[derive (Clone, Copy, Default)] |
| 24416 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 24417 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 24418 | pub struct GetPointerControlReply { |
| 24419 | pub sequence: u16, |
| 24420 | pub length: u32, |
| 24421 | pub acceleration_numerator: u16, |
| 24422 | pub acceleration_denominator: u16, |
| 24423 | pub threshold: u16, |
| 24424 | } |
| 24425 | impl_debug_if_no_extra_traits!(GetPointerControlReply, "GetPointerControlReply" ); |
| 24426 | impl TryParse for GetPointerControlReply { |
| 24427 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 24428 | let remaining: &[u8] = initial_value; |
| 24429 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 24430 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 24431 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 24432 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 24433 | let (acceleration_numerator: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 24434 | let (acceleration_denominator: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 24435 | let (threshold: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 24436 | let remaining: &[u8] = remaining.get(18..).ok_or(err:ParseError::InsufficientData)?; |
| 24437 | if response_type != 1 { |
| 24438 | return Err(ParseError::InvalidValue); |
| 24439 | } |
| 24440 | let result: GetPointerControlReply = GetPointerControlReply { sequence, length, acceleration_numerator, acceleration_denominator, threshold }; |
| 24441 | let _ = remaining; |
| 24442 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 24443 | .ok_or(err:ParseError::InsufficientData)?; |
| 24444 | Ok((result, remaining)) |
| 24445 | } |
| 24446 | } |
| 24447 | impl Serialize for GetPointerControlReply { |
| 24448 | type Bytes = [u8; 32]; |
| 24449 | fn serialize(&self) -> [u8; 32] { |
| 24450 | let response_type_bytes = &[1]; |
| 24451 | let sequence_bytes = self.sequence.serialize(); |
| 24452 | let length_bytes = self.length.serialize(); |
| 24453 | let acceleration_numerator_bytes = self.acceleration_numerator.serialize(); |
| 24454 | let acceleration_denominator_bytes = self.acceleration_denominator.serialize(); |
| 24455 | let threshold_bytes = self.threshold.serialize(); |
| 24456 | [ |
| 24457 | response_type_bytes[0], |
| 24458 | 0, |
| 24459 | sequence_bytes[0], |
| 24460 | sequence_bytes[1], |
| 24461 | length_bytes[0], |
| 24462 | length_bytes[1], |
| 24463 | length_bytes[2], |
| 24464 | length_bytes[3], |
| 24465 | acceleration_numerator_bytes[0], |
| 24466 | acceleration_numerator_bytes[1], |
| 24467 | acceleration_denominator_bytes[0], |
| 24468 | acceleration_denominator_bytes[1], |
| 24469 | threshold_bytes[0], |
| 24470 | threshold_bytes[1], |
| 24471 | 0, |
| 24472 | 0, |
| 24473 | 0, |
| 24474 | 0, |
| 24475 | 0, |
| 24476 | 0, |
| 24477 | 0, |
| 24478 | 0, |
| 24479 | 0, |
| 24480 | 0, |
| 24481 | 0, |
| 24482 | 0, |
| 24483 | 0, |
| 24484 | 0, |
| 24485 | 0, |
| 24486 | 0, |
| 24487 | 0, |
| 24488 | 0, |
| 24489 | ] |
| 24490 | } |
| 24491 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 24492 | bytes.reserve(32); |
| 24493 | let response_type_bytes = &[1]; |
| 24494 | bytes.push(response_type_bytes[0]); |
| 24495 | bytes.extend_from_slice(&[0; 1]); |
| 24496 | self.sequence.serialize_into(bytes); |
| 24497 | self.length.serialize_into(bytes); |
| 24498 | self.acceleration_numerator.serialize_into(bytes); |
| 24499 | self.acceleration_denominator.serialize_into(bytes); |
| 24500 | self.threshold.serialize_into(bytes); |
| 24501 | bytes.extend_from_slice(&[0; 18]); |
| 24502 | } |
| 24503 | } |
| 24504 | |
| 24505 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 24506 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 24507 | pub struct Blanking(u8); |
| 24508 | impl Blanking { |
| 24509 | pub const NOT_PREFERRED: Self = Self(0); |
| 24510 | pub const PREFERRED: Self = Self(1); |
| 24511 | pub const DEFAULT: Self = Self(2); |
| 24512 | } |
| 24513 | impl From<Blanking> for u8 { |
| 24514 | #[inline ] |
| 24515 | fn from(input: Blanking) -> Self { |
| 24516 | input.0 |
| 24517 | } |
| 24518 | } |
| 24519 | impl From<Blanking> for Option<u8> { |
| 24520 | #[inline ] |
| 24521 | fn from(input: Blanking) -> Self { |
| 24522 | Some(input.0) |
| 24523 | } |
| 24524 | } |
| 24525 | impl From<Blanking> for u16 { |
| 24526 | #[inline ] |
| 24527 | fn from(input: Blanking) -> Self { |
| 24528 | u16::from(input.0) |
| 24529 | } |
| 24530 | } |
| 24531 | impl From<Blanking> for Option<u16> { |
| 24532 | #[inline ] |
| 24533 | fn from(input: Blanking) -> Self { |
| 24534 | Some(u16::from(input.0)) |
| 24535 | } |
| 24536 | } |
| 24537 | impl From<Blanking> for u32 { |
| 24538 | #[inline ] |
| 24539 | fn from(input: Blanking) -> Self { |
| 24540 | u32::from(input.0) |
| 24541 | } |
| 24542 | } |
| 24543 | impl From<Blanking> for Option<u32> { |
| 24544 | #[inline ] |
| 24545 | fn from(input: Blanking) -> Self { |
| 24546 | Some(u32::from(input.0)) |
| 24547 | } |
| 24548 | } |
| 24549 | impl From<u8> for Blanking { |
| 24550 | #[inline ] |
| 24551 | fn from(value: u8) -> Self { |
| 24552 | Self(value) |
| 24553 | } |
| 24554 | } |
| 24555 | impl core::fmt::Debug for Blanking { |
| 24556 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 24557 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 24558 | (Self::NOT_PREFERRED.0.into(), "NOT_PREFERRED" , "NotPreferred" ), |
| 24559 | (Self::PREFERRED.0.into(), "PREFERRED" , "Preferred" ), |
| 24560 | (Self::DEFAULT.0.into(), "DEFAULT" , "Default" ), |
| 24561 | ]; |
| 24562 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 24563 | } |
| 24564 | } |
| 24565 | |
| 24566 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 24567 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 24568 | pub struct Exposures(u8); |
| 24569 | impl Exposures { |
| 24570 | pub const NOT_ALLOWED: Self = Self(0); |
| 24571 | pub const ALLOWED: Self = Self(1); |
| 24572 | pub const DEFAULT: Self = Self(2); |
| 24573 | } |
| 24574 | impl From<Exposures> for u8 { |
| 24575 | #[inline ] |
| 24576 | fn from(input: Exposures) -> Self { |
| 24577 | input.0 |
| 24578 | } |
| 24579 | } |
| 24580 | impl From<Exposures> for Option<u8> { |
| 24581 | #[inline ] |
| 24582 | fn from(input: Exposures) -> Self { |
| 24583 | Some(input.0) |
| 24584 | } |
| 24585 | } |
| 24586 | impl From<Exposures> for u16 { |
| 24587 | #[inline ] |
| 24588 | fn from(input: Exposures) -> Self { |
| 24589 | u16::from(input.0) |
| 24590 | } |
| 24591 | } |
| 24592 | impl From<Exposures> for Option<u16> { |
| 24593 | #[inline ] |
| 24594 | fn from(input: Exposures) -> Self { |
| 24595 | Some(u16::from(input.0)) |
| 24596 | } |
| 24597 | } |
| 24598 | impl From<Exposures> for u32 { |
| 24599 | #[inline ] |
| 24600 | fn from(input: Exposures) -> Self { |
| 24601 | u32::from(input.0) |
| 24602 | } |
| 24603 | } |
| 24604 | impl From<Exposures> for Option<u32> { |
| 24605 | #[inline ] |
| 24606 | fn from(input: Exposures) -> Self { |
| 24607 | Some(u32::from(input.0)) |
| 24608 | } |
| 24609 | } |
| 24610 | impl From<u8> for Exposures { |
| 24611 | #[inline ] |
| 24612 | fn from(value: u8) -> Self { |
| 24613 | Self(value) |
| 24614 | } |
| 24615 | } |
| 24616 | impl core::fmt::Debug for Exposures { |
| 24617 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 24618 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 24619 | (Self::NOT_ALLOWED.0.into(), "NOT_ALLOWED" , "NotAllowed" ), |
| 24620 | (Self::ALLOWED.0.into(), "ALLOWED" , "Allowed" ), |
| 24621 | (Self::DEFAULT.0.into(), "DEFAULT" , "Default" ), |
| 24622 | ]; |
| 24623 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 24624 | } |
| 24625 | } |
| 24626 | |
| 24627 | /// Opcode for the SetScreenSaver request |
| 24628 | pub const SET_SCREEN_SAVER_REQUEST: u8 = 107; |
| 24629 | #[derive (Clone, Copy, Default)] |
| 24630 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 24631 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 24632 | pub struct SetScreenSaverRequest { |
| 24633 | pub timeout: i16, |
| 24634 | pub interval: i16, |
| 24635 | pub prefer_blanking: Blanking, |
| 24636 | pub allow_exposures: Exposures, |
| 24637 | } |
| 24638 | impl_debug_if_no_extra_traits!(SetScreenSaverRequest, "SetScreenSaverRequest" ); |
| 24639 | impl SetScreenSaverRequest { |
| 24640 | /// Serialize this request into bytes for the provided connection |
| 24641 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 24642 | let length_so_far = 0; |
| 24643 | let timeout_bytes = self.timeout.serialize(); |
| 24644 | let interval_bytes = self.interval.serialize(); |
| 24645 | let prefer_blanking_bytes = u8::from(self.prefer_blanking).serialize(); |
| 24646 | let allow_exposures_bytes = u8::from(self.allow_exposures).serialize(); |
| 24647 | let mut request0 = vec![ |
| 24648 | SET_SCREEN_SAVER_REQUEST, |
| 24649 | 0, |
| 24650 | 0, |
| 24651 | 0, |
| 24652 | timeout_bytes[0], |
| 24653 | timeout_bytes[1], |
| 24654 | interval_bytes[0], |
| 24655 | interval_bytes[1], |
| 24656 | prefer_blanking_bytes[0], |
| 24657 | allow_exposures_bytes[0], |
| 24658 | 0, |
| 24659 | 0, |
| 24660 | ]; |
| 24661 | let length_so_far = length_so_far + request0.len(); |
| 24662 | assert_eq!(length_so_far % 4, 0); |
| 24663 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 24664 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 24665 | ([request0.into()], vec![]) |
| 24666 | } |
| 24667 | /// Parse this request given its header, its body, and any fds that go along with it |
| 24668 | #[cfg (feature = "request-parsing" )] |
| 24669 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 24670 | if header.major_opcode != SET_SCREEN_SAVER_REQUEST { |
| 24671 | return Err(ParseError::InvalidValue); |
| 24672 | } |
| 24673 | let remaining = &[header.minor_opcode]; |
| 24674 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 24675 | let _ = remaining; |
| 24676 | let (timeout, remaining) = i16::try_parse(value)?; |
| 24677 | let (interval, remaining) = i16::try_parse(remaining)?; |
| 24678 | let (prefer_blanking, remaining) = u8::try_parse(remaining)?; |
| 24679 | let prefer_blanking = prefer_blanking.into(); |
| 24680 | let (allow_exposures, remaining) = u8::try_parse(remaining)?; |
| 24681 | let allow_exposures = allow_exposures.into(); |
| 24682 | let _ = remaining; |
| 24683 | Ok(SetScreenSaverRequest { |
| 24684 | timeout, |
| 24685 | interval, |
| 24686 | prefer_blanking, |
| 24687 | allow_exposures, |
| 24688 | }) |
| 24689 | } |
| 24690 | } |
| 24691 | impl Request for SetScreenSaverRequest { |
| 24692 | const EXTENSION_NAME: Option<&'static str> = None; |
| 24693 | |
| 24694 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 24695 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 24696 | // Flatten the buffers into a single vector |
| 24697 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 24698 | (buf, fds) |
| 24699 | } |
| 24700 | } |
| 24701 | impl crate::x11_utils::VoidRequest for SetScreenSaverRequest { |
| 24702 | } |
| 24703 | |
| 24704 | /// Opcode for the GetScreenSaver request |
| 24705 | pub const GET_SCREEN_SAVER_REQUEST: u8 = 108; |
| 24706 | #[derive (Clone, Copy, Default)] |
| 24707 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 24708 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 24709 | pub struct GetScreenSaverRequest; |
| 24710 | impl_debug_if_no_extra_traits!(GetScreenSaverRequest, "GetScreenSaverRequest" ); |
| 24711 | impl GetScreenSaverRequest { |
| 24712 | /// Serialize this request into bytes for the provided connection |
| 24713 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 24714 | let length_so_far = 0; |
| 24715 | let mut request0 = vec![ |
| 24716 | GET_SCREEN_SAVER_REQUEST, |
| 24717 | 0, |
| 24718 | 0, |
| 24719 | 0, |
| 24720 | ]; |
| 24721 | let length_so_far = length_so_far + request0.len(); |
| 24722 | assert_eq!(length_so_far % 4, 0); |
| 24723 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 24724 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 24725 | ([request0.into()], vec![]) |
| 24726 | } |
| 24727 | /// Parse this request given its header, its body, and any fds that go along with it |
| 24728 | #[cfg (feature = "request-parsing" )] |
| 24729 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 24730 | if header.major_opcode != GET_SCREEN_SAVER_REQUEST { |
| 24731 | return Err(ParseError::InvalidValue); |
| 24732 | } |
| 24733 | let remaining = &[header.minor_opcode]; |
| 24734 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 24735 | let _ = remaining; |
| 24736 | let _ = value; |
| 24737 | Ok(GetScreenSaverRequest |
| 24738 | ) |
| 24739 | } |
| 24740 | } |
| 24741 | impl Request for GetScreenSaverRequest { |
| 24742 | const EXTENSION_NAME: Option<&'static str> = None; |
| 24743 | |
| 24744 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 24745 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 24746 | // Flatten the buffers into a single vector |
| 24747 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 24748 | (buf, fds) |
| 24749 | } |
| 24750 | } |
| 24751 | impl crate::x11_utils::ReplyRequest for GetScreenSaverRequest { |
| 24752 | type Reply = GetScreenSaverReply; |
| 24753 | } |
| 24754 | |
| 24755 | #[derive (Clone, Copy, Default)] |
| 24756 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 24757 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 24758 | pub struct GetScreenSaverReply { |
| 24759 | pub sequence: u16, |
| 24760 | pub length: u32, |
| 24761 | pub timeout: u16, |
| 24762 | pub interval: u16, |
| 24763 | pub prefer_blanking: Blanking, |
| 24764 | pub allow_exposures: Exposures, |
| 24765 | } |
| 24766 | impl_debug_if_no_extra_traits!(GetScreenSaverReply, "GetScreenSaverReply" ); |
| 24767 | impl TryParse for GetScreenSaverReply { |
| 24768 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 24769 | let remaining: &[u8] = initial_value; |
| 24770 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 24771 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 24772 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 24773 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 24774 | let (timeout: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 24775 | let (interval: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 24776 | let (prefer_blanking: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 24777 | let (allow_exposures: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 24778 | let remaining: &[u8] = remaining.get(18..).ok_or(err:ParseError::InsufficientData)?; |
| 24779 | if response_type != 1 { |
| 24780 | return Err(ParseError::InvalidValue); |
| 24781 | } |
| 24782 | let prefer_blanking: Blanking = prefer_blanking.into(); |
| 24783 | let allow_exposures: Exposures = allow_exposures.into(); |
| 24784 | let result: GetScreenSaverReply = GetScreenSaverReply { sequence, length, timeout, interval, prefer_blanking, allow_exposures }; |
| 24785 | let _ = remaining; |
| 24786 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 24787 | .ok_or(err:ParseError::InsufficientData)?; |
| 24788 | Ok((result, remaining)) |
| 24789 | } |
| 24790 | } |
| 24791 | impl Serialize for GetScreenSaverReply { |
| 24792 | type Bytes = [u8; 32]; |
| 24793 | fn serialize(&self) -> [u8; 32] { |
| 24794 | let response_type_bytes = &[1]; |
| 24795 | let sequence_bytes = self.sequence.serialize(); |
| 24796 | let length_bytes = self.length.serialize(); |
| 24797 | let timeout_bytes = self.timeout.serialize(); |
| 24798 | let interval_bytes = self.interval.serialize(); |
| 24799 | let prefer_blanking_bytes = u8::from(self.prefer_blanking).serialize(); |
| 24800 | let allow_exposures_bytes = u8::from(self.allow_exposures).serialize(); |
| 24801 | [ |
| 24802 | response_type_bytes[0], |
| 24803 | 0, |
| 24804 | sequence_bytes[0], |
| 24805 | sequence_bytes[1], |
| 24806 | length_bytes[0], |
| 24807 | length_bytes[1], |
| 24808 | length_bytes[2], |
| 24809 | length_bytes[3], |
| 24810 | timeout_bytes[0], |
| 24811 | timeout_bytes[1], |
| 24812 | interval_bytes[0], |
| 24813 | interval_bytes[1], |
| 24814 | prefer_blanking_bytes[0], |
| 24815 | allow_exposures_bytes[0], |
| 24816 | 0, |
| 24817 | 0, |
| 24818 | 0, |
| 24819 | 0, |
| 24820 | 0, |
| 24821 | 0, |
| 24822 | 0, |
| 24823 | 0, |
| 24824 | 0, |
| 24825 | 0, |
| 24826 | 0, |
| 24827 | 0, |
| 24828 | 0, |
| 24829 | 0, |
| 24830 | 0, |
| 24831 | 0, |
| 24832 | 0, |
| 24833 | 0, |
| 24834 | ] |
| 24835 | } |
| 24836 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 24837 | bytes.reserve(32); |
| 24838 | let response_type_bytes = &[1]; |
| 24839 | bytes.push(response_type_bytes[0]); |
| 24840 | bytes.extend_from_slice(&[0; 1]); |
| 24841 | self.sequence.serialize_into(bytes); |
| 24842 | self.length.serialize_into(bytes); |
| 24843 | self.timeout.serialize_into(bytes); |
| 24844 | self.interval.serialize_into(bytes); |
| 24845 | u8::from(self.prefer_blanking).serialize_into(bytes); |
| 24846 | u8::from(self.allow_exposures).serialize_into(bytes); |
| 24847 | bytes.extend_from_slice(&[0; 18]); |
| 24848 | } |
| 24849 | } |
| 24850 | |
| 24851 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 24852 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 24853 | pub struct HostMode(u8); |
| 24854 | impl HostMode { |
| 24855 | pub const INSERT: Self = Self(0); |
| 24856 | pub const DELETE: Self = Self(1); |
| 24857 | } |
| 24858 | impl From<HostMode> for u8 { |
| 24859 | #[inline ] |
| 24860 | fn from(input: HostMode) -> Self { |
| 24861 | input.0 |
| 24862 | } |
| 24863 | } |
| 24864 | impl From<HostMode> for Option<u8> { |
| 24865 | #[inline ] |
| 24866 | fn from(input: HostMode) -> Self { |
| 24867 | Some(input.0) |
| 24868 | } |
| 24869 | } |
| 24870 | impl From<HostMode> for u16 { |
| 24871 | #[inline ] |
| 24872 | fn from(input: HostMode) -> Self { |
| 24873 | u16::from(input.0) |
| 24874 | } |
| 24875 | } |
| 24876 | impl From<HostMode> for Option<u16> { |
| 24877 | #[inline ] |
| 24878 | fn from(input: HostMode) -> Self { |
| 24879 | Some(u16::from(input.0)) |
| 24880 | } |
| 24881 | } |
| 24882 | impl From<HostMode> for u32 { |
| 24883 | #[inline ] |
| 24884 | fn from(input: HostMode) -> Self { |
| 24885 | u32::from(input.0) |
| 24886 | } |
| 24887 | } |
| 24888 | impl From<HostMode> for Option<u32> { |
| 24889 | #[inline ] |
| 24890 | fn from(input: HostMode) -> Self { |
| 24891 | Some(u32::from(input.0)) |
| 24892 | } |
| 24893 | } |
| 24894 | impl From<u8> for HostMode { |
| 24895 | #[inline ] |
| 24896 | fn from(value: u8) -> Self { |
| 24897 | Self(value) |
| 24898 | } |
| 24899 | } |
| 24900 | impl core::fmt::Debug for HostMode { |
| 24901 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 24902 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 24903 | (Self::INSERT.0.into(), "INSERT" , "Insert" ), |
| 24904 | (Self::DELETE.0.into(), "DELETE" , "Delete" ), |
| 24905 | ]; |
| 24906 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 24907 | } |
| 24908 | } |
| 24909 | |
| 24910 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 24911 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 24912 | pub struct Family(u8); |
| 24913 | impl Family { |
| 24914 | pub const INTERNET: Self = Self(0); |
| 24915 | pub const DEC_NET: Self = Self(1); |
| 24916 | pub const CHAOS: Self = Self(2); |
| 24917 | pub const SERVER_INTERPRETED: Self = Self(5); |
| 24918 | pub const INTERNET6: Self = Self(6); |
| 24919 | } |
| 24920 | impl From<Family> for u8 { |
| 24921 | #[inline ] |
| 24922 | fn from(input: Family) -> Self { |
| 24923 | input.0 |
| 24924 | } |
| 24925 | } |
| 24926 | impl From<Family> for Option<u8> { |
| 24927 | #[inline ] |
| 24928 | fn from(input: Family) -> Self { |
| 24929 | Some(input.0) |
| 24930 | } |
| 24931 | } |
| 24932 | impl From<Family> for u16 { |
| 24933 | #[inline ] |
| 24934 | fn from(input: Family) -> Self { |
| 24935 | u16::from(input.0) |
| 24936 | } |
| 24937 | } |
| 24938 | impl From<Family> for Option<u16> { |
| 24939 | #[inline ] |
| 24940 | fn from(input: Family) -> Self { |
| 24941 | Some(u16::from(input.0)) |
| 24942 | } |
| 24943 | } |
| 24944 | impl From<Family> for u32 { |
| 24945 | #[inline ] |
| 24946 | fn from(input: Family) -> Self { |
| 24947 | u32::from(input.0) |
| 24948 | } |
| 24949 | } |
| 24950 | impl From<Family> for Option<u32> { |
| 24951 | #[inline ] |
| 24952 | fn from(input: Family) -> Self { |
| 24953 | Some(u32::from(input.0)) |
| 24954 | } |
| 24955 | } |
| 24956 | impl From<u8> for Family { |
| 24957 | #[inline ] |
| 24958 | fn from(value: u8) -> Self { |
| 24959 | Self(value) |
| 24960 | } |
| 24961 | } |
| 24962 | impl core::fmt::Debug for Family { |
| 24963 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 24964 | let variants: [(u32, &'static str, &'static …); 5] = [ |
| 24965 | (Self::INTERNET.0.into(), "INTERNET" , "Internet" ), |
| 24966 | (Self::DEC_NET.0.into(), "DEC_NET" , "DECnet" ), |
| 24967 | (Self::CHAOS.0.into(), "CHAOS" , "Chaos" ), |
| 24968 | (Self::SERVER_INTERPRETED.0.into(), "SERVER_INTERPRETED" , "ServerInterpreted" ), |
| 24969 | (Self::INTERNET6.0.into(), "INTERNET6" , "Internet6" ), |
| 24970 | ]; |
| 24971 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 24972 | } |
| 24973 | } |
| 24974 | |
| 24975 | /// Opcode for the ChangeHosts request |
| 24976 | pub const CHANGE_HOSTS_REQUEST: u8 = 109; |
| 24977 | #[derive (Clone, Default)] |
| 24978 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 24979 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 24980 | pub struct ChangeHostsRequest<'input> { |
| 24981 | pub mode: HostMode, |
| 24982 | pub family: Family, |
| 24983 | pub address: Cow<'input, [u8]>, |
| 24984 | } |
| 24985 | impl_debug_if_no_extra_traits!(ChangeHostsRequest<'_>, "ChangeHostsRequest" ); |
| 24986 | impl<'input> ChangeHostsRequest<'input> { |
| 24987 | /// Serialize this request into bytes for the provided connection |
| 24988 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 24989 | let length_so_far = 0; |
| 24990 | let mode_bytes = u8::from(self.mode).serialize(); |
| 24991 | let family_bytes = u8::from(self.family).serialize(); |
| 24992 | let address_len = u16::try_from(self.address.len()).expect("`address` has too many elements" ); |
| 24993 | let address_len_bytes = address_len.serialize(); |
| 24994 | let mut request0 = vec![ |
| 24995 | CHANGE_HOSTS_REQUEST, |
| 24996 | mode_bytes[0], |
| 24997 | 0, |
| 24998 | 0, |
| 24999 | family_bytes[0], |
| 25000 | 0, |
| 25001 | address_len_bytes[0], |
| 25002 | address_len_bytes[1], |
| 25003 | ]; |
| 25004 | let length_so_far = length_so_far + request0.len(); |
| 25005 | let length_so_far = length_so_far + self.address.len(); |
| 25006 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 25007 | let length_so_far = length_so_far + padding0.len(); |
| 25008 | assert_eq!(length_so_far % 4, 0); |
| 25009 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 25010 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 25011 | ([request0.into(), self.address, padding0.into()], vec![]) |
| 25012 | } |
| 25013 | /// Parse this request given its header, its body, and any fds that go along with it |
| 25014 | #[cfg (feature = "request-parsing" )] |
| 25015 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 25016 | if header.major_opcode != CHANGE_HOSTS_REQUEST { |
| 25017 | return Err(ParseError::InvalidValue); |
| 25018 | } |
| 25019 | let remaining = &[header.minor_opcode]; |
| 25020 | let (mode, remaining) = u8::try_parse(remaining)?; |
| 25021 | let mode = mode.into(); |
| 25022 | let _ = remaining; |
| 25023 | let (family, remaining) = u8::try_parse(value)?; |
| 25024 | let family = family.into(); |
| 25025 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 25026 | let (address_len, remaining) = u16::try_parse(remaining)?; |
| 25027 | let (address, remaining) = crate::x11_utils::parse_u8_list(remaining, address_len.try_to_usize()?)?; |
| 25028 | let _ = remaining; |
| 25029 | Ok(ChangeHostsRequest { |
| 25030 | mode, |
| 25031 | family, |
| 25032 | address: Cow::Borrowed(address), |
| 25033 | }) |
| 25034 | } |
| 25035 | /// Clone all borrowed data in this ChangeHostsRequest. |
| 25036 | pub fn into_owned(self) -> ChangeHostsRequest<'static> { |
| 25037 | ChangeHostsRequest { |
| 25038 | mode: self.mode, |
| 25039 | family: self.family, |
| 25040 | address: Cow::Owned(self.address.into_owned()), |
| 25041 | } |
| 25042 | } |
| 25043 | } |
| 25044 | impl<'input> Request for ChangeHostsRequest<'input> { |
| 25045 | const EXTENSION_NAME: Option<&'static str> = None; |
| 25046 | |
| 25047 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 25048 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 25049 | // Flatten the buffers into a single vector |
| 25050 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 25051 | (buf, fds) |
| 25052 | } |
| 25053 | } |
| 25054 | impl<'input> crate::x11_utils::VoidRequest for ChangeHostsRequest<'input> { |
| 25055 | } |
| 25056 | |
| 25057 | #[derive (Clone, Default)] |
| 25058 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 25059 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 25060 | pub struct Host { |
| 25061 | pub family: Family, |
| 25062 | pub address: Vec<u8>, |
| 25063 | } |
| 25064 | impl_debug_if_no_extra_traits!(Host, "Host" ); |
| 25065 | impl TryParse for Host { |
| 25066 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 25067 | let value: &[u8] = remaining; |
| 25068 | let (family: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 25069 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 25070 | let (address_len: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 25071 | let (address: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data:remaining, list_length:address_len.try_to_usize()?)?; |
| 25072 | let address: Vec = address.to_vec(); |
| 25073 | // Align offset to multiple of 4 |
| 25074 | let offset: usize = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 25075 | let misalignment: usize = (4 - (offset % 4)) % 4; |
| 25076 | let remaining: &[u8] = remaining.get(misalignment..).ok_or(err:ParseError::InsufficientData)?; |
| 25077 | let family: Family = family.into(); |
| 25078 | let result: Host = Host { family, address }; |
| 25079 | Ok((result, remaining)) |
| 25080 | } |
| 25081 | } |
| 25082 | impl Serialize for Host { |
| 25083 | type Bytes = Vec<u8>; |
| 25084 | fn serialize(&self) -> Vec<u8> { |
| 25085 | let mut result: Vec = Vec::new(); |
| 25086 | self.serialize_into(&mut result); |
| 25087 | result |
| 25088 | } |
| 25089 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 25090 | bytes.reserve(additional:4); |
| 25091 | u8::from(self.family).serialize_into(bytes); |
| 25092 | bytes.extend_from_slice(&[0; 1]); |
| 25093 | let address_len: u16 = u16::try_from(self.address.len()).expect(msg:"`address` has too many elements" ); |
| 25094 | address_len.serialize_into(bytes); |
| 25095 | bytes.extend_from_slice(&self.address); |
| 25096 | bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]); |
| 25097 | } |
| 25098 | } |
| 25099 | impl Host { |
| 25100 | /// Get the value of the `address_len` field. |
| 25101 | /// |
| 25102 | /// The `address_len` field is used as the length field of the `address` field. |
| 25103 | /// This function computes the field's value again based on the length of the list. |
| 25104 | /// |
| 25105 | /// # Panics |
| 25106 | /// |
| 25107 | /// Panics if the value cannot be represented in the target type. This |
| 25108 | /// cannot happen with values of the struct received from the X11 server. |
| 25109 | pub fn address_len(&self) -> u16 { |
| 25110 | self.address.len() |
| 25111 | .try_into().unwrap() |
| 25112 | } |
| 25113 | } |
| 25114 | |
| 25115 | /// Opcode for the ListHosts request |
| 25116 | pub const LIST_HOSTS_REQUEST: u8 = 110; |
| 25117 | #[derive (Clone, Copy, Default)] |
| 25118 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 25119 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 25120 | pub struct ListHostsRequest; |
| 25121 | impl_debug_if_no_extra_traits!(ListHostsRequest, "ListHostsRequest" ); |
| 25122 | impl ListHostsRequest { |
| 25123 | /// Serialize this request into bytes for the provided connection |
| 25124 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 25125 | let length_so_far = 0; |
| 25126 | let mut request0 = vec![ |
| 25127 | LIST_HOSTS_REQUEST, |
| 25128 | 0, |
| 25129 | 0, |
| 25130 | 0, |
| 25131 | ]; |
| 25132 | let length_so_far = length_so_far + request0.len(); |
| 25133 | assert_eq!(length_so_far % 4, 0); |
| 25134 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 25135 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 25136 | ([request0.into()], vec![]) |
| 25137 | } |
| 25138 | /// Parse this request given its header, its body, and any fds that go along with it |
| 25139 | #[cfg (feature = "request-parsing" )] |
| 25140 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 25141 | if header.major_opcode != LIST_HOSTS_REQUEST { |
| 25142 | return Err(ParseError::InvalidValue); |
| 25143 | } |
| 25144 | let remaining = &[header.minor_opcode]; |
| 25145 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 25146 | let _ = remaining; |
| 25147 | let _ = value; |
| 25148 | Ok(ListHostsRequest |
| 25149 | ) |
| 25150 | } |
| 25151 | } |
| 25152 | impl Request for ListHostsRequest { |
| 25153 | const EXTENSION_NAME: Option<&'static str> = None; |
| 25154 | |
| 25155 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 25156 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 25157 | // Flatten the buffers into a single vector |
| 25158 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 25159 | (buf, fds) |
| 25160 | } |
| 25161 | } |
| 25162 | impl crate::x11_utils::ReplyRequest for ListHostsRequest { |
| 25163 | type Reply = ListHostsReply; |
| 25164 | } |
| 25165 | |
| 25166 | #[derive (Clone, Default)] |
| 25167 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 25168 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 25169 | pub struct ListHostsReply { |
| 25170 | pub mode: AccessControl, |
| 25171 | pub sequence: u16, |
| 25172 | pub length: u32, |
| 25173 | pub hosts: Vec<Host>, |
| 25174 | } |
| 25175 | impl_debug_if_no_extra_traits!(ListHostsReply, "ListHostsReply" ); |
| 25176 | impl TryParse for ListHostsReply { |
| 25177 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 25178 | let remaining: &[u8] = initial_value; |
| 25179 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 25180 | let (mode: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 25181 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 25182 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 25183 | let (hosts_len: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 25184 | let remaining: &[u8] = remaining.get(22..).ok_or(err:ParseError::InsufficientData)?; |
| 25185 | let (hosts: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<Host>(data:remaining, list_length:hosts_len.try_to_usize()?)?; |
| 25186 | if response_type != 1 { |
| 25187 | return Err(ParseError::InvalidValue); |
| 25188 | } |
| 25189 | let mode: AccessControl = mode.into(); |
| 25190 | let result: ListHostsReply = ListHostsReply { mode, sequence, length, hosts }; |
| 25191 | let _ = remaining; |
| 25192 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 25193 | .ok_or(err:ParseError::InsufficientData)?; |
| 25194 | Ok((result, remaining)) |
| 25195 | } |
| 25196 | } |
| 25197 | impl Serialize for ListHostsReply { |
| 25198 | type Bytes = Vec<u8>; |
| 25199 | fn serialize(&self) -> Vec<u8> { |
| 25200 | let mut result: Vec = Vec::new(); |
| 25201 | self.serialize_into(&mut result); |
| 25202 | result |
| 25203 | } |
| 25204 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 25205 | bytes.reserve(additional:32); |
| 25206 | let response_type_bytes: &[u8; 1] = &[1]; |
| 25207 | bytes.push(response_type_bytes[0]); |
| 25208 | u8::from(self.mode).serialize_into(bytes); |
| 25209 | self.sequence.serialize_into(bytes); |
| 25210 | self.length.serialize_into(bytes); |
| 25211 | let hosts_len: u16 = u16::try_from(self.hosts.len()).expect(msg:"`hosts` has too many elements" ); |
| 25212 | hosts_len.serialize_into(bytes); |
| 25213 | bytes.extend_from_slice(&[0; 22]); |
| 25214 | self.hosts.serialize_into(bytes); |
| 25215 | } |
| 25216 | } |
| 25217 | impl ListHostsReply { |
| 25218 | /// Get the value of the `hosts_len` field. |
| 25219 | /// |
| 25220 | /// The `hosts_len` field is used as the length field of the `hosts` field. |
| 25221 | /// This function computes the field's value again based on the length of the list. |
| 25222 | /// |
| 25223 | /// # Panics |
| 25224 | /// |
| 25225 | /// Panics if the value cannot be represented in the target type. This |
| 25226 | /// cannot happen with values of the struct received from the X11 server. |
| 25227 | pub fn hosts_len(&self) -> u16 { |
| 25228 | self.hosts.len() |
| 25229 | .try_into().unwrap() |
| 25230 | } |
| 25231 | } |
| 25232 | |
| 25233 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 25234 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 25235 | pub struct AccessControl(u8); |
| 25236 | impl AccessControl { |
| 25237 | pub const DISABLE: Self = Self(0); |
| 25238 | pub const ENABLE: Self = Self(1); |
| 25239 | } |
| 25240 | impl From<AccessControl> for u8 { |
| 25241 | #[inline ] |
| 25242 | fn from(input: AccessControl) -> Self { |
| 25243 | input.0 |
| 25244 | } |
| 25245 | } |
| 25246 | impl From<AccessControl> for Option<u8> { |
| 25247 | #[inline ] |
| 25248 | fn from(input: AccessControl) -> Self { |
| 25249 | Some(input.0) |
| 25250 | } |
| 25251 | } |
| 25252 | impl From<AccessControl> for u16 { |
| 25253 | #[inline ] |
| 25254 | fn from(input: AccessControl) -> Self { |
| 25255 | u16::from(input.0) |
| 25256 | } |
| 25257 | } |
| 25258 | impl From<AccessControl> for Option<u16> { |
| 25259 | #[inline ] |
| 25260 | fn from(input: AccessControl) -> Self { |
| 25261 | Some(u16::from(input.0)) |
| 25262 | } |
| 25263 | } |
| 25264 | impl From<AccessControl> for u32 { |
| 25265 | #[inline ] |
| 25266 | fn from(input: AccessControl) -> Self { |
| 25267 | u32::from(input.0) |
| 25268 | } |
| 25269 | } |
| 25270 | impl From<AccessControl> for Option<u32> { |
| 25271 | #[inline ] |
| 25272 | fn from(input: AccessControl) -> Self { |
| 25273 | Some(u32::from(input.0)) |
| 25274 | } |
| 25275 | } |
| 25276 | impl From<u8> for AccessControl { |
| 25277 | #[inline ] |
| 25278 | fn from(value: u8) -> Self { |
| 25279 | Self(value) |
| 25280 | } |
| 25281 | } |
| 25282 | impl core::fmt::Debug for AccessControl { |
| 25283 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 25284 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 25285 | (Self::DISABLE.0.into(), "DISABLE" , "Disable" ), |
| 25286 | (Self::ENABLE.0.into(), "ENABLE" , "Enable" ), |
| 25287 | ]; |
| 25288 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 25289 | } |
| 25290 | } |
| 25291 | |
| 25292 | /// Opcode for the SetAccessControl request |
| 25293 | pub const SET_ACCESS_CONTROL_REQUEST: u8 = 111; |
| 25294 | #[derive (Clone, Copy, Default)] |
| 25295 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 25296 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 25297 | pub struct SetAccessControlRequest { |
| 25298 | pub mode: AccessControl, |
| 25299 | } |
| 25300 | impl_debug_if_no_extra_traits!(SetAccessControlRequest, "SetAccessControlRequest" ); |
| 25301 | impl SetAccessControlRequest { |
| 25302 | /// Serialize this request into bytes for the provided connection |
| 25303 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 25304 | let length_so_far = 0; |
| 25305 | let mode_bytes = u8::from(self.mode).serialize(); |
| 25306 | let mut request0 = vec![ |
| 25307 | SET_ACCESS_CONTROL_REQUEST, |
| 25308 | mode_bytes[0], |
| 25309 | 0, |
| 25310 | 0, |
| 25311 | ]; |
| 25312 | let length_so_far = length_so_far + request0.len(); |
| 25313 | assert_eq!(length_so_far % 4, 0); |
| 25314 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 25315 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 25316 | ([request0.into()], vec![]) |
| 25317 | } |
| 25318 | /// Parse this request given its header, its body, and any fds that go along with it |
| 25319 | #[cfg (feature = "request-parsing" )] |
| 25320 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 25321 | if header.major_opcode != SET_ACCESS_CONTROL_REQUEST { |
| 25322 | return Err(ParseError::InvalidValue); |
| 25323 | } |
| 25324 | let remaining = &[header.minor_opcode]; |
| 25325 | let (mode, remaining) = u8::try_parse(remaining)?; |
| 25326 | let mode = mode.into(); |
| 25327 | let _ = remaining; |
| 25328 | let _ = value; |
| 25329 | Ok(SetAccessControlRequest { |
| 25330 | mode, |
| 25331 | }) |
| 25332 | } |
| 25333 | } |
| 25334 | impl Request for SetAccessControlRequest { |
| 25335 | const EXTENSION_NAME: Option<&'static str> = None; |
| 25336 | |
| 25337 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 25338 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 25339 | // Flatten the buffers into a single vector |
| 25340 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 25341 | (buf, fds) |
| 25342 | } |
| 25343 | } |
| 25344 | impl crate::x11_utils::VoidRequest for SetAccessControlRequest { |
| 25345 | } |
| 25346 | |
| 25347 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 25348 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 25349 | pub struct CloseDown(u8); |
| 25350 | impl CloseDown { |
| 25351 | pub const DESTROY_ALL: Self = Self(0); |
| 25352 | pub const RETAIN_PERMANENT: Self = Self(1); |
| 25353 | pub const RETAIN_TEMPORARY: Self = Self(2); |
| 25354 | } |
| 25355 | impl From<CloseDown> for u8 { |
| 25356 | #[inline ] |
| 25357 | fn from(input: CloseDown) -> Self { |
| 25358 | input.0 |
| 25359 | } |
| 25360 | } |
| 25361 | impl From<CloseDown> for Option<u8> { |
| 25362 | #[inline ] |
| 25363 | fn from(input: CloseDown) -> Self { |
| 25364 | Some(input.0) |
| 25365 | } |
| 25366 | } |
| 25367 | impl From<CloseDown> for u16 { |
| 25368 | #[inline ] |
| 25369 | fn from(input: CloseDown) -> Self { |
| 25370 | u16::from(input.0) |
| 25371 | } |
| 25372 | } |
| 25373 | impl From<CloseDown> for Option<u16> { |
| 25374 | #[inline ] |
| 25375 | fn from(input: CloseDown) -> Self { |
| 25376 | Some(u16::from(input.0)) |
| 25377 | } |
| 25378 | } |
| 25379 | impl From<CloseDown> for u32 { |
| 25380 | #[inline ] |
| 25381 | fn from(input: CloseDown) -> Self { |
| 25382 | u32::from(input.0) |
| 25383 | } |
| 25384 | } |
| 25385 | impl From<CloseDown> for Option<u32> { |
| 25386 | #[inline ] |
| 25387 | fn from(input: CloseDown) -> Self { |
| 25388 | Some(u32::from(input.0)) |
| 25389 | } |
| 25390 | } |
| 25391 | impl From<u8> for CloseDown { |
| 25392 | #[inline ] |
| 25393 | fn from(value: u8) -> Self { |
| 25394 | Self(value) |
| 25395 | } |
| 25396 | } |
| 25397 | impl core::fmt::Debug for CloseDown { |
| 25398 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 25399 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 25400 | (Self::DESTROY_ALL.0.into(), "DESTROY_ALL" , "DestroyAll" ), |
| 25401 | (Self::RETAIN_PERMANENT.0.into(), "RETAIN_PERMANENT" , "RetainPermanent" ), |
| 25402 | (Self::RETAIN_TEMPORARY.0.into(), "RETAIN_TEMPORARY" , "RetainTemporary" ), |
| 25403 | ]; |
| 25404 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 25405 | } |
| 25406 | } |
| 25407 | |
| 25408 | /// Opcode for the SetCloseDownMode request |
| 25409 | pub const SET_CLOSE_DOWN_MODE_REQUEST: u8 = 112; |
| 25410 | #[derive (Clone, Copy, Default)] |
| 25411 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 25412 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 25413 | pub struct SetCloseDownModeRequest { |
| 25414 | pub mode: CloseDown, |
| 25415 | } |
| 25416 | impl_debug_if_no_extra_traits!(SetCloseDownModeRequest, "SetCloseDownModeRequest" ); |
| 25417 | impl SetCloseDownModeRequest { |
| 25418 | /// Serialize this request into bytes for the provided connection |
| 25419 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 25420 | let length_so_far = 0; |
| 25421 | let mode_bytes = u8::from(self.mode).serialize(); |
| 25422 | let mut request0 = vec![ |
| 25423 | SET_CLOSE_DOWN_MODE_REQUEST, |
| 25424 | mode_bytes[0], |
| 25425 | 0, |
| 25426 | 0, |
| 25427 | ]; |
| 25428 | let length_so_far = length_so_far + request0.len(); |
| 25429 | assert_eq!(length_so_far % 4, 0); |
| 25430 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 25431 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 25432 | ([request0.into()], vec![]) |
| 25433 | } |
| 25434 | /// Parse this request given its header, its body, and any fds that go along with it |
| 25435 | #[cfg (feature = "request-parsing" )] |
| 25436 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 25437 | if header.major_opcode != SET_CLOSE_DOWN_MODE_REQUEST { |
| 25438 | return Err(ParseError::InvalidValue); |
| 25439 | } |
| 25440 | let remaining = &[header.minor_opcode]; |
| 25441 | let (mode, remaining) = u8::try_parse(remaining)?; |
| 25442 | let mode = mode.into(); |
| 25443 | let _ = remaining; |
| 25444 | let _ = value; |
| 25445 | Ok(SetCloseDownModeRequest { |
| 25446 | mode, |
| 25447 | }) |
| 25448 | } |
| 25449 | } |
| 25450 | impl Request for SetCloseDownModeRequest { |
| 25451 | const EXTENSION_NAME: Option<&'static str> = None; |
| 25452 | |
| 25453 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 25454 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 25455 | // Flatten the buffers into a single vector |
| 25456 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 25457 | (buf, fds) |
| 25458 | } |
| 25459 | } |
| 25460 | impl crate::x11_utils::VoidRequest for SetCloseDownModeRequest { |
| 25461 | } |
| 25462 | |
| 25463 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 25464 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 25465 | pub struct Kill(u8); |
| 25466 | impl Kill { |
| 25467 | pub const ALL_TEMPORARY: Self = Self(0); |
| 25468 | } |
| 25469 | impl From<Kill> for u8 { |
| 25470 | #[inline ] |
| 25471 | fn from(input: Kill) -> Self { |
| 25472 | input.0 |
| 25473 | } |
| 25474 | } |
| 25475 | impl From<Kill> for Option<u8> { |
| 25476 | #[inline ] |
| 25477 | fn from(input: Kill) -> Self { |
| 25478 | Some(input.0) |
| 25479 | } |
| 25480 | } |
| 25481 | impl From<Kill> for u16 { |
| 25482 | #[inline ] |
| 25483 | fn from(input: Kill) -> Self { |
| 25484 | u16::from(input.0) |
| 25485 | } |
| 25486 | } |
| 25487 | impl From<Kill> for Option<u16> { |
| 25488 | #[inline ] |
| 25489 | fn from(input: Kill) -> Self { |
| 25490 | Some(u16::from(input.0)) |
| 25491 | } |
| 25492 | } |
| 25493 | impl From<Kill> for u32 { |
| 25494 | #[inline ] |
| 25495 | fn from(input: Kill) -> Self { |
| 25496 | u32::from(input.0) |
| 25497 | } |
| 25498 | } |
| 25499 | impl From<Kill> for Option<u32> { |
| 25500 | #[inline ] |
| 25501 | fn from(input: Kill) -> Self { |
| 25502 | Some(u32::from(input.0)) |
| 25503 | } |
| 25504 | } |
| 25505 | impl From<u8> for Kill { |
| 25506 | #[inline ] |
| 25507 | fn from(value: u8) -> Self { |
| 25508 | Self(value) |
| 25509 | } |
| 25510 | } |
| 25511 | impl core::fmt::Debug for Kill { |
| 25512 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 25513 | let variants: [(u32, &'static str, &'static …); 1] = [ |
| 25514 | (Self::ALL_TEMPORARY.0.into(), "ALL_TEMPORARY" , "AllTemporary" ), |
| 25515 | ]; |
| 25516 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 25517 | } |
| 25518 | } |
| 25519 | |
| 25520 | /// Opcode for the KillClient request |
| 25521 | pub const KILL_CLIENT_REQUEST: u8 = 113; |
| 25522 | /// kills a client. |
| 25523 | /// |
| 25524 | /// Forces a close down of the client that created the specified `resource`. |
| 25525 | /// |
| 25526 | /// # Fields |
| 25527 | /// |
| 25528 | /// * `resource` - Any resource belonging to the client (for example a Window), used to identify |
| 25529 | /// the client connection. |
| 25530 | /// |
| 25531 | /// The special value of `XCB_KILL_ALL_TEMPORARY`, the resources of all clients |
| 25532 | /// that have terminated in `RetainTemporary` (TODO) are destroyed. |
| 25533 | /// |
| 25534 | /// # Errors |
| 25535 | /// |
| 25536 | /// * `Value` - The specified `resource` does not exist. |
| 25537 | /// |
| 25538 | /// # See |
| 25539 | /// |
| 25540 | /// * `xkill`: program |
| 25541 | #[derive (Clone, Copy, Default)] |
| 25542 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 25543 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 25544 | pub struct KillClientRequest { |
| 25545 | pub resource: u32, |
| 25546 | } |
| 25547 | impl_debug_if_no_extra_traits!(KillClientRequest, "KillClientRequest" ); |
| 25548 | impl KillClientRequest { |
| 25549 | /// Serialize this request into bytes for the provided connection |
| 25550 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 25551 | let length_so_far = 0; |
| 25552 | let resource_bytes = self.resource.serialize(); |
| 25553 | let mut request0 = vec![ |
| 25554 | KILL_CLIENT_REQUEST, |
| 25555 | 0, |
| 25556 | 0, |
| 25557 | 0, |
| 25558 | resource_bytes[0], |
| 25559 | resource_bytes[1], |
| 25560 | resource_bytes[2], |
| 25561 | resource_bytes[3], |
| 25562 | ]; |
| 25563 | let length_so_far = length_so_far + request0.len(); |
| 25564 | assert_eq!(length_so_far % 4, 0); |
| 25565 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 25566 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 25567 | ([request0.into()], vec![]) |
| 25568 | } |
| 25569 | /// Parse this request given its header, its body, and any fds that go along with it |
| 25570 | #[cfg (feature = "request-parsing" )] |
| 25571 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 25572 | if header.major_opcode != KILL_CLIENT_REQUEST { |
| 25573 | return Err(ParseError::InvalidValue); |
| 25574 | } |
| 25575 | let remaining = &[header.minor_opcode]; |
| 25576 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 25577 | let _ = remaining; |
| 25578 | let (resource, remaining) = u32::try_parse(value)?; |
| 25579 | let _ = remaining; |
| 25580 | Ok(KillClientRequest { |
| 25581 | resource, |
| 25582 | }) |
| 25583 | } |
| 25584 | } |
| 25585 | impl Request for KillClientRequest { |
| 25586 | const EXTENSION_NAME: Option<&'static str> = None; |
| 25587 | |
| 25588 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 25589 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 25590 | // Flatten the buffers into a single vector |
| 25591 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 25592 | (buf, fds) |
| 25593 | } |
| 25594 | } |
| 25595 | impl crate::x11_utils::VoidRequest for KillClientRequest { |
| 25596 | } |
| 25597 | |
| 25598 | /// Opcode for the RotateProperties request |
| 25599 | pub const ROTATE_PROPERTIES_REQUEST: u8 = 114; |
| 25600 | #[derive (Clone, Default)] |
| 25601 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 25602 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 25603 | pub struct RotatePropertiesRequest<'input> { |
| 25604 | pub window: Window, |
| 25605 | pub delta: i16, |
| 25606 | pub atoms: Cow<'input, [Atom]>, |
| 25607 | } |
| 25608 | impl_debug_if_no_extra_traits!(RotatePropertiesRequest<'_>, "RotatePropertiesRequest" ); |
| 25609 | impl<'input> RotatePropertiesRequest<'input> { |
| 25610 | /// Serialize this request into bytes for the provided connection |
| 25611 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 25612 | let length_so_far = 0; |
| 25613 | let window_bytes = self.window.serialize(); |
| 25614 | let atoms_len = u16::try_from(self.atoms.len()).expect("`atoms` has too many elements" ); |
| 25615 | let atoms_len_bytes = atoms_len.serialize(); |
| 25616 | let delta_bytes = self.delta.serialize(); |
| 25617 | let mut request0 = vec![ |
| 25618 | ROTATE_PROPERTIES_REQUEST, |
| 25619 | 0, |
| 25620 | 0, |
| 25621 | 0, |
| 25622 | window_bytes[0], |
| 25623 | window_bytes[1], |
| 25624 | window_bytes[2], |
| 25625 | window_bytes[3], |
| 25626 | atoms_len_bytes[0], |
| 25627 | atoms_len_bytes[1], |
| 25628 | delta_bytes[0], |
| 25629 | delta_bytes[1], |
| 25630 | ]; |
| 25631 | let length_so_far = length_so_far + request0.len(); |
| 25632 | let atoms_bytes = self.atoms.serialize(); |
| 25633 | let length_so_far = length_so_far + atoms_bytes.len(); |
| 25634 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 25635 | let length_so_far = length_so_far + padding0.len(); |
| 25636 | assert_eq!(length_so_far % 4, 0); |
| 25637 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 25638 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 25639 | ([request0.into(), atoms_bytes.into(), padding0.into()], vec![]) |
| 25640 | } |
| 25641 | /// Parse this request given its header, its body, and any fds that go along with it |
| 25642 | #[cfg (feature = "request-parsing" )] |
| 25643 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 25644 | if header.major_opcode != ROTATE_PROPERTIES_REQUEST { |
| 25645 | return Err(ParseError::InvalidValue); |
| 25646 | } |
| 25647 | let remaining = &[header.minor_opcode]; |
| 25648 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 25649 | let _ = remaining; |
| 25650 | let (window, remaining) = Window::try_parse(value)?; |
| 25651 | let (atoms_len, remaining) = u16::try_parse(remaining)?; |
| 25652 | let (delta, remaining) = i16::try_parse(remaining)?; |
| 25653 | let (atoms, remaining) = crate::x11_utils::parse_list::<Atom>(remaining, atoms_len.try_to_usize()?)?; |
| 25654 | let _ = remaining; |
| 25655 | Ok(RotatePropertiesRequest { |
| 25656 | window, |
| 25657 | delta, |
| 25658 | atoms: Cow::Owned(atoms), |
| 25659 | }) |
| 25660 | } |
| 25661 | /// Clone all borrowed data in this RotatePropertiesRequest. |
| 25662 | pub fn into_owned(self) -> RotatePropertiesRequest<'static> { |
| 25663 | RotatePropertiesRequest { |
| 25664 | window: self.window, |
| 25665 | delta: self.delta, |
| 25666 | atoms: Cow::Owned(self.atoms.into_owned()), |
| 25667 | } |
| 25668 | } |
| 25669 | } |
| 25670 | impl<'input> Request for RotatePropertiesRequest<'input> { |
| 25671 | const EXTENSION_NAME: Option<&'static str> = None; |
| 25672 | |
| 25673 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 25674 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 25675 | // Flatten the buffers into a single vector |
| 25676 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 25677 | (buf, fds) |
| 25678 | } |
| 25679 | } |
| 25680 | impl<'input> crate::x11_utils::VoidRequest for RotatePropertiesRequest<'input> { |
| 25681 | } |
| 25682 | |
| 25683 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 25684 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 25685 | pub struct ScreenSaver(u8); |
| 25686 | impl ScreenSaver { |
| 25687 | pub const RESET: Self = Self(0); |
| 25688 | pub const ACTIVE: Self = Self(1); |
| 25689 | } |
| 25690 | impl From<ScreenSaver> for u8 { |
| 25691 | #[inline ] |
| 25692 | fn from(input: ScreenSaver) -> Self { |
| 25693 | input.0 |
| 25694 | } |
| 25695 | } |
| 25696 | impl From<ScreenSaver> for Option<u8> { |
| 25697 | #[inline ] |
| 25698 | fn from(input: ScreenSaver) -> Self { |
| 25699 | Some(input.0) |
| 25700 | } |
| 25701 | } |
| 25702 | impl From<ScreenSaver> for u16 { |
| 25703 | #[inline ] |
| 25704 | fn from(input: ScreenSaver) -> Self { |
| 25705 | u16::from(input.0) |
| 25706 | } |
| 25707 | } |
| 25708 | impl From<ScreenSaver> for Option<u16> { |
| 25709 | #[inline ] |
| 25710 | fn from(input: ScreenSaver) -> Self { |
| 25711 | Some(u16::from(input.0)) |
| 25712 | } |
| 25713 | } |
| 25714 | impl From<ScreenSaver> for u32 { |
| 25715 | #[inline ] |
| 25716 | fn from(input: ScreenSaver) -> Self { |
| 25717 | u32::from(input.0) |
| 25718 | } |
| 25719 | } |
| 25720 | impl From<ScreenSaver> for Option<u32> { |
| 25721 | #[inline ] |
| 25722 | fn from(input: ScreenSaver) -> Self { |
| 25723 | Some(u32::from(input.0)) |
| 25724 | } |
| 25725 | } |
| 25726 | impl From<u8> for ScreenSaver { |
| 25727 | #[inline ] |
| 25728 | fn from(value: u8) -> Self { |
| 25729 | Self(value) |
| 25730 | } |
| 25731 | } |
| 25732 | impl core::fmt::Debug for ScreenSaver { |
| 25733 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 25734 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 25735 | (Self::RESET.0.into(), "RESET" , "Reset" ), |
| 25736 | (Self::ACTIVE.0.into(), "ACTIVE" , "Active" ), |
| 25737 | ]; |
| 25738 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 25739 | } |
| 25740 | } |
| 25741 | |
| 25742 | /// Opcode for the ForceScreenSaver request |
| 25743 | pub const FORCE_SCREEN_SAVER_REQUEST: u8 = 115; |
| 25744 | #[derive (Clone, Copy, Default)] |
| 25745 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 25746 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 25747 | pub struct ForceScreenSaverRequest { |
| 25748 | pub mode: ScreenSaver, |
| 25749 | } |
| 25750 | impl_debug_if_no_extra_traits!(ForceScreenSaverRequest, "ForceScreenSaverRequest" ); |
| 25751 | impl ForceScreenSaverRequest { |
| 25752 | /// Serialize this request into bytes for the provided connection |
| 25753 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 25754 | let length_so_far = 0; |
| 25755 | let mode_bytes = u8::from(self.mode).serialize(); |
| 25756 | let mut request0 = vec![ |
| 25757 | FORCE_SCREEN_SAVER_REQUEST, |
| 25758 | mode_bytes[0], |
| 25759 | 0, |
| 25760 | 0, |
| 25761 | ]; |
| 25762 | let length_so_far = length_so_far + request0.len(); |
| 25763 | assert_eq!(length_so_far % 4, 0); |
| 25764 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 25765 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 25766 | ([request0.into()], vec![]) |
| 25767 | } |
| 25768 | /// Parse this request given its header, its body, and any fds that go along with it |
| 25769 | #[cfg (feature = "request-parsing" )] |
| 25770 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 25771 | if header.major_opcode != FORCE_SCREEN_SAVER_REQUEST { |
| 25772 | return Err(ParseError::InvalidValue); |
| 25773 | } |
| 25774 | let remaining = &[header.minor_opcode]; |
| 25775 | let (mode, remaining) = u8::try_parse(remaining)?; |
| 25776 | let mode = mode.into(); |
| 25777 | let _ = remaining; |
| 25778 | let _ = value; |
| 25779 | Ok(ForceScreenSaverRequest { |
| 25780 | mode, |
| 25781 | }) |
| 25782 | } |
| 25783 | } |
| 25784 | impl Request for ForceScreenSaverRequest { |
| 25785 | const EXTENSION_NAME: Option<&'static str> = None; |
| 25786 | |
| 25787 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 25788 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 25789 | // Flatten the buffers into a single vector |
| 25790 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 25791 | (buf, fds) |
| 25792 | } |
| 25793 | } |
| 25794 | impl crate::x11_utils::VoidRequest for ForceScreenSaverRequest { |
| 25795 | } |
| 25796 | |
| 25797 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 25798 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 25799 | pub struct MappingStatus(u8); |
| 25800 | impl MappingStatus { |
| 25801 | pub const SUCCESS: Self = Self(0); |
| 25802 | pub const BUSY: Self = Self(1); |
| 25803 | pub const FAILURE: Self = Self(2); |
| 25804 | } |
| 25805 | impl From<MappingStatus> for u8 { |
| 25806 | #[inline ] |
| 25807 | fn from(input: MappingStatus) -> Self { |
| 25808 | input.0 |
| 25809 | } |
| 25810 | } |
| 25811 | impl From<MappingStatus> for Option<u8> { |
| 25812 | #[inline ] |
| 25813 | fn from(input: MappingStatus) -> Self { |
| 25814 | Some(input.0) |
| 25815 | } |
| 25816 | } |
| 25817 | impl From<MappingStatus> for u16 { |
| 25818 | #[inline ] |
| 25819 | fn from(input: MappingStatus) -> Self { |
| 25820 | u16::from(input.0) |
| 25821 | } |
| 25822 | } |
| 25823 | impl From<MappingStatus> for Option<u16> { |
| 25824 | #[inline ] |
| 25825 | fn from(input: MappingStatus) -> Self { |
| 25826 | Some(u16::from(input.0)) |
| 25827 | } |
| 25828 | } |
| 25829 | impl From<MappingStatus> for u32 { |
| 25830 | #[inline ] |
| 25831 | fn from(input: MappingStatus) -> Self { |
| 25832 | u32::from(input.0) |
| 25833 | } |
| 25834 | } |
| 25835 | impl From<MappingStatus> for Option<u32> { |
| 25836 | #[inline ] |
| 25837 | fn from(input: MappingStatus) -> Self { |
| 25838 | Some(u32::from(input.0)) |
| 25839 | } |
| 25840 | } |
| 25841 | impl From<u8> for MappingStatus { |
| 25842 | #[inline ] |
| 25843 | fn from(value: u8) -> Self { |
| 25844 | Self(value) |
| 25845 | } |
| 25846 | } |
| 25847 | impl core::fmt::Debug for MappingStatus { |
| 25848 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 25849 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 25850 | (Self::SUCCESS.0.into(), "SUCCESS" , "Success" ), |
| 25851 | (Self::BUSY.0.into(), "BUSY" , "Busy" ), |
| 25852 | (Self::FAILURE.0.into(), "FAILURE" , "Failure" ), |
| 25853 | ]; |
| 25854 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 25855 | } |
| 25856 | } |
| 25857 | |
| 25858 | /// Opcode for the SetPointerMapping request |
| 25859 | pub const SET_POINTER_MAPPING_REQUEST: u8 = 116; |
| 25860 | #[derive (Clone, Default)] |
| 25861 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 25862 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 25863 | pub struct SetPointerMappingRequest<'input> { |
| 25864 | pub map: Cow<'input, [u8]>, |
| 25865 | } |
| 25866 | impl_debug_if_no_extra_traits!(SetPointerMappingRequest<'_>, "SetPointerMappingRequest" ); |
| 25867 | impl<'input> SetPointerMappingRequest<'input> { |
| 25868 | /// Serialize this request into bytes for the provided connection |
| 25869 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 25870 | let length_so_far = 0; |
| 25871 | let map_len = u8::try_from(self.map.len()).expect("`map` has too many elements" ); |
| 25872 | let map_len_bytes = map_len.serialize(); |
| 25873 | let mut request0 = vec![ |
| 25874 | SET_POINTER_MAPPING_REQUEST, |
| 25875 | map_len_bytes[0], |
| 25876 | 0, |
| 25877 | 0, |
| 25878 | ]; |
| 25879 | let length_so_far = length_so_far + request0.len(); |
| 25880 | let length_so_far = length_so_far + self.map.len(); |
| 25881 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 25882 | let length_so_far = length_so_far + padding0.len(); |
| 25883 | assert_eq!(length_so_far % 4, 0); |
| 25884 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 25885 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 25886 | ([request0.into(), self.map, padding0.into()], vec![]) |
| 25887 | } |
| 25888 | /// Parse this request given its header, its body, and any fds that go along with it |
| 25889 | #[cfg (feature = "request-parsing" )] |
| 25890 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 25891 | if header.major_opcode != SET_POINTER_MAPPING_REQUEST { |
| 25892 | return Err(ParseError::InvalidValue); |
| 25893 | } |
| 25894 | let remaining = &[header.minor_opcode]; |
| 25895 | let (map_len, remaining) = u8::try_parse(remaining)?; |
| 25896 | let _ = remaining; |
| 25897 | let (map, remaining) = crate::x11_utils::parse_u8_list(value, map_len.try_to_usize()?)?; |
| 25898 | let _ = remaining; |
| 25899 | Ok(SetPointerMappingRequest { |
| 25900 | map: Cow::Borrowed(map), |
| 25901 | }) |
| 25902 | } |
| 25903 | /// Clone all borrowed data in this SetPointerMappingRequest. |
| 25904 | pub fn into_owned(self) -> SetPointerMappingRequest<'static> { |
| 25905 | SetPointerMappingRequest { |
| 25906 | map: Cow::Owned(self.map.into_owned()), |
| 25907 | } |
| 25908 | } |
| 25909 | } |
| 25910 | impl<'input> Request for SetPointerMappingRequest<'input> { |
| 25911 | const EXTENSION_NAME: Option<&'static str> = None; |
| 25912 | |
| 25913 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 25914 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 25915 | // Flatten the buffers into a single vector |
| 25916 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 25917 | (buf, fds) |
| 25918 | } |
| 25919 | } |
| 25920 | impl<'input> crate::x11_utils::ReplyRequest for SetPointerMappingRequest<'input> { |
| 25921 | type Reply = SetPointerMappingReply; |
| 25922 | } |
| 25923 | |
| 25924 | #[derive (Clone, Copy, Default)] |
| 25925 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 25926 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 25927 | pub struct SetPointerMappingReply { |
| 25928 | pub status: MappingStatus, |
| 25929 | pub sequence: u16, |
| 25930 | pub length: u32, |
| 25931 | } |
| 25932 | impl_debug_if_no_extra_traits!(SetPointerMappingReply, "SetPointerMappingReply" ); |
| 25933 | impl TryParse for SetPointerMappingReply { |
| 25934 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 25935 | let remaining: &[u8] = initial_value; |
| 25936 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 25937 | let (status: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 25938 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 25939 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 25940 | if response_type != 1 { |
| 25941 | return Err(ParseError::InvalidValue); |
| 25942 | } |
| 25943 | let status: MappingStatus = status.into(); |
| 25944 | let result: SetPointerMappingReply = SetPointerMappingReply { status, sequence, length }; |
| 25945 | let _ = remaining; |
| 25946 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 25947 | .ok_or(err:ParseError::InsufficientData)?; |
| 25948 | Ok((result, remaining)) |
| 25949 | } |
| 25950 | } |
| 25951 | impl Serialize for SetPointerMappingReply { |
| 25952 | type Bytes = [u8; 8]; |
| 25953 | fn serialize(&self) -> [u8; 8] { |
| 25954 | let response_type_bytes = &[1]; |
| 25955 | let status_bytes = u8::from(self.status).serialize(); |
| 25956 | let sequence_bytes = self.sequence.serialize(); |
| 25957 | let length_bytes = self.length.serialize(); |
| 25958 | [ |
| 25959 | response_type_bytes[0], |
| 25960 | status_bytes[0], |
| 25961 | sequence_bytes[0], |
| 25962 | sequence_bytes[1], |
| 25963 | length_bytes[0], |
| 25964 | length_bytes[1], |
| 25965 | length_bytes[2], |
| 25966 | length_bytes[3], |
| 25967 | ] |
| 25968 | } |
| 25969 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 25970 | bytes.reserve(8); |
| 25971 | let response_type_bytes = &[1]; |
| 25972 | bytes.push(response_type_bytes[0]); |
| 25973 | u8::from(self.status).serialize_into(bytes); |
| 25974 | self.sequence.serialize_into(bytes); |
| 25975 | self.length.serialize_into(bytes); |
| 25976 | } |
| 25977 | } |
| 25978 | |
| 25979 | /// Opcode for the GetPointerMapping request |
| 25980 | pub const GET_POINTER_MAPPING_REQUEST: u8 = 117; |
| 25981 | #[derive (Clone, Copy, Default)] |
| 25982 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 25983 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 25984 | pub struct GetPointerMappingRequest; |
| 25985 | impl_debug_if_no_extra_traits!(GetPointerMappingRequest, "GetPointerMappingRequest" ); |
| 25986 | impl GetPointerMappingRequest { |
| 25987 | /// Serialize this request into bytes for the provided connection |
| 25988 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 25989 | let length_so_far = 0; |
| 25990 | let mut request0 = vec![ |
| 25991 | GET_POINTER_MAPPING_REQUEST, |
| 25992 | 0, |
| 25993 | 0, |
| 25994 | 0, |
| 25995 | ]; |
| 25996 | let length_so_far = length_so_far + request0.len(); |
| 25997 | assert_eq!(length_so_far % 4, 0); |
| 25998 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 25999 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 26000 | ([request0.into()], vec![]) |
| 26001 | } |
| 26002 | /// Parse this request given its header, its body, and any fds that go along with it |
| 26003 | #[cfg (feature = "request-parsing" )] |
| 26004 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 26005 | if header.major_opcode != GET_POINTER_MAPPING_REQUEST { |
| 26006 | return Err(ParseError::InvalidValue); |
| 26007 | } |
| 26008 | let remaining = &[header.minor_opcode]; |
| 26009 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 26010 | let _ = remaining; |
| 26011 | let _ = value; |
| 26012 | Ok(GetPointerMappingRequest |
| 26013 | ) |
| 26014 | } |
| 26015 | } |
| 26016 | impl Request for GetPointerMappingRequest { |
| 26017 | const EXTENSION_NAME: Option<&'static str> = None; |
| 26018 | |
| 26019 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 26020 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 26021 | // Flatten the buffers into a single vector |
| 26022 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 26023 | (buf, fds) |
| 26024 | } |
| 26025 | } |
| 26026 | impl crate::x11_utils::ReplyRequest for GetPointerMappingRequest { |
| 26027 | type Reply = GetPointerMappingReply; |
| 26028 | } |
| 26029 | |
| 26030 | #[derive (Clone, Default)] |
| 26031 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 26032 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 26033 | pub struct GetPointerMappingReply { |
| 26034 | pub sequence: u16, |
| 26035 | pub length: u32, |
| 26036 | pub map: Vec<u8>, |
| 26037 | } |
| 26038 | impl_debug_if_no_extra_traits!(GetPointerMappingReply, "GetPointerMappingReply" ); |
| 26039 | impl TryParse for GetPointerMappingReply { |
| 26040 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 26041 | let remaining: &[u8] = initial_value; |
| 26042 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 26043 | let (map_len: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 26044 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 26045 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 26046 | let remaining: &[u8] = remaining.get(24..).ok_or(err:ParseError::InsufficientData)?; |
| 26047 | let (map: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data:remaining, list_length:map_len.try_to_usize()?)?; |
| 26048 | let map: Vec = map.to_vec(); |
| 26049 | if response_type != 1 { |
| 26050 | return Err(ParseError::InvalidValue); |
| 26051 | } |
| 26052 | let result: GetPointerMappingReply = GetPointerMappingReply { sequence, length, map }; |
| 26053 | let _ = remaining; |
| 26054 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 26055 | .ok_or(err:ParseError::InsufficientData)?; |
| 26056 | Ok((result, remaining)) |
| 26057 | } |
| 26058 | } |
| 26059 | impl Serialize for GetPointerMappingReply { |
| 26060 | type Bytes = Vec<u8>; |
| 26061 | fn serialize(&self) -> Vec<u8> { |
| 26062 | let mut result: Vec = Vec::new(); |
| 26063 | self.serialize_into(&mut result); |
| 26064 | result |
| 26065 | } |
| 26066 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 26067 | bytes.reserve(additional:32); |
| 26068 | let response_type_bytes: &[u8; 1] = &[1]; |
| 26069 | bytes.push(response_type_bytes[0]); |
| 26070 | let map_len: u8 = u8::try_from(self.map.len()).expect(msg:"`map` has too many elements" ); |
| 26071 | map_len.serialize_into(bytes); |
| 26072 | self.sequence.serialize_into(bytes); |
| 26073 | self.length.serialize_into(bytes); |
| 26074 | bytes.extend_from_slice(&[0; 24]); |
| 26075 | bytes.extend_from_slice(&self.map); |
| 26076 | } |
| 26077 | } |
| 26078 | impl GetPointerMappingReply { |
| 26079 | /// Get the value of the `map_len` field. |
| 26080 | /// |
| 26081 | /// The `map_len` field is used as the length field of the `map` field. |
| 26082 | /// This function computes the field's value again based on the length of the list. |
| 26083 | /// |
| 26084 | /// # Panics |
| 26085 | /// |
| 26086 | /// Panics if the value cannot be represented in the target type. This |
| 26087 | /// cannot happen with values of the struct received from the X11 server. |
| 26088 | pub fn map_len(&self) -> u8 { |
| 26089 | self.map.len() |
| 26090 | .try_into().unwrap() |
| 26091 | } |
| 26092 | } |
| 26093 | |
| 26094 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 26095 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 26096 | pub struct MapIndex(u8); |
| 26097 | impl MapIndex { |
| 26098 | pub const SHIFT: Self = Self(0); |
| 26099 | pub const LOCK: Self = Self(1); |
| 26100 | pub const CONTROL: Self = Self(2); |
| 26101 | pub const M1: Self = Self(3); |
| 26102 | pub const M2: Self = Self(4); |
| 26103 | pub const M3: Self = Self(5); |
| 26104 | pub const M4: Self = Self(6); |
| 26105 | pub const M5: Self = Self(7); |
| 26106 | } |
| 26107 | impl From<MapIndex> for u8 { |
| 26108 | #[inline ] |
| 26109 | fn from(input: MapIndex) -> Self { |
| 26110 | input.0 |
| 26111 | } |
| 26112 | } |
| 26113 | impl From<MapIndex> for Option<u8> { |
| 26114 | #[inline ] |
| 26115 | fn from(input: MapIndex) -> Self { |
| 26116 | Some(input.0) |
| 26117 | } |
| 26118 | } |
| 26119 | impl From<MapIndex> for u16 { |
| 26120 | #[inline ] |
| 26121 | fn from(input: MapIndex) -> Self { |
| 26122 | u16::from(input.0) |
| 26123 | } |
| 26124 | } |
| 26125 | impl From<MapIndex> for Option<u16> { |
| 26126 | #[inline ] |
| 26127 | fn from(input: MapIndex) -> Self { |
| 26128 | Some(u16::from(input.0)) |
| 26129 | } |
| 26130 | } |
| 26131 | impl From<MapIndex> for u32 { |
| 26132 | #[inline ] |
| 26133 | fn from(input: MapIndex) -> Self { |
| 26134 | u32::from(input.0) |
| 26135 | } |
| 26136 | } |
| 26137 | impl From<MapIndex> for Option<u32> { |
| 26138 | #[inline ] |
| 26139 | fn from(input: MapIndex) -> Self { |
| 26140 | Some(u32::from(input.0)) |
| 26141 | } |
| 26142 | } |
| 26143 | impl From<u8> for MapIndex { |
| 26144 | #[inline ] |
| 26145 | fn from(value: u8) -> Self { |
| 26146 | Self(value) |
| 26147 | } |
| 26148 | } |
| 26149 | impl core::fmt::Debug for MapIndex { |
| 26150 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 26151 | let variants: [(u32, &'static str, &'static …); 8] = [ |
| 26152 | (Self::SHIFT.0.into(), "SHIFT" , "Shift" ), |
| 26153 | (Self::LOCK.0.into(), "LOCK" , "Lock" ), |
| 26154 | (Self::CONTROL.0.into(), "CONTROL" , "Control" ), |
| 26155 | (Self::M1.0.into(), "M1" , "M1" ), |
| 26156 | (Self::M2.0.into(), "M2" , "M2" ), |
| 26157 | (Self::M3.0.into(), "M3" , "M3" ), |
| 26158 | (Self::M4.0.into(), "M4" , "M4" ), |
| 26159 | (Self::M5.0.into(), "M5" , "M5" ), |
| 26160 | ]; |
| 26161 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 26162 | } |
| 26163 | } |
| 26164 | |
| 26165 | /// Opcode for the SetModifierMapping request |
| 26166 | pub const SET_MODIFIER_MAPPING_REQUEST: u8 = 118; |
| 26167 | #[derive (Clone, Default)] |
| 26168 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 26169 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 26170 | pub struct SetModifierMappingRequest<'input> { |
| 26171 | pub keycodes: Cow<'input, [Keycode]>, |
| 26172 | } |
| 26173 | impl_debug_if_no_extra_traits!(SetModifierMappingRequest<'_>, "SetModifierMappingRequest" ); |
| 26174 | impl<'input> SetModifierMappingRequest<'input> { |
| 26175 | /// Serialize this request into bytes for the provided connection |
| 26176 | pub fn serialize(self) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 26177 | let length_so_far = 0; |
| 26178 | assert_eq!(self.keycodes.len() % 8, 0, "`keycodes` has an incorrect length, must be a multiple of 8" ); |
| 26179 | let keycodes_per_modifier = u8::try_from(self.keycodes.len() / 8).expect("`keycodes` has too many elements" ); |
| 26180 | let keycodes_per_modifier_bytes = keycodes_per_modifier.serialize(); |
| 26181 | let mut request0 = vec![ |
| 26182 | SET_MODIFIER_MAPPING_REQUEST, |
| 26183 | keycodes_per_modifier_bytes[0], |
| 26184 | 0, |
| 26185 | 0, |
| 26186 | ]; |
| 26187 | let length_so_far = length_so_far + request0.len(); |
| 26188 | let length_so_far = length_so_far + self.keycodes.len(); |
| 26189 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 26190 | let length_so_far = length_so_far + padding0.len(); |
| 26191 | assert_eq!(length_so_far % 4, 0); |
| 26192 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 26193 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 26194 | ([request0.into(), self.keycodes, padding0.into()], vec![]) |
| 26195 | } |
| 26196 | /// Parse this request given its header, its body, and any fds that go along with it |
| 26197 | #[cfg (feature = "request-parsing" )] |
| 26198 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 26199 | if header.major_opcode != SET_MODIFIER_MAPPING_REQUEST { |
| 26200 | return Err(ParseError::InvalidValue); |
| 26201 | } |
| 26202 | let remaining = &[header.minor_opcode]; |
| 26203 | let (keycodes_per_modifier, remaining) = u8::try_parse(remaining)?; |
| 26204 | let _ = remaining; |
| 26205 | let (keycodes, remaining) = crate::x11_utils::parse_u8_list(value, u32::from(keycodes_per_modifier).checked_mul(8u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; |
| 26206 | let _ = remaining; |
| 26207 | Ok(SetModifierMappingRequest { |
| 26208 | keycodes: Cow::Borrowed(keycodes), |
| 26209 | }) |
| 26210 | } |
| 26211 | /// Clone all borrowed data in this SetModifierMappingRequest. |
| 26212 | pub fn into_owned(self) -> SetModifierMappingRequest<'static> { |
| 26213 | SetModifierMappingRequest { |
| 26214 | keycodes: Cow::Owned(self.keycodes.into_owned()), |
| 26215 | } |
| 26216 | } |
| 26217 | } |
| 26218 | impl<'input> Request for SetModifierMappingRequest<'input> { |
| 26219 | const EXTENSION_NAME: Option<&'static str> = None; |
| 26220 | |
| 26221 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 26222 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(); |
| 26223 | // Flatten the buffers into a single vector |
| 26224 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 26225 | (buf, fds) |
| 26226 | } |
| 26227 | } |
| 26228 | impl<'input> crate::x11_utils::ReplyRequest for SetModifierMappingRequest<'input> { |
| 26229 | type Reply = SetModifierMappingReply; |
| 26230 | } |
| 26231 | |
| 26232 | #[derive (Clone, Copy, Default)] |
| 26233 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 26234 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 26235 | pub struct SetModifierMappingReply { |
| 26236 | pub status: MappingStatus, |
| 26237 | pub sequence: u16, |
| 26238 | pub length: u32, |
| 26239 | } |
| 26240 | impl_debug_if_no_extra_traits!(SetModifierMappingReply, "SetModifierMappingReply" ); |
| 26241 | impl TryParse for SetModifierMappingReply { |
| 26242 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 26243 | let remaining: &[u8] = initial_value; |
| 26244 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 26245 | let (status: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 26246 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 26247 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 26248 | if response_type != 1 { |
| 26249 | return Err(ParseError::InvalidValue); |
| 26250 | } |
| 26251 | let status: MappingStatus = status.into(); |
| 26252 | let result: SetModifierMappingReply = SetModifierMappingReply { status, sequence, length }; |
| 26253 | let _ = remaining; |
| 26254 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 26255 | .ok_or(err:ParseError::InsufficientData)?; |
| 26256 | Ok((result, remaining)) |
| 26257 | } |
| 26258 | } |
| 26259 | impl Serialize for SetModifierMappingReply { |
| 26260 | type Bytes = [u8; 8]; |
| 26261 | fn serialize(&self) -> [u8; 8] { |
| 26262 | let response_type_bytes = &[1]; |
| 26263 | let status_bytes = u8::from(self.status).serialize(); |
| 26264 | let sequence_bytes = self.sequence.serialize(); |
| 26265 | let length_bytes = self.length.serialize(); |
| 26266 | [ |
| 26267 | response_type_bytes[0], |
| 26268 | status_bytes[0], |
| 26269 | sequence_bytes[0], |
| 26270 | sequence_bytes[1], |
| 26271 | length_bytes[0], |
| 26272 | length_bytes[1], |
| 26273 | length_bytes[2], |
| 26274 | length_bytes[3], |
| 26275 | ] |
| 26276 | } |
| 26277 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 26278 | bytes.reserve(8); |
| 26279 | let response_type_bytes = &[1]; |
| 26280 | bytes.push(response_type_bytes[0]); |
| 26281 | u8::from(self.status).serialize_into(bytes); |
| 26282 | self.sequence.serialize_into(bytes); |
| 26283 | self.length.serialize_into(bytes); |
| 26284 | } |
| 26285 | } |
| 26286 | |
| 26287 | /// Opcode for the GetModifierMapping request |
| 26288 | pub const GET_MODIFIER_MAPPING_REQUEST: u8 = 119; |
| 26289 | #[derive (Clone, Copy, Default)] |
| 26290 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 26291 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 26292 | pub struct GetModifierMappingRequest; |
| 26293 | impl_debug_if_no_extra_traits!(GetModifierMappingRequest, "GetModifierMappingRequest" ); |
| 26294 | impl GetModifierMappingRequest { |
| 26295 | /// Serialize this request into bytes for the provided connection |
| 26296 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 26297 | let length_so_far = 0; |
| 26298 | let mut request0 = vec![ |
| 26299 | GET_MODIFIER_MAPPING_REQUEST, |
| 26300 | 0, |
| 26301 | 0, |
| 26302 | 0, |
| 26303 | ]; |
| 26304 | let length_so_far = length_so_far + request0.len(); |
| 26305 | assert_eq!(length_so_far % 4, 0); |
| 26306 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 26307 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 26308 | ([request0.into()], vec![]) |
| 26309 | } |
| 26310 | /// Parse this request given its header, its body, and any fds that go along with it |
| 26311 | #[cfg (feature = "request-parsing" )] |
| 26312 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 26313 | if header.major_opcode != GET_MODIFIER_MAPPING_REQUEST { |
| 26314 | return Err(ParseError::InvalidValue); |
| 26315 | } |
| 26316 | let remaining = &[header.minor_opcode]; |
| 26317 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 26318 | let _ = remaining; |
| 26319 | let _ = value; |
| 26320 | Ok(GetModifierMappingRequest |
| 26321 | ) |
| 26322 | } |
| 26323 | } |
| 26324 | impl Request for GetModifierMappingRequest { |
| 26325 | const EXTENSION_NAME: Option<&'static str> = None; |
| 26326 | |
| 26327 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 26328 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 26329 | // Flatten the buffers into a single vector |
| 26330 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 26331 | (buf, fds) |
| 26332 | } |
| 26333 | } |
| 26334 | impl crate::x11_utils::ReplyRequest for GetModifierMappingRequest { |
| 26335 | type Reply = GetModifierMappingReply; |
| 26336 | } |
| 26337 | |
| 26338 | #[derive (Clone, Default)] |
| 26339 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 26340 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 26341 | pub struct GetModifierMappingReply { |
| 26342 | pub sequence: u16, |
| 26343 | pub length: u32, |
| 26344 | pub keycodes: Vec<Keycode>, |
| 26345 | } |
| 26346 | impl_debug_if_no_extra_traits!(GetModifierMappingReply, "GetModifierMappingReply" ); |
| 26347 | impl TryParse for GetModifierMappingReply { |
| 26348 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 26349 | let remaining: &[u8] = initial_value; |
| 26350 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 26351 | let (keycodes_per_modifier: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 26352 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 26353 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 26354 | let remaining: &[u8] = remaining.get(24..).ok_or(err:ParseError::InsufficientData)?; |
| 26355 | let (keycodes: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data:remaining, list_length:u32::from(keycodes_per_modifier).checked_mul(8u32).ok_or(err:ParseError::InvalidExpression)?.try_to_usize()?)?; |
| 26356 | let keycodes: Vec = keycodes.to_vec(); |
| 26357 | if response_type != 1 { |
| 26358 | return Err(ParseError::InvalidValue); |
| 26359 | } |
| 26360 | let result: GetModifierMappingReply = GetModifierMappingReply { sequence, length, keycodes }; |
| 26361 | let _ = remaining; |
| 26362 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 26363 | .ok_or(err:ParseError::InsufficientData)?; |
| 26364 | Ok((result, remaining)) |
| 26365 | } |
| 26366 | } |
| 26367 | impl Serialize for GetModifierMappingReply { |
| 26368 | type Bytes = Vec<u8>; |
| 26369 | fn serialize(&self) -> Vec<u8> { |
| 26370 | let mut result: Vec = Vec::new(); |
| 26371 | self.serialize_into(&mut result); |
| 26372 | result |
| 26373 | } |
| 26374 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 26375 | bytes.reserve(additional:32); |
| 26376 | let response_type_bytes: &[u8; 1] = &[1]; |
| 26377 | bytes.push(response_type_bytes[0]); |
| 26378 | assert_eq!(self.keycodes.len() % 8, 0, "`keycodes` has an incorrect length, must be a multiple of 8" ); |
| 26379 | let keycodes_per_modifier: u8 = u8::try_from(self.keycodes.len() / 8).expect(msg:"`keycodes` has too many elements" ); |
| 26380 | keycodes_per_modifier.serialize_into(bytes); |
| 26381 | self.sequence.serialize_into(bytes); |
| 26382 | self.length.serialize_into(bytes); |
| 26383 | bytes.extend_from_slice(&[0; 24]); |
| 26384 | bytes.extend_from_slice(&self.keycodes); |
| 26385 | } |
| 26386 | } |
| 26387 | impl GetModifierMappingReply { |
| 26388 | /// Get the value of the `keycodes_per_modifier` field. |
| 26389 | /// |
| 26390 | /// The `keycodes_per_modifier` field is used as the length field of the `keycodes` field. |
| 26391 | /// This function computes the field's value again based on the length of the list. |
| 26392 | /// |
| 26393 | /// # Panics |
| 26394 | /// |
| 26395 | /// Panics if the value cannot be represented in the target type. This |
| 26396 | /// cannot happen with values of the struct received from the X11 server. |
| 26397 | pub fn keycodes_per_modifier(&self) -> u8 { |
| 26398 | self.keycodes.len() |
| 26399 | .checked_div(8).unwrap() |
| 26400 | .try_into().unwrap() |
| 26401 | } |
| 26402 | } |
| 26403 | |
| 26404 | /// Opcode for the NoOperation request |
| 26405 | pub const NO_OPERATION_REQUEST: u8 = 127; |
| 26406 | #[derive (Clone, Copy, Default)] |
| 26407 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 26408 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 26409 | pub struct NoOperationRequest; |
| 26410 | impl_debug_if_no_extra_traits!(NoOperationRequest, "NoOperationRequest" ); |
| 26411 | impl NoOperationRequest { |
| 26412 | /// Serialize this request into bytes for the provided connection |
| 26413 | pub fn serialize(self) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 26414 | let length_so_far = 0; |
| 26415 | let mut request0 = vec![ |
| 26416 | NO_OPERATION_REQUEST, |
| 26417 | 0, |
| 26418 | 0, |
| 26419 | 0, |
| 26420 | ]; |
| 26421 | let length_so_far = length_so_far + request0.len(); |
| 26422 | assert_eq!(length_so_far % 4, 0); |
| 26423 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 26424 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 26425 | ([request0.into()], vec![]) |
| 26426 | } |
| 26427 | /// Parse this request given its header, its body, and any fds that go along with it |
| 26428 | #[cfg (feature = "request-parsing" )] |
| 26429 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 26430 | if header.major_opcode != NO_OPERATION_REQUEST { |
| 26431 | return Err(ParseError::InvalidValue); |
| 26432 | } |
| 26433 | let remaining = &[header.minor_opcode]; |
| 26434 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 26435 | let _ = remaining; |
| 26436 | let _ = value; |
| 26437 | Ok(NoOperationRequest |
| 26438 | ) |
| 26439 | } |
| 26440 | } |
| 26441 | impl Request for NoOperationRequest { |
| 26442 | const EXTENSION_NAME: Option<&'static str> = None; |
| 26443 | |
| 26444 | fn serialize(self, _major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 26445 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(); |
| 26446 | // Flatten the buffers into a single vector |
| 26447 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 26448 | (buf, fds) |
| 26449 | } |
| 26450 | } |
| 26451 | impl crate::x11_utils::VoidRequest for NoOperationRequest { |
| 26452 | } |
| 26453 | |
| 26454 | |