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