1 // This file contains generated code. Do not edit directly.
2 // To regenerate this, run 'make'.
3
4 //! Bindings to the `Xinerama` 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::xproto;
23
24 /// The X11 name of the extension for QueryExtension
25 pub const X11_EXTENSION_NAME: &str = "XINERAMA";
26
27 /// The version number of this extension that this client library supports.
28 ///
29 /// This constant contains the version number of this extension that is supported
30 /// by this build of x11rb. For most things, it does not make sense to use this
31 /// information. If you need to send a `QueryVersion`, it is recommended to instead
32 /// send the maximum version of the extension that you need.
33 pub const X11_XML_VERSION: (u32, u32) = (1, 1);
34
35 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
36 pub struct ScreenInfo {
37 pub x_org: i16,
38 pub y_org: i16,
39 pub width: u16,
40 pub height: u16,
41 }
42 impl TryParse for ScreenInfo {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>43 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
44 let (x_org, remaining) = i16::try_parse(remaining)?;
45 let (y_org, remaining) = i16::try_parse(remaining)?;
46 let (width, remaining) = u16::try_parse(remaining)?;
47 let (height, remaining) = u16::try_parse(remaining)?;
48 let result = ScreenInfo { x_org, y_org, width, height };
49 Ok((result, remaining))
50 }
51 }
52 impl Serialize for ScreenInfo {
53 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]54 fn serialize(&self) -> [u8; 8] {
55 let x_org_bytes = self.x_org.serialize();
56 let y_org_bytes = self.y_org.serialize();
57 let width_bytes = self.width.serialize();
58 let height_bytes = self.height.serialize();
59 [
60 x_org_bytes[0],
61 x_org_bytes[1],
62 y_org_bytes[0],
63 y_org_bytes[1],
64 width_bytes[0],
65 width_bytes[1],
66 height_bytes[0],
67 height_bytes[1],
68 ]
69 }
serialize_into(&self, bytes: &mut Vec<u8>)70 fn serialize_into(&self, bytes: &mut Vec<u8>) {
71 bytes.reserve(8);
72 self.x_org.serialize_into(bytes);
73 self.y_org.serialize_into(bytes);
74 self.width.serialize_into(bytes);
75 self.height.serialize_into(bytes);
76 }
77 }
78
79 /// Opcode for the QueryVersion request
80 pub const QUERY_VERSION_REQUEST: u8 = 0;
81 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
82 pub struct QueryVersionRequest {
83 pub major: u8,
84 pub minor: u8,
85 }
86 impl QueryVersionRequest {
87 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,88 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
89 where
90 Conn: RequestConnection + ?Sized,
91 {
92 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
93 .ok_or(ConnectionError::UnsupportedExtension)?;
94 let length_so_far = 0;
95 let major_bytes = self.major.serialize();
96 let minor_bytes = self.minor.serialize();
97 let mut request0 = vec![
98 extension_information.major_opcode,
99 QUERY_VERSION_REQUEST,
100 0,
101 0,
102 major_bytes[0],
103 minor_bytes[0],
104 0,
105 0,
106 ];
107 let length_so_far = length_so_far + request0.len();
108 assert_eq!(length_so_far % 4, 0);
109 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
110 request0[2..4].copy_from_slice(&length.to_ne_bytes());
111 Ok((vec![request0.into()], vec![]))
112 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError> where Conn: RequestConnection + ?Sized,113 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError>
114 where
115 Conn: RequestConnection + ?Sized,
116 {
117 let (bytes, fds) = self.serialize(conn)?;
118 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
119 conn.send_request_with_reply(&slices, fds)
120 }
121 /// 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>122 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
123 if header.minor_opcode != QUERY_VERSION_REQUEST {
124 return Err(ParseError::InvalidValue);
125 }
126 let (major, remaining) = u8::try_parse(value)?;
127 let (minor, remaining) = u8::try_parse(remaining)?;
128 let _ = remaining;
129 Ok(QueryVersionRequest {
130 major,
131 minor,
132 })
133 }
134 }
135 impl Request for QueryVersionRequest {
136 type Reply = QueryVersionReply;
137 }
query_version<Conn>(conn: &Conn, major: u8, minor: u8) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError> where Conn: RequestConnection + ?Sized,138 pub fn query_version<Conn>(conn: &Conn, major: u8, minor: u8) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError>
139 where
140 Conn: RequestConnection + ?Sized,
141 {
142 let request0 = QueryVersionRequest {
143 major,
144 minor,
145 };
146 request0.send(conn)
147 }
148
149 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
150 pub struct QueryVersionReply {
151 pub sequence: u16,
152 pub length: u32,
153 pub major: u16,
154 pub minor: u16,
155 }
156 impl TryParse for QueryVersionReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>157 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
158 let remaining = initial_value;
159 let (response_type, remaining) = u8::try_parse(remaining)?;
160 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
161 let (sequence, remaining) = u16::try_parse(remaining)?;
162 let (length, remaining) = u32::try_parse(remaining)?;
163 let (major, remaining) = u16::try_parse(remaining)?;
164 let (minor, remaining) = u16::try_parse(remaining)?;
165 if response_type != 1 {
166 return Err(ParseError::InvalidValue);
167 }
168 let result = QueryVersionReply { sequence, length, major, minor };
169 let _ = remaining;
170 let remaining = initial_value.get(32 + length as usize * 4..)
171 .ok_or(ParseError::InsufficientData)?;
172 Ok((result, remaining))
173 }
174 }
175
176 /// Opcode for the GetState request
177 pub const GET_STATE_REQUEST: u8 = 1;
178 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
179 pub struct GetStateRequest {
180 pub window: xproto::Window,
181 }
182 impl GetStateRequest {
183 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,184 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
185 where
186 Conn: RequestConnection + ?Sized,
187 {
188 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
189 .ok_or(ConnectionError::UnsupportedExtension)?;
190 let length_so_far = 0;
191 let window_bytes = self.window.serialize();
192 let mut request0 = vec![
193 extension_information.major_opcode,
194 GET_STATE_REQUEST,
195 0,
196 0,
197 window_bytes[0],
198 window_bytes[1],
199 window_bytes[2],
200 window_bytes[3],
201 ];
202 let length_so_far = length_so_far + request0.len();
203 assert_eq!(length_so_far % 4, 0);
204 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
205 request0[2..4].copy_from_slice(&length.to_ne_bytes());
206 Ok((vec![request0.into()], vec![]))
207 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetStateReply>, ConnectionError> where Conn: RequestConnection + ?Sized,208 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetStateReply>, ConnectionError>
209 where
210 Conn: RequestConnection + ?Sized,
211 {
212 let (bytes, fds) = self.serialize(conn)?;
213 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
214 conn.send_request_with_reply(&slices, fds)
215 }
216 /// 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>217 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
218 if header.minor_opcode != GET_STATE_REQUEST {
219 return Err(ParseError::InvalidValue);
220 }
221 let (window, remaining) = xproto::Window::try_parse(value)?;
222 let _ = remaining;
223 Ok(GetStateRequest {
224 window,
225 })
226 }
227 }
228 impl Request for GetStateRequest {
229 type Reply = GetStateReply;
230 }
get_state<Conn>(conn: &Conn, window: xproto::Window) -> Result<Cookie<'_, Conn, GetStateReply>, ConnectionError> where Conn: RequestConnection + ?Sized,231 pub fn get_state<Conn>(conn: &Conn, window: xproto::Window) -> Result<Cookie<'_, Conn, GetStateReply>, ConnectionError>
232 where
233 Conn: RequestConnection + ?Sized,
234 {
235 let request0 = GetStateRequest {
236 window,
237 };
238 request0.send(conn)
239 }
240
241 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
242 pub struct GetStateReply {
243 pub state: u8,
244 pub sequence: u16,
245 pub length: u32,
246 pub window: xproto::Window,
247 }
248 impl TryParse for GetStateReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>249 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
250 let remaining = initial_value;
251 let (response_type, remaining) = u8::try_parse(remaining)?;
252 let (state, remaining) = u8::try_parse(remaining)?;
253 let (sequence, remaining) = u16::try_parse(remaining)?;
254 let (length, remaining) = u32::try_parse(remaining)?;
255 let (window, remaining) = xproto::Window::try_parse(remaining)?;
256 if response_type != 1 {
257 return Err(ParseError::InvalidValue);
258 }
259 let result = GetStateReply { state, sequence, length, window };
260 let _ = remaining;
261 let remaining = initial_value.get(32 + length as usize * 4..)
262 .ok_or(ParseError::InsufficientData)?;
263 Ok((result, remaining))
264 }
265 }
266
267 /// Opcode for the GetScreenCount request
268 pub const GET_SCREEN_COUNT_REQUEST: u8 = 2;
269 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
270 pub struct GetScreenCountRequest {
271 pub window: xproto::Window,
272 }
273 impl GetScreenCountRequest {
274 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,275 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
276 where
277 Conn: RequestConnection + ?Sized,
278 {
279 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
280 .ok_or(ConnectionError::UnsupportedExtension)?;
281 let length_so_far = 0;
282 let window_bytes = self.window.serialize();
283 let mut request0 = vec![
284 extension_information.major_opcode,
285 GET_SCREEN_COUNT_REQUEST,
286 0,
287 0,
288 window_bytes[0],
289 window_bytes[1],
290 window_bytes[2],
291 window_bytes[3],
292 ];
293 let length_so_far = length_so_far + request0.len();
294 assert_eq!(length_so_far % 4, 0);
295 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
296 request0[2..4].copy_from_slice(&length.to_ne_bytes());
297 Ok((vec![request0.into()], vec![]))
298 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetScreenCountReply>, ConnectionError> where Conn: RequestConnection + ?Sized,299 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetScreenCountReply>, ConnectionError>
300 where
301 Conn: RequestConnection + ?Sized,
302 {
303 let (bytes, fds) = self.serialize(conn)?;
304 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
305 conn.send_request_with_reply(&slices, fds)
306 }
307 /// 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>308 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
309 if header.minor_opcode != GET_SCREEN_COUNT_REQUEST {
310 return Err(ParseError::InvalidValue);
311 }
312 let (window, remaining) = xproto::Window::try_parse(value)?;
313 let _ = remaining;
314 Ok(GetScreenCountRequest {
315 window,
316 })
317 }
318 }
319 impl Request for GetScreenCountRequest {
320 type Reply = GetScreenCountReply;
321 }
get_screen_count<Conn>(conn: &Conn, window: xproto::Window) -> Result<Cookie<'_, Conn, GetScreenCountReply>, ConnectionError> where Conn: RequestConnection + ?Sized,322 pub fn get_screen_count<Conn>(conn: &Conn, window: xproto::Window) -> Result<Cookie<'_, Conn, GetScreenCountReply>, ConnectionError>
323 where
324 Conn: RequestConnection + ?Sized,
325 {
326 let request0 = GetScreenCountRequest {
327 window,
328 };
329 request0.send(conn)
330 }
331
332 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
333 pub struct GetScreenCountReply {
334 pub screen_count: u8,
335 pub sequence: u16,
336 pub length: u32,
337 pub window: xproto::Window,
338 }
339 impl TryParse for GetScreenCountReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>340 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
341 let remaining = initial_value;
342 let (response_type, remaining) = u8::try_parse(remaining)?;
343 let (screen_count, remaining) = u8::try_parse(remaining)?;
344 let (sequence, remaining) = u16::try_parse(remaining)?;
345 let (length, remaining) = u32::try_parse(remaining)?;
346 let (window, remaining) = xproto::Window::try_parse(remaining)?;
347 if response_type != 1 {
348 return Err(ParseError::InvalidValue);
349 }
350 let result = GetScreenCountReply { screen_count, sequence, length, window };
351 let _ = remaining;
352 let remaining = initial_value.get(32 + length as usize * 4..)
353 .ok_or(ParseError::InsufficientData)?;
354 Ok((result, remaining))
355 }
356 }
357
358 /// Opcode for the GetScreenSize request
359 pub const GET_SCREEN_SIZE_REQUEST: u8 = 3;
360 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
361 pub struct GetScreenSizeRequest {
362 pub window: xproto::Window,
363 pub screen: u32,
364 }
365 impl GetScreenSizeRequest {
366 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,367 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
368 where
369 Conn: RequestConnection + ?Sized,
370 {
371 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
372 .ok_or(ConnectionError::UnsupportedExtension)?;
373 let length_so_far = 0;
374 let window_bytes = self.window.serialize();
375 let screen_bytes = self.screen.serialize();
376 let mut request0 = vec![
377 extension_information.major_opcode,
378 GET_SCREEN_SIZE_REQUEST,
379 0,
380 0,
381 window_bytes[0],
382 window_bytes[1],
383 window_bytes[2],
384 window_bytes[3],
385 screen_bytes[0],
386 screen_bytes[1],
387 screen_bytes[2],
388 screen_bytes[3],
389 ];
390 let length_so_far = length_so_far + request0.len();
391 assert_eq!(length_so_far % 4, 0);
392 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
393 request0[2..4].copy_from_slice(&length.to_ne_bytes());
394 Ok((vec![request0.into()], vec![]))
395 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetScreenSizeReply>, ConnectionError> where Conn: RequestConnection + ?Sized,396 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetScreenSizeReply>, ConnectionError>
397 where
398 Conn: RequestConnection + ?Sized,
399 {
400 let (bytes, fds) = self.serialize(conn)?;
401 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
402 conn.send_request_with_reply(&slices, fds)
403 }
404 /// 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>405 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
406 if header.minor_opcode != GET_SCREEN_SIZE_REQUEST {
407 return Err(ParseError::InvalidValue);
408 }
409 let (window, remaining) = xproto::Window::try_parse(value)?;
410 let (screen, remaining) = u32::try_parse(remaining)?;
411 let _ = remaining;
412 Ok(GetScreenSizeRequest {
413 window,
414 screen,
415 })
416 }
417 }
418 impl Request for GetScreenSizeRequest {
419 type Reply = GetScreenSizeReply;
420 }
get_screen_size<Conn>(conn: &Conn, window: xproto::Window, screen: u32) -> Result<Cookie<'_, Conn, GetScreenSizeReply>, ConnectionError> where Conn: RequestConnection + ?Sized,421 pub fn get_screen_size<Conn>(conn: &Conn, window: xproto::Window, screen: u32) -> Result<Cookie<'_, Conn, GetScreenSizeReply>, ConnectionError>
422 where
423 Conn: RequestConnection + ?Sized,
424 {
425 let request0 = GetScreenSizeRequest {
426 window,
427 screen,
428 };
429 request0.send(conn)
430 }
431
432 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
433 pub struct GetScreenSizeReply {
434 pub sequence: u16,
435 pub length: u32,
436 pub width: u32,
437 pub height: u32,
438 pub window: xproto::Window,
439 pub screen: u32,
440 }
441 impl TryParse for GetScreenSizeReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>442 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
443 let remaining = initial_value;
444 let (response_type, remaining) = u8::try_parse(remaining)?;
445 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
446 let (sequence, remaining) = u16::try_parse(remaining)?;
447 let (length, remaining) = u32::try_parse(remaining)?;
448 let (width, remaining) = u32::try_parse(remaining)?;
449 let (height, remaining) = u32::try_parse(remaining)?;
450 let (window, remaining) = xproto::Window::try_parse(remaining)?;
451 let (screen, remaining) = u32::try_parse(remaining)?;
452 if response_type != 1 {
453 return Err(ParseError::InvalidValue);
454 }
455 let result = GetScreenSizeReply { sequence, length, width, height, window, screen };
456 let _ = remaining;
457 let remaining = initial_value.get(32 + length as usize * 4..)
458 .ok_or(ParseError::InsufficientData)?;
459 Ok((result, remaining))
460 }
461 }
462
463 /// Opcode for the IsActive request
464 pub const IS_ACTIVE_REQUEST: u8 = 4;
465 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
466 pub struct IsActiveRequest;
467 impl IsActiveRequest {
468 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,469 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
470 where
471 Conn: RequestConnection + ?Sized,
472 {
473 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
474 .ok_or(ConnectionError::UnsupportedExtension)?;
475 let length_so_far = 0;
476 let mut request0 = vec![
477 extension_information.major_opcode,
478 IS_ACTIVE_REQUEST,
479 0,
480 0,
481 ];
482 let length_so_far = length_so_far + request0.len();
483 assert_eq!(length_so_far % 4, 0);
484 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
485 request0[2..4].copy_from_slice(&length.to_ne_bytes());
486 Ok((vec![request0.into()], vec![]))
487 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, IsActiveReply>, ConnectionError> where Conn: RequestConnection + ?Sized,488 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, IsActiveReply>, ConnectionError>
489 where
490 Conn: RequestConnection + ?Sized,
491 {
492 let (bytes, fds) = self.serialize(conn)?;
493 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
494 conn.send_request_with_reply(&slices, fds)
495 }
496 /// 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>497 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
498 if header.minor_opcode != IS_ACTIVE_REQUEST {
499 return Err(ParseError::InvalidValue);
500 }
501 let _ = value;
502 Ok(IsActiveRequest
503 )
504 }
505 }
506 impl Request for IsActiveRequest {
507 type Reply = IsActiveReply;
508 }
is_active<Conn>(conn: &Conn) -> Result<Cookie<'_, Conn, IsActiveReply>, ConnectionError> where Conn: RequestConnection + ?Sized,509 pub fn is_active<Conn>(conn: &Conn) -> Result<Cookie<'_, Conn, IsActiveReply>, ConnectionError>
510 where
511 Conn: RequestConnection + ?Sized,
512 {
513 let request0 = IsActiveRequest;
514 request0.send(conn)
515 }
516
517 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
518 pub struct IsActiveReply {
519 pub sequence: u16,
520 pub length: u32,
521 pub state: u32,
522 }
523 impl TryParse for IsActiveReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>524 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
525 let remaining = initial_value;
526 let (response_type, remaining) = u8::try_parse(remaining)?;
527 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
528 let (sequence, remaining) = u16::try_parse(remaining)?;
529 let (length, remaining) = u32::try_parse(remaining)?;
530 let (state, remaining) = u32::try_parse(remaining)?;
531 if response_type != 1 {
532 return Err(ParseError::InvalidValue);
533 }
534 let result = IsActiveReply { sequence, length, state };
535 let _ = remaining;
536 let remaining = initial_value.get(32 + length as usize * 4..)
537 .ok_or(ParseError::InsufficientData)?;
538 Ok((result, remaining))
539 }
540 }
541
542 /// Opcode for the QueryScreens request
543 pub const QUERY_SCREENS_REQUEST: u8 = 5;
544 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
545 pub struct QueryScreensRequest;
546 impl QueryScreensRequest {
547 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,548 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
549 where
550 Conn: RequestConnection + ?Sized,
551 {
552 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
553 .ok_or(ConnectionError::UnsupportedExtension)?;
554 let length_so_far = 0;
555 let mut request0 = vec![
556 extension_information.major_opcode,
557 QUERY_SCREENS_REQUEST,
558 0,
559 0,
560 ];
561 let length_so_far = length_so_far + request0.len();
562 assert_eq!(length_so_far % 4, 0);
563 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
564 request0[2..4].copy_from_slice(&length.to_ne_bytes());
565 Ok((vec![request0.into()], vec![]))
566 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, QueryScreensReply>, ConnectionError> where Conn: RequestConnection + ?Sized,567 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, QueryScreensReply>, ConnectionError>
568 where
569 Conn: RequestConnection + ?Sized,
570 {
571 let (bytes, fds) = self.serialize(conn)?;
572 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
573 conn.send_request_with_reply(&slices, fds)
574 }
575 /// 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>576 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
577 if header.minor_opcode != QUERY_SCREENS_REQUEST {
578 return Err(ParseError::InvalidValue);
579 }
580 let _ = value;
581 Ok(QueryScreensRequest
582 )
583 }
584 }
585 impl Request for QueryScreensRequest {
586 type Reply = QueryScreensReply;
587 }
query_screens<Conn>(conn: &Conn) -> Result<Cookie<'_, Conn, QueryScreensReply>, ConnectionError> where Conn: RequestConnection + ?Sized,588 pub fn query_screens<Conn>(conn: &Conn) -> Result<Cookie<'_, Conn, QueryScreensReply>, ConnectionError>
589 where
590 Conn: RequestConnection + ?Sized,
591 {
592 let request0 = QueryScreensRequest;
593 request0.send(conn)
594 }
595
596 #[derive(Debug, Clone, PartialEq, Eq)]
597 pub struct QueryScreensReply {
598 pub sequence: u16,
599 pub length: u32,
600 pub screen_info: Vec<ScreenInfo>,
601 }
602 impl TryParse for QueryScreensReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>603 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
604 let remaining = initial_value;
605 let (response_type, remaining) = u8::try_parse(remaining)?;
606 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
607 let (sequence, remaining) = u16::try_parse(remaining)?;
608 let (length, remaining) = u32::try_parse(remaining)?;
609 let (number, remaining) = u32::try_parse(remaining)?;
610 let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
611 let (screen_info, remaining) = crate::x11_utils::parse_list::<ScreenInfo>(remaining, number.try_to_usize()?)?;
612 if response_type != 1 {
613 return Err(ParseError::InvalidValue);
614 }
615 let result = QueryScreensReply { sequence, length, screen_info };
616 let _ = remaining;
617 let remaining = initial_value.get(32 + length as usize * 4..)
618 .ok_or(ParseError::InsufficientData)?;
619 Ok((result, remaining))
620 }
621 }
622 impl QueryScreensReply {
623 /// Get the value of the `number` field.
624 ///
625 /// The `number` field is used as the length field of the `screen_info` field.
626 /// This function computes the field's value again based on the length of the list.
627 ///
628 /// # Panics
629 ///
630 /// Panics if the value cannot be represented in the target type. This
631 /// cannot happen with values of the struct received from the X11 server.
number(&self) -> u32632 pub fn number(&self) -> u32 {
633 self.screen_info.len()
634 .try_into().unwrap()
635 }
636 }
637
638 /// Extension trait defining the requests of this extension.
639 pub trait ConnectionExt: RequestConnection {
xinerama_query_version(&self, major: u8, minor: u8) -> Result<Cookie<'_, Self, QueryVersionReply>, ConnectionError>640 fn xinerama_query_version(&self, major: u8, minor: u8) -> Result<Cookie<'_, Self, QueryVersionReply>, ConnectionError>
641 {
642 query_version(self, major, minor)
643 }
xinerama_get_state(&self, window: xproto::Window) -> Result<Cookie<'_, Self, GetStateReply>, ConnectionError>644 fn xinerama_get_state(&self, window: xproto::Window) -> Result<Cookie<'_, Self, GetStateReply>, ConnectionError>
645 {
646 get_state(self, window)
647 }
xinerama_get_screen_count(&self, window: xproto::Window) -> Result<Cookie<'_, Self, GetScreenCountReply>, ConnectionError>648 fn xinerama_get_screen_count(&self, window: xproto::Window) -> Result<Cookie<'_, Self, GetScreenCountReply>, ConnectionError>
649 {
650 get_screen_count(self, window)
651 }
xinerama_get_screen_size(&self, window: xproto::Window, screen: u32) -> Result<Cookie<'_, Self, GetScreenSizeReply>, ConnectionError>652 fn xinerama_get_screen_size(&self, window: xproto::Window, screen: u32) -> Result<Cookie<'_, Self, GetScreenSizeReply>, ConnectionError>
653 {
654 get_screen_size(self, window, screen)
655 }
xinerama_is_active(&self) -> Result<Cookie<'_, Self, IsActiveReply>, ConnectionError>656 fn xinerama_is_active(&self) -> Result<Cookie<'_, Self, IsActiveReply>, ConnectionError>
657 {
658 is_active(self)
659 }
xinerama_query_screens(&self) -> Result<Cookie<'_, Self, QueryScreensReply>, ConnectionError>660 fn xinerama_query_screens(&self) -> Result<Cookie<'_, Self, QueryScreensReply>, ConnectionError>
661 {
662 query_screens(self)
663 }
664 }
665
666 impl<C: RequestConnection + ?Sized> ConnectionExt for C {}
667