1 | // This file contains generated code. Do not edit directly. |
2 | // To regenerate this, run 'make'. |
3 | |
4 | //! Bindings to the `XFixes` X11 extension. |
5 | |
6 | #![allow (clippy::too_many_arguments)] |
7 | // The code generator is simpler if it can always use conversions |
8 | #![allow (clippy::useless_conversion)] |
9 | |
10 | #[allow (unused_imports)] |
11 | use alloc::borrow::Cow; |
12 | #[allow (unused_imports)] |
13 | use core::convert::TryInto; |
14 | use alloc::vec; |
15 | use alloc::vec::Vec; |
16 | use core::convert::TryFrom; |
17 | use crate::errors::ParseError; |
18 | #[allow (unused_imports)] |
19 | use crate::x11_utils::TryIntoUSize; |
20 | use crate::BufWithFds; |
21 | #[allow (unused_imports)] |
22 | use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; |
23 | #[allow (unused_imports)] |
24 | use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; |
25 | #[allow (unused_imports)] |
26 | use super::render; |
27 | #[allow (unused_imports)] |
28 | use super::shape; |
29 | #[allow (unused_imports)] |
30 | use super::xproto; |
31 | |
32 | /// The X11 name of the extension for QueryExtension |
33 | pub const X11_EXTENSION_NAME: &str = "XFIXES" ; |
34 | |
35 | /// The version number of this extension that this client library supports. |
36 | /// |
37 | /// This constant contains the version number of this extension that is supported |
38 | /// by this build of x11rb. For most things, it does not make sense to use this |
39 | /// information. If you need to send a `QueryVersion`, it is recommended to instead |
40 | /// send the maximum version of the extension that you need. |
41 | pub const X11_XML_VERSION: (u32, u32) = (6, 0); |
42 | |
43 | /// Opcode for the QueryVersion request |
44 | pub const QUERY_VERSION_REQUEST: u8 = 0; |
45 | #[derive (Clone, Copy, Default)] |
46 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
47 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
48 | pub struct QueryVersionRequest { |
49 | pub client_major_version: u32, |
50 | pub client_minor_version: u32, |
51 | } |
52 | impl_debug_if_no_extra_traits!(QueryVersionRequest, "QueryVersionRequest" ); |
53 | impl QueryVersionRequest { |
54 | /// Serialize this request into bytes for the provided connection |
55 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
56 | let length_so_far = 0; |
57 | let client_major_version_bytes = self.client_major_version.serialize(); |
58 | let client_minor_version_bytes = self.client_minor_version.serialize(); |
59 | let mut request0 = vec![ |
60 | major_opcode, |
61 | QUERY_VERSION_REQUEST, |
62 | 0, |
63 | 0, |
64 | client_major_version_bytes[0], |
65 | client_major_version_bytes[1], |
66 | client_major_version_bytes[2], |
67 | client_major_version_bytes[3], |
68 | client_minor_version_bytes[0], |
69 | client_minor_version_bytes[1], |
70 | client_minor_version_bytes[2], |
71 | client_minor_version_bytes[3], |
72 | ]; |
73 | let length_so_far = length_so_far + request0.len(); |
74 | assert_eq!(length_so_far % 4, 0); |
75 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
76 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
77 | ([request0.into()], vec![]) |
78 | } |
79 | /// Parse this request given its header, its body, and any fds that go along with it |
80 | #[cfg (feature = "request-parsing" )] |
81 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
82 | if header.minor_opcode != QUERY_VERSION_REQUEST { |
83 | return Err(ParseError::InvalidValue); |
84 | } |
85 | let (client_major_version, remaining) = u32::try_parse(value)?; |
86 | let (client_minor_version, remaining) = u32::try_parse(remaining)?; |
87 | let _ = remaining; |
88 | Ok(QueryVersionRequest { |
89 | client_major_version, |
90 | client_minor_version, |
91 | }) |
92 | } |
93 | } |
94 | impl Request for QueryVersionRequest { |
95 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
96 | |
97 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
98 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
99 | // Flatten the buffers into a single vector |
100 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
101 | (buf, fds) |
102 | } |
103 | } |
104 | impl crate::x11_utils::ReplyRequest for QueryVersionRequest { |
105 | type Reply = QueryVersionReply; |
106 | } |
107 | |
108 | #[derive (Clone, Copy, Default)] |
109 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
110 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
111 | pub struct QueryVersionReply { |
112 | pub sequence: u16, |
113 | pub length: u32, |
114 | pub major_version: u32, |
115 | pub minor_version: u32, |
116 | } |
117 | impl_debug_if_no_extra_traits!(QueryVersionReply, "QueryVersionReply" ); |
118 | impl TryParse for QueryVersionReply { |
119 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
120 | let remaining: &[u8] = initial_value; |
121 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
122 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
123 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
124 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
125 | let (major_version: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
126 | let (minor_version: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
127 | let remaining: &[u8] = remaining.get(16..).ok_or(err:ParseError::InsufficientData)?; |
128 | if response_type != 1 { |
129 | return Err(ParseError::InvalidValue); |
130 | } |
131 | let result: QueryVersionReply = QueryVersionReply { sequence, length, major_version, minor_version }; |
132 | let _ = remaining; |
133 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
134 | .ok_or(err:ParseError::InsufficientData)?; |
135 | Ok((result, remaining)) |
136 | } |
137 | } |
138 | impl Serialize for QueryVersionReply { |
139 | type Bytes = [u8; 32]; |
140 | fn serialize(&self) -> [u8; 32] { |
141 | let response_type_bytes = &[1]; |
142 | let sequence_bytes = self.sequence.serialize(); |
143 | let length_bytes = self.length.serialize(); |
144 | let major_version_bytes = self.major_version.serialize(); |
145 | let minor_version_bytes = self.minor_version.serialize(); |
146 | [ |
147 | response_type_bytes[0], |
148 | 0, |
149 | sequence_bytes[0], |
150 | sequence_bytes[1], |
151 | length_bytes[0], |
152 | length_bytes[1], |
153 | length_bytes[2], |
154 | length_bytes[3], |
155 | major_version_bytes[0], |
156 | major_version_bytes[1], |
157 | major_version_bytes[2], |
158 | major_version_bytes[3], |
159 | minor_version_bytes[0], |
160 | minor_version_bytes[1], |
161 | minor_version_bytes[2], |
162 | minor_version_bytes[3], |
163 | 0, |
164 | 0, |
165 | 0, |
166 | 0, |
167 | 0, |
168 | 0, |
169 | 0, |
170 | 0, |
171 | 0, |
172 | 0, |
173 | 0, |
174 | 0, |
175 | 0, |
176 | 0, |
177 | 0, |
178 | 0, |
179 | ] |
180 | } |
181 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
182 | bytes.reserve(32); |
183 | let response_type_bytes = &[1]; |
184 | bytes.push(response_type_bytes[0]); |
185 | bytes.extend_from_slice(&[0; 1]); |
186 | self.sequence.serialize_into(bytes); |
187 | self.length.serialize_into(bytes); |
188 | self.major_version.serialize_into(bytes); |
189 | self.minor_version.serialize_into(bytes); |
190 | bytes.extend_from_slice(&[0; 16]); |
191 | } |
192 | } |
193 | |
194 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
195 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
196 | pub struct SaveSetMode(u8); |
197 | impl SaveSetMode { |
198 | pub const INSERT: Self = Self(0); |
199 | pub const DELETE: Self = Self(1); |
200 | } |
201 | impl From<SaveSetMode> for u8 { |
202 | #[inline ] |
203 | fn from(input: SaveSetMode) -> Self { |
204 | input.0 |
205 | } |
206 | } |
207 | impl From<SaveSetMode> for Option<u8> { |
208 | #[inline ] |
209 | fn from(input: SaveSetMode) -> Self { |
210 | Some(input.0) |
211 | } |
212 | } |
213 | impl From<SaveSetMode> for u16 { |
214 | #[inline ] |
215 | fn from(input: SaveSetMode) -> Self { |
216 | u16::from(input.0) |
217 | } |
218 | } |
219 | impl From<SaveSetMode> for Option<u16> { |
220 | #[inline ] |
221 | fn from(input: SaveSetMode) -> Self { |
222 | Some(u16::from(input.0)) |
223 | } |
224 | } |
225 | impl From<SaveSetMode> for u32 { |
226 | #[inline ] |
227 | fn from(input: SaveSetMode) -> Self { |
228 | u32::from(input.0) |
229 | } |
230 | } |
231 | impl From<SaveSetMode> for Option<u32> { |
232 | #[inline ] |
233 | fn from(input: SaveSetMode) -> Self { |
234 | Some(u32::from(input.0)) |
235 | } |
236 | } |
237 | impl From<u8> for SaveSetMode { |
238 | #[inline ] |
239 | fn from(value: u8) -> Self { |
240 | Self(value) |
241 | } |
242 | } |
243 | impl core::fmt::Debug for SaveSetMode { |
244 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
245 | let variants: [(u32, &str, &str); 2] = [ |
246 | (Self::INSERT.0.into(), "INSERT" , "Insert" ), |
247 | (Self::DELETE.0.into(), "DELETE" , "Delete" ), |
248 | ]; |
249 | pretty_print_enum(fmt, self.0.into(), &variants) |
250 | } |
251 | } |
252 | |
253 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
254 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
255 | pub struct SaveSetTarget(u8); |
256 | impl SaveSetTarget { |
257 | pub const NEAREST: Self = Self(0); |
258 | pub const ROOT: Self = Self(1); |
259 | } |
260 | impl From<SaveSetTarget> for u8 { |
261 | #[inline ] |
262 | fn from(input: SaveSetTarget) -> Self { |
263 | input.0 |
264 | } |
265 | } |
266 | impl From<SaveSetTarget> for Option<u8> { |
267 | #[inline ] |
268 | fn from(input: SaveSetTarget) -> Self { |
269 | Some(input.0) |
270 | } |
271 | } |
272 | impl From<SaveSetTarget> for u16 { |
273 | #[inline ] |
274 | fn from(input: SaveSetTarget) -> Self { |
275 | u16::from(input.0) |
276 | } |
277 | } |
278 | impl From<SaveSetTarget> for Option<u16> { |
279 | #[inline ] |
280 | fn from(input: SaveSetTarget) -> Self { |
281 | Some(u16::from(input.0)) |
282 | } |
283 | } |
284 | impl From<SaveSetTarget> for u32 { |
285 | #[inline ] |
286 | fn from(input: SaveSetTarget) -> Self { |
287 | u32::from(input.0) |
288 | } |
289 | } |
290 | impl From<SaveSetTarget> for Option<u32> { |
291 | #[inline ] |
292 | fn from(input: SaveSetTarget) -> Self { |
293 | Some(u32::from(input.0)) |
294 | } |
295 | } |
296 | impl From<u8> for SaveSetTarget { |
297 | #[inline ] |
298 | fn from(value: u8) -> Self { |
299 | Self(value) |
300 | } |
301 | } |
302 | impl core::fmt::Debug for SaveSetTarget { |
303 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
304 | let variants: [(u32, &str, &str); 2] = [ |
305 | (Self::NEAREST.0.into(), "NEAREST" , "Nearest" ), |
306 | (Self::ROOT.0.into(), "ROOT" , "Root" ), |
307 | ]; |
308 | pretty_print_enum(fmt, self.0.into(), &variants) |
309 | } |
310 | } |
311 | |
312 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
313 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
314 | pub struct SaveSetMapping(u8); |
315 | impl SaveSetMapping { |
316 | pub const MAP: Self = Self(0); |
317 | pub const UNMAP: Self = Self(1); |
318 | } |
319 | impl From<SaveSetMapping> for u8 { |
320 | #[inline ] |
321 | fn from(input: SaveSetMapping) -> Self { |
322 | input.0 |
323 | } |
324 | } |
325 | impl From<SaveSetMapping> for Option<u8> { |
326 | #[inline ] |
327 | fn from(input: SaveSetMapping) -> Self { |
328 | Some(input.0) |
329 | } |
330 | } |
331 | impl From<SaveSetMapping> for u16 { |
332 | #[inline ] |
333 | fn from(input: SaveSetMapping) -> Self { |
334 | u16::from(input.0) |
335 | } |
336 | } |
337 | impl From<SaveSetMapping> for Option<u16> { |
338 | #[inline ] |
339 | fn from(input: SaveSetMapping) -> Self { |
340 | Some(u16::from(input.0)) |
341 | } |
342 | } |
343 | impl From<SaveSetMapping> for u32 { |
344 | #[inline ] |
345 | fn from(input: SaveSetMapping) -> Self { |
346 | u32::from(input.0) |
347 | } |
348 | } |
349 | impl From<SaveSetMapping> for Option<u32> { |
350 | #[inline ] |
351 | fn from(input: SaveSetMapping) -> Self { |
352 | Some(u32::from(input.0)) |
353 | } |
354 | } |
355 | impl From<u8> for SaveSetMapping { |
356 | #[inline ] |
357 | fn from(value: u8) -> Self { |
358 | Self(value) |
359 | } |
360 | } |
361 | impl core::fmt::Debug for SaveSetMapping { |
362 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
363 | let variants: [(u32, &str, &str); 2] = [ |
364 | (Self::MAP.0.into(), "MAP" , "Map" ), |
365 | (Self::UNMAP.0.into(), "UNMAP" , "Unmap" ), |
366 | ]; |
367 | pretty_print_enum(fmt, self.0.into(), &variants) |
368 | } |
369 | } |
370 | |
371 | /// Opcode for the ChangeSaveSet request |
372 | pub const CHANGE_SAVE_SET_REQUEST: u8 = 1; |
373 | #[derive (Clone, Copy, Default)] |
374 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
375 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
376 | pub struct ChangeSaveSetRequest { |
377 | pub mode: SaveSetMode, |
378 | pub target: SaveSetTarget, |
379 | pub map: SaveSetMapping, |
380 | pub window: xproto::Window, |
381 | } |
382 | impl_debug_if_no_extra_traits!(ChangeSaveSetRequest, "ChangeSaveSetRequest" ); |
383 | impl ChangeSaveSetRequest { |
384 | /// Serialize this request into bytes for the provided connection |
385 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
386 | let length_so_far = 0; |
387 | let mode_bytes = u8::from(self.mode).serialize(); |
388 | let target_bytes = u8::from(self.target).serialize(); |
389 | let map_bytes = u8::from(self.map).serialize(); |
390 | let window_bytes = self.window.serialize(); |
391 | let mut request0 = vec![ |
392 | major_opcode, |
393 | CHANGE_SAVE_SET_REQUEST, |
394 | 0, |
395 | 0, |
396 | mode_bytes[0], |
397 | target_bytes[0], |
398 | map_bytes[0], |
399 | 0, |
400 | window_bytes[0], |
401 | window_bytes[1], |
402 | window_bytes[2], |
403 | window_bytes[3], |
404 | ]; |
405 | let length_so_far = length_so_far + request0.len(); |
406 | assert_eq!(length_so_far % 4, 0); |
407 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
408 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
409 | ([request0.into()], vec![]) |
410 | } |
411 | /// Parse this request given its header, its body, and any fds that go along with it |
412 | #[cfg (feature = "request-parsing" )] |
413 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
414 | if header.minor_opcode != CHANGE_SAVE_SET_REQUEST { |
415 | return Err(ParseError::InvalidValue); |
416 | } |
417 | let (mode, remaining) = u8::try_parse(value)?; |
418 | let mode = mode.into(); |
419 | let (target, remaining) = u8::try_parse(remaining)?; |
420 | let target = target.into(); |
421 | let (map, remaining) = u8::try_parse(remaining)?; |
422 | let map = map.into(); |
423 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
424 | let (window, remaining) = xproto::Window::try_parse(remaining)?; |
425 | let _ = remaining; |
426 | Ok(ChangeSaveSetRequest { |
427 | mode, |
428 | target, |
429 | map, |
430 | window, |
431 | }) |
432 | } |
433 | } |
434 | impl Request for ChangeSaveSetRequest { |
435 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
436 | |
437 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
438 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
439 | // Flatten the buffers into a single vector |
440 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
441 | (buf, fds) |
442 | } |
443 | } |
444 | impl crate::x11_utils::VoidRequest for ChangeSaveSetRequest { |
445 | } |
446 | |
447 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
448 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
449 | pub struct SelectionEvent(u8); |
450 | impl SelectionEvent { |
451 | pub const SET_SELECTION_OWNER: Self = Self(0); |
452 | pub const SELECTION_WINDOW_DESTROY: Self = Self(1); |
453 | pub const SELECTION_CLIENT_CLOSE: Self = Self(2); |
454 | } |
455 | impl From<SelectionEvent> for u8 { |
456 | #[inline ] |
457 | fn from(input: SelectionEvent) -> Self { |
458 | input.0 |
459 | } |
460 | } |
461 | impl From<SelectionEvent> for Option<u8> { |
462 | #[inline ] |
463 | fn from(input: SelectionEvent) -> Self { |
464 | Some(input.0) |
465 | } |
466 | } |
467 | impl From<SelectionEvent> for u16 { |
468 | #[inline ] |
469 | fn from(input: SelectionEvent) -> Self { |
470 | u16::from(input.0) |
471 | } |
472 | } |
473 | impl From<SelectionEvent> for Option<u16> { |
474 | #[inline ] |
475 | fn from(input: SelectionEvent) -> Self { |
476 | Some(u16::from(input.0)) |
477 | } |
478 | } |
479 | impl From<SelectionEvent> for u32 { |
480 | #[inline ] |
481 | fn from(input: SelectionEvent) -> Self { |
482 | u32::from(input.0) |
483 | } |
484 | } |
485 | impl From<SelectionEvent> for Option<u32> { |
486 | #[inline ] |
487 | fn from(input: SelectionEvent) -> Self { |
488 | Some(u32::from(input.0)) |
489 | } |
490 | } |
491 | impl From<u8> for SelectionEvent { |
492 | #[inline ] |
493 | fn from(value: u8) -> Self { |
494 | Self(value) |
495 | } |
496 | } |
497 | impl core::fmt::Debug for SelectionEvent { |
498 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
499 | let variants: [(u32, &str, &str); 3] = [ |
500 | (Self::SET_SELECTION_OWNER.0.into(), "SET_SELECTION_OWNER" , "SetSelectionOwner" ), |
501 | (Self::SELECTION_WINDOW_DESTROY.0.into(), "SELECTION_WINDOW_DESTROY" , "SelectionWindowDestroy" ), |
502 | (Self::SELECTION_CLIENT_CLOSE.0.into(), "SELECTION_CLIENT_CLOSE" , "SelectionClientClose" ), |
503 | ]; |
504 | pretty_print_enum(fmt, self.0.into(), &variants) |
505 | } |
506 | } |
507 | |
508 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
509 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
510 | pub struct SelectionEventMask(u32); |
511 | impl SelectionEventMask { |
512 | pub const SET_SELECTION_OWNER: Self = Self(1 << 0); |
513 | pub const SELECTION_WINDOW_DESTROY: Self = Self(1 << 1); |
514 | pub const SELECTION_CLIENT_CLOSE: Self = Self(1 << 2); |
515 | } |
516 | impl From<SelectionEventMask> for u32 { |
517 | #[inline ] |
518 | fn from(input: SelectionEventMask) -> Self { |
519 | input.0 |
520 | } |
521 | } |
522 | impl From<SelectionEventMask> for Option<u32> { |
523 | #[inline ] |
524 | fn from(input: SelectionEventMask) -> Self { |
525 | Some(input.0) |
526 | } |
527 | } |
528 | impl From<u8> for SelectionEventMask { |
529 | #[inline ] |
530 | fn from(value: u8) -> Self { |
531 | Self(value.into()) |
532 | } |
533 | } |
534 | impl From<u16> for SelectionEventMask { |
535 | #[inline ] |
536 | fn from(value: u16) -> Self { |
537 | Self(value.into()) |
538 | } |
539 | } |
540 | impl From<u32> for SelectionEventMask { |
541 | #[inline ] |
542 | fn from(value: u32) -> Self { |
543 | Self(value) |
544 | } |
545 | } |
546 | impl core::fmt::Debug for SelectionEventMask { |
547 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
548 | let variants: [(u32, &str, &str); 3] = [ |
549 | (Self::SET_SELECTION_OWNER.0, "SET_SELECTION_OWNER" , "SetSelectionOwner" ), |
550 | (Self::SELECTION_WINDOW_DESTROY.0, "SELECTION_WINDOW_DESTROY" , "SelectionWindowDestroy" ), |
551 | (Self::SELECTION_CLIENT_CLOSE.0, "SELECTION_CLIENT_CLOSE" , "SelectionClientClose" ), |
552 | ]; |
553 | pretty_print_bitmask(fmt, self.0, &variants) |
554 | } |
555 | } |
556 | bitmask_binop!(SelectionEventMask, u32); |
557 | |
558 | /// Opcode for the SelectionNotify event |
559 | pub const SELECTION_NOTIFY_EVENT: u8 = 0; |
560 | #[derive (Clone, Copy, Default)] |
561 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
562 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
563 | pub struct SelectionNotifyEvent { |
564 | pub response_type: u8, |
565 | pub subtype: SelectionEvent, |
566 | pub sequence: u16, |
567 | pub window: xproto::Window, |
568 | pub owner: xproto::Window, |
569 | pub selection: xproto::Atom, |
570 | pub timestamp: xproto::Timestamp, |
571 | pub selection_timestamp: xproto::Timestamp, |
572 | } |
573 | impl_debug_if_no_extra_traits!(SelectionNotifyEvent, "SelectionNotifyEvent" ); |
574 | impl TryParse for SelectionNotifyEvent { |
575 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
576 | let remaining: &[u8] = initial_value; |
577 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
578 | let (subtype: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
579 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
580 | let (window: u32, remaining: &[u8]) = xproto::Window::try_parse(remaining)?; |
581 | let (owner: u32, remaining: &[u8]) = xproto::Window::try_parse(remaining)?; |
582 | let (selection: u32, remaining: &[u8]) = xproto::Atom::try_parse(remaining)?; |
583 | let (timestamp: u32, remaining: &[u8]) = xproto::Timestamp::try_parse(remaining)?; |
584 | let (selection_timestamp: u32, remaining: &[u8]) = xproto::Timestamp::try_parse(remaining)?; |
585 | let remaining: &[u8] = remaining.get(8..).ok_or(err:ParseError::InsufficientData)?; |
586 | let subtype: SelectionEvent = subtype.into(); |
587 | let result: SelectionNotifyEvent = SelectionNotifyEvent { response_type, subtype, sequence, window, owner, selection, timestamp, selection_timestamp }; |
588 | let _ = remaining; |
589 | let remaining: &[u8] = initial_value.get(32..) |
590 | .ok_or(err:ParseError::InsufficientData)?; |
591 | Ok((result, remaining)) |
592 | } |
593 | } |
594 | impl Serialize for SelectionNotifyEvent { |
595 | type Bytes = [u8; 32]; |
596 | fn serialize(&self) -> [u8; 32] { |
597 | let response_type_bytes = self.response_type.serialize(); |
598 | let subtype_bytes = u8::from(self.subtype).serialize(); |
599 | let sequence_bytes = self.sequence.serialize(); |
600 | let window_bytes = self.window.serialize(); |
601 | let owner_bytes = self.owner.serialize(); |
602 | let selection_bytes = self.selection.serialize(); |
603 | let timestamp_bytes = self.timestamp.serialize(); |
604 | let selection_timestamp_bytes = self.selection_timestamp.serialize(); |
605 | [ |
606 | response_type_bytes[0], |
607 | subtype_bytes[0], |
608 | sequence_bytes[0], |
609 | sequence_bytes[1], |
610 | window_bytes[0], |
611 | window_bytes[1], |
612 | window_bytes[2], |
613 | window_bytes[3], |
614 | owner_bytes[0], |
615 | owner_bytes[1], |
616 | owner_bytes[2], |
617 | owner_bytes[3], |
618 | selection_bytes[0], |
619 | selection_bytes[1], |
620 | selection_bytes[2], |
621 | selection_bytes[3], |
622 | timestamp_bytes[0], |
623 | timestamp_bytes[1], |
624 | timestamp_bytes[2], |
625 | timestamp_bytes[3], |
626 | selection_timestamp_bytes[0], |
627 | selection_timestamp_bytes[1], |
628 | selection_timestamp_bytes[2], |
629 | selection_timestamp_bytes[3], |
630 | 0, |
631 | 0, |
632 | 0, |
633 | 0, |
634 | 0, |
635 | 0, |
636 | 0, |
637 | 0, |
638 | ] |
639 | } |
640 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
641 | bytes.reserve(32); |
642 | self.response_type.serialize_into(bytes); |
643 | u8::from(self.subtype).serialize_into(bytes); |
644 | self.sequence.serialize_into(bytes); |
645 | self.window.serialize_into(bytes); |
646 | self.owner.serialize_into(bytes); |
647 | self.selection.serialize_into(bytes); |
648 | self.timestamp.serialize_into(bytes); |
649 | self.selection_timestamp.serialize_into(bytes); |
650 | bytes.extend_from_slice(&[0; 8]); |
651 | } |
652 | } |
653 | impl From<&SelectionNotifyEvent> for [u8; 32] { |
654 | fn from(input: &SelectionNotifyEvent) -> Self { |
655 | let response_type_bytes = input.response_type.serialize(); |
656 | let subtype_bytes = u8::from(input.subtype).serialize(); |
657 | let sequence_bytes = input.sequence.serialize(); |
658 | let window_bytes = input.window.serialize(); |
659 | let owner_bytes = input.owner.serialize(); |
660 | let selection_bytes = input.selection.serialize(); |
661 | let timestamp_bytes = input.timestamp.serialize(); |
662 | let selection_timestamp_bytes = input.selection_timestamp.serialize(); |
663 | [ |
664 | response_type_bytes[0], |
665 | subtype_bytes[0], |
666 | sequence_bytes[0], |
667 | sequence_bytes[1], |
668 | window_bytes[0], |
669 | window_bytes[1], |
670 | window_bytes[2], |
671 | window_bytes[3], |
672 | owner_bytes[0], |
673 | owner_bytes[1], |
674 | owner_bytes[2], |
675 | owner_bytes[3], |
676 | selection_bytes[0], |
677 | selection_bytes[1], |
678 | selection_bytes[2], |
679 | selection_bytes[3], |
680 | timestamp_bytes[0], |
681 | timestamp_bytes[1], |
682 | timestamp_bytes[2], |
683 | timestamp_bytes[3], |
684 | selection_timestamp_bytes[0], |
685 | selection_timestamp_bytes[1], |
686 | selection_timestamp_bytes[2], |
687 | selection_timestamp_bytes[3], |
688 | 0, |
689 | 0, |
690 | 0, |
691 | 0, |
692 | 0, |
693 | 0, |
694 | 0, |
695 | 0, |
696 | ] |
697 | } |
698 | } |
699 | impl From<SelectionNotifyEvent> for [u8; 32] { |
700 | fn from(input: SelectionNotifyEvent) -> Self { |
701 | Self::from(&input) |
702 | } |
703 | } |
704 | |
705 | /// Opcode for the SelectSelectionInput request |
706 | pub const SELECT_SELECTION_INPUT_REQUEST: u8 = 2; |
707 | #[derive (Clone, Copy, Default)] |
708 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
709 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
710 | pub struct SelectSelectionInputRequest { |
711 | pub window: xproto::Window, |
712 | pub selection: xproto::Atom, |
713 | pub event_mask: SelectionEventMask, |
714 | } |
715 | impl_debug_if_no_extra_traits!(SelectSelectionInputRequest, "SelectSelectionInputRequest" ); |
716 | impl SelectSelectionInputRequest { |
717 | /// Serialize this request into bytes for the provided connection |
718 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
719 | let length_so_far = 0; |
720 | let window_bytes = self.window.serialize(); |
721 | let selection_bytes = self.selection.serialize(); |
722 | let event_mask_bytes = u32::from(self.event_mask).serialize(); |
723 | let mut request0 = vec![ |
724 | major_opcode, |
725 | SELECT_SELECTION_INPUT_REQUEST, |
726 | 0, |
727 | 0, |
728 | window_bytes[0], |
729 | window_bytes[1], |
730 | window_bytes[2], |
731 | window_bytes[3], |
732 | selection_bytes[0], |
733 | selection_bytes[1], |
734 | selection_bytes[2], |
735 | selection_bytes[3], |
736 | event_mask_bytes[0], |
737 | event_mask_bytes[1], |
738 | event_mask_bytes[2], |
739 | event_mask_bytes[3], |
740 | ]; |
741 | let length_so_far = length_so_far + request0.len(); |
742 | assert_eq!(length_so_far % 4, 0); |
743 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
744 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
745 | ([request0.into()], vec![]) |
746 | } |
747 | /// Parse this request given its header, its body, and any fds that go along with it |
748 | #[cfg (feature = "request-parsing" )] |
749 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
750 | if header.minor_opcode != SELECT_SELECTION_INPUT_REQUEST { |
751 | return Err(ParseError::InvalidValue); |
752 | } |
753 | let (window, remaining) = xproto::Window::try_parse(value)?; |
754 | let (selection, remaining) = xproto::Atom::try_parse(remaining)?; |
755 | let (event_mask, remaining) = u32::try_parse(remaining)?; |
756 | let event_mask = event_mask.into(); |
757 | let _ = remaining; |
758 | Ok(SelectSelectionInputRequest { |
759 | window, |
760 | selection, |
761 | event_mask, |
762 | }) |
763 | } |
764 | } |
765 | impl Request for SelectSelectionInputRequest { |
766 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
767 | |
768 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
769 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
770 | // Flatten the buffers into a single vector |
771 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
772 | (buf, fds) |
773 | } |
774 | } |
775 | impl crate::x11_utils::VoidRequest for SelectSelectionInputRequest { |
776 | } |
777 | |
778 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
779 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
780 | pub struct CursorNotify(u8); |
781 | impl CursorNotify { |
782 | pub const DISPLAY_CURSOR: Self = Self(0); |
783 | } |
784 | impl From<CursorNotify> for u8 { |
785 | #[inline ] |
786 | fn from(input: CursorNotify) -> Self { |
787 | input.0 |
788 | } |
789 | } |
790 | impl From<CursorNotify> for Option<u8> { |
791 | #[inline ] |
792 | fn from(input: CursorNotify) -> Self { |
793 | Some(input.0) |
794 | } |
795 | } |
796 | impl From<CursorNotify> for u16 { |
797 | #[inline ] |
798 | fn from(input: CursorNotify) -> Self { |
799 | u16::from(input.0) |
800 | } |
801 | } |
802 | impl From<CursorNotify> for Option<u16> { |
803 | #[inline ] |
804 | fn from(input: CursorNotify) -> Self { |
805 | Some(u16::from(input.0)) |
806 | } |
807 | } |
808 | impl From<CursorNotify> for u32 { |
809 | #[inline ] |
810 | fn from(input: CursorNotify) -> Self { |
811 | u32::from(input.0) |
812 | } |
813 | } |
814 | impl From<CursorNotify> for Option<u32> { |
815 | #[inline ] |
816 | fn from(input: CursorNotify) -> Self { |
817 | Some(u32::from(input.0)) |
818 | } |
819 | } |
820 | impl From<u8> for CursorNotify { |
821 | #[inline ] |
822 | fn from(value: u8) -> Self { |
823 | Self(value) |
824 | } |
825 | } |
826 | impl core::fmt::Debug for CursorNotify { |
827 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
828 | let variants: [(u32, &str, &str); 1] = [ |
829 | (Self::DISPLAY_CURSOR.0.into(), "DISPLAY_CURSOR" , "DisplayCursor" ), |
830 | ]; |
831 | pretty_print_enum(fmt, self.0.into(), &variants) |
832 | } |
833 | } |
834 | |
835 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
836 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
837 | pub struct CursorNotifyMask(u32); |
838 | impl CursorNotifyMask { |
839 | pub const DISPLAY_CURSOR: Self = Self(1 << 0); |
840 | } |
841 | impl From<CursorNotifyMask> for u32 { |
842 | #[inline ] |
843 | fn from(input: CursorNotifyMask) -> Self { |
844 | input.0 |
845 | } |
846 | } |
847 | impl From<CursorNotifyMask> for Option<u32> { |
848 | #[inline ] |
849 | fn from(input: CursorNotifyMask) -> Self { |
850 | Some(input.0) |
851 | } |
852 | } |
853 | impl From<u8> for CursorNotifyMask { |
854 | #[inline ] |
855 | fn from(value: u8) -> Self { |
856 | Self(value.into()) |
857 | } |
858 | } |
859 | impl From<u16> for CursorNotifyMask { |
860 | #[inline ] |
861 | fn from(value: u16) -> Self { |
862 | Self(value.into()) |
863 | } |
864 | } |
865 | impl From<u32> for CursorNotifyMask { |
866 | #[inline ] |
867 | fn from(value: u32) -> Self { |
868 | Self(value) |
869 | } |
870 | } |
871 | impl core::fmt::Debug for CursorNotifyMask { |
872 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
873 | let variants: [(u32, &str, &str); 1] = [ |
874 | (Self::DISPLAY_CURSOR.0, "DISPLAY_CURSOR" , "DisplayCursor" ), |
875 | ]; |
876 | pretty_print_bitmask(fmt, self.0, &variants) |
877 | } |
878 | } |
879 | bitmask_binop!(CursorNotifyMask, u32); |
880 | |
881 | /// Opcode for the CursorNotify event |
882 | pub const CURSOR_NOTIFY_EVENT: u8 = 1; |
883 | #[derive (Clone, Copy, Default)] |
884 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
885 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
886 | pub struct CursorNotifyEvent { |
887 | pub response_type: u8, |
888 | pub subtype: CursorNotify, |
889 | pub sequence: u16, |
890 | pub window: xproto::Window, |
891 | pub cursor_serial: u32, |
892 | pub timestamp: xproto::Timestamp, |
893 | pub name: xproto::Atom, |
894 | } |
895 | impl_debug_if_no_extra_traits!(CursorNotifyEvent, "CursorNotifyEvent" ); |
896 | impl TryParse for CursorNotifyEvent { |
897 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
898 | let remaining: &[u8] = initial_value; |
899 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
900 | let (subtype: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
901 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
902 | let (window: u32, remaining: &[u8]) = xproto::Window::try_parse(remaining)?; |
903 | let (cursor_serial: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
904 | let (timestamp: u32, remaining: &[u8]) = xproto::Timestamp::try_parse(remaining)?; |
905 | let (name: u32, remaining: &[u8]) = xproto::Atom::try_parse(remaining)?; |
906 | let remaining: &[u8] = remaining.get(12..).ok_or(err:ParseError::InsufficientData)?; |
907 | let subtype: CursorNotify = subtype.into(); |
908 | let result: CursorNotifyEvent = CursorNotifyEvent { response_type, subtype, sequence, window, cursor_serial, timestamp, name }; |
909 | let _ = remaining; |
910 | let remaining: &[u8] = initial_value.get(32..) |
911 | .ok_or(err:ParseError::InsufficientData)?; |
912 | Ok((result, remaining)) |
913 | } |
914 | } |
915 | impl Serialize for CursorNotifyEvent { |
916 | type Bytes = [u8; 32]; |
917 | fn serialize(&self) -> [u8; 32] { |
918 | let response_type_bytes = self.response_type.serialize(); |
919 | let subtype_bytes = u8::from(self.subtype).serialize(); |
920 | let sequence_bytes = self.sequence.serialize(); |
921 | let window_bytes = self.window.serialize(); |
922 | let cursor_serial_bytes = self.cursor_serial.serialize(); |
923 | let timestamp_bytes = self.timestamp.serialize(); |
924 | let name_bytes = self.name.serialize(); |
925 | [ |
926 | response_type_bytes[0], |
927 | subtype_bytes[0], |
928 | sequence_bytes[0], |
929 | sequence_bytes[1], |
930 | window_bytes[0], |
931 | window_bytes[1], |
932 | window_bytes[2], |
933 | window_bytes[3], |
934 | cursor_serial_bytes[0], |
935 | cursor_serial_bytes[1], |
936 | cursor_serial_bytes[2], |
937 | cursor_serial_bytes[3], |
938 | timestamp_bytes[0], |
939 | timestamp_bytes[1], |
940 | timestamp_bytes[2], |
941 | timestamp_bytes[3], |
942 | name_bytes[0], |
943 | name_bytes[1], |
944 | name_bytes[2], |
945 | name_bytes[3], |
946 | 0, |
947 | 0, |
948 | 0, |
949 | 0, |
950 | 0, |
951 | 0, |
952 | 0, |
953 | 0, |
954 | 0, |
955 | 0, |
956 | 0, |
957 | 0, |
958 | ] |
959 | } |
960 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
961 | bytes.reserve(32); |
962 | self.response_type.serialize_into(bytes); |
963 | u8::from(self.subtype).serialize_into(bytes); |
964 | self.sequence.serialize_into(bytes); |
965 | self.window.serialize_into(bytes); |
966 | self.cursor_serial.serialize_into(bytes); |
967 | self.timestamp.serialize_into(bytes); |
968 | self.name.serialize_into(bytes); |
969 | bytes.extend_from_slice(&[0; 12]); |
970 | } |
971 | } |
972 | impl From<&CursorNotifyEvent> for [u8; 32] { |
973 | fn from(input: &CursorNotifyEvent) -> Self { |
974 | let response_type_bytes = input.response_type.serialize(); |
975 | let subtype_bytes = u8::from(input.subtype).serialize(); |
976 | let sequence_bytes = input.sequence.serialize(); |
977 | let window_bytes = input.window.serialize(); |
978 | let cursor_serial_bytes = input.cursor_serial.serialize(); |
979 | let timestamp_bytes = input.timestamp.serialize(); |
980 | let name_bytes = input.name.serialize(); |
981 | [ |
982 | response_type_bytes[0], |
983 | subtype_bytes[0], |
984 | sequence_bytes[0], |
985 | sequence_bytes[1], |
986 | window_bytes[0], |
987 | window_bytes[1], |
988 | window_bytes[2], |
989 | window_bytes[3], |
990 | cursor_serial_bytes[0], |
991 | cursor_serial_bytes[1], |
992 | cursor_serial_bytes[2], |
993 | cursor_serial_bytes[3], |
994 | timestamp_bytes[0], |
995 | timestamp_bytes[1], |
996 | timestamp_bytes[2], |
997 | timestamp_bytes[3], |
998 | name_bytes[0], |
999 | name_bytes[1], |
1000 | name_bytes[2], |
1001 | name_bytes[3], |
1002 | 0, |
1003 | 0, |
1004 | 0, |
1005 | 0, |
1006 | 0, |
1007 | 0, |
1008 | 0, |
1009 | 0, |
1010 | 0, |
1011 | 0, |
1012 | 0, |
1013 | 0, |
1014 | ] |
1015 | } |
1016 | } |
1017 | impl From<CursorNotifyEvent> for [u8; 32] { |
1018 | fn from(input: CursorNotifyEvent) -> Self { |
1019 | Self::from(&input) |
1020 | } |
1021 | } |
1022 | |
1023 | /// Opcode for the SelectCursorInput request |
1024 | pub const SELECT_CURSOR_INPUT_REQUEST: u8 = 3; |
1025 | #[derive (Clone, Copy, Default)] |
1026 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
1027 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
1028 | pub struct SelectCursorInputRequest { |
1029 | pub window: xproto::Window, |
1030 | pub event_mask: CursorNotifyMask, |
1031 | } |
1032 | impl_debug_if_no_extra_traits!(SelectCursorInputRequest, "SelectCursorInputRequest" ); |
1033 | impl SelectCursorInputRequest { |
1034 | /// Serialize this request into bytes for the provided connection |
1035 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
1036 | let length_so_far = 0; |
1037 | let window_bytes = self.window.serialize(); |
1038 | let event_mask_bytes = u32::from(self.event_mask).serialize(); |
1039 | let mut request0 = vec![ |
1040 | major_opcode, |
1041 | SELECT_CURSOR_INPUT_REQUEST, |
1042 | 0, |
1043 | 0, |
1044 | window_bytes[0], |
1045 | window_bytes[1], |
1046 | window_bytes[2], |
1047 | window_bytes[3], |
1048 | event_mask_bytes[0], |
1049 | event_mask_bytes[1], |
1050 | event_mask_bytes[2], |
1051 | event_mask_bytes[3], |
1052 | ]; |
1053 | let length_so_far = length_so_far + request0.len(); |
1054 | assert_eq!(length_so_far % 4, 0); |
1055 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
1056 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
1057 | ([request0.into()], vec![]) |
1058 | } |
1059 | /// Parse this request given its header, its body, and any fds that go along with it |
1060 | #[cfg (feature = "request-parsing" )] |
1061 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
1062 | if header.minor_opcode != SELECT_CURSOR_INPUT_REQUEST { |
1063 | return Err(ParseError::InvalidValue); |
1064 | } |
1065 | let (window, remaining) = xproto::Window::try_parse(value)?; |
1066 | let (event_mask, remaining) = u32::try_parse(remaining)?; |
1067 | let event_mask = event_mask.into(); |
1068 | let _ = remaining; |
1069 | Ok(SelectCursorInputRequest { |
1070 | window, |
1071 | event_mask, |
1072 | }) |
1073 | } |
1074 | } |
1075 | impl Request for SelectCursorInputRequest { |
1076 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
1077 | |
1078 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
1079 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
1080 | // Flatten the buffers into a single vector |
1081 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
1082 | (buf, fds) |
1083 | } |
1084 | } |
1085 | impl crate::x11_utils::VoidRequest for SelectCursorInputRequest { |
1086 | } |
1087 | |
1088 | /// Opcode for the GetCursorImage request |
1089 | pub const GET_CURSOR_IMAGE_REQUEST: u8 = 4; |
1090 | #[derive (Clone, Copy, Default)] |
1091 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
1092 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
1093 | pub struct GetCursorImageRequest; |
1094 | impl_debug_if_no_extra_traits!(GetCursorImageRequest, "GetCursorImageRequest" ); |
1095 | impl GetCursorImageRequest { |
1096 | /// Serialize this request into bytes for the provided connection |
1097 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
1098 | let length_so_far = 0; |
1099 | let mut request0 = vec![ |
1100 | major_opcode, |
1101 | GET_CURSOR_IMAGE_REQUEST, |
1102 | 0, |
1103 | 0, |
1104 | ]; |
1105 | let length_so_far = length_so_far + request0.len(); |
1106 | assert_eq!(length_so_far % 4, 0); |
1107 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
1108 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
1109 | ([request0.into()], vec![]) |
1110 | } |
1111 | /// Parse this request given its header, its body, and any fds that go along with it |
1112 | #[cfg (feature = "request-parsing" )] |
1113 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
1114 | if header.minor_opcode != GET_CURSOR_IMAGE_REQUEST { |
1115 | return Err(ParseError::InvalidValue); |
1116 | } |
1117 | let _ = value; |
1118 | Ok(GetCursorImageRequest |
1119 | ) |
1120 | } |
1121 | } |
1122 | impl Request for GetCursorImageRequest { |
1123 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
1124 | |
1125 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
1126 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
1127 | // Flatten the buffers into a single vector |
1128 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
1129 | (buf, fds) |
1130 | } |
1131 | } |
1132 | impl crate::x11_utils::ReplyRequest for GetCursorImageRequest { |
1133 | type Reply = GetCursorImageReply; |
1134 | } |
1135 | |
1136 | #[derive (Clone, Default)] |
1137 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
1138 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
1139 | pub struct GetCursorImageReply { |
1140 | pub sequence: u16, |
1141 | pub length: u32, |
1142 | pub x: i16, |
1143 | pub y: i16, |
1144 | pub width: u16, |
1145 | pub height: u16, |
1146 | pub xhot: u16, |
1147 | pub yhot: u16, |
1148 | pub cursor_serial: u32, |
1149 | pub cursor_image: Vec<u32>, |
1150 | } |
1151 | impl_debug_if_no_extra_traits!(GetCursorImageReply, "GetCursorImageReply" ); |
1152 | impl TryParse for GetCursorImageReply { |
1153 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
1154 | let remaining = initial_value; |
1155 | let (response_type, remaining) = u8::try_parse(remaining)?; |
1156 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
1157 | let (sequence, remaining) = u16::try_parse(remaining)?; |
1158 | let (length, remaining) = u32::try_parse(remaining)?; |
1159 | let (x, remaining) = i16::try_parse(remaining)?; |
1160 | let (y, remaining) = i16::try_parse(remaining)?; |
1161 | let (width, remaining) = u16::try_parse(remaining)?; |
1162 | let (height, remaining) = u16::try_parse(remaining)?; |
1163 | let (xhot, remaining) = u16::try_parse(remaining)?; |
1164 | let (yhot, remaining) = u16::try_parse(remaining)?; |
1165 | let (cursor_serial, remaining) = u32::try_parse(remaining)?; |
1166 | let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?; |
1167 | let (cursor_image, remaining) = crate::x11_utils::parse_list::<u32>(remaining, u32::from(width).checked_mul(u32::from(height)).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; |
1168 | if response_type != 1 { |
1169 | return Err(ParseError::InvalidValue); |
1170 | } |
1171 | let result = GetCursorImageReply { sequence, length, x, y, width, height, xhot, yhot, cursor_serial, cursor_image }; |
1172 | let _ = remaining; |
1173 | let remaining = initial_value.get(32 + length as usize * 4..) |
1174 | .ok_or(ParseError::InsufficientData)?; |
1175 | Ok((result, remaining)) |
1176 | } |
1177 | } |
1178 | impl Serialize for GetCursorImageReply { |
1179 | type Bytes = Vec<u8>; |
1180 | fn serialize(&self) -> Vec<u8> { |
1181 | let mut result = Vec::new(); |
1182 | self.serialize_into(&mut result); |
1183 | result |
1184 | } |
1185 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
1186 | bytes.reserve(32); |
1187 | let response_type_bytes = &[1]; |
1188 | bytes.push(response_type_bytes[0]); |
1189 | bytes.extend_from_slice(&[0; 1]); |
1190 | self.sequence.serialize_into(bytes); |
1191 | self.length.serialize_into(bytes); |
1192 | self.x.serialize_into(bytes); |
1193 | self.y.serialize_into(bytes); |
1194 | self.width.serialize_into(bytes); |
1195 | self.height.serialize_into(bytes); |
1196 | self.xhot.serialize_into(bytes); |
1197 | self.yhot.serialize_into(bytes); |
1198 | self.cursor_serial.serialize_into(bytes); |
1199 | bytes.extend_from_slice(&[0; 8]); |
1200 | assert_eq!(self.cursor_image.len(), usize::try_from(u32::from(self.width).checked_mul(u32::from(self.height)).unwrap()).unwrap(), "`cursor_image` has an incorrect length" ); |
1201 | self.cursor_image.serialize_into(bytes); |
1202 | } |
1203 | } |
1204 | |
1205 | pub type Region = u32; |
1206 | |
1207 | /// Opcode for the BadRegion error |
1208 | pub const BAD_REGION_ERROR: u8 = 0; |
1209 | |
1210 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
1211 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
1212 | pub struct RegionEnum(u8); |
1213 | impl RegionEnum { |
1214 | pub const NONE: Self = Self(0); |
1215 | } |
1216 | impl From<RegionEnum> for u8 { |
1217 | #[inline ] |
1218 | fn from(input: RegionEnum) -> Self { |
1219 | input.0 |
1220 | } |
1221 | } |
1222 | impl From<RegionEnum> for Option<u8> { |
1223 | #[inline ] |
1224 | fn from(input: RegionEnum) -> Self { |
1225 | Some(input.0) |
1226 | } |
1227 | } |
1228 | impl From<RegionEnum> for u16 { |
1229 | #[inline ] |
1230 | fn from(input: RegionEnum) -> Self { |
1231 | u16::from(input.0) |
1232 | } |
1233 | } |
1234 | impl From<RegionEnum> for Option<u16> { |
1235 | #[inline ] |
1236 | fn from(input: RegionEnum) -> Self { |
1237 | Some(u16::from(input.0)) |
1238 | } |
1239 | } |
1240 | impl From<RegionEnum> for u32 { |
1241 | #[inline ] |
1242 | fn from(input: RegionEnum) -> Self { |
1243 | u32::from(input.0) |
1244 | } |
1245 | } |
1246 | impl From<RegionEnum> for Option<u32> { |
1247 | #[inline ] |
1248 | fn from(input: RegionEnum) -> Self { |
1249 | Some(u32::from(input.0)) |
1250 | } |
1251 | } |
1252 | impl From<u8> for RegionEnum { |
1253 | #[inline ] |
1254 | fn from(value: u8) -> Self { |
1255 | Self(value) |
1256 | } |
1257 | } |
1258 | impl core::fmt::Debug for RegionEnum { |
1259 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
1260 | let variants: [(u32, &str, &str); 1] = [ |
1261 | (Self::NONE.0.into(), "NONE" , "None" ), |
1262 | ]; |
1263 | pretty_print_enum(fmt, self.0.into(), &variants) |
1264 | } |
1265 | } |
1266 | |
1267 | /// Opcode for the CreateRegion request |
1268 | pub const CREATE_REGION_REQUEST: u8 = 5; |
1269 | #[derive (Clone, Default)] |
1270 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
1271 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
1272 | pub struct CreateRegionRequest<'input> { |
1273 | pub region: Region, |
1274 | pub rectangles: Cow<'input, [xproto::Rectangle]>, |
1275 | } |
1276 | impl_debug_if_no_extra_traits!(CreateRegionRequest<'_>, "CreateRegionRequest" ); |
1277 | impl<'input> CreateRegionRequest<'input> { |
1278 | /// Serialize this request into bytes for the provided connection |
1279 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
1280 | let length_so_far = 0; |
1281 | let region_bytes = self.region.serialize(); |
1282 | let mut request0 = vec![ |
1283 | major_opcode, |
1284 | CREATE_REGION_REQUEST, |
1285 | 0, |
1286 | 0, |
1287 | region_bytes[0], |
1288 | region_bytes[1], |
1289 | region_bytes[2], |
1290 | region_bytes[3], |
1291 | ]; |
1292 | let length_so_far = length_so_far + request0.len(); |
1293 | let rectangles_bytes = self.rectangles.serialize(); |
1294 | let length_so_far = length_so_far + rectangles_bytes.len(); |
1295 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
1296 | let length_so_far = length_so_far + padding0.len(); |
1297 | assert_eq!(length_so_far % 4, 0); |
1298 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
1299 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
1300 | ([request0.into(), rectangles_bytes.into(), padding0.into()], vec![]) |
1301 | } |
1302 | /// Parse this request given its header, its body, and any fds that go along with it |
1303 | #[cfg (feature = "request-parsing" )] |
1304 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
1305 | if header.minor_opcode != CREATE_REGION_REQUEST { |
1306 | return Err(ParseError::InvalidValue); |
1307 | } |
1308 | let (region, remaining) = Region::try_parse(value)?; |
1309 | let mut remaining = remaining; |
1310 | // Length is 'everything left in the input' |
1311 | let mut rectangles = Vec::new(); |
1312 | while !remaining.is_empty() { |
1313 | let (v, new_remaining) = xproto::Rectangle::try_parse(remaining)?; |
1314 | remaining = new_remaining; |
1315 | rectangles.push(v); |
1316 | } |
1317 | let _ = remaining; |
1318 | Ok(CreateRegionRequest { |
1319 | region, |
1320 | rectangles: Cow::Owned(rectangles), |
1321 | }) |
1322 | } |
1323 | /// Clone all borrowed data in this CreateRegionRequest. |
1324 | pub fn into_owned(self) -> CreateRegionRequest<'static> { |
1325 | CreateRegionRequest { |
1326 | region: self.region, |
1327 | rectangles: Cow::Owned(self.rectangles.into_owned()), |
1328 | } |
1329 | } |
1330 | } |
1331 | impl<'input> Request for CreateRegionRequest<'input> { |
1332 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
1333 | |
1334 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
1335 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(major_opcode); |
1336 | // Flatten the buffers into a single vector |
1337 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
1338 | (buf, fds) |
1339 | } |
1340 | } |
1341 | impl<'input> crate::x11_utils::VoidRequest for CreateRegionRequest<'input> { |
1342 | } |
1343 | |
1344 | /// Opcode for the CreateRegionFromBitmap request |
1345 | pub const CREATE_REGION_FROM_BITMAP_REQUEST: u8 = 6; |
1346 | #[derive (Clone, Copy, Default)] |
1347 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
1348 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
1349 | pub struct CreateRegionFromBitmapRequest { |
1350 | pub region: Region, |
1351 | pub bitmap: xproto::Pixmap, |
1352 | } |
1353 | impl_debug_if_no_extra_traits!(CreateRegionFromBitmapRequest, "CreateRegionFromBitmapRequest" ); |
1354 | impl CreateRegionFromBitmapRequest { |
1355 | /// Serialize this request into bytes for the provided connection |
1356 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
1357 | let length_so_far = 0; |
1358 | let region_bytes = self.region.serialize(); |
1359 | let bitmap_bytes = self.bitmap.serialize(); |
1360 | let mut request0 = vec![ |
1361 | major_opcode, |
1362 | CREATE_REGION_FROM_BITMAP_REQUEST, |
1363 | 0, |
1364 | 0, |
1365 | region_bytes[0], |
1366 | region_bytes[1], |
1367 | region_bytes[2], |
1368 | region_bytes[3], |
1369 | bitmap_bytes[0], |
1370 | bitmap_bytes[1], |
1371 | bitmap_bytes[2], |
1372 | bitmap_bytes[3], |
1373 | ]; |
1374 | let length_so_far = length_so_far + request0.len(); |
1375 | assert_eq!(length_so_far % 4, 0); |
1376 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
1377 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
1378 | ([request0.into()], vec![]) |
1379 | } |
1380 | /// Parse this request given its header, its body, and any fds that go along with it |
1381 | #[cfg (feature = "request-parsing" )] |
1382 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
1383 | if header.minor_opcode != CREATE_REGION_FROM_BITMAP_REQUEST { |
1384 | return Err(ParseError::InvalidValue); |
1385 | } |
1386 | let (region, remaining) = Region::try_parse(value)?; |
1387 | let (bitmap, remaining) = xproto::Pixmap::try_parse(remaining)?; |
1388 | let _ = remaining; |
1389 | Ok(CreateRegionFromBitmapRequest { |
1390 | region, |
1391 | bitmap, |
1392 | }) |
1393 | } |
1394 | } |
1395 | impl Request for CreateRegionFromBitmapRequest { |
1396 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
1397 | |
1398 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
1399 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
1400 | // Flatten the buffers into a single vector |
1401 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
1402 | (buf, fds) |
1403 | } |
1404 | } |
1405 | impl crate::x11_utils::VoidRequest for CreateRegionFromBitmapRequest { |
1406 | } |
1407 | |
1408 | /// Opcode for the CreateRegionFromWindow request |
1409 | pub const CREATE_REGION_FROM_WINDOW_REQUEST: u8 = 7; |
1410 | #[derive (Clone, Copy, Default)] |
1411 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
1412 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
1413 | pub struct CreateRegionFromWindowRequest { |
1414 | pub region: Region, |
1415 | pub window: xproto::Window, |
1416 | pub kind: shape::SK, |
1417 | } |
1418 | impl_debug_if_no_extra_traits!(CreateRegionFromWindowRequest, "CreateRegionFromWindowRequest" ); |
1419 | impl CreateRegionFromWindowRequest { |
1420 | /// Serialize this request into bytes for the provided connection |
1421 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
1422 | let length_so_far = 0; |
1423 | let region_bytes = self.region.serialize(); |
1424 | let window_bytes = self.window.serialize(); |
1425 | let kind_bytes = shape::Kind::from(self.kind).serialize(); |
1426 | let mut request0 = vec![ |
1427 | major_opcode, |
1428 | CREATE_REGION_FROM_WINDOW_REQUEST, |
1429 | 0, |
1430 | 0, |
1431 | region_bytes[0], |
1432 | region_bytes[1], |
1433 | region_bytes[2], |
1434 | region_bytes[3], |
1435 | window_bytes[0], |
1436 | window_bytes[1], |
1437 | window_bytes[2], |
1438 | window_bytes[3], |
1439 | kind_bytes[0], |
1440 | 0, |
1441 | 0, |
1442 | 0, |
1443 | ]; |
1444 | let length_so_far = length_so_far + request0.len(); |
1445 | assert_eq!(length_so_far % 4, 0); |
1446 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
1447 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
1448 | ([request0.into()], vec![]) |
1449 | } |
1450 | /// Parse this request given its header, its body, and any fds that go along with it |
1451 | #[cfg (feature = "request-parsing" )] |
1452 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
1453 | if header.minor_opcode != CREATE_REGION_FROM_WINDOW_REQUEST { |
1454 | return Err(ParseError::InvalidValue); |
1455 | } |
1456 | let (region, remaining) = Region::try_parse(value)?; |
1457 | let (window, remaining) = xproto::Window::try_parse(remaining)?; |
1458 | let (kind, remaining) = shape::Kind::try_parse(remaining)?; |
1459 | let kind = kind.into(); |
1460 | let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; |
1461 | let _ = remaining; |
1462 | Ok(CreateRegionFromWindowRequest { |
1463 | region, |
1464 | window, |
1465 | kind, |
1466 | }) |
1467 | } |
1468 | } |
1469 | impl Request for CreateRegionFromWindowRequest { |
1470 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
1471 | |
1472 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
1473 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
1474 | // Flatten the buffers into a single vector |
1475 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
1476 | (buf, fds) |
1477 | } |
1478 | } |
1479 | impl crate::x11_utils::VoidRequest for CreateRegionFromWindowRequest { |
1480 | } |
1481 | |
1482 | /// Opcode for the CreateRegionFromGC request |
1483 | pub const CREATE_REGION_FROM_GC_REQUEST: u8 = 8; |
1484 | #[derive (Clone, Copy, Default)] |
1485 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
1486 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
1487 | pub struct CreateRegionFromGCRequest { |
1488 | pub region: Region, |
1489 | pub gc: xproto::Gcontext, |
1490 | } |
1491 | impl_debug_if_no_extra_traits!(CreateRegionFromGCRequest, "CreateRegionFromGCRequest" ); |
1492 | impl CreateRegionFromGCRequest { |
1493 | /// Serialize this request into bytes for the provided connection |
1494 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
1495 | let length_so_far = 0; |
1496 | let region_bytes = self.region.serialize(); |
1497 | let gc_bytes = self.gc.serialize(); |
1498 | let mut request0 = vec![ |
1499 | major_opcode, |
1500 | CREATE_REGION_FROM_GC_REQUEST, |
1501 | 0, |
1502 | 0, |
1503 | region_bytes[0], |
1504 | region_bytes[1], |
1505 | region_bytes[2], |
1506 | region_bytes[3], |
1507 | gc_bytes[0], |
1508 | gc_bytes[1], |
1509 | gc_bytes[2], |
1510 | gc_bytes[3], |
1511 | ]; |
1512 | let length_so_far = length_so_far + request0.len(); |
1513 | assert_eq!(length_so_far % 4, 0); |
1514 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
1515 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
1516 | ([request0.into()], vec![]) |
1517 | } |
1518 | /// Parse this request given its header, its body, and any fds that go along with it |
1519 | #[cfg (feature = "request-parsing" )] |
1520 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
1521 | if header.minor_opcode != CREATE_REGION_FROM_GC_REQUEST { |
1522 | return Err(ParseError::InvalidValue); |
1523 | } |
1524 | let (region, remaining) = Region::try_parse(value)?; |
1525 | let (gc, remaining) = xproto::Gcontext::try_parse(remaining)?; |
1526 | let _ = remaining; |
1527 | Ok(CreateRegionFromGCRequest { |
1528 | region, |
1529 | gc, |
1530 | }) |
1531 | } |
1532 | } |
1533 | impl Request for CreateRegionFromGCRequest { |
1534 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
1535 | |
1536 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
1537 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
1538 | // Flatten the buffers into a single vector |
1539 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
1540 | (buf, fds) |
1541 | } |
1542 | } |
1543 | impl crate::x11_utils::VoidRequest for CreateRegionFromGCRequest { |
1544 | } |
1545 | |
1546 | /// Opcode for the CreateRegionFromPicture request |
1547 | pub const CREATE_REGION_FROM_PICTURE_REQUEST: u8 = 9; |
1548 | #[derive (Clone, Copy, Default)] |
1549 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
1550 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
1551 | pub struct CreateRegionFromPictureRequest { |
1552 | pub region: Region, |
1553 | pub picture: render::Picture, |
1554 | } |
1555 | impl_debug_if_no_extra_traits!(CreateRegionFromPictureRequest, "CreateRegionFromPictureRequest" ); |
1556 | impl CreateRegionFromPictureRequest { |
1557 | /// Serialize this request into bytes for the provided connection |
1558 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
1559 | let length_so_far = 0; |
1560 | let region_bytes = self.region.serialize(); |
1561 | let picture_bytes = self.picture.serialize(); |
1562 | let mut request0 = vec![ |
1563 | major_opcode, |
1564 | CREATE_REGION_FROM_PICTURE_REQUEST, |
1565 | 0, |
1566 | 0, |
1567 | region_bytes[0], |
1568 | region_bytes[1], |
1569 | region_bytes[2], |
1570 | region_bytes[3], |
1571 | picture_bytes[0], |
1572 | picture_bytes[1], |
1573 | picture_bytes[2], |
1574 | picture_bytes[3], |
1575 | ]; |
1576 | let length_so_far = length_so_far + request0.len(); |
1577 | assert_eq!(length_so_far % 4, 0); |
1578 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
1579 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
1580 | ([request0.into()], vec![]) |
1581 | } |
1582 | /// Parse this request given its header, its body, and any fds that go along with it |
1583 | #[cfg (feature = "request-parsing" )] |
1584 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
1585 | if header.minor_opcode != CREATE_REGION_FROM_PICTURE_REQUEST { |
1586 | return Err(ParseError::InvalidValue); |
1587 | } |
1588 | let (region, remaining) = Region::try_parse(value)?; |
1589 | let (picture, remaining) = render::Picture::try_parse(remaining)?; |
1590 | let _ = remaining; |
1591 | Ok(CreateRegionFromPictureRequest { |
1592 | region, |
1593 | picture, |
1594 | }) |
1595 | } |
1596 | } |
1597 | impl Request for CreateRegionFromPictureRequest { |
1598 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
1599 | |
1600 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
1601 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
1602 | // Flatten the buffers into a single vector |
1603 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
1604 | (buf, fds) |
1605 | } |
1606 | } |
1607 | impl crate::x11_utils::VoidRequest for CreateRegionFromPictureRequest { |
1608 | } |
1609 | |
1610 | /// Opcode for the DestroyRegion request |
1611 | pub const DESTROY_REGION_REQUEST: u8 = 10; |
1612 | #[derive (Clone, Copy, Default)] |
1613 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
1614 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
1615 | pub struct DestroyRegionRequest { |
1616 | pub region: Region, |
1617 | } |
1618 | impl_debug_if_no_extra_traits!(DestroyRegionRequest, "DestroyRegionRequest" ); |
1619 | impl DestroyRegionRequest { |
1620 | /// Serialize this request into bytes for the provided connection |
1621 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
1622 | let length_so_far = 0; |
1623 | let region_bytes = self.region.serialize(); |
1624 | let mut request0 = vec![ |
1625 | major_opcode, |
1626 | DESTROY_REGION_REQUEST, |
1627 | 0, |
1628 | 0, |
1629 | region_bytes[0], |
1630 | region_bytes[1], |
1631 | region_bytes[2], |
1632 | region_bytes[3], |
1633 | ]; |
1634 | let length_so_far = length_so_far + request0.len(); |
1635 | assert_eq!(length_so_far % 4, 0); |
1636 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
1637 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
1638 | ([request0.into()], vec![]) |
1639 | } |
1640 | /// Parse this request given its header, its body, and any fds that go along with it |
1641 | #[cfg (feature = "request-parsing" )] |
1642 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
1643 | if header.minor_opcode != DESTROY_REGION_REQUEST { |
1644 | return Err(ParseError::InvalidValue); |
1645 | } |
1646 | let (region, remaining) = Region::try_parse(value)?; |
1647 | let _ = remaining; |
1648 | Ok(DestroyRegionRequest { |
1649 | region, |
1650 | }) |
1651 | } |
1652 | } |
1653 | impl Request for DestroyRegionRequest { |
1654 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
1655 | |
1656 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
1657 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
1658 | // Flatten the buffers into a single vector |
1659 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
1660 | (buf, fds) |
1661 | } |
1662 | } |
1663 | impl crate::x11_utils::VoidRequest for DestroyRegionRequest { |
1664 | } |
1665 | |
1666 | /// Opcode for the SetRegion request |
1667 | pub const SET_REGION_REQUEST: u8 = 11; |
1668 | #[derive (Clone, Default)] |
1669 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
1670 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
1671 | pub struct SetRegionRequest<'input> { |
1672 | pub region: Region, |
1673 | pub rectangles: Cow<'input, [xproto::Rectangle]>, |
1674 | } |
1675 | impl_debug_if_no_extra_traits!(SetRegionRequest<'_>, "SetRegionRequest" ); |
1676 | impl<'input> SetRegionRequest<'input> { |
1677 | /// Serialize this request into bytes for the provided connection |
1678 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
1679 | let length_so_far = 0; |
1680 | let region_bytes = self.region.serialize(); |
1681 | let mut request0 = vec![ |
1682 | major_opcode, |
1683 | SET_REGION_REQUEST, |
1684 | 0, |
1685 | 0, |
1686 | region_bytes[0], |
1687 | region_bytes[1], |
1688 | region_bytes[2], |
1689 | region_bytes[3], |
1690 | ]; |
1691 | let length_so_far = length_so_far + request0.len(); |
1692 | let rectangles_bytes = self.rectangles.serialize(); |
1693 | let length_so_far = length_so_far + rectangles_bytes.len(); |
1694 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
1695 | let length_so_far = length_so_far + padding0.len(); |
1696 | assert_eq!(length_so_far % 4, 0); |
1697 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
1698 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
1699 | ([request0.into(), rectangles_bytes.into(), padding0.into()], vec![]) |
1700 | } |
1701 | /// Parse this request given its header, its body, and any fds that go along with it |
1702 | #[cfg (feature = "request-parsing" )] |
1703 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
1704 | if header.minor_opcode != SET_REGION_REQUEST { |
1705 | return Err(ParseError::InvalidValue); |
1706 | } |
1707 | let (region, remaining) = Region::try_parse(value)?; |
1708 | let mut remaining = remaining; |
1709 | // Length is 'everything left in the input' |
1710 | let mut rectangles = Vec::new(); |
1711 | while !remaining.is_empty() { |
1712 | let (v, new_remaining) = xproto::Rectangle::try_parse(remaining)?; |
1713 | remaining = new_remaining; |
1714 | rectangles.push(v); |
1715 | } |
1716 | let _ = remaining; |
1717 | Ok(SetRegionRequest { |
1718 | region, |
1719 | rectangles: Cow::Owned(rectangles), |
1720 | }) |
1721 | } |
1722 | /// Clone all borrowed data in this SetRegionRequest. |
1723 | pub fn into_owned(self) -> SetRegionRequest<'static> { |
1724 | SetRegionRequest { |
1725 | region: self.region, |
1726 | rectangles: Cow::Owned(self.rectangles.into_owned()), |
1727 | } |
1728 | } |
1729 | } |
1730 | impl<'input> Request for SetRegionRequest<'input> { |
1731 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
1732 | |
1733 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
1734 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(major_opcode); |
1735 | // Flatten the buffers into a single vector |
1736 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
1737 | (buf, fds) |
1738 | } |
1739 | } |
1740 | impl<'input> crate::x11_utils::VoidRequest for SetRegionRequest<'input> { |
1741 | } |
1742 | |
1743 | /// Opcode for the CopyRegion request |
1744 | pub const COPY_REGION_REQUEST: u8 = 12; |
1745 | #[derive (Clone, Copy, Default)] |
1746 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
1747 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
1748 | pub struct CopyRegionRequest { |
1749 | pub source: Region, |
1750 | pub destination: Region, |
1751 | } |
1752 | impl_debug_if_no_extra_traits!(CopyRegionRequest, "CopyRegionRequest" ); |
1753 | impl CopyRegionRequest { |
1754 | /// Serialize this request into bytes for the provided connection |
1755 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
1756 | let length_so_far = 0; |
1757 | let source_bytes = self.source.serialize(); |
1758 | let destination_bytes = self.destination.serialize(); |
1759 | let mut request0 = vec![ |
1760 | major_opcode, |
1761 | COPY_REGION_REQUEST, |
1762 | 0, |
1763 | 0, |
1764 | source_bytes[0], |
1765 | source_bytes[1], |
1766 | source_bytes[2], |
1767 | source_bytes[3], |
1768 | destination_bytes[0], |
1769 | destination_bytes[1], |
1770 | destination_bytes[2], |
1771 | destination_bytes[3], |
1772 | ]; |
1773 | let length_so_far = length_so_far + request0.len(); |
1774 | assert_eq!(length_so_far % 4, 0); |
1775 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
1776 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
1777 | ([request0.into()], vec![]) |
1778 | } |
1779 | /// Parse this request given its header, its body, and any fds that go along with it |
1780 | #[cfg (feature = "request-parsing" )] |
1781 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
1782 | if header.minor_opcode != COPY_REGION_REQUEST { |
1783 | return Err(ParseError::InvalidValue); |
1784 | } |
1785 | let (source, remaining) = Region::try_parse(value)?; |
1786 | let (destination, remaining) = Region::try_parse(remaining)?; |
1787 | let _ = remaining; |
1788 | Ok(CopyRegionRequest { |
1789 | source, |
1790 | destination, |
1791 | }) |
1792 | } |
1793 | } |
1794 | impl Request for CopyRegionRequest { |
1795 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
1796 | |
1797 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
1798 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
1799 | // Flatten the buffers into a single vector |
1800 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
1801 | (buf, fds) |
1802 | } |
1803 | } |
1804 | impl crate::x11_utils::VoidRequest for CopyRegionRequest { |
1805 | } |
1806 | |
1807 | /// Opcode for the UnionRegion request |
1808 | pub const UNION_REGION_REQUEST: u8 = 13; |
1809 | #[derive (Clone, Copy, Default)] |
1810 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
1811 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
1812 | pub struct UnionRegionRequest { |
1813 | pub source1: Region, |
1814 | pub source2: Region, |
1815 | pub destination: Region, |
1816 | } |
1817 | impl_debug_if_no_extra_traits!(UnionRegionRequest, "UnionRegionRequest" ); |
1818 | impl UnionRegionRequest { |
1819 | /// Serialize this request into bytes for the provided connection |
1820 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
1821 | let length_so_far = 0; |
1822 | let source1_bytes = self.source1.serialize(); |
1823 | let source2_bytes = self.source2.serialize(); |
1824 | let destination_bytes = self.destination.serialize(); |
1825 | let mut request0 = vec![ |
1826 | major_opcode, |
1827 | UNION_REGION_REQUEST, |
1828 | 0, |
1829 | 0, |
1830 | source1_bytes[0], |
1831 | source1_bytes[1], |
1832 | source1_bytes[2], |
1833 | source1_bytes[3], |
1834 | source2_bytes[0], |
1835 | source2_bytes[1], |
1836 | source2_bytes[2], |
1837 | source2_bytes[3], |
1838 | destination_bytes[0], |
1839 | destination_bytes[1], |
1840 | destination_bytes[2], |
1841 | destination_bytes[3], |
1842 | ]; |
1843 | let length_so_far = length_so_far + request0.len(); |
1844 | assert_eq!(length_so_far % 4, 0); |
1845 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
1846 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
1847 | ([request0.into()], vec![]) |
1848 | } |
1849 | /// Parse this request given its header, its body, and any fds that go along with it |
1850 | #[cfg (feature = "request-parsing" )] |
1851 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
1852 | if header.minor_opcode != UNION_REGION_REQUEST { |
1853 | return Err(ParseError::InvalidValue); |
1854 | } |
1855 | let (source1, remaining) = Region::try_parse(value)?; |
1856 | let (source2, remaining) = Region::try_parse(remaining)?; |
1857 | let (destination, remaining) = Region::try_parse(remaining)?; |
1858 | let _ = remaining; |
1859 | Ok(UnionRegionRequest { |
1860 | source1, |
1861 | source2, |
1862 | destination, |
1863 | }) |
1864 | } |
1865 | } |
1866 | impl Request for UnionRegionRequest { |
1867 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
1868 | |
1869 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
1870 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
1871 | // Flatten the buffers into a single vector |
1872 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
1873 | (buf, fds) |
1874 | } |
1875 | } |
1876 | impl crate::x11_utils::VoidRequest for UnionRegionRequest { |
1877 | } |
1878 | |
1879 | /// Opcode for the IntersectRegion request |
1880 | pub const INTERSECT_REGION_REQUEST: u8 = 14; |
1881 | #[derive (Clone, Copy, Default)] |
1882 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
1883 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
1884 | pub struct IntersectRegionRequest { |
1885 | pub source1: Region, |
1886 | pub source2: Region, |
1887 | pub destination: Region, |
1888 | } |
1889 | impl_debug_if_no_extra_traits!(IntersectRegionRequest, "IntersectRegionRequest" ); |
1890 | impl IntersectRegionRequest { |
1891 | /// Serialize this request into bytes for the provided connection |
1892 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
1893 | let length_so_far = 0; |
1894 | let source1_bytes = self.source1.serialize(); |
1895 | let source2_bytes = self.source2.serialize(); |
1896 | let destination_bytes = self.destination.serialize(); |
1897 | let mut request0 = vec![ |
1898 | major_opcode, |
1899 | INTERSECT_REGION_REQUEST, |
1900 | 0, |
1901 | 0, |
1902 | source1_bytes[0], |
1903 | source1_bytes[1], |
1904 | source1_bytes[2], |
1905 | source1_bytes[3], |
1906 | source2_bytes[0], |
1907 | source2_bytes[1], |
1908 | source2_bytes[2], |
1909 | source2_bytes[3], |
1910 | destination_bytes[0], |
1911 | destination_bytes[1], |
1912 | destination_bytes[2], |
1913 | destination_bytes[3], |
1914 | ]; |
1915 | let length_so_far = length_so_far + request0.len(); |
1916 | assert_eq!(length_so_far % 4, 0); |
1917 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
1918 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
1919 | ([request0.into()], vec![]) |
1920 | } |
1921 | /// Parse this request given its header, its body, and any fds that go along with it |
1922 | #[cfg (feature = "request-parsing" )] |
1923 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
1924 | if header.minor_opcode != INTERSECT_REGION_REQUEST { |
1925 | return Err(ParseError::InvalidValue); |
1926 | } |
1927 | let (source1, remaining) = Region::try_parse(value)?; |
1928 | let (source2, remaining) = Region::try_parse(remaining)?; |
1929 | let (destination, remaining) = Region::try_parse(remaining)?; |
1930 | let _ = remaining; |
1931 | Ok(IntersectRegionRequest { |
1932 | source1, |
1933 | source2, |
1934 | destination, |
1935 | }) |
1936 | } |
1937 | } |
1938 | impl Request for IntersectRegionRequest { |
1939 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
1940 | |
1941 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
1942 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
1943 | // Flatten the buffers into a single vector |
1944 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
1945 | (buf, fds) |
1946 | } |
1947 | } |
1948 | impl crate::x11_utils::VoidRequest for IntersectRegionRequest { |
1949 | } |
1950 | |
1951 | /// Opcode for the SubtractRegion request |
1952 | pub const SUBTRACT_REGION_REQUEST: u8 = 15; |
1953 | #[derive (Clone, Copy, Default)] |
1954 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
1955 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
1956 | pub struct SubtractRegionRequest { |
1957 | pub source1: Region, |
1958 | pub source2: Region, |
1959 | pub destination: Region, |
1960 | } |
1961 | impl_debug_if_no_extra_traits!(SubtractRegionRequest, "SubtractRegionRequest" ); |
1962 | impl SubtractRegionRequest { |
1963 | /// Serialize this request into bytes for the provided connection |
1964 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
1965 | let length_so_far = 0; |
1966 | let source1_bytes = self.source1.serialize(); |
1967 | let source2_bytes = self.source2.serialize(); |
1968 | let destination_bytes = self.destination.serialize(); |
1969 | let mut request0 = vec![ |
1970 | major_opcode, |
1971 | SUBTRACT_REGION_REQUEST, |
1972 | 0, |
1973 | 0, |
1974 | source1_bytes[0], |
1975 | source1_bytes[1], |
1976 | source1_bytes[2], |
1977 | source1_bytes[3], |
1978 | source2_bytes[0], |
1979 | source2_bytes[1], |
1980 | source2_bytes[2], |
1981 | source2_bytes[3], |
1982 | destination_bytes[0], |
1983 | destination_bytes[1], |
1984 | destination_bytes[2], |
1985 | destination_bytes[3], |
1986 | ]; |
1987 | let length_so_far = length_so_far + request0.len(); |
1988 | assert_eq!(length_so_far % 4, 0); |
1989 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
1990 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
1991 | ([request0.into()], vec![]) |
1992 | } |
1993 | /// Parse this request given its header, its body, and any fds that go along with it |
1994 | #[cfg (feature = "request-parsing" )] |
1995 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
1996 | if header.minor_opcode != SUBTRACT_REGION_REQUEST { |
1997 | return Err(ParseError::InvalidValue); |
1998 | } |
1999 | let (source1, remaining) = Region::try_parse(value)?; |
2000 | let (source2, remaining) = Region::try_parse(remaining)?; |
2001 | let (destination, remaining) = Region::try_parse(remaining)?; |
2002 | let _ = remaining; |
2003 | Ok(SubtractRegionRequest { |
2004 | source1, |
2005 | source2, |
2006 | destination, |
2007 | }) |
2008 | } |
2009 | } |
2010 | impl Request for SubtractRegionRequest { |
2011 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
2012 | |
2013 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
2014 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
2015 | // Flatten the buffers into a single vector |
2016 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
2017 | (buf, fds) |
2018 | } |
2019 | } |
2020 | impl crate::x11_utils::VoidRequest for SubtractRegionRequest { |
2021 | } |
2022 | |
2023 | /// Opcode for the InvertRegion request |
2024 | pub const INVERT_REGION_REQUEST: u8 = 16; |
2025 | #[derive (Clone, Copy, Default)] |
2026 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
2027 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
2028 | pub struct InvertRegionRequest { |
2029 | pub source: Region, |
2030 | pub bounds: xproto::Rectangle, |
2031 | pub destination: Region, |
2032 | } |
2033 | impl_debug_if_no_extra_traits!(InvertRegionRequest, "InvertRegionRequest" ); |
2034 | impl InvertRegionRequest { |
2035 | /// Serialize this request into bytes for the provided connection |
2036 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
2037 | let length_so_far = 0; |
2038 | let source_bytes = self.source.serialize(); |
2039 | let bounds_bytes = self.bounds.serialize(); |
2040 | let destination_bytes = self.destination.serialize(); |
2041 | let mut request0 = vec![ |
2042 | major_opcode, |
2043 | INVERT_REGION_REQUEST, |
2044 | 0, |
2045 | 0, |
2046 | source_bytes[0], |
2047 | source_bytes[1], |
2048 | source_bytes[2], |
2049 | source_bytes[3], |
2050 | bounds_bytes[0], |
2051 | bounds_bytes[1], |
2052 | bounds_bytes[2], |
2053 | bounds_bytes[3], |
2054 | bounds_bytes[4], |
2055 | bounds_bytes[5], |
2056 | bounds_bytes[6], |
2057 | bounds_bytes[7], |
2058 | destination_bytes[0], |
2059 | destination_bytes[1], |
2060 | destination_bytes[2], |
2061 | destination_bytes[3], |
2062 | ]; |
2063 | let length_so_far = length_so_far + request0.len(); |
2064 | assert_eq!(length_so_far % 4, 0); |
2065 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
2066 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
2067 | ([request0.into()], vec![]) |
2068 | } |
2069 | /// Parse this request given its header, its body, and any fds that go along with it |
2070 | #[cfg (feature = "request-parsing" )] |
2071 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
2072 | if header.minor_opcode != INVERT_REGION_REQUEST { |
2073 | return Err(ParseError::InvalidValue); |
2074 | } |
2075 | let (source, remaining) = Region::try_parse(value)?; |
2076 | let (bounds, remaining) = xproto::Rectangle::try_parse(remaining)?; |
2077 | let (destination, remaining) = Region::try_parse(remaining)?; |
2078 | let _ = remaining; |
2079 | Ok(InvertRegionRequest { |
2080 | source, |
2081 | bounds, |
2082 | destination, |
2083 | }) |
2084 | } |
2085 | } |
2086 | impl Request for InvertRegionRequest { |
2087 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
2088 | |
2089 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
2090 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
2091 | // Flatten the buffers into a single vector |
2092 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
2093 | (buf, fds) |
2094 | } |
2095 | } |
2096 | impl crate::x11_utils::VoidRequest for InvertRegionRequest { |
2097 | } |
2098 | |
2099 | /// Opcode for the TranslateRegion request |
2100 | pub const TRANSLATE_REGION_REQUEST: u8 = 17; |
2101 | #[derive (Clone, Copy, Default)] |
2102 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
2103 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
2104 | pub struct TranslateRegionRequest { |
2105 | pub region: Region, |
2106 | pub dx: i16, |
2107 | pub dy: i16, |
2108 | } |
2109 | impl_debug_if_no_extra_traits!(TranslateRegionRequest, "TranslateRegionRequest" ); |
2110 | impl TranslateRegionRequest { |
2111 | /// Serialize this request into bytes for the provided connection |
2112 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
2113 | let length_so_far = 0; |
2114 | let region_bytes = self.region.serialize(); |
2115 | let dx_bytes = self.dx.serialize(); |
2116 | let dy_bytes = self.dy.serialize(); |
2117 | let mut request0 = vec![ |
2118 | major_opcode, |
2119 | TRANSLATE_REGION_REQUEST, |
2120 | 0, |
2121 | 0, |
2122 | region_bytes[0], |
2123 | region_bytes[1], |
2124 | region_bytes[2], |
2125 | region_bytes[3], |
2126 | dx_bytes[0], |
2127 | dx_bytes[1], |
2128 | dy_bytes[0], |
2129 | dy_bytes[1], |
2130 | ]; |
2131 | let length_so_far = length_so_far + request0.len(); |
2132 | assert_eq!(length_so_far % 4, 0); |
2133 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
2134 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
2135 | ([request0.into()], vec![]) |
2136 | } |
2137 | /// Parse this request given its header, its body, and any fds that go along with it |
2138 | #[cfg (feature = "request-parsing" )] |
2139 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
2140 | if header.minor_opcode != TRANSLATE_REGION_REQUEST { |
2141 | return Err(ParseError::InvalidValue); |
2142 | } |
2143 | let (region, remaining) = Region::try_parse(value)?; |
2144 | let (dx, remaining) = i16::try_parse(remaining)?; |
2145 | let (dy, remaining) = i16::try_parse(remaining)?; |
2146 | let _ = remaining; |
2147 | Ok(TranslateRegionRequest { |
2148 | region, |
2149 | dx, |
2150 | dy, |
2151 | }) |
2152 | } |
2153 | } |
2154 | impl Request for TranslateRegionRequest { |
2155 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
2156 | |
2157 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
2158 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
2159 | // Flatten the buffers into a single vector |
2160 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
2161 | (buf, fds) |
2162 | } |
2163 | } |
2164 | impl crate::x11_utils::VoidRequest for TranslateRegionRequest { |
2165 | } |
2166 | |
2167 | /// Opcode for the RegionExtents request |
2168 | pub const REGION_EXTENTS_REQUEST: u8 = 18; |
2169 | #[derive (Clone, Copy, Default)] |
2170 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
2171 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
2172 | pub struct RegionExtentsRequest { |
2173 | pub source: Region, |
2174 | pub destination: Region, |
2175 | } |
2176 | impl_debug_if_no_extra_traits!(RegionExtentsRequest, "RegionExtentsRequest" ); |
2177 | impl RegionExtentsRequest { |
2178 | /// Serialize this request into bytes for the provided connection |
2179 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
2180 | let length_so_far = 0; |
2181 | let source_bytes = self.source.serialize(); |
2182 | let destination_bytes = self.destination.serialize(); |
2183 | let mut request0 = vec![ |
2184 | major_opcode, |
2185 | REGION_EXTENTS_REQUEST, |
2186 | 0, |
2187 | 0, |
2188 | source_bytes[0], |
2189 | source_bytes[1], |
2190 | source_bytes[2], |
2191 | source_bytes[3], |
2192 | destination_bytes[0], |
2193 | destination_bytes[1], |
2194 | destination_bytes[2], |
2195 | destination_bytes[3], |
2196 | ]; |
2197 | let length_so_far = length_so_far + request0.len(); |
2198 | assert_eq!(length_so_far % 4, 0); |
2199 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
2200 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
2201 | ([request0.into()], vec![]) |
2202 | } |
2203 | /// Parse this request given its header, its body, and any fds that go along with it |
2204 | #[cfg (feature = "request-parsing" )] |
2205 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
2206 | if header.minor_opcode != REGION_EXTENTS_REQUEST { |
2207 | return Err(ParseError::InvalidValue); |
2208 | } |
2209 | let (source, remaining) = Region::try_parse(value)?; |
2210 | let (destination, remaining) = Region::try_parse(remaining)?; |
2211 | let _ = remaining; |
2212 | Ok(RegionExtentsRequest { |
2213 | source, |
2214 | destination, |
2215 | }) |
2216 | } |
2217 | } |
2218 | impl Request for RegionExtentsRequest { |
2219 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
2220 | |
2221 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
2222 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
2223 | // Flatten the buffers into a single vector |
2224 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
2225 | (buf, fds) |
2226 | } |
2227 | } |
2228 | impl crate::x11_utils::VoidRequest for RegionExtentsRequest { |
2229 | } |
2230 | |
2231 | /// Opcode for the FetchRegion request |
2232 | pub const FETCH_REGION_REQUEST: u8 = 19; |
2233 | #[derive (Clone, Copy, Default)] |
2234 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
2235 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
2236 | pub struct FetchRegionRequest { |
2237 | pub region: Region, |
2238 | } |
2239 | impl_debug_if_no_extra_traits!(FetchRegionRequest, "FetchRegionRequest" ); |
2240 | impl FetchRegionRequest { |
2241 | /// Serialize this request into bytes for the provided connection |
2242 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
2243 | let length_so_far = 0; |
2244 | let region_bytes = self.region.serialize(); |
2245 | let mut request0 = vec![ |
2246 | major_opcode, |
2247 | FETCH_REGION_REQUEST, |
2248 | 0, |
2249 | 0, |
2250 | region_bytes[0], |
2251 | region_bytes[1], |
2252 | region_bytes[2], |
2253 | region_bytes[3], |
2254 | ]; |
2255 | let length_so_far = length_so_far + request0.len(); |
2256 | assert_eq!(length_so_far % 4, 0); |
2257 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
2258 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
2259 | ([request0.into()], vec![]) |
2260 | } |
2261 | /// Parse this request given its header, its body, and any fds that go along with it |
2262 | #[cfg (feature = "request-parsing" )] |
2263 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
2264 | if header.minor_opcode != FETCH_REGION_REQUEST { |
2265 | return Err(ParseError::InvalidValue); |
2266 | } |
2267 | let (region, remaining) = Region::try_parse(value)?; |
2268 | let _ = remaining; |
2269 | Ok(FetchRegionRequest { |
2270 | region, |
2271 | }) |
2272 | } |
2273 | } |
2274 | impl Request for FetchRegionRequest { |
2275 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
2276 | |
2277 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
2278 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
2279 | // Flatten the buffers into a single vector |
2280 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
2281 | (buf, fds) |
2282 | } |
2283 | } |
2284 | impl crate::x11_utils::ReplyRequest for FetchRegionRequest { |
2285 | type Reply = FetchRegionReply; |
2286 | } |
2287 | |
2288 | #[derive (Clone, Default)] |
2289 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
2290 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
2291 | pub struct FetchRegionReply { |
2292 | pub sequence: u16, |
2293 | pub extents: xproto::Rectangle, |
2294 | pub rectangles: Vec<xproto::Rectangle>, |
2295 | } |
2296 | impl_debug_if_no_extra_traits!(FetchRegionReply, "FetchRegionReply" ); |
2297 | impl TryParse for FetchRegionReply { |
2298 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
2299 | let remaining: &[u8] = initial_value; |
2300 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
2301 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
2302 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
2303 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
2304 | let (extents: Rectangle, remaining: &[u8]) = xproto::Rectangle::try_parse(remaining)?; |
2305 | let remaining: &[u8] = remaining.get(16..).ok_or(err:ParseError::InsufficientData)?; |
2306 | let (rectangles: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<xproto::Rectangle>(data:remaining, list_length:u32::from(length).checked_div(2u32).ok_or(err:ParseError::InvalidExpression)?.try_to_usize()?)?; |
2307 | if response_type != 1 { |
2308 | return Err(ParseError::InvalidValue); |
2309 | } |
2310 | let result: FetchRegionReply = FetchRegionReply { sequence, extents, rectangles }; |
2311 | let _ = remaining; |
2312 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
2313 | .ok_or(err:ParseError::InsufficientData)?; |
2314 | Ok((result, remaining)) |
2315 | } |
2316 | } |
2317 | impl Serialize for FetchRegionReply { |
2318 | type Bytes = Vec<u8>; |
2319 | fn serialize(&self) -> Vec<u8> { |
2320 | let mut result: Vec = Vec::new(); |
2321 | self.serialize_into(&mut result); |
2322 | result |
2323 | } |
2324 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
2325 | bytes.reserve(additional:32); |
2326 | let response_type_bytes: &[u8; 1] = &[1]; |
2327 | bytes.push(response_type_bytes[0]); |
2328 | bytes.extend_from_slice(&[0; 1]); |
2329 | self.sequence.serialize_into(bytes); |
2330 | let length: u32 = u32::try_from(self.rectangles.len()).ok().and_then(|len| len.checked_mul(2)).expect(msg:"`rectangles` has too many elements" ); |
2331 | length.serialize_into(bytes); |
2332 | self.extents.serialize_into(bytes); |
2333 | bytes.extend_from_slice(&[0; 16]); |
2334 | self.rectangles.serialize_into(bytes); |
2335 | } |
2336 | } |
2337 | impl FetchRegionReply { |
2338 | /// Get the value of the `length` field. |
2339 | /// |
2340 | /// The `length` field is used as the length field of the `rectangles` field. |
2341 | /// This function computes the field's value again based on the length of the list. |
2342 | /// |
2343 | /// # Panics |
2344 | /// |
2345 | /// Panics if the value cannot be represented in the target type. This |
2346 | /// cannot happen with values of the struct received from the X11 server. |
2347 | pub fn length(&self) -> u32 { |
2348 | self.rectangles.len() |
2349 | .checked_mul(2).unwrap() |
2350 | .try_into().unwrap() |
2351 | } |
2352 | } |
2353 | |
2354 | /// Opcode for the SetGCClipRegion request |
2355 | pub const SET_GC_CLIP_REGION_REQUEST: u8 = 20; |
2356 | #[derive (Clone, Copy, Default)] |
2357 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
2358 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
2359 | pub struct SetGCClipRegionRequest { |
2360 | pub gc: xproto::Gcontext, |
2361 | pub region: Region, |
2362 | pub x_origin: i16, |
2363 | pub y_origin: i16, |
2364 | } |
2365 | impl_debug_if_no_extra_traits!(SetGCClipRegionRequest, "SetGCClipRegionRequest" ); |
2366 | impl SetGCClipRegionRequest { |
2367 | /// Serialize this request into bytes for the provided connection |
2368 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
2369 | let length_so_far = 0; |
2370 | let gc_bytes = self.gc.serialize(); |
2371 | let region_bytes = self.region.serialize(); |
2372 | let x_origin_bytes = self.x_origin.serialize(); |
2373 | let y_origin_bytes = self.y_origin.serialize(); |
2374 | let mut request0 = vec![ |
2375 | major_opcode, |
2376 | SET_GC_CLIP_REGION_REQUEST, |
2377 | 0, |
2378 | 0, |
2379 | gc_bytes[0], |
2380 | gc_bytes[1], |
2381 | gc_bytes[2], |
2382 | gc_bytes[3], |
2383 | region_bytes[0], |
2384 | region_bytes[1], |
2385 | region_bytes[2], |
2386 | region_bytes[3], |
2387 | x_origin_bytes[0], |
2388 | x_origin_bytes[1], |
2389 | y_origin_bytes[0], |
2390 | y_origin_bytes[1], |
2391 | ]; |
2392 | let length_so_far = length_so_far + request0.len(); |
2393 | assert_eq!(length_so_far % 4, 0); |
2394 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
2395 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
2396 | ([request0.into()], vec![]) |
2397 | } |
2398 | /// Parse this request given its header, its body, and any fds that go along with it |
2399 | #[cfg (feature = "request-parsing" )] |
2400 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
2401 | if header.minor_opcode != SET_GC_CLIP_REGION_REQUEST { |
2402 | return Err(ParseError::InvalidValue); |
2403 | } |
2404 | let (gc, remaining) = xproto::Gcontext::try_parse(value)?; |
2405 | let (region, remaining) = Region::try_parse(remaining)?; |
2406 | let (x_origin, remaining) = i16::try_parse(remaining)?; |
2407 | let (y_origin, remaining) = i16::try_parse(remaining)?; |
2408 | let _ = remaining; |
2409 | Ok(SetGCClipRegionRequest { |
2410 | gc, |
2411 | region, |
2412 | x_origin, |
2413 | y_origin, |
2414 | }) |
2415 | } |
2416 | } |
2417 | impl Request for SetGCClipRegionRequest { |
2418 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
2419 | |
2420 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
2421 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
2422 | // Flatten the buffers into a single vector |
2423 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
2424 | (buf, fds) |
2425 | } |
2426 | } |
2427 | impl crate::x11_utils::VoidRequest for SetGCClipRegionRequest { |
2428 | } |
2429 | |
2430 | /// Opcode for the SetWindowShapeRegion request |
2431 | pub const SET_WINDOW_SHAPE_REGION_REQUEST: u8 = 21; |
2432 | #[derive (Clone, Copy, Default)] |
2433 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
2434 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
2435 | pub struct SetWindowShapeRegionRequest { |
2436 | pub dest: xproto::Window, |
2437 | pub dest_kind: shape::SK, |
2438 | pub x_offset: i16, |
2439 | pub y_offset: i16, |
2440 | pub region: Region, |
2441 | } |
2442 | impl_debug_if_no_extra_traits!(SetWindowShapeRegionRequest, "SetWindowShapeRegionRequest" ); |
2443 | impl SetWindowShapeRegionRequest { |
2444 | /// Serialize this request into bytes for the provided connection |
2445 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
2446 | let length_so_far = 0; |
2447 | let dest_bytes = self.dest.serialize(); |
2448 | let dest_kind_bytes = shape::Kind::from(self.dest_kind).serialize(); |
2449 | let x_offset_bytes = self.x_offset.serialize(); |
2450 | let y_offset_bytes = self.y_offset.serialize(); |
2451 | let region_bytes = self.region.serialize(); |
2452 | let mut request0 = vec![ |
2453 | major_opcode, |
2454 | SET_WINDOW_SHAPE_REGION_REQUEST, |
2455 | 0, |
2456 | 0, |
2457 | dest_bytes[0], |
2458 | dest_bytes[1], |
2459 | dest_bytes[2], |
2460 | dest_bytes[3], |
2461 | dest_kind_bytes[0], |
2462 | 0, |
2463 | 0, |
2464 | 0, |
2465 | x_offset_bytes[0], |
2466 | x_offset_bytes[1], |
2467 | y_offset_bytes[0], |
2468 | y_offset_bytes[1], |
2469 | region_bytes[0], |
2470 | region_bytes[1], |
2471 | region_bytes[2], |
2472 | region_bytes[3], |
2473 | ]; |
2474 | let length_so_far = length_so_far + request0.len(); |
2475 | assert_eq!(length_so_far % 4, 0); |
2476 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
2477 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
2478 | ([request0.into()], vec![]) |
2479 | } |
2480 | /// Parse this request given its header, its body, and any fds that go along with it |
2481 | #[cfg (feature = "request-parsing" )] |
2482 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
2483 | if header.minor_opcode != SET_WINDOW_SHAPE_REGION_REQUEST { |
2484 | return Err(ParseError::InvalidValue); |
2485 | } |
2486 | let (dest, remaining) = xproto::Window::try_parse(value)?; |
2487 | let (dest_kind, remaining) = shape::Kind::try_parse(remaining)?; |
2488 | let dest_kind = dest_kind.into(); |
2489 | let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; |
2490 | let (x_offset, remaining) = i16::try_parse(remaining)?; |
2491 | let (y_offset, remaining) = i16::try_parse(remaining)?; |
2492 | let (region, remaining) = Region::try_parse(remaining)?; |
2493 | let _ = remaining; |
2494 | Ok(SetWindowShapeRegionRequest { |
2495 | dest, |
2496 | dest_kind, |
2497 | x_offset, |
2498 | y_offset, |
2499 | region, |
2500 | }) |
2501 | } |
2502 | } |
2503 | impl Request for SetWindowShapeRegionRequest { |
2504 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
2505 | |
2506 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
2507 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
2508 | // Flatten the buffers into a single vector |
2509 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
2510 | (buf, fds) |
2511 | } |
2512 | } |
2513 | impl crate::x11_utils::VoidRequest for SetWindowShapeRegionRequest { |
2514 | } |
2515 | |
2516 | /// Opcode for the SetPictureClipRegion request |
2517 | pub const SET_PICTURE_CLIP_REGION_REQUEST: u8 = 22; |
2518 | #[derive (Clone, Copy, Default)] |
2519 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
2520 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
2521 | pub struct SetPictureClipRegionRequest { |
2522 | pub picture: render::Picture, |
2523 | pub region: Region, |
2524 | pub x_origin: i16, |
2525 | pub y_origin: i16, |
2526 | } |
2527 | impl_debug_if_no_extra_traits!(SetPictureClipRegionRequest, "SetPictureClipRegionRequest" ); |
2528 | impl SetPictureClipRegionRequest { |
2529 | /// Serialize this request into bytes for the provided connection |
2530 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
2531 | let length_so_far = 0; |
2532 | let picture_bytes = self.picture.serialize(); |
2533 | let region_bytes = self.region.serialize(); |
2534 | let x_origin_bytes = self.x_origin.serialize(); |
2535 | let y_origin_bytes = self.y_origin.serialize(); |
2536 | let mut request0 = vec![ |
2537 | major_opcode, |
2538 | SET_PICTURE_CLIP_REGION_REQUEST, |
2539 | 0, |
2540 | 0, |
2541 | picture_bytes[0], |
2542 | picture_bytes[1], |
2543 | picture_bytes[2], |
2544 | picture_bytes[3], |
2545 | region_bytes[0], |
2546 | region_bytes[1], |
2547 | region_bytes[2], |
2548 | region_bytes[3], |
2549 | x_origin_bytes[0], |
2550 | x_origin_bytes[1], |
2551 | y_origin_bytes[0], |
2552 | y_origin_bytes[1], |
2553 | ]; |
2554 | let length_so_far = length_so_far + request0.len(); |
2555 | assert_eq!(length_so_far % 4, 0); |
2556 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
2557 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
2558 | ([request0.into()], vec![]) |
2559 | } |
2560 | /// Parse this request given its header, its body, and any fds that go along with it |
2561 | #[cfg (feature = "request-parsing" )] |
2562 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
2563 | if header.minor_opcode != SET_PICTURE_CLIP_REGION_REQUEST { |
2564 | return Err(ParseError::InvalidValue); |
2565 | } |
2566 | let (picture, remaining) = render::Picture::try_parse(value)?; |
2567 | let (region, remaining) = Region::try_parse(remaining)?; |
2568 | let (x_origin, remaining) = i16::try_parse(remaining)?; |
2569 | let (y_origin, remaining) = i16::try_parse(remaining)?; |
2570 | let _ = remaining; |
2571 | Ok(SetPictureClipRegionRequest { |
2572 | picture, |
2573 | region, |
2574 | x_origin, |
2575 | y_origin, |
2576 | }) |
2577 | } |
2578 | } |
2579 | impl Request for SetPictureClipRegionRequest { |
2580 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
2581 | |
2582 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
2583 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
2584 | // Flatten the buffers into a single vector |
2585 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
2586 | (buf, fds) |
2587 | } |
2588 | } |
2589 | impl crate::x11_utils::VoidRequest for SetPictureClipRegionRequest { |
2590 | } |
2591 | |
2592 | /// Opcode for the SetCursorName request |
2593 | pub const SET_CURSOR_NAME_REQUEST: u8 = 23; |
2594 | #[derive (Clone, Default)] |
2595 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
2596 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
2597 | pub struct SetCursorNameRequest<'input> { |
2598 | pub cursor: xproto::Cursor, |
2599 | pub name: Cow<'input, [u8]>, |
2600 | } |
2601 | impl_debug_if_no_extra_traits!(SetCursorNameRequest<'_>, "SetCursorNameRequest" ); |
2602 | impl<'input> SetCursorNameRequest<'input> { |
2603 | /// Serialize this request into bytes for the provided connection |
2604 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
2605 | let length_so_far = 0; |
2606 | let cursor_bytes = self.cursor.serialize(); |
2607 | let nbytes = u16::try_from(self.name.len()).expect("`name` has too many elements" ); |
2608 | let nbytes_bytes = nbytes.serialize(); |
2609 | let mut request0 = vec![ |
2610 | major_opcode, |
2611 | SET_CURSOR_NAME_REQUEST, |
2612 | 0, |
2613 | 0, |
2614 | cursor_bytes[0], |
2615 | cursor_bytes[1], |
2616 | cursor_bytes[2], |
2617 | cursor_bytes[3], |
2618 | nbytes_bytes[0], |
2619 | nbytes_bytes[1], |
2620 | 0, |
2621 | 0, |
2622 | ]; |
2623 | let length_so_far = length_so_far + request0.len(); |
2624 | let length_so_far = length_so_far + self.name.len(); |
2625 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
2626 | let length_so_far = length_so_far + padding0.len(); |
2627 | assert_eq!(length_so_far % 4, 0); |
2628 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
2629 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
2630 | ([request0.into(), self.name, padding0.into()], vec![]) |
2631 | } |
2632 | /// Parse this request given its header, its body, and any fds that go along with it |
2633 | #[cfg (feature = "request-parsing" )] |
2634 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
2635 | if header.minor_opcode != SET_CURSOR_NAME_REQUEST { |
2636 | return Err(ParseError::InvalidValue); |
2637 | } |
2638 | let (cursor, remaining) = xproto::Cursor::try_parse(value)?; |
2639 | let (nbytes, remaining) = u16::try_parse(remaining)?; |
2640 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
2641 | let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, nbytes.try_to_usize()?)?; |
2642 | let _ = remaining; |
2643 | Ok(SetCursorNameRequest { |
2644 | cursor, |
2645 | name: Cow::Borrowed(name), |
2646 | }) |
2647 | } |
2648 | /// Clone all borrowed data in this SetCursorNameRequest. |
2649 | pub fn into_owned(self) -> SetCursorNameRequest<'static> { |
2650 | SetCursorNameRequest { |
2651 | cursor: self.cursor, |
2652 | name: Cow::Owned(self.name.into_owned()), |
2653 | } |
2654 | } |
2655 | } |
2656 | impl<'input> Request for SetCursorNameRequest<'input> { |
2657 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
2658 | |
2659 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
2660 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(major_opcode); |
2661 | // Flatten the buffers into a single vector |
2662 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
2663 | (buf, fds) |
2664 | } |
2665 | } |
2666 | impl<'input> crate::x11_utils::VoidRequest for SetCursorNameRequest<'input> { |
2667 | } |
2668 | |
2669 | /// Opcode for the GetCursorName request |
2670 | pub const GET_CURSOR_NAME_REQUEST: u8 = 24; |
2671 | #[derive (Clone, Copy, Default)] |
2672 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
2673 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
2674 | pub struct GetCursorNameRequest { |
2675 | pub cursor: xproto::Cursor, |
2676 | } |
2677 | impl_debug_if_no_extra_traits!(GetCursorNameRequest, "GetCursorNameRequest" ); |
2678 | impl GetCursorNameRequest { |
2679 | /// Serialize this request into bytes for the provided connection |
2680 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
2681 | let length_so_far = 0; |
2682 | let cursor_bytes = self.cursor.serialize(); |
2683 | let mut request0 = vec![ |
2684 | major_opcode, |
2685 | GET_CURSOR_NAME_REQUEST, |
2686 | 0, |
2687 | 0, |
2688 | cursor_bytes[0], |
2689 | cursor_bytes[1], |
2690 | cursor_bytes[2], |
2691 | cursor_bytes[3], |
2692 | ]; |
2693 | let length_so_far = length_so_far + request0.len(); |
2694 | assert_eq!(length_so_far % 4, 0); |
2695 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
2696 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
2697 | ([request0.into()], vec![]) |
2698 | } |
2699 | /// Parse this request given its header, its body, and any fds that go along with it |
2700 | #[cfg (feature = "request-parsing" )] |
2701 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
2702 | if header.minor_opcode != GET_CURSOR_NAME_REQUEST { |
2703 | return Err(ParseError::InvalidValue); |
2704 | } |
2705 | let (cursor, remaining) = xproto::Cursor::try_parse(value)?; |
2706 | let _ = remaining; |
2707 | Ok(GetCursorNameRequest { |
2708 | cursor, |
2709 | }) |
2710 | } |
2711 | } |
2712 | impl Request for GetCursorNameRequest { |
2713 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
2714 | |
2715 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
2716 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
2717 | // Flatten the buffers into a single vector |
2718 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
2719 | (buf, fds) |
2720 | } |
2721 | } |
2722 | impl crate::x11_utils::ReplyRequest for GetCursorNameRequest { |
2723 | type Reply = GetCursorNameReply; |
2724 | } |
2725 | |
2726 | #[derive (Clone, Default)] |
2727 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
2728 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
2729 | pub struct GetCursorNameReply { |
2730 | pub sequence: u16, |
2731 | pub length: u32, |
2732 | pub atom: xproto::Atom, |
2733 | pub name: Vec<u8>, |
2734 | } |
2735 | impl_debug_if_no_extra_traits!(GetCursorNameReply, "GetCursorNameReply" ); |
2736 | impl TryParse for GetCursorNameReply { |
2737 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
2738 | let remaining: &[u8] = initial_value; |
2739 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
2740 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
2741 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
2742 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
2743 | let (atom: u32, remaining: &[u8]) = xproto::Atom::try_parse(remaining)?; |
2744 | let (nbytes: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
2745 | let remaining: &[u8] = remaining.get(18..).ok_or(err:ParseError::InsufficientData)?; |
2746 | let (name: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data:remaining, list_length:nbytes.try_to_usize()?)?; |
2747 | let name: Vec = name.to_vec(); |
2748 | if response_type != 1 { |
2749 | return Err(ParseError::InvalidValue); |
2750 | } |
2751 | let result: GetCursorNameReply = GetCursorNameReply { sequence, length, atom, name }; |
2752 | let _ = remaining; |
2753 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
2754 | .ok_or(err:ParseError::InsufficientData)?; |
2755 | Ok((result, remaining)) |
2756 | } |
2757 | } |
2758 | impl Serialize for GetCursorNameReply { |
2759 | type Bytes = Vec<u8>; |
2760 | fn serialize(&self) -> Vec<u8> { |
2761 | let mut result: Vec = Vec::new(); |
2762 | self.serialize_into(&mut result); |
2763 | result |
2764 | } |
2765 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
2766 | bytes.reserve(additional:32); |
2767 | let response_type_bytes: &[u8; 1] = &[1]; |
2768 | bytes.push(response_type_bytes[0]); |
2769 | bytes.extend_from_slice(&[0; 1]); |
2770 | self.sequence.serialize_into(bytes); |
2771 | self.length.serialize_into(bytes); |
2772 | self.atom.serialize_into(bytes); |
2773 | let nbytes: u16 = u16::try_from(self.name.len()).expect(msg:"`name` has too many elements" ); |
2774 | nbytes.serialize_into(bytes); |
2775 | bytes.extend_from_slice(&[0; 18]); |
2776 | bytes.extend_from_slice(&self.name); |
2777 | } |
2778 | } |
2779 | impl GetCursorNameReply { |
2780 | /// Get the value of the `nbytes` field. |
2781 | /// |
2782 | /// The `nbytes` field is used as the length field of the `name` field. |
2783 | /// This function computes the field's value again based on the length of the list. |
2784 | /// |
2785 | /// # Panics |
2786 | /// |
2787 | /// Panics if the value cannot be represented in the target type. This |
2788 | /// cannot happen with values of the struct received from the X11 server. |
2789 | pub fn nbytes(&self) -> u16 { |
2790 | self.name.len() |
2791 | .try_into().unwrap() |
2792 | } |
2793 | } |
2794 | |
2795 | /// Opcode for the GetCursorImageAndName request |
2796 | pub const GET_CURSOR_IMAGE_AND_NAME_REQUEST: u8 = 25; |
2797 | #[derive (Clone, Copy, Default)] |
2798 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
2799 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
2800 | pub struct GetCursorImageAndNameRequest; |
2801 | impl_debug_if_no_extra_traits!(GetCursorImageAndNameRequest, "GetCursorImageAndNameRequest" ); |
2802 | impl GetCursorImageAndNameRequest { |
2803 | /// Serialize this request into bytes for the provided connection |
2804 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
2805 | let length_so_far = 0; |
2806 | let mut request0 = vec![ |
2807 | major_opcode, |
2808 | GET_CURSOR_IMAGE_AND_NAME_REQUEST, |
2809 | 0, |
2810 | 0, |
2811 | ]; |
2812 | let length_so_far = length_so_far + request0.len(); |
2813 | assert_eq!(length_so_far % 4, 0); |
2814 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
2815 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
2816 | ([request0.into()], vec![]) |
2817 | } |
2818 | /// Parse this request given its header, its body, and any fds that go along with it |
2819 | #[cfg (feature = "request-parsing" )] |
2820 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
2821 | if header.minor_opcode != GET_CURSOR_IMAGE_AND_NAME_REQUEST { |
2822 | return Err(ParseError::InvalidValue); |
2823 | } |
2824 | let _ = value; |
2825 | Ok(GetCursorImageAndNameRequest |
2826 | ) |
2827 | } |
2828 | } |
2829 | impl Request for GetCursorImageAndNameRequest { |
2830 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
2831 | |
2832 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
2833 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
2834 | // Flatten the buffers into a single vector |
2835 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
2836 | (buf, fds) |
2837 | } |
2838 | } |
2839 | impl crate::x11_utils::ReplyRequest for GetCursorImageAndNameRequest { |
2840 | type Reply = GetCursorImageAndNameReply; |
2841 | } |
2842 | |
2843 | #[derive (Clone, Default)] |
2844 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
2845 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
2846 | pub struct GetCursorImageAndNameReply { |
2847 | pub sequence: u16, |
2848 | pub length: u32, |
2849 | pub x: i16, |
2850 | pub y: i16, |
2851 | pub width: u16, |
2852 | pub height: u16, |
2853 | pub xhot: u16, |
2854 | pub yhot: u16, |
2855 | pub cursor_serial: u32, |
2856 | pub cursor_atom: xproto::Atom, |
2857 | pub cursor_image: Vec<u32>, |
2858 | pub name: Vec<u8>, |
2859 | } |
2860 | impl_debug_if_no_extra_traits!(GetCursorImageAndNameReply, "GetCursorImageAndNameReply" ); |
2861 | impl TryParse for GetCursorImageAndNameReply { |
2862 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
2863 | let remaining = initial_value; |
2864 | let (response_type, remaining) = u8::try_parse(remaining)?; |
2865 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
2866 | let (sequence, remaining) = u16::try_parse(remaining)?; |
2867 | let (length, remaining) = u32::try_parse(remaining)?; |
2868 | let (x, remaining) = i16::try_parse(remaining)?; |
2869 | let (y, remaining) = i16::try_parse(remaining)?; |
2870 | let (width, remaining) = u16::try_parse(remaining)?; |
2871 | let (height, remaining) = u16::try_parse(remaining)?; |
2872 | let (xhot, remaining) = u16::try_parse(remaining)?; |
2873 | let (yhot, remaining) = u16::try_parse(remaining)?; |
2874 | let (cursor_serial, remaining) = u32::try_parse(remaining)?; |
2875 | let (cursor_atom, remaining) = xproto::Atom::try_parse(remaining)?; |
2876 | let (nbytes, remaining) = u16::try_parse(remaining)?; |
2877 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
2878 | let (cursor_image, remaining) = crate::x11_utils::parse_list::<u32>(remaining, u32::from(width).checked_mul(u32::from(height)).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; |
2879 | let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, nbytes.try_to_usize()?)?; |
2880 | let name = name.to_vec(); |
2881 | if response_type != 1 { |
2882 | return Err(ParseError::InvalidValue); |
2883 | } |
2884 | let result = GetCursorImageAndNameReply { sequence, length, x, y, width, height, xhot, yhot, cursor_serial, cursor_atom, cursor_image, name }; |
2885 | let _ = remaining; |
2886 | let remaining = initial_value.get(32 + length as usize * 4..) |
2887 | .ok_or(ParseError::InsufficientData)?; |
2888 | Ok((result, remaining)) |
2889 | } |
2890 | } |
2891 | impl Serialize for GetCursorImageAndNameReply { |
2892 | type Bytes = Vec<u8>; |
2893 | fn serialize(&self) -> Vec<u8> { |
2894 | let mut result = Vec::new(); |
2895 | self.serialize_into(&mut result); |
2896 | result |
2897 | } |
2898 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
2899 | bytes.reserve(32); |
2900 | let response_type_bytes = &[1]; |
2901 | bytes.push(response_type_bytes[0]); |
2902 | bytes.extend_from_slice(&[0; 1]); |
2903 | self.sequence.serialize_into(bytes); |
2904 | self.length.serialize_into(bytes); |
2905 | self.x.serialize_into(bytes); |
2906 | self.y.serialize_into(bytes); |
2907 | self.width.serialize_into(bytes); |
2908 | self.height.serialize_into(bytes); |
2909 | self.xhot.serialize_into(bytes); |
2910 | self.yhot.serialize_into(bytes); |
2911 | self.cursor_serial.serialize_into(bytes); |
2912 | self.cursor_atom.serialize_into(bytes); |
2913 | let nbytes = u16::try_from(self.name.len()).expect("`name` has too many elements" ); |
2914 | nbytes.serialize_into(bytes); |
2915 | bytes.extend_from_slice(&[0; 2]); |
2916 | assert_eq!(self.cursor_image.len(), usize::try_from(u32::from(self.width).checked_mul(u32::from(self.height)).unwrap()).unwrap(), "`cursor_image` has an incorrect length" ); |
2917 | self.cursor_image.serialize_into(bytes); |
2918 | bytes.extend_from_slice(&self.name); |
2919 | } |
2920 | } |
2921 | impl GetCursorImageAndNameReply { |
2922 | /// Get the value of the `nbytes` field. |
2923 | /// |
2924 | /// The `nbytes` field is used as the length field of the `name` field. |
2925 | /// This function computes the field's value again based on the length of the list. |
2926 | /// |
2927 | /// # Panics |
2928 | /// |
2929 | /// Panics if the value cannot be represented in the target type. This |
2930 | /// cannot happen with values of the struct received from the X11 server. |
2931 | pub fn nbytes(&self) -> u16 { |
2932 | self.name.len() |
2933 | .try_into().unwrap() |
2934 | } |
2935 | } |
2936 | |
2937 | /// Opcode for the ChangeCursor request |
2938 | pub const CHANGE_CURSOR_REQUEST: u8 = 26; |
2939 | #[derive (Clone, Copy, Default)] |
2940 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
2941 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
2942 | pub struct ChangeCursorRequest { |
2943 | pub source: xproto::Cursor, |
2944 | pub destination: xproto::Cursor, |
2945 | } |
2946 | impl_debug_if_no_extra_traits!(ChangeCursorRequest, "ChangeCursorRequest" ); |
2947 | impl ChangeCursorRequest { |
2948 | /// Serialize this request into bytes for the provided connection |
2949 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
2950 | let length_so_far = 0; |
2951 | let source_bytes = self.source.serialize(); |
2952 | let destination_bytes = self.destination.serialize(); |
2953 | let mut request0 = vec![ |
2954 | major_opcode, |
2955 | CHANGE_CURSOR_REQUEST, |
2956 | 0, |
2957 | 0, |
2958 | source_bytes[0], |
2959 | source_bytes[1], |
2960 | source_bytes[2], |
2961 | source_bytes[3], |
2962 | destination_bytes[0], |
2963 | destination_bytes[1], |
2964 | destination_bytes[2], |
2965 | destination_bytes[3], |
2966 | ]; |
2967 | let length_so_far = length_so_far + request0.len(); |
2968 | assert_eq!(length_so_far % 4, 0); |
2969 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
2970 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
2971 | ([request0.into()], vec![]) |
2972 | } |
2973 | /// Parse this request given its header, its body, and any fds that go along with it |
2974 | #[cfg (feature = "request-parsing" )] |
2975 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
2976 | if header.minor_opcode != CHANGE_CURSOR_REQUEST { |
2977 | return Err(ParseError::InvalidValue); |
2978 | } |
2979 | let (source, remaining) = xproto::Cursor::try_parse(value)?; |
2980 | let (destination, remaining) = xproto::Cursor::try_parse(remaining)?; |
2981 | let _ = remaining; |
2982 | Ok(ChangeCursorRequest { |
2983 | source, |
2984 | destination, |
2985 | }) |
2986 | } |
2987 | } |
2988 | impl Request for ChangeCursorRequest { |
2989 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
2990 | |
2991 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
2992 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
2993 | // Flatten the buffers into a single vector |
2994 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
2995 | (buf, fds) |
2996 | } |
2997 | } |
2998 | impl crate::x11_utils::VoidRequest for ChangeCursorRequest { |
2999 | } |
3000 | |
3001 | /// Opcode for the ChangeCursorByName request |
3002 | pub const CHANGE_CURSOR_BY_NAME_REQUEST: u8 = 27; |
3003 | #[derive (Clone, Default)] |
3004 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
3005 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
3006 | pub struct ChangeCursorByNameRequest<'input> { |
3007 | pub src: xproto::Cursor, |
3008 | pub name: Cow<'input, [u8]>, |
3009 | } |
3010 | impl_debug_if_no_extra_traits!(ChangeCursorByNameRequest<'_>, "ChangeCursorByNameRequest" ); |
3011 | impl<'input> ChangeCursorByNameRequest<'input> { |
3012 | /// Serialize this request into bytes for the provided connection |
3013 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
3014 | let length_so_far = 0; |
3015 | let src_bytes = self.src.serialize(); |
3016 | let nbytes = u16::try_from(self.name.len()).expect("`name` has too many elements" ); |
3017 | let nbytes_bytes = nbytes.serialize(); |
3018 | let mut request0 = vec![ |
3019 | major_opcode, |
3020 | CHANGE_CURSOR_BY_NAME_REQUEST, |
3021 | 0, |
3022 | 0, |
3023 | src_bytes[0], |
3024 | src_bytes[1], |
3025 | src_bytes[2], |
3026 | src_bytes[3], |
3027 | nbytes_bytes[0], |
3028 | nbytes_bytes[1], |
3029 | 0, |
3030 | 0, |
3031 | ]; |
3032 | let length_so_far = length_so_far + request0.len(); |
3033 | let length_so_far = length_so_far + self.name.len(); |
3034 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
3035 | let length_so_far = length_so_far + padding0.len(); |
3036 | assert_eq!(length_so_far % 4, 0); |
3037 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
3038 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
3039 | ([request0.into(), self.name, padding0.into()], vec![]) |
3040 | } |
3041 | /// Parse this request given its header, its body, and any fds that go along with it |
3042 | #[cfg (feature = "request-parsing" )] |
3043 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
3044 | if header.minor_opcode != CHANGE_CURSOR_BY_NAME_REQUEST { |
3045 | return Err(ParseError::InvalidValue); |
3046 | } |
3047 | let (src, remaining) = xproto::Cursor::try_parse(value)?; |
3048 | let (nbytes, remaining) = u16::try_parse(remaining)?; |
3049 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
3050 | let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, nbytes.try_to_usize()?)?; |
3051 | let _ = remaining; |
3052 | Ok(ChangeCursorByNameRequest { |
3053 | src, |
3054 | name: Cow::Borrowed(name), |
3055 | }) |
3056 | } |
3057 | /// Clone all borrowed data in this ChangeCursorByNameRequest. |
3058 | pub fn into_owned(self) -> ChangeCursorByNameRequest<'static> { |
3059 | ChangeCursorByNameRequest { |
3060 | src: self.src, |
3061 | name: Cow::Owned(self.name.into_owned()), |
3062 | } |
3063 | } |
3064 | } |
3065 | impl<'input> Request for ChangeCursorByNameRequest<'input> { |
3066 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
3067 | |
3068 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
3069 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(major_opcode); |
3070 | // Flatten the buffers into a single vector |
3071 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
3072 | (buf, fds) |
3073 | } |
3074 | } |
3075 | impl<'input> crate::x11_utils::VoidRequest for ChangeCursorByNameRequest<'input> { |
3076 | } |
3077 | |
3078 | /// Opcode for the ExpandRegion request |
3079 | pub const EXPAND_REGION_REQUEST: u8 = 28; |
3080 | #[derive (Clone, Copy, Default)] |
3081 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
3082 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
3083 | pub struct ExpandRegionRequest { |
3084 | pub source: Region, |
3085 | pub destination: Region, |
3086 | pub left: u16, |
3087 | pub right: u16, |
3088 | pub top: u16, |
3089 | pub bottom: u16, |
3090 | } |
3091 | impl_debug_if_no_extra_traits!(ExpandRegionRequest, "ExpandRegionRequest" ); |
3092 | impl ExpandRegionRequest { |
3093 | /// Serialize this request into bytes for the provided connection |
3094 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
3095 | let length_so_far = 0; |
3096 | let source_bytes = self.source.serialize(); |
3097 | let destination_bytes = self.destination.serialize(); |
3098 | let left_bytes = self.left.serialize(); |
3099 | let right_bytes = self.right.serialize(); |
3100 | let top_bytes = self.top.serialize(); |
3101 | let bottom_bytes = self.bottom.serialize(); |
3102 | let mut request0 = vec![ |
3103 | major_opcode, |
3104 | EXPAND_REGION_REQUEST, |
3105 | 0, |
3106 | 0, |
3107 | source_bytes[0], |
3108 | source_bytes[1], |
3109 | source_bytes[2], |
3110 | source_bytes[3], |
3111 | destination_bytes[0], |
3112 | destination_bytes[1], |
3113 | destination_bytes[2], |
3114 | destination_bytes[3], |
3115 | left_bytes[0], |
3116 | left_bytes[1], |
3117 | right_bytes[0], |
3118 | right_bytes[1], |
3119 | top_bytes[0], |
3120 | top_bytes[1], |
3121 | bottom_bytes[0], |
3122 | bottom_bytes[1], |
3123 | ]; |
3124 | let length_so_far = length_so_far + request0.len(); |
3125 | assert_eq!(length_so_far % 4, 0); |
3126 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
3127 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
3128 | ([request0.into()], vec![]) |
3129 | } |
3130 | /// Parse this request given its header, its body, and any fds that go along with it |
3131 | #[cfg (feature = "request-parsing" )] |
3132 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
3133 | if header.minor_opcode != EXPAND_REGION_REQUEST { |
3134 | return Err(ParseError::InvalidValue); |
3135 | } |
3136 | let (source, remaining) = Region::try_parse(value)?; |
3137 | let (destination, remaining) = Region::try_parse(remaining)?; |
3138 | let (left, remaining) = u16::try_parse(remaining)?; |
3139 | let (right, remaining) = u16::try_parse(remaining)?; |
3140 | let (top, remaining) = u16::try_parse(remaining)?; |
3141 | let (bottom, remaining) = u16::try_parse(remaining)?; |
3142 | let _ = remaining; |
3143 | Ok(ExpandRegionRequest { |
3144 | source, |
3145 | destination, |
3146 | left, |
3147 | right, |
3148 | top, |
3149 | bottom, |
3150 | }) |
3151 | } |
3152 | } |
3153 | impl Request for ExpandRegionRequest { |
3154 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
3155 | |
3156 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
3157 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
3158 | // Flatten the buffers into a single vector |
3159 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
3160 | (buf, fds) |
3161 | } |
3162 | } |
3163 | impl crate::x11_utils::VoidRequest for ExpandRegionRequest { |
3164 | } |
3165 | |
3166 | /// Opcode for the HideCursor request |
3167 | pub const HIDE_CURSOR_REQUEST: u8 = 29; |
3168 | #[derive (Clone, Copy, Default)] |
3169 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
3170 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
3171 | pub struct HideCursorRequest { |
3172 | pub window: xproto::Window, |
3173 | } |
3174 | impl_debug_if_no_extra_traits!(HideCursorRequest, "HideCursorRequest" ); |
3175 | impl HideCursorRequest { |
3176 | /// Serialize this request into bytes for the provided connection |
3177 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
3178 | let length_so_far = 0; |
3179 | let window_bytes = self.window.serialize(); |
3180 | let mut request0 = vec![ |
3181 | major_opcode, |
3182 | HIDE_CURSOR_REQUEST, |
3183 | 0, |
3184 | 0, |
3185 | window_bytes[0], |
3186 | window_bytes[1], |
3187 | window_bytes[2], |
3188 | window_bytes[3], |
3189 | ]; |
3190 | let length_so_far = length_so_far + request0.len(); |
3191 | assert_eq!(length_so_far % 4, 0); |
3192 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
3193 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
3194 | ([request0.into()], vec![]) |
3195 | } |
3196 | /// Parse this request given its header, its body, and any fds that go along with it |
3197 | #[cfg (feature = "request-parsing" )] |
3198 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
3199 | if header.minor_opcode != HIDE_CURSOR_REQUEST { |
3200 | return Err(ParseError::InvalidValue); |
3201 | } |
3202 | let (window, remaining) = xproto::Window::try_parse(value)?; |
3203 | let _ = remaining; |
3204 | Ok(HideCursorRequest { |
3205 | window, |
3206 | }) |
3207 | } |
3208 | } |
3209 | impl Request for HideCursorRequest { |
3210 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
3211 | |
3212 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
3213 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
3214 | // Flatten the buffers into a single vector |
3215 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
3216 | (buf, fds) |
3217 | } |
3218 | } |
3219 | impl crate::x11_utils::VoidRequest for HideCursorRequest { |
3220 | } |
3221 | |
3222 | /// Opcode for the ShowCursor request |
3223 | pub const SHOW_CURSOR_REQUEST: u8 = 30; |
3224 | #[derive (Clone, Copy, Default)] |
3225 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
3226 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
3227 | pub struct ShowCursorRequest { |
3228 | pub window: xproto::Window, |
3229 | } |
3230 | impl_debug_if_no_extra_traits!(ShowCursorRequest, "ShowCursorRequest" ); |
3231 | impl ShowCursorRequest { |
3232 | /// Serialize this request into bytes for the provided connection |
3233 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
3234 | let length_so_far = 0; |
3235 | let window_bytes = self.window.serialize(); |
3236 | let mut request0 = vec![ |
3237 | major_opcode, |
3238 | SHOW_CURSOR_REQUEST, |
3239 | 0, |
3240 | 0, |
3241 | window_bytes[0], |
3242 | window_bytes[1], |
3243 | window_bytes[2], |
3244 | window_bytes[3], |
3245 | ]; |
3246 | let length_so_far = length_so_far + request0.len(); |
3247 | assert_eq!(length_so_far % 4, 0); |
3248 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
3249 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
3250 | ([request0.into()], vec![]) |
3251 | } |
3252 | /// Parse this request given its header, its body, and any fds that go along with it |
3253 | #[cfg (feature = "request-parsing" )] |
3254 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
3255 | if header.minor_opcode != SHOW_CURSOR_REQUEST { |
3256 | return Err(ParseError::InvalidValue); |
3257 | } |
3258 | let (window, remaining) = xproto::Window::try_parse(value)?; |
3259 | let _ = remaining; |
3260 | Ok(ShowCursorRequest { |
3261 | window, |
3262 | }) |
3263 | } |
3264 | } |
3265 | impl Request for ShowCursorRequest { |
3266 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
3267 | |
3268 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
3269 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
3270 | // Flatten the buffers into a single vector |
3271 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
3272 | (buf, fds) |
3273 | } |
3274 | } |
3275 | impl crate::x11_utils::VoidRequest for ShowCursorRequest { |
3276 | } |
3277 | |
3278 | pub type Barrier = u32; |
3279 | |
3280 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
3281 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
3282 | pub struct BarrierDirections(u32); |
3283 | impl BarrierDirections { |
3284 | pub const POSITIVE_X: Self = Self(1 << 0); |
3285 | pub const POSITIVE_Y: Self = Self(1 << 1); |
3286 | pub const NEGATIVE_X: Self = Self(1 << 2); |
3287 | pub const NEGATIVE_Y: Self = Self(1 << 3); |
3288 | } |
3289 | impl From<BarrierDirections> for u32 { |
3290 | #[inline ] |
3291 | fn from(input: BarrierDirections) -> Self { |
3292 | input.0 |
3293 | } |
3294 | } |
3295 | impl From<BarrierDirections> for Option<u32> { |
3296 | #[inline ] |
3297 | fn from(input: BarrierDirections) -> Self { |
3298 | Some(input.0) |
3299 | } |
3300 | } |
3301 | impl From<u8> for BarrierDirections { |
3302 | #[inline ] |
3303 | fn from(value: u8) -> Self { |
3304 | Self(value.into()) |
3305 | } |
3306 | } |
3307 | impl From<u16> for BarrierDirections { |
3308 | #[inline ] |
3309 | fn from(value: u16) -> Self { |
3310 | Self(value.into()) |
3311 | } |
3312 | } |
3313 | impl From<u32> for BarrierDirections { |
3314 | #[inline ] |
3315 | fn from(value: u32) -> Self { |
3316 | Self(value) |
3317 | } |
3318 | } |
3319 | impl core::fmt::Debug for BarrierDirections { |
3320 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
3321 | let variants: [(u32, &str, &str); 4] = [ |
3322 | (Self::POSITIVE_X.0, "POSITIVE_X" , "PositiveX" ), |
3323 | (Self::POSITIVE_Y.0, "POSITIVE_Y" , "PositiveY" ), |
3324 | (Self::NEGATIVE_X.0, "NEGATIVE_X" , "NegativeX" ), |
3325 | (Self::NEGATIVE_Y.0, "NEGATIVE_Y" , "NegativeY" ), |
3326 | ]; |
3327 | pretty_print_bitmask(fmt, self.0, &variants) |
3328 | } |
3329 | } |
3330 | bitmask_binop!(BarrierDirections, u32); |
3331 | |
3332 | /// Opcode for the CreatePointerBarrier request |
3333 | pub const CREATE_POINTER_BARRIER_REQUEST: u8 = 31; |
3334 | #[derive (Clone, Default)] |
3335 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
3336 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
3337 | pub struct CreatePointerBarrierRequest<'input> { |
3338 | pub barrier: Barrier, |
3339 | pub window: xproto::Window, |
3340 | pub x1: u16, |
3341 | pub y1: u16, |
3342 | pub x2: u16, |
3343 | pub y2: u16, |
3344 | pub directions: BarrierDirections, |
3345 | pub devices: Cow<'input, [u16]>, |
3346 | } |
3347 | impl_debug_if_no_extra_traits!(CreatePointerBarrierRequest<'_>, "CreatePointerBarrierRequest" ); |
3348 | impl<'input> CreatePointerBarrierRequest<'input> { |
3349 | /// Serialize this request into bytes for the provided connection |
3350 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
3351 | let length_so_far = 0; |
3352 | let barrier_bytes = self.barrier.serialize(); |
3353 | let window_bytes = self.window.serialize(); |
3354 | let x1_bytes = self.x1.serialize(); |
3355 | let y1_bytes = self.y1.serialize(); |
3356 | let x2_bytes = self.x2.serialize(); |
3357 | let y2_bytes = self.y2.serialize(); |
3358 | let directions_bytes = u32::from(self.directions).serialize(); |
3359 | let num_devices = u16::try_from(self.devices.len()).expect("`devices` has too many elements" ); |
3360 | let num_devices_bytes = num_devices.serialize(); |
3361 | let mut request0 = vec![ |
3362 | major_opcode, |
3363 | CREATE_POINTER_BARRIER_REQUEST, |
3364 | 0, |
3365 | 0, |
3366 | barrier_bytes[0], |
3367 | barrier_bytes[1], |
3368 | barrier_bytes[2], |
3369 | barrier_bytes[3], |
3370 | window_bytes[0], |
3371 | window_bytes[1], |
3372 | window_bytes[2], |
3373 | window_bytes[3], |
3374 | x1_bytes[0], |
3375 | x1_bytes[1], |
3376 | y1_bytes[0], |
3377 | y1_bytes[1], |
3378 | x2_bytes[0], |
3379 | x2_bytes[1], |
3380 | y2_bytes[0], |
3381 | y2_bytes[1], |
3382 | directions_bytes[0], |
3383 | directions_bytes[1], |
3384 | directions_bytes[2], |
3385 | directions_bytes[3], |
3386 | 0, |
3387 | 0, |
3388 | num_devices_bytes[0], |
3389 | num_devices_bytes[1], |
3390 | ]; |
3391 | let length_so_far = length_so_far + request0.len(); |
3392 | let devices_bytes = self.devices.serialize(); |
3393 | let length_so_far = length_so_far + devices_bytes.len(); |
3394 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
3395 | let length_so_far = length_so_far + padding0.len(); |
3396 | assert_eq!(length_so_far % 4, 0); |
3397 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
3398 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
3399 | ([request0.into(), devices_bytes.into(), padding0.into()], vec![]) |
3400 | } |
3401 | /// Parse this request given its header, its body, and any fds that go along with it |
3402 | #[cfg (feature = "request-parsing" )] |
3403 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
3404 | if header.minor_opcode != CREATE_POINTER_BARRIER_REQUEST { |
3405 | return Err(ParseError::InvalidValue); |
3406 | } |
3407 | let (barrier, remaining) = Barrier::try_parse(value)?; |
3408 | let (window, remaining) = xproto::Window::try_parse(remaining)?; |
3409 | let (x1, remaining) = u16::try_parse(remaining)?; |
3410 | let (y1, remaining) = u16::try_parse(remaining)?; |
3411 | let (x2, remaining) = u16::try_parse(remaining)?; |
3412 | let (y2, remaining) = u16::try_parse(remaining)?; |
3413 | let (directions, remaining) = u32::try_parse(remaining)?; |
3414 | let directions = directions.into(); |
3415 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
3416 | let (num_devices, remaining) = u16::try_parse(remaining)?; |
3417 | let (devices, remaining) = crate::x11_utils::parse_list::<u16>(remaining, num_devices.try_to_usize()?)?; |
3418 | let _ = remaining; |
3419 | Ok(CreatePointerBarrierRequest { |
3420 | barrier, |
3421 | window, |
3422 | x1, |
3423 | y1, |
3424 | x2, |
3425 | y2, |
3426 | directions, |
3427 | devices: Cow::Owned(devices), |
3428 | }) |
3429 | } |
3430 | /// Clone all borrowed data in this CreatePointerBarrierRequest. |
3431 | pub fn into_owned(self) -> CreatePointerBarrierRequest<'static> { |
3432 | CreatePointerBarrierRequest { |
3433 | barrier: self.barrier, |
3434 | window: self.window, |
3435 | x1: self.x1, |
3436 | y1: self.y1, |
3437 | x2: self.x2, |
3438 | y2: self.y2, |
3439 | directions: self.directions, |
3440 | devices: Cow::Owned(self.devices.into_owned()), |
3441 | } |
3442 | } |
3443 | } |
3444 | impl<'input> Request for CreatePointerBarrierRequest<'input> { |
3445 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
3446 | |
3447 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
3448 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(major_opcode); |
3449 | // Flatten the buffers into a single vector |
3450 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
3451 | (buf, fds) |
3452 | } |
3453 | } |
3454 | impl<'input> crate::x11_utils::VoidRequest for CreatePointerBarrierRequest<'input> { |
3455 | } |
3456 | |
3457 | /// Opcode for the DeletePointerBarrier request |
3458 | pub const DELETE_POINTER_BARRIER_REQUEST: u8 = 32; |
3459 | #[derive (Clone, Copy, Default)] |
3460 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
3461 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
3462 | pub struct DeletePointerBarrierRequest { |
3463 | pub barrier: Barrier, |
3464 | } |
3465 | impl_debug_if_no_extra_traits!(DeletePointerBarrierRequest, "DeletePointerBarrierRequest" ); |
3466 | impl DeletePointerBarrierRequest { |
3467 | /// Serialize this request into bytes for the provided connection |
3468 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
3469 | let length_so_far = 0; |
3470 | let barrier_bytes = self.barrier.serialize(); |
3471 | let mut request0 = vec![ |
3472 | major_opcode, |
3473 | DELETE_POINTER_BARRIER_REQUEST, |
3474 | 0, |
3475 | 0, |
3476 | barrier_bytes[0], |
3477 | barrier_bytes[1], |
3478 | barrier_bytes[2], |
3479 | barrier_bytes[3], |
3480 | ]; |
3481 | let length_so_far = length_so_far + request0.len(); |
3482 | assert_eq!(length_so_far % 4, 0); |
3483 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
3484 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
3485 | ([request0.into()], vec![]) |
3486 | } |
3487 | /// Parse this request given its header, its body, and any fds that go along with it |
3488 | #[cfg (feature = "request-parsing" )] |
3489 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
3490 | if header.minor_opcode != DELETE_POINTER_BARRIER_REQUEST { |
3491 | return Err(ParseError::InvalidValue); |
3492 | } |
3493 | let (barrier, remaining) = Barrier::try_parse(value)?; |
3494 | let _ = remaining; |
3495 | Ok(DeletePointerBarrierRequest { |
3496 | barrier, |
3497 | }) |
3498 | } |
3499 | } |
3500 | impl Request for DeletePointerBarrierRequest { |
3501 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
3502 | |
3503 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
3504 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
3505 | // Flatten the buffers into a single vector |
3506 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
3507 | (buf, fds) |
3508 | } |
3509 | } |
3510 | impl crate::x11_utils::VoidRequest for DeletePointerBarrierRequest { |
3511 | } |
3512 | |
3513 | /// # Fields |
3514 | /// |
3515 | /// * `Default` - The default behavior for regular clients: the X11 server won't terminate as long |
3516 | /// as such clients are still connected, and should this client disconnect, the |
3517 | /// server will continue running so long as other clients (that have not set |
3518 | /// XFixesClientDisconnectFlagTerminate) are connected. |
3519 | /// * `Terminate` - Indicates to the X11 server that it can ignore the client and terminate itself |
3520 | /// even though the client is still connected to the X11 server. |
3521 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
3522 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
3523 | pub struct ClientDisconnectFlags(u32); |
3524 | impl ClientDisconnectFlags { |
3525 | pub const DEFAULT: Self = Self(0); |
3526 | pub const TERMINATE: Self = Self(1 << 0); |
3527 | } |
3528 | impl From<ClientDisconnectFlags> for u32 { |
3529 | #[inline ] |
3530 | fn from(input: ClientDisconnectFlags) -> Self { |
3531 | input.0 |
3532 | } |
3533 | } |
3534 | impl From<ClientDisconnectFlags> for Option<u32> { |
3535 | #[inline ] |
3536 | fn from(input: ClientDisconnectFlags) -> Self { |
3537 | Some(input.0) |
3538 | } |
3539 | } |
3540 | impl From<u8> for ClientDisconnectFlags { |
3541 | #[inline ] |
3542 | fn from(value: u8) -> Self { |
3543 | Self(value.into()) |
3544 | } |
3545 | } |
3546 | impl From<u16> for ClientDisconnectFlags { |
3547 | #[inline ] |
3548 | fn from(value: u16) -> Self { |
3549 | Self(value.into()) |
3550 | } |
3551 | } |
3552 | impl From<u32> for ClientDisconnectFlags { |
3553 | #[inline ] |
3554 | fn from(value: u32) -> Self { |
3555 | Self(value) |
3556 | } |
3557 | } |
3558 | impl core::fmt::Debug for ClientDisconnectFlags { |
3559 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
3560 | let variants: [(u32, &str, &str); 2] = [ |
3561 | (Self::DEFAULT.0, "DEFAULT" , "Default" ), |
3562 | (Self::TERMINATE.0, "TERMINATE" , "Terminate" ), |
3563 | ]; |
3564 | pretty_print_bitmask(fmt, self.0, &variants) |
3565 | } |
3566 | } |
3567 | bitmask_binop!(ClientDisconnectFlags, u32); |
3568 | |
3569 | /// Opcode for the SetClientDisconnectMode request |
3570 | pub const SET_CLIENT_DISCONNECT_MODE_REQUEST: u8 = 33; |
3571 | /// Sets the disconnect mode for the client.. |
3572 | /// |
3573 | /// # Fields |
3574 | /// |
3575 | /// * `disconnect_mode` - The new disconnect mode. |
3576 | #[derive (Clone, Copy, Default)] |
3577 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
3578 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
3579 | pub struct SetClientDisconnectModeRequest { |
3580 | pub disconnect_mode: ClientDisconnectFlags, |
3581 | } |
3582 | impl_debug_if_no_extra_traits!(SetClientDisconnectModeRequest, "SetClientDisconnectModeRequest" ); |
3583 | impl SetClientDisconnectModeRequest { |
3584 | /// Serialize this request into bytes for the provided connection |
3585 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
3586 | let length_so_far = 0; |
3587 | let disconnect_mode_bytes = u32::from(self.disconnect_mode).serialize(); |
3588 | let mut request0 = vec![ |
3589 | major_opcode, |
3590 | SET_CLIENT_DISCONNECT_MODE_REQUEST, |
3591 | 0, |
3592 | 0, |
3593 | disconnect_mode_bytes[0], |
3594 | disconnect_mode_bytes[1], |
3595 | disconnect_mode_bytes[2], |
3596 | disconnect_mode_bytes[3], |
3597 | ]; |
3598 | let length_so_far = length_so_far + request0.len(); |
3599 | assert_eq!(length_so_far % 4, 0); |
3600 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
3601 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
3602 | ([request0.into()], vec![]) |
3603 | } |
3604 | /// Parse this request given its header, its body, and any fds that go along with it |
3605 | #[cfg (feature = "request-parsing" )] |
3606 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
3607 | if header.minor_opcode != SET_CLIENT_DISCONNECT_MODE_REQUEST { |
3608 | return Err(ParseError::InvalidValue); |
3609 | } |
3610 | let (disconnect_mode, remaining) = u32::try_parse(value)?; |
3611 | let disconnect_mode = disconnect_mode.into(); |
3612 | let _ = remaining; |
3613 | Ok(SetClientDisconnectModeRequest { |
3614 | disconnect_mode, |
3615 | }) |
3616 | } |
3617 | } |
3618 | impl Request for SetClientDisconnectModeRequest { |
3619 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
3620 | |
3621 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
3622 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
3623 | // Flatten the buffers into a single vector |
3624 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
3625 | (buf, fds) |
3626 | } |
3627 | } |
3628 | impl crate::x11_utils::VoidRequest for SetClientDisconnectModeRequest { |
3629 | } |
3630 | |
3631 | /// Opcode for the GetClientDisconnectMode request |
3632 | pub const GET_CLIENT_DISCONNECT_MODE_REQUEST: u8 = 34; |
3633 | #[derive (Clone, Copy, Default)] |
3634 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
3635 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
3636 | pub struct GetClientDisconnectModeRequest; |
3637 | impl_debug_if_no_extra_traits!(GetClientDisconnectModeRequest, "GetClientDisconnectModeRequest" ); |
3638 | impl GetClientDisconnectModeRequest { |
3639 | /// Serialize this request into bytes for the provided connection |
3640 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
3641 | let length_so_far = 0; |
3642 | let mut request0 = vec![ |
3643 | major_opcode, |
3644 | GET_CLIENT_DISCONNECT_MODE_REQUEST, |
3645 | 0, |
3646 | 0, |
3647 | ]; |
3648 | let length_so_far = length_so_far + request0.len(); |
3649 | assert_eq!(length_so_far % 4, 0); |
3650 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
3651 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
3652 | ([request0.into()], vec![]) |
3653 | } |
3654 | /// Parse this request given its header, its body, and any fds that go along with it |
3655 | #[cfg (feature = "request-parsing" )] |
3656 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
3657 | if header.minor_opcode != GET_CLIENT_DISCONNECT_MODE_REQUEST { |
3658 | return Err(ParseError::InvalidValue); |
3659 | } |
3660 | let _ = value; |
3661 | Ok(GetClientDisconnectModeRequest |
3662 | ) |
3663 | } |
3664 | } |
3665 | impl Request for GetClientDisconnectModeRequest { |
3666 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
3667 | |
3668 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
3669 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
3670 | // Flatten the buffers into a single vector |
3671 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
3672 | (buf, fds) |
3673 | } |
3674 | } |
3675 | impl crate::x11_utils::ReplyRequest for GetClientDisconnectModeRequest { |
3676 | type Reply = GetClientDisconnectModeReply; |
3677 | } |
3678 | |
3679 | /// Gets the disconnect mode for the client.. |
3680 | /// |
3681 | /// # Fields |
3682 | /// |
3683 | /// * `disconnect_mode` - The current disconnect mode. |
3684 | #[derive (Clone, Copy, Default)] |
3685 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
3686 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
3687 | pub struct GetClientDisconnectModeReply { |
3688 | pub sequence: u16, |
3689 | pub length: u32, |
3690 | pub disconnect_mode: ClientDisconnectFlags, |
3691 | } |
3692 | impl_debug_if_no_extra_traits!(GetClientDisconnectModeReply, "GetClientDisconnectModeReply" ); |
3693 | impl TryParse for GetClientDisconnectModeReply { |
3694 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
3695 | let remaining: &[u8] = initial_value; |
3696 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
3697 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
3698 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
3699 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
3700 | let (disconnect_mode: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
3701 | let remaining: &[u8] = remaining.get(20..).ok_or(err:ParseError::InsufficientData)?; |
3702 | if response_type != 1 { |
3703 | return Err(ParseError::InvalidValue); |
3704 | } |
3705 | let disconnect_mode: ClientDisconnectFlags = disconnect_mode.into(); |
3706 | let result: GetClientDisconnectModeReply = GetClientDisconnectModeReply { sequence, length, disconnect_mode }; |
3707 | let _ = remaining; |
3708 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
3709 | .ok_or(err:ParseError::InsufficientData)?; |
3710 | Ok((result, remaining)) |
3711 | } |
3712 | } |
3713 | impl Serialize for GetClientDisconnectModeReply { |
3714 | type Bytes = [u8; 32]; |
3715 | fn serialize(&self) -> [u8; 32] { |
3716 | let response_type_bytes = &[1]; |
3717 | let sequence_bytes = self.sequence.serialize(); |
3718 | let length_bytes = self.length.serialize(); |
3719 | let disconnect_mode_bytes = u32::from(self.disconnect_mode).serialize(); |
3720 | [ |
3721 | response_type_bytes[0], |
3722 | 0, |
3723 | sequence_bytes[0], |
3724 | sequence_bytes[1], |
3725 | length_bytes[0], |
3726 | length_bytes[1], |
3727 | length_bytes[2], |
3728 | length_bytes[3], |
3729 | disconnect_mode_bytes[0], |
3730 | disconnect_mode_bytes[1], |
3731 | disconnect_mode_bytes[2], |
3732 | disconnect_mode_bytes[3], |
3733 | 0, |
3734 | 0, |
3735 | 0, |
3736 | 0, |
3737 | 0, |
3738 | 0, |
3739 | 0, |
3740 | 0, |
3741 | 0, |
3742 | 0, |
3743 | 0, |
3744 | 0, |
3745 | 0, |
3746 | 0, |
3747 | 0, |
3748 | 0, |
3749 | 0, |
3750 | 0, |
3751 | 0, |
3752 | 0, |
3753 | ] |
3754 | } |
3755 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
3756 | bytes.reserve(32); |
3757 | let response_type_bytes = &[1]; |
3758 | bytes.push(response_type_bytes[0]); |
3759 | bytes.extend_from_slice(&[0; 1]); |
3760 | self.sequence.serialize_into(bytes); |
3761 | self.length.serialize_into(bytes); |
3762 | u32::from(self.disconnect_mode).serialize_into(bytes); |
3763 | bytes.extend_from_slice(&[0; 20]); |
3764 | } |
3765 | } |
3766 | |
3767 | |