1 // This file contains generated code. Do not edit directly.
2 // To regenerate this, run 'make'.
3
4 //! Bindings to the `xkb` 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 = "XKEYBOARD";
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, 0);
34
35 #[derive(Clone, Copy, PartialEq, Eq)]
36 pub struct Const(u8);
37 impl Const {
38 pub const MAX_LEGAL_KEY_CODE: Self = Self(255);
39 pub const PER_KEY_BIT_ARRAY_SIZE: Self = Self(32);
40 pub const KEY_NAME_LENGTH: Self = Self(4);
41 }
42 impl From<Const> for u8 {
43 #[inline]
from(input: Const) -> Self44 fn from(input: Const) -> Self {
45 input.0
46 }
47 }
48 impl From<Const> for Option<u8> {
49 #[inline]
from(input: Const) -> Self50 fn from(input: Const) -> Self {
51 Some(input.0)
52 }
53 }
54 impl From<Const> for u16 {
55 #[inline]
from(input: Const) -> Self56 fn from(input: Const) -> Self {
57 u16::from(input.0)
58 }
59 }
60 impl From<Const> for Option<u16> {
61 #[inline]
from(input: Const) -> Self62 fn from(input: Const) -> Self {
63 Some(u16::from(input.0))
64 }
65 }
66 impl From<Const> for u32 {
67 #[inline]
from(input: Const) -> Self68 fn from(input: Const) -> Self {
69 u32::from(input.0)
70 }
71 }
72 impl From<Const> for Option<u32> {
73 #[inline]
from(input: Const) -> Self74 fn from(input: Const) -> Self {
75 Some(u32::from(input.0))
76 }
77 }
78 impl From<u8> for Const {
79 #[inline]
from(value: u8) -> Self80 fn from(value: u8) -> Self {
81 Self(value)
82 }
83 }
84 impl std::fmt::Debug for Const {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result85 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
86 let variants = [
87 (Self::MAX_LEGAL_KEY_CODE.0.into(), "MAX_LEGAL_KEY_CODE", "MaxLegalKeyCode"),
88 (Self::PER_KEY_BIT_ARRAY_SIZE.0.into(), "PER_KEY_BIT_ARRAY_SIZE", "PerKeyBitArraySize"),
89 (Self::KEY_NAME_LENGTH.0.into(), "KEY_NAME_LENGTH", "KeyNameLength"),
90 ];
91 pretty_print_enum(fmt, self.0.into(), &variants)
92 }
93 }
94
95 #[derive(Clone, Copy, PartialEq, Eq)]
96 pub struct EventType(u16);
97 impl EventType {
98 pub const NEW_KEYBOARD_NOTIFY: Self = Self(1 << 0);
99 pub const MAP_NOTIFY: Self = Self(1 << 1);
100 pub const STATE_NOTIFY: Self = Self(1 << 2);
101 pub const CONTROLS_NOTIFY: Self = Self(1 << 3);
102 pub const INDICATOR_STATE_NOTIFY: Self = Self(1 << 4);
103 pub const INDICATOR_MAP_NOTIFY: Self = Self(1 << 5);
104 pub const NAMES_NOTIFY: Self = Self(1 << 6);
105 pub const COMPAT_MAP_NOTIFY: Self = Self(1 << 7);
106 pub const BELL_NOTIFY: Self = Self(1 << 8);
107 pub const ACTION_MESSAGE: Self = Self(1 << 9);
108 pub const ACCESS_X_NOTIFY: Self = Self(1 << 10);
109 pub const EXTENSION_DEVICE_NOTIFY: Self = Self(1 << 11);
110 }
111 impl From<EventType> for u16 {
112 #[inline]
from(input: EventType) -> Self113 fn from(input: EventType) -> Self {
114 input.0
115 }
116 }
117 impl From<EventType> for Option<u16> {
118 #[inline]
from(input: EventType) -> Self119 fn from(input: EventType) -> Self {
120 Some(input.0)
121 }
122 }
123 impl From<EventType> for u32 {
124 #[inline]
from(input: EventType) -> Self125 fn from(input: EventType) -> Self {
126 u32::from(input.0)
127 }
128 }
129 impl From<EventType> for Option<u32> {
130 #[inline]
from(input: EventType) -> Self131 fn from(input: EventType) -> Self {
132 Some(u32::from(input.0))
133 }
134 }
135 impl From<u8> for EventType {
136 #[inline]
from(value: u8) -> Self137 fn from(value: u8) -> Self {
138 Self(value.into())
139 }
140 }
141 impl From<u16> for EventType {
142 #[inline]
from(value: u16) -> Self143 fn from(value: u16) -> Self {
144 Self(value)
145 }
146 }
147 impl std::fmt::Debug for EventType {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result148 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
149 let variants = [
150 (Self::NEW_KEYBOARD_NOTIFY.0.into(), "NEW_KEYBOARD_NOTIFY", "NewKeyboardNotify"),
151 (Self::MAP_NOTIFY.0.into(), "MAP_NOTIFY", "MapNotify"),
152 (Self::STATE_NOTIFY.0.into(), "STATE_NOTIFY", "StateNotify"),
153 (Self::CONTROLS_NOTIFY.0.into(), "CONTROLS_NOTIFY", "ControlsNotify"),
154 (Self::INDICATOR_STATE_NOTIFY.0.into(), "INDICATOR_STATE_NOTIFY", "IndicatorStateNotify"),
155 (Self::INDICATOR_MAP_NOTIFY.0.into(), "INDICATOR_MAP_NOTIFY", "IndicatorMapNotify"),
156 (Self::NAMES_NOTIFY.0.into(), "NAMES_NOTIFY", "NamesNotify"),
157 (Self::COMPAT_MAP_NOTIFY.0.into(), "COMPAT_MAP_NOTIFY", "CompatMapNotify"),
158 (Self::BELL_NOTIFY.0.into(), "BELL_NOTIFY", "BellNotify"),
159 (Self::ACTION_MESSAGE.0.into(), "ACTION_MESSAGE", "ActionMessage"),
160 (Self::ACCESS_X_NOTIFY.0.into(), "ACCESS_X_NOTIFY", "AccessXNotify"),
161 (Self::EXTENSION_DEVICE_NOTIFY.0.into(), "EXTENSION_DEVICE_NOTIFY", "ExtensionDeviceNotify"),
162 ];
163 pretty_print_bitmask(fmt, self.0.into(), &variants)
164 }
165 }
166 bitmask_binop!(EventType, u16);
167
168 #[derive(Clone, Copy, PartialEq, Eq)]
169 pub struct NKNDetail(u8);
170 impl NKNDetail {
171 pub const KEYCODES: Self = Self(1 << 0);
172 pub const GEOMETRY: Self = Self(1 << 1);
173 pub const DEVICE_ID: Self = Self(1 << 2);
174 }
175 impl From<NKNDetail> for u8 {
176 #[inline]
from(input: NKNDetail) -> Self177 fn from(input: NKNDetail) -> Self {
178 input.0
179 }
180 }
181 impl From<NKNDetail> for Option<u8> {
182 #[inline]
from(input: NKNDetail) -> Self183 fn from(input: NKNDetail) -> Self {
184 Some(input.0)
185 }
186 }
187 impl From<NKNDetail> for u16 {
188 #[inline]
from(input: NKNDetail) -> Self189 fn from(input: NKNDetail) -> Self {
190 u16::from(input.0)
191 }
192 }
193 impl From<NKNDetail> for Option<u16> {
194 #[inline]
from(input: NKNDetail) -> Self195 fn from(input: NKNDetail) -> Self {
196 Some(u16::from(input.0))
197 }
198 }
199 impl From<NKNDetail> for u32 {
200 #[inline]
from(input: NKNDetail) -> Self201 fn from(input: NKNDetail) -> Self {
202 u32::from(input.0)
203 }
204 }
205 impl From<NKNDetail> for Option<u32> {
206 #[inline]
from(input: NKNDetail) -> Self207 fn from(input: NKNDetail) -> Self {
208 Some(u32::from(input.0))
209 }
210 }
211 impl From<u8> for NKNDetail {
212 #[inline]
from(value: u8) -> Self213 fn from(value: u8) -> Self {
214 Self(value)
215 }
216 }
217 impl std::fmt::Debug for NKNDetail {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result218 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
219 let variants = [
220 (Self::KEYCODES.0.into(), "KEYCODES", "Keycodes"),
221 (Self::GEOMETRY.0.into(), "GEOMETRY", "Geometry"),
222 (Self::DEVICE_ID.0.into(), "DEVICE_ID", "DeviceID"),
223 ];
224 pretty_print_bitmask(fmt, self.0.into(), &variants)
225 }
226 }
227 bitmask_binop!(NKNDetail, u8);
228
229 #[derive(Clone, Copy, PartialEq, Eq)]
230 pub struct AXNDetail(u8);
231 impl AXNDetail {
232 pub const SK_PRESS: Self = Self(1 << 0);
233 pub const SK_ACCEPT: Self = Self(1 << 1);
234 pub const SK_REJECT: Self = Self(1 << 2);
235 pub const SK_RELEASE: Self = Self(1 << 3);
236 pub const BK_ACCEPT: Self = Self(1 << 4);
237 pub const BK_REJECT: Self = Self(1 << 5);
238 pub const AXK_WARNING: Self = Self(1 << 6);
239 }
240 impl From<AXNDetail> for u8 {
241 #[inline]
from(input: AXNDetail) -> Self242 fn from(input: AXNDetail) -> Self {
243 input.0
244 }
245 }
246 impl From<AXNDetail> for Option<u8> {
247 #[inline]
from(input: AXNDetail) -> Self248 fn from(input: AXNDetail) -> Self {
249 Some(input.0)
250 }
251 }
252 impl From<AXNDetail> for u16 {
253 #[inline]
from(input: AXNDetail) -> Self254 fn from(input: AXNDetail) -> Self {
255 u16::from(input.0)
256 }
257 }
258 impl From<AXNDetail> for Option<u16> {
259 #[inline]
from(input: AXNDetail) -> Self260 fn from(input: AXNDetail) -> Self {
261 Some(u16::from(input.0))
262 }
263 }
264 impl From<AXNDetail> for u32 {
265 #[inline]
from(input: AXNDetail) -> Self266 fn from(input: AXNDetail) -> Self {
267 u32::from(input.0)
268 }
269 }
270 impl From<AXNDetail> for Option<u32> {
271 #[inline]
from(input: AXNDetail) -> Self272 fn from(input: AXNDetail) -> Self {
273 Some(u32::from(input.0))
274 }
275 }
276 impl From<u8> for AXNDetail {
277 #[inline]
from(value: u8) -> Self278 fn from(value: u8) -> Self {
279 Self(value)
280 }
281 }
282 impl std::fmt::Debug for AXNDetail {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result283 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
284 let variants = [
285 (Self::SK_PRESS.0.into(), "SK_PRESS", "SKPress"),
286 (Self::SK_ACCEPT.0.into(), "SK_ACCEPT", "SKAccept"),
287 (Self::SK_REJECT.0.into(), "SK_REJECT", "SKReject"),
288 (Self::SK_RELEASE.0.into(), "SK_RELEASE", "SKRelease"),
289 (Self::BK_ACCEPT.0.into(), "BK_ACCEPT", "BKAccept"),
290 (Self::BK_REJECT.0.into(), "BK_REJECT", "BKReject"),
291 (Self::AXK_WARNING.0.into(), "AXK_WARNING", "AXKWarning"),
292 ];
293 pretty_print_bitmask(fmt, self.0.into(), &variants)
294 }
295 }
296 bitmask_binop!(AXNDetail, u8);
297
298 #[derive(Clone, Copy, PartialEq, Eq)]
299 pub struct MapPart(u8);
300 impl MapPart {
301 pub const KEY_TYPES: Self = Self(1 << 0);
302 pub const KEY_SYMS: Self = Self(1 << 1);
303 pub const MODIFIER_MAP: Self = Self(1 << 2);
304 pub const EXPLICIT_COMPONENTS: Self = Self(1 << 3);
305 pub const KEY_ACTIONS: Self = Self(1 << 4);
306 pub const KEY_BEHAVIORS: Self = Self(1 << 5);
307 pub const VIRTUAL_MODS: Self = Self(1 << 6);
308 pub const VIRTUAL_MOD_MAP: Self = Self(1 << 7);
309 }
310 impl From<MapPart> for u8 {
311 #[inline]
from(input: MapPart) -> Self312 fn from(input: MapPart) -> Self {
313 input.0
314 }
315 }
316 impl From<MapPart> for Option<u8> {
317 #[inline]
from(input: MapPart) -> Self318 fn from(input: MapPart) -> Self {
319 Some(input.0)
320 }
321 }
322 impl From<MapPart> for u16 {
323 #[inline]
from(input: MapPart) -> Self324 fn from(input: MapPart) -> Self {
325 u16::from(input.0)
326 }
327 }
328 impl From<MapPart> for Option<u16> {
329 #[inline]
from(input: MapPart) -> Self330 fn from(input: MapPart) -> Self {
331 Some(u16::from(input.0))
332 }
333 }
334 impl From<MapPart> for u32 {
335 #[inline]
from(input: MapPart) -> Self336 fn from(input: MapPart) -> Self {
337 u32::from(input.0)
338 }
339 }
340 impl From<MapPart> for Option<u32> {
341 #[inline]
from(input: MapPart) -> Self342 fn from(input: MapPart) -> Self {
343 Some(u32::from(input.0))
344 }
345 }
346 impl From<u8> for MapPart {
347 #[inline]
from(value: u8) -> Self348 fn from(value: u8) -> Self {
349 Self(value)
350 }
351 }
352 impl std::fmt::Debug for MapPart {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result353 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
354 let variants = [
355 (Self::KEY_TYPES.0.into(), "KEY_TYPES", "KeyTypes"),
356 (Self::KEY_SYMS.0.into(), "KEY_SYMS", "KeySyms"),
357 (Self::MODIFIER_MAP.0.into(), "MODIFIER_MAP", "ModifierMap"),
358 (Self::EXPLICIT_COMPONENTS.0.into(), "EXPLICIT_COMPONENTS", "ExplicitComponents"),
359 (Self::KEY_ACTIONS.0.into(), "KEY_ACTIONS", "KeyActions"),
360 (Self::KEY_BEHAVIORS.0.into(), "KEY_BEHAVIORS", "KeyBehaviors"),
361 (Self::VIRTUAL_MODS.0.into(), "VIRTUAL_MODS", "VirtualMods"),
362 (Self::VIRTUAL_MOD_MAP.0.into(), "VIRTUAL_MOD_MAP", "VirtualModMap"),
363 ];
364 pretty_print_bitmask(fmt, self.0.into(), &variants)
365 }
366 }
367 bitmask_binop!(MapPart, u8);
368
369 #[derive(Clone, Copy, PartialEq, Eq)]
370 pub struct SetMapFlags(u8);
371 impl SetMapFlags {
372 pub const RESIZE_TYPES: Self = Self(1 << 0);
373 pub const RECOMPUTE_ACTIONS: Self = Self(1 << 1);
374 }
375 impl From<SetMapFlags> for u8 {
376 #[inline]
from(input: SetMapFlags) -> Self377 fn from(input: SetMapFlags) -> Self {
378 input.0
379 }
380 }
381 impl From<SetMapFlags> for Option<u8> {
382 #[inline]
from(input: SetMapFlags) -> Self383 fn from(input: SetMapFlags) -> Self {
384 Some(input.0)
385 }
386 }
387 impl From<SetMapFlags> for u16 {
388 #[inline]
from(input: SetMapFlags) -> Self389 fn from(input: SetMapFlags) -> Self {
390 u16::from(input.0)
391 }
392 }
393 impl From<SetMapFlags> for Option<u16> {
394 #[inline]
from(input: SetMapFlags) -> Self395 fn from(input: SetMapFlags) -> Self {
396 Some(u16::from(input.0))
397 }
398 }
399 impl From<SetMapFlags> for u32 {
400 #[inline]
from(input: SetMapFlags) -> Self401 fn from(input: SetMapFlags) -> Self {
402 u32::from(input.0)
403 }
404 }
405 impl From<SetMapFlags> for Option<u32> {
406 #[inline]
from(input: SetMapFlags) -> Self407 fn from(input: SetMapFlags) -> Self {
408 Some(u32::from(input.0))
409 }
410 }
411 impl From<u8> for SetMapFlags {
412 #[inline]
from(value: u8) -> Self413 fn from(value: u8) -> Self {
414 Self(value)
415 }
416 }
417 impl std::fmt::Debug for SetMapFlags {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result418 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
419 let variants = [
420 (Self::RESIZE_TYPES.0.into(), "RESIZE_TYPES", "ResizeTypes"),
421 (Self::RECOMPUTE_ACTIONS.0.into(), "RECOMPUTE_ACTIONS", "RecomputeActions"),
422 ];
423 pretty_print_bitmask(fmt, self.0.into(), &variants)
424 }
425 }
426 bitmask_binop!(SetMapFlags, u8);
427
428 #[derive(Clone, Copy, PartialEq, Eq)]
429 pub struct StatePart(u16);
430 impl StatePart {
431 pub const MODIFIER_STATE: Self = Self(1 << 0);
432 pub const MODIFIER_BASE: Self = Self(1 << 1);
433 pub const MODIFIER_LATCH: Self = Self(1 << 2);
434 pub const MODIFIER_LOCK: Self = Self(1 << 3);
435 pub const GROUP_STATE: Self = Self(1 << 4);
436 pub const GROUP_BASE: Self = Self(1 << 5);
437 pub const GROUP_LATCH: Self = Self(1 << 6);
438 pub const GROUP_LOCK: Self = Self(1 << 7);
439 pub const COMPAT_STATE: Self = Self(1 << 8);
440 pub const GRAB_MODS: Self = Self(1 << 9);
441 pub const COMPAT_GRAB_MODS: Self = Self(1 << 10);
442 pub const LOOKUP_MODS: Self = Self(1 << 11);
443 pub const COMPAT_LOOKUP_MODS: Self = Self(1 << 12);
444 pub const POINTER_BUTTONS: Self = Self(1 << 13);
445 }
446 impl From<StatePart> for u16 {
447 #[inline]
from(input: StatePart) -> Self448 fn from(input: StatePart) -> Self {
449 input.0
450 }
451 }
452 impl From<StatePart> for Option<u16> {
453 #[inline]
from(input: StatePart) -> Self454 fn from(input: StatePart) -> Self {
455 Some(input.0)
456 }
457 }
458 impl From<StatePart> for u32 {
459 #[inline]
from(input: StatePart) -> Self460 fn from(input: StatePart) -> Self {
461 u32::from(input.0)
462 }
463 }
464 impl From<StatePart> for Option<u32> {
465 #[inline]
from(input: StatePart) -> Self466 fn from(input: StatePart) -> Self {
467 Some(u32::from(input.0))
468 }
469 }
470 impl From<u8> for StatePart {
471 #[inline]
from(value: u8) -> Self472 fn from(value: u8) -> Self {
473 Self(value.into())
474 }
475 }
476 impl From<u16> for StatePart {
477 #[inline]
from(value: u16) -> Self478 fn from(value: u16) -> Self {
479 Self(value)
480 }
481 }
482 impl std::fmt::Debug for StatePart {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result483 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
484 let variants = [
485 (Self::MODIFIER_STATE.0.into(), "MODIFIER_STATE", "ModifierState"),
486 (Self::MODIFIER_BASE.0.into(), "MODIFIER_BASE", "ModifierBase"),
487 (Self::MODIFIER_LATCH.0.into(), "MODIFIER_LATCH", "ModifierLatch"),
488 (Self::MODIFIER_LOCK.0.into(), "MODIFIER_LOCK", "ModifierLock"),
489 (Self::GROUP_STATE.0.into(), "GROUP_STATE", "GroupState"),
490 (Self::GROUP_BASE.0.into(), "GROUP_BASE", "GroupBase"),
491 (Self::GROUP_LATCH.0.into(), "GROUP_LATCH", "GroupLatch"),
492 (Self::GROUP_LOCK.0.into(), "GROUP_LOCK", "GroupLock"),
493 (Self::COMPAT_STATE.0.into(), "COMPAT_STATE", "CompatState"),
494 (Self::GRAB_MODS.0.into(), "GRAB_MODS", "GrabMods"),
495 (Self::COMPAT_GRAB_MODS.0.into(), "COMPAT_GRAB_MODS", "CompatGrabMods"),
496 (Self::LOOKUP_MODS.0.into(), "LOOKUP_MODS", "LookupMods"),
497 (Self::COMPAT_LOOKUP_MODS.0.into(), "COMPAT_LOOKUP_MODS", "CompatLookupMods"),
498 (Self::POINTER_BUTTONS.0.into(), "POINTER_BUTTONS", "PointerButtons"),
499 ];
500 pretty_print_bitmask(fmt, self.0.into(), &variants)
501 }
502 }
503 bitmask_binop!(StatePart, u16);
504
505 #[derive(Clone, Copy, PartialEq, Eq)]
506 pub struct BoolCtrl(u16);
507 impl BoolCtrl {
508 pub const REPEAT_KEYS: Self = Self(1 << 0);
509 pub const SLOW_KEYS: Self = Self(1 << 1);
510 pub const BOUNCE_KEYS: Self = Self(1 << 2);
511 pub const STICKY_KEYS: Self = Self(1 << 3);
512 pub const MOUSE_KEYS: Self = Self(1 << 4);
513 pub const MOUSE_KEYS_ACCEL: Self = Self(1 << 5);
514 pub const ACCESS_X_KEYS: Self = Self(1 << 6);
515 pub const ACCESS_X_TIMEOUT_MASK: Self = Self(1 << 7);
516 pub const ACCESS_X_FEEDBACK_MASK: Self = Self(1 << 8);
517 pub const AUDIBLE_BELL_MASK: Self = Self(1 << 9);
518 pub const OVERLAY1_MASK: Self = Self(1 << 10);
519 pub const OVERLAY2_MASK: Self = Self(1 << 11);
520 pub const IGNORE_GROUP_LOCK_MASK: Self = Self(1 << 12);
521 }
522 impl From<BoolCtrl> for u16 {
523 #[inline]
from(input: BoolCtrl) -> Self524 fn from(input: BoolCtrl) -> Self {
525 input.0
526 }
527 }
528 impl From<BoolCtrl> for Option<u16> {
529 #[inline]
from(input: BoolCtrl) -> Self530 fn from(input: BoolCtrl) -> Self {
531 Some(input.0)
532 }
533 }
534 impl From<BoolCtrl> for u32 {
535 #[inline]
from(input: BoolCtrl) -> Self536 fn from(input: BoolCtrl) -> Self {
537 u32::from(input.0)
538 }
539 }
540 impl From<BoolCtrl> for Option<u32> {
541 #[inline]
from(input: BoolCtrl) -> Self542 fn from(input: BoolCtrl) -> Self {
543 Some(u32::from(input.0))
544 }
545 }
546 impl From<u8> for BoolCtrl {
547 #[inline]
from(value: u8) -> Self548 fn from(value: u8) -> Self {
549 Self(value.into())
550 }
551 }
552 impl From<u16> for BoolCtrl {
553 #[inline]
from(value: u16) -> Self554 fn from(value: u16) -> Self {
555 Self(value)
556 }
557 }
558 impl std::fmt::Debug for BoolCtrl {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result559 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
560 let variants = [
561 (Self::REPEAT_KEYS.0.into(), "REPEAT_KEYS", "RepeatKeys"),
562 (Self::SLOW_KEYS.0.into(), "SLOW_KEYS", "SlowKeys"),
563 (Self::BOUNCE_KEYS.0.into(), "BOUNCE_KEYS", "BounceKeys"),
564 (Self::STICKY_KEYS.0.into(), "STICKY_KEYS", "StickyKeys"),
565 (Self::MOUSE_KEYS.0.into(), "MOUSE_KEYS", "MouseKeys"),
566 (Self::MOUSE_KEYS_ACCEL.0.into(), "MOUSE_KEYS_ACCEL", "MouseKeysAccel"),
567 (Self::ACCESS_X_KEYS.0.into(), "ACCESS_X_KEYS", "AccessXKeys"),
568 (Self::ACCESS_X_TIMEOUT_MASK.0.into(), "ACCESS_X_TIMEOUT_MASK", "AccessXTimeoutMask"),
569 (Self::ACCESS_X_FEEDBACK_MASK.0.into(), "ACCESS_X_FEEDBACK_MASK", "AccessXFeedbackMask"),
570 (Self::AUDIBLE_BELL_MASK.0.into(), "AUDIBLE_BELL_MASK", "AudibleBellMask"),
571 (Self::OVERLAY1_MASK.0.into(), "OVERLAY1_MASK", "Overlay1Mask"),
572 (Self::OVERLAY2_MASK.0.into(), "OVERLAY2_MASK", "Overlay2Mask"),
573 (Self::IGNORE_GROUP_LOCK_MASK.0.into(), "IGNORE_GROUP_LOCK_MASK", "IgnoreGroupLockMask"),
574 ];
575 pretty_print_bitmask(fmt, self.0.into(), &variants)
576 }
577 }
578 bitmask_binop!(BoolCtrl, u16);
579
580 #[derive(Clone, Copy, PartialEq, Eq)]
581 pub struct Control(u32);
582 impl Control {
583 pub const GROUPS_WRAP: Self = Self(1 << 27);
584 pub const INTERNAL_MODS: Self = Self(1 << 28);
585 pub const IGNORE_LOCK_MODS: Self = Self(1 << 29);
586 pub const PER_KEY_REPEAT: Self = Self(1 << 30);
587 pub const CONTROLS_ENABLED: Self = Self(1 << 31);
588 }
589 impl From<Control> for u32 {
590 #[inline]
from(input: Control) -> Self591 fn from(input: Control) -> Self {
592 input.0
593 }
594 }
595 impl From<Control> for Option<u32> {
596 #[inline]
from(input: Control) -> Self597 fn from(input: Control) -> Self {
598 Some(input.0)
599 }
600 }
601 impl From<u8> for Control {
602 #[inline]
from(value: u8) -> Self603 fn from(value: u8) -> Self {
604 Self(value.into())
605 }
606 }
607 impl From<u16> for Control {
608 #[inline]
from(value: u16) -> Self609 fn from(value: u16) -> Self {
610 Self(value.into())
611 }
612 }
613 impl From<u32> for Control {
614 #[inline]
from(value: u32) -> Self615 fn from(value: u32) -> Self {
616 Self(value)
617 }
618 }
619 impl std::fmt::Debug for Control {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result620 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
621 let variants = [
622 (Self::GROUPS_WRAP.0, "GROUPS_WRAP", "GroupsWrap"),
623 (Self::INTERNAL_MODS.0, "INTERNAL_MODS", "InternalMods"),
624 (Self::IGNORE_LOCK_MODS.0, "IGNORE_LOCK_MODS", "IgnoreLockMods"),
625 (Self::PER_KEY_REPEAT.0, "PER_KEY_REPEAT", "PerKeyRepeat"),
626 (Self::CONTROLS_ENABLED.0, "CONTROLS_ENABLED", "ControlsEnabled"),
627 ];
628 pretty_print_bitmask(fmt, self.0, &variants)
629 }
630 }
631 bitmask_binop!(Control, u32);
632
633 #[derive(Clone, Copy, PartialEq, Eq)]
634 pub struct AXOption(u16);
635 impl AXOption {
636 pub const SK_PRESS_FB: Self = Self(1 << 0);
637 pub const SK_ACCEPT_FB: Self = Self(1 << 1);
638 pub const FEATURE_FB: Self = Self(1 << 2);
639 pub const SLOW_WARN_FB: Self = Self(1 << 3);
640 pub const INDICATOR_FB: Self = Self(1 << 4);
641 pub const STICKY_KEYS_FB: Self = Self(1 << 5);
642 pub const TWO_KEYS: Self = Self(1 << 6);
643 pub const LATCH_TO_LOCK: Self = Self(1 << 7);
644 pub const SK_RELEASE_FB: Self = Self(1 << 8);
645 pub const SK_REJECT_FB: Self = Self(1 << 9);
646 pub const BK_REJECT_FB: Self = Self(1 << 10);
647 pub const DUMB_BELL: Self = Self(1 << 11);
648 }
649 impl From<AXOption> for u16 {
650 #[inline]
from(input: AXOption) -> Self651 fn from(input: AXOption) -> Self {
652 input.0
653 }
654 }
655 impl From<AXOption> for Option<u16> {
656 #[inline]
from(input: AXOption) -> Self657 fn from(input: AXOption) -> Self {
658 Some(input.0)
659 }
660 }
661 impl From<AXOption> for u32 {
662 #[inline]
from(input: AXOption) -> Self663 fn from(input: AXOption) -> Self {
664 u32::from(input.0)
665 }
666 }
667 impl From<AXOption> for Option<u32> {
668 #[inline]
from(input: AXOption) -> Self669 fn from(input: AXOption) -> Self {
670 Some(u32::from(input.0))
671 }
672 }
673 impl From<u8> for AXOption {
674 #[inline]
from(value: u8) -> Self675 fn from(value: u8) -> Self {
676 Self(value.into())
677 }
678 }
679 impl From<u16> for AXOption {
680 #[inline]
from(value: u16) -> Self681 fn from(value: u16) -> Self {
682 Self(value)
683 }
684 }
685 impl std::fmt::Debug for AXOption {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result686 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
687 let variants = [
688 (Self::SK_PRESS_FB.0.into(), "SK_PRESS_FB", "SKPressFB"),
689 (Self::SK_ACCEPT_FB.0.into(), "SK_ACCEPT_FB", "SKAcceptFB"),
690 (Self::FEATURE_FB.0.into(), "FEATURE_FB", "FeatureFB"),
691 (Self::SLOW_WARN_FB.0.into(), "SLOW_WARN_FB", "SlowWarnFB"),
692 (Self::INDICATOR_FB.0.into(), "INDICATOR_FB", "IndicatorFB"),
693 (Self::STICKY_KEYS_FB.0.into(), "STICKY_KEYS_FB", "StickyKeysFB"),
694 (Self::TWO_KEYS.0.into(), "TWO_KEYS", "TwoKeys"),
695 (Self::LATCH_TO_LOCK.0.into(), "LATCH_TO_LOCK", "LatchToLock"),
696 (Self::SK_RELEASE_FB.0.into(), "SK_RELEASE_FB", "SKReleaseFB"),
697 (Self::SK_REJECT_FB.0.into(), "SK_REJECT_FB", "SKRejectFB"),
698 (Self::BK_REJECT_FB.0.into(), "BK_REJECT_FB", "BKRejectFB"),
699 (Self::DUMB_BELL.0.into(), "DUMB_BELL", "DumbBell"),
700 ];
701 pretty_print_bitmask(fmt, self.0.into(), &variants)
702 }
703 }
704 bitmask_binop!(AXOption, u16);
705
706 pub type DeviceSpec = u16;
707
708 #[derive(Clone, Copy, PartialEq, Eq)]
709 pub struct LedClassResult(u16);
710 impl LedClassResult {
711 pub const KBD_FEEDBACK_CLASS: Self = Self(0);
712 pub const LED_FEEDBACK_CLASS: Self = Self(4);
713 }
714 impl From<LedClassResult> for u16 {
715 #[inline]
from(input: LedClassResult) -> Self716 fn from(input: LedClassResult) -> Self {
717 input.0
718 }
719 }
720 impl From<LedClassResult> for Option<u16> {
721 #[inline]
from(input: LedClassResult) -> Self722 fn from(input: LedClassResult) -> Self {
723 Some(input.0)
724 }
725 }
726 impl From<LedClassResult> for u32 {
727 #[inline]
from(input: LedClassResult) -> Self728 fn from(input: LedClassResult) -> Self {
729 u32::from(input.0)
730 }
731 }
732 impl From<LedClassResult> for Option<u32> {
733 #[inline]
from(input: LedClassResult) -> Self734 fn from(input: LedClassResult) -> Self {
735 Some(u32::from(input.0))
736 }
737 }
738 impl From<u8> for LedClassResult {
739 #[inline]
from(value: u8) -> Self740 fn from(value: u8) -> Self {
741 Self(value.into())
742 }
743 }
744 impl From<u16> for LedClassResult {
745 #[inline]
from(value: u16) -> Self746 fn from(value: u16) -> Self {
747 Self(value)
748 }
749 }
750 impl std::fmt::Debug for LedClassResult {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result751 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
752 let variants = [
753 (Self::KBD_FEEDBACK_CLASS.0.into(), "KBD_FEEDBACK_CLASS", "KbdFeedbackClass"),
754 (Self::LED_FEEDBACK_CLASS.0.into(), "LED_FEEDBACK_CLASS", "LedFeedbackClass"),
755 ];
756 pretty_print_enum(fmt, self.0.into(), &variants)
757 }
758 }
759
760 #[derive(Clone, Copy, PartialEq, Eq)]
761 pub struct LedClass(u16);
762 impl LedClass {
763 pub const KBD_FEEDBACK_CLASS: Self = Self(0);
764 pub const LED_FEEDBACK_CLASS: Self = Self(4);
765 pub const DFLT_XI_CLASS: Self = Self(768);
766 pub const ALL_XI_CLASSES: Self = Self(1280);
767 }
768 impl From<LedClass> for u16 {
769 #[inline]
from(input: LedClass) -> Self770 fn from(input: LedClass) -> Self {
771 input.0
772 }
773 }
774 impl From<LedClass> for Option<u16> {
775 #[inline]
from(input: LedClass) -> Self776 fn from(input: LedClass) -> Self {
777 Some(input.0)
778 }
779 }
780 impl From<LedClass> for u32 {
781 #[inline]
from(input: LedClass) -> Self782 fn from(input: LedClass) -> Self {
783 u32::from(input.0)
784 }
785 }
786 impl From<LedClass> for Option<u32> {
787 #[inline]
from(input: LedClass) -> Self788 fn from(input: LedClass) -> Self {
789 Some(u32::from(input.0))
790 }
791 }
792 impl From<u8> for LedClass {
793 #[inline]
from(value: u8) -> Self794 fn from(value: u8) -> Self {
795 Self(value.into())
796 }
797 }
798 impl From<u16> for LedClass {
799 #[inline]
from(value: u16) -> Self800 fn from(value: u16) -> Self {
801 Self(value)
802 }
803 }
804 impl std::fmt::Debug for LedClass {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result805 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
806 let variants = [
807 (Self::KBD_FEEDBACK_CLASS.0.into(), "KBD_FEEDBACK_CLASS", "KbdFeedbackClass"),
808 (Self::LED_FEEDBACK_CLASS.0.into(), "LED_FEEDBACK_CLASS", "LedFeedbackClass"),
809 (Self::DFLT_XI_CLASS.0.into(), "DFLT_XI_CLASS", "DfltXIClass"),
810 (Self::ALL_XI_CLASSES.0.into(), "ALL_XI_CLASSES", "AllXIClasses"),
811 ];
812 pretty_print_enum(fmt, self.0.into(), &variants)
813 }
814 }
815
816 pub type LedClassSpec = u16;
817
818 #[derive(Clone, Copy, PartialEq, Eq)]
819 pub struct BellClassResult(u8);
820 impl BellClassResult {
821 pub const KBD_FEEDBACK_CLASS: Self = Self(0);
822 pub const BELL_FEEDBACK_CLASS: Self = Self(5);
823 }
824 impl From<BellClassResult> for u8 {
825 #[inline]
from(input: BellClassResult) -> Self826 fn from(input: BellClassResult) -> Self {
827 input.0
828 }
829 }
830 impl From<BellClassResult> for Option<u8> {
831 #[inline]
from(input: BellClassResult) -> Self832 fn from(input: BellClassResult) -> Self {
833 Some(input.0)
834 }
835 }
836 impl From<BellClassResult> for u16 {
837 #[inline]
from(input: BellClassResult) -> Self838 fn from(input: BellClassResult) -> Self {
839 u16::from(input.0)
840 }
841 }
842 impl From<BellClassResult> for Option<u16> {
843 #[inline]
from(input: BellClassResult) -> Self844 fn from(input: BellClassResult) -> Self {
845 Some(u16::from(input.0))
846 }
847 }
848 impl From<BellClassResult> for u32 {
849 #[inline]
from(input: BellClassResult) -> Self850 fn from(input: BellClassResult) -> Self {
851 u32::from(input.0)
852 }
853 }
854 impl From<BellClassResult> for Option<u32> {
855 #[inline]
from(input: BellClassResult) -> Self856 fn from(input: BellClassResult) -> Self {
857 Some(u32::from(input.0))
858 }
859 }
860 impl From<u8> for BellClassResult {
861 #[inline]
from(value: u8) -> Self862 fn from(value: u8) -> Self {
863 Self(value)
864 }
865 }
866 impl std::fmt::Debug for BellClassResult {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result867 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
868 let variants = [
869 (Self::KBD_FEEDBACK_CLASS.0.into(), "KBD_FEEDBACK_CLASS", "KbdFeedbackClass"),
870 (Self::BELL_FEEDBACK_CLASS.0.into(), "BELL_FEEDBACK_CLASS", "BellFeedbackClass"),
871 ];
872 pretty_print_enum(fmt, self.0.into(), &variants)
873 }
874 }
875
876 #[derive(Clone, Copy, PartialEq, Eq)]
877 pub struct BellClass(u16);
878 impl BellClass {
879 pub const KBD_FEEDBACK_CLASS: Self = Self(0);
880 pub const BELL_FEEDBACK_CLASS: Self = Self(5);
881 pub const DFLT_XI_CLASS: Self = Self(768);
882 }
883 impl From<BellClass> for u16 {
884 #[inline]
from(input: BellClass) -> Self885 fn from(input: BellClass) -> Self {
886 input.0
887 }
888 }
889 impl From<BellClass> for Option<u16> {
890 #[inline]
from(input: BellClass) -> Self891 fn from(input: BellClass) -> Self {
892 Some(input.0)
893 }
894 }
895 impl From<BellClass> for u32 {
896 #[inline]
from(input: BellClass) -> Self897 fn from(input: BellClass) -> Self {
898 u32::from(input.0)
899 }
900 }
901 impl From<BellClass> for Option<u32> {
902 #[inline]
from(input: BellClass) -> Self903 fn from(input: BellClass) -> Self {
904 Some(u32::from(input.0))
905 }
906 }
907 impl From<u8> for BellClass {
908 #[inline]
from(value: u8) -> Self909 fn from(value: u8) -> Self {
910 Self(value.into())
911 }
912 }
913 impl From<u16> for BellClass {
914 #[inline]
from(value: u16) -> Self915 fn from(value: u16) -> Self {
916 Self(value)
917 }
918 }
919 impl std::fmt::Debug for BellClass {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result920 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
921 let variants = [
922 (Self::KBD_FEEDBACK_CLASS.0.into(), "KBD_FEEDBACK_CLASS", "KbdFeedbackClass"),
923 (Self::BELL_FEEDBACK_CLASS.0.into(), "BELL_FEEDBACK_CLASS", "BellFeedbackClass"),
924 (Self::DFLT_XI_CLASS.0.into(), "DFLT_XI_CLASS", "DfltXIClass"),
925 ];
926 pretty_print_enum(fmt, self.0.into(), &variants)
927 }
928 }
929
930 pub type BellClassSpec = u16;
931
932 #[derive(Clone, Copy, PartialEq, Eq)]
933 pub struct ID(u16);
934 impl ID {
935 pub const USE_CORE_KBD: Self = Self(256);
936 pub const USE_CORE_PTR: Self = Self(512);
937 pub const DFLT_XI_CLASS: Self = Self(768);
938 pub const DFLT_XI_ID: Self = Self(1024);
939 pub const ALL_XI_CLASS: Self = Self(1280);
940 pub const ALL_XI_ID: Self = Self(1536);
941 pub const XI_NONE: Self = Self(65280);
942 }
943 impl From<ID> for u16 {
944 #[inline]
from(input: ID) -> Self945 fn from(input: ID) -> Self {
946 input.0
947 }
948 }
949 impl From<ID> for Option<u16> {
950 #[inline]
from(input: ID) -> Self951 fn from(input: ID) -> Self {
952 Some(input.0)
953 }
954 }
955 impl From<ID> for u32 {
956 #[inline]
from(input: ID) -> Self957 fn from(input: ID) -> Self {
958 u32::from(input.0)
959 }
960 }
961 impl From<ID> for Option<u32> {
962 #[inline]
from(input: ID) -> Self963 fn from(input: ID) -> Self {
964 Some(u32::from(input.0))
965 }
966 }
967 impl From<u8> for ID {
968 #[inline]
from(value: u8) -> Self969 fn from(value: u8) -> Self {
970 Self(value.into())
971 }
972 }
973 impl From<u16> for ID {
974 #[inline]
from(value: u16) -> Self975 fn from(value: u16) -> Self {
976 Self(value)
977 }
978 }
979 impl std::fmt::Debug for ID {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result980 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
981 let variants = [
982 (Self::USE_CORE_KBD.0.into(), "USE_CORE_KBD", "UseCoreKbd"),
983 (Self::USE_CORE_PTR.0.into(), "USE_CORE_PTR", "UseCorePtr"),
984 (Self::DFLT_XI_CLASS.0.into(), "DFLT_XI_CLASS", "DfltXIClass"),
985 (Self::DFLT_XI_ID.0.into(), "DFLT_XI_ID", "DfltXIId"),
986 (Self::ALL_XI_CLASS.0.into(), "ALL_XI_CLASS", "AllXIClass"),
987 (Self::ALL_XI_ID.0.into(), "ALL_XI_ID", "AllXIId"),
988 (Self::XI_NONE.0.into(), "XI_NONE", "XINone"),
989 ];
990 pretty_print_enum(fmt, self.0.into(), &variants)
991 }
992 }
993
994 pub type IDSpec = u16;
995
996 #[derive(Clone, Copy, PartialEq, Eq)]
997 pub struct Group(u8);
998 impl Group {
999 pub const M1: Self = Self(0);
1000 pub const M2: Self = Self(1);
1001 pub const M3: Self = Self(2);
1002 pub const M4: Self = Self(3);
1003 }
1004 impl From<Group> for u8 {
1005 #[inline]
from(input: Group) -> Self1006 fn from(input: Group) -> Self {
1007 input.0
1008 }
1009 }
1010 impl From<Group> for Option<u8> {
1011 #[inline]
from(input: Group) -> Self1012 fn from(input: Group) -> Self {
1013 Some(input.0)
1014 }
1015 }
1016 impl From<Group> for u16 {
1017 #[inline]
from(input: Group) -> Self1018 fn from(input: Group) -> Self {
1019 u16::from(input.0)
1020 }
1021 }
1022 impl From<Group> for Option<u16> {
1023 #[inline]
from(input: Group) -> Self1024 fn from(input: Group) -> Self {
1025 Some(u16::from(input.0))
1026 }
1027 }
1028 impl From<Group> for u32 {
1029 #[inline]
from(input: Group) -> Self1030 fn from(input: Group) -> Self {
1031 u32::from(input.0)
1032 }
1033 }
1034 impl From<Group> for Option<u32> {
1035 #[inline]
from(input: Group) -> Self1036 fn from(input: Group) -> Self {
1037 Some(u32::from(input.0))
1038 }
1039 }
1040 impl From<u8> for Group {
1041 #[inline]
from(value: u8) -> Self1042 fn from(value: u8) -> Self {
1043 Self(value)
1044 }
1045 }
1046 impl std::fmt::Debug for Group {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result1047 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1048 let variants = [
1049 (Self::M1.0.into(), "M1", "M1"),
1050 (Self::M2.0.into(), "M2", "M2"),
1051 (Self::M3.0.into(), "M3", "M3"),
1052 (Self::M4.0.into(), "M4", "M4"),
1053 ];
1054 pretty_print_enum(fmt, self.0.into(), &variants)
1055 }
1056 }
1057
1058 #[derive(Clone, Copy, PartialEq, Eq)]
1059 pub struct Groups(u8);
1060 impl Groups {
1061 pub const ANY: Self = Self(254);
1062 pub const ALL: Self = Self(255);
1063 }
1064 impl From<Groups> for u8 {
1065 #[inline]
from(input: Groups) -> Self1066 fn from(input: Groups) -> Self {
1067 input.0
1068 }
1069 }
1070 impl From<Groups> for Option<u8> {
1071 #[inline]
from(input: Groups) -> Self1072 fn from(input: Groups) -> Self {
1073 Some(input.0)
1074 }
1075 }
1076 impl From<Groups> for u16 {
1077 #[inline]
from(input: Groups) -> Self1078 fn from(input: Groups) -> Self {
1079 u16::from(input.0)
1080 }
1081 }
1082 impl From<Groups> for Option<u16> {
1083 #[inline]
from(input: Groups) -> Self1084 fn from(input: Groups) -> Self {
1085 Some(u16::from(input.0))
1086 }
1087 }
1088 impl From<Groups> for u32 {
1089 #[inline]
from(input: Groups) -> Self1090 fn from(input: Groups) -> Self {
1091 u32::from(input.0)
1092 }
1093 }
1094 impl From<Groups> for Option<u32> {
1095 #[inline]
from(input: Groups) -> Self1096 fn from(input: Groups) -> Self {
1097 Some(u32::from(input.0))
1098 }
1099 }
1100 impl From<u8> for Groups {
1101 #[inline]
from(value: u8) -> Self1102 fn from(value: u8) -> Self {
1103 Self(value)
1104 }
1105 }
1106 impl std::fmt::Debug for Groups {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result1107 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1108 let variants = [
1109 (Self::ANY.0.into(), "ANY", "Any"),
1110 (Self::ALL.0.into(), "ALL", "All"),
1111 ];
1112 pretty_print_enum(fmt, self.0.into(), &variants)
1113 }
1114 }
1115
1116 #[derive(Clone, Copy, PartialEq, Eq)]
1117 pub struct SetOfGroup(u8);
1118 impl SetOfGroup {
1119 pub const GROUP1: Self = Self(1 << 0);
1120 pub const GROUP2: Self = Self(1 << 1);
1121 pub const GROUP3: Self = Self(1 << 2);
1122 pub const GROUP4: Self = Self(1 << 3);
1123 }
1124 impl From<SetOfGroup> for u8 {
1125 #[inline]
from(input: SetOfGroup) -> Self1126 fn from(input: SetOfGroup) -> Self {
1127 input.0
1128 }
1129 }
1130 impl From<SetOfGroup> for Option<u8> {
1131 #[inline]
from(input: SetOfGroup) -> Self1132 fn from(input: SetOfGroup) -> Self {
1133 Some(input.0)
1134 }
1135 }
1136 impl From<SetOfGroup> for u16 {
1137 #[inline]
from(input: SetOfGroup) -> Self1138 fn from(input: SetOfGroup) -> Self {
1139 u16::from(input.0)
1140 }
1141 }
1142 impl From<SetOfGroup> for Option<u16> {
1143 #[inline]
from(input: SetOfGroup) -> Self1144 fn from(input: SetOfGroup) -> Self {
1145 Some(u16::from(input.0))
1146 }
1147 }
1148 impl From<SetOfGroup> for u32 {
1149 #[inline]
from(input: SetOfGroup) -> Self1150 fn from(input: SetOfGroup) -> Self {
1151 u32::from(input.0)
1152 }
1153 }
1154 impl From<SetOfGroup> for Option<u32> {
1155 #[inline]
from(input: SetOfGroup) -> Self1156 fn from(input: SetOfGroup) -> Self {
1157 Some(u32::from(input.0))
1158 }
1159 }
1160 impl From<u8> for SetOfGroup {
1161 #[inline]
from(value: u8) -> Self1162 fn from(value: u8) -> Self {
1163 Self(value)
1164 }
1165 }
1166 impl std::fmt::Debug for SetOfGroup {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result1167 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1168 let variants = [
1169 (Self::GROUP1.0.into(), "GROUP1", "Group1"),
1170 (Self::GROUP2.0.into(), "GROUP2", "Group2"),
1171 (Self::GROUP3.0.into(), "GROUP3", "Group3"),
1172 (Self::GROUP4.0.into(), "GROUP4", "Group4"),
1173 ];
1174 pretty_print_bitmask(fmt, self.0.into(), &variants)
1175 }
1176 }
1177 bitmask_binop!(SetOfGroup, u8);
1178
1179 #[derive(Clone, Copy, PartialEq, Eq)]
1180 pub struct SetOfGroups(u8);
1181 impl SetOfGroups {
1182 pub const ANY: Self = Self(1 << 7);
1183 }
1184 impl From<SetOfGroups> for u8 {
1185 #[inline]
from(input: SetOfGroups) -> Self1186 fn from(input: SetOfGroups) -> Self {
1187 input.0
1188 }
1189 }
1190 impl From<SetOfGroups> for Option<u8> {
1191 #[inline]
from(input: SetOfGroups) -> Self1192 fn from(input: SetOfGroups) -> Self {
1193 Some(input.0)
1194 }
1195 }
1196 impl From<SetOfGroups> for u16 {
1197 #[inline]
from(input: SetOfGroups) -> Self1198 fn from(input: SetOfGroups) -> Self {
1199 u16::from(input.0)
1200 }
1201 }
1202 impl From<SetOfGroups> for Option<u16> {
1203 #[inline]
from(input: SetOfGroups) -> Self1204 fn from(input: SetOfGroups) -> Self {
1205 Some(u16::from(input.0))
1206 }
1207 }
1208 impl From<SetOfGroups> for u32 {
1209 #[inline]
from(input: SetOfGroups) -> Self1210 fn from(input: SetOfGroups) -> Self {
1211 u32::from(input.0)
1212 }
1213 }
1214 impl From<SetOfGroups> for Option<u32> {
1215 #[inline]
from(input: SetOfGroups) -> Self1216 fn from(input: SetOfGroups) -> Self {
1217 Some(u32::from(input.0))
1218 }
1219 }
1220 impl From<u8> for SetOfGroups {
1221 #[inline]
from(value: u8) -> Self1222 fn from(value: u8) -> Self {
1223 Self(value)
1224 }
1225 }
1226 impl std::fmt::Debug for SetOfGroups {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result1227 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1228 let variants = [
1229 (Self::ANY.0.into(), "ANY", "Any"),
1230 ];
1231 pretty_print_bitmask(fmt, self.0.into(), &variants)
1232 }
1233 }
1234 bitmask_binop!(SetOfGroups, u8);
1235
1236 #[derive(Clone, Copy, PartialEq, Eq)]
1237 pub struct GroupsWrap(u8);
1238 impl GroupsWrap {
1239 pub const WRAP_INTO_RANGE: Self = Self(0);
1240 pub const CLAMP_INTO_RANGE: Self = Self(1 << 6);
1241 pub const REDIRECT_INTO_RANGE: Self = Self(1 << 7);
1242 }
1243 impl From<GroupsWrap> for u8 {
1244 #[inline]
from(input: GroupsWrap) -> Self1245 fn from(input: GroupsWrap) -> Self {
1246 input.0
1247 }
1248 }
1249 impl From<GroupsWrap> for Option<u8> {
1250 #[inline]
from(input: GroupsWrap) -> Self1251 fn from(input: GroupsWrap) -> Self {
1252 Some(input.0)
1253 }
1254 }
1255 impl From<GroupsWrap> for u16 {
1256 #[inline]
from(input: GroupsWrap) -> Self1257 fn from(input: GroupsWrap) -> Self {
1258 u16::from(input.0)
1259 }
1260 }
1261 impl From<GroupsWrap> for Option<u16> {
1262 #[inline]
from(input: GroupsWrap) -> Self1263 fn from(input: GroupsWrap) -> Self {
1264 Some(u16::from(input.0))
1265 }
1266 }
1267 impl From<GroupsWrap> for u32 {
1268 #[inline]
from(input: GroupsWrap) -> Self1269 fn from(input: GroupsWrap) -> Self {
1270 u32::from(input.0)
1271 }
1272 }
1273 impl From<GroupsWrap> for Option<u32> {
1274 #[inline]
from(input: GroupsWrap) -> Self1275 fn from(input: GroupsWrap) -> Self {
1276 Some(u32::from(input.0))
1277 }
1278 }
1279 impl From<u8> for GroupsWrap {
1280 #[inline]
from(value: u8) -> Self1281 fn from(value: u8) -> Self {
1282 Self(value)
1283 }
1284 }
1285 impl std::fmt::Debug for GroupsWrap {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result1286 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1287 let variants = [
1288 (Self::WRAP_INTO_RANGE.0.into(), "WRAP_INTO_RANGE", "WrapIntoRange"),
1289 (Self::CLAMP_INTO_RANGE.0.into(), "CLAMP_INTO_RANGE", "ClampIntoRange"),
1290 (Self::REDIRECT_INTO_RANGE.0.into(), "REDIRECT_INTO_RANGE", "RedirectIntoRange"),
1291 ];
1292 pretty_print_bitmask(fmt, self.0.into(), &variants)
1293 }
1294 }
1295 bitmask_binop!(GroupsWrap, u8);
1296
1297 #[derive(Clone, Copy, PartialEq, Eq)]
1298 pub struct VModsHigh(u8);
1299 impl VModsHigh {
1300 pub const M15: Self = Self(1 << 7);
1301 pub const M14: Self = Self(1 << 6);
1302 pub const M13: Self = Self(1 << 5);
1303 pub const M12: Self = Self(1 << 4);
1304 pub const M11: Self = Self(1 << 3);
1305 pub const M10: Self = Self(1 << 2);
1306 pub const M9: Self = Self(1 << 1);
1307 pub const M8: Self = Self(1 << 0);
1308 }
1309 impl From<VModsHigh> for u8 {
1310 #[inline]
from(input: VModsHigh) -> Self1311 fn from(input: VModsHigh) -> Self {
1312 input.0
1313 }
1314 }
1315 impl From<VModsHigh> for Option<u8> {
1316 #[inline]
from(input: VModsHigh) -> Self1317 fn from(input: VModsHigh) -> Self {
1318 Some(input.0)
1319 }
1320 }
1321 impl From<VModsHigh> for u16 {
1322 #[inline]
from(input: VModsHigh) -> Self1323 fn from(input: VModsHigh) -> Self {
1324 u16::from(input.0)
1325 }
1326 }
1327 impl From<VModsHigh> for Option<u16> {
1328 #[inline]
from(input: VModsHigh) -> Self1329 fn from(input: VModsHigh) -> Self {
1330 Some(u16::from(input.0))
1331 }
1332 }
1333 impl From<VModsHigh> for u32 {
1334 #[inline]
from(input: VModsHigh) -> Self1335 fn from(input: VModsHigh) -> Self {
1336 u32::from(input.0)
1337 }
1338 }
1339 impl From<VModsHigh> for Option<u32> {
1340 #[inline]
from(input: VModsHigh) -> Self1341 fn from(input: VModsHigh) -> Self {
1342 Some(u32::from(input.0))
1343 }
1344 }
1345 impl From<u8> for VModsHigh {
1346 #[inline]
from(value: u8) -> Self1347 fn from(value: u8) -> Self {
1348 Self(value)
1349 }
1350 }
1351 impl std::fmt::Debug for VModsHigh {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result1352 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1353 let variants = [
1354 (Self::M15.0.into(), "M15", "M15"),
1355 (Self::M14.0.into(), "M14", "M14"),
1356 (Self::M13.0.into(), "M13", "M13"),
1357 (Self::M12.0.into(), "M12", "M12"),
1358 (Self::M11.0.into(), "M11", "M11"),
1359 (Self::M10.0.into(), "M10", "M10"),
1360 (Self::M9.0.into(), "M9", "M9"),
1361 (Self::M8.0.into(), "M8", "M8"),
1362 ];
1363 pretty_print_bitmask(fmt, self.0.into(), &variants)
1364 }
1365 }
1366 bitmask_binop!(VModsHigh, u8);
1367
1368 #[derive(Clone, Copy, PartialEq, Eq)]
1369 pub struct VModsLow(u8);
1370 impl VModsLow {
1371 pub const M7: Self = Self(1 << 7);
1372 pub const M6: Self = Self(1 << 6);
1373 pub const M5: Self = Self(1 << 5);
1374 pub const M4: Self = Self(1 << 4);
1375 pub const M3: Self = Self(1 << 3);
1376 pub const M2: Self = Self(1 << 2);
1377 pub const M1: Self = Self(1 << 1);
1378 pub const M0: Self = Self(1 << 0);
1379 }
1380 impl From<VModsLow> for u8 {
1381 #[inline]
from(input: VModsLow) -> Self1382 fn from(input: VModsLow) -> Self {
1383 input.0
1384 }
1385 }
1386 impl From<VModsLow> for Option<u8> {
1387 #[inline]
from(input: VModsLow) -> Self1388 fn from(input: VModsLow) -> Self {
1389 Some(input.0)
1390 }
1391 }
1392 impl From<VModsLow> for u16 {
1393 #[inline]
from(input: VModsLow) -> Self1394 fn from(input: VModsLow) -> Self {
1395 u16::from(input.0)
1396 }
1397 }
1398 impl From<VModsLow> for Option<u16> {
1399 #[inline]
from(input: VModsLow) -> Self1400 fn from(input: VModsLow) -> Self {
1401 Some(u16::from(input.0))
1402 }
1403 }
1404 impl From<VModsLow> for u32 {
1405 #[inline]
from(input: VModsLow) -> Self1406 fn from(input: VModsLow) -> Self {
1407 u32::from(input.0)
1408 }
1409 }
1410 impl From<VModsLow> for Option<u32> {
1411 #[inline]
from(input: VModsLow) -> Self1412 fn from(input: VModsLow) -> Self {
1413 Some(u32::from(input.0))
1414 }
1415 }
1416 impl From<u8> for VModsLow {
1417 #[inline]
from(value: u8) -> Self1418 fn from(value: u8) -> Self {
1419 Self(value)
1420 }
1421 }
1422 impl std::fmt::Debug for VModsLow {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result1423 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1424 let variants = [
1425 (Self::M7.0.into(), "M7", "M7"),
1426 (Self::M6.0.into(), "M6", "M6"),
1427 (Self::M5.0.into(), "M5", "M5"),
1428 (Self::M4.0.into(), "M4", "M4"),
1429 (Self::M3.0.into(), "M3", "M3"),
1430 (Self::M2.0.into(), "M2", "M2"),
1431 (Self::M1.0.into(), "M1", "M1"),
1432 (Self::M0.0.into(), "M0", "M0"),
1433 ];
1434 pretty_print_bitmask(fmt, self.0.into(), &variants)
1435 }
1436 }
1437 bitmask_binop!(VModsLow, u8);
1438
1439 #[derive(Clone, Copy, PartialEq, Eq)]
1440 pub struct VMod(u16);
1441 impl VMod {
1442 pub const M15: Self = Self(1 << 15);
1443 pub const M14: Self = Self(1 << 14);
1444 pub const M13: Self = Self(1 << 13);
1445 pub const M12: Self = Self(1 << 12);
1446 pub const M11: Self = Self(1 << 11);
1447 pub const M10: Self = Self(1 << 10);
1448 pub const M9: Self = Self(1 << 9);
1449 pub const M8: Self = Self(1 << 8);
1450 pub const M7: Self = Self(1 << 7);
1451 pub const M6: Self = Self(1 << 6);
1452 pub const M5: Self = Self(1 << 5);
1453 pub const M4: Self = Self(1 << 4);
1454 pub const M3: Self = Self(1 << 3);
1455 pub const M2: Self = Self(1 << 2);
1456 pub const M1: Self = Self(1 << 1);
1457 pub const M0: Self = Self(1 << 0);
1458 }
1459 impl From<VMod> for u16 {
1460 #[inline]
from(input: VMod) -> Self1461 fn from(input: VMod) -> Self {
1462 input.0
1463 }
1464 }
1465 impl From<VMod> for Option<u16> {
1466 #[inline]
from(input: VMod) -> Self1467 fn from(input: VMod) -> Self {
1468 Some(input.0)
1469 }
1470 }
1471 impl From<VMod> for u32 {
1472 #[inline]
from(input: VMod) -> Self1473 fn from(input: VMod) -> Self {
1474 u32::from(input.0)
1475 }
1476 }
1477 impl From<VMod> for Option<u32> {
1478 #[inline]
from(input: VMod) -> Self1479 fn from(input: VMod) -> Self {
1480 Some(u32::from(input.0))
1481 }
1482 }
1483 impl From<u8> for VMod {
1484 #[inline]
from(value: u8) -> Self1485 fn from(value: u8) -> Self {
1486 Self(value.into())
1487 }
1488 }
1489 impl From<u16> for VMod {
1490 #[inline]
from(value: u16) -> Self1491 fn from(value: u16) -> Self {
1492 Self(value)
1493 }
1494 }
1495 impl std::fmt::Debug for VMod {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result1496 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1497 let variants = [
1498 (Self::M15.0.into(), "M15", "M15"),
1499 (Self::M14.0.into(), "M14", "M14"),
1500 (Self::M13.0.into(), "M13", "M13"),
1501 (Self::M12.0.into(), "M12", "M12"),
1502 (Self::M11.0.into(), "M11", "M11"),
1503 (Self::M10.0.into(), "M10", "M10"),
1504 (Self::M9.0.into(), "M9", "M9"),
1505 (Self::M8.0.into(), "M8", "M8"),
1506 (Self::M7.0.into(), "M7", "M7"),
1507 (Self::M6.0.into(), "M6", "M6"),
1508 (Self::M5.0.into(), "M5", "M5"),
1509 (Self::M4.0.into(), "M4", "M4"),
1510 (Self::M3.0.into(), "M3", "M3"),
1511 (Self::M2.0.into(), "M2", "M2"),
1512 (Self::M1.0.into(), "M1", "M1"),
1513 (Self::M0.0.into(), "M0", "M0"),
1514 ];
1515 pretty_print_bitmask(fmt, self.0.into(), &variants)
1516 }
1517 }
1518 bitmask_binop!(VMod, u16);
1519
1520 #[derive(Clone, Copy, PartialEq, Eq)]
1521 pub struct Explicit(u8);
1522 impl Explicit {
1523 pub const V_MOD_MAP: Self = Self(1 << 7);
1524 pub const BEHAVIOR: Self = Self(1 << 6);
1525 pub const AUTO_REPEAT: Self = Self(1 << 5);
1526 pub const INTERPRET: Self = Self(1 << 4);
1527 pub const KEY_TYPE4: Self = Self(1 << 3);
1528 pub const KEY_TYPE3: Self = Self(1 << 2);
1529 pub const KEY_TYPE2: Self = Self(1 << 1);
1530 pub const KEY_TYPE1: Self = Self(1 << 0);
1531 }
1532 impl From<Explicit> for u8 {
1533 #[inline]
from(input: Explicit) -> Self1534 fn from(input: Explicit) -> Self {
1535 input.0
1536 }
1537 }
1538 impl From<Explicit> for Option<u8> {
1539 #[inline]
from(input: Explicit) -> Self1540 fn from(input: Explicit) -> Self {
1541 Some(input.0)
1542 }
1543 }
1544 impl From<Explicit> for u16 {
1545 #[inline]
from(input: Explicit) -> Self1546 fn from(input: Explicit) -> Self {
1547 u16::from(input.0)
1548 }
1549 }
1550 impl From<Explicit> for Option<u16> {
1551 #[inline]
from(input: Explicit) -> Self1552 fn from(input: Explicit) -> Self {
1553 Some(u16::from(input.0))
1554 }
1555 }
1556 impl From<Explicit> for u32 {
1557 #[inline]
from(input: Explicit) -> Self1558 fn from(input: Explicit) -> Self {
1559 u32::from(input.0)
1560 }
1561 }
1562 impl From<Explicit> for Option<u32> {
1563 #[inline]
from(input: Explicit) -> Self1564 fn from(input: Explicit) -> Self {
1565 Some(u32::from(input.0))
1566 }
1567 }
1568 impl From<u8> for Explicit {
1569 #[inline]
from(value: u8) -> Self1570 fn from(value: u8) -> Self {
1571 Self(value)
1572 }
1573 }
1574 impl std::fmt::Debug for Explicit {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result1575 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1576 let variants = [
1577 (Self::V_MOD_MAP.0.into(), "V_MOD_MAP", "VModMap"),
1578 (Self::BEHAVIOR.0.into(), "BEHAVIOR", "Behavior"),
1579 (Self::AUTO_REPEAT.0.into(), "AUTO_REPEAT", "AutoRepeat"),
1580 (Self::INTERPRET.0.into(), "INTERPRET", "Interpret"),
1581 (Self::KEY_TYPE4.0.into(), "KEY_TYPE4", "KeyType4"),
1582 (Self::KEY_TYPE3.0.into(), "KEY_TYPE3", "KeyType3"),
1583 (Self::KEY_TYPE2.0.into(), "KEY_TYPE2", "KeyType2"),
1584 (Self::KEY_TYPE1.0.into(), "KEY_TYPE1", "KeyType1"),
1585 ];
1586 pretty_print_bitmask(fmt, self.0.into(), &variants)
1587 }
1588 }
1589 bitmask_binop!(Explicit, u8);
1590
1591 #[derive(Clone, Copy, PartialEq, Eq)]
1592 pub struct SymInterpretMatch(u8);
1593 impl SymInterpretMatch {
1594 pub const NONE_OF: Self = Self(0);
1595 pub const ANY_OF_OR_NONE: Self = Self(1);
1596 pub const ANY_OF: Self = Self(2);
1597 pub const ALL_OF: Self = Self(3);
1598 pub const EXACTLY: Self = Self(4);
1599 }
1600 impl From<SymInterpretMatch> for u8 {
1601 #[inline]
from(input: SymInterpretMatch) -> Self1602 fn from(input: SymInterpretMatch) -> Self {
1603 input.0
1604 }
1605 }
1606 impl From<SymInterpretMatch> for Option<u8> {
1607 #[inline]
from(input: SymInterpretMatch) -> Self1608 fn from(input: SymInterpretMatch) -> Self {
1609 Some(input.0)
1610 }
1611 }
1612 impl From<SymInterpretMatch> for u16 {
1613 #[inline]
from(input: SymInterpretMatch) -> Self1614 fn from(input: SymInterpretMatch) -> Self {
1615 u16::from(input.0)
1616 }
1617 }
1618 impl From<SymInterpretMatch> for Option<u16> {
1619 #[inline]
from(input: SymInterpretMatch) -> Self1620 fn from(input: SymInterpretMatch) -> Self {
1621 Some(u16::from(input.0))
1622 }
1623 }
1624 impl From<SymInterpretMatch> for u32 {
1625 #[inline]
from(input: SymInterpretMatch) -> Self1626 fn from(input: SymInterpretMatch) -> Self {
1627 u32::from(input.0)
1628 }
1629 }
1630 impl From<SymInterpretMatch> for Option<u32> {
1631 #[inline]
from(input: SymInterpretMatch) -> Self1632 fn from(input: SymInterpretMatch) -> Self {
1633 Some(u32::from(input.0))
1634 }
1635 }
1636 impl From<u8> for SymInterpretMatch {
1637 #[inline]
from(value: u8) -> Self1638 fn from(value: u8) -> Self {
1639 Self(value)
1640 }
1641 }
1642 impl std::fmt::Debug for SymInterpretMatch {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result1643 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1644 let variants = [
1645 (Self::NONE_OF.0.into(), "NONE_OF", "NoneOf"),
1646 (Self::ANY_OF_OR_NONE.0.into(), "ANY_OF_OR_NONE", "AnyOfOrNone"),
1647 (Self::ANY_OF.0.into(), "ANY_OF", "AnyOf"),
1648 (Self::ALL_OF.0.into(), "ALL_OF", "AllOf"),
1649 (Self::EXACTLY.0.into(), "EXACTLY", "Exactly"),
1650 ];
1651 pretty_print_enum(fmt, self.0.into(), &variants)
1652 }
1653 }
1654
1655 #[derive(Clone, Copy, PartialEq, Eq)]
1656 pub struct SymInterpMatch(u8);
1657 impl SymInterpMatch {
1658 pub const LEVEL_ONE_ONLY: Self = Self(1 << 7);
1659 pub const OP_MASK: Self = Self(127);
1660 }
1661 impl From<SymInterpMatch> for u8 {
1662 #[inline]
from(input: SymInterpMatch) -> Self1663 fn from(input: SymInterpMatch) -> Self {
1664 input.0
1665 }
1666 }
1667 impl From<SymInterpMatch> for Option<u8> {
1668 #[inline]
from(input: SymInterpMatch) -> Self1669 fn from(input: SymInterpMatch) -> Self {
1670 Some(input.0)
1671 }
1672 }
1673 impl From<SymInterpMatch> for u16 {
1674 #[inline]
from(input: SymInterpMatch) -> Self1675 fn from(input: SymInterpMatch) -> Self {
1676 u16::from(input.0)
1677 }
1678 }
1679 impl From<SymInterpMatch> for Option<u16> {
1680 #[inline]
from(input: SymInterpMatch) -> Self1681 fn from(input: SymInterpMatch) -> Self {
1682 Some(u16::from(input.0))
1683 }
1684 }
1685 impl From<SymInterpMatch> for u32 {
1686 #[inline]
from(input: SymInterpMatch) -> Self1687 fn from(input: SymInterpMatch) -> Self {
1688 u32::from(input.0)
1689 }
1690 }
1691 impl From<SymInterpMatch> for Option<u32> {
1692 #[inline]
from(input: SymInterpMatch) -> Self1693 fn from(input: SymInterpMatch) -> Self {
1694 Some(u32::from(input.0))
1695 }
1696 }
1697 impl From<u8> for SymInterpMatch {
1698 #[inline]
from(value: u8) -> Self1699 fn from(value: u8) -> Self {
1700 Self(value)
1701 }
1702 }
1703 impl std::fmt::Debug for SymInterpMatch {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result1704 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1705 let variants = [
1706 (Self::LEVEL_ONE_ONLY.0.into(), "LEVEL_ONE_ONLY", "LevelOneOnly"),
1707 (Self::OP_MASK.0.into(), "OP_MASK", "OpMask"),
1708 ];
1709 pretty_print_enum(fmt, self.0.into(), &variants)
1710 }
1711 }
1712
1713 #[derive(Clone, Copy, PartialEq, Eq)]
1714 pub struct IMFlag(u8);
1715 impl IMFlag {
1716 pub const NO_EXPLICIT: Self = Self(1 << 7);
1717 pub const NO_AUTOMATIC: Self = Self(1 << 6);
1718 pub const LED_DRIVES_KB: Self = Self(1 << 5);
1719 }
1720 impl From<IMFlag> for u8 {
1721 #[inline]
from(input: IMFlag) -> Self1722 fn from(input: IMFlag) -> Self {
1723 input.0
1724 }
1725 }
1726 impl From<IMFlag> for Option<u8> {
1727 #[inline]
from(input: IMFlag) -> Self1728 fn from(input: IMFlag) -> Self {
1729 Some(input.0)
1730 }
1731 }
1732 impl From<IMFlag> for u16 {
1733 #[inline]
from(input: IMFlag) -> Self1734 fn from(input: IMFlag) -> Self {
1735 u16::from(input.0)
1736 }
1737 }
1738 impl From<IMFlag> for Option<u16> {
1739 #[inline]
from(input: IMFlag) -> Self1740 fn from(input: IMFlag) -> Self {
1741 Some(u16::from(input.0))
1742 }
1743 }
1744 impl From<IMFlag> for u32 {
1745 #[inline]
from(input: IMFlag) -> Self1746 fn from(input: IMFlag) -> Self {
1747 u32::from(input.0)
1748 }
1749 }
1750 impl From<IMFlag> for Option<u32> {
1751 #[inline]
from(input: IMFlag) -> Self1752 fn from(input: IMFlag) -> Self {
1753 Some(u32::from(input.0))
1754 }
1755 }
1756 impl From<u8> for IMFlag {
1757 #[inline]
from(value: u8) -> Self1758 fn from(value: u8) -> Self {
1759 Self(value)
1760 }
1761 }
1762 impl std::fmt::Debug for IMFlag {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result1763 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1764 let variants = [
1765 (Self::NO_EXPLICIT.0.into(), "NO_EXPLICIT", "NoExplicit"),
1766 (Self::NO_AUTOMATIC.0.into(), "NO_AUTOMATIC", "NoAutomatic"),
1767 (Self::LED_DRIVES_KB.0.into(), "LED_DRIVES_KB", "LEDDrivesKB"),
1768 ];
1769 pretty_print_bitmask(fmt, self.0.into(), &variants)
1770 }
1771 }
1772 bitmask_binop!(IMFlag, u8);
1773
1774 #[derive(Clone, Copy, PartialEq, Eq)]
1775 pub struct IMModsWhich(u8);
1776 impl IMModsWhich {
1777 pub const USE_COMPAT: Self = Self(1 << 4);
1778 pub const USE_EFFECTIVE: Self = Self(1 << 3);
1779 pub const USE_LOCKED: Self = Self(1 << 2);
1780 pub const USE_LATCHED: Self = Self(1 << 1);
1781 pub const USE_BASE: Self = Self(1 << 0);
1782 }
1783 impl From<IMModsWhich> for u8 {
1784 #[inline]
from(input: IMModsWhich) -> Self1785 fn from(input: IMModsWhich) -> Self {
1786 input.0
1787 }
1788 }
1789 impl From<IMModsWhich> for Option<u8> {
1790 #[inline]
from(input: IMModsWhich) -> Self1791 fn from(input: IMModsWhich) -> Self {
1792 Some(input.0)
1793 }
1794 }
1795 impl From<IMModsWhich> for u16 {
1796 #[inline]
from(input: IMModsWhich) -> Self1797 fn from(input: IMModsWhich) -> Self {
1798 u16::from(input.0)
1799 }
1800 }
1801 impl From<IMModsWhich> for Option<u16> {
1802 #[inline]
from(input: IMModsWhich) -> Self1803 fn from(input: IMModsWhich) -> Self {
1804 Some(u16::from(input.0))
1805 }
1806 }
1807 impl From<IMModsWhich> for u32 {
1808 #[inline]
from(input: IMModsWhich) -> Self1809 fn from(input: IMModsWhich) -> Self {
1810 u32::from(input.0)
1811 }
1812 }
1813 impl From<IMModsWhich> for Option<u32> {
1814 #[inline]
from(input: IMModsWhich) -> Self1815 fn from(input: IMModsWhich) -> Self {
1816 Some(u32::from(input.0))
1817 }
1818 }
1819 impl From<u8> for IMModsWhich {
1820 #[inline]
from(value: u8) -> Self1821 fn from(value: u8) -> Self {
1822 Self(value)
1823 }
1824 }
1825 impl std::fmt::Debug for IMModsWhich {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result1826 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1827 let variants = [
1828 (Self::USE_COMPAT.0.into(), "USE_COMPAT", "UseCompat"),
1829 (Self::USE_EFFECTIVE.0.into(), "USE_EFFECTIVE", "UseEffective"),
1830 (Self::USE_LOCKED.0.into(), "USE_LOCKED", "UseLocked"),
1831 (Self::USE_LATCHED.0.into(), "USE_LATCHED", "UseLatched"),
1832 (Self::USE_BASE.0.into(), "USE_BASE", "UseBase"),
1833 ];
1834 pretty_print_bitmask(fmt, self.0.into(), &variants)
1835 }
1836 }
1837 bitmask_binop!(IMModsWhich, u8);
1838
1839 #[derive(Clone, Copy, PartialEq, Eq)]
1840 pub struct IMGroupsWhich(u8);
1841 impl IMGroupsWhich {
1842 pub const USE_COMPAT: Self = Self(1 << 4);
1843 pub const USE_EFFECTIVE: Self = Self(1 << 3);
1844 pub const USE_LOCKED: Self = Self(1 << 2);
1845 pub const USE_LATCHED: Self = Self(1 << 1);
1846 pub const USE_BASE: Self = Self(1 << 0);
1847 }
1848 impl From<IMGroupsWhich> for u8 {
1849 #[inline]
from(input: IMGroupsWhich) -> Self1850 fn from(input: IMGroupsWhich) -> Self {
1851 input.0
1852 }
1853 }
1854 impl From<IMGroupsWhich> for Option<u8> {
1855 #[inline]
from(input: IMGroupsWhich) -> Self1856 fn from(input: IMGroupsWhich) -> Self {
1857 Some(input.0)
1858 }
1859 }
1860 impl From<IMGroupsWhich> for u16 {
1861 #[inline]
from(input: IMGroupsWhich) -> Self1862 fn from(input: IMGroupsWhich) -> Self {
1863 u16::from(input.0)
1864 }
1865 }
1866 impl From<IMGroupsWhich> for Option<u16> {
1867 #[inline]
from(input: IMGroupsWhich) -> Self1868 fn from(input: IMGroupsWhich) -> Self {
1869 Some(u16::from(input.0))
1870 }
1871 }
1872 impl From<IMGroupsWhich> for u32 {
1873 #[inline]
from(input: IMGroupsWhich) -> Self1874 fn from(input: IMGroupsWhich) -> Self {
1875 u32::from(input.0)
1876 }
1877 }
1878 impl From<IMGroupsWhich> for Option<u32> {
1879 #[inline]
from(input: IMGroupsWhich) -> Self1880 fn from(input: IMGroupsWhich) -> Self {
1881 Some(u32::from(input.0))
1882 }
1883 }
1884 impl From<u8> for IMGroupsWhich {
1885 #[inline]
from(value: u8) -> Self1886 fn from(value: u8) -> Self {
1887 Self(value)
1888 }
1889 }
1890 impl std::fmt::Debug for IMGroupsWhich {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result1891 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1892 let variants = [
1893 (Self::USE_COMPAT.0.into(), "USE_COMPAT", "UseCompat"),
1894 (Self::USE_EFFECTIVE.0.into(), "USE_EFFECTIVE", "UseEffective"),
1895 (Self::USE_LOCKED.0.into(), "USE_LOCKED", "UseLocked"),
1896 (Self::USE_LATCHED.0.into(), "USE_LATCHED", "UseLatched"),
1897 (Self::USE_BASE.0.into(), "USE_BASE", "UseBase"),
1898 ];
1899 pretty_print_bitmask(fmt, self.0.into(), &variants)
1900 }
1901 }
1902 bitmask_binop!(IMGroupsWhich, u8);
1903
1904 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
1905 pub struct IndicatorMap {
1906 pub flags: IMFlag,
1907 pub which_groups: IMGroupsWhich,
1908 pub groups: SetOfGroup,
1909 pub which_mods: IMModsWhich,
1910 pub mods: u8,
1911 pub real_mods: u8,
1912 pub vmods: u16,
1913 pub ctrls: u32,
1914 }
1915 impl TryParse for IndicatorMap {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>1916 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1917 let (flags, remaining) = u8::try_parse(remaining)?;
1918 let (which_groups, remaining) = u8::try_parse(remaining)?;
1919 let (groups, remaining) = u8::try_parse(remaining)?;
1920 let (which_mods, remaining) = u8::try_parse(remaining)?;
1921 let (mods, remaining) = u8::try_parse(remaining)?;
1922 let (real_mods, remaining) = u8::try_parse(remaining)?;
1923 let (vmods, remaining) = u16::try_parse(remaining)?;
1924 let (ctrls, remaining) = u32::try_parse(remaining)?;
1925 let flags = flags.into();
1926 let which_groups = which_groups.into();
1927 let groups = groups.into();
1928 let which_mods = which_mods.into();
1929 let result = IndicatorMap { flags, which_groups, groups, which_mods, mods, real_mods, vmods, ctrls };
1930 Ok((result, remaining))
1931 }
1932 }
1933 impl Serialize for IndicatorMap {
1934 type Bytes = [u8; 12];
serialize(&self) -> [u8; 12]1935 fn serialize(&self) -> [u8; 12] {
1936 let flags_bytes = u8::from(self.flags).serialize();
1937 let which_groups_bytes = u8::from(self.which_groups).serialize();
1938 let groups_bytes = u8::from(self.groups).serialize();
1939 let which_mods_bytes = u8::from(self.which_mods).serialize();
1940 let mods_bytes = self.mods.serialize();
1941 let real_mods_bytes = self.real_mods.serialize();
1942 let vmods_bytes = self.vmods.serialize();
1943 let ctrls_bytes = self.ctrls.serialize();
1944 [
1945 flags_bytes[0],
1946 which_groups_bytes[0],
1947 groups_bytes[0],
1948 which_mods_bytes[0],
1949 mods_bytes[0],
1950 real_mods_bytes[0],
1951 vmods_bytes[0],
1952 vmods_bytes[1],
1953 ctrls_bytes[0],
1954 ctrls_bytes[1],
1955 ctrls_bytes[2],
1956 ctrls_bytes[3],
1957 ]
1958 }
serialize_into(&self, bytes: &mut Vec<u8>)1959 fn serialize_into(&self, bytes: &mut Vec<u8>) {
1960 bytes.reserve(12);
1961 u8::from(self.flags).serialize_into(bytes);
1962 u8::from(self.which_groups).serialize_into(bytes);
1963 u8::from(self.groups).serialize_into(bytes);
1964 u8::from(self.which_mods).serialize_into(bytes);
1965 self.mods.serialize_into(bytes);
1966 self.real_mods.serialize_into(bytes);
1967 self.vmods.serialize_into(bytes);
1968 self.ctrls.serialize_into(bytes);
1969 }
1970 }
1971
1972 #[derive(Clone, Copy, PartialEq, Eq)]
1973 pub struct CMDetail(u8);
1974 impl CMDetail {
1975 pub const SYM_INTERP: Self = Self(1 << 0);
1976 pub const GROUP_COMPAT: Self = Self(1 << 1);
1977 }
1978 impl From<CMDetail> for u8 {
1979 #[inline]
from(input: CMDetail) -> Self1980 fn from(input: CMDetail) -> Self {
1981 input.0
1982 }
1983 }
1984 impl From<CMDetail> for Option<u8> {
1985 #[inline]
from(input: CMDetail) -> Self1986 fn from(input: CMDetail) -> Self {
1987 Some(input.0)
1988 }
1989 }
1990 impl From<CMDetail> for u16 {
1991 #[inline]
from(input: CMDetail) -> Self1992 fn from(input: CMDetail) -> Self {
1993 u16::from(input.0)
1994 }
1995 }
1996 impl From<CMDetail> for Option<u16> {
1997 #[inline]
from(input: CMDetail) -> Self1998 fn from(input: CMDetail) -> Self {
1999 Some(u16::from(input.0))
2000 }
2001 }
2002 impl From<CMDetail> for u32 {
2003 #[inline]
from(input: CMDetail) -> Self2004 fn from(input: CMDetail) -> Self {
2005 u32::from(input.0)
2006 }
2007 }
2008 impl From<CMDetail> for Option<u32> {
2009 #[inline]
from(input: CMDetail) -> Self2010 fn from(input: CMDetail) -> Self {
2011 Some(u32::from(input.0))
2012 }
2013 }
2014 impl From<u8> for CMDetail {
2015 #[inline]
from(value: u8) -> Self2016 fn from(value: u8) -> Self {
2017 Self(value)
2018 }
2019 }
2020 impl std::fmt::Debug for CMDetail {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result2021 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2022 let variants = [
2023 (Self::SYM_INTERP.0.into(), "SYM_INTERP", "SymInterp"),
2024 (Self::GROUP_COMPAT.0.into(), "GROUP_COMPAT", "GroupCompat"),
2025 ];
2026 pretty_print_bitmask(fmt, self.0.into(), &variants)
2027 }
2028 }
2029 bitmask_binop!(CMDetail, u8);
2030
2031 #[derive(Clone, Copy, PartialEq, Eq)]
2032 pub struct NameDetail(u16);
2033 impl NameDetail {
2034 pub const KEYCODES: Self = Self(1 << 0);
2035 pub const GEOMETRY: Self = Self(1 << 1);
2036 pub const SYMBOLS: Self = Self(1 << 2);
2037 pub const PHYS_SYMBOLS: Self = Self(1 << 3);
2038 pub const TYPES: Self = Self(1 << 4);
2039 pub const COMPAT: Self = Self(1 << 5);
2040 pub const KEY_TYPE_NAMES: Self = Self(1 << 6);
2041 pub const KT_LEVEL_NAMES: Self = Self(1 << 7);
2042 pub const INDICATOR_NAMES: Self = Self(1 << 8);
2043 pub const KEY_NAMES: Self = Self(1 << 9);
2044 pub const KEY_ALIASES: Self = Self(1 << 10);
2045 pub const VIRTUAL_MOD_NAMES: Self = Self(1 << 11);
2046 pub const GROUP_NAMES: Self = Self(1 << 12);
2047 pub const RG_NAMES: Self = Self(1 << 13);
2048 }
2049 impl From<NameDetail> for u16 {
2050 #[inline]
from(input: NameDetail) -> Self2051 fn from(input: NameDetail) -> Self {
2052 input.0
2053 }
2054 }
2055 impl From<NameDetail> for Option<u16> {
2056 #[inline]
from(input: NameDetail) -> Self2057 fn from(input: NameDetail) -> Self {
2058 Some(input.0)
2059 }
2060 }
2061 impl From<NameDetail> for u32 {
2062 #[inline]
from(input: NameDetail) -> Self2063 fn from(input: NameDetail) -> Self {
2064 u32::from(input.0)
2065 }
2066 }
2067 impl From<NameDetail> for Option<u32> {
2068 #[inline]
from(input: NameDetail) -> Self2069 fn from(input: NameDetail) -> Self {
2070 Some(u32::from(input.0))
2071 }
2072 }
2073 impl From<u8> for NameDetail {
2074 #[inline]
from(value: u8) -> Self2075 fn from(value: u8) -> Self {
2076 Self(value.into())
2077 }
2078 }
2079 impl From<u16> for NameDetail {
2080 #[inline]
from(value: u16) -> Self2081 fn from(value: u16) -> Self {
2082 Self(value)
2083 }
2084 }
2085 impl std::fmt::Debug for NameDetail {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result2086 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2087 let variants = [
2088 (Self::KEYCODES.0.into(), "KEYCODES", "Keycodes"),
2089 (Self::GEOMETRY.0.into(), "GEOMETRY", "Geometry"),
2090 (Self::SYMBOLS.0.into(), "SYMBOLS", "Symbols"),
2091 (Self::PHYS_SYMBOLS.0.into(), "PHYS_SYMBOLS", "PhysSymbols"),
2092 (Self::TYPES.0.into(), "TYPES", "Types"),
2093 (Self::COMPAT.0.into(), "COMPAT", "Compat"),
2094 (Self::KEY_TYPE_NAMES.0.into(), "KEY_TYPE_NAMES", "KeyTypeNames"),
2095 (Self::KT_LEVEL_NAMES.0.into(), "KT_LEVEL_NAMES", "KTLevelNames"),
2096 (Self::INDICATOR_NAMES.0.into(), "INDICATOR_NAMES", "IndicatorNames"),
2097 (Self::KEY_NAMES.0.into(), "KEY_NAMES", "KeyNames"),
2098 (Self::KEY_ALIASES.0.into(), "KEY_ALIASES", "KeyAliases"),
2099 (Self::VIRTUAL_MOD_NAMES.0.into(), "VIRTUAL_MOD_NAMES", "VirtualModNames"),
2100 (Self::GROUP_NAMES.0.into(), "GROUP_NAMES", "GroupNames"),
2101 (Self::RG_NAMES.0.into(), "RG_NAMES", "RGNames"),
2102 ];
2103 pretty_print_bitmask(fmt, self.0.into(), &variants)
2104 }
2105 }
2106 bitmask_binop!(NameDetail, u16);
2107
2108 #[derive(Clone, Copy, PartialEq, Eq)]
2109 pub struct GBNDetail(u8);
2110 impl GBNDetail {
2111 pub const TYPES: Self = Self(1 << 0);
2112 pub const COMPAT_MAP: Self = Self(1 << 1);
2113 pub const CLIENT_SYMBOLS: Self = Self(1 << 2);
2114 pub const SERVER_SYMBOLS: Self = Self(1 << 3);
2115 pub const INDICATOR_MAPS: Self = Self(1 << 4);
2116 pub const KEY_NAMES: Self = Self(1 << 5);
2117 pub const GEOMETRY: Self = Self(1 << 6);
2118 pub const OTHER_NAMES: Self = Self(1 << 7);
2119 }
2120 impl From<GBNDetail> for u8 {
2121 #[inline]
from(input: GBNDetail) -> Self2122 fn from(input: GBNDetail) -> Self {
2123 input.0
2124 }
2125 }
2126 impl From<GBNDetail> for Option<u8> {
2127 #[inline]
from(input: GBNDetail) -> Self2128 fn from(input: GBNDetail) -> Self {
2129 Some(input.0)
2130 }
2131 }
2132 impl From<GBNDetail> for u16 {
2133 #[inline]
from(input: GBNDetail) -> Self2134 fn from(input: GBNDetail) -> Self {
2135 u16::from(input.0)
2136 }
2137 }
2138 impl From<GBNDetail> for Option<u16> {
2139 #[inline]
from(input: GBNDetail) -> Self2140 fn from(input: GBNDetail) -> Self {
2141 Some(u16::from(input.0))
2142 }
2143 }
2144 impl From<GBNDetail> for u32 {
2145 #[inline]
from(input: GBNDetail) -> Self2146 fn from(input: GBNDetail) -> Self {
2147 u32::from(input.0)
2148 }
2149 }
2150 impl From<GBNDetail> for Option<u32> {
2151 #[inline]
from(input: GBNDetail) -> Self2152 fn from(input: GBNDetail) -> Self {
2153 Some(u32::from(input.0))
2154 }
2155 }
2156 impl From<u8> for GBNDetail {
2157 #[inline]
from(value: u8) -> Self2158 fn from(value: u8) -> Self {
2159 Self(value)
2160 }
2161 }
2162 impl std::fmt::Debug for GBNDetail {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result2163 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2164 let variants = [
2165 (Self::TYPES.0.into(), "TYPES", "Types"),
2166 (Self::COMPAT_MAP.0.into(), "COMPAT_MAP", "CompatMap"),
2167 (Self::CLIENT_SYMBOLS.0.into(), "CLIENT_SYMBOLS", "ClientSymbols"),
2168 (Self::SERVER_SYMBOLS.0.into(), "SERVER_SYMBOLS", "ServerSymbols"),
2169 (Self::INDICATOR_MAPS.0.into(), "INDICATOR_MAPS", "IndicatorMaps"),
2170 (Self::KEY_NAMES.0.into(), "KEY_NAMES", "KeyNames"),
2171 (Self::GEOMETRY.0.into(), "GEOMETRY", "Geometry"),
2172 (Self::OTHER_NAMES.0.into(), "OTHER_NAMES", "OtherNames"),
2173 ];
2174 pretty_print_bitmask(fmt, self.0.into(), &variants)
2175 }
2176 }
2177 bitmask_binop!(GBNDetail, u8);
2178
2179 #[derive(Clone, Copy, PartialEq, Eq)]
2180 pub struct XIFeature(u8);
2181 impl XIFeature {
2182 pub const KEYBOARDS: Self = Self(1 << 0);
2183 pub const BUTTON_ACTIONS: Self = Self(1 << 1);
2184 pub const INDICATOR_NAMES: Self = Self(1 << 2);
2185 pub const INDICATOR_MAPS: Self = Self(1 << 3);
2186 pub const INDICATOR_STATE: Self = Self(1 << 4);
2187 }
2188 impl From<XIFeature> for u8 {
2189 #[inline]
from(input: XIFeature) -> Self2190 fn from(input: XIFeature) -> Self {
2191 input.0
2192 }
2193 }
2194 impl From<XIFeature> for Option<u8> {
2195 #[inline]
from(input: XIFeature) -> Self2196 fn from(input: XIFeature) -> Self {
2197 Some(input.0)
2198 }
2199 }
2200 impl From<XIFeature> for u16 {
2201 #[inline]
from(input: XIFeature) -> Self2202 fn from(input: XIFeature) -> Self {
2203 u16::from(input.0)
2204 }
2205 }
2206 impl From<XIFeature> for Option<u16> {
2207 #[inline]
from(input: XIFeature) -> Self2208 fn from(input: XIFeature) -> Self {
2209 Some(u16::from(input.0))
2210 }
2211 }
2212 impl From<XIFeature> for u32 {
2213 #[inline]
from(input: XIFeature) -> Self2214 fn from(input: XIFeature) -> Self {
2215 u32::from(input.0)
2216 }
2217 }
2218 impl From<XIFeature> for Option<u32> {
2219 #[inline]
from(input: XIFeature) -> Self2220 fn from(input: XIFeature) -> Self {
2221 Some(u32::from(input.0))
2222 }
2223 }
2224 impl From<u8> for XIFeature {
2225 #[inline]
from(value: u8) -> Self2226 fn from(value: u8) -> Self {
2227 Self(value)
2228 }
2229 }
2230 impl std::fmt::Debug for XIFeature {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result2231 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2232 let variants = [
2233 (Self::KEYBOARDS.0.into(), "KEYBOARDS", "Keyboards"),
2234 (Self::BUTTON_ACTIONS.0.into(), "BUTTON_ACTIONS", "ButtonActions"),
2235 (Self::INDICATOR_NAMES.0.into(), "INDICATOR_NAMES", "IndicatorNames"),
2236 (Self::INDICATOR_MAPS.0.into(), "INDICATOR_MAPS", "IndicatorMaps"),
2237 (Self::INDICATOR_STATE.0.into(), "INDICATOR_STATE", "IndicatorState"),
2238 ];
2239 pretty_print_bitmask(fmt, self.0.into(), &variants)
2240 }
2241 }
2242 bitmask_binop!(XIFeature, u8);
2243
2244 #[derive(Clone, Copy, PartialEq, Eq)]
2245 pub struct PerClientFlag(u8);
2246 impl PerClientFlag {
2247 pub const DETECTABLE_AUTO_REPEAT: Self = Self(1 << 0);
2248 pub const GRABS_USE_XKB_STATE: Self = Self(1 << 1);
2249 pub const AUTO_RESET_CONTROLS: Self = Self(1 << 2);
2250 pub const LOOKUP_STATE_WHEN_GRABBED: Self = Self(1 << 3);
2251 pub const SEND_EVENT_USES_XKB_STATE: Self = Self(1 << 4);
2252 }
2253 impl From<PerClientFlag> for u8 {
2254 #[inline]
from(input: PerClientFlag) -> Self2255 fn from(input: PerClientFlag) -> Self {
2256 input.0
2257 }
2258 }
2259 impl From<PerClientFlag> for Option<u8> {
2260 #[inline]
from(input: PerClientFlag) -> Self2261 fn from(input: PerClientFlag) -> Self {
2262 Some(input.0)
2263 }
2264 }
2265 impl From<PerClientFlag> for u16 {
2266 #[inline]
from(input: PerClientFlag) -> Self2267 fn from(input: PerClientFlag) -> Self {
2268 u16::from(input.0)
2269 }
2270 }
2271 impl From<PerClientFlag> for Option<u16> {
2272 #[inline]
from(input: PerClientFlag) -> Self2273 fn from(input: PerClientFlag) -> Self {
2274 Some(u16::from(input.0))
2275 }
2276 }
2277 impl From<PerClientFlag> for u32 {
2278 #[inline]
from(input: PerClientFlag) -> Self2279 fn from(input: PerClientFlag) -> Self {
2280 u32::from(input.0)
2281 }
2282 }
2283 impl From<PerClientFlag> for Option<u32> {
2284 #[inline]
from(input: PerClientFlag) -> Self2285 fn from(input: PerClientFlag) -> Self {
2286 Some(u32::from(input.0))
2287 }
2288 }
2289 impl From<u8> for PerClientFlag {
2290 #[inline]
from(value: u8) -> Self2291 fn from(value: u8) -> Self {
2292 Self(value)
2293 }
2294 }
2295 impl std::fmt::Debug for PerClientFlag {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result2296 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2297 let variants = [
2298 (Self::DETECTABLE_AUTO_REPEAT.0.into(), "DETECTABLE_AUTO_REPEAT", "DetectableAutoRepeat"),
2299 (Self::GRABS_USE_XKB_STATE.0.into(), "GRABS_USE_XKB_STATE", "GrabsUseXKBState"),
2300 (Self::AUTO_RESET_CONTROLS.0.into(), "AUTO_RESET_CONTROLS", "AutoResetControls"),
2301 (Self::LOOKUP_STATE_WHEN_GRABBED.0.into(), "LOOKUP_STATE_WHEN_GRABBED", "LookupStateWhenGrabbed"),
2302 (Self::SEND_EVENT_USES_XKB_STATE.0.into(), "SEND_EVENT_USES_XKB_STATE", "SendEventUsesXKBState"),
2303 ];
2304 pretty_print_bitmask(fmt, self.0.into(), &variants)
2305 }
2306 }
2307 bitmask_binop!(PerClientFlag, u8);
2308
2309 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2310 pub struct ModDef {
2311 pub mask: u8,
2312 pub real_mods: u8,
2313 pub vmods: u16,
2314 }
2315 impl TryParse for ModDef {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>2316 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2317 let (mask, remaining) = u8::try_parse(remaining)?;
2318 let (real_mods, remaining) = u8::try_parse(remaining)?;
2319 let (vmods, remaining) = u16::try_parse(remaining)?;
2320 let result = ModDef { mask, real_mods, vmods };
2321 Ok((result, remaining))
2322 }
2323 }
2324 impl Serialize for ModDef {
2325 type Bytes = [u8; 4];
serialize(&self) -> [u8; 4]2326 fn serialize(&self) -> [u8; 4] {
2327 let mask_bytes = self.mask.serialize();
2328 let real_mods_bytes = self.real_mods.serialize();
2329 let vmods_bytes = self.vmods.serialize();
2330 [
2331 mask_bytes[0],
2332 real_mods_bytes[0],
2333 vmods_bytes[0],
2334 vmods_bytes[1],
2335 ]
2336 }
serialize_into(&self, bytes: &mut Vec<u8>)2337 fn serialize_into(&self, bytes: &mut Vec<u8>) {
2338 bytes.reserve(4);
2339 self.mask.serialize_into(bytes);
2340 self.real_mods.serialize_into(bytes);
2341 self.vmods.serialize_into(bytes);
2342 }
2343 }
2344
2345 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2346 pub struct KeyName {
2347 pub name: [u8; 4],
2348 }
2349 impl TryParse for KeyName {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>2350 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2351 let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, 4)?;
2352 let name = <[u8; 4]>::try_from(name).unwrap();
2353 let result = KeyName { name };
2354 Ok((result, remaining))
2355 }
2356 }
2357 impl Serialize for KeyName {
2358 type Bytes = [u8; 4];
serialize(&self) -> [u8; 4]2359 fn serialize(&self) -> [u8; 4] {
2360 [
2361 self.name[0],
2362 self.name[1],
2363 self.name[2],
2364 self.name[3],
2365 ]
2366 }
serialize_into(&self, bytes: &mut Vec<u8>)2367 fn serialize_into(&self, bytes: &mut Vec<u8>) {
2368 bytes.reserve(4);
2369 bytes.extend_from_slice(&self.name);
2370 }
2371 }
2372
2373 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2374 pub struct KeyAlias {
2375 pub real: [u8; 4],
2376 pub alias: [u8; 4],
2377 }
2378 impl TryParse for KeyAlias {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>2379 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2380 let (real, remaining) = crate::x11_utils::parse_u8_list(remaining, 4)?;
2381 let real = <[u8; 4]>::try_from(real).unwrap();
2382 let (alias, remaining) = crate::x11_utils::parse_u8_list(remaining, 4)?;
2383 let alias = <[u8; 4]>::try_from(alias).unwrap();
2384 let result = KeyAlias { real, alias };
2385 Ok((result, remaining))
2386 }
2387 }
2388 impl Serialize for KeyAlias {
2389 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]2390 fn serialize(&self) -> [u8; 8] {
2391 [
2392 self.real[0],
2393 self.real[1],
2394 self.real[2],
2395 self.real[3],
2396 self.alias[0],
2397 self.alias[1],
2398 self.alias[2],
2399 self.alias[3],
2400 ]
2401 }
serialize_into(&self, bytes: &mut Vec<u8>)2402 fn serialize_into(&self, bytes: &mut Vec<u8>) {
2403 bytes.reserve(8);
2404 bytes.extend_from_slice(&self.real);
2405 bytes.extend_from_slice(&self.alias);
2406 }
2407 }
2408
2409 #[derive(Debug, Clone, PartialEq, Eq)]
2410 pub struct CountedString16 {
2411 pub string: Vec<u8>,
2412 pub alignment_pad: Vec<u8>,
2413 }
2414 impl TryParse for CountedString16 {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>2415 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2416 let (length, remaining) = u16::try_parse(remaining)?;
2417 let (string, remaining) = crate::x11_utils::parse_u8_list(remaining, length.try_to_usize()?)?;
2418 let string = string.to_vec();
2419 let (alignment_pad, remaining) = crate::x11_utils::parse_u8_list(remaining, (u32::from(length).checked_add(5u32).ok_or(ParseError::InvalidExpression)? & (!3u32)).checked_sub(u32::from(length).checked_add(2u32).ok_or(ParseError::InvalidExpression)?).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?;
2420 let alignment_pad = alignment_pad.to_vec();
2421 let result = CountedString16 { string, alignment_pad };
2422 Ok((result, remaining))
2423 }
2424 }
2425 impl Serialize for CountedString16 {
2426 type Bytes = Vec<u8>;
serialize(&self) -> Vec<u8>2427 fn serialize(&self) -> Vec<u8> {
2428 let mut result = Vec::new();
2429 self.serialize_into(&mut result);
2430 result
2431 }
serialize_into(&self, bytes: &mut Vec<u8>)2432 fn serialize_into(&self, bytes: &mut Vec<u8>) {
2433 let length = u16::try_from(self.string.len()).expect("`string` has too many elements");
2434 length.serialize_into(bytes);
2435 bytes.extend_from_slice(&self.string);
2436 assert_eq!(self.alignment_pad.len(), usize::try_from((u32::from(length).checked_add(5u32).unwrap() & (!3u32)).checked_sub(u32::from(length).checked_add(2u32).unwrap()).unwrap()).unwrap(), "`alignment_pad` has an incorrect length");
2437 bytes.extend_from_slice(&self.alignment_pad);
2438 }
2439 }
2440 impl CountedString16 {
2441 /// Get the value of the `length` field.
2442 ///
2443 /// The `length` field is used as the length field of the `string` field.
2444 /// This function computes the field's value again based on the length of the list.
2445 ///
2446 /// # Panics
2447 ///
2448 /// Panics if the value cannot be represented in the target type. This
2449 /// cannot happen with values of the struct received from the X11 server.
length(&self) -> u162450 pub fn length(&self) -> u16 {
2451 self.string.len()
2452 .try_into().unwrap()
2453 }
2454 }
2455
2456 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2457 pub struct KTMapEntry {
2458 pub active: bool,
2459 pub mods_mask: u8,
2460 pub level: u8,
2461 pub mods_mods: u8,
2462 pub mods_vmods: u16,
2463 }
2464 impl TryParse for KTMapEntry {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>2465 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2466 let (active, remaining) = bool::try_parse(remaining)?;
2467 let (mods_mask, remaining) = u8::try_parse(remaining)?;
2468 let (level, remaining) = u8::try_parse(remaining)?;
2469 let (mods_mods, remaining) = u8::try_parse(remaining)?;
2470 let (mods_vmods, remaining) = u16::try_parse(remaining)?;
2471 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
2472 let result = KTMapEntry { active, mods_mask, level, mods_mods, mods_vmods };
2473 Ok((result, remaining))
2474 }
2475 }
2476 impl Serialize for KTMapEntry {
2477 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]2478 fn serialize(&self) -> [u8; 8] {
2479 let active_bytes = self.active.serialize();
2480 let mods_mask_bytes = self.mods_mask.serialize();
2481 let level_bytes = self.level.serialize();
2482 let mods_mods_bytes = self.mods_mods.serialize();
2483 let mods_vmods_bytes = self.mods_vmods.serialize();
2484 [
2485 active_bytes[0],
2486 mods_mask_bytes[0],
2487 level_bytes[0],
2488 mods_mods_bytes[0],
2489 mods_vmods_bytes[0],
2490 mods_vmods_bytes[1],
2491 0,
2492 0,
2493 ]
2494 }
serialize_into(&self, bytes: &mut Vec<u8>)2495 fn serialize_into(&self, bytes: &mut Vec<u8>) {
2496 bytes.reserve(8);
2497 self.active.serialize_into(bytes);
2498 self.mods_mask.serialize_into(bytes);
2499 self.level.serialize_into(bytes);
2500 self.mods_mods.serialize_into(bytes);
2501 self.mods_vmods.serialize_into(bytes);
2502 bytes.extend_from_slice(&[0; 2]);
2503 }
2504 }
2505
2506 #[derive(Debug, Clone, PartialEq, Eq)]
2507 pub struct KeyType {
2508 pub mods_mask: u8,
2509 pub mods_mods: u8,
2510 pub mods_vmods: u16,
2511 pub num_levels: u8,
2512 pub has_preserve: bool,
2513 pub map: Vec<KTMapEntry>,
2514 pub preserve: Vec<ModDef>,
2515 }
2516 impl TryParse for KeyType {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>2517 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2518 let (mods_mask, remaining) = u8::try_parse(remaining)?;
2519 let (mods_mods, remaining) = u8::try_parse(remaining)?;
2520 let (mods_vmods, remaining) = u16::try_parse(remaining)?;
2521 let (num_levels, remaining) = u8::try_parse(remaining)?;
2522 let (n_map_entries, remaining) = u8::try_parse(remaining)?;
2523 let (has_preserve, remaining) = bool::try_parse(remaining)?;
2524 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2525 let (map, remaining) = crate::x11_utils::parse_list::<KTMapEntry>(remaining, n_map_entries.try_to_usize()?)?;
2526 let (preserve, remaining) = crate::x11_utils::parse_list::<ModDef>(remaining, u32::from(has_preserve).checked_mul(u32::from(n_map_entries)).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?;
2527 let result = KeyType { mods_mask, mods_mods, mods_vmods, num_levels, has_preserve, map, preserve };
2528 Ok((result, remaining))
2529 }
2530 }
2531 impl Serialize for KeyType {
2532 type Bytes = Vec<u8>;
serialize(&self) -> Vec<u8>2533 fn serialize(&self) -> Vec<u8> {
2534 let mut result = Vec::new();
2535 self.serialize_into(&mut result);
2536 result
2537 }
serialize_into(&self, bytes: &mut Vec<u8>)2538 fn serialize_into(&self, bytes: &mut Vec<u8>) {
2539 bytes.reserve(8);
2540 self.mods_mask.serialize_into(bytes);
2541 self.mods_mods.serialize_into(bytes);
2542 self.mods_vmods.serialize_into(bytes);
2543 self.num_levels.serialize_into(bytes);
2544 let n_map_entries = u8::try_from(self.map.len()).expect("`map` has too many elements");
2545 n_map_entries.serialize_into(bytes);
2546 self.has_preserve.serialize_into(bytes);
2547 bytes.extend_from_slice(&[0; 1]);
2548 self.map.serialize_into(bytes);
2549 assert_eq!(self.preserve.len(), usize::try_from(u32::from(self.has_preserve).checked_mul(u32::from(n_map_entries)).unwrap()).unwrap(), "`preserve` has an incorrect length");
2550 self.preserve.serialize_into(bytes);
2551 }
2552 }
2553 impl KeyType {
2554 /// Get the value of the `nMapEntries` field.
2555 ///
2556 /// The `nMapEntries` field is used as the length field of the `map` field.
2557 /// This function computes the field's value again based on the length of the list.
2558 ///
2559 /// # Panics
2560 ///
2561 /// Panics if the value cannot be represented in the target type. This
2562 /// cannot happen with values of the struct received from the X11 server.
n_map_entries(&self) -> u82563 pub fn n_map_entries(&self) -> u8 {
2564 self.map.len()
2565 .try_into().unwrap()
2566 }
2567 }
2568
2569 #[derive(Debug, Clone, PartialEq, Eq)]
2570 pub struct KeySymMap {
2571 pub kt_index: [u8; 4],
2572 pub group_info: u8,
2573 pub width: u8,
2574 pub syms: Vec<xproto::Keysym>,
2575 }
2576 impl TryParse for KeySymMap {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>2577 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2578 let (kt_index, remaining) = crate::x11_utils::parse_u8_list(remaining, 4)?;
2579 let kt_index = <[u8; 4]>::try_from(kt_index).unwrap();
2580 let (group_info, remaining) = u8::try_parse(remaining)?;
2581 let (width, remaining) = u8::try_parse(remaining)?;
2582 let (n_syms, remaining) = u16::try_parse(remaining)?;
2583 let (syms, remaining) = crate::x11_utils::parse_list::<xproto::Keysym>(remaining, n_syms.try_to_usize()?)?;
2584 let result = KeySymMap { kt_index, group_info, width, syms };
2585 Ok((result, remaining))
2586 }
2587 }
2588 impl Serialize for KeySymMap {
2589 type Bytes = Vec<u8>;
serialize(&self) -> Vec<u8>2590 fn serialize(&self) -> Vec<u8> {
2591 let mut result = Vec::new();
2592 self.serialize_into(&mut result);
2593 result
2594 }
serialize_into(&self, bytes: &mut Vec<u8>)2595 fn serialize_into(&self, bytes: &mut Vec<u8>) {
2596 bytes.reserve(8);
2597 bytes.extend_from_slice(&self.kt_index);
2598 self.group_info.serialize_into(bytes);
2599 self.width.serialize_into(bytes);
2600 let n_syms = u16::try_from(self.syms.len()).expect("`syms` has too many elements");
2601 n_syms.serialize_into(bytes);
2602 self.syms.serialize_into(bytes);
2603 }
2604 }
2605 impl KeySymMap {
2606 /// Get the value of the `nSyms` field.
2607 ///
2608 /// The `nSyms` field is used as the length field of the `syms` field.
2609 /// This function computes the field's value again based on the length of the list.
2610 ///
2611 /// # Panics
2612 ///
2613 /// Panics if the value cannot be represented in the target type. This
2614 /// cannot happen with values of the struct received from the X11 server.
n_syms(&self) -> u162615 pub fn n_syms(&self) -> u16 {
2616 self.syms.len()
2617 .try_into().unwrap()
2618 }
2619 }
2620
2621 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2622 pub struct CommonBehavior {
2623 pub type_: u8,
2624 pub data: u8,
2625 }
2626 impl TryParse for CommonBehavior {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>2627 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2628 let (type_, remaining) = u8::try_parse(remaining)?;
2629 let (data, remaining) = u8::try_parse(remaining)?;
2630 let result = CommonBehavior { type_, data };
2631 Ok((result, remaining))
2632 }
2633 }
2634 impl Serialize for CommonBehavior {
2635 type Bytes = [u8; 2];
serialize(&self) -> [u8; 2]2636 fn serialize(&self) -> [u8; 2] {
2637 let type_bytes = self.type_.serialize();
2638 let data_bytes = self.data.serialize();
2639 [
2640 type_bytes[0],
2641 data_bytes[0],
2642 ]
2643 }
serialize_into(&self, bytes: &mut Vec<u8>)2644 fn serialize_into(&self, bytes: &mut Vec<u8>) {
2645 bytes.reserve(2);
2646 self.type_.serialize_into(bytes);
2647 self.data.serialize_into(bytes);
2648 }
2649 }
2650
2651 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2652 pub struct DefaultBehavior {
2653 pub type_: u8,
2654 }
2655 impl TryParse for DefaultBehavior {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>2656 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2657 let (type_, remaining) = u8::try_parse(remaining)?;
2658 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2659 let result = DefaultBehavior { type_ };
2660 Ok((result, remaining))
2661 }
2662 }
2663 impl Serialize for DefaultBehavior {
2664 type Bytes = [u8; 2];
serialize(&self) -> [u8; 2]2665 fn serialize(&self) -> [u8; 2] {
2666 let type_bytes = self.type_.serialize();
2667 [
2668 type_bytes[0],
2669 0,
2670 ]
2671 }
serialize_into(&self, bytes: &mut Vec<u8>)2672 fn serialize_into(&self, bytes: &mut Vec<u8>) {
2673 bytes.reserve(2);
2674 self.type_.serialize_into(bytes);
2675 bytes.extend_from_slice(&[0; 1]);
2676 }
2677 }
2678
2679 pub type LockBehavior = DefaultBehavior;
2680
2681 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2682 pub struct RadioGroupBehavior {
2683 pub type_: u8,
2684 pub group: u8,
2685 }
2686 impl TryParse for RadioGroupBehavior {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>2687 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2688 let (type_, remaining) = u8::try_parse(remaining)?;
2689 let (group, remaining) = u8::try_parse(remaining)?;
2690 let result = RadioGroupBehavior { type_, group };
2691 Ok((result, remaining))
2692 }
2693 }
2694 impl Serialize for RadioGroupBehavior {
2695 type Bytes = [u8; 2];
serialize(&self) -> [u8; 2]2696 fn serialize(&self) -> [u8; 2] {
2697 let type_bytes = self.type_.serialize();
2698 let group_bytes = self.group.serialize();
2699 [
2700 type_bytes[0],
2701 group_bytes[0],
2702 ]
2703 }
serialize_into(&self, bytes: &mut Vec<u8>)2704 fn serialize_into(&self, bytes: &mut Vec<u8>) {
2705 bytes.reserve(2);
2706 self.type_.serialize_into(bytes);
2707 self.group.serialize_into(bytes);
2708 }
2709 }
2710
2711 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2712 pub struct OverlayBehavior {
2713 pub type_: u8,
2714 pub key: xproto::Keycode,
2715 }
2716 impl TryParse for OverlayBehavior {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>2717 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2718 let (type_, remaining) = u8::try_parse(remaining)?;
2719 let (key, remaining) = xproto::Keycode::try_parse(remaining)?;
2720 let result = OverlayBehavior { type_, key };
2721 Ok((result, remaining))
2722 }
2723 }
2724 impl Serialize for OverlayBehavior {
2725 type Bytes = [u8; 2];
serialize(&self) -> [u8; 2]2726 fn serialize(&self) -> [u8; 2] {
2727 let type_bytes = self.type_.serialize();
2728 let key_bytes = self.key.serialize();
2729 [
2730 type_bytes[0],
2731 key_bytes[0],
2732 ]
2733 }
serialize_into(&self, bytes: &mut Vec<u8>)2734 fn serialize_into(&self, bytes: &mut Vec<u8>) {
2735 bytes.reserve(2);
2736 self.type_.serialize_into(bytes);
2737 self.key.serialize_into(bytes);
2738 }
2739 }
2740
2741 pub type PermamentLockBehavior = LockBehavior;
2742
2743 pub type PermamentRadioGroupBehavior = RadioGroupBehavior;
2744
2745 pub type PermamentOverlayBehavior = OverlayBehavior;
2746
2747 #[derive(Debug, Copy, Clone)]
2748 pub struct Behavior([u8; 2]);
2749 impl Behavior {
as_common(&self) -> CommonBehavior2750 pub fn as_common(&self) -> CommonBehavior {
2751 fn do_the_parse(remaining: &[u8]) -> Result<CommonBehavior, ParseError> {
2752 let (common, remaining) = CommonBehavior::try_parse(remaining)?;
2753 let _ = remaining;
2754 Ok(common)
2755 }
2756 do_the_parse(&self.0).unwrap()
2757 }
as_default(&self) -> DefaultBehavior2758 pub fn as_default(&self) -> DefaultBehavior {
2759 fn do_the_parse(remaining: &[u8]) -> Result<DefaultBehavior, ParseError> {
2760 let (default, remaining) = DefaultBehavior::try_parse(remaining)?;
2761 let _ = remaining;
2762 Ok(default)
2763 }
2764 do_the_parse(&self.0).unwrap()
2765 }
as_lock(&self) -> LockBehavior2766 pub fn as_lock(&self) -> LockBehavior {
2767 fn do_the_parse(remaining: &[u8]) -> Result<LockBehavior, ParseError> {
2768 let (lock, remaining) = LockBehavior::try_parse(remaining)?;
2769 let _ = remaining;
2770 Ok(lock)
2771 }
2772 do_the_parse(&self.0).unwrap()
2773 }
as_radio_group(&self) -> RadioGroupBehavior2774 pub fn as_radio_group(&self) -> RadioGroupBehavior {
2775 fn do_the_parse(remaining: &[u8]) -> Result<RadioGroupBehavior, ParseError> {
2776 let (radio_group, remaining) = RadioGroupBehavior::try_parse(remaining)?;
2777 let _ = remaining;
2778 Ok(radio_group)
2779 }
2780 do_the_parse(&self.0).unwrap()
2781 }
as_overlay1(&self) -> OverlayBehavior2782 pub fn as_overlay1(&self) -> OverlayBehavior {
2783 fn do_the_parse(remaining: &[u8]) -> Result<OverlayBehavior, ParseError> {
2784 let (overlay1, remaining) = OverlayBehavior::try_parse(remaining)?;
2785 let _ = remaining;
2786 Ok(overlay1)
2787 }
2788 do_the_parse(&self.0).unwrap()
2789 }
as_overlay2(&self) -> OverlayBehavior2790 pub fn as_overlay2(&self) -> OverlayBehavior {
2791 fn do_the_parse(remaining: &[u8]) -> Result<OverlayBehavior, ParseError> {
2792 let (overlay2, remaining) = OverlayBehavior::try_parse(remaining)?;
2793 let _ = remaining;
2794 Ok(overlay2)
2795 }
2796 do_the_parse(&self.0).unwrap()
2797 }
as_permament_lock(&self) -> PermamentLockBehavior2798 pub fn as_permament_lock(&self) -> PermamentLockBehavior {
2799 fn do_the_parse(remaining: &[u8]) -> Result<PermamentLockBehavior, ParseError> {
2800 let (permament_lock, remaining) = PermamentLockBehavior::try_parse(remaining)?;
2801 let _ = remaining;
2802 Ok(permament_lock)
2803 }
2804 do_the_parse(&self.0).unwrap()
2805 }
as_permament_radio_group(&self) -> PermamentRadioGroupBehavior2806 pub fn as_permament_radio_group(&self) -> PermamentRadioGroupBehavior {
2807 fn do_the_parse(remaining: &[u8]) -> Result<PermamentRadioGroupBehavior, ParseError> {
2808 let (permament_radio_group, remaining) = PermamentRadioGroupBehavior::try_parse(remaining)?;
2809 let _ = remaining;
2810 Ok(permament_radio_group)
2811 }
2812 do_the_parse(&self.0).unwrap()
2813 }
as_permament_overlay1(&self) -> PermamentOverlayBehavior2814 pub fn as_permament_overlay1(&self) -> PermamentOverlayBehavior {
2815 fn do_the_parse(remaining: &[u8]) -> Result<PermamentOverlayBehavior, ParseError> {
2816 let (permament_overlay1, remaining) = PermamentOverlayBehavior::try_parse(remaining)?;
2817 let _ = remaining;
2818 Ok(permament_overlay1)
2819 }
2820 do_the_parse(&self.0).unwrap()
2821 }
as_permament_overlay2(&self) -> PermamentOverlayBehavior2822 pub fn as_permament_overlay2(&self) -> PermamentOverlayBehavior {
2823 fn do_the_parse(remaining: &[u8]) -> Result<PermamentOverlayBehavior, ParseError> {
2824 let (permament_overlay2, remaining) = PermamentOverlayBehavior::try_parse(remaining)?;
2825 let _ = remaining;
2826 Ok(permament_overlay2)
2827 }
2828 do_the_parse(&self.0).unwrap()
2829 }
as_type(&self) -> u82830 pub fn as_type(&self) -> u8 {
2831 fn do_the_parse(remaining: &[u8]) -> Result<u8, ParseError> {
2832 let (type_, remaining) = u8::try_parse(remaining)?;
2833 let _ = remaining;
2834 Ok(type_)
2835 }
2836 do_the_parse(&self.0).unwrap()
2837 }
2838 }
2839 impl Serialize for Behavior {
2840 type Bytes = [u8; 2];
serialize(&self) -> [u8; 2]2841 fn serialize(&self) -> [u8; 2] {
2842 self.0
2843 }
serialize_into(&self, bytes: &mut Vec<u8>)2844 fn serialize_into(&self, bytes: &mut Vec<u8>) {
2845 bytes.extend_from_slice(&self.0);
2846 }
2847 }
2848 impl TryParse for Behavior {
try_parse(value: &[u8]) -> Result<(Self, &[u8]), ParseError>2849 fn try_parse(value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2850 let inner: [u8; 2] = value.get(..2)
2851 .ok_or(ParseError::InsufficientData)?
2852 .try_into()
2853 .unwrap();
2854 let result = Behavior(inner);
2855 Ok((result, &value[2..]))
2856 }
2857 }
2858 impl From<CommonBehavior> for Behavior {
from(common: CommonBehavior) -> Self2859 fn from(common: CommonBehavior) -> Self {
2860 let common_bytes = common.serialize();
2861 Self(common_bytes)
2862 }
2863 }
2864 impl From<DefaultBehavior> for Behavior {
from(default: DefaultBehavior) -> Self2865 fn from(default: DefaultBehavior) -> Self {
2866 let default_bytes = default.serialize();
2867 Self(default_bytes)
2868 }
2869 }
2870 impl From<RadioGroupBehavior> for Behavior {
from(radio_group: RadioGroupBehavior) -> Self2871 fn from(radio_group: RadioGroupBehavior) -> Self {
2872 let radio_group_bytes = radio_group.serialize();
2873 Self(radio_group_bytes)
2874 }
2875 }
2876 impl From<OverlayBehavior> for Behavior {
from(overlay1: OverlayBehavior) -> Self2877 fn from(overlay1: OverlayBehavior) -> Self {
2878 let overlay1_bytes = overlay1.serialize();
2879 Self(overlay1_bytes)
2880 }
2881 }
2882 impl From<u8> for Behavior {
from(type_: u8) -> Self2883 fn from(type_: u8) -> Self {
2884 let type_bytes = type_.serialize();
2885 let value = [
2886 type_bytes[0],
2887 0,
2888 ];
2889 Self(value)
2890 }
2891 }
2892
2893 #[derive(Clone, Copy, PartialEq, Eq)]
2894 pub struct BehaviorType(u8);
2895 impl BehaviorType {
2896 pub const DEFAULT: Self = Self(0);
2897 pub const LOCK: Self = Self(1);
2898 pub const RADIO_GROUP: Self = Self(2);
2899 pub const OVERLAY1: Self = Self(3);
2900 pub const OVERLAY2: Self = Self(4);
2901 pub const PERMAMENT_LOCK: Self = Self(129);
2902 pub const PERMAMENT_RADIO_GROUP: Self = Self(130);
2903 pub const PERMAMENT_OVERLAY1: Self = Self(131);
2904 pub const PERMAMENT_OVERLAY2: Self = Self(132);
2905 }
2906 impl From<BehaviorType> for u8 {
2907 #[inline]
from(input: BehaviorType) -> Self2908 fn from(input: BehaviorType) -> Self {
2909 input.0
2910 }
2911 }
2912 impl From<BehaviorType> for Option<u8> {
2913 #[inline]
from(input: BehaviorType) -> Self2914 fn from(input: BehaviorType) -> Self {
2915 Some(input.0)
2916 }
2917 }
2918 impl From<BehaviorType> for u16 {
2919 #[inline]
from(input: BehaviorType) -> Self2920 fn from(input: BehaviorType) -> Self {
2921 u16::from(input.0)
2922 }
2923 }
2924 impl From<BehaviorType> for Option<u16> {
2925 #[inline]
from(input: BehaviorType) -> Self2926 fn from(input: BehaviorType) -> Self {
2927 Some(u16::from(input.0))
2928 }
2929 }
2930 impl From<BehaviorType> for u32 {
2931 #[inline]
from(input: BehaviorType) -> Self2932 fn from(input: BehaviorType) -> Self {
2933 u32::from(input.0)
2934 }
2935 }
2936 impl From<BehaviorType> for Option<u32> {
2937 #[inline]
from(input: BehaviorType) -> Self2938 fn from(input: BehaviorType) -> Self {
2939 Some(u32::from(input.0))
2940 }
2941 }
2942 impl From<u8> for BehaviorType {
2943 #[inline]
from(value: u8) -> Self2944 fn from(value: u8) -> Self {
2945 Self(value)
2946 }
2947 }
2948 impl std::fmt::Debug for BehaviorType {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result2949 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2950 let variants = [
2951 (Self::DEFAULT.0.into(), "DEFAULT", "Default"),
2952 (Self::LOCK.0.into(), "LOCK", "Lock"),
2953 (Self::RADIO_GROUP.0.into(), "RADIO_GROUP", "RadioGroup"),
2954 (Self::OVERLAY1.0.into(), "OVERLAY1", "Overlay1"),
2955 (Self::OVERLAY2.0.into(), "OVERLAY2", "Overlay2"),
2956 (Self::PERMAMENT_LOCK.0.into(), "PERMAMENT_LOCK", "PermamentLock"),
2957 (Self::PERMAMENT_RADIO_GROUP.0.into(), "PERMAMENT_RADIO_GROUP", "PermamentRadioGroup"),
2958 (Self::PERMAMENT_OVERLAY1.0.into(), "PERMAMENT_OVERLAY1", "PermamentOverlay1"),
2959 (Self::PERMAMENT_OVERLAY2.0.into(), "PERMAMENT_OVERLAY2", "PermamentOverlay2"),
2960 ];
2961 pretty_print_enum(fmt, self.0.into(), &variants)
2962 }
2963 }
2964
2965 #[derive(Debug, Clone, Copy)]
2966 pub struct SetBehavior {
2967 pub keycode: xproto::Keycode,
2968 pub behavior: Behavior,
2969 }
2970 impl TryParse for SetBehavior {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>2971 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2972 let (keycode, remaining) = xproto::Keycode::try_parse(remaining)?;
2973 let (behavior, remaining) = Behavior::try_parse(remaining)?;
2974 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2975 let result = SetBehavior { keycode, behavior };
2976 Ok((result, remaining))
2977 }
2978 }
2979 impl Serialize for SetBehavior {
2980 type Bytes = [u8; 4];
serialize(&self) -> [u8; 4]2981 fn serialize(&self) -> [u8; 4] {
2982 let keycode_bytes = self.keycode.serialize();
2983 let behavior_bytes = self.behavior.serialize();
2984 [
2985 keycode_bytes[0],
2986 behavior_bytes[0],
2987 behavior_bytes[1],
2988 0,
2989 ]
2990 }
serialize_into(&self, bytes: &mut Vec<u8>)2991 fn serialize_into(&self, bytes: &mut Vec<u8>) {
2992 bytes.reserve(4);
2993 self.keycode.serialize_into(bytes);
2994 self.behavior.serialize_into(bytes);
2995 bytes.extend_from_slice(&[0; 1]);
2996 }
2997 }
2998
2999 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
3000 pub struct SetExplicit {
3001 pub keycode: xproto::Keycode,
3002 pub explicit: u8,
3003 }
3004 impl TryParse for SetExplicit {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>3005 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3006 let (keycode, remaining) = xproto::Keycode::try_parse(remaining)?;
3007 let (explicit, remaining) = u8::try_parse(remaining)?;
3008 let result = SetExplicit { keycode, explicit };
3009 Ok((result, remaining))
3010 }
3011 }
3012 impl Serialize for SetExplicit {
3013 type Bytes = [u8; 2];
serialize(&self) -> [u8; 2]3014 fn serialize(&self) -> [u8; 2] {
3015 let keycode_bytes = self.keycode.serialize();
3016 let explicit_bytes = self.explicit.serialize();
3017 [
3018 keycode_bytes[0],
3019 explicit_bytes[0],
3020 ]
3021 }
serialize_into(&self, bytes: &mut Vec<u8>)3022 fn serialize_into(&self, bytes: &mut Vec<u8>) {
3023 bytes.reserve(2);
3024 self.keycode.serialize_into(bytes);
3025 self.explicit.serialize_into(bytes);
3026 }
3027 }
3028
3029 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
3030 pub struct KeyModMap {
3031 pub keycode: xproto::Keycode,
3032 pub mods: u8,
3033 }
3034 impl TryParse for KeyModMap {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>3035 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3036 let (keycode, remaining) = xproto::Keycode::try_parse(remaining)?;
3037 let (mods, remaining) = u8::try_parse(remaining)?;
3038 let result = KeyModMap { keycode, mods };
3039 Ok((result, remaining))
3040 }
3041 }
3042 impl Serialize for KeyModMap {
3043 type Bytes = [u8; 2];
serialize(&self) -> [u8; 2]3044 fn serialize(&self) -> [u8; 2] {
3045 let keycode_bytes = self.keycode.serialize();
3046 let mods_bytes = self.mods.serialize();
3047 [
3048 keycode_bytes[0],
3049 mods_bytes[0],
3050 ]
3051 }
serialize_into(&self, bytes: &mut Vec<u8>)3052 fn serialize_into(&self, bytes: &mut Vec<u8>) {
3053 bytes.reserve(2);
3054 self.keycode.serialize_into(bytes);
3055 self.mods.serialize_into(bytes);
3056 }
3057 }
3058
3059 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
3060 pub struct KeyVModMap {
3061 pub keycode: xproto::Keycode,
3062 pub vmods: u16,
3063 }
3064 impl TryParse for KeyVModMap {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>3065 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3066 let (keycode, remaining) = xproto::Keycode::try_parse(remaining)?;
3067 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
3068 let (vmods, remaining) = u16::try_parse(remaining)?;
3069 let result = KeyVModMap { keycode, vmods };
3070 Ok((result, remaining))
3071 }
3072 }
3073 impl Serialize for KeyVModMap {
3074 type Bytes = [u8; 4];
serialize(&self) -> [u8; 4]3075 fn serialize(&self) -> [u8; 4] {
3076 let keycode_bytes = self.keycode.serialize();
3077 let vmods_bytes = self.vmods.serialize();
3078 [
3079 keycode_bytes[0],
3080 0,
3081 vmods_bytes[0],
3082 vmods_bytes[1],
3083 ]
3084 }
serialize_into(&self, bytes: &mut Vec<u8>)3085 fn serialize_into(&self, bytes: &mut Vec<u8>) {
3086 bytes.reserve(4);
3087 self.keycode.serialize_into(bytes);
3088 bytes.extend_from_slice(&[0; 1]);
3089 self.vmods.serialize_into(bytes);
3090 }
3091 }
3092
3093 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
3094 pub struct KTSetMapEntry {
3095 pub level: u8,
3096 pub real_mods: u8,
3097 pub virtual_mods: u16,
3098 }
3099 impl TryParse for KTSetMapEntry {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>3100 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3101 let (level, remaining) = u8::try_parse(remaining)?;
3102 let (real_mods, remaining) = u8::try_parse(remaining)?;
3103 let (virtual_mods, remaining) = u16::try_parse(remaining)?;
3104 let result = KTSetMapEntry { level, real_mods, virtual_mods };
3105 Ok((result, remaining))
3106 }
3107 }
3108 impl Serialize for KTSetMapEntry {
3109 type Bytes = [u8; 4];
serialize(&self) -> [u8; 4]3110 fn serialize(&self) -> [u8; 4] {
3111 let level_bytes = self.level.serialize();
3112 let real_mods_bytes = self.real_mods.serialize();
3113 let virtual_mods_bytes = self.virtual_mods.serialize();
3114 [
3115 level_bytes[0],
3116 real_mods_bytes[0],
3117 virtual_mods_bytes[0],
3118 virtual_mods_bytes[1],
3119 ]
3120 }
serialize_into(&self, bytes: &mut Vec<u8>)3121 fn serialize_into(&self, bytes: &mut Vec<u8>) {
3122 bytes.reserve(4);
3123 self.level.serialize_into(bytes);
3124 self.real_mods.serialize_into(bytes);
3125 self.virtual_mods.serialize_into(bytes);
3126 }
3127 }
3128
3129 #[derive(Debug, Clone, PartialEq, Eq)]
3130 pub struct SetKeyType {
3131 pub mask: u8,
3132 pub real_mods: u8,
3133 pub virtual_mods: u16,
3134 pub num_levels: u8,
3135 pub preserve: bool,
3136 pub entries: Vec<KTSetMapEntry>,
3137 pub preserve_entries: Vec<KTSetMapEntry>,
3138 }
3139 impl TryParse for SetKeyType {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>3140 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3141 let (mask, remaining) = u8::try_parse(remaining)?;
3142 let (real_mods, remaining) = u8::try_parse(remaining)?;
3143 let (virtual_mods, remaining) = u16::try_parse(remaining)?;
3144 let (num_levels, remaining) = u8::try_parse(remaining)?;
3145 let (n_map_entries, remaining) = u8::try_parse(remaining)?;
3146 let (preserve, remaining) = bool::try_parse(remaining)?;
3147 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
3148 let (entries, remaining) = crate::x11_utils::parse_list::<KTSetMapEntry>(remaining, n_map_entries.try_to_usize()?)?;
3149 let (preserve_entries, remaining) = crate::x11_utils::parse_list::<KTSetMapEntry>(remaining, u32::from(preserve).checked_mul(u32::from(n_map_entries)).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?;
3150 let result = SetKeyType { mask, real_mods, virtual_mods, num_levels, preserve, entries, preserve_entries };
3151 Ok((result, remaining))
3152 }
3153 }
3154 impl Serialize for SetKeyType {
3155 type Bytes = Vec<u8>;
serialize(&self) -> Vec<u8>3156 fn serialize(&self) -> Vec<u8> {
3157 let mut result = Vec::new();
3158 self.serialize_into(&mut result);
3159 result
3160 }
serialize_into(&self, bytes: &mut Vec<u8>)3161 fn serialize_into(&self, bytes: &mut Vec<u8>) {
3162 bytes.reserve(8);
3163 self.mask.serialize_into(bytes);
3164 self.real_mods.serialize_into(bytes);
3165 self.virtual_mods.serialize_into(bytes);
3166 self.num_levels.serialize_into(bytes);
3167 let n_map_entries = u8::try_from(self.entries.len()).expect("`entries` has too many elements");
3168 n_map_entries.serialize_into(bytes);
3169 self.preserve.serialize_into(bytes);
3170 bytes.extend_from_slice(&[0; 1]);
3171 self.entries.serialize_into(bytes);
3172 assert_eq!(self.preserve_entries.len(), usize::try_from(u32::from(self.preserve).checked_mul(u32::from(n_map_entries)).unwrap()).unwrap(), "`preserve_entries` has an incorrect length");
3173 self.preserve_entries.serialize_into(bytes);
3174 }
3175 }
3176 impl SetKeyType {
3177 /// Get the value of the `nMapEntries` field.
3178 ///
3179 /// The `nMapEntries` field is used as the length field of the `entries` field.
3180 /// This function computes the field's value again based on the length of the list.
3181 ///
3182 /// # Panics
3183 ///
3184 /// Panics if the value cannot be represented in the target type. This
3185 /// cannot happen with values of the struct received from the X11 server.
n_map_entries(&self) -> u83186 pub fn n_map_entries(&self) -> u8 {
3187 self.entries.len()
3188 .try_into().unwrap()
3189 }
3190 }
3191
3192 pub type String8 = u8;
3193
3194 #[derive(Debug, Clone, PartialEq, Eq)]
3195 pub struct Outline {
3196 pub corner_radius: u8,
3197 pub points: Vec<xproto::Point>,
3198 }
3199 impl TryParse for Outline {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>3200 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3201 let (n_points, remaining) = u8::try_parse(remaining)?;
3202 let (corner_radius, remaining) = u8::try_parse(remaining)?;
3203 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
3204 let (points, remaining) = crate::x11_utils::parse_list::<xproto::Point>(remaining, n_points.try_to_usize()?)?;
3205 let result = Outline { corner_radius, points };
3206 Ok((result, remaining))
3207 }
3208 }
3209 impl Serialize for Outline {
3210 type Bytes = Vec<u8>;
serialize(&self) -> Vec<u8>3211 fn serialize(&self) -> Vec<u8> {
3212 let mut result = Vec::new();
3213 self.serialize_into(&mut result);
3214 result
3215 }
serialize_into(&self, bytes: &mut Vec<u8>)3216 fn serialize_into(&self, bytes: &mut Vec<u8>) {
3217 bytes.reserve(4);
3218 let n_points = u8::try_from(self.points.len()).expect("`points` has too many elements");
3219 n_points.serialize_into(bytes);
3220 self.corner_radius.serialize_into(bytes);
3221 bytes.extend_from_slice(&[0; 2]);
3222 self.points.serialize_into(bytes);
3223 }
3224 }
3225 impl Outline {
3226 /// Get the value of the `nPoints` field.
3227 ///
3228 /// The `nPoints` field is used as the length field of the `points` field.
3229 /// This function computes the field's value again based on the length of the list.
3230 ///
3231 /// # Panics
3232 ///
3233 /// Panics if the value cannot be represented in the target type. This
3234 /// cannot happen with values of the struct received from the X11 server.
n_points(&self) -> u83235 pub fn n_points(&self) -> u8 {
3236 self.points.len()
3237 .try_into().unwrap()
3238 }
3239 }
3240
3241 #[derive(Debug, Clone, PartialEq, Eq)]
3242 pub struct Shape {
3243 pub name: xproto::Atom,
3244 pub primary_ndx: u8,
3245 pub approx_ndx: u8,
3246 pub outlines: Vec<Outline>,
3247 }
3248 impl TryParse for Shape {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>3249 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3250 let (name, remaining) = xproto::Atom::try_parse(remaining)?;
3251 let (n_outlines, remaining) = u8::try_parse(remaining)?;
3252 let (primary_ndx, remaining) = u8::try_parse(remaining)?;
3253 let (approx_ndx, remaining) = u8::try_parse(remaining)?;
3254 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
3255 let (outlines, remaining) = crate::x11_utils::parse_list::<Outline>(remaining, n_outlines.try_to_usize()?)?;
3256 let result = Shape { name, primary_ndx, approx_ndx, outlines };
3257 Ok((result, remaining))
3258 }
3259 }
3260 impl Serialize for Shape {
3261 type Bytes = Vec<u8>;
serialize(&self) -> Vec<u8>3262 fn serialize(&self) -> Vec<u8> {
3263 let mut result = Vec::new();
3264 self.serialize_into(&mut result);
3265 result
3266 }
serialize_into(&self, bytes: &mut Vec<u8>)3267 fn serialize_into(&self, bytes: &mut Vec<u8>) {
3268 bytes.reserve(8);
3269 self.name.serialize_into(bytes);
3270 let n_outlines = u8::try_from(self.outlines.len()).expect("`outlines` has too many elements");
3271 n_outlines.serialize_into(bytes);
3272 self.primary_ndx.serialize_into(bytes);
3273 self.approx_ndx.serialize_into(bytes);
3274 bytes.extend_from_slice(&[0; 1]);
3275 self.outlines.serialize_into(bytes);
3276 }
3277 }
3278 impl Shape {
3279 /// Get the value of the `nOutlines` field.
3280 ///
3281 /// The `nOutlines` field is used as the length field of the `outlines` field.
3282 /// This function computes the field's value again based on the length of the list.
3283 ///
3284 /// # Panics
3285 ///
3286 /// Panics if the value cannot be represented in the target type. This
3287 /// cannot happen with values of the struct received from the X11 server.
n_outlines(&self) -> u83288 pub fn n_outlines(&self) -> u8 {
3289 self.outlines.len()
3290 .try_into().unwrap()
3291 }
3292 }
3293
3294 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
3295 pub struct Key {
3296 pub name: [String8; 4],
3297 pub gap: i16,
3298 pub shape_ndx: u8,
3299 pub color_ndx: u8,
3300 }
3301 impl TryParse for Key {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>3302 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3303 let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, 4)?;
3304 let name = <[u8; 4]>::try_from(name).unwrap();
3305 let (gap, remaining) = i16::try_parse(remaining)?;
3306 let (shape_ndx, remaining) = u8::try_parse(remaining)?;
3307 let (color_ndx, remaining) = u8::try_parse(remaining)?;
3308 let result = Key { name, gap, shape_ndx, color_ndx };
3309 Ok((result, remaining))
3310 }
3311 }
3312 impl Serialize for Key {
3313 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]3314 fn serialize(&self) -> [u8; 8] {
3315 let gap_bytes = self.gap.serialize();
3316 let shape_ndx_bytes = self.shape_ndx.serialize();
3317 let color_ndx_bytes = self.color_ndx.serialize();
3318 [
3319 self.name[0],
3320 self.name[1],
3321 self.name[2],
3322 self.name[3],
3323 gap_bytes[0],
3324 gap_bytes[1],
3325 shape_ndx_bytes[0],
3326 color_ndx_bytes[0],
3327 ]
3328 }
serialize_into(&self, bytes: &mut Vec<u8>)3329 fn serialize_into(&self, bytes: &mut Vec<u8>) {
3330 bytes.reserve(8);
3331 bytes.extend_from_slice(&self.name);
3332 self.gap.serialize_into(bytes);
3333 self.shape_ndx.serialize_into(bytes);
3334 self.color_ndx.serialize_into(bytes);
3335 }
3336 }
3337
3338 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
3339 pub struct OverlayKey {
3340 pub over: [String8; 4],
3341 pub under: [String8; 4],
3342 }
3343 impl TryParse for OverlayKey {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>3344 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3345 let (over, remaining) = crate::x11_utils::parse_u8_list(remaining, 4)?;
3346 let over = <[u8; 4]>::try_from(over).unwrap();
3347 let (under, remaining) = crate::x11_utils::parse_u8_list(remaining, 4)?;
3348 let under = <[u8; 4]>::try_from(under).unwrap();
3349 let result = OverlayKey { over, under };
3350 Ok((result, remaining))
3351 }
3352 }
3353 impl Serialize for OverlayKey {
3354 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]3355 fn serialize(&self) -> [u8; 8] {
3356 [
3357 self.over[0],
3358 self.over[1],
3359 self.over[2],
3360 self.over[3],
3361 self.under[0],
3362 self.under[1],
3363 self.under[2],
3364 self.under[3],
3365 ]
3366 }
serialize_into(&self, bytes: &mut Vec<u8>)3367 fn serialize_into(&self, bytes: &mut Vec<u8>) {
3368 bytes.reserve(8);
3369 bytes.extend_from_slice(&self.over);
3370 bytes.extend_from_slice(&self.under);
3371 }
3372 }
3373
3374 #[derive(Debug, Clone, PartialEq, Eq)]
3375 pub struct OverlayRow {
3376 pub row_under: u8,
3377 pub keys: Vec<OverlayKey>,
3378 }
3379 impl TryParse for OverlayRow {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>3380 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3381 let (row_under, remaining) = u8::try_parse(remaining)?;
3382 let (n_keys, remaining) = u8::try_parse(remaining)?;
3383 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
3384 let (keys, remaining) = crate::x11_utils::parse_list::<OverlayKey>(remaining, n_keys.try_to_usize()?)?;
3385 let result = OverlayRow { row_under, keys };
3386 Ok((result, remaining))
3387 }
3388 }
3389 impl Serialize for OverlayRow {
3390 type Bytes = Vec<u8>;
serialize(&self) -> Vec<u8>3391 fn serialize(&self) -> Vec<u8> {
3392 let mut result = Vec::new();
3393 self.serialize_into(&mut result);
3394 result
3395 }
serialize_into(&self, bytes: &mut Vec<u8>)3396 fn serialize_into(&self, bytes: &mut Vec<u8>) {
3397 bytes.reserve(4);
3398 self.row_under.serialize_into(bytes);
3399 let n_keys = u8::try_from(self.keys.len()).expect("`keys` has too many elements");
3400 n_keys.serialize_into(bytes);
3401 bytes.extend_from_slice(&[0; 2]);
3402 self.keys.serialize_into(bytes);
3403 }
3404 }
3405 impl OverlayRow {
3406 /// Get the value of the `nKeys` field.
3407 ///
3408 /// The `nKeys` field is used as the length field of the `keys` field.
3409 /// This function computes the field's value again based on the length of the list.
3410 ///
3411 /// # Panics
3412 ///
3413 /// Panics if the value cannot be represented in the target type. This
3414 /// cannot happen with values of the struct received from the X11 server.
n_keys(&self) -> u83415 pub fn n_keys(&self) -> u8 {
3416 self.keys.len()
3417 .try_into().unwrap()
3418 }
3419 }
3420
3421 #[derive(Debug, Clone, PartialEq, Eq)]
3422 pub struct Overlay {
3423 pub name: xproto::Atom,
3424 pub rows: Vec<OverlayRow>,
3425 }
3426 impl TryParse for Overlay {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>3427 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3428 let (name, remaining) = xproto::Atom::try_parse(remaining)?;
3429 let (n_rows, remaining) = u8::try_parse(remaining)?;
3430 let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?;
3431 let (rows, remaining) = crate::x11_utils::parse_list::<OverlayRow>(remaining, n_rows.try_to_usize()?)?;
3432 let result = Overlay { name, rows };
3433 Ok((result, remaining))
3434 }
3435 }
3436 impl Serialize for Overlay {
3437 type Bytes = Vec<u8>;
serialize(&self) -> Vec<u8>3438 fn serialize(&self) -> Vec<u8> {
3439 let mut result = Vec::new();
3440 self.serialize_into(&mut result);
3441 result
3442 }
serialize_into(&self, bytes: &mut Vec<u8>)3443 fn serialize_into(&self, bytes: &mut Vec<u8>) {
3444 bytes.reserve(8);
3445 self.name.serialize_into(bytes);
3446 let n_rows = u8::try_from(self.rows.len()).expect("`rows` has too many elements");
3447 n_rows.serialize_into(bytes);
3448 bytes.extend_from_slice(&[0; 3]);
3449 self.rows.serialize_into(bytes);
3450 }
3451 }
3452 impl Overlay {
3453 /// Get the value of the `nRows` field.
3454 ///
3455 /// The `nRows` field is used as the length field of the `rows` field.
3456 /// This function computes the field's value again based on the length of the list.
3457 ///
3458 /// # Panics
3459 ///
3460 /// Panics if the value cannot be represented in the target type. This
3461 /// cannot happen with values of the struct received from the X11 server.
n_rows(&self) -> u83462 pub fn n_rows(&self) -> u8 {
3463 self.rows.len()
3464 .try_into().unwrap()
3465 }
3466 }
3467
3468 #[derive(Debug, Clone, PartialEq, Eq)]
3469 pub struct Row {
3470 pub top: i16,
3471 pub left: i16,
3472 pub vertical: bool,
3473 pub keys: Vec<Key>,
3474 }
3475 impl TryParse for Row {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>3476 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3477 let (top, remaining) = i16::try_parse(remaining)?;
3478 let (left, remaining) = i16::try_parse(remaining)?;
3479 let (n_keys, remaining) = u8::try_parse(remaining)?;
3480 let (vertical, remaining) = bool::try_parse(remaining)?;
3481 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
3482 let (keys, remaining) = crate::x11_utils::parse_list::<Key>(remaining, n_keys.try_to_usize()?)?;
3483 let result = Row { top, left, vertical, keys };
3484 Ok((result, remaining))
3485 }
3486 }
3487 impl Serialize for Row {
3488 type Bytes = Vec<u8>;
serialize(&self) -> Vec<u8>3489 fn serialize(&self) -> Vec<u8> {
3490 let mut result = Vec::new();
3491 self.serialize_into(&mut result);
3492 result
3493 }
serialize_into(&self, bytes: &mut Vec<u8>)3494 fn serialize_into(&self, bytes: &mut Vec<u8>) {
3495 bytes.reserve(8);
3496 self.top.serialize_into(bytes);
3497 self.left.serialize_into(bytes);
3498 let n_keys = u8::try_from(self.keys.len()).expect("`keys` has too many elements");
3499 n_keys.serialize_into(bytes);
3500 self.vertical.serialize_into(bytes);
3501 bytes.extend_from_slice(&[0; 2]);
3502 self.keys.serialize_into(bytes);
3503 }
3504 }
3505 impl Row {
3506 /// Get the value of the `nKeys` field.
3507 ///
3508 /// The `nKeys` field is used as the length field of the `keys` field.
3509 /// This function computes the field's value again based on the length of the list.
3510 ///
3511 /// # Panics
3512 ///
3513 /// Panics if the value cannot be represented in the target type. This
3514 /// cannot happen with values of the struct received from the X11 server.
n_keys(&self) -> u83515 pub fn n_keys(&self) -> u8 {
3516 self.keys.len()
3517 .try_into().unwrap()
3518 }
3519 }
3520
3521 #[derive(Clone, Copy, PartialEq, Eq)]
3522 pub struct DoodadType(u8);
3523 impl DoodadType {
3524 pub const OUTLINE: Self = Self(1);
3525 pub const SOLID: Self = Self(2);
3526 pub const TEXT: Self = Self(3);
3527 pub const INDICATOR: Self = Self(4);
3528 pub const LOGO: Self = Self(5);
3529 }
3530 impl From<DoodadType> for u8 {
3531 #[inline]
from(input: DoodadType) -> Self3532 fn from(input: DoodadType) -> Self {
3533 input.0
3534 }
3535 }
3536 impl From<DoodadType> for Option<u8> {
3537 #[inline]
from(input: DoodadType) -> Self3538 fn from(input: DoodadType) -> Self {
3539 Some(input.0)
3540 }
3541 }
3542 impl From<DoodadType> for u16 {
3543 #[inline]
from(input: DoodadType) -> Self3544 fn from(input: DoodadType) -> Self {
3545 u16::from(input.0)
3546 }
3547 }
3548 impl From<DoodadType> for Option<u16> {
3549 #[inline]
from(input: DoodadType) -> Self3550 fn from(input: DoodadType) -> Self {
3551 Some(u16::from(input.0))
3552 }
3553 }
3554 impl From<DoodadType> for u32 {
3555 #[inline]
from(input: DoodadType) -> Self3556 fn from(input: DoodadType) -> Self {
3557 u32::from(input.0)
3558 }
3559 }
3560 impl From<DoodadType> for Option<u32> {
3561 #[inline]
from(input: DoodadType) -> Self3562 fn from(input: DoodadType) -> Self {
3563 Some(u32::from(input.0))
3564 }
3565 }
3566 impl From<u8> for DoodadType {
3567 #[inline]
from(value: u8) -> Self3568 fn from(value: u8) -> Self {
3569 Self(value)
3570 }
3571 }
3572 impl std::fmt::Debug for DoodadType {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result3573 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3574 let variants = [
3575 (Self::OUTLINE.0.into(), "OUTLINE", "Outline"),
3576 (Self::SOLID.0.into(), "SOLID", "Solid"),
3577 (Self::TEXT.0.into(), "TEXT", "Text"),
3578 (Self::INDICATOR.0.into(), "INDICATOR", "Indicator"),
3579 (Self::LOGO.0.into(), "LOGO", "Logo"),
3580 ];
3581 pretty_print_enum(fmt, self.0.into(), &variants)
3582 }
3583 }
3584
3585 #[derive(Debug, Clone, PartialEq, Eq)]
3586 pub struct Listing {
3587 pub flags: u16,
3588 pub string: Vec<String8>,
3589 }
3590 impl TryParse for Listing {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>3591 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3592 let value = remaining;
3593 let (flags, remaining) = u16::try_parse(remaining)?;
3594 let (length, remaining) = u16::try_parse(remaining)?;
3595 let (string, remaining) = crate::x11_utils::parse_u8_list(remaining, length.try_to_usize()?)?;
3596 let string = string.to_vec();
3597 // Align offset to multiple of 2
3598 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
3599 let misalignment = (2 - (offset % 2)) % 2;
3600 let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
3601 let result = Listing { flags, string };
3602 Ok((result, remaining))
3603 }
3604 }
3605 impl Serialize for Listing {
3606 type Bytes = Vec<u8>;
serialize(&self) -> Vec<u8>3607 fn serialize(&self) -> Vec<u8> {
3608 let mut result = Vec::new();
3609 self.serialize_into(&mut result);
3610 result
3611 }
serialize_into(&self, bytes: &mut Vec<u8>)3612 fn serialize_into(&self, bytes: &mut Vec<u8>) {
3613 bytes.reserve(4);
3614 self.flags.serialize_into(bytes);
3615 let length = u16::try_from(self.string.len()).expect("`string` has too many elements");
3616 length.serialize_into(bytes);
3617 bytes.extend_from_slice(&self.string);
3618 bytes.extend_from_slice(&[0; 1][..(2 - (bytes.len() % 2)) % 2]);
3619 }
3620 }
3621 impl Listing {
3622 /// Get the value of the `length` field.
3623 ///
3624 /// The `length` field is used as the length field of the `string` field.
3625 /// This function computes the field's value again based on the length of the list.
3626 ///
3627 /// # Panics
3628 ///
3629 /// Panics if the value cannot be represented in the target type. This
3630 /// cannot happen with values of the struct received from the X11 server.
length(&self) -> u163631 pub fn length(&self) -> u16 {
3632 self.string.len()
3633 .try_into().unwrap()
3634 }
3635 }
3636
3637 #[derive(Debug, Clone, PartialEq, Eq)]
3638 pub struct DeviceLedInfo {
3639 pub led_class: LedClass,
3640 pub led_id: IDSpec,
3641 pub names_present: u32,
3642 pub maps_present: u32,
3643 pub phys_indicators: u32,
3644 pub state: u32,
3645 pub names: Vec<xproto::Atom>,
3646 pub maps: Vec<IndicatorMap>,
3647 }
3648 impl TryParse for DeviceLedInfo {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>3649 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3650 let (led_class, remaining) = LedClassSpec::try_parse(remaining)?;
3651 let (led_id, remaining) = IDSpec::try_parse(remaining)?;
3652 let (names_present, remaining) = u32::try_parse(remaining)?;
3653 let (maps_present, remaining) = u32::try_parse(remaining)?;
3654 let (phys_indicators, remaining) = u32::try_parse(remaining)?;
3655 let (state, remaining) = u32::try_parse(remaining)?;
3656 let (names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, names_present.count_ones().try_to_usize()?)?;
3657 let (maps, remaining) = crate::x11_utils::parse_list::<IndicatorMap>(remaining, maps_present.count_ones().try_to_usize()?)?;
3658 let led_class = led_class.into();
3659 let result = DeviceLedInfo { led_class, led_id, names_present, maps_present, phys_indicators, state, names, maps };
3660 Ok((result, remaining))
3661 }
3662 }
3663 impl Serialize for DeviceLedInfo {
3664 type Bytes = Vec<u8>;
serialize(&self) -> Vec<u8>3665 fn serialize(&self) -> Vec<u8> {
3666 let mut result = Vec::new();
3667 self.serialize_into(&mut result);
3668 result
3669 }
serialize_into(&self, bytes: &mut Vec<u8>)3670 fn serialize_into(&self, bytes: &mut Vec<u8>) {
3671 bytes.reserve(20);
3672 LedClassSpec::from(self.led_class).serialize_into(bytes);
3673 self.led_id.serialize_into(bytes);
3674 self.names_present.serialize_into(bytes);
3675 self.maps_present.serialize_into(bytes);
3676 self.phys_indicators.serialize_into(bytes);
3677 self.state.serialize_into(bytes);
3678 assert_eq!(self.names.len(), usize::try_from(self.names_present.count_ones()).unwrap(), "`names` has an incorrect length");
3679 self.names.serialize_into(bytes);
3680 assert_eq!(self.maps.len(), usize::try_from(self.maps_present.count_ones()).unwrap(), "`maps` has an incorrect length");
3681 self.maps.serialize_into(bytes);
3682 }
3683 }
3684
3685 #[derive(Clone, Copy, PartialEq, Eq)]
3686 pub struct Error(u8);
3687 impl Error {
3688 pub const BAD_DEVICE: Self = Self(255);
3689 pub const BAD_CLASS: Self = Self(254);
3690 pub const BAD_ID: Self = Self(253);
3691 }
3692 impl From<Error> for u8 {
3693 #[inline]
from(input: Error) -> Self3694 fn from(input: Error) -> Self {
3695 input.0
3696 }
3697 }
3698 impl From<Error> for Option<u8> {
3699 #[inline]
from(input: Error) -> Self3700 fn from(input: Error) -> Self {
3701 Some(input.0)
3702 }
3703 }
3704 impl From<Error> for u16 {
3705 #[inline]
from(input: Error) -> Self3706 fn from(input: Error) -> Self {
3707 u16::from(input.0)
3708 }
3709 }
3710 impl From<Error> for Option<u16> {
3711 #[inline]
from(input: Error) -> Self3712 fn from(input: Error) -> Self {
3713 Some(u16::from(input.0))
3714 }
3715 }
3716 impl From<Error> for u32 {
3717 #[inline]
from(input: Error) -> Self3718 fn from(input: Error) -> Self {
3719 u32::from(input.0)
3720 }
3721 }
3722 impl From<Error> for Option<u32> {
3723 #[inline]
from(input: Error) -> Self3724 fn from(input: Error) -> Self {
3725 Some(u32::from(input.0))
3726 }
3727 }
3728 impl From<u8> for Error {
3729 #[inline]
from(value: u8) -> Self3730 fn from(value: u8) -> Self {
3731 Self(value)
3732 }
3733 }
3734 impl std::fmt::Debug for Error {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result3735 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3736 let variants = [
3737 (Self::BAD_DEVICE.0.into(), "BAD_DEVICE", "BadDevice"),
3738 (Self::BAD_CLASS.0.into(), "BAD_CLASS", "BadClass"),
3739 (Self::BAD_ID.0.into(), "BAD_ID", "BadId"),
3740 ];
3741 pretty_print_enum(fmt, self.0.into(), &variants)
3742 }
3743 }
3744
3745 /// Opcode for the Keyboard error
3746 pub const KEYBOARD_ERROR: u8 = 0;
3747
3748 #[derive(Clone, Copy, PartialEq, Eq)]
3749 pub struct SA(u8);
3750 impl SA {
3751 pub const CLEAR_LOCKS: Self = Self(1 << 0);
3752 pub const LATCH_TO_LOCK: Self = Self(1 << 1);
3753 pub const USE_MOD_MAP_MODS: Self = Self(1 << 2);
3754 pub const GROUP_ABSOLUTE: Self = Self(1 << 2);
3755 }
3756 impl From<SA> for u8 {
3757 #[inline]
from(input: SA) -> Self3758 fn from(input: SA) -> Self {
3759 input.0
3760 }
3761 }
3762 impl From<SA> for Option<u8> {
3763 #[inline]
from(input: SA) -> Self3764 fn from(input: SA) -> Self {
3765 Some(input.0)
3766 }
3767 }
3768 impl From<SA> for u16 {
3769 #[inline]
from(input: SA) -> Self3770 fn from(input: SA) -> Self {
3771 u16::from(input.0)
3772 }
3773 }
3774 impl From<SA> for Option<u16> {
3775 #[inline]
from(input: SA) -> Self3776 fn from(input: SA) -> Self {
3777 Some(u16::from(input.0))
3778 }
3779 }
3780 impl From<SA> for u32 {
3781 #[inline]
from(input: SA) -> Self3782 fn from(input: SA) -> Self {
3783 u32::from(input.0)
3784 }
3785 }
3786 impl From<SA> for Option<u32> {
3787 #[inline]
from(input: SA) -> Self3788 fn from(input: SA) -> Self {
3789 Some(u32::from(input.0))
3790 }
3791 }
3792 impl From<u8> for SA {
3793 #[inline]
from(value: u8) -> Self3794 fn from(value: u8) -> Self {
3795 Self(value)
3796 }
3797 }
3798 impl std::fmt::Debug for SA {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result3799 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3800 let variants = [
3801 (Self::CLEAR_LOCKS.0.into(), "CLEAR_LOCKS", "ClearLocks"),
3802 (Self::LATCH_TO_LOCK.0.into(), "LATCH_TO_LOCK", "LatchToLock"),
3803 (Self::USE_MOD_MAP_MODS.0.into(), "USE_MOD_MAP_MODS", "UseModMapMods"),
3804 (Self::GROUP_ABSOLUTE.0.into(), "GROUP_ABSOLUTE", "GroupAbsolute"),
3805 ];
3806 pretty_print_bitmask(fmt, self.0.into(), &variants)
3807 }
3808 }
3809 bitmask_binop!(SA, u8);
3810
3811 #[derive(Clone, Copy, PartialEq, Eq)]
3812 pub struct SAType(u8);
3813 impl SAType {
3814 pub const NO_ACTION: Self = Self(0);
3815 pub const SET_MODS: Self = Self(1);
3816 pub const LATCH_MODS: Self = Self(2);
3817 pub const LOCK_MODS: Self = Self(3);
3818 pub const SET_GROUP: Self = Self(4);
3819 pub const LATCH_GROUP: Self = Self(5);
3820 pub const LOCK_GROUP: Self = Self(6);
3821 pub const MOVE_PTR: Self = Self(7);
3822 pub const PTR_BTN: Self = Self(8);
3823 pub const LOCK_PTR_BTN: Self = Self(9);
3824 pub const SET_PTR_DFLT: Self = Self(10);
3825 pub const ISO_LOCK: Self = Self(11);
3826 pub const TERMINATE: Self = Self(12);
3827 pub const SWITCH_SCREEN: Self = Self(13);
3828 pub const SET_CONTROLS: Self = Self(14);
3829 pub const LOCK_CONTROLS: Self = Self(15);
3830 pub const ACTION_MESSAGE: Self = Self(16);
3831 pub const REDIRECT_KEY: Self = Self(17);
3832 pub const DEVICE_BTN: Self = Self(18);
3833 pub const LOCK_DEVICE_BTN: Self = Self(19);
3834 pub const DEVICE_VALUATOR: Self = Self(20);
3835 }
3836 impl From<SAType> for u8 {
3837 #[inline]
from(input: SAType) -> Self3838 fn from(input: SAType) -> Self {
3839 input.0
3840 }
3841 }
3842 impl From<SAType> for Option<u8> {
3843 #[inline]
from(input: SAType) -> Self3844 fn from(input: SAType) -> Self {
3845 Some(input.0)
3846 }
3847 }
3848 impl From<SAType> for u16 {
3849 #[inline]
from(input: SAType) -> Self3850 fn from(input: SAType) -> Self {
3851 u16::from(input.0)
3852 }
3853 }
3854 impl From<SAType> for Option<u16> {
3855 #[inline]
from(input: SAType) -> Self3856 fn from(input: SAType) -> Self {
3857 Some(u16::from(input.0))
3858 }
3859 }
3860 impl From<SAType> for u32 {
3861 #[inline]
from(input: SAType) -> Self3862 fn from(input: SAType) -> Self {
3863 u32::from(input.0)
3864 }
3865 }
3866 impl From<SAType> for Option<u32> {
3867 #[inline]
from(input: SAType) -> Self3868 fn from(input: SAType) -> Self {
3869 Some(u32::from(input.0))
3870 }
3871 }
3872 impl From<u8> for SAType {
3873 #[inline]
from(value: u8) -> Self3874 fn from(value: u8) -> Self {
3875 Self(value)
3876 }
3877 }
3878 impl std::fmt::Debug for SAType {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result3879 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3880 let variants = [
3881 (Self::NO_ACTION.0.into(), "NO_ACTION", "NoAction"),
3882 (Self::SET_MODS.0.into(), "SET_MODS", "SetMods"),
3883 (Self::LATCH_MODS.0.into(), "LATCH_MODS", "LatchMods"),
3884 (Self::LOCK_MODS.0.into(), "LOCK_MODS", "LockMods"),
3885 (Self::SET_GROUP.0.into(), "SET_GROUP", "SetGroup"),
3886 (Self::LATCH_GROUP.0.into(), "LATCH_GROUP", "LatchGroup"),
3887 (Self::LOCK_GROUP.0.into(), "LOCK_GROUP", "LockGroup"),
3888 (Self::MOVE_PTR.0.into(), "MOVE_PTR", "MovePtr"),
3889 (Self::PTR_BTN.0.into(), "PTR_BTN", "PtrBtn"),
3890 (Self::LOCK_PTR_BTN.0.into(), "LOCK_PTR_BTN", "LockPtrBtn"),
3891 (Self::SET_PTR_DFLT.0.into(), "SET_PTR_DFLT", "SetPtrDflt"),
3892 (Self::ISO_LOCK.0.into(), "ISO_LOCK", "ISOLock"),
3893 (Self::TERMINATE.0.into(), "TERMINATE", "Terminate"),
3894 (Self::SWITCH_SCREEN.0.into(), "SWITCH_SCREEN", "SwitchScreen"),
3895 (Self::SET_CONTROLS.0.into(), "SET_CONTROLS", "SetControls"),
3896 (Self::LOCK_CONTROLS.0.into(), "LOCK_CONTROLS", "LockControls"),
3897 (Self::ACTION_MESSAGE.0.into(), "ACTION_MESSAGE", "ActionMessage"),
3898 (Self::REDIRECT_KEY.0.into(), "REDIRECT_KEY", "RedirectKey"),
3899 (Self::DEVICE_BTN.0.into(), "DEVICE_BTN", "DeviceBtn"),
3900 (Self::LOCK_DEVICE_BTN.0.into(), "LOCK_DEVICE_BTN", "LockDeviceBtn"),
3901 (Self::DEVICE_VALUATOR.0.into(), "DEVICE_VALUATOR", "DeviceValuator"),
3902 ];
3903 pretty_print_enum(fmt, self.0.into(), &variants)
3904 }
3905 }
3906
3907 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
3908 pub struct SANoAction {
3909 pub type_: SAType,
3910 }
3911 impl TryParse for SANoAction {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>3912 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3913 let (type_, remaining) = u8::try_parse(remaining)?;
3914 let remaining = remaining.get(7..).ok_or(ParseError::InsufficientData)?;
3915 let type_ = type_.into();
3916 let result = SANoAction { type_ };
3917 Ok((result, remaining))
3918 }
3919 }
3920 impl Serialize for SANoAction {
3921 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]3922 fn serialize(&self) -> [u8; 8] {
3923 let type_bytes = u8::from(self.type_).serialize();
3924 [
3925 type_bytes[0],
3926 0,
3927 0,
3928 0,
3929 0,
3930 0,
3931 0,
3932 0,
3933 ]
3934 }
serialize_into(&self, bytes: &mut Vec<u8>)3935 fn serialize_into(&self, bytes: &mut Vec<u8>) {
3936 bytes.reserve(8);
3937 u8::from(self.type_).serialize_into(bytes);
3938 bytes.extend_from_slice(&[0; 7]);
3939 }
3940 }
3941
3942 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
3943 pub struct SASetMods {
3944 pub type_: SAType,
3945 pub flags: u8,
3946 pub mask: u8,
3947 pub real_mods: u8,
3948 pub vmods_high: u8,
3949 pub vmods_low: u8,
3950 }
3951 impl TryParse for SASetMods {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>3952 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3953 let (type_, remaining) = u8::try_parse(remaining)?;
3954 let (flags, remaining) = u8::try_parse(remaining)?;
3955 let (mask, remaining) = u8::try_parse(remaining)?;
3956 let (real_mods, remaining) = u8::try_parse(remaining)?;
3957 let (vmods_high, remaining) = u8::try_parse(remaining)?;
3958 let (vmods_low, remaining) = u8::try_parse(remaining)?;
3959 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
3960 let type_ = type_.into();
3961 let result = SASetMods { type_, flags, mask, real_mods, vmods_high, vmods_low };
3962 Ok((result, remaining))
3963 }
3964 }
3965 impl Serialize for SASetMods {
3966 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]3967 fn serialize(&self) -> [u8; 8] {
3968 let type_bytes = u8::from(self.type_).serialize();
3969 let flags_bytes = self.flags.serialize();
3970 let mask_bytes = self.mask.serialize();
3971 let real_mods_bytes = self.real_mods.serialize();
3972 let vmods_high_bytes = self.vmods_high.serialize();
3973 let vmods_low_bytes = self.vmods_low.serialize();
3974 [
3975 type_bytes[0],
3976 flags_bytes[0],
3977 mask_bytes[0],
3978 real_mods_bytes[0],
3979 vmods_high_bytes[0],
3980 vmods_low_bytes[0],
3981 0,
3982 0,
3983 ]
3984 }
serialize_into(&self, bytes: &mut Vec<u8>)3985 fn serialize_into(&self, bytes: &mut Vec<u8>) {
3986 bytes.reserve(8);
3987 u8::from(self.type_).serialize_into(bytes);
3988 self.flags.serialize_into(bytes);
3989 self.mask.serialize_into(bytes);
3990 self.real_mods.serialize_into(bytes);
3991 self.vmods_high.serialize_into(bytes);
3992 self.vmods_low.serialize_into(bytes);
3993 bytes.extend_from_slice(&[0; 2]);
3994 }
3995 }
3996
3997 pub type SALatchMods = SASetMods;
3998
3999 pub type SALockMods = SASetMods;
4000
4001 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
4002 pub struct SASetGroup {
4003 pub type_: SAType,
4004 pub flags: u8,
4005 pub group: i8,
4006 }
4007 impl TryParse for SASetGroup {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>4008 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
4009 let (type_, remaining) = u8::try_parse(remaining)?;
4010 let (flags, remaining) = u8::try_parse(remaining)?;
4011 let (group, remaining) = i8::try_parse(remaining)?;
4012 let remaining = remaining.get(5..).ok_or(ParseError::InsufficientData)?;
4013 let type_ = type_.into();
4014 let result = SASetGroup { type_, flags, group };
4015 Ok((result, remaining))
4016 }
4017 }
4018 impl Serialize for SASetGroup {
4019 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]4020 fn serialize(&self) -> [u8; 8] {
4021 let type_bytes = u8::from(self.type_).serialize();
4022 let flags_bytes = self.flags.serialize();
4023 let group_bytes = self.group.serialize();
4024 [
4025 type_bytes[0],
4026 flags_bytes[0],
4027 group_bytes[0],
4028 0,
4029 0,
4030 0,
4031 0,
4032 0,
4033 ]
4034 }
serialize_into(&self, bytes: &mut Vec<u8>)4035 fn serialize_into(&self, bytes: &mut Vec<u8>) {
4036 bytes.reserve(8);
4037 u8::from(self.type_).serialize_into(bytes);
4038 self.flags.serialize_into(bytes);
4039 self.group.serialize_into(bytes);
4040 bytes.extend_from_slice(&[0; 5]);
4041 }
4042 }
4043
4044 pub type SALatchGroup = SASetGroup;
4045
4046 pub type SALockGroup = SASetGroup;
4047
4048 #[derive(Clone, Copy, PartialEq, Eq)]
4049 pub struct SAMovePtrFlag(u8);
4050 impl SAMovePtrFlag {
4051 pub const NO_ACCELERATION: Self = Self(1 << 0);
4052 pub const MOVE_ABSOLUTE_X: Self = Self(1 << 1);
4053 pub const MOVE_ABSOLUTE_Y: Self = Self(1 << 2);
4054 }
4055 impl From<SAMovePtrFlag> for u8 {
4056 #[inline]
from(input: SAMovePtrFlag) -> Self4057 fn from(input: SAMovePtrFlag) -> Self {
4058 input.0
4059 }
4060 }
4061 impl From<SAMovePtrFlag> for Option<u8> {
4062 #[inline]
from(input: SAMovePtrFlag) -> Self4063 fn from(input: SAMovePtrFlag) -> Self {
4064 Some(input.0)
4065 }
4066 }
4067 impl From<SAMovePtrFlag> for u16 {
4068 #[inline]
from(input: SAMovePtrFlag) -> Self4069 fn from(input: SAMovePtrFlag) -> Self {
4070 u16::from(input.0)
4071 }
4072 }
4073 impl From<SAMovePtrFlag> for Option<u16> {
4074 #[inline]
from(input: SAMovePtrFlag) -> Self4075 fn from(input: SAMovePtrFlag) -> Self {
4076 Some(u16::from(input.0))
4077 }
4078 }
4079 impl From<SAMovePtrFlag> for u32 {
4080 #[inline]
from(input: SAMovePtrFlag) -> Self4081 fn from(input: SAMovePtrFlag) -> Self {
4082 u32::from(input.0)
4083 }
4084 }
4085 impl From<SAMovePtrFlag> for Option<u32> {
4086 #[inline]
from(input: SAMovePtrFlag) -> Self4087 fn from(input: SAMovePtrFlag) -> Self {
4088 Some(u32::from(input.0))
4089 }
4090 }
4091 impl From<u8> for SAMovePtrFlag {
4092 #[inline]
from(value: u8) -> Self4093 fn from(value: u8) -> Self {
4094 Self(value)
4095 }
4096 }
4097 impl std::fmt::Debug for SAMovePtrFlag {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result4098 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4099 let variants = [
4100 (Self::NO_ACCELERATION.0.into(), "NO_ACCELERATION", "NoAcceleration"),
4101 (Self::MOVE_ABSOLUTE_X.0.into(), "MOVE_ABSOLUTE_X", "MoveAbsoluteX"),
4102 (Self::MOVE_ABSOLUTE_Y.0.into(), "MOVE_ABSOLUTE_Y", "MoveAbsoluteY"),
4103 ];
4104 pretty_print_bitmask(fmt, self.0.into(), &variants)
4105 }
4106 }
4107 bitmask_binop!(SAMovePtrFlag, u8);
4108
4109 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
4110 pub struct SAMovePtr {
4111 pub type_: SAType,
4112 pub flags: u8,
4113 pub x_high: i8,
4114 pub x_low: u8,
4115 pub y_high: i8,
4116 pub y_low: u8,
4117 }
4118 impl TryParse for SAMovePtr {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>4119 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
4120 let (type_, remaining) = u8::try_parse(remaining)?;
4121 let (flags, remaining) = u8::try_parse(remaining)?;
4122 let (x_high, remaining) = i8::try_parse(remaining)?;
4123 let (x_low, remaining) = u8::try_parse(remaining)?;
4124 let (y_high, remaining) = i8::try_parse(remaining)?;
4125 let (y_low, remaining) = u8::try_parse(remaining)?;
4126 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
4127 let type_ = type_.into();
4128 let result = SAMovePtr { type_, flags, x_high, x_low, y_high, y_low };
4129 Ok((result, remaining))
4130 }
4131 }
4132 impl Serialize for SAMovePtr {
4133 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]4134 fn serialize(&self) -> [u8; 8] {
4135 let type_bytes = u8::from(self.type_).serialize();
4136 let flags_bytes = self.flags.serialize();
4137 let x_high_bytes = self.x_high.serialize();
4138 let x_low_bytes = self.x_low.serialize();
4139 let y_high_bytes = self.y_high.serialize();
4140 let y_low_bytes = self.y_low.serialize();
4141 [
4142 type_bytes[0],
4143 flags_bytes[0],
4144 x_high_bytes[0],
4145 x_low_bytes[0],
4146 y_high_bytes[0],
4147 y_low_bytes[0],
4148 0,
4149 0,
4150 ]
4151 }
serialize_into(&self, bytes: &mut Vec<u8>)4152 fn serialize_into(&self, bytes: &mut Vec<u8>) {
4153 bytes.reserve(8);
4154 u8::from(self.type_).serialize_into(bytes);
4155 self.flags.serialize_into(bytes);
4156 self.x_high.serialize_into(bytes);
4157 self.x_low.serialize_into(bytes);
4158 self.y_high.serialize_into(bytes);
4159 self.y_low.serialize_into(bytes);
4160 bytes.extend_from_slice(&[0; 2]);
4161 }
4162 }
4163
4164 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
4165 pub struct SAPtrBtn {
4166 pub type_: SAType,
4167 pub flags: u8,
4168 pub count: u8,
4169 pub button: u8,
4170 }
4171 impl TryParse for SAPtrBtn {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>4172 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
4173 let (type_, remaining) = u8::try_parse(remaining)?;
4174 let (flags, remaining) = u8::try_parse(remaining)?;
4175 let (count, remaining) = u8::try_parse(remaining)?;
4176 let (button, remaining) = u8::try_parse(remaining)?;
4177 let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?;
4178 let type_ = type_.into();
4179 let result = SAPtrBtn { type_, flags, count, button };
4180 Ok((result, remaining))
4181 }
4182 }
4183 impl Serialize for SAPtrBtn {
4184 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]4185 fn serialize(&self) -> [u8; 8] {
4186 let type_bytes = u8::from(self.type_).serialize();
4187 let flags_bytes = self.flags.serialize();
4188 let count_bytes = self.count.serialize();
4189 let button_bytes = self.button.serialize();
4190 [
4191 type_bytes[0],
4192 flags_bytes[0],
4193 count_bytes[0],
4194 button_bytes[0],
4195 0,
4196 0,
4197 0,
4198 0,
4199 ]
4200 }
serialize_into(&self, bytes: &mut Vec<u8>)4201 fn serialize_into(&self, bytes: &mut Vec<u8>) {
4202 bytes.reserve(8);
4203 u8::from(self.type_).serialize_into(bytes);
4204 self.flags.serialize_into(bytes);
4205 self.count.serialize_into(bytes);
4206 self.button.serialize_into(bytes);
4207 bytes.extend_from_slice(&[0; 4]);
4208 }
4209 }
4210
4211 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
4212 pub struct SALockPtrBtn {
4213 pub type_: SAType,
4214 pub flags: u8,
4215 pub button: u8,
4216 }
4217 impl TryParse for SALockPtrBtn {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>4218 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
4219 let (type_, remaining) = u8::try_parse(remaining)?;
4220 let (flags, remaining) = u8::try_parse(remaining)?;
4221 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
4222 let (button, remaining) = u8::try_parse(remaining)?;
4223 let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?;
4224 let type_ = type_.into();
4225 let result = SALockPtrBtn { type_, flags, button };
4226 Ok((result, remaining))
4227 }
4228 }
4229 impl Serialize for SALockPtrBtn {
4230 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]4231 fn serialize(&self) -> [u8; 8] {
4232 let type_bytes = u8::from(self.type_).serialize();
4233 let flags_bytes = self.flags.serialize();
4234 let button_bytes = self.button.serialize();
4235 [
4236 type_bytes[0],
4237 flags_bytes[0],
4238 0,
4239 button_bytes[0],
4240 0,
4241 0,
4242 0,
4243 0,
4244 ]
4245 }
serialize_into(&self, bytes: &mut Vec<u8>)4246 fn serialize_into(&self, bytes: &mut Vec<u8>) {
4247 bytes.reserve(8);
4248 u8::from(self.type_).serialize_into(bytes);
4249 self.flags.serialize_into(bytes);
4250 bytes.extend_from_slice(&[0; 1]);
4251 self.button.serialize_into(bytes);
4252 bytes.extend_from_slice(&[0; 4]);
4253 }
4254 }
4255
4256 #[derive(Clone, Copy, PartialEq, Eq)]
4257 pub struct SASetPtrDfltFlag(u8);
4258 impl SASetPtrDfltFlag {
4259 pub const DFLT_BTN_ABSOLUTE: Self = Self(1 << 2);
4260 pub const AFFECT_DFLT_BUTTON: Self = Self(1 << 0);
4261 }
4262 impl From<SASetPtrDfltFlag> for u8 {
4263 #[inline]
from(input: SASetPtrDfltFlag) -> Self4264 fn from(input: SASetPtrDfltFlag) -> Self {
4265 input.0
4266 }
4267 }
4268 impl From<SASetPtrDfltFlag> for Option<u8> {
4269 #[inline]
from(input: SASetPtrDfltFlag) -> Self4270 fn from(input: SASetPtrDfltFlag) -> Self {
4271 Some(input.0)
4272 }
4273 }
4274 impl From<SASetPtrDfltFlag> for u16 {
4275 #[inline]
from(input: SASetPtrDfltFlag) -> Self4276 fn from(input: SASetPtrDfltFlag) -> Self {
4277 u16::from(input.0)
4278 }
4279 }
4280 impl From<SASetPtrDfltFlag> for Option<u16> {
4281 #[inline]
from(input: SASetPtrDfltFlag) -> Self4282 fn from(input: SASetPtrDfltFlag) -> Self {
4283 Some(u16::from(input.0))
4284 }
4285 }
4286 impl From<SASetPtrDfltFlag> for u32 {
4287 #[inline]
from(input: SASetPtrDfltFlag) -> Self4288 fn from(input: SASetPtrDfltFlag) -> Self {
4289 u32::from(input.0)
4290 }
4291 }
4292 impl From<SASetPtrDfltFlag> for Option<u32> {
4293 #[inline]
from(input: SASetPtrDfltFlag) -> Self4294 fn from(input: SASetPtrDfltFlag) -> Self {
4295 Some(u32::from(input.0))
4296 }
4297 }
4298 impl From<u8> for SASetPtrDfltFlag {
4299 #[inline]
from(value: u8) -> Self4300 fn from(value: u8) -> Self {
4301 Self(value)
4302 }
4303 }
4304 impl std::fmt::Debug for SASetPtrDfltFlag {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result4305 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4306 let variants = [
4307 (Self::DFLT_BTN_ABSOLUTE.0.into(), "DFLT_BTN_ABSOLUTE", "DfltBtnAbsolute"),
4308 (Self::AFFECT_DFLT_BUTTON.0.into(), "AFFECT_DFLT_BUTTON", "AffectDfltButton"),
4309 ];
4310 pretty_print_bitmask(fmt, self.0.into(), &variants)
4311 }
4312 }
4313 bitmask_binop!(SASetPtrDfltFlag, u8);
4314
4315 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
4316 pub struct SASetPtrDflt {
4317 pub type_: SAType,
4318 pub flags: u8,
4319 pub affect: u8,
4320 pub value: i8,
4321 }
4322 impl TryParse for SASetPtrDflt {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>4323 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
4324 let (type_, remaining) = u8::try_parse(remaining)?;
4325 let (flags, remaining) = u8::try_parse(remaining)?;
4326 let (affect, remaining) = u8::try_parse(remaining)?;
4327 let (value, remaining) = i8::try_parse(remaining)?;
4328 let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?;
4329 let type_ = type_.into();
4330 let result = SASetPtrDflt { type_, flags, affect, value };
4331 Ok((result, remaining))
4332 }
4333 }
4334 impl Serialize for SASetPtrDflt {
4335 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]4336 fn serialize(&self) -> [u8; 8] {
4337 let type_bytes = u8::from(self.type_).serialize();
4338 let flags_bytes = self.flags.serialize();
4339 let affect_bytes = self.affect.serialize();
4340 let value_bytes = self.value.serialize();
4341 [
4342 type_bytes[0],
4343 flags_bytes[0],
4344 affect_bytes[0],
4345 value_bytes[0],
4346 0,
4347 0,
4348 0,
4349 0,
4350 ]
4351 }
serialize_into(&self, bytes: &mut Vec<u8>)4352 fn serialize_into(&self, bytes: &mut Vec<u8>) {
4353 bytes.reserve(8);
4354 u8::from(self.type_).serialize_into(bytes);
4355 self.flags.serialize_into(bytes);
4356 self.affect.serialize_into(bytes);
4357 self.value.serialize_into(bytes);
4358 bytes.extend_from_slice(&[0; 4]);
4359 }
4360 }
4361
4362 #[derive(Clone, Copy, PartialEq, Eq)]
4363 pub struct SAIsoLockFlag(u8);
4364 impl SAIsoLockFlag {
4365 pub const NO_LOCK: Self = Self(1 << 0);
4366 pub const NO_UNLOCK: Self = Self(1 << 1);
4367 pub const USE_MOD_MAP_MODS: Self = Self(1 << 2);
4368 pub const GROUP_ABSOLUTE: Self = Self(1 << 2);
4369 pub const ISO_DFLT_IS_GROUP: Self = Self(1 << 3);
4370 }
4371 impl From<SAIsoLockFlag> for u8 {
4372 #[inline]
from(input: SAIsoLockFlag) -> Self4373 fn from(input: SAIsoLockFlag) -> Self {
4374 input.0
4375 }
4376 }
4377 impl From<SAIsoLockFlag> for Option<u8> {
4378 #[inline]
from(input: SAIsoLockFlag) -> Self4379 fn from(input: SAIsoLockFlag) -> Self {
4380 Some(input.0)
4381 }
4382 }
4383 impl From<SAIsoLockFlag> for u16 {
4384 #[inline]
from(input: SAIsoLockFlag) -> Self4385 fn from(input: SAIsoLockFlag) -> Self {
4386 u16::from(input.0)
4387 }
4388 }
4389 impl From<SAIsoLockFlag> for Option<u16> {
4390 #[inline]
from(input: SAIsoLockFlag) -> Self4391 fn from(input: SAIsoLockFlag) -> Self {
4392 Some(u16::from(input.0))
4393 }
4394 }
4395 impl From<SAIsoLockFlag> for u32 {
4396 #[inline]
from(input: SAIsoLockFlag) -> Self4397 fn from(input: SAIsoLockFlag) -> Self {
4398 u32::from(input.0)
4399 }
4400 }
4401 impl From<SAIsoLockFlag> for Option<u32> {
4402 #[inline]
from(input: SAIsoLockFlag) -> Self4403 fn from(input: SAIsoLockFlag) -> Self {
4404 Some(u32::from(input.0))
4405 }
4406 }
4407 impl From<u8> for SAIsoLockFlag {
4408 #[inline]
from(value: u8) -> Self4409 fn from(value: u8) -> Self {
4410 Self(value)
4411 }
4412 }
4413 impl std::fmt::Debug for SAIsoLockFlag {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result4414 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4415 let variants = [
4416 (Self::NO_LOCK.0.into(), "NO_LOCK", "NoLock"),
4417 (Self::NO_UNLOCK.0.into(), "NO_UNLOCK", "NoUnlock"),
4418 (Self::USE_MOD_MAP_MODS.0.into(), "USE_MOD_MAP_MODS", "UseModMapMods"),
4419 (Self::GROUP_ABSOLUTE.0.into(), "GROUP_ABSOLUTE", "GroupAbsolute"),
4420 (Self::ISO_DFLT_IS_GROUP.0.into(), "ISO_DFLT_IS_GROUP", "ISODfltIsGroup"),
4421 ];
4422 pretty_print_bitmask(fmt, self.0.into(), &variants)
4423 }
4424 }
4425 bitmask_binop!(SAIsoLockFlag, u8);
4426
4427 #[derive(Clone, Copy, PartialEq, Eq)]
4428 pub struct SAIsoLockNoAffect(u8);
4429 impl SAIsoLockNoAffect {
4430 pub const CTRLS: Self = Self(1 << 3);
4431 pub const PTR: Self = Self(1 << 4);
4432 pub const GROUP: Self = Self(1 << 5);
4433 pub const MODS: Self = Self(1 << 6);
4434 }
4435 impl From<SAIsoLockNoAffect> for u8 {
4436 #[inline]
from(input: SAIsoLockNoAffect) -> Self4437 fn from(input: SAIsoLockNoAffect) -> Self {
4438 input.0
4439 }
4440 }
4441 impl From<SAIsoLockNoAffect> for Option<u8> {
4442 #[inline]
from(input: SAIsoLockNoAffect) -> Self4443 fn from(input: SAIsoLockNoAffect) -> Self {
4444 Some(input.0)
4445 }
4446 }
4447 impl From<SAIsoLockNoAffect> for u16 {
4448 #[inline]
from(input: SAIsoLockNoAffect) -> Self4449 fn from(input: SAIsoLockNoAffect) -> Self {
4450 u16::from(input.0)
4451 }
4452 }
4453 impl From<SAIsoLockNoAffect> for Option<u16> {
4454 #[inline]
from(input: SAIsoLockNoAffect) -> Self4455 fn from(input: SAIsoLockNoAffect) -> Self {
4456 Some(u16::from(input.0))
4457 }
4458 }
4459 impl From<SAIsoLockNoAffect> for u32 {
4460 #[inline]
from(input: SAIsoLockNoAffect) -> Self4461 fn from(input: SAIsoLockNoAffect) -> Self {
4462 u32::from(input.0)
4463 }
4464 }
4465 impl From<SAIsoLockNoAffect> for Option<u32> {
4466 #[inline]
from(input: SAIsoLockNoAffect) -> Self4467 fn from(input: SAIsoLockNoAffect) -> Self {
4468 Some(u32::from(input.0))
4469 }
4470 }
4471 impl From<u8> for SAIsoLockNoAffect {
4472 #[inline]
from(value: u8) -> Self4473 fn from(value: u8) -> Self {
4474 Self(value)
4475 }
4476 }
4477 impl std::fmt::Debug for SAIsoLockNoAffect {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result4478 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4479 let variants = [
4480 (Self::CTRLS.0.into(), "CTRLS", "Ctrls"),
4481 (Self::PTR.0.into(), "PTR", "Ptr"),
4482 (Self::GROUP.0.into(), "GROUP", "Group"),
4483 (Self::MODS.0.into(), "MODS", "Mods"),
4484 ];
4485 pretty_print_bitmask(fmt, self.0.into(), &variants)
4486 }
4487 }
4488 bitmask_binop!(SAIsoLockNoAffect, u8);
4489
4490 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
4491 pub struct SAIsoLock {
4492 pub type_: SAType,
4493 pub flags: u8,
4494 pub mask: u8,
4495 pub real_mods: u8,
4496 pub group: i8,
4497 pub affect: u8,
4498 pub vmods_high: u8,
4499 pub vmods_low: u8,
4500 }
4501 impl TryParse for SAIsoLock {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>4502 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
4503 let (type_, remaining) = u8::try_parse(remaining)?;
4504 let (flags, remaining) = u8::try_parse(remaining)?;
4505 let (mask, remaining) = u8::try_parse(remaining)?;
4506 let (real_mods, remaining) = u8::try_parse(remaining)?;
4507 let (group, remaining) = i8::try_parse(remaining)?;
4508 let (affect, remaining) = u8::try_parse(remaining)?;
4509 let (vmods_high, remaining) = u8::try_parse(remaining)?;
4510 let (vmods_low, remaining) = u8::try_parse(remaining)?;
4511 let type_ = type_.into();
4512 let result = SAIsoLock { type_, flags, mask, real_mods, group, affect, vmods_high, vmods_low };
4513 Ok((result, remaining))
4514 }
4515 }
4516 impl Serialize for SAIsoLock {
4517 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]4518 fn serialize(&self) -> [u8; 8] {
4519 let type_bytes = u8::from(self.type_).serialize();
4520 let flags_bytes = self.flags.serialize();
4521 let mask_bytes = self.mask.serialize();
4522 let real_mods_bytes = self.real_mods.serialize();
4523 let group_bytes = self.group.serialize();
4524 let affect_bytes = self.affect.serialize();
4525 let vmods_high_bytes = self.vmods_high.serialize();
4526 let vmods_low_bytes = self.vmods_low.serialize();
4527 [
4528 type_bytes[0],
4529 flags_bytes[0],
4530 mask_bytes[0],
4531 real_mods_bytes[0],
4532 group_bytes[0],
4533 affect_bytes[0],
4534 vmods_high_bytes[0],
4535 vmods_low_bytes[0],
4536 ]
4537 }
serialize_into(&self, bytes: &mut Vec<u8>)4538 fn serialize_into(&self, bytes: &mut Vec<u8>) {
4539 bytes.reserve(8);
4540 u8::from(self.type_).serialize_into(bytes);
4541 self.flags.serialize_into(bytes);
4542 self.mask.serialize_into(bytes);
4543 self.real_mods.serialize_into(bytes);
4544 self.group.serialize_into(bytes);
4545 self.affect.serialize_into(bytes);
4546 self.vmods_high.serialize_into(bytes);
4547 self.vmods_low.serialize_into(bytes);
4548 }
4549 }
4550
4551 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
4552 pub struct SATerminate {
4553 pub type_: SAType,
4554 }
4555 impl TryParse for SATerminate {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>4556 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
4557 let (type_, remaining) = u8::try_parse(remaining)?;
4558 let remaining = remaining.get(7..).ok_or(ParseError::InsufficientData)?;
4559 let type_ = type_.into();
4560 let result = SATerminate { type_ };
4561 Ok((result, remaining))
4562 }
4563 }
4564 impl Serialize for SATerminate {
4565 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]4566 fn serialize(&self) -> [u8; 8] {
4567 let type_bytes = u8::from(self.type_).serialize();
4568 [
4569 type_bytes[0],
4570 0,
4571 0,
4572 0,
4573 0,
4574 0,
4575 0,
4576 0,
4577 ]
4578 }
serialize_into(&self, bytes: &mut Vec<u8>)4579 fn serialize_into(&self, bytes: &mut Vec<u8>) {
4580 bytes.reserve(8);
4581 u8::from(self.type_).serialize_into(bytes);
4582 bytes.extend_from_slice(&[0; 7]);
4583 }
4584 }
4585
4586 #[derive(Clone, Copy, PartialEq, Eq)]
4587 pub struct SwitchScreenFlag(u8);
4588 impl SwitchScreenFlag {
4589 pub const APPLICATION: Self = Self(1 << 0);
4590 pub const ABSOLUTE: Self = Self(1 << 2);
4591 }
4592 impl From<SwitchScreenFlag> for u8 {
4593 #[inline]
from(input: SwitchScreenFlag) -> Self4594 fn from(input: SwitchScreenFlag) -> Self {
4595 input.0
4596 }
4597 }
4598 impl From<SwitchScreenFlag> for Option<u8> {
4599 #[inline]
from(input: SwitchScreenFlag) -> Self4600 fn from(input: SwitchScreenFlag) -> Self {
4601 Some(input.0)
4602 }
4603 }
4604 impl From<SwitchScreenFlag> for u16 {
4605 #[inline]
from(input: SwitchScreenFlag) -> Self4606 fn from(input: SwitchScreenFlag) -> Self {
4607 u16::from(input.0)
4608 }
4609 }
4610 impl From<SwitchScreenFlag> for Option<u16> {
4611 #[inline]
from(input: SwitchScreenFlag) -> Self4612 fn from(input: SwitchScreenFlag) -> Self {
4613 Some(u16::from(input.0))
4614 }
4615 }
4616 impl From<SwitchScreenFlag> for u32 {
4617 #[inline]
from(input: SwitchScreenFlag) -> Self4618 fn from(input: SwitchScreenFlag) -> Self {
4619 u32::from(input.0)
4620 }
4621 }
4622 impl From<SwitchScreenFlag> for Option<u32> {
4623 #[inline]
from(input: SwitchScreenFlag) -> Self4624 fn from(input: SwitchScreenFlag) -> Self {
4625 Some(u32::from(input.0))
4626 }
4627 }
4628 impl From<u8> for SwitchScreenFlag {
4629 #[inline]
from(value: u8) -> Self4630 fn from(value: u8) -> Self {
4631 Self(value)
4632 }
4633 }
4634 impl std::fmt::Debug for SwitchScreenFlag {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result4635 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4636 let variants = [
4637 (Self::APPLICATION.0.into(), "APPLICATION", "Application"),
4638 (Self::ABSOLUTE.0.into(), "ABSOLUTE", "Absolute"),
4639 ];
4640 pretty_print_bitmask(fmt, self.0.into(), &variants)
4641 }
4642 }
4643 bitmask_binop!(SwitchScreenFlag, u8);
4644
4645 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
4646 pub struct SASwitchScreen {
4647 pub type_: SAType,
4648 pub flags: u8,
4649 pub new_screen: i8,
4650 }
4651 impl TryParse for SASwitchScreen {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>4652 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
4653 let (type_, remaining) = u8::try_parse(remaining)?;
4654 let (flags, remaining) = u8::try_parse(remaining)?;
4655 let (new_screen, remaining) = i8::try_parse(remaining)?;
4656 let remaining = remaining.get(5..).ok_or(ParseError::InsufficientData)?;
4657 let type_ = type_.into();
4658 let result = SASwitchScreen { type_, flags, new_screen };
4659 Ok((result, remaining))
4660 }
4661 }
4662 impl Serialize for SASwitchScreen {
4663 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]4664 fn serialize(&self) -> [u8; 8] {
4665 let type_bytes = u8::from(self.type_).serialize();
4666 let flags_bytes = self.flags.serialize();
4667 let new_screen_bytes = self.new_screen.serialize();
4668 [
4669 type_bytes[0],
4670 flags_bytes[0],
4671 new_screen_bytes[0],
4672 0,
4673 0,
4674 0,
4675 0,
4676 0,
4677 ]
4678 }
serialize_into(&self, bytes: &mut Vec<u8>)4679 fn serialize_into(&self, bytes: &mut Vec<u8>) {
4680 bytes.reserve(8);
4681 u8::from(self.type_).serialize_into(bytes);
4682 self.flags.serialize_into(bytes);
4683 self.new_screen.serialize_into(bytes);
4684 bytes.extend_from_slice(&[0; 5]);
4685 }
4686 }
4687
4688 #[derive(Clone, Copy, PartialEq, Eq)]
4689 pub struct BoolCtrlsHigh(u8);
4690 impl BoolCtrlsHigh {
4691 pub const ACCESS_X_FEEDBACK: Self = Self(1 << 0);
4692 pub const AUDIBLE_BELL: Self = Self(1 << 1);
4693 pub const OVERLAY1: Self = Self(1 << 2);
4694 pub const OVERLAY2: Self = Self(1 << 3);
4695 pub const IGNORE_GROUP_LOCK: Self = Self(1 << 4);
4696 }
4697 impl From<BoolCtrlsHigh> for u8 {
4698 #[inline]
from(input: BoolCtrlsHigh) -> Self4699 fn from(input: BoolCtrlsHigh) -> Self {
4700 input.0
4701 }
4702 }
4703 impl From<BoolCtrlsHigh> for Option<u8> {
4704 #[inline]
from(input: BoolCtrlsHigh) -> Self4705 fn from(input: BoolCtrlsHigh) -> Self {
4706 Some(input.0)
4707 }
4708 }
4709 impl From<BoolCtrlsHigh> for u16 {
4710 #[inline]
from(input: BoolCtrlsHigh) -> Self4711 fn from(input: BoolCtrlsHigh) -> Self {
4712 u16::from(input.0)
4713 }
4714 }
4715 impl From<BoolCtrlsHigh> for Option<u16> {
4716 #[inline]
from(input: BoolCtrlsHigh) -> Self4717 fn from(input: BoolCtrlsHigh) -> Self {
4718 Some(u16::from(input.0))
4719 }
4720 }
4721 impl From<BoolCtrlsHigh> for u32 {
4722 #[inline]
from(input: BoolCtrlsHigh) -> Self4723 fn from(input: BoolCtrlsHigh) -> Self {
4724 u32::from(input.0)
4725 }
4726 }
4727 impl From<BoolCtrlsHigh> for Option<u32> {
4728 #[inline]
from(input: BoolCtrlsHigh) -> Self4729 fn from(input: BoolCtrlsHigh) -> Self {
4730 Some(u32::from(input.0))
4731 }
4732 }
4733 impl From<u8> for BoolCtrlsHigh {
4734 #[inline]
from(value: u8) -> Self4735 fn from(value: u8) -> Self {
4736 Self(value)
4737 }
4738 }
4739 impl std::fmt::Debug for BoolCtrlsHigh {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result4740 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4741 let variants = [
4742 (Self::ACCESS_X_FEEDBACK.0.into(), "ACCESS_X_FEEDBACK", "AccessXFeedback"),
4743 (Self::AUDIBLE_BELL.0.into(), "AUDIBLE_BELL", "AudibleBell"),
4744 (Self::OVERLAY1.0.into(), "OVERLAY1", "Overlay1"),
4745 (Self::OVERLAY2.0.into(), "OVERLAY2", "Overlay2"),
4746 (Self::IGNORE_GROUP_LOCK.0.into(), "IGNORE_GROUP_LOCK", "IgnoreGroupLock"),
4747 ];
4748 pretty_print_bitmask(fmt, self.0.into(), &variants)
4749 }
4750 }
4751 bitmask_binop!(BoolCtrlsHigh, u8);
4752
4753 #[derive(Clone, Copy, PartialEq, Eq)]
4754 pub struct BoolCtrlsLow(u8);
4755 impl BoolCtrlsLow {
4756 pub const REPEAT_KEYS: Self = Self(1 << 0);
4757 pub const SLOW_KEYS: Self = Self(1 << 1);
4758 pub const BOUNCE_KEYS: Self = Self(1 << 2);
4759 pub const STICKY_KEYS: Self = Self(1 << 3);
4760 pub const MOUSE_KEYS: Self = Self(1 << 4);
4761 pub const MOUSE_KEYS_ACCEL: Self = Self(1 << 5);
4762 pub const ACCESS_X_KEYS: Self = Self(1 << 6);
4763 pub const ACCESS_X_TIMEOUT: Self = Self(1 << 7);
4764 }
4765 impl From<BoolCtrlsLow> for u8 {
4766 #[inline]
from(input: BoolCtrlsLow) -> Self4767 fn from(input: BoolCtrlsLow) -> Self {
4768 input.0
4769 }
4770 }
4771 impl From<BoolCtrlsLow> for Option<u8> {
4772 #[inline]
from(input: BoolCtrlsLow) -> Self4773 fn from(input: BoolCtrlsLow) -> Self {
4774 Some(input.0)
4775 }
4776 }
4777 impl From<BoolCtrlsLow> for u16 {
4778 #[inline]
from(input: BoolCtrlsLow) -> Self4779 fn from(input: BoolCtrlsLow) -> Self {
4780 u16::from(input.0)
4781 }
4782 }
4783 impl From<BoolCtrlsLow> for Option<u16> {
4784 #[inline]
from(input: BoolCtrlsLow) -> Self4785 fn from(input: BoolCtrlsLow) -> Self {
4786 Some(u16::from(input.0))
4787 }
4788 }
4789 impl From<BoolCtrlsLow> for u32 {
4790 #[inline]
from(input: BoolCtrlsLow) -> Self4791 fn from(input: BoolCtrlsLow) -> Self {
4792 u32::from(input.0)
4793 }
4794 }
4795 impl From<BoolCtrlsLow> for Option<u32> {
4796 #[inline]
from(input: BoolCtrlsLow) -> Self4797 fn from(input: BoolCtrlsLow) -> Self {
4798 Some(u32::from(input.0))
4799 }
4800 }
4801 impl From<u8> for BoolCtrlsLow {
4802 #[inline]
from(value: u8) -> Self4803 fn from(value: u8) -> Self {
4804 Self(value)
4805 }
4806 }
4807 impl std::fmt::Debug for BoolCtrlsLow {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result4808 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4809 let variants = [
4810 (Self::REPEAT_KEYS.0.into(), "REPEAT_KEYS", "RepeatKeys"),
4811 (Self::SLOW_KEYS.0.into(), "SLOW_KEYS", "SlowKeys"),
4812 (Self::BOUNCE_KEYS.0.into(), "BOUNCE_KEYS", "BounceKeys"),
4813 (Self::STICKY_KEYS.0.into(), "STICKY_KEYS", "StickyKeys"),
4814 (Self::MOUSE_KEYS.0.into(), "MOUSE_KEYS", "MouseKeys"),
4815 (Self::MOUSE_KEYS_ACCEL.0.into(), "MOUSE_KEYS_ACCEL", "MouseKeysAccel"),
4816 (Self::ACCESS_X_KEYS.0.into(), "ACCESS_X_KEYS", "AccessXKeys"),
4817 (Self::ACCESS_X_TIMEOUT.0.into(), "ACCESS_X_TIMEOUT", "AccessXTimeout"),
4818 ];
4819 pretty_print_bitmask(fmt, self.0.into(), &variants)
4820 }
4821 }
4822 bitmask_binop!(BoolCtrlsLow, u8);
4823
4824 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
4825 pub struct SASetControls {
4826 pub type_: SAType,
4827 pub bool_ctrls_high: u8,
4828 pub bool_ctrls_low: u8,
4829 }
4830 impl TryParse for SASetControls {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>4831 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
4832 let (type_, remaining) = u8::try_parse(remaining)?;
4833 let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?;
4834 let (bool_ctrls_high, remaining) = u8::try_parse(remaining)?;
4835 let (bool_ctrls_low, remaining) = u8::try_parse(remaining)?;
4836 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
4837 let type_ = type_.into();
4838 let result = SASetControls { type_, bool_ctrls_high, bool_ctrls_low };
4839 Ok((result, remaining))
4840 }
4841 }
4842 impl Serialize for SASetControls {
4843 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]4844 fn serialize(&self) -> [u8; 8] {
4845 let type_bytes = u8::from(self.type_).serialize();
4846 let bool_ctrls_high_bytes = self.bool_ctrls_high.serialize();
4847 let bool_ctrls_low_bytes = self.bool_ctrls_low.serialize();
4848 [
4849 type_bytes[0],
4850 0,
4851 0,
4852 0,
4853 bool_ctrls_high_bytes[0],
4854 bool_ctrls_low_bytes[0],
4855 0,
4856 0,
4857 ]
4858 }
serialize_into(&self, bytes: &mut Vec<u8>)4859 fn serialize_into(&self, bytes: &mut Vec<u8>) {
4860 bytes.reserve(8);
4861 u8::from(self.type_).serialize_into(bytes);
4862 bytes.extend_from_slice(&[0; 3]);
4863 self.bool_ctrls_high.serialize_into(bytes);
4864 self.bool_ctrls_low.serialize_into(bytes);
4865 bytes.extend_from_slice(&[0; 2]);
4866 }
4867 }
4868
4869 pub type SALockControls = SASetControls;
4870
4871 #[derive(Clone, Copy, PartialEq, Eq)]
4872 pub struct ActionMessageFlag(u8);
4873 impl ActionMessageFlag {
4874 pub const ON_PRESS: Self = Self(1 << 0);
4875 pub const ON_RELEASE: Self = Self(1 << 1);
4876 pub const GEN_KEY_EVENT: Self = Self(1 << 2);
4877 }
4878 impl From<ActionMessageFlag> for u8 {
4879 #[inline]
from(input: ActionMessageFlag) -> Self4880 fn from(input: ActionMessageFlag) -> Self {
4881 input.0
4882 }
4883 }
4884 impl From<ActionMessageFlag> for Option<u8> {
4885 #[inline]
from(input: ActionMessageFlag) -> Self4886 fn from(input: ActionMessageFlag) -> Self {
4887 Some(input.0)
4888 }
4889 }
4890 impl From<ActionMessageFlag> for u16 {
4891 #[inline]
from(input: ActionMessageFlag) -> Self4892 fn from(input: ActionMessageFlag) -> Self {
4893 u16::from(input.0)
4894 }
4895 }
4896 impl From<ActionMessageFlag> for Option<u16> {
4897 #[inline]
from(input: ActionMessageFlag) -> Self4898 fn from(input: ActionMessageFlag) -> Self {
4899 Some(u16::from(input.0))
4900 }
4901 }
4902 impl From<ActionMessageFlag> for u32 {
4903 #[inline]
from(input: ActionMessageFlag) -> Self4904 fn from(input: ActionMessageFlag) -> Self {
4905 u32::from(input.0)
4906 }
4907 }
4908 impl From<ActionMessageFlag> for Option<u32> {
4909 #[inline]
from(input: ActionMessageFlag) -> Self4910 fn from(input: ActionMessageFlag) -> Self {
4911 Some(u32::from(input.0))
4912 }
4913 }
4914 impl From<u8> for ActionMessageFlag {
4915 #[inline]
from(value: u8) -> Self4916 fn from(value: u8) -> Self {
4917 Self(value)
4918 }
4919 }
4920 impl std::fmt::Debug for ActionMessageFlag {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result4921 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4922 let variants = [
4923 (Self::ON_PRESS.0.into(), "ON_PRESS", "OnPress"),
4924 (Self::ON_RELEASE.0.into(), "ON_RELEASE", "OnRelease"),
4925 (Self::GEN_KEY_EVENT.0.into(), "GEN_KEY_EVENT", "GenKeyEvent"),
4926 ];
4927 pretty_print_bitmask(fmt, self.0.into(), &variants)
4928 }
4929 }
4930 bitmask_binop!(ActionMessageFlag, u8);
4931
4932 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
4933 pub struct SAActionMessage {
4934 pub type_: SAType,
4935 pub flags: u8,
4936 pub message: [u8; 6],
4937 }
4938 impl TryParse for SAActionMessage {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>4939 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
4940 let (type_, remaining) = u8::try_parse(remaining)?;
4941 let (flags, remaining) = u8::try_parse(remaining)?;
4942 let (message, remaining) = crate::x11_utils::parse_u8_list(remaining, 6)?;
4943 let message = <[u8; 6]>::try_from(message).unwrap();
4944 let type_ = type_.into();
4945 let result = SAActionMessage { type_, flags, message };
4946 Ok((result, remaining))
4947 }
4948 }
4949 impl Serialize for SAActionMessage {
4950 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]4951 fn serialize(&self) -> [u8; 8] {
4952 let type_bytes = u8::from(self.type_).serialize();
4953 let flags_bytes = self.flags.serialize();
4954 [
4955 type_bytes[0],
4956 flags_bytes[0],
4957 self.message[0],
4958 self.message[1],
4959 self.message[2],
4960 self.message[3],
4961 self.message[4],
4962 self.message[5],
4963 ]
4964 }
serialize_into(&self, bytes: &mut Vec<u8>)4965 fn serialize_into(&self, bytes: &mut Vec<u8>) {
4966 bytes.reserve(8);
4967 u8::from(self.type_).serialize_into(bytes);
4968 self.flags.serialize_into(bytes);
4969 bytes.extend_from_slice(&self.message);
4970 }
4971 }
4972
4973 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
4974 pub struct SARedirectKey {
4975 pub type_: SAType,
4976 pub newkey: xproto::Keycode,
4977 pub mask: u8,
4978 pub real_modifiers: u8,
4979 pub vmods_mask_high: u8,
4980 pub vmods_mask_low: u8,
4981 pub vmods_high: u8,
4982 pub vmods_low: u8,
4983 }
4984 impl TryParse for SARedirectKey {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>4985 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
4986 let (type_, remaining) = u8::try_parse(remaining)?;
4987 let (newkey, remaining) = xproto::Keycode::try_parse(remaining)?;
4988 let (mask, remaining) = u8::try_parse(remaining)?;
4989 let (real_modifiers, remaining) = u8::try_parse(remaining)?;
4990 let (vmods_mask_high, remaining) = u8::try_parse(remaining)?;
4991 let (vmods_mask_low, remaining) = u8::try_parse(remaining)?;
4992 let (vmods_high, remaining) = u8::try_parse(remaining)?;
4993 let (vmods_low, remaining) = u8::try_parse(remaining)?;
4994 let type_ = type_.into();
4995 let result = SARedirectKey { type_, newkey, mask, real_modifiers, vmods_mask_high, vmods_mask_low, vmods_high, vmods_low };
4996 Ok((result, remaining))
4997 }
4998 }
4999 impl Serialize for SARedirectKey {
5000 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]5001 fn serialize(&self) -> [u8; 8] {
5002 let type_bytes = u8::from(self.type_).serialize();
5003 let newkey_bytes = self.newkey.serialize();
5004 let mask_bytes = self.mask.serialize();
5005 let real_modifiers_bytes = self.real_modifiers.serialize();
5006 let vmods_mask_high_bytes = self.vmods_mask_high.serialize();
5007 let vmods_mask_low_bytes = self.vmods_mask_low.serialize();
5008 let vmods_high_bytes = self.vmods_high.serialize();
5009 let vmods_low_bytes = self.vmods_low.serialize();
5010 [
5011 type_bytes[0],
5012 newkey_bytes[0],
5013 mask_bytes[0],
5014 real_modifiers_bytes[0],
5015 vmods_mask_high_bytes[0],
5016 vmods_mask_low_bytes[0],
5017 vmods_high_bytes[0],
5018 vmods_low_bytes[0],
5019 ]
5020 }
serialize_into(&self, bytes: &mut Vec<u8>)5021 fn serialize_into(&self, bytes: &mut Vec<u8>) {
5022 bytes.reserve(8);
5023 u8::from(self.type_).serialize_into(bytes);
5024 self.newkey.serialize_into(bytes);
5025 self.mask.serialize_into(bytes);
5026 self.real_modifiers.serialize_into(bytes);
5027 self.vmods_mask_high.serialize_into(bytes);
5028 self.vmods_mask_low.serialize_into(bytes);
5029 self.vmods_high.serialize_into(bytes);
5030 self.vmods_low.serialize_into(bytes);
5031 }
5032 }
5033
5034 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
5035 pub struct SADeviceBtn {
5036 pub type_: SAType,
5037 pub flags: u8,
5038 pub count: u8,
5039 pub button: u8,
5040 pub device: u8,
5041 }
5042 impl TryParse for SADeviceBtn {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>5043 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
5044 let (type_, remaining) = u8::try_parse(remaining)?;
5045 let (flags, remaining) = u8::try_parse(remaining)?;
5046 let (count, remaining) = u8::try_parse(remaining)?;
5047 let (button, remaining) = u8::try_parse(remaining)?;
5048 let (device, remaining) = u8::try_parse(remaining)?;
5049 let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?;
5050 let type_ = type_.into();
5051 let result = SADeviceBtn { type_, flags, count, button, device };
5052 Ok((result, remaining))
5053 }
5054 }
5055 impl Serialize for SADeviceBtn {
5056 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]5057 fn serialize(&self) -> [u8; 8] {
5058 let type_bytes = u8::from(self.type_).serialize();
5059 let flags_bytes = self.flags.serialize();
5060 let count_bytes = self.count.serialize();
5061 let button_bytes = self.button.serialize();
5062 let device_bytes = self.device.serialize();
5063 [
5064 type_bytes[0],
5065 flags_bytes[0],
5066 count_bytes[0],
5067 button_bytes[0],
5068 device_bytes[0],
5069 0,
5070 0,
5071 0,
5072 ]
5073 }
serialize_into(&self, bytes: &mut Vec<u8>)5074 fn serialize_into(&self, bytes: &mut Vec<u8>) {
5075 bytes.reserve(8);
5076 u8::from(self.type_).serialize_into(bytes);
5077 self.flags.serialize_into(bytes);
5078 self.count.serialize_into(bytes);
5079 self.button.serialize_into(bytes);
5080 self.device.serialize_into(bytes);
5081 bytes.extend_from_slice(&[0; 3]);
5082 }
5083 }
5084
5085 #[derive(Clone, Copy, PartialEq, Eq)]
5086 pub struct LockDeviceFlags(u8);
5087 impl LockDeviceFlags {
5088 pub const NO_LOCK: Self = Self(1 << 0);
5089 pub const NO_UNLOCK: Self = Self(1 << 1);
5090 }
5091 impl From<LockDeviceFlags> for u8 {
5092 #[inline]
from(input: LockDeviceFlags) -> Self5093 fn from(input: LockDeviceFlags) -> Self {
5094 input.0
5095 }
5096 }
5097 impl From<LockDeviceFlags> for Option<u8> {
5098 #[inline]
from(input: LockDeviceFlags) -> Self5099 fn from(input: LockDeviceFlags) -> Self {
5100 Some(input.0)
5101 }
5102 }
5103 impl From<LockDeviceFlags> for u16 {
5104 #[inline]
from(input: LockDeviceFlags) -> Self5105 fn from(input: LockDeviceFlags) -> Self {
5106 u16::from(input.0)
5107 }
5108 }
5109 impl From<LockDeviceFlags> for Option<u16> {
5110 #[inline]
from(input: LockDeviceFlags) -> Self5111 fn from(input: LockDeviceFlags) -> Self {
5112 Some(u16::from(input.0))
5113 }
5114 }
5115 impl From<LockDeviceFlags> for u32 {
5116 #[inline]
from(input: LockDeviceFlags) -> Self5117 fn from(input: LockDeviceFlags) -> Self {
5118 u32::from(input.0)
5119 }
5120 }
5121 impl From<LockDeviceFlags> for Option<u32> {
5122 #[inline]
from(input: LockDeviceFlags) -> Self5123 fn from(input: LockDeviceFlags) -> Self {
5124 Some(u32::from(input.0))
5125 }
5126 }
5127 impl From<u8> for LockDeviceFlags {
5128 #[inline]
from(value: u8) -> Self5129 fn from(value: u8) -> Self {
5130 Self(value)
5131 }
5132 }
5133 impl std::fmt::Debug for LockDeviceFlags {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result5134 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5135 let variants = [
5136 (Self::NO_LOCK.0.into(), "NO_LOCK", "NoLock"),
5137 (Self::NO_UNLOCK.0.into(), "NO_UNLOCK", "NoUnlock"),
5138 ];
5139 pretty_print_bitmask(fmt, self.0.into(), &variants)
5140 }
5141 }
5142 bitmask_binop!(LockDeviceFlags, u8);
5143
5144 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
5145 pub struct SALockDeviceBtn {
5146 pub type_: SAType,
5147 pub flags: u8,
5148 pub button: u8,
5149 pub device: u8,
5150 }
5151 impl TryParse for SALockDeviceBtn {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>5152 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
5153 let (type_, remaining) = u8::try_parse(remaining)?;
5154 let (flags, remaining) = u8::try_parse(remaining)?;
5155 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
5156 let (button, remaining) = u8::try_parse(remaining)?;
5157 let (device, remaining) = u8::try_parse(remaining)?;
5158 let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?;
5159 let type_ = type_.into();
5160 let result = SALockDeviceBtn { type_, flags, button, device };
5161 Ok((result, remaining))
5162 }
5163 }
5164 impl Serialize for SALockDeviceBtn {
5165 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]5166 fn serialize(&self) -> [u8; 8] {
5167 let type_bytes = u8::from(self.type_).serialize();
5168 let flags_bytes = self.flags.serialize();
5169 let button_bytes = self.button.serialize();
5170 let device_bytes = self.device.serialize();
5171 [
5172 type_bytes[0],
5173 flags_bytes[0],
5174 0,
5175 button_bytes[0],
5176 device_bytes[0],
5177 0,
5178 0,
5179 0,
5180 ]
5181 }
serialize_into(&self, bytes: &mut Vec<u8>)5182 fn serialize_into(&self, bytes: &mut Vec<u8>) {
5183 bytes.reserve(8);
5184 u8::from(self.type_).serialize_into(bytes);
5185 self.flags.serialize_into(bytes);
5186 bytes.extend_from_slice(&[0; 1]);
5187 self.button.serialize_into(bytes);
5188 self.device.serialize_into(bytes);
5189 bytes.extend_from_slice(&[0; 3]);
5190 }
5191 }
5192
5193 #[derive(Clone, Copy, PartialEq, Eq)]
5194 pub struct SAValWhat(u8);
5195 impl SAValWhat {
5196 pub const IGNORE_VAL: Self = Self(0);
5197 pub const SET_VAL_MIN: Self = Self(1);
5198 pub const SET_VAL_CENTER: Self = Self(2);
5199 pub const SET_VAL_MAX: Self = Self(3);
5200 pub const SET_VAL_RELATIVE: Self = Self(4);
5201 pub const SET_VAL_ABSOLUTE: Self = Self(5);
5202 }
5203 impl From<SAValWhat> for u8 {
5204 #[inline]
from(input: SAValWhat) -> Self5205 fn from(input: SAValWhat) -> Self {
5206 input.0
5207 }
5208 }
5209 impl From<SAValWhat> for Option<u8> {
5210 #[inline]
from(input: SAValWhat) -> Self5211 fn from(input: SAValWhat) -> Self {
5212 Some(input.0)
5213 }
5214 }
5215 impl From<SAValWhat> for u16 {
5216 #[inline]
from(input: SAValWhat) -> Self5217 fn from(input: SAValWhat) -> Self {
5218 u16::from(input.0)
5219 }
5220 }
5221 impl From<SAValWhat> for Option<u16> {
5222 #[inline]
from(input: SAValWhat) -> Self5223 fn from(input: SAValWhat) -> Self {
5224 Some(u16::from(input.0))
5225 }
5226 }
5227 impl From<SAValWhat> for u32 {
5228 #[inline]
from(input: SAValWhat) -> Self5229 fn from(input: SAValWhat) -> Self {
5230 u32::from(input.0)
5231 }
5232 }
5233 impl From<SAValWhat> for Option<u32> {
5234 #[inline]
from(input: SAValWhat) -> Self5235 fn from(input: SAValWhat) -> Self {
5236 Some(u32::from(input.0))
5237 }
5238 }
5239 impl From<u8> for SAValWhat {
5240 #[inline]
from(value: u8) -> Self5241 fn from(value: u8) -> Self {
5242 Self(value)
5243 }
5244 }
5245 impl std::fmt::Debug for SAValWhat {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result5246 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5247 let variants = [
5248 (Self::IGNORE_VAL.0.into(), "IGNORE_VAL", "IgnoreVal"),
5249 (Self::SET_VAL_MIN.0.into(), "SET_VAL_MIN", "SetValMin"),
5250 (Self::SET_VAL_CENTER.0.into(), "SET_VAL_CENTER", "SetValCenter"),
5251 (Self::SET_VAL_MAX.0.into(), "SET_VAL_MAX", "SetValMax"),
5252 (Self::SET_VAL_RELATIVE.0.into(), "SET_VAL_RELATIVE", "SetValRelative"),
5253 (Self::SET_VAL_ABSOLUTE.0.into(), "SET_VAL_ABSOLUTE", "SetValAbsolute"),
5254 ];
5255 pretty_print_enum(fmt, self.0.into(), &variants)
5256 }
5257 }
5258
5259 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
5260 pub struct SADeviceValuator {
5261 pub type_: SAType,
5262 pub device: u8,
5263 pub val1what: SAValWhat,
5264 pub val1index: u8,
5265 pub val1value: u8,
5266 pub val2what: SAValWhat,
5267 pub val2index: u8,
5268 pub val2value: u8,
5269 }
5270 impl TryParse for SADeviceValuator {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>5271 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
5272 let (type_, remaining) = u8::try_parse(remaining)?;
5273 let (device, remaining) = u8::try_parse(remaining)?;
5274 let (val1what, remaining) = u8::try_parse(remaining)?;
5275 let (val1index, remaining) = u8::try_parse(remaining)?;
5276 let (val1value, remaining) = u8::try_parse(remaining)?;
5277 let (val2what, remaining) = u8::try_parse(remaining)?;
5278 let (val2index, remaining) = u8::try_parse(remaining)?;
5279 let (val2value, remaining) = u8::try_parse(remaining)?;
5280 let type_ = type_.into();
5281 let val1what = val1what.into();
5282 let val2what = val2what.into();
5283 let result = SADeviceValuator { type_, device, val1what, val1index, val1value, val2what, val2index, val2value };
5284 Ok((result, remaining))
5285 }
5286 }
5287 impl Serialize for SADeviceValuator {
5288 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]5289 fn serialize(&self) -> [u8; 8] {
5290 let type_bytes = u8::from(self.type_).serialize();
5291 let device_bytes = self.device.serialize();
5292 let val1what_bytes = u8::from(self.val1what).serialize();
5293 let val1index_bytes = self.val1index.serialize();
5294 let val1value_bytes = self.val1value.serialize();
5295 let val2what_bytes = u8::from(self.val2what).serialize();
5296 let val2index_bytes = self.val2index.serialize();
5297 let val2value_bytes = self.val2value.serialize();
5298 [
5299 type_bytes[0],
5300 device_bytes[0],
5301 val1what_bytes[0],
5302 val1index_bytes[0],
5303 val1value_bytes[0],
5304 val2what_bytes[0],
5305 val2index_bytes[0],
5306 val2value_bytes[0],
5307 ]
5308 }
serialize_into(&self, bytes: &mut Vec<u8>)5309 fn serialize_into(&self, bytes: &mut Vec<u8>) {
5310 bytes.reserve(8);
5311 u8::from(self.type_).serialize_into(bytes);
5312 self.device.serialize_into(bytes);
5313 u8::from(self.val1what).serialize_into(bytes);
5314 self.val1index.serialize_into(bytes);
5315 self.val1value.serialize_into(bytes);
5316 u8::from(self.val2what).serialize_into(bytes);
5317 self.val2index.serialize_into(bytes);
5318 self.val2value.serialize_into(bytes);
5319 }
5320 }
5321
5322 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
5323 pub struct SIAction {
5324 pub type_: SAType,
5325 pub data: [u8; 7],
5326 }
5327 impl TryParse for SIAction {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>5328 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
5329 let (type_, remaining) = u8::try_parse(remaining)?;
5330 let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, 7)?;
5331 let data = <[u8; 7]>::try_from(data).unwrap();
5332 let type_ = type_.into();
5333 let result = SIAction { type_, data };
5334 Ok((result, remaining))
5335 }
5336 }
5337 impl Serialize for SIAction {
5338 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]5339 fn serialize(&self) -> [u8; 8] {
5340 let type_bytes = u8::from(self.type_).serialize();
5341 [
5342 type_bytes[0],
5343 self.data[0],
5344 self.data[1],
5345 self.data[2],
5346 self.data[3],
5347 self.data[4],
5348 self.data[5],
5349 self.data[6],
5350 ]
5351 }
serialize_into(&self, bytes: &mut Vec<u8>)5352 fn serialize_into(&self, bytes: &mut Vec<u8>) {
5353 bytes.reserve(8);
5354 u8::from(self.type_).serialize_into(bytes);
5355 bytes.extend_from_slice(&self.data);
5356 }
5357 }
5358
5359 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
5360 pub struct SymInterpret {
5361 pub sym: xproto::Keysym,
5362 pub mods: u8,
5363 pub match_: u8,
5364 pub virtual_mod: u8,
5365 pub flags: u8,
5366 pub action: SIAction,
5367 }
5368 impl TryParse for SymInterpret {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>5369 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
5370 let (sym, remaining) = xproto::Keysym::try_parse(remaining)?;
5371 let (mods, remaining) = u8::try_parse(remaining)?;
5372 let (match_, remaining) = u8::try_parse(remaining)?;
5373 let (virtual_mod, remaining) = u8::try_parse(remaining)?;
5374 let (flags, remaining) = u8::try_parse(remaining)?;
5375 let (action, remaining) = SIAction::try_parse(remaining)?;
5376 let result = SymInterpret { sym, mods, match_, virtual_mod, flags, action };
5377 Ok((result, remaining))
5378 }
5379 }
5380 impl Serialize for SymInterpret {
5381 type Bytes = [u8; 16];
serialize(&self) -> [u8; 16]5382 fn serialize(&self) -> [u8; 16] {
5383 let sym_bytes = self.sym.serialize();
5384 let mods_bytes = self.mods.serialize();
5385 let match_bytes = self.match_.serialize();
5386 let virtual_mod_bytes = self.virtual_mod.serialize();
5387 let flags_bytes = self.flags.serialize();
5388 let action_bytes = self.action.serialize();
5389 [
5390 sym_bytes[0],
5391 sym_bytes[1],
5392 sym_bytes[2],
5393 sym_bytes[3],
5394 mods_bytes[0],
5395 match_bytes[0],
5396 virtual_mod_bytes[0],
5397 flags_bytes[0],
5398 action_bytes[0],
5399 action_bytes[1],
5400 action_bytes[2],
5401 action_bytes[3],
5402 action_bytes[4],
5403 action_bytes[5],
5404 action_bytes[6],
5405 action_bytes[7],
5406 ]
5407 }
serialize_into(&self, bytes: &mut Vec<u8>)5408 fn serialize_into(&self, bytes: &mut Vec<u8>) {
5409 bytes.reserve(16);
5410 self.sym.serialize_into(bytes);
5411 self.mods.serialize_into(bytes);
5412 self.match_.serialize_into(bytes);
5413 self.virtual_mod.serialize_into(bytes);
5414 self.flags.serialize_into(bytes);
5415 self.action.serialize_into(bytes);
5416 }
5417 }
5418
5419 #[derive(Debug, Copy, Clone)]
5420 pub struct Action([u8; 8]);
5421 impl Action {
as_noaction(&self) -> SANoAction5422 pub fn as_noaction(&self) -> SANoAction {
5423 fn do_the_parse(remaining: &[u8]) -> Result<SANoAction, ParseError> {
5424 let (noaction, remaining) = SANoAction::try_parse(remaining)?;
5425 let _ = remaining;
5426 Ok(noaction)
5427 }
5428 do_the_parse(&self.0).unwrap()
5429 }
as_setmods(&self) -> SASetMods5430 pub fn as_setmods(&self) -> SASetMods {
5431 fn do_the_parse(remaining: &[u8]) -> Result<SASetMods, ParseError> {
5432 let (setmods, remaining) = SASetMods::try_parse(remaining)?;
5433 let _ = remaining;
5434 Ok(setmods)
5435 }
5436 do_the_parse(&self.0).unwrap()
5437 }
as_latchmods(&self) -> SALatchMods5438 pub fn as_latchmods(&self) -> SALatchMods {
5439 fn do_the_parse(remaining: &[u8]) -> Result<SALatchMods, ParseError> {
5440 let (latchmods, remaining) = SALatchMods::try_parse(remaining)?;
5441 let _ = remaining;
5442 Ok(latchmods)
5443 }
5444 do_the_parse(&self.0).unwrap()
5445 }
as_lockmods(&self) -> SALockMods5446 pub fn as_lockmods(&self) -> SALockMods {
5447 fn do_the_parse(remaining: &[u8]) -> Result<SALockMods, ParseError> {
5448 let (lockmods, remaining) = SALockMods::try_parse(remaining)?;
5449 let _ = remaining;
5450 Ok(lockmods)
5451 }
5452 do_the_parse(&self.0).unwrap()
5453 }
as_setgroup(&self) -> SASetGroup5454 pub fn as_setgroup(&self) -> SASetGroup {
5455 fn do_the_parse(remaining: &[u8]) -> Result<SASetGroup, ParseError> {
5456 let (setgroup, remaining) = SASetGroup::try_parse(remaining)?;
5457 let _ = remaining;
5458 Ok(setgroup)
5459 }
5460 do_the_parse(&self.0).unwrap()
5461 }
as_latchgroup(&self) -> SALatchGroup5462 pub fn as_latchgroup(&self) -> SALatchGroup {
5463 fn do_the_parse(remaining: &[u8]) -> Result<SALatchGroup, ParseError> {
5464 let (latchgroup, remaining) = SALatchGroup::try_parse(remaining)?;
5465 let _ = remaining;
5466 Ok(latchgroup)
5467 }
5468 do_the_parse(&self.0).unwrap()
5469 }
as_lockgroup(&self) -> SALockGroup5470 pub fn as_lockgroup(&self) -> SALockGroup {
5471 fn do_the_parse(remaining: &[u8]) -> Result<SALockGroup, ParseError> {
5472 let (lockgroup, remaining) = SALockGroup::try_parse(remaining)?;
5473 let _ = remaining;
5474 Ok(lockgroup)
5475 }
5476 do_the_parse(&self.0).unwrap()
5477 }
as_moveptr(&self) -> SAMovePtr5478 pub fn as_moveptr(&self) -> SAMovePtr {
5479 fn do_the_parse(remaining: &[u8]) -> Result<SAMovePtr, ParseError> {
5480 let (moveptr, remaining) = SAMovePtr::try_parse(remaining)?;
5481 let _ = remaining;
5482 Ok(moveptr)
5483 }
5484 do_the_parse(&self.0).unwrap()
5485 }
as_ptrbtn(&self) -> SAPtrBtn5486 pub fn as_ptrbtn(&self) -> SAPtrBtn {
5487 fn do_the_parse(remaining: &[u8]) -> Result<SAPtrBtn, ParseError> {
5488 let (ptrbtn, remaining) = SAPtrBtn::try_parse(remaining)?;
5489 let _ = remaining;
5490 Ok(ptrbtn)
5491 }
5492 do_the_parse(&self.0).unwrap()
5493 }
as_lockptrbtn(&self) -> SALockPtrBtn5494 pub fn as_lockptrbtn(&self) -> SALockPtrBtn {
5495 fn do_the_parse(remaining: &[u8]) -> Result<SALockPtrBtn, ParseError> {
5496 let (lockptrbtn, remaining) = SALockPtrBtn::try_parse(remaining)?;
5497 let _ = remaining;
5498 Ok(lockptrbtn)
5499 }
5500 do_the_parse(&self.0).unwrap()
5501 }
as_setptrdflt(&self) -> SASetPtrDflt5502 pub fn as_setptrdflt(&self) -> SASetPtrDflt {
5503 fn do_the_parse(remaining: &[u8]) -> Result<SASetPtrDflt, ParseError> {
5504 let (setptrdflt, remaining) = SASetPtrDflt::try_parse(remaining)?;
5505 let _ = remaining;
5506 Ok(setptrdflt)
5507 }
5508 do_the_parse(&self.0).unwrap()
5509 }
as_isolock(&self) -> SAIsoLock5510 pub fn as_isolock(&self) -> SAIsoLock {
5511 fn do_the_parse(remaining: &[u8]) -> Result<SAIsoLock, ParseError> {
5512 let (isolock, remaining) = SAIsoLock::try_parse(remaining)?;
5513 let _ = remaining;
5514 Ok(isolock)
5515 }
5516 do_the_parse(&self.0).unwrap()
5517 }
as_terminate(&self) -> SATerminate5518 pub fn as_terminate(&self) -> SATerminate {
5519 fn do_the_parse(remaining: &[u8]) -> Result<SATerminate, ParseError> {
5520 let (terminate, remaining) = SATerminate::try_parse(remaining)?;
5521 let _ = remaining;
5522 Ok(terminate)
5523 }
5524 do_the_parse(&self.0).unwrap()
5525 }
as_switchscreen(&self) -> SASwitchScreen5526 pub fn as_switchscreen(&self) -> SASwitchScreen {
5527 fn do_the_parse(remaining: &[u8]) -> Result<SASwitchScreen, ParseError> {
5528 let (switchscreen, remaining) = SASwitchScreen::try_parse(remaining)?;
5529 let _ = remaining;
5530 Ok(switchscreen)
5531 }
5532 do_the_parse(&self.0).unwrap()
5533 }
as_setcontrols(&self) -> SASetControls5534 pub fn as_setcontrols(&self) -> SASetControls {
5535 fn do_the_parse(remaining: &[u8]) -> Result<SASetControls, ParseError> {
5536 let (setcontrols, remaining) = SASetControls::try_parse(remaining)?;
5537 let _ = remaining;
5538 Ok(setcontrols)
5539 }
5540 do_the_parse(&self.0).unwrap()
5541 }
as_lockcontrols(&self) -> SALockControls5542 pub fn as_lockcontrols(&self) -> SALockControls {
5543 fn do_the_parse(remaining: &[u8]) -> Result<SALockControls, ParseError> {
5544 let (lockcontrols, remaining) = SALockControls::try_parse(remaining)?;
5545 let _ = remaining;
5546 Ok(lockcontrols)
5547 }
5548 do_the_parse(&self.0).unwrap()
5549 }
as_message(&self) -> SAActionMessage5550 pub fn as_message(&self) -> SAActionMessage {
5551 fn do_the_parse(remaining: &[u8]) -> Result<SAActionMessage, ParseError> {
5552 let (message, remaining) = SAActionMessage::try_parse(remaining)?;
5553 let _ = remaining;
5554 Ok(message)
5555 }
5556 do_the_parse(&self.0).unwrap()
5557 }
as_redirect(&self) -> SARedirectKey5558 pub fn as_redirect(&self) -> SARedirectKey {
5559 fn do_the_parse(remaining: &[u8]) -> Result<SARedirectKey, ParseError> {
5560 let (redirect, remaining) = SARedirectKey::try_parse(remaining)?;
5561 let _ = remaining;
5562 Ok(redirect)
5563 }
5564 do_the_parse(&self.0).unwrap()
5565 }
as_devbtn(&self) -> SADeviceBtn5566 pub fn as_devbtn(&self) -> SADeviceBtn {
5567 fn do_the_parse(remaining: &[u8]) -> Result<SADeviceBtn, ParseError> {
5568 let (devbtn, remaining) = SADeviceBtn::try_parse(remaining)?;
5569 let _ = remaining;
5570 Ok(devbtn)
5571 }
5572 do_the_parse(&self.0).unwrap()
5573 }
as_lockdevbtn(&self) -> SALockDeviceBtn5574 pub fn as_lockdevbtn(&self) -> SALockDeviceBtn {
5575 fn do_the_parse(remaining: &[u8]) -> Result<SALockDeviceBtn, ParseError> {
5576 let (lockdevbtn, remaining) = SALockDeviceBtn::try_parse(remaining)?;
5577 let _ = remaining;
5578 Ok(lockdevbtn)
5579 }
5580 do_the_parse(&self.0).unwrap()
5581 }
as_devval(&self) -> SADeviceValuator5582 pub fn as_devval(&self) -> SADeviceValuator {
5583 fn do_the_parse(remaining: &[u8]) -> Result<SADeviceValuator, ParseError> {
5584 let (devval, remaining) = SADeviceValuator::try_parse(remaining)?;
5585 let _ = remaining;
5586 Ok(devval)
5587 }
5588 do_the_parse(&self.0).unwrap()
5589 }
as_type(&self) -> SAType5590 pub fn as_type(&self) -> SAType {
5591 fn do_the_parse(remaining: &[u8]) -> Result<SAType, ParseError> {
5592 let (type_, remaining) = u8::try_parse(remaining)?;
5593 let type_ = type_.into();
5594 let _ = remaining;
5595 Ok(type_)
5596 }
5597 do_the_parse(&self.0).unwrap()
5598 }
5599 }
5600 impl Serialize for Action {
5601 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]5602 fn serialize(&self) -> [u8; 8] {
5603 self.0
5604 }
serialize_into(&self, bytes: &mut Vec<u8>)5605 fn serialize_into(&self, bytes: &mut Vec<u8>) {
5606 bytes.extend_from_slice(&self.0);
5607 }
5608 }
5609 impl TryParse for Action {
try_parse(value: &[u8]) -> Result<(Self, &[u8]), ParseError>5610 fn try_parse(value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
5611 let inner: [u8; 8] = value.get(..8)
5612 .ok_or(ParseError::InsufficientData)?
5613 .try_into()
5614 .unwrap();
5615 let result = Action(inner);
5616 Ok((result, &value[8..]))
5617 }
5618 }
5619 impl From<SANoAction> for Action {
from(noaction: SANoAction) -> Self5620 fn from(noaction: SANoAction) -> Self {
5621 let noaction_bytes = noaction.serialize();
5622 Self(noaction_bytes)
5623 }
5624 }
5625 impl From<SASetMods> for Action {
from(setmods: SASetMods) -> Self5626 fn from(setmods: SASetMods) -> Self {
5627 let setmods_bytes = setmods.serialize();
5628 Self(setmods_bytes)
5629 }
5630 }
5631 impl From<SASetGroup> for Action {
from(setgroup: SASetGroup) -> Self5632 fn from(setgroup: SASetGroup) -> Self {
5633 let setgroup_bytes = setgroup.serialize();
5634 Self(setgroup_bytes)
5635 }
5636 }
5637 impl From<SAMovePtr> for Action {
from(moveptr: SAMovePtr) -> Self5638 fn from(moveptr: SAMovePtr) -> Self {
5639 let moveptr_bytes = moveptr.serialize();
5640 Self(moveptr_bytes)
5641 }
5642 }
5643 impl From<SAPtrBtn> for Action {
from(ptrbtn: SAPtrBtn) -> Self5644 fn from(ptrbtn: SAPtrBtn) -> Self {
5645 let ptrbtn_bytes = ptrbtn.serialize();
5646 Self(ptrbtn_bytes)
5647 }
5648 }
5649 impl From<SALockPtrBtn> for Action {
from(lockptrbtn: SALockPtrBtn) -> Self5650 fn from(lockptrbtn: SALockPtrBtn) -> Self {
5651 let lockptrbtn_bytes = lockptrbtn.serialize();
5652 Self(lockptrbtn_bytes)
5653 }
5654 }
5655 impl From<SASetPtrDflt> for Action {
from(setptrdflt: SASetPtrDflt) -> Self5656 fn from(setptrdflt: SASetPtrDflt) -> Self {
5657 let setptrdflt_bytes = setptrdflt.serialize();
5658 Self(setptrdflt_bytes)
5659 }
5660 }
5661 impl From<SAIsoLock> for Action {
from(isolock: SAIsoLock) -> Self5662 fn from(isolock: SAIsoLock) -> Self {
5663 let isolock_bytes = isolock.serialize();
5664 Self(isolock_bytes)
5665 }
5666 }
5667 impl From<SATerminate> for Action {
from(terminate: SATerminate) -> Self5668 fn from(terminate: SATerminate) -> Self {
5669 let terminate_bytes = terminate.serialize();
5670 Self(terminate_bytes)
5671 }
5672 }
5673 impl From<SASwitchScreen> for Action {
from(switchscreen: SASwitchScreen) -> Self5674 fn from(switchscreen: SASwitchScreen) -> Self {
5675 let switchscreen_bytes = switchscreen.serialize();
5676 Self(switchscreen_bytes)
5677 }
5678 }
5679 impl From<SASetControls> for Action {
from(setcontrols: SASetControls) -> Self5680 fn from(setcontrols: SASetControls) -> Self {
5681 let setcontrols_bytes = setcontrols.serialize();
5682 Self(setcontrols_bytes)
5683 }
5684 }
5685 impl From<SAActionMessage> for Action {
from(message: SAActionMessage) -> Self5686 fn from(message: SAActionMessage) -> Self {
5687 let message_bytes = message.serialize();
5688 Self(message_bytes)
5689 }
5690 }
5691 impl From<SARedirectKey> for Action {
from(redirect: SARedirectKey) -> Self5692 fn from(redirect: SARedirectKey) -> Self {
5693 let redirect_bytes = redirect.serialize();
5694 Self(redirect_bytes)
5695 }
5696 }
5697 impl From<SADeviceBtn> for Action {
from(devbtn: SADeviceBtn) -> Self5698 fn from(devbtn: SADeviceBtn) -> Self {
5699 let devbtn_bytes = devbtn.serialize();
5700 Self(devbtn_bytes)
5701 }
5702 }
5703 impl From<SALockDeviceBtn> for Action {
from(lockdevbtn: SALockDeviceBtn) -> Self5704 fn from(lockdevbtn: SALockDeviceBtn) -> Self {
5705 let lockdevbtn_bytes = lockdevbtn.serialize();
5706 Self(lockdevbtn_bytes)
5707 }
5708 }
5709 impl From<SADeviceValuator> for Action {
from(devval: SADeviceValuator) -> Self5710 fn from(devval: SADeviceValuator) -> Self {
5711 let devval_bytes = devval.serialize();
5712 Self(devval_bytes)
5713 }
5714 }
5715 impl From<SAType> for Action {
from(type_: SAType) -> Self5716 fn from(type_: SAType) -> Self {
5717 let type_bytes = u8::from(type_).serialize();
5718 let value = [
5719 type_bytes[0],
5720 0,
5721 0,
5722 0,
5723 0,
5724 0,
5725 0,
5726 0,
5727 ];
5728 Self(value)
5729 }
5730 }
5731
5732 /// Opcode for the UseExtension request
5733 pub const USE_EXTENSION_REQUEST: u8 = 0;
5734 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
5735 pub struct UseExtensionRequest {
5736 pub wanted_major: u16,
5737 pub wanted_minor: u16,
5738 }
5739 impl UseExtensionRequest {
5740 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,5741 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
5742 where
5743 Conn: RequestConnection + ?Sized,
5744 {
5745 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
5746 .ok_or(ConnectionError::UnsupportedExtension)?;
5747 let length_so_far = 0;
5748 let wanted_major_bytes = self.wanted_major.serialize();
5749 let wanted_minor_bytes = self.wanted_minor.serialize();
5750 let mut request0 = vec![
5751 extension_information.major_opcode,
5752 USE_EXTENSION_REQUEST,
5753 0,
5754 0,
5755 wanted_major_bytes[0],
5756 wanted_major_bytes[1],
5757 wanted_minor_bytes[0],
5758 wanted_minor_bytes[1],
5759 ];
5760 let length_so_far = length_so_far + request0.len();
5761 assert_eq!(length_so_far % 4, 0);
5762 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
5763 request0[2..4].copy_from_slice(&length.to_ne_bytes());
5764 Ok((vec![request0.into()], vec![]))
5765 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, UseExtensionReply>, ConnectionError> where Conn: RequestConnection + ?Sized,5766 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, UseExtensionReply>, ConnectionError>
5767 where
5768 Conn: RequestConnection + ?Sized,
5769 {
5770 let (bytes, fds) = self.serialize(conn)?;
5771 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
5772 conn.send_request_with_reply(&slices, fds)
5773 }
5774 /// 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>5775 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
5776 if header.minor_opcode != USE_EXTENSION_REQUEST {
5777 return Err(ParseError::InvalidValue);
5778 }
5779 let (wanted_major, remaining) = u16::try_parse(value)?;
5780 let (wanted_minor, remaining) = u16::try_parse(remaining)?;
5781 let _ = remaining;
5782 Ok(UseExtensionRequest {
5783 wanted_major,
5784 wanted_minor,
5785 })
5786 }
5787 }
5788 impl Request for UseExtensionRequest {
5789 type Reply = UseExtensionReply;
5790 }
use_extension<Conn>(conn: &Conn, wanted_major: u16, wanted_minor: u16) -> Result<Cookie<'_, Conn, UseExtensionReply>, ConnectionError> where Conn: RequestConnection + ?Sized,5791 pub fn use_extension<Conn>(conn: &Conn, wanted_major: u16, wanted_minor: u16) -> Result<Cookie<'_, Conn, UseExtensionReply>, ConnectionError>
5792 where
5793 Conn: RequestConnection + ?Sized,
5794 {
5795 let request0 = UseExtensionRequest {
5796 wanted_major,
5797 wanted_minor,
5798 };
5799 request0.send(conn)
5800 }
5801
5802 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
5803 pub struct UseExtensionReply {
5804 pub supported: bool,
5805 pub sequence: u16,
5806 pub length: u32,
5807 pub server_major: u16,
5808 pub server_minor: u16,
5809 }
5810 impl TryParse for UseExtensionReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>5811 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
5812 let remaining = initial_value;
5813 let (response_type, remaining) = u8::try_parse(remaining)?;
5814 let (supported, remaining) = bool::try_parse(remaining)?;
5815 let (sequence, remaining) = u16::try_parse(remaining)?;
5816 let (length, remaining) = u32::try_parse(remaining)?;
5817 let (server_major, remaining) = u16::try_parse(remaining)?;
5818 let (server_minor, remaining) = u16::try_parse(remaining)?;
5819 let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
5820 if response_type != 1 {
5821 return Err(ParseError::InvalidValue);
5822 }
5823 let result = UseExtensionReply { supported, sequence, length, server_major, server_minor };
5824 let _ = remaining;
5825 let remaining = initial_value.get(32 + length as usize * 4..)
5826 .ok_or(ParseError::InsufficientData)?;
5827 Ok((result, remaining))
5828 }
5829 }
5830
5831 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
5832 pub struct SelectEventsAuxBitcase1 {
5833 pub affect_new_keyboard: u16,
5834 pub new_keyboard_details: u16,
5835 }
5836 impl TryParse for SelectEventsAuxBitcase1 {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>5837 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
5838 let (affect_new_keyboard, remaining) = u16::try_parse(remaining)?;
5839 let (new_keyboard_details, remaining) = u16::try_parse(remaining)?;
5840 let result = SelectEventsAuxBitcase1 { affect_new_keyboard, new_keyboard_details };
5841 Ok((result, remaining))
5842 }
5843 }
5844 impl Serialize for SelectEventsAuxBitcase1 {
5845 type Bytes = [u8; 4];
serialize(&self) -> [u8; 4]5846 fn serialize(&self) -> [u8; 4] {
5847 let affect_new_keyboard_bytes = self.affect_new_keyboard.serialize();
5848 let new_keyboard_details_bytes = self.new_keyboard_details.serialize();
5849 [
5850 affect_new_keyboard_bytes[0],
5851 affect_new_keyboard_bytes[1],
5852 new_keyboard_details_bytes[0],
5853 new_keyboard_details_bytes[1],
5854 ]
5855 }
serialize_into(&self, bytes: &mut Vec<u8>)5856 fn serialize_into(&self, bytes: &mut Vec<u8>) {
5857 bytes.reserve(4);
5858 self.affect_new_keyboard.serialize_into(bytes);
5859 self.new_keyboard_details.serialize_into(bytes);
5860 }
5861 }
5862 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
5863 pub struct SelectEventsAuxBitcase2 {
5864 pub affect_state: u16,
5865 pub state_details: u16,
5866 }
5867 impl TryParse for SelectEventsAuxBitcase2 {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>5868 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
5869 let (affect_state, remaining) = u16::try_parse(remaining)?;
5870 let (state_details, remaining) = u16::try_parse(remaining)?;
5871 let result = SelectEventsAuxBitcase2 { affect_state, state_details };
5872 Ok((result, remaining))
5873 }
5874 }
5875 impl Serialize for SelectEventsAuxBitcase2 {
5876 type Bytes = [u8; 4];
serialize(&self) -> [u8; 4]5877 fn serialize(&self) -> [u8; 4] {
5878 let affect_state_bytes = self.affect_state.serialize();
5879 let state_details_bytes = self.state_details.serialize();
5880 [
5881 affect_state_bytes[0],
5882 affect_state_bytes[1],
5883 state_details_bytes[0],
5884 state_details_bytes[1],
5885 ]
5886 }
serialize_into(&self, bytes: &mut Vec<u8>)5887 fn serialize_into(&self, bytes: &mut Vec<u8>) {
5888 bytes.reserve(4);
5889 self.affect_state.serialize_into(bytes);
5890 self.state_details.serialize_into(bytes);
5891 }
5892 }
5893 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
5894 pub struct SelectEventsAuxBitcase3 {
5895 pub affect_ctrls: u32,
5896 pub ctrl_details: u32,
5897 }
5898 impl TryParse for SelectEventsAuxBitcase3 {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>5899 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
5900 let (affect_ctrls, remaining) = u32::try_parse(remaining)?;
5901 let (ctrl_details, remaining) = u32::try_parse(remaining)?;
5902 let result = SelectEventsAuxBitcase3 { affect_ctrls, ctrl_details };
5903 Ok((result, remaining))
5904 }
5905 }
5906 impl Serialize for SelectEventsAuxBitcase3 {
5907 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]5908 fn serialize(&self) -> [u8; 8] {
5909 let affect_ctrls_bytes = self.affect_ctrls.serialize();
5910 let ctrl_details_bytes = self.ctrl_details.serialize();
5911 [
5912 affect_ctrls_bytes[0],
5913 affect_ctrls_bytes[1],
5914 affect_ctrls_bytes[2],
5915 affect_ctrls_bytes[3],
5916 ctrl_details_bytes[0],
5917 ctrl_details_bytes[1],
5918 ctrl_details_bytes[2],
5919 ctrl_details_bytes[3],
5920 ]
5921 }
serialize_into(&self, bytes: &mut Vec<u8>)5922 fn serialize_into(&self, bytes: &mut Vec<u8>) {
5923 bytes.reserve(8);
5924 self.affect_ctrls.serialize_into(bytes);
5925 self.ctrl_details.serialize_into(bytes);
5926 }
5927 }
5928 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
5929 pub struct SelectEventsAuxBitcase4 {
5930 pub affect_indicator_state: u32,
5931 pub indicator_state_details: u32,
5932 }
5933 impl TryParse for SelectEventsAuxBitcase4 {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>5934 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
5935 let (affect_indicator_state, remaining) = u32::try_parse(remaining)?;
5936 let (indicator_state_details, remaining) = u32::try_parse(remaining)?;
5937 let result = SelectEventsAuxBitcase4 { affect_indicator_state, indicator_state_details };
5938 Ok((result, remaining))
5939 }
5940 }
5941 impl Serialize for SelectEventsAuxBitcase4 {
5942 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]5943 fn serialize(&self) -> [u8; 8] {
5944 let affect_indicator_state_bytes = self.affect_indicator_state.serialize();
5945 let indicator_state_details_bytes = self.indicator_state_details.serialize();
5946 [
5947 affect_indicator_state_bytes[0],
5948 affect_indicator_state_bytes[1],
5949 affect_indicator_state_bytes[2],
5950 affect_indicator_state_bytes[3],
5951 indicator_state_details_bytes[0],
5952 indicator_state_details_bytes[1],
5953 indicator_state_details_bytes[2],
5954 indicator_state_details_bytes[3],
5955 ]
5956 }
serialize_into(&self, bytes: &mut Vec<u8>)5957 fn serialize_into(&self, bytes: &mut Vec<u8>) {
5958 bytes.reserve(8);
5959 self.affect_indicator_state.serialize_into(bytes);
5960 self.indicator_state_details.serialize_into(bytes);
5961 }
5962 }
5963 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
5964 pub struct SelectEventsAuxBitcase5 {
5965 pub affect_indicator_map: u32,
5966 pub indicator_map_details: u32,
5967 }
5968 impl TryParse for SelectEventsAuxBitcase5 {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>5969 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
5970 let (affect_indicator_map, remaining) = u32::try_parse(remaining)?;
5971 let (indicator_map_details, remaining) = u32::try_parse(remaining)?;
5972 let result = SelectEventsAuxBitcase5 { affect_indicator_map, indicator_map_details };
5973 Ok((result, remaining))
5974 }
5975 }
5976 impl Serialize for SelectEventsAuxBitcase5 {
5977 type Bytes = [u8; 8];
serialize(&self) -> [u8; 8]5978 fn serialize(&self) -> [u8; 8] {
5979 let affect_indicator_map_bytes = self.affect_indicator_map.serialize();
5980 let indicator_map_details_bytes = self.indicator_map_details.serialize();
5981 [
5982 affect_indicator_map_bytes[0],
5983 affect_indicator_map_bytes[1],
5984 affect_indicator_map_bytes[2],
5985 affect_indicator_map_bytes[3],
5986 indicator_map_details_bytes[0],
5987 indicator_map_details_bytes[1],
5988 indicator_map_details_bytes[2],
5989 indicator_map_details_bytes[3],
5990 ]
5991 }
serialize_into(&self, bytes: &mut Vec<u8>)5992 fn serialize_into(&self, bytes: &mut Vec<u8>) {
5993 bytes.reserve(8);
5994 self.affect_indicator_map.serialize_into(bytes);
5995 self.indicator_map_details.serialize_into(bytes);
5996 }
5997 }
5998 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
5999 pub struct SelectEventsAuxBitcase6 {
6000 pub affect_names: u16,
6001 pub names_details: u16,
6002 }
6003 impl TryParse for SelectEventsAuxBitcase6 {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>6004 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
6005 let (affect_names, remaining) = u16::try_parse(remaining)?;
6006 let (names_details, remaining) = u16::try_parse(remaining)?;
6007 let result = SelectEventsAuxBitcase6 { affect_names, names_details };
6008 Ok((result, remaining))
6009 }
6010 }
6011 impl Serialize for SelectEventsAuxBitcase6 {
6012 type Bytes = [u8; 4];
serialize(&self) -> [u8; 4]6013 fn serialize(&self) -> [u8; 4] {
6014 let affect_names_bytes = self.affect_names.serialize();
6015 let names_details_bytes = self.names_details.serialize();
6016 [
6017 affect_names_bytes[0],
6018 affect_names_bytes[1],
6019 names_details_bytes[0],
6020 names_details_bytes[1],
6021 ]
6022 }
serialize_into(&self, bytes: &mut Vec<u8>)6023 fn serialize_into(&self, bytes: &mut Vec<u8>) {
6024 bytes.reserve(4);
6025 self.affect_names.serialize_into(bytes);
6026 self.names_details.serialize_into(bytes);
6027 }
6028 }
6029 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
6030 pub struct SelectEventsAuxBitcase7 {
6031 pub affect_compat: u8,
6032 pub compat_details: u8,
6033 }
6034 impl TryParse for SelectEventsAuxBitcase7 {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>6035 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
6036 let (affect_compat, remaining) = u8::try_parse(remaining)?;
6037 let (compat_details, remaining) = u8::try_parse(remaining)?;
6038 let result = SelectEventsAuxBitcase7 { affect_compat, compat_details };
6039 Ok((result, remaining))
6040 }
6041 }
6042 impl Serialize for SelectEventsAuxBitcase7 {
6043 type Bytes = [u8; 2];
serialize(&self) -> [u8; 2]6044 fn serialize(&self) -> [u8; 2] {
6045 let affect_compat_bytes = self.affect_compat.serialize();
6046 let compat_details_bytes = self.compat_details.serialize();
6047 [
6048 affect_compat_bytes[0],
6049 compat_details_bytes[0],
6050 ]
6051 }
serialize_into(&self, bytes: &mut Vec<u8>)6052 fn serialize_into(&self, bytes: &mut Vec<u8>) {
6053 bytes.reserve(2);
6054 self.affect_compat.serialize_into(bytes);
6055 self.compat_details.serialize_into(bytes);
6056 }
6057 }
6058 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
6059 pub struct SelectEventsAuxBitcase8 {
6060 pub affect_bell: u8,
6061 pub bell_details: u8,
6062 }
6063 impl TryParse for SelectEventsAuxBitcase8 {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>6064 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
6065 let (affect_bell, remaining) = u8::try_parse(remaining)?;
6066 let (bell_details, remaining) = u8::try_parse(remaining)?;
6067 let result = SelectEventsAuxBitcase8 { affect_bell, bell_details };
6068 Ok((result, remaining))
6069 }
6070 }
6071 impl Serialize for SelectEventsAuxBitcase8 {
6072 type Bytes = [u8; 2];
serialize(&self) -> [u8; 2]6073 fn serialize(&self) -> [u8; 2] {
6074 let affect_bell_bytes = self.affect_bell.serialize();
6075 let bell_details_bytes = self.bell_details.serialize();
6076 [
6077 affect_bell_bytes[0],
6078 bell_details_bytes[0],
6079 ]
6080 }
serialize_into(&self, bytes: &mut Vec<u8>)6081 fn serialize_into(&self, bytes: &mut Vec<u8>) {
6082 bytes.reserve(2);
6083 self.affect_bell.serialize_into(bytes);
6084 self.bell_details.serialize_into(bytes);
6085 }
6086 }
6087 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
6088 pub struct SelectEventsAuxBitcase9 {
6089 pub affect_msg_details: u8,
6090 pub msg_details: u8,
6091 }
6092 impl TryParse for SelectEventsAuxBitcase9 {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>6093 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
6094 let (affect_msg_details, remaining) = u8::try_parse(remaining)?;
6095 let (msg_details, remaining) = u8::try_parse(remaining)?;
6096 let result = SelectEventsAuxBitcase9 { affect_msg_details, msg_details };
6097 Ok((result, remaining))
6098 }
6099 }
6100 impl Serialize for SelectEventsAuxBitcase9 {
6101 type Bytes = [u8; 2];
serialize(&self) -> [u8; 2]6102 fn serialize(&self) -> [u8; 2] {
6103 let affect_msg_details_bytes = self.affect_msg_details.serialize();
6104 let msg_details_bytes = self.msg_details.serialize();
6105 [
6106 affect_msg_details_bytes[0],
6107 msg_details_bytes[0],
6108 ]
6109 }
serialize_into(&self, bytes: &mut Vec<u8>)6110 fn serialize_into(&self, bytes: &mut Vec<u8>) {
6111 bytes.reserve(2);
6112 self.affect_msg_details.serialize_into(bytes);
6113 self.msg_details.serialize_into(bytes);
6114 }
6115 }
6116 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
6117 pub struct SelectEventsAuxBitcase10 {
6118 pub affect_access_x: u16,
6119 pub access_x_details: u16,
6120 }
6121 impl TryParse for SelectEventsAuxBitcase10 {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>6122 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
6123 let (affect_access_x, remaining) = u16::try_parse(remaining)?;
6124 let (access_x_details, remaining) = u16::try_parse(remaining)?;
6125 let result = SelectEventsAuxBitcase10 { affect_access_x, access_x_details };
6126 Ok((result, remaining))
6127 }
6128 }
6129 impl Serialize for SelectEventsAuxBitcase10 {
6130 type Bytes = [u8; 4];
serialize(&self) -> [u8; 4]6131 fn serialize(&self) -> [u8; 4] {
6132 let affect_access_x_bytes = self.affect_access_x.serialize();
6133 let access_x_details_bytes = self.access_x_details.serialize();
6134 [
6135 affect_access_x_bytes[0],
6136 affect_access_x_bytes[1],
6137 access_x_details_bytes[0],
6138 access_x_details_bytes[1],
6139 ]
6140 }
serialize_into(&self, bytes: &mut Vec<u8>)6141 fn serialize_into(&self, bytes: &mut Vec<u8>) {
6142 bytes.reserve(4);
6143 self.affect_access_x.serialize_into(bytes);
6144 self.access_x_details.serialize_into(bytes);
6145 }
6146 }
6147 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
6148 pub struct SelectEventsAuxBitcase11 {
6149 pub affect_ext_dev: u16,
6150 pub extdev_details: u16,
6151 }
6152 impl TryParse for SelectEventsAuxBitcase11 {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>6153 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
6154 let (affect_ext_dev, remaining) = u16::try_parse(remaining)?;
6155 let (extdev_details, remaining) = u16::try_parse(remaining)?;
6156 let result = SelectEventsAuxBitcase11 { affect_ext_dev, extdev_details };
6157 Ok((result, remaining))
6158 }
6159 }
6160 impl Serialize for SelectEventsAuxBitcase11 {
6161 type Bytes = [u8; 4];
serialize(&self) -> [u8; 4]6162 fn serialize(&self) -> [u8; 4] {
6163 let affect_ext_dev_bytes = self.affect_ext_dev.serialize();
6164 let extdev_details_bytes = self.extdev_details.serialize();
6165 [
6166 affect_ext_dev_bytes[0],
6167 affect_ext_dev_bytes[1],
6168 extdev_details_bytes[0],
6169 extdev_details_bytes[1],
6170 ]
6171 }
serialize_into(&self, bytes: &mut Vec<u8>)6172 fn serialize_into(&self, bytes: &mut Vec<u8>) {
6173 bytes.reserve(4);
6174 self.affect_ext_dev.serialize_into(bytes);
6175 self.extdev_details.serialize_into(bytes);
6176 }
6177 }
6178 /// Auxiliary and optional information for the `select_events` function
6179 #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
6180 pub struct SelectEventsAux {
6181 pub bitcase1: Option<SelectEventsAuxBitcase1>,
6182 pub bitcase2: Option<SelectEventsAuxBitcase2>,
6183 pub bitcase3: Option<SelectEventsAuxBitcase3>,
6184 pub bitcase4: Option<SelectEventsAuxBitcase4>,
6185 pub bitcase5: Option<SelectEventsAuxBitcase5>,
6186 pub bitcase6: Option<SelectEventsAuxBitcase6>,
6187 pub bitcase7: Option<SelectEventsAuxBitcase7>,
6188 pub bitcase8: Option<SelectEventsAuxBitcase8>,
6189 pub bitcase9: Option<SelectEventsAuxBitcase9>,
6190 pub bitcase10: Option<SelectEventsAuxBitcase10>,
6191 pub bitcase11: Option<SelectEventsAuxBitcase11>,
6192 }
6193 impl SelectEventsAux {
try_parse(value: &[u8], affect_which: u16, clear: u16, select_all: u16) -> Result<(Self, &[u8]), ParseError>6194 fn try_parse(value: &[u8], affect_which: u16, clear: u16, select_all: u16) -> Result<(Self, &[u8]), ParseError> {
6195 let switch_expr = u32::from(affect_which) & ((!u32::from(clear)) & (!u32::from(select_all)));
6196 let mut outer_remaining = value;
6197 let bitcase1 = if switch_expr & u32::from(EventType::NEW_KEYBOARD_NOTIFY) != 0 {
6198 let (bitcase1, new_remaining) = SelectEventsAuxBitcase1::try_parse(outer_remaining)?;
6199 outer_remaining = new_remaining;
6200 Some(bitcase1)
6201 } else {
6202 None
6203 };
6204 let bitcase2 = if switch_expr & u32::from(EventType::STATE_NOTIFY) != 0 {
6205 let (bitcase2, new_remaining) = SelectEventsAuxBitcase2::try_parse(outer_remaining)?;
6206 outer_remaining = new_remaining;
6207 Some(bitcase2)
6208 } else {
6209 None
6210 };
6211 let bitcase3 = if switch_expr & u32::from(EventType::CONTROLS_NOTIFY) != 0 {
6212 let (bitcase3, new_remaining) = SelectEventsAuxBitcase3::try_parse(outer_remaining)?;
6213 outer_remaining = new_remaining;
6214 Some(bitcase3)
6215 } else {
6216 None
6217 };
6218 let bitcase4 = if switch_expr & u32::from(EventType::INDICATOR_STATE_NOTIFY) != 0 {
6219 let (bitcase4, new_remaining) = SelectEventsAuxBitcase4::try_parse(outer_remaining)?;
6220 outer_remaining = new_remaining;
6221 Some(bitcase4)
6222 } else {
6223 None
6224 };
6225 let bitcase5 = if switch_expr & u32::from(EventType::INDICATOR_MAP_NOTIFY) != 0 {
6226 let (bitcase5, new_remaining) = SelectEventsAuxBitcase5::try_parse(outer_remaining)?;
6227 outer_remaining = new_remaining;
6228 Some(bitcase5)
6229 } else {
6230 None
6231 };
6232 let bitcase6 = if switch_expr & u32::from(EventType::NAMES_NOTIFY) != 0 {
6233 let (bitcase6, new_remaining) = SelectEventsAuxBitcase6::try_parse(outer_remaining)?;
6234 outer_remaining = new_remaining;
6235 Some(bitcase6)
6236 } else {
6237 None
6238 };
6239 let bitcase7 = if switch_expr & u32::from(EventType::COMPAT_MAP_NOTIFY) != 0 {
6240 let (bitcase7, new_remaining) = SelectEventsAuxBitcase7::try_parse(outer_remaining)?;
6241 outer_remaining = new_remaining;
6242 Some(bitcase7)
6243 } else {
6244 None
6245 };
6246 let bitcase8 = if switch_expr & u32::from(EventType::BELL_NOTIFY) != 0 {
6247 let (bitcase8, new_remaining) = SelectEventsAuxBitcase8::try_parse(outer_remaining)?;
6248 outer_remaining = new_remaining;
6249 Some(bitcase8)
6250 } else {
6251 None
6252 };
6253 let bitcase9 = if switch_expr & u32::from(EventType::ACTION_MESSAGE) != 0 {
6254 let (bitcase9, new_remaining) = SelectEventsAuxBitcase9::try_parse(outer_remaining)?;
6255 outer_remaining = new_remaining;
6256 Some(bitcase9)
6257 } else {
6258 None
6259 };
6260 let bitcase10 = if switch_expr & u32::from(EventType::ACCESS_X_NOTIFY) != 0 {
6261 let (bitcase10, new_remaining) = SelectEventsAuxBitcase10::try_parse(outer_remaining)?;
6262 outer_remaining = new_remaining;
6263 Some(bitcase10)
6264 } else {
6265 None
6266 };
6267 let bitcase11 = if switch_expr & u32::from(EventType::EXTENSION_DEVICE_NOTIFY) != 0 {
6268 let (bitcase11, new_remaining) = SelectEventsAuxBitcase11::try_parse(outer_remaining)?;
6269 outer_remaining = new_remaining;
6270 Some(bitcase11)
6271 } else {
6272 None
6273 };
6274 let result = SelectEventsAux { bitcase1, bitcase2, bitcase3, bitcase4, bitcase5, bitcase6, bitcase7, bitcase8, bitcase9, bitcase10, bitcase11 };
6275 Ok((result, outer_remaining))
6276 }
6277 }
6278 impl SelectEventsAux {
6279 #[allow(dead_code)]
serialize(&self, affect_which: u16, clear: u16, select_all: u16) -> Vec<u8>6280 fn serialize(&self, affect_which: u16, clear: u16, select_all: u16) -> Vec<u8> {
6281 let mut result = Vec::new();
6282 self.serialize_into(&mut result, affect_which, clear, select_all);
6283 result
6284 }
serialize_into(&self, bytes: &mut Vec<u8>, affect_which: u16, clear: u16, select_all: u16)6285 fn serialize_into(&self, bytes: &mut Vec<u8>, affect_which: u16, clear: u16, select_all: u16) {
6286 assert_eq!(self.switch_expr(), u32::from(affect_which) & ((!u32::from(clear)) & (!u32::from(select_all))), "switch `details` has an inconsistent discriminant");
6287 if let Some(ref bitcase1) = self.bitcase1 {
6288 bitcase1.serialize_into(bytes);
6289 }
6290 if let Some(ref bitcase2) = self.bitcase2 {
6291 bitcase2.serialize_into(bytes);
6292 }
6293 if let Some(ref bitcase3) = self.bitcase3 {
6294 bitcase3.serialize_into(bytes);
6295 }
6296 if let Some(ref bitcase4) = self.bitcase4 {
6297 bitcase4.serialize_into(bytes);
6298 }
6299 if let Some(ref bitcase5) = self.bitcase5 {
6300 bitcase5.serialize_into(bytes);
6301 }
6302 if let Some(ref bitcase6) = self.bitcase6 {
6303 bitcase6.serialize_into(bytes);
6304 }
6305 if let Some(ref bitcase7) = self.bitcase7 {
6306 bitcase7.serialize_into(bytes);
6307 }
6308 if let Some(ref bitcase8) = self.bitcase8 {
6309 bitcase8.serialize_into(bytes);
6310 }
6311 if let Some(ref bitcase9) = self.bitcase9 {
6312 bitcase9.serialize_into(bytes);
6313 }
6314 if let Some(ref bitcase10) = self.bitcase10 {
6315 bitcase10.serialize_into(bytes);
6316 }
6317 if let Some(ref bitcase11) = self.bitcase11 {
6318 bitcase11.serialize_into(bytes);
6319 }
6320 }
6321 }
6322 impl SelectEventsAux {
switch_expr(&self) -> u326323 fn switch_expr(&self) -> u32 {
6324 let mut expr_value = 0;
6325 if self.bitcase1.is_some() {
6326 expr_value |= u32::from(EventType::NEW_KEYBOARD_NOTIFY);
6327 }
6328 if self.bitcase2.is_some() {
6329 expr_value |= u32::from(EventType::STATE_NOTIFY);
6330 }
6331 if self.bitcase3.is_some() {
6332 expr_value |= u32::from(EventType::CONTROLS_NOTIFY);
6333 }
6334 if self.bitcase4.is_some() {
6335 expr_value |= u32::from(EventType::INDICATOR_STATE_NOTIFY);
6336 }
6337 if self.bitcase5.is_some() {
6338 expr_value |= u32::from(EventType::INDICATOR_MAP_NOTIFY);
6339 }
6340 if self.bitcase6.is_some() {
6341 expr_value |= u32::from(EventType::NAMES_NOTIFY);
6342 }
6343 if self.bitcase7.is_some() {
6344 expr_value |= u32::from(EventType::COMPAT_MAP_NOTIFY);
6345 }
6346 if self.bitcase8.is_some() {
6347 expr_value |= u32::from(EventType::BELL_NOTIFY);
6348 }
6349 if self.bitcase9.is_some() {
6350 expr_value |= u32::from(EventType::ACTION_MESSAGE);
6351 }
6352 if self.bitcase10.is_some() {
6353 expr_value |= u32::from(EventType::ACCESS_X_NOTIFY);
6354 }
6355 if self.bitcase11.is_some() {
6356 expr_value |= u32::from(EventType::EXTENSION_DEVICE_NOTIFY);
6357 }
6358 expr_value
6359 }
6360 }
6361 impl SelectEventsAux {
6362 /// Create a new instance with all fields unset / not present.
new() -> Self6363 pub fn new() -> Self {
6364 Default::default()
6365 }
6366 /// Set the `bitcase1` field of this structure.
bitcase1<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase1>>6367 pub fn bitcase1<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase1>> {
6368 self.bitcase1 = value.into();
6369 self
6370 }
6371 /// Set the `bitcase2` field of this structure.
bitcase2<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase2>>6372 pub fn bitcase2<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase2>> {
6373 self.bitcase2 = value.into();
6374 self
6375 }
6376 /// Set the `bitcase3` field of this structure.
bitcase3<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase3>>6377 pub fn bitcase3<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase3>> {
6378 self.bitcase3 = value.into();
6379 self
6380 }
6381 /// Set the `bitcase4` field of this structure.
bitcase4<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase4>>6382 pub fn bitcase4<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase4>> {
6383 self.bitcase4 = value.into();
6384 self
6385 }
6386 /// Set the `bitcase5` field of this structure.
bitcase5<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase5>>6387 pub fn bitcase5<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase5>> {
6388 self.bitcase5 = value.into();
6389 self
6390 }
6391 /// Set the `bitcase6` field of this structure.
bitcase6<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase6>>6392 pub fn bitcase6<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase6>> {
6393 self.bitcase6 = value.into();
6394 self
6395 }
6396 /// Set the `bitcase7` field of this structure.
bitcase7<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase7>>6397 pub fn bitcase7<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase7>> {
6398 self.bitcase7 = value.into();
6399 self
6400 }
6401 /// Set the `bitcase8` field of this structure.
bitcase8<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase8>>6402 pub fn bitcase8<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase8>> {
6403 self.bitcase8 = value.into();
6404 self
6405 }
6406 /// Set the `bitcase9` field of this structure.
bitcase9<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase9>>6407 pub fn bitcase9<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase9>> {
6408 self.bitcase9 = value.into();
6409 self
6410 }
6411 /// Set the `bitcase10` field of this structure.
bitcase10<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase10>>6412 pub fn bitcase10<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase10>> {
6413 self.bitcase10 = value.into();
6414 self
6415 }
6416 /// Set the `bitcase11` field of this structure.
bitcase11<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase11>>6417 pub fn bitcase11<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBitcase11>> {
6418 self.bitcase11 = value.into();
6419 self
6420 }
6421 }
6422
6423 /// Opcode for the SelectEvents request
6424 pub const SELECT_EVENTS_REQUEST: u8 = 1;
6425 #[derive(Debug, Clone, PartialEq, Eq)]
6426 pub struct SelectEventsRequest<'input> {
6427 pub device_spec: DeviceSpec,
6428 pub clear: u16,
6429 pub select_all: u16,
6430 pub affect_map: u16,
6431 pub map: u16,
6432 pub details: Cow<'input, SelectEventsAux>,
6433 }
6434 impl<'input> SelectEventsRequest<'input> {
6435 /// Serialize this request into bytes for the provided connection
serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,6436 fn serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
6437 where
6438 Conn: RequestConnection + ?Sized,
6439 {
6440 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
6441 .ok_or(ConnectionError::UnsupportedExtension)?;
6442 let length_so_far = 0;
6443 let device_spec_bytes = self.device_spec.serialize();
6444 let affect_which = u16::try_from(self.details.switch_expr() | (u32::from(self.clear) | u32::from(self.select_all))).unwrap();
6445 let affect_which_bytes = affect_which.serialize();
6446 let clear_bytes = self.clear.serialize();
6447 let select_all_bytes = self.select_all.serialize();
6448 let affect_map_bytes = self.affect_map.serialize();
6449 let map_bytes = self.map.serialize();
6450 let mut request0 = vec![
6451 extension_information.major_opcode,
6452 SELECT_EVENTS_REQUEST,
6453 0,
6454 0,
6455 device_spec_bytes[0],
6456 device_spec_bytes[1],
6457 affect_which_bytes[0],
6458 affect_which_bytes[1],
6459 clear_bytes[0],
6460 clear_bytes[1],
6461 select_all_bytes[0],
6462 select_all_bytes[1],
6463 affect_map_bytes[0],
6464 affect_map_bytes[1],
6465 map_bytes[0],
6466 map_bytes[1],
6467 ];
6468 let length_so_far = length_so_far + request0.len();
6469 let details_bytes = self.details.serialize(affect_which, self.clear, self.select_all);
6470 let length_so_far = length_so_far + details_bytes.len();
6471 let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
6472 let length_so_far = length_so_far + padding0.len();
6473 assert_eq!(length_so_far % 4, 0);
6474 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
6475 request0[2..4].copy_from_slice(&length.to_ne_bytes());
6476 Ok((vec![request0.into(), details_bytes.into(), padding0.into()], vec![]))
6477 }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,6478 pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
6479 where
6480 Conn: RequestConnection + ?Sized,
6481 {
6482 let (bytes, fds) = self.serialize(conn)?;
6483 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
6484 conn.send_request_without_reply(&slices, fds)
6485 }
6486 /// 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>6487 pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
6488 if header.minor_opcode != SELECT_EVENTS_REQUEST {
6489 return Err(ParseError::InvalidValue);
6490 }
6491 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
6492 let (affect_which, remaining) = u16::try_parse(remaining)?;
6493 let (clear, remaining) = u16::try_parse(remaining)?;
6494 let (select_all, remaining) = u16::try_parse(remaining)?;
6495 let (affect_map, remaining) = u16::try_parse(remaining)?;
6496 let (map, remaining) = u16::try_parse(remaining)?;
6497 let (details, remaining) = SelectEventsAux::try_parse(remaining, affect_which, clear, select_all)?;
6498 let _ = remaining;
6499 Ok(SelectEventsRequest {
6500 device_spec,
6501 clear,
6502 select_all,
6503 affect_map,
6504 map,
6505 details: Cow::Owned(details),
6506 })
6507 }
6508 /// Clone all borrowed data in this SelectEventsRequest.
into_owned(self) -> SelectEventsRequest<'static>6509 pub fn into_owned(self) -> SelectEventsRequest<'static> {
6510 SelectEventsRequest {
6511 device_spec: self.device_spec,
6512 clear: self.clear,
6513 select_all: self.select_all,
6514 affect_map: self.affect_map,
6515 map: self.map,
6516 details: Cow::Owned(self.details.into_owned()),
6517 }
6518 }
6519 }
6520 impl<'input> Request for SelectEventsRequest<'input> {
6521 type Reply = ();
6522 }
select_events<'c, 'input, Conn, A, B, C, D>(conn: &'c Conn, device_spec: DeviceSpec, clear: A, select_all: B, affect_map: C, map: D, details: &'input SelectEventsAux) -> Result<VoidCookie<'c, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<u16>, B: Into<u16>, C: Into<u16>, D: Into<u16>,6523 pub fn select_events<'c, 'input, Conn, A, B, C, D>(conn: &'c Conn, device_spec: DeviceSpec, clear: A, select_all: B, affect_map: C, map: D, details: &'input SelectEventsAux) -> Result<VoidCookie<'c, Conn>, ConnectionError>
6524 where
6525 Conn: RequestConnection + ?Sized,
6526 A: Into<u16>,
6527 B: Into<u16>,
6528 C: Into<u16>,
6529 D: Into<u16>,
6530 {
6531 let clear: u16 = clear.into();
6532 let select_all: u16 = select_all.into();
6533 let affect_map: u16 = affect_map.into();
6534 let map: u16 = map.into();
6535 let request0 = SelectEventsRequest {
6536 device_spec,
6537 clear,
6538 select_all,
6539 affect_map,
6540 map,
6541 details: Cow::Borrowed(details),
6542 };
6543 request0.send(conn)
6544 }
6545
6546 /// Opcode for the Bell request
6547 pub const BELL_REQUEST: u8 = 3;
6548 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
6549 pub struct BellRequest {
6550 pub device_spec: DeviceSpec,
6551 pub bell_class: BellClassSpec,
6552 pub bell_id: IDSpec,
6553 pub percent: i8,
6554 pub force_sound: bool,
6555 pub event_only: bool,
6556 pub pitch: i16,
6557 pub duration: i16,
6558 pub name: xproto::Atom,
6559 pub window: xproto::Window,
6560 }
6561 impl BellRequest {
6562 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,6563 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
6564 where
6565 Conn: RequestConnection + ?Sized,
6566 {
6567 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
6568 .ok_or(ConnectionError::UnsupportedExtension)?;
6569 let length_so_far = 0;
6570 let device_spec_bytes = self.device_spec.serialize();
6571 let bell_class_bytes = self.bell_class.serialize();
6572 let bell_id_bytes = self.bell_id.serialize();
6573 let percent_bytes = self.percent.serialize();
6574 let force_sound_bytes = self.force_sound.serialize();
6575 let event_only_bytes = self.event_only.serialize();
6576 let pitch_bytes = self.pitch.serialize();
6577 let duration_bytes = self.duration.serialize();
6578 let name_bytes = self.name.serialize();
6579 let window_bytes = self.window.serialize();
6580 let mut request0 = vec![
6581 extension_information.major_opcode,
6582 BELL_REQUEST,
6583 0,
6584 0,
6585 device_spec_bytes[0],
6586 device_spec_bytes[1],
6587 bell_class_bytes[0],
6588 bell_class_bytes[1],
6589 bell_id_bytes[0],
6590 bell_id_bytes[1],
6591 percent_bytes[0],
6592 force_sound_bytes[0],
6593 event_only_bytes[0],
6594 0,
6595 pitch_bytes[0],
6596 pitch_bytes[1],
6597 duration_bytes[0],
6598 duration_bytes[1],
6599 0,
6600 0,
6601 name_bytes[0],
6602 name_bytes[1],
6603 name_bytes[2],
6604 name_bytes[3],
6605 window_bytes[0],
6606 window_bytes[1],
6607 window_bytes[2],
6608 window_bytes[3],
6609 ];
6610 let length_so_far = length_so_far + request0.len();
6611 assert_eq!(length_so_far % 4, 0);
6612 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
6613 request0[2..4].copy_from_slice(&length.to_ne_bytes());
6614 Ok((vec![request0.into()], vec![]))
6615 }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,6616 pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
6617 where
6618 Conn: RequestConnection + ?Sized,
6619 {
6620 let (bytes, fds) = self.serialize(conn)?;
6621 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
6622 conn.send_request_without_reply(&slices, fds)
6623 }
6624 /// 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>6625 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
6626 if header.minor_opcode != BELL_REQUEST {
6627 return Err(ParseError::InvalidValue);
6628 }
6629 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
6630 let (bell_class, remaining) = BellClassSpec::try_parse(remaining)?;
6631 let (bell_id, remaining) = IDSpec::try_parse(remaining)?;
6632 let (percent, remaining) = i8::try_parse(remaining)?;
6633 let (force_sound, remaining) = bool::try_parse(remaining)?;
6634 let (event_only, remaining) = bool::try_parse(remaining)?;
6635 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
6636 let (pitch, remaining) = i16::try_parse(remaining)?;
6637 let (duration, remaining) = i16::try_parse(remaining)?;
6638 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
6639 let (name, remaining) = xproto::Atom::try_parse(remaining)?;
6640 let (window, remaining) = xproto::Window::try_parse(remaining)?;
6641 let _ = remaining;
6642 Ok(BellRequest {
6643 device_spec,
6644 bell_class,
6645 bell_id,
6646 percent,
6647 force_sound,
6648 event_only,
6649 pitch,
6650 duration,
6651 name,
6652 window,
6653 })
6654 }
6655 }
6656 impl Request for BellRequest {
6657 type Reply = ();
6658 }
bell<Conn>(conn: &Conn, device_spec: DeviceSpec, bell_class: BellClassSpec, bell_id: IDSpec, percent: i8, force_sound: bool, event_only: bool, pitch: i16, duration: i16, name: xproto::Atom, window: xproto::Window) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,6659 pub fn bell<Conn>(conn: &Conn, device_spec: DeviceSpec, bell_class: BellClassSpec, bell_id: IDSpec, percent: i8, force_sound: bool, event_only: bool, pitch: i16, duration: i16, name: xproto::Atom, window: xproto::Window) -> Result<VoidCookie<'_, Conn>, ConnectionError>
6660 where
6661 Conn: RequestConnection + ?Sized,
6662 {
6663 let request0 = BellRequest {
6664 device_spec,
6665 bell_class,
6666 bell_id,
6667 percent,
6668 force_sound,
6669 event_only,
6670 pitch,
6671 duration,
6672 name,
6673 window,
6674 };
6675 request0.send(conn)
6676 }
6677
6678 /// Opcode for the GetState request
6679 pub const GET_STATE_REQUEST: u8 = 4;
6680 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
6681 pub struct GetStateRequest {
6682 pub device_spec: DeviceSpec,
6683 }
6684 impl GetStateRequest {
6685 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,6686 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
6687 where
6688 Conn: RequestConnection + ?Sized,
6689 {
6690 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
6691 .ok_or(ConnectionError::UnsupportedExtension)?;
6692 let length_so_far = 0;
6693 let device_spec_bytes = self.device_spec.serialize();
6694 let mut request0 = vec![
6695 extension_information.major_opcode,
6696 GET_STATE_REQUEST,
6697 0,
6698 0,
6699 device_spec_bytes[0],
6700 device_spec_bytes[1],
6701 0,
6702 0,
6703 ];
6704 let length_so_far = length_so_far + request0.len();
6705 assert_eq!(length_so_far % 4, 0);
6706 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
6707 request0[2..4].copy_from_slice(&length.to_ne_bytes());
6708 Ok((vec![request0.into()], vec![]))
6709 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetStateReply>, ConnectionError> where Conn: RequestConnection + ?Sized,6710 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetStateReply>, ConnectionError>
6711 where
6712 Conn: RequestConnection + ?Sized,
6713 {
6714 let (bytes, fds) = self.serialize(conn)?;
6715 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
6716 conn.send_request_with_reply(&slices, fds)
6717 }
6718 /// 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>6719 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
6720 if header.minor_opcode != GET_STATE_REQUEST {
6721 return Err(ParseError::InvalidValue);
6722 }
6723 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
6724 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
6725 let _ = remaining;
6726 Ok(GetStateRequest {
6727 device_spec,
6728 })
6729 }
6730 }
6731 impl Request for GetStateRequest {
6732 type Reply = GetStateReply;
6733 }
get_state<Conn>(conn: &Conn, device_spec: DeviceSpec) -> Result<Cookie<'_, Conn, GetStateReply>, ConnectionError> where Conn: RequestConnection + ?Sized,6734 pub fn get_state<Conn>(conn: &Conn, device_spec: DeviceSpec) -> Result<Cookie<'_, Conn, GetStateReply>, ConnectionError>
6735 where
6736 Conn: RequestConnection + ?Sized,
6737 {
6738 let request0 = GetStateRequest {
6739 device_spec,
6740 };
6741 request0.send(conn)
6742 }
6743
6744 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
6745 pub struct GetStateReply {
6746 pub device_id: u8,
6747 pub sequence: u16,
6748 pub length: u32,
6749 pub mods: u8,
6750 pub base_mods: u8,
6751 pub latched_mods: u8,
6752 pub locked_mods: u8,
6753 pub group: Group,
6754 pub locked_group: Group,
6755 pub base_group: i16,
6756 pub latched_group: i16,
6757 pub compat_state: u8,
6758 pub grab_mods: u8,
6759 pub compat_grab_mods: u8,
6760 pub lookup_mods: u8,
6761 pub compat_lookup_mods: u8,
6762 pub ptr_btn_state: u16,
6763 }
6764 impl TryParse for GetStateReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>6765 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
6766 let remaining = initial_value;
6767 let (response_type, remaining) = u8::try_parse(remaining)?;
6768 let (device_id, remaining) = u8::try_parse(remaining)?;
6769 let (sequence, remaining) = u16::try_parse(remaining)?;
6770 let (length, remaining) = u32::try_parse(remaining)?;
6771 let (mods, remaining) = u8::try_parse(remaining)?;
6772 let (base_mods, remaining) = u8::try_parse(remaining)?;
6773 let (latched_mods, remaining) = u8::try_parse(remaining)?;
6774 let (locked_mods, remaining) = u8::try_parse(remaining)?;
6775 let (group, remaining) = u8::try_parse(remaining)?;
6776 let (locked_group, remaining) = u8::try_parse(remaining)?;
6777 let (base_group, remaining) = i16::try_parse(remaining)?;
6778 let (latched_group, remaining) = i16::try_parse(remaining)?;
6779 let (compat_state, remaining) = u8::try_parse(remaining)?;
6780 let (grab_mods, remaining) = u8::try_parse(remaining)?;
6781 let (compat_grab_mods, remaining) = u8::try_parse(remaining)?;
6782 let (lookup_mods, remaining) = u8::try_parse(remaining)?;
6783 let (compat_lookup_mods, remaining) = u8::try_parse(remaining)?;
6784 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
6785 let (ptr_btn_state, remaining) = u16::try_parse(remaining)?;
6786 let remaining = remaining.get(6..).ok_or(ParseError::InsufficientData)?;
6787 if response_type != 1 {
6788 return Err(ParseError::InvalidValue);
6789 }
6790 let group = group.into();
6791 let locked_group = locked_group.into();
6792 let result = GetStateReply { device_id, sequence, length, mods, base_mods, latched_mods, locked_mods, group, locked_group, base_group, latched_group, compat_state, grab_mods, compat_grab_mods, lookup_mods, compat_lookup_mods, ptr_btn_state };
6793 let _ = remaining;
6794 let remaining = initial_value.get(32 + length as usize * 4..)
6795 .ok_or(ParseError::InsufficientData)?;
6796 Ok((result, remaining))
6797 }
6798 }
6799
6800 /// Opcode for the LatchLockState request
6801 pub const LATCH_LOCK_STATE_REQUEST: u8 = 5;
6802 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
6803 pub struct LatchLockStateRequest {
6804 pub device_spec: DeviceSpec,
6805 pub affect_mod_locks: u8,
6806 pub mod_locks: u8,
6807 pub lock_group: bool,
6808 pub group_lock: Group,
6809 pub affect_mod_latches: u8,
6810 pub latch_group: bool,
6811 pub group_latch: u16,
6812 }
6813 impl LatchLockStateRequest {
6814 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,6815 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
6816 where
6817 Conn: RequestConnection + ?Sized,
6818 {
6819 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
6820 .ok_or(ConnectionError::UnsupportedExtension)?;
6821 let length_so_far = 0;
6822 let device_spec_bytes = self.device_spec.serialize();
6823 let affect_mod_locks_bytes = self.affect_mod_locks.serialize();
6824 let mod_locks_bytes = self.mod_locks.serialize();
6825 let lock_group_bytes = self.lock_group.serialize();
6826 let group_lock_bytes = u8::from(self.group_lock).serialize();
6827 let affect_mod_latches_bytes = self.affect_mod_latches.serialize();
6828 let latch_group_bytes = self.latch_group.serialize();
6829 let group_latch_bytes = self.group_latch.serialize();
6830 let mut request0 = vec![
6831 extension_information.major_opcode,
6832 LATCH_LOCK_STATE_REQUEST,
6833 0,
6834 0,
6835 device_spec_bytes[0],
6836 device_spec_bytes[1],
6837 affect_mod_locks_bytes[0],
6838 mod_locks_bytes[0],
6839 lock_group_bytes[0],
6840 group_lock_bytes[0],
6841 affect_mod_latches_bytes[0],
6842 0,
6843 0,
6844 latch_group_bytes[0],
6845 group_latch_bytes[0],
6846 group_latch_bytes[1],
6847 ];
6848 let length_so_far = length_so_far + request0.len();
6849 assert_eq!(length_so_far % 4, 0);
6850 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
6851 request0[2..4].copy_from_slice(&length.to_ne_bytes());
6852 Ok((vec![request0.into()], vec![]))
6853 }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,6854 pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
6855 where
6856 Conn: RequestConnection + ?Sized,
6857 {
6858 let (bytes, fds) = self.serialize(conn)?;
6859 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
6860 conn.send_request_without_reply(&slices, fds)
6861 }
6862 /// 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>6863 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
6864 if header.minor_opcode != LATCH_LOCK_STATE_REQUEST {
6865 return Err(ParseError::InvalidValue);
6866 }
6867 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
6868 let (affect_mod_locks, remaining) = u8::try_parse(remaining)?;
6869 let (mod_locks, remaining) = u8::try_parse(remaining)?;
6870 let (lock_group, remaining) = bool::try_parse(remaining)?;
6871 let (group_lock, remaining) = u8::try_parse(remaining)?;
6872 let group_lock = group_lock.into();
6873 let (affect_mod_latches, remaining) = u8::try_parse(remaining)?;
6874 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
6875 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
6876 let (latch_group, remaining) = bool::try_parse(remaining)?;
6877 let (group_latch, remaining) = u16::try_parse(remaining)?;
6878 let _ = remaining;
6879 Ok(LatchLockStateRequest {
6880 device_spec,
6881 affect_mod_locks,
6882 mod_locks,
6883 lock_group,
6884 group_lock,
6885 affect_mod_latches,
6886 latch_group,
6887 group_latch,
6888 })
6889 }
6890 }
6891 impl Request for LatchLockStateRequest {
6892 type Reply = ();
6893 }
latch_lock_state<Conn, A, B, C>(conn: &Conn, device_spec: DeviceSpec, affect_mod_locks: A, mod_locks: B, lock_group: bool, group_lock: Group, affect_mod_latches: C, latch_group: bool, group_latch: u16) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<u8>, B: Into<u8>, C: Into<u8>,6894 pub fn latch_lock_state<Conn, A, B, C>(conn: &Conn, device_spec: DeviceSpec, affect_mod_locks: A, mod_locks: B, lock_group: bool, group_lock: Group, affect_mod_latches: C, latch_group: bool, group_latch: u16) -> Result<VoidCookie<'_, Conn>, ConnectionError>
6895 where
6896 Conn: RequestConnection + ?Sized,
6897 A: Into<u8>,
6898 B: Into<u8>,
6899 C: Into<u8>,
6900 {
6901 let affect_mod_locks: u8 = affect_mod_locks.into();
6902 let mod_locks: u8 = mod_locks.into();
6903 let affect_mod_latches: u8 = affect_mod_latches.into();
6904 let request0 = LatchLockStateRequest {
6905 device_spec,
6906 affect_mod_locks,
6907 mod_locks,
6908 lock_group,
6909 group_lock,
6910 affect_mod_latches,
6911 latch_group,
6912 group_latch,
6913 };
6914 request0.send(conn)
6915 }
6916
6917 /// Opcode for the GetControls request
6918 pub const GET_CONTROLS_REQUEST: u8 = 6;
6919 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
6920 pub struct GetControlsRequest {
6921 pub device_spec: DeviceSpec,
6922 }
6923 impl GetControlsRequest {
6924 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,6925 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
6926 where
6927 Conn: RequestConnection + ?Sized,
6928 {
6929 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
6930 .ok_or(ConnectionError::UnsupportedExtension)?;
6931 let length_so_far = 0;
6932 let device_spec_bytes = self.device_spec.serialize();
6933 let mut request0 = vec![
6934 extension_information.major_opcode,
6935 GET_CONTROLS_REQUEST,
6936 0,
6937 0,
6938 device_spec_bytes[0],
6939 device_spec_bytes[1],
6940 0,
6941 0,
6942 ];
6943 let length_so_far = length_so_far + request0.len();
6944 assert_eq!(length_so_far % 4, 0);
6945 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
6946 request0[2..4].copy_from_slice(&length.to_ne_bytes());
6947 Ok((vec![request0.into()], vec![]))
6948 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetControlsReply>, ConnectionError> where Conn: RequestConnection + ?Sized,6949 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetControlsReply>, ConnectionError>
6950 where
6951 Conn: RequestConnection + ?Sized,
6952 {
6953 let (bytes, fds) = self.serialize(conn)?;
6954 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
6955 conn.send_request_with_reply(&slices, fds)
6956 }
6957 /// 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>6958 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
6959 if header.minor_opcode != GET_CONTROLS_REQUEST {
6960 return Err(ParseError::InvalidValue);
6961 }
6962 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
6963 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
6964 let _ = remaining;
6965 Ok(GetControlsRequest {
6966 device_spec,
6967 })
6968 }
6969 }
6970 impl Request for GetControlsRequest {
6971 type Reply = GetControlsReply;
6972 }
get_controls<Conn>(conn: &Conn, device_spec: DeviceSpec) -> Result<Cookie<'_, Conn, GetControlsReply>, ConnectionError> where Conn: RequestConnection + ?Sized,6973 pub fn get_controls<Conn>(conn: &Conn, device_spec: DeviceSpec) -> Result<Cookie<'_, Conn, GetControlsReply>, ConnectionError>
6974 where
6975 Conn: RequestConnection + ?Sized,
6976 {
6977 let request0 = GetControlsRequest {
6978 device_spec,
6979 };
6980 request0.send(conn)
6981 }
6982
6983 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
6984 pub struct GetControlsReply {
6985 pub device_id: u8,
6986 pub sequence: u16,
6987 pub length: u32,
6988 pub mouse_keys_dflt_btn: u8,
6989 pub num_groups: u8,
6990 pub groups_wrap: u8,
6991 pub internal_mods_mask: u8,
6992 pub ignore_lock_mods_mask: u8,
6993 pub internal_mods_real_mods: u8,
6994 pub ignore_lock_mods_real_mods: u8,
6995 pub internal_mods_vmods: u16,
6996 pub ignore_lock_mods_vmods: u16,
6997 pub repeat_delay: u16,
6998 pub repeat_interval: u16,
6999 pub slow_keys_delay: u16,
7000 pub debounce_delay: u16,
7001 pub mouse_keys_delay: u16,
7002 pub mouse_keys_interval: u16,
7003 pub mouse_keys_time_to_max: u16,
7004 pub mouse_keys_max_speed: u16,
7005 pub mouse_keys_curve: i16,
7006 pub access_x_option: u16,
7007 pub access_x_timeout: u16,
7008 pub access_x_timeout_options_mask: u16,
7009 pub access_x_timeout_options_values: u16,
7010 pub access_x_timeout_mask: u32,
7011 pub access_x_timeout_values: u32,
7012 pub enabled_controls: u32,
7013 pub per_key_repeat: [u8; 32],
7014 }
7015 impl TryParse for GetControlsReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>7016 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
7017 let remaining = initial_value;
7018 let (response_type, remaining) = u8::try_parse(remaining)?;
7019 let (device_id, remaining) = u8::try_parse(remaining)?;
7020 let (sequence, remaining) = u16::try_parse(remaining)?;
7021 let (length, remaining) = u32::try_parse(remaining)?;
7022 let (mouse_keys_dflt_btn, remaining) = u8::try_parse(remaining)?;
7023 let (num_groups, remaining) = u8::try_parse(remaining)?;
7024 let (groups_wrap, remaining) = u8::try_parse(remaining)?;
7025 let (internal_mods_mask, remaining) = u8::try_parse(remaining)?;
7026 let (ignore_lock_mods_mask, remaining) = u8::try_parse(remaining)?;
7027 let (internal_mods_real_mods, remaining) = u8::try_parse(remaining)?;
7028 let (ignore_lock_mods_real_mods, remaining) = u8::try_parse(remaining)?;
7029 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
7030 let (internal_mods_vmods, remaining) = u16::try_parse(remaining)?;
7031 let (ignore_lock_mods_vmods, remaining) = u16::try_parse(remaining)?;
7032 let (repeat_delay, remaining) = u16::try_parse(remaining)?;
7033 let (repeat_interval, remaining) = u16::try_parse(remaining)?;
7034 let (slow_keys_delay, remaining) = u16::try_parse(remaining)?;
7035 let (debounce_delay, remaining) = u16::try_parse(remaining)?;
7036 let (mouse_keys_delay, remaining) = u16::try_parse(remaining)?;
7037 let (mouse_keys_interval, remaining) = u16::try_parse(remaining)?;
7038 let (mouse_keys_time_to_max, remaining) = u16::try_parse(remaining)?;
7039 let (mouse_keys_max_speed, remaining) = u16::try_parse(remaining)?;
7040 let (mouse_keys_curve, remaining) = i16::try_parse(remaining)?;
7041 let (access_x_option, remaining) = u16::try_parse(remaining)?;
7042 let (access_x_timeout, remaining) = u16::try_parse(remaining)?;
7043 let (access_x_timeout_options_mask, remaining) = u16::try_parse(remaining)?;
7044 let (access_x_timeout_options_values, remaining) = u16::try_parse(remaining)?;
7045 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
7046 let (access_x_timeout_mask, remaining) = u32::try_parse(remaining)?;
7047 let (access_x_timeout_values, remaining) = u32::try_parse(remaining)?;
7048 let (enabled_controls, remaining) = u32::try_parse(remaining)?;
7049 let (per_key_repeat, remaining) = crate::x11_utils::parse_u8_list(remaining, 32)?;
7050 let per_key_repeat = <[u8; 32]>::try_from(per_key_repeat).unwrap();
7051 if response_type != 1 {
7052 return Err(ParseError::InvalidValue);
7053 }
7054 let result = GetControlsReply { device_id, sequence, length, mouse_keys_dflt_btn, num_groups, groups_wrap, internal_mods_mask, ignore_lock_mods_mask, internal_mods_real_mods, ignore_lock_mods_real_mods, internal_mods_vmods, ignore_lock_mods_vmods, repeat_delay, repeat_interval, slow_keys_delay, debounce_delay, mouse_keys_delay, mouse_keys_interval, mouse_keys_time_to_max, mouse_keys_max_speed, mouse_keys_curve, access_x_option, access_x_timeout, access_x_timeout_options_mask, access_x_timeout_options_values, access_x_timeout_mask, access_x_timeout_values, enabled_controls, per_key_repeat };
7055 let _ = remaining;
7056 let remaining = initial_value.get(32 + length as usize * 4..)
7057 .ok_or(ParseError::InsufficientData)?;
7058 Ok((result, remaining))
7059 }
7060 }
7061
7062 /// Opcode for the SetControls request
7063 pub const SET_CONTROLS_REQUEST: u8 = 7;
7064 #[derive(Debug, Clone, PartialEq, Eq)]
7065 pub struct SetControlsRequest<'input> {
7066 pub device_spec: DeviceSpec,
7067 pub affect_internal_real_mods: u8,
7068 pub internal_real_mods: u8,
7069 pub affect_ignore_lock_real_mods: u8,
7070 pub ignore_lock_real_mods: u8,
7071 pub affect_internal_virtual_mods: u16,
7072 pub internal_virtual_mods: u16,
7073 pub affect_ignore_lock_virtual_mods: u16,
7074 pub ignore_lock_virtual_mods: u16,
7075 pub mouse_keys_dflt_btn: u8,
7076 pub groups_wrap: u8,
7077 pub access_x_options: u16,
7078 pub affect_enabled_controls: u32,
7079 pub enabled_controls: u32,
7080 pub change_controls: u32,
7081 pub repeat_delay: u16,
7082 pub repeat_interval: u16,
7083 pub slow_keys_delay: u16,
7084 pub debounce_delay: u16,
7085 pub mouse_keys_delay: u16,
7086 pub mouse_keys_interval: u16,
7087 pub mouse_keys_time_to_max: u16,
7088 pub mouse_keys_max_speed: u16,
7089 pub mouse_keys_curve: i16,
7090 pub access_x_timeout: u16,
7091 pub access_x_timeout_mask: u32,
7092 pub access_x_timeout_values: u32,
7093 pub access_x_timeout_options_mask: u16,
7094 pub access_x_timeout_options_values: u16,
7095 pub per_key_repeat: Cow<'input, [u8; 32]>,
7096 }
7097 impl<'input> SetControlsRequest<'input> {
7098 /// Serialize this request into bytes for the provided connection
serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,7099 fn serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
7100 where
7101 Conn: RequestConnection + ?Sized,
7102 {
7103 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
7104 .ok_or(ConnectionError::UnsupportedExtension)?;
7105 let length_so_far = 0;
7106 let device_spec_bytes = self.device_spec.serialize();
7107 let affect_internal_real_mods_bytes = self.affect_internal_real_mods.serialize();
7108 let internal_real_mods_bytes = self.internal_real_mods.serialize();
7109 let affect_ignore_lock_real_mods_bytes = self.affect_ignore_lock_real_mods.serialize();
7110 let ignore_lock_real_mods_bytes = self.ignore_lock_real_mods.serialize();
7111 let affect_internal_virtual_mods_bytes = self.affect_internal_virtual_mods.serialize();
7112 let internal_virtual_mods_bytes = self.internal_virtual_mods.serialize();
7113 let affect_ignore_lock_virtual_mods_bytes = self.affect_ignore_lock_virtual_mods.serialize();
7114 let ignore_lock_virtual_mods_bytes = self.ignore_lock_virtual_mods.serialize();
7115 let mouse_keys_dflt_btn_bytes = self.mouse_keys_dflt_btn.serialize();
7116 let groups_wrap_bytes = self.groups_wrap.serialize();
7117 let access_x_options_bytes = self.access_x_options.serialize();
7118 let affect_enabled_controls_bytes = self.affect_enabled_controls.serialize();
7119 let enabled_controls_bytes = self.enabled_controls.serialize();
7120 let change_controls_bytes = self.change_controls.serialize();
7121 let repeat_delay_bytes = self.repeat_delay.serialize();
7122 let repeat_interval_bytes = self.repeat_interval.serialize();
7123 let slow_keys_delay_bytes = self.slow_keys_delay.serialize();
7124 let debounce_delay_bytes = self.debounce_delay.serialize();
7125 let mouse_keys_delay_bytes = self.mouse_keys_delay.serialize();
7126 let mouse_keys_interval_bytes = self.mouse_keys_interval.serialize();
7127 let mouse_keys_time_to_max_bytes = self.mouse_keys_time_to_max.serialize();
7128 let mouse_keys_max_speed_bytes = self.mouse_keys_max_speed.serialize();
7129 let mouse_keys_curve_bytes = self.mouse_keys_curve.serialize();
7130 let access_x_timeout_bytes = self.access_x_timeout.serialize();
7131 let access_x_timeout_mask_bytes = self.access_x_timeout_mask.serialize();
7132 let access_x_timeout_values_bytes = self.access_x_timeout_values.serialize();
7133 let access_x_timeout_options_mask_bytes = self.access_x_timeout_options_mask.serialize();
7134 let access_x_timeout_options_values_bytes = self.access_x_timeout_options_values.serialize();
7135 let mut request0 = vec![
7136 extension_information.major_opcode,
7137 SET_CONTROLS_REQUEST,
7138 0,
7139 0,
7140 device_spec_bytes[0],
7141 device_spec_bytes[1],
7142 affect_internal_real_mods_bytes[0],
7143 internal_real_mods_bytes[0],
7144 affect_ignore_lock_real_mods_bytes[0],
7145 ignore_lock_real_mods_bytes[0],
7146 affect_internal_virtual_mods_bytes[0],
7147 affect_internal_virtual_mods_bytes[1],
7148 internal_virtual_mods_bytes[0],
7149 internal_virtual_mods_bytes[1],
7150 affect_ignore_lock_virtual_mods_bytes[0],
7151 affect_ignore_lock_virtual_mods_bytes[1],
7152 ignore_lock_virtual_mods_bytes[0],
7153 ignore_lock_virtual_mods_bytes[1],
7154 mouse_keys_dflt_btn_bytes[0],
7155 groups_wrap_bytes[0],
7156 access_x_options_bytes[0],
7157 access_x_options_bytes[1],
7158 0,
7159 0,
7160 affect_enabled_controls_bytes[0],
7161 affect_enabled_controls_bytes[1],
7162 affect_enabled_controls_bytes[2],
7163 affect_enabled_controls_bytes[3],
7164 enabled_controls_bytes[0],
7165 enabled_controls_bytes[1],
7166 enabled_controls_bytes[2],
7167 enabled_controls_bytes[3],
7168 change_controls_bytes[0],
7169 change_controls_bytes[1],
7170 change_controls_bytes[2],
7171 change_controls_bytes[3],
7172 repeat_delay_bytes[0],
7173 repeat_delay_bytes[1],
7174 repeat_interval_bytes[0],
7175 repeat_interval_bytes[1],
7176 slow_keys_delay_bytes[0],
7177 slow_keys_delay_bytes[1],
7178 debounce_delay_bytes[0],
7179 debounce_delay_bytes[1],
7180 mouse_keys_delay_bytes[0],
7181 mouse_keys_delay_bytes[1],
7182 mouse_keys_interval_bytes[0],
7183 mouse_keys_interval_bytes[1],
7184 mouse_keys_time_to_max_bytes[0],
7185 mouse_keys_time_to_max_bytes[1],
7186 mouse_keys_max_speed_bytes[0],
7187 mouse_keys_max_speed_bytes[1],
7188 mouse_keys_curve_bytes[0],
7189 mouse_keys_curve_bytes[1],
7190 access_x_timeout_bytes[0],
7191 access_x_timeout_bytes[1],
7192 access_x_timeout_mask_bytes[0],
7193 access_x_timeout_mask_bytes[1],
7194 access_x_timeout_mask_bytes[2],
7195 access_x_timeout_mask_bytes[3],
7196 access_x_timeout_values_bytes[0],
7197 access_x_timeout_values_bytes[1],
7198 access_x_timeout_values_bytes[2],
7199 access_x_timeout_values_bytes[3],
7200 access_x_timeout_options_mask_bytes[0],
7201 access_x_timeout_options_mask_bytes[1],
7202 access_x_timeout_options_values_bytes[0],
7203 access_x_timeout_options_values_bytes[1],
7204 ];
7205 let length_so_far = length_so_far + request0.len();
7206 let length_so_far = length_so_far + self.per_key_repeat.len();
7207 assert_eq!(length_so_far % 4, 0);
7208 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
7209 request0[2..4].copy_from_slice(&length.to_ne_bytes());
7210 Ok((vec![request0.into(), Cow::Owned(self.per_key_repeat.to_vec())], vec![]))
7211 }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,7212 pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
7213 where
7214 Conn: RequestConnection + ?Sized,
7215 {
7216 let (bytes, fds) = self.serialize(conn)?;
7217 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
7218 conn.send_request_without_reply(&slices, fds)
7219 }
7220 /// 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>7221 pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
7222 if header.minor_opcode != SET_CONTROLS_REQUEST {
7223 return Err(ParseError::InvalidValue);
7224 }
7225 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
7226 let (affect_internal_real_mods, remaining) = u8::try_parse(remaining)?;
7227 let (internal_real_mods, remaining) = u8::try_parse(remaining)?;
7228 let (affect_ignore_lock_real_mods, remaining) = u8::try_parse(remaining)?;
7229 let (ignore_lock_real_mods, remaining) = u8::try_parse(remaining)?;
7230 let (affect_internal_virtual_mods, remaining) = u16::try_parse(remaining)?;
7231 let (internal_virtual_mods, remaining) = u16::try_parse(remaining)?;
7232 let (affect_ignore_lock_virtual_mods, remaining) = u16::try_parse(remaining)?;
7233 let (ignore_lock_virtual_mods, remaining) = u16::try_parse(remaining)?;
7234 let (mouse_keys_dflt_btn, remaining) = u8::try_parse(remaining)?;
7235 let (groups_wrap, remaining) = u8::try_parse(remaining)?;
7236 let (access_x_options, remaining) = u16::try_parse(remaining)?;
7237 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
7238 let (affect_enabled_controls, remaining) = u32::try_parse(remaining)?;
7239 let (enabled_controls, remaining) = u32::try_parse(remaining)?;
7240 let (change_controls, remaining) = u32::try_parse(remaining)?;
7241 let (repeat_delay, remaining) = u16::try_parse(remaining)?;
7242 let (repeat_interval, remaining) = u16::try_parse(remaining)?;
7243 let (slow_keys_delay, remaining) = u16::try_parse(remaining)?;
7244 let (debounce_delay, remaining) = u16::try_parse(remaining)?;
7245 let (mouse_keys_delay, remaining) = u16::try_parse(remaining)?;
7246 let (mouse_keys_interval, remaining) = u16::try_parse(remaining)?;
7247 let (mouse_keys_time_to_max, remaining) = u16::try_parse(remaining)?;
7248 let (mouse_keys_max_speed, remaining) = u16::try_parse(remaining)?;
7249 let (mouse_keys_curve, remaining) = i16::try_parse(remaining)?;
7250 let (access_x_timeout, remaining) = u16::try_parse(remaining)?;
7251 let (access_x_timeout_mask, remaining) = u32::try_parse(remaining)?;
7252 let (access_x_timeout_values, remaining) = u32::try_parse(remaining)?;
7253 let (access_x_timeout_options_mask, remaining) = u16::try_parse(remaining)?;
7254 let (access_x_timeout_options_values, remaining) = u16::try_parse(remaining)?;
7255 let (per_key_repeat, remaining) = crate::x11_utils::parse_u8_list(remaining, 32)?;
7256 let per_key_repeat = <&[u8; 32]>::try_from(per_key_repeat).unwrap();
7257 let _ = remaining;
7258 Ok(SetControlsRequest {
7259 device_spec,
7260 affect_internal_real_mods,
7261 internal_real_mods,
7262 affect_ignore_lock_real_mods,
7263 ignore_lock_real_mods,
7264 affect_internal_virtual_mods,
7265 internal_virtual_mods,
7266 affect_ignore_lock_virtual_mods,
7267 ignore_lock_virtual_mods,
7268 mouse_keys_dflt_btn,
7269 groups_wrap,
7270 access_x_options,
7271 affect_enabled_controls,
7272 enabled_controls,
7273 change_controls,
7274 repeat_delay,
7275 repeat_interval,
7276 slow_keys_delay,
7277 debounce_delay,
7278 mouse_keys_delay,
7279 mouse_keys_interval,
7280 mouse_keys_time_to_max,
7281 mouse_keys_max_speed,
7282 mouse_keys_curve,
7283 access_x_timeout,
7284 access_x_timeout_mask,
7285 access_x_timeout_values,
7286 access_x_timeout_options_mask,
7287 access_x_timeout_options_values,
7288 per_key_repeat: Cow::Borrowed(per_key_repeat),
7289 })
7290 }
7291 /// Clone all borrowed data in this SetControlsRequest.
into_owned(self) -> SetControlsRequest<'static>7292 pub fn into_owned(self) -> SetControlsRequest<'static> {
7293 SetControlsRequest {
7294 device_spec: self.device_spec,
7295 affect_internal_real_mods: self.affect_internal_real_mods,
7296 internal_real_mods: self.internal_real_mods,
7297 affect_ignore_lock_real_mods: self.affect_ignore_lock_real_mods,
7298 ignore_lock_real_mods: self.ignore_lock_real_mods,
7299 affect_internal_virtual_mods: self.affect_internal_virtual_mods,
7300 internal_virtual_mods: self.internal_virtual_mods,
7301 affect_ignore_lock_virtual_mods: self.affect_ignore_lock_virtual_mods,
7302 ignore_lock_virtual_mods: self.ignore_lock_virtual_mods,
7303 mouse_keys_dflt_btn: self.mouse_keys_dflt_btn,
7304 groups_wrap: self.groups_wrap,
7305 access_x_options: self.access_x_options,
7306 affect_enabled_controls: self.affect_enabled_controls,
7307 enabled_controls: self.enabled_controls,
7308 change_controls: self.change_controls,
7309 repeat_delay: self.repeat_delay,
7310 repeat_interval: self.repeat_interval,
7311 slow_keys_delay: self.slow_keys_delay,
7312 debounce_delay: self.debounce_delay,
7313 mouse_keys_delay: self.mouse_keys_delay,
7314 mouse_keys_interval: self.mouse_keys_interval,
7315 mouse_keys_time_to_max: self.mouse_keys_time_to_max,
7316 mouse_keys_max_speed: self.mouse_keys_max_speed,
7317 mouse_keys_curve: self.mouse_keys_curve,
7318 access_x_timeout: self.access_x_timeout,
7319 access_x_timeout_mask: self.access_x_timeout_mask,
7320 access_x_timeout_values: self.access_x_timeout_values,
7321 access_x_timeout_options_mask: self.access_x_timeout_options_mask,
7322 access_x_timeout_options_values: self.access_x_timeout_options_values,
7323 per_key_repeat: Cow::Owned(self.per_key_repeat.into_owned()),
7324 }
7325 }
7326 }
7327 impl<'input> Request for SetControlsRequest<'input> {
7328 type Reply = ();
7329 }
set_controls<'c, 'input, Conn, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(conn: &'c Conn, device_spec: DeviceSpec, affect_internal_real_mods: A, internal_real_mods: B, affect_ignore_lock_real_mods: C, ignore_lock_real_mods: D, affect_internal_virtual_mods: E, internal_virtual_mods: F, affect_ignore_lock_virtual_mods: G, ignore_lock_virtual_mods: H, mouse_keys_dflt_btn: u8, groups_wrap: u8, access_x_options: I, affect_enabled_controls: J, enabled_controls: K, change_controls: L, repeat_delay: u16, repeat_interval: u16, slow_keys_delay: u16, debounce_delay: u16, mouse_keys_delay: u16, mouse_keys_interval: u16, mouse_keys_time_to_max: u16, mouse_keys_max_speed: u16, mouse_keys_curve: i16, access_x_timeout: u16, access_x_timeout_mask: M, access_x_timeout_values: N, access_x_timeout_options_mask: O, access_x_timeout_options_values: P, per_key_repeat: &'input [u8; 32]) -> Result<VoidCookie<'c, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<u8>, B: Into<u8>, C: Into<u8>, D: Into<u8>, E: Into<u16>, F: Into<u16>, G: Into<u16>, H: Into<u16>, I: Into<u16>, J: Into<u32>, K: Into<u32>, L: Into<u32>, M: Into<u32>, N: Into<u32>, O: Into<u16>, P: Into<u16>,7330 pub fn set_controls<'c, 'input, Conn, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(conn: &'c Conn, device_spec: DeviceSpec, affect_internal_real_mods: A, internal_real_mods: B, affect_ignore_lock_real_mods: C, ignore_lock_real_mods: D, affect_internal_virtual_mods: E, internal_virtual_mods: F, affect_ignore_lock_virtual_mods: G, ignore_lock_virtual_mods: H, mouse_keys_dflt_btn: u8, groups_wrap: u8, access_x_options: I, affect_enabled_controls: J, enabled_controls: K, change_controls: L, repeat_delay: u16, repeat_interval: u16, slow_keys_delay: u16, debounce_delay: u16, mouse_keys_delay: u16, mouse_keys_interval: u16, mouse_keys_time_to_max: u16, mouse_keys_max_speed: u16, mouse_keys_curve: i16, access_x_timeout: u16, access_x_timeout_mask: M, access_x_timeout_values: N, access_x_timeout_options_mask: O, access_x_timeout_options_values: P, per_key_repeat: &'input [u8; 32]) -> Result<VoidCookie<'c, Conn>, ConnectionError>
7331 where
7332 Conn: RequestConnection + ?Sized,
7333 A: Into<u8>,
7334 B: Into<u8>,
7335 C: Into<u8>,
7336 D: Into<u8>,
7337 E: Into<u16>,
7338 F: Into<u16>,
7339 G: Into<u16>,
7340 H: Into<u16>,
7341 I: Into<u16>,
7342 J: Into<u32>,
7343 K: Into<u32>,
7344 L: Into<u32>,
7345 M: Into<u32>,
7346 N: Into<u32>,
7347 O: Into<u16>,
7348 P: Into<u16>,
7349 {
7350 let affect_internal_real_mods: u8 = affect_internal_real_mods.into();
7351 let internal_real_mods: u8 = internal_real_mods.into();
7352 let affect_ignore_lock_real_mods: u8 = affect_ignore_lock_real_mods.into();
7353 let ignore_lock_real_mods: u8 = ignore_lock_real_mods.into();
7354 let affect_internal_virtual_mods: u16 = affect_internal_virtual_mods.into();
7355 let internal_virtual_mods: u16 = internal_virtual_mods.into();
7356 let affect_ignore_lock_virtual_mods: u16 = affect_ignore_lock_virtual_mods.into();
7357 let ignore_lock_virtual_mods: u16 = ignore_lock_virtual_mods.into();
7358 let access_x_options: u16 = access_x_options.into();
7359 let affect_enabled_controls: u32 = affect_enabled_controls.into();
7360 let enabled_controls: u32 = enabled_controls.into();
7361 let change_controls: u32 = change_controls.into();
7362 let access_x_timeout_mask: u32 = access_x_timeout_mask.into();
7363 let access_x_timeout_values: u32 = access_x_timeout_values.into();
7364 let access_x_timeout_options_mask: u16 = access_x_timeout_options_mask.into();
7365 let access_x_timeout_options_values: u16 = access_x_timeout_options_values.into();
7366 let request0 = SetControlsRequest {
7367 device_spec,
7368 affect_internal_real_mods,
7369 internal_real_mods,
7370 affect_ignore_lock_real_mods,
7371 ignore_lock_real_mods,
7372 affect_internal_virtual_mods,
7373 internal_virtual_mods,
7374 affect_ignore_lock_virtual_mods,
7375 ignore_lock_virtual_mods,
7376 mouse_keys_dflt_btn,
7377 groups_wrap,
7378 access_x_options,
7379 affect_enabled_controls,
7380 enabled_controls,
7381 change_controls,
7382 repeat_delay,
7383 repeat_interval,
7384 slow_keys_delay,
7385 debounce_delay,
7386 mouse_keys_delay,
7387 mouse_keys_interval,
7388 mouse_keys_time_to_max,
7389 mouse_keys_max_speed,
7390 mouse_keys_curve,
7391 access_x_timeout,
7392 access_x_timeout_mask,
7393 access_x_timeout_values,
7394 access_x_timeout_options_mask,
7395 access_x_timeout_options_values,
7396 per_key_repeat: Cow::Borrowed(per_key_repeat),
7397 };
7398 request0.send(conn)
7399 }
7400
7401 /// Opcode for the GetMap request
7402 pub const GET_MAP_REQUEST: u8 = 8;
7403 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
7404 pub struct GetMapRequest {
7405 pub device_spec: DeviceSpec,
7406 pub full: u16,
7407 pub partial: u16,
7408 pub first_type: u8,
7409 pub n_types: u8,
7410 pub first_key_sym: xproto::Keycode,
7411 pub n_key_syms: u8,
7412 pub first_key_action: xproto::Keycode,
7413 pub n_key_actions: u8,
7414 pub first_key_behavior: xproto::Keycode,
7415 pub n_key_behaviors: u8,
7416 pub virtual_mods: u16,
7417 pub first_key_explicit: xproto::Keycode,
7418 pub n_key_explicit: u8,
7419 pub first_mod_map_key: xproto::Keycode,
7420 pub n_mod_map_keys: u8,
7421 pub first_v_mod_map_key: xproto::Keycode,
7422 pub n_v_mod_map_keys: u8,
7423 }
7424 impl GetMapRequest {
7425 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,7426 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
7427 where
7428 Conn: RequestConnection + ?Sized,
7429 {
7430 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
7431 .ok_or(ConnectionError::UnsupportedExtension)?;
7432 let length_so_far = 0;
7433 let device_spec_bytes = self.device_spec.serialize();
7434 let full_bytes = self.full.serialize();
7435 let partial_bytes = self.partial.serialize();
7436 let first_type_bytes = self.first_type.serialize();
7437 let n_types_bytes = self.n_types.serialize();
7438 let first_key_sym_bytes = self.first_key_sym.serialize();
7439 let n_key_syms_bytes = self.n_key_syms.serialize();
7440 let first_key_action_bytes = self.first_key_action.serialize();
7441 let n_key_actions_bytes = self.n_key_actions.serialize();
7442 let first_key_behavior_bytes = self.first_key_behavior.serialize();
7443 let n_key_behaviors_bytes = self.n_key_behaviors.serialize();
7444 let virtual_mods_bytes = self.virtual_mods.serialize();
7445 let first_key_explicit_bytes = self.first_key_explicit.serialize();
7446 let n_key_explicit_bytes = self.n_key_explicit.serialize();
7447 let first_mod_map_key_bytes = self.first_mod_map_key.serialize();
7448 let n_mod_map_keys_bytes = self.n_mod_map_keys.serialize();
7449 let first_v_mod_map_key_bytes = self.first_v_mod_map_key.serialize();
7450 let n_v_mod_map_keys_bytes = self.n_v_mod_map_keys.serialize();
7451 let mut request0 = vec![
7452 extension_information.major_opcode,
7453 GET_MAP_REQUEST,
7454 0,
7455 0,
7456 device_spec_bytes[0],
7457 device_spec_bytes[1],
7458 full_bytes[0],
7459 full_bytes[1],
7460 partial_bytes[0],
7461 partial_bytes[1],
7462 first_type_bytes[0],
7463 n_types_bytes[0],
7464 first_key_sym_bytes[0],
7465 n_key_syms_bytes[0],
7466 first_key_action_bytes[0],
7467 n_key_actions_bytes[0],
7468 first_key_behavior_bytes[0],
7469 n_key_behaviors_bytes[0],
7470 virtual_mods_bytes[0],
7471 virtual_mods_bytes[1],
7472 first_key_explicit_bytes[0],
7473 n_key_explicit_bytes[0],
7474 first_mod_map_key_bytes[0],
7475 n_mod_map_keys_bytes[0],
7476 first_v_mod_map_key_bytes[0],
7477 n_v_mod_map_keys_bytes[0],
7478 0,
7479 0,
7480 ];
7481 let length_so_far = length_so_far + request0.len();
7482 assert_eq!(length_so_far % 4, 0);
7483 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
7484 request0[2..4].copy_from_slice(&length.to_ne_bytes());
7485 Ok((vec![request0.into()], vec![]))
7486 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetMapReply>, ConnectionError> where Conn: RequestConnection + ?Sized,7487 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetMapReply>, ConnectionError>
7488 where
7489 Conn: RequestConnection + ?Sized,
7490 {
7491 let (bytes, fds) = self.serialize(conn)?;
7492 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
7493 conn.send_request_with_reply(&slices, fds)
7494 }
7495 /// 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>7496 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
7497 if header.minor_opcode != GET_MAP_REQUEST {
7498 return Err(ParseError::InvalidValue);
7499 }
7500 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
7501 let (full, remaining) = u16::try_parse(remaining)?;
7502 let (partial, remaining) = u16::try_parse(remaining)?;
7503 let (first_type, remaining) = u8::try_parse(remaining)?;
7504 let (n_types, remaining) = u8::try_parse(remaining)?;
7505 let (first_key_sym, remaining) = xproto::Keycode::try_parse(remaining)?;
7506 let (n_key_syms, remaining) = u8::try_parse(remaining)?;
7507 let (first_key_action, remaining) = xproto::Keycode::try_parse(remaining)?;
7508 let (n_key_actions, remaining) = u8::try_parse(remaining)?;
7509 let (first_key_behavior, remaining) = xproto::Keycode::try_parse(remaining)?;
7510 let (n_key_behaviors, remaining) = u8::try_parse(remaining)?;
7511 let (virtual_mods, remaining) = u16::try_parse(remaining)?;
7512 let (first_key_explicit, remaining) = xproto::Keycode::try_parse(remaining)?;
7513 let (n_key_explicit, remaining) = u8::try_parse(remaining)?;
7514 let (first_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?;
7515 let (n_mod_map_keys, remaining) = u8::try_parse(remaining)?;
7516 let (first_v_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?;
7517 let (n_v_mod_map_keys, remaining) = u8::try_parse(remaining)?;
7518 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
7519 let _ = remaining;
7520 Ok(GetMapRequest {
7521 device_spec,
7522 full,
7523 partial,
7524 first_type,
7525 n_types,
7526 first_key_sym,
7527 n_key_syms,
7528 first_key_action,
7529 n_key_actions,
7530 first_key_behavior,
7531 n_key_behaviors,
7532 virtual_mods,
7533 first_key_explicit,
7534 n_key_explicit,
7535 first_mod_map_key,
7536 n_mod_map_keys,
7537 first_v_mod_map_key,
7538 n_v_mod_map_keys,
7539 })
7540 }
7541 }
7542 impl Request for GetMapRequest {
7543 type Reply = GetMapReply;
7544 }
get_map<Conn, A, B, C>(conn: &Conn, device_spec: DeviceSpec, full: A, partial: B, first_type: u8, n_types: u8, first_key_sym: xproto::Keycode, n_key_syms: u8, first_key_action: xproto::Keycode, n_key_actions: u8, first_key_behavior: xproto::Keycode, n_key_behaviors: u8, virtual_mods: C, first_key_explicit: xproto::Keycode, n_key_explicit: u8, first_mod_map_key: xproto::Keycode, n_mod_map_keys: u8, first_v_mod_map_key: xproto::Keycode, n_v_mod_map_keys: u8) -> Result<Cookie<'_, Conn, GetMapReply>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<u16>, B: Into<u16>, C: Into<u16>,7545 pub fn get_map<Conn, A, B, C>(conn: &Conn, device_spec: DeviceSpec, full: A, partial: B, first_type: u8, n_types: u8, first_key_sym: xproto::Keycode, n_key_syms: u8, first_key_action: xproto::Keycode, n_key_actions: u8, first_key_behavior: xproto::Keycode, n_key_behaviors: u8, virtual_mods: C, first_key_explicit: xproto::Keycode, n_key_explicit: u8, first_mod_map_key: xproto::Keycode, n_mod_map_keys: u8, first_v_mod_map_key: xproto::Keycode, n_v_mod_map_keys: u8) -> Result<Cookie<'_, Conn, GetMapReply>, ConnectionError>
7546 where
7547 Conn: RequestConnection + ?Sized,
7548 A: Into<u16>,
7549 B: Into<u16>,
7550 C: Into<u16>,
7551 {
7552 let full: u16 = full.into();
7553 let partial: u16 = partial.into();
7554 let virtual_mods: u16 = virtual_mods.into();
7555 let request0 = GetMapRequest {
7556 device_spec,
7557 full,
7558 partial,
7559 first_type,
7560 n_types,
7561 first_key_sym,
7562 n_key_syms,
7563 first_key_action,
7564 n_key_actions,
7565 first_key_behavior,
7566 n_key_behaviors,
7567 virtual_mods,
7568 first_key_explicit,
7569 n_key_explicit,
7570 first_mod_map_key,
7571 n_mod_map_keys,
7572 first_v_mod_map_key,
7573 n_v_mod_map_keys,
7574 };
7575 request0.send(conn)
7576 }
7577
7578 #[derive(Debug, Clone)]
7579 pub struct GetMapMapBitcase3 {
7580 pub acts_rtrn_count: Vec<u8>,
7581 pub acts_rtrn_acts: Vec<Action>,
7582 }
7583 impl GetMapMapBitcase3 {
try_parse(remaining: &[u8], n_key_actions: u8, total_actions: u16) -> Result<(Self, &[u8]), ParseError>7584 pub fn try_parse(remaining: &[u8], n_key_actions: u8, total_actions: u16) -> Result<(Self, &[u8]), ParseError> {
7585 let value = remaining;
7586 let (acts_rtrn_count, remaining) = crate::x11_utils::parse_u8_list(remaining, n_key_actions.try_to_usize()?)?;
7587 let acts_rtrn_count = acts_rtrn_count.to_vec();
7588 // Align offset to multiple of 4
7589 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
7590 let misalignment = (4 - (offset % 4)) % 4;
7591 let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
7592 let (acts_rtrn_acts, remaining) = crate::x11_utils::parse_list::<Action>(remaining, total_actions.try_to_usize()?)?;
7593 let result = GetMapMapBitcase3 { acts_rtrn_count, acts_rtrn_acts };
7594 Ok((result, remaining))
7595 }
7596 }
7597 #[derive(Debug, Clone, Default)]
7598 pub struct GetMapMap {
7599 pub types_rtrn: Option<Vec<KeyType>>,
7600 pub syms_rtrn: Option<Vec<KeySymMap>>,
7601 pub bitcase3: Option<GetMapMapBitcase3>,
7602 pub behaviors_rtrn: Option<Vec<SetBehavior>>,
7603 pub vmods_rtrn: Option<Vec<u8>>,
7604 pub explicit_rtrn: Option<Vec<SetExplicit>>,
7605 pub modmap_rtrn: Option<Vec<KeyModMap>>,
7606 pub vmodmap_rtrn: Option<Vec<KeyVModMap>>,
7607 }
7608 impl GetMapMap {
try_parse(value: &[u8], present: u16, n_types: u8, n_key_syms: u8, n_key_actions: u8, total_actions: u16, total_key_behaviors: u8, virtual_mods: u16, total_key_explicit: u8, total_mod_map_keys: u8, total_v_mod_map_keys: u8) -> Result<(Self, &[u8]), ParseError>7609 fn try_parse(value: &[u8], present: u16, n_types: u8, n_key_syms: u8, n_key_actions: u8, total_actions: u16, total_key_behaviors: u8, virtual_mods: u16, total_key_explicit: u8, total_mod_map_keys: u8, total_v_mod_map_keys: u8) -> Result<(Self, &[u8]), ParseError> {
7610 let switch_expr = u32::from(present);
7611 let mut outer_remaining = value;
7612 let types_rtrn = if switch_expr & u32::from(MapPart::KEY_TYPES) != 0 {
7613 let remaining = outer_remaining;
7614 let (types_rtrn, remaining) = crate::x11_utils::parse_list::<KeyType>(remaining, n_types.try_to_usize()?)?;
7615 outer_remaining = remaining;
7616 Some(types_rtrn)
7617 } else {
7618 None
7619 };
7620 let syms_rtrn = if switch_expr & u32::from(MapPart::KEY_SYMS) != 0 {
7621 let remaining = outer_remaining;
7622 let (syms_rtrn, remaining) = crate::x11_utils::parse_list::<KeySymMap>(remaining, n_key_syms.try_to_usize()?)?;
7623 outer_remaining = remaining;
7624 Some(syms_rtrn)
7625 } else {
7626 None
7627 };
7628 let bitcase3 = if switch_expr & u32::from(MapPart::KEY_ACTIONS) != 0 {
7629 let (bitcase3, new_remaining) = GetMapMapBitcase3::try_parse(outer_remaining, n_key_actions, total_actions)?;
7630 outer_remaining = new_remaining;
7631 Some(bitcase3)
7632 } else {
7633 None
7634 };
7635 let behaviors_rtrn = if switch_expr & u32::from(MapPart::KEY_BEHAVIORS) != 0 {
7636 let remaining = outer_remaining;
7637 let (behaviors_rtrn, remaining) = crate::x11_utils::parse_list::<SetBehavior>(remaining, total_key_behaviors.try_to_usize()?)?;
7638 outer_remaining = remaining;
7639 Some(behaviors_rtrn)
7640 } else {
7641 None
7642 };
7643 let vmods_rtrn = if switch_expr & u32::from(MapPart::VIRTUAL_MODS) != 0 {
7644 let remaining = outer_remaining;
7645 let value = remaining;
7646 let (vmods_rtrn, remaining) = crate::x11_utils::parse_u8_list(remaining, virtual_mods.count_ones().try_to_usize()?)?;
7647 let vmods_rtrn = vmods_rtrn.to_vec();
7648 // Align offset to multiple of 4
7649 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
7650 let misalignment = (4 - (offset % 4)) % 4;
7651 let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
7652 outer_remaining = remaining;
7653 Some(vmods_rtrn)
7654 } else {
7655 None
7656 };
7657 let explicit_rtrn = if switch_expr & u32::from(MapPart::EXPLICIT_COMPONENTS) != 0 {
7658 let remaining = outer_remaining;
7659 let value = remaining;
7660 let (explicit_rtrn, remaining) = crate::x11_utils::parse_list::<SetExplicit>(remaining, total_key_explicit.try_to_usize()?)?;
7661 // Align offset to multiple of 4
7662 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
7663 let misalignment = (4 - (offset % 4)) % 4;
7664 let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
7665 outer_remaining = remaining;
7666 Some(explicit_rtrn)
7667 } else {
7668 None
7669 };
7670 let modmap_rtrn = if switch_expr & u32::from(MapPart::MODIFIER_MAP) != 0 {
7671 let remaining = outer_remaining;
7672 let value = remaining;
7673 let (modmap_rtrn, remaining) = crate::x11_utils::parse_list::<KeyModMap>(remaining, total_mod_map_keys.try_to_usize()?)?;
7674 // Align offset to multiple of 4
7675 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
7676 let misalignment = (4 - (offset % 4)) % 4;
7677 let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
7678 outer_remaining = remaining;
7679 Some(modmap_rtrn)
7680 } else {
7681 None
7682 };
7683 let vmodmap_rtrn = if switch_expr & u32::from(MapPart::VIRTUAL_MOD_MAP) != 0 {
7684 let remaining = outer_remaining;
7685 let (vmodmap_rtrn, remaining) = crate::x11_utils::parse_list::<KeyVModMap>(remaining, total_v_mod_map_keys.try_to_usize()?)?;
7686 outer_remaining = remaining;
7687 Some(vmodmap_rtrn)
7688 } else {
7689 None
7690 };
7691 let result = GetMapMap { types_rtrn, syms_rtrn, bitcase3, behaviors_rtrn, vmods_rtrn, explicit_rtrn, modmap_rtrn, vmodmap_rtrn };
7692 Ok((result, outer_remaining))
7693 }
7694 }
7695
7696 #[derive(Debug, Clone)]
7697 pub struct GetMapReply {
7698 pub device_id: u8,
7699 pub sequence: u16,
7700 pub length: u32,
7701 pub min_key_code: xproto::Keycode,
7702 pub max_key_code: xproto::Keycode,
7703 pub first_type: u8,
7704 pub n_types: u8,
7705 pub total_types: u8,
7706 pub first_key_sym: xproto::Keycode,
7707 pub total_syms: u16,
7708 pub n_key_syms: u8,
7709 pub first_key_action: xproto::Keycode,
7710 pub total_actions: u16,
7711 pub n_key_actions: u8,
7712 pub first_key_behavior: xproto::Keycode,
7713 pub n_key_behaviors: u8,
7714 pub total_key_behaviors: u8,
7715 pub first_key_explicit: xproto::Keycode,
7716 pub n_key_explicit: u8,
7717 pub total_key_explicit: u8,
7718 pub first_mod_map_key: xproto::Keycode,
7719 pub n_mod_map_keys: u8,
7720 pub total_mod_map_keys: u8,
7721 pub first_v_mod_map_key: xproto::Keycode,
7722 pub n_v_mod_map_keys: u8,
7723 pub total_v_mod_map_keys: u8,
7724 pub virtual_mods: u16,
7725 pub map: GetMapMap,
7726 }
7727 impl TryParse for GetMapReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>7728 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
7729 let remaining = initial_value;
7730 let (response_type, remaining) = u8::try_parse(remaining)?;
7731 let (device_id, remaining) = u8::try_parse(remaining)?;
7732 let (sequence, remaining) = u16::try_parse(remaining)?;
7733 let (length, remaining) = u32::try_parse(remaining)?;
7734 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
7735 let (min_key_code, remaining) = xproto::Keycode::try_parse(remaining)?;
7736 let (max_key_code, remaining) = xproto::Keycode::try_parse(remaining)?;
7737 let (present, remaining) = u16::try_parse(remaining)?;
7738 let (first_type, remaining) = u8::try_parse(remaining)?;
7739 let (n_types, remaining) = u8::try_parse(remaining)?;
7740 let (total_types, remaining) = u8::try_parse(remaining)?;
7741 let (first_key_sym, remaining) = xproto::Keycode::try_parse(remaining)?;
7742 let (total_syms, remaining) = u16::try_parse(remaining)?;
7743 let (n_key_syms, remaining) = u8::try_parse(remaining)?;
7744 let (first_key_action, remaining) = xproto::Keycode::try_parse(remaining)?;
7745 let (total_actions, remaining) = u16::try_parse(remaining)?;
7746 let (n_key_actions, remaining) = u8::try_parse(remaining)?;
7747 let (first_key_behavior, remaining) = xproto::Keycode::try_parse(remaining)?;
7748 let (n_key_behaviors, remaining) = u8::try_parse(remaining)?;
7749 let (total_key_behaviors, remaining) = u8::try_parse(remaining)?;
7750 let (first_key_explicit, remaining) = xproto::Keycode::try_parse(remaining)?;
7751 let (n_key_explicit, remaining) = u8::try_parse(remaining)?;
7752 let (total_key_explicit, remaining) = u8::try_parse(remaining)?;
7753 let (first_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?;
7754 let (n_mod_map_keys, remaining) = u8::try_parse(remaining)?;
7755 let (total_mod_map_keys, remaining) = u8::try_parse(remaining)?;
7756 let (first_v_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?;
7757 let (n_v_mod_map_keys, remaining) = u8::try_parse(remaining)?;
7758 let (total_v_mod_map_keys, remaining) = u8::try_parse(remaining)?;
7759 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
7760 let (virtual_mods, remaining) = u16::try_parse(remaining)?;
7761 let (map, remaining) = GetMapMap::try_parse(remaining, present, n_types, n_key_syms, n_key_actions, total_actions, total_key_behaviors, virtual_mods, total_key_explicit, total_mod_map_keys, total_v_mod_map_keys)?;
7762 if response_type != 1 {
7763 return Err(ParseError::InvalidValue);
7764 }
7765 let result = GetMapReply { device_id, sequence, length, min_key_code, max_key_code, first_type, n_types, total_types, first_key_sym, total_syms, n_key_syms, first_key_action, total_actions, n_key_actions, first_key_behavior, n_key_behaviors, total_key_behaviors, first_key_explicit, n_key_explicit, total_key_explicit, first_mod_map_key, n_mod_map_keys, total_mod_map_keys, first_v_mod_map_key, n_v_mod_map_keys, total_v_mod_map_keys, virtual_mods, map };
7766 let _ = remaining;
7767 let remaining = initial_value.get(32 + length as usize * 4..)
7768 .ok_or(ParseError::InsufficientData)?;
7769 Ok((result, remaining))
7770 }
7771 }
7772
7773 #[derive(Debug, Clone)]
7774 pub struct SetMapAuxBitcase3 {
7775 pub actions_count: Vec<u8>,
7776 pub actions: Vec<Action>,
7777 }
7778 impl SetMapAuxBitcase3 {
try_parse(remaining: &[u8], n_key_actions: u8, total_actions: u16) -> Result<(Self, &[u8]), ParseError>7779 pub fn try_parse(remaining: &[u8], n_key_actions: u8, total_actions: u16) -> Result<(Self, &[u8]), ParseError> {
7780 let value = remaining;
7781 let (actions_count, remaining) = crate::x11_utils::parse_u8_list(remaining, n_key_actions.try_to_usize()?)?;
7782 let actions_count = actions_count.to_vec();
7783 // Align offset to multiple of 4
7784 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
7785 let misalignment = (4 - (offset % 4)) % 4;
7786 let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
7787 let (actions, remaining) = crate::x11_utils::parse_list::<Action>(remaining, total_actions.try_to_usize()?)?;
7788 let result = SetMapAuxBitcase3 { actions_count, actions };
7789 Ok((result, remaining))
7790 }
7791 }
7792 impl SetMapAuxBitcase3 {
7793 #[allow(dead_code)]
serialize(&self, n_key_actions: u8, total_actions: u16) -> Vec<u8>7794 fn serialize(&self, n_key_actions: u8, total_actions: u16) -> Vec<u8> {
7795 let mut result = Vec::new();
7796 self.serialize_into(&mut result, n_key_actions, total_actions);
7797 result
7798 }
serialize_into(&self, bytes: &mut Vec<u8>, n_key_actions: u8, total_actions: u16)7799 fn serialize_into(&self, bytes: &mut Vec<u8>, n_key_actions: u8, total_actions: u16) {
7800 assert_eq!(self.actions_count.len(), usize::try_from(n_key_actions).unwrap(), "`actions_count` has an incorrect length");
7801 bytes.extend_from_slice(&self.actions_count);
7802 bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]);
7803 assert_eq!(self.actions.len(), usize::try_from(total_actions).unwrap(), "`actions` has an incorrect length");
7804 self.actions.serialize_into(bytes);
7805 }
7806 }
7807 /// Auxiliary and optional information for the `set_map` function
7808 #[derive(Debug, Clone, Default)]
7809 pub struct SetMapAux {
7810 pub types: Option<Vec<SetKeyType>>,
7811 pub syms: Option<Vec<KeySymMap>>,
7812 pub bitcase3: Option<SetMapAuxBitcase3>,
7813 pub behaviors: Option<Vec<SetBehavior>>,
7814 pub vmods: Option<Vec<u8>>,
7815 pub explicit: Option<Vec<SetExplicit>>,
7816 pub modmap: Option<Vec<KeyModMap>>,
7817 pub vmodmap: Option<Vec<KeyVModMap>>,
7818 }
7819 impl SetMapAux {
try_parse(value: &[u8], present: u16, n_types: u8, n_key_syms: u8, n_key_actions: u8, total_actions: u16, total_key_behaviors: u8, virtual_mods: u16, total_key_explicit: u8, total_mod_map_keys: u8, total_v_mod_map_keys: u8) -> Result<(Self, &[u8]), ParseError>7820 fn try_parse(value: &[u8], present: u16, n_types: u8, n_key_syms: u8, n_key_actions: u8, total_actions: u16, total_key_behaviors: u8, virtual_mods: u16, total_key_explicit: u8, total_mod_map_keys: u8, total_v_mod_map_keys: u8) -> Result<(Self, &[u8]), ParseError> {
7821 let switch_expr = u32::from(present);
7822 let mut outer_remaining = value;
7823 let types = if switch_expr & u32::from(MapPart::KEY_TYPES) != 0 {
7824 let remaining = outer_remaining;
7825 let (types, remaining) = crate::x11_utils::parse_list::<SetKeyType>(remaining, n_types.try_to_usize()?)?;
7826 outer_remaining = remaining;
7827 Some(types)
7828 } else {
7829 None
7830 };
7831 let syms = if switch_expr & u32::from(MapPart::KEY_SYMS) != 0 {
7832 let remaining = outer_remaining;
7833 let (syms, remaining) = crate::x11_utils::parse_list::<KeySymMap>(remaining, n_key_syms.try_to_usize()?)?;
7834 outer_remaining = remaining;
7835 Some(syms)
7836 } else {
7837 None
7838 };
7839 let bitcase3 = if switch_expr & u32::from(MapPart::KEY_ACTIONS) != 0 {
7840 let (bitcase3, new_remaining) = SetMapAuxBitcase3::try_parse(outer_remaining, n_key_actions, total_actions)?;
7841 outer_remaining = new_remaining;
7842 Some(bitcase3)
7843 } else {
7844 None
7845 };
7846 let behaviors = if switch_expr & u32::from(MapPart::KEY_BEHAVIORS) != 0 {
7847 let remaining = outer_remaining;
7848 let (behaviors, remaining) = crate::x11_utils::parse_list::<SetBehavior>(remaining, total_key_behaviors.try_to_usize()?)?;
7849 outer_remaining = remaining;
7850 Some(behaviors)
7851 } else {
7852 None
7853 };
7854 let vmods = if switch_expr & u32::from(MapPart::VIRTUAL_MODS) != 0 {
7855 let remaining = outer_remaining;
7856 let value = remaining;
7857 let (vmods, remaining) = crate::x11_utils::parse_u8_list(remaining, virtual_mods.count_ones().try_to_usize()?)?;
7858 let vmods = vmods.to_vec();
7859 // Align offset to multiple of 4
7860 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
7861 let misalignment = (4 - (offset % 4)) % 4;
7862 let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
7863 outer_remaining = remaining;
7864 Some(vmods)
7865 } else {
7866 None
7867 };
7868 let explicit = if switch_expr & u32::from(MapPart::EXPLICIT_COMPONENTS) != 0 {
7869 let remaining = outer_remaining;
7870 let (explicit, remaining) = crate::x11_utils::parse_list::<SetExplicit>(remaining, total_key_explicit.try_to_usize()?)?;
7871 outer_remaining = remaining;
7872 Some(explicit)
7873 } else {
7874 None
7875 };
7876 let modmap = if switch_expr & u32::from(MapPart::MODIFIER_MAP) != 0 {
7877 let remaining = outer_remaining;
7878 let (modmap, remaining) = crate::x11_utils::parse_list::<KeyModMap>(remaining, total_mod_map_keys.try_to_usize()?)?;
7879 outer_remaining = remaining;
7880 Some(modmap)
7881 } else {
7882 None
7883 };
7884 let vmodmap = if switch_expr & u32::from(MapPart::VIRTUAL_MOD_MAP) != 0 {
7885 let remaining = outer_remaining;
7886 let (vmodmap, remaining) = crate::x11_utils::parse_list::<KeyVModMap>(remaining, total_v_mod_map_keys.try_to_usize()?)?;
7887 outer_remaining = remaining;
7888 Some(vmodmap)
7889 } else {
7890 None
7891 };
7892 let result = SetMapAux { types, syms, bitcase3, behaviors, vmods, explicit, modmap, vmodmap };
7893 Ok((result, outer_remaining))
7894 }
7895 }
7896 impl SetMapAux {
7897 #[allow(dead_code)]
serialize(&self, present: u16, n_types: u8, n_key_syms: u8, n_key_actions: u8, total_actions: u16, total_key_behaviors: u8, virtual_mods: u16, total_key_explicit: u8, total_mod_map_keys: u8, total_v_mod_map_keys: u8) -> Vec<u8>7898 fn serialize(&self, present: u16, n_types: u8, n_key_syms: u8, n_key_actions: u8, total_actions: u16, total_key_behaviors: u8, virtual_mods: u16, total_key_explicit: u8, total_mod_map_keys: u8, total_v_mod_map_keys: u8) -> Vec<u8> {
7899 let mut result = Vec::new();
7900 self.serialize_into(&mut result, present, n_types, n_key_syms, n_key_actions, total_actions, total_key_behaviors, virtual_mods, total_key_explicit, total_mod_map_keys, total_v_mod_map_keys);
7901 result
7902 }
serialize_into(&self, bytes: &mut Vec<u8>, present: u16, n_types: u8, n_key_syms: u8, n_key_actions: u8, total_actions: u16, total_key_behaviors: u8, virtual_mods: u16, total_key_explicit: u8, total_mod_map_keys: u8, total_v_mod_map_keys: u8)7903 fn serialize_into(&self, bytes: &mut Vec<u8>, present: u16, n_types: u8, n_key_syms: u8, n_key_actions: u8, total_actions: u16, total_key_behaviors: u8, virtual_mods: u16, total_key_explicit: u8, total_mod_map_keys: u8, total_v_mod_map_keys: u8) {
7904 assert_eq!(self.switch_expr(), u32::from(present), "switch `values` has an inconsistent discriminant");
7905 if let Some(ref types) = self.types {
7906 assert_eq!(types.len(), usize::try_from(n_types).unwrap(), "`types` has an incorrect length");
7907 types.serialize_into(bytes);
7908 }
7909 if let Some(ref syms) = self.syms {
7910 assert_eq!(syms.len(), usize::try_from(n_key_syms).unwrap(), "`syms` has an incorrect length");
7911 syms.serialize_into(bytes);
7912 }
7913 if let Some(ref bitcase3) = self.bitcase3 {
7914 bitcase3.serialize_into(bytes, n_key_actions, total_actions);
7915 }
7916 if let Some(ref behaviors) = self.behaviors {
7917 assert_eq!(behaviors.len(), usize::try_from(total_key_behaviors).unwrap(), "`behaviors` has an incorrect length");
7918 behaviors.serialize_into(bytes);
7919 }
7920 if let Some(ref vmods) = self.vmods {
7921 assert_eq!(vmods.len(), usize::try_from(virtual_mods.count_ones()).unwrap(), "`vmods` has an incorrect length");
7922 bytes.extend_from_slice(&vmods);
7923 bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]);
7924 }
7925 if let Some(ref explicit) = self.explicit {
7926 assert_eq!(explicit.len(), usize::try_from(total_key_explicit).unwrap(), "`explicit` has an incorrect length");
7927 explicit.serialize_into(bytes);
7928 }
7929 if let Some(ref modmap) = self.modmap {
7930 assert_eq!(modmap.len(), usize::try_from(total_mod_map_keys).unwrap(), "`modmap` has an incorrect length");
7931 modmap.serialize_into(bytes);
7932 }
7933 if let Some(ref vmodmap) = self.vmodmap {
7934 assert_eq!(vmodmap.len(), usize::try_from(total_v_mod_map_keys).unwrap(), "`vmodmap` has an incorrect length");
7935 vmodmap.serialize_into(bytes);
7936 }
7937 }
7938 }
7939 impl SetMapAux {
switch_expr(&self) -> u327940 fn switch_expr(&self) -> u32 {
7941 let mut expr_value = 0;
7942 if self.types.is_some() {
7943 expr_value |= u32::from(MapPart::KEY_TYPES);
7944 }
7945 if self.syms.is_some() {
7946 expr_value |= u32::from(MapPart::KEY_SYMS);
7947 }
7948 if self.bitcase3.is_some() {
7949 expr_value |= u32::from(MapPart::KEY_ACTIONS);
7950 }
7951 if self.behaviors.is_some() {
7952 expr_value |= u32::from(MapPart::KEY_BEHAVIORS);
7953 }
7954 if self.vmods.is_some() {
7955 expr_value |= u32::from(MapPart::VIRTUAL_MODS);
7956 }
7957 if self.explicit.is_some() {
7958 expr_value |= u32::from(MapPart::EXPLICIT_COMPONENTS);
7959 }
7960 if self.modmap.is_some() {
7961 expr_value |= u32::from(MapPart::MODIFIER_MAP);
7962 }
7963 if self.vmodmap.is_some() {
7964 expr_value |= u32::from(MapPart::VIRTUAL_MOD_MAP);
7965 }
7966 expr_value
7967 }
7968 }
7969 impl SetMapAux {
7970 /// Create a new instance with all fields unset / not present.
new() -> Self7971 pub fn new() -> Self {
7972 Default::default()
7973 }
7974 /// Set the `types` field of this structure.
types<I>(mut self, value: I) -> Self where I: Into<Option<Vec<SetKeyType>>>7975 pub fn types<I>(mut self, value: I) -> Self where I: Into<Option<Vec<SetKeyType>>> {
7976 self.types = value.into();
7977 self
7978 }
7979 /// Set the `syms` field of this structure.
syms<I>(mut self, value: I) -> Self where I: Into<Option<Vec<KeySymMap>>>7980 pub fn syms<I>(mut self, value: I) -> Self where I: Into<Option<Vec<KeySymMap>>> {
7981 self.syms = value.into();
7982 self
7983 }
7984 /// Set the `bitcase3` field of this structure.
bitcase3<I>(mut self, value: I) -> Self where I: Into<Option<SetMapAuxBitcase3>>7985 pub fn bitcase3<I>(mut self, value: I) -> Self where I: Into<Option<SetMapAuxBitcase3>> {
7986 self.bitcase3 = value.into();
7987 self
7988 }
7989 /// Set the `behaviors` field of this structure.
behaviors<I>(mut self, value: I) -> Self where I: Into<Option<Vec<SetBehavior>>>7990 pub fn behaviors<I>(mut self, value: I) -> Self where I: Into<Option<Vec<SetBehavior>>> {
7991 self.behaviors = value.into();
7992 self
7993 }
7994 /// Set the `vmods` field of this structure.
vmods<I>(mut self, value: I) -> Self where I: Into<Option<Vec<u8>>>7995 pub fn vmods<I>(mut self, value: I) -> Self where I: Into<Option<Vec<u8>>> {
7996 self.vmods = value.into();
7997 self
7998 }
7999 /// Set the `explicit` field of this structure.
explicit<I>(mut self, value: I) -> Self where I: Into<Option<Vec<SetExplicit>>>8000 pub fn explicit<I>(mut self, value: I) -> Self where I: Into<Option<Vec<SetExplicit>>> {
8001 self.explicit = value.into();
8002 self
8003 }
8004 /// Set the `modmap` field of this structure.
modmap<I>(mut self, value: I) -> Self where I: Into<Option<Vec<KeyModMap>>>8005 pub fn modmap<I>(mut self, value: I) -> Self where I: Into<Option<Vec<KeyModMap>>> {
8006 self.modmap = value.into();
8007 self
8008 }
8009 /// Set the `vmodmap` field of this structure.
vmodmap<I>(mut self, value: I) -> Self where I: Into<Option<Vec<KeyVModMap>>>8010 pub fn vmodmap<I>(mut self, value: I) -> Self where I: Into<Option<Vec<KeyVModMap>>> {
8011 self.vmodmap = value.into();
8012 self
8013 }
8014 }
8015
8016 /// Opcode for the SetMap request
8017 pub const SET_MAP_REQUEST: u8 = 9;
8018 #[derive(Debug, Clone)]
8019 pub struct SetMapRequest<'input> {
8020 pub device_spec: DeviceSpec,
8021 pub flags: u16,
8022 pub min_key_code: xproto::Keycode,
8023 pub max_key_code: xproto::Keycode,
8024 pub first_type: u8,
8025 pub n_types: u8,
8026 pub first_key_sym: xproto::Keycode,
8027 pub n_key_syms: u8,
8028 pub total_syms: u16,
8029 pub first_key_action: xproto::Keycode,
8030 pub n_key_actions: u8,
8031 pub total_actions: u16,
8032 pub first_key_behavior: xproto::Keycode,
8033 pub n_key_behaviors: u8,
8034 pub total_key_behaviors: u8,
8035 pub first_key_explicit: xproto::Keycode,
8036 pub n_key_explicit: u8,
8037 pub total_key_explicit: u8,
8038 pub first_mod_map_key: xproto::Keycode,
8039 pub n_mod_map_keys: u8,
8040 pub total_mod_map_keys: u8,
8041 pub first_v_mod_map_key: xproto::Keycode,
8042 pub n_v_mod_map_keys: u8,
8043 pub total_v_mod_map_keys: u8,
8044 pub virtual_mods: u16,
8045 pub values: Cow<'input, SetMapAux>,
8046 }
8047 impl<'input> SetMapRequest<'input> {
8048 /// Serialize this request into bytes for the provided connection
serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,8049 fn serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
8050 where
8051 Conn: RequestConnection + ?Sized,
8052 {
8053 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
8054 .ok_or(ConnectionError::UnsupportedExtension)?;
8055 let length_so_far = 0;
8056 let device_spec_bytes = self.device_spec.serialize();
8057 let present = u16::try_from(self.values.switch_expr()).unwrap();
8058 let present_bytes = present.serialize();
8059 let flags_bytes = self.flags.serialize();
8060 let min_key_code_bytes = self.min_key_code.serialize();
8061 let max_key_code_bytes = self.max_key_code.serialize();
8062 let first_type_bytes = self.first_type.serialize();
8063 let n_types_bytes = self.n_types.serialize();
8064 let first_key_sym_bytes = self.first_key_sym.serialize();
8065 let n_key_syms_bytes = self.n_key_syms.serialize();
8066 let total_syms_bytes = self.total_syms.serialize();
8067 let first_key_action_bytes = self.first_key_action.serialize();
8068 let n_key_actions_bytes = self.n_key_actions.serialize();
8069 let total_actions_bytes = self.total_actions.serialize();
8070 let first_key_behavior_bytes = self.first_key_behavior.serialize();
8071 let n_key_behaviors_bytes = self.n_key_behaviors.serialize();
8072 let total_key_behaviors_bytes = self.total_key_behaviors.serialize();
8073 let first_key_explicit_bytes = self.first_key_explicit.serialize();
8074 let n_key_explicit_bytes = self.n_key_explicit.serialize();
8075 let total_key_explicit_bytes = self.total_key_explicit.serialize();
8076 let first_mod_map_key_bytes = self.first_mod_map_key.serialize();
8077 let n_mod_map_keys_bytes = self.n_mod_map_keys.serialize();
8078 let total_mod_map_keys_bytes = self.total_mod_map_keys.serialize();
8079 let first_v_mod_map_key_bytes = self.first_v_mod_map_key.serialize();
8080 let n_v_mod_map_keys_bytes = self.n_v_mod_map_keys.serialize();
8081 let total_v_mod_map_keys_bytes = self.total_v_mod_map_keys.serialize();
8082 let virtual_mods_bytes = self.virtual_mods.serialize();
8083 let mut request0 = vec![
8084 extension_information.major_opcode,
8085 SET_MAP_REQUEST,
8086 0,
8087 0,
8088 device_spec_bytes[0],
8089 device_spec_bytes[1],
8090 present_bytes[0],
8091 present_bytes[1],
8092 flags_bytes[0],
8093 flags_bytes[1],
8094 min_key_code_bytes[0],
8095 max_key_code_bytes[0],
8096 first_type_bytes[0],
8097 n_types_bytes[0],
8098 first_key_sym_bytes[0],
8099 n_key_syms_bytes[0],
8100 total_syms_bytes[0],
8101 total_syms_bytes[1],
8102 first_key_action_bytes[0],
8103 n_key_actions_bytes[0],
8104 total_actions_bytes[0],
8105 total_actions_bytes[1],
8106 first_key_behavior_bytes[0],
8107 n_key_behaviors_bytes[0],
8108 total_key_behaviors_bytes[0],
8109 first_key_explicit_bytes[0],
8110 n_key_explicit_bytes[0],
8111 total_key_explicit_bytes[0],
8112 first_mod_map_key_bytes[0],
8113 n_mod_map_keys_bytes[0],
8114 total_mod_map_keys_bytes[0],
8115 first_v_mod_map_key_bytes[0],
8116 n_v_mod_map_keys_bytes[0],
8117 total_v_mod_map_keys_bytes[0],
8118 virtual_mods_bytes[0],
8119 virtual_mods_bytes[1],
8120 ];
8121 let length_so_far = length_so_far + request0.len();
8122 let values_bytes = self.values.serialize(present, self.n_types, self.n_key_syms, self.n_key_actions, self.total_actions, self.total_key_behaviors, self.virtual_mods, self.total_key_explicit, self.total_mod_map_keys, self.total_v_mod_map_keys);
8123 let length_so_far = length_so_far + values_bytes.len();
8124 let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
8125 let length_so_far = length_so_far + padding0.len();
8126 assert_eq!(length_so_far % 4, 0);
8127 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
8128 request0[2..4].copy_from_slice(&length.to_ne_bytes());
8129 Ok((vec![request0.into(), values_bytes.into(), padding0.into()], vec![]))
8130 }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,8131 pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
8132 where
8133 Conn: RequestConnection + ?Sized,
8134 {
8135 let (bytes, fds) = self.serialize(conn)?;
8136 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
8137 conn.send_request_without_reply(&slices, fds)
8138 }
8139 /// 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>8140 pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
8141 if header.minor_opcode != SET_MAP_REQUEST {
8142 return Err(ParseError::InvalidValue);
8143 }
8144 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
8145 let (present, remaining) = u16::try_parse(remaining)?;
8146 let (flags, remaining) = u16::try_parse(remaining)?;
8147 let (min_key_code, remaining) = xproto::Keycode::try_parse(remaining)?;
8148 let (max_key_code, remaining) = xproto::Keycode::try_parse(remaining)?;
8149 let (first_type, remaining) = u8::try_parse(remaining)?;
8150 let (n_types, remaining) = u8::try_parse(remaining)?;
8151 let (first_key_sym, remaining) = xproto::Keycode::try_parse(remaining)?;
8152 let (n_key_syms, remaining) = u8::try_parse(remaining)?;
8153 let (total_syms, remaining) = u16::try_parse(remaining)?;
8154 let (first_key_action, remaining) = xproto::Keycode::try_parse(remaining)?;
8155 let (n_key_actions, remaining) = u8::try_parse(remaining)?;
8156 let (total_actions, remaining) = u16::try_parse(remaining)?;
8157 let (first_key_behavior, remaining) = xproto::Keycode::try_parse(remaining)?;
8158 let (n_key_behaviors, remaining) = u8::try_parse(remaining)?;
8159 let (total_key_behaviors, remaining) = u8::try_parse(remaining)?;
8160 let (first_key_explicit, remaining) = xproto::Keycode::try_parse(remaining)?;
8161 let (n_key_explicit, remaining) = u8::try_parse(remaining)?;
8162 let (total_key_explicit, remaining) = u8::try_parse(remaining)?;
8163 let (first_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?;
8164 let (n_mod_map_keys, remaining) = u8::try_parse(remaining)?;
8165 let (total_mod_map_keys, remaining) = u8::try_parse(remaining)?;
8166 let (first_v_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?;
8167 let (n_v_mod_map_keys, remaining) = u8::try_parse(remaining)?;
8168 let (total_v_mod_map_keys, remaining) = u8::try_parse(remaining)?;
8169 let (virtual_mods, remaining) = u16::try_parse(remaining)?;
8170 let (values, remaining) = SetMapAux::try_parse(remaining, present, n_types, n_key_syms, n_key_actions, total_actions, total_key_behaviors, virtual_mods, total_key_explicit, total_mod_map_keys, total_v_mod_map_keys)?;
8171 let _ = remaining;
8172 Ok(SetMapRequest {
8173 device_spec,
8174 flags,
8175 min_key_code,
8176 max_key_code,
8177 first_type,
8178 n_types,
8179 first_key_sym,
8180 n_key_syms,
8181 total_syms,
8182 first_key_action,
8183 n_key_actions,
8184 total_actions,
8185 first_key_behavior,
8186 n_key_behaviors,
8187 total_key_behaviors,
8188 first_key_explicit,
8189 n_key_explicit,
8190 total_key_explicit,
8191 first_mod_map_key,
8192 n_mod_map_keys,
8193 total_mod_map_keys,
8194 first_v_mod_map_key,
8195 n_v_mod_map_keys,
8196 total_v_mod_map_keys,
8197 virtual_mods,
8198 values: Cow::Owned(values),
8199 })
8200 }
8201 /// Clone all borrowed data in this SetMapRequest.
into_owned(self) -> SetMapRequest<'static>8202 pub fn into_owned(self) -> SetMapRequest<'static> {
8203 SetMapRequest {
8204 device_spec: self.device_spec,
8205 flags: self.flags,
8206 min_key_code: self.min_key_code,
8207 max_key_code: self.max_key_code,
8208 first_type: self.first_type,
8209 n_types: self.n_types,
8210 first_key_sym: self.first_key_sym,
8211 n_key_syms: self.n_key_syms,
8212 total_syms: self.total_syms,
8213 first_key_action: self.first_key_action,
8214 n_key_actions: self.n_key_actions,
8215 total_actions: self.total_actions,
8216 first_key_behavior: self.first_key_behavior,
8217 n_key_behaviors: self.n_key_behaviors,
8218 total_key_behaviors: self.total_key_behaviors,
8219 first_key_explicit: self.first_key_explicit,
8220 n_key_explicit: self.n_key_explicit,
8221 total_key_explicit: self.total_key_explicit,
8222 first_mod_map_key: self.first_mod_map_key,
8223 n_mod_map_keys: self.n_mod_map_keys,
8224 total_mod_map_keys: self.total_mod_map_keys,
8225 first_v_mod_map_key: self.first_v_mod_map_key,
8226 n_v_mod_map_keys: self.n_v_mod_map_keys,
8227 total_v_mod_map_keys: self.total_v_mod_map_keys,
8228 virtual_mods: self.virtual_mods,
8229 values: Cow::Owned(self.values.into_owned()),
8230 }
8231 }
8232 }
8233 impl<'input> Request for SetMapRequest<'input> {
8234 type Reply = ();
8235 }
set_map<'c, 'input, Conn, A, B>(conn: &'c Conn, device_spec: DeviceSpec, flags: A, min_key_code: xproto::Keycode, max_key_code: xproto::Keycode, first_type: u8, n_types: u8, first_key_sym: xproto::Keycode, n_key_syms: u8, total_syms: u16, first_key_action: xproto::Keycode, n_key_actions: u8, total_actions: u16, first_key_behavior: xproto::Keycode, n_key_behaviors: u8, total_key_behaviors: u8, first_key_explicit: xproto::Keycode, n_key_explicit: u8, total_key_explicit: u8, first_mod_map_key: xproto::Keycode, n_mod_map_keys: u8, total_mod_map_keys: u8, first_v_mod_map_key: xproto::Keycode, n_v_mod_map_keys: u8, total_v_mod_map_keys: u8, virtual_mods: B, values: &'input SetMapAux) -> Result<VoidCookie<'c, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<u16>, B: Into<u16>,8236 pub fn set_map<'c, 'input, Conn, A, B>(conn: &'c Conn, device_spec: DeviceSpec, flags: A, min_key_code: xproto::Keycode, max_key_code: xproto::Keycode, first_type: u8, n_types: u8, first_key_sym: xproto::Keycode, n_key_syms: u8, total_syms: u16, first_key_action: xproto::Keycode, n_key_actions: u8, total_actions: u16, first_key_behavior: xproto::Keycode, n_key_behaviors: u8, total_key_behaviors: u8, first_key_explicit: xproto::Keycode, n_key_explicit: u8, total_key_explicit: u8, first_mod_map_key: xproto::Keycode, n_mod_map_keys: u8, total_mod_map_keys: u8, first_v_mod_map_key: xproto::Keycode, n_v_mod_map_keys: u8, total_v_mod_map_keys: u8, virtual_mods: B, values: &'input SetMapAux) -> Result<VoidCookie<'c, Conn>, ConnectionError>
8237 where
8238 Conn: RequestConnection + ?Sized,
8239 A: Into<u16>,
8240 B: Into<u16>,
8241 {
8242 let flags: u16 = flags.into();
8243 let virtual_mods: u16 = virtual_mods.into();
8244 let request0 = SetMapRequest {
8245 device_spec,
8246 flags,
8247 min_key_code,
8248 max_key_code,
8249 first_type,
8250 n_types,
8251 first_key_sym,
8252 n_key_syms,
8253 total_syms,
8254 first_key_action,
8255 n_key_actions,
8256 total_actions,
8257 first_key_behavior,
8258 n_key_behaviors,
8259 total_key_behaviors,
8260 first_key_explicit,
8261 n_key_explicit,
8262 total_key_explicit,
8263 first_mod_map_key,
8264 n_mod_map_keys,
8265 total_mod_map_keys,
8266 first_v_mod_map_key,
8267 n_v_mod_map_keys,
8268 total_v_mod_map_keys,
8269 virtual_mods,
8270 values: Cow::Borrowed(values),
8271 };
8272 request0.send(conn)
8273 }
8274
8275 /// Opcode for the GetCompatMap request
8276 pub const GET_COMPAT_MAP_REQUEST: u8 = 10;
8277 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
8278 pub struct GetCompatMapRequest {
8279 pub device_spec: DeviceSpec,
8280 pub groups: u8,
8281 pub get_all_si: bool,
8282 pub first_si: u16,
8283 pub n_si: u16,
8284 }
8285 impl GetCompatMapRequest {
8286 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,8287 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
8288 where
8289 Conn: RequestConnection + ?Sized,
8290 {
8291 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
8292 .ok_or(ConnectionError::UnsupportedExtension)?;
8293 let length_so_far = 0;
8294 let device_spec_bytes = self.device_spec.serialize();
8295 let groups_bytes = self.groups.serialize();
8296 let get_all_si_bytes = self.get_all_si.serialize();
8297 let first_si_bytes = self.first_si.serialize();
8298 let n_si_bytes = self.n_si.serialize();
8299 let mut request0 = vec![
8300 extension_information.major_opcode,
8301 GET_COMPAT_MAP_REQUEST,
8302 0,
8303 0,
8304 device_spec_bytes[0],
8305 device_spec_bytes[1],
8306 groups_bytes[0],
8307 get_all_si_bytes[0],
8308 first_si_bytes[0],
8309 first_si_bytes[1],
8310 n_si_bytes[0],
8311 n_si_bytes[1],
8312 ];
8313 let length_so_far = length_so_far + request0.len();
8314 assert_eq!(length_so_far % 4, 0);
8315 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
8316 request0[2..4].copy_from_slice(&length.to_ne_bytes());
8317 Ok((vec![request0.into()], vec![]))
8318 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetCompatMapReply>, ConnectionError> where Conn: RequestConnection + ?Sized,8319 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetCompatMapReply>, ConnectionError>
8320 where
8321 Conn: RequestConnection + ?Sized,
8322 {
8323 let (bytes, fds) = self.serialize(conn)?;
8324 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
8325 conn.send_request_with_reply(&slices, fds)
8326 }
8327 /// 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>8328 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
8329 if header.minor_opcode != GET_COMPAT_MAP_REQUEST {
8330 return Err(ParseError::InvalidValue);
8331 }
8332 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
8333 let (groups, remaining) = u8::try_parse(remaining)?;
8334 let (get_all_si, remaining) = bool::try_parse(remaining)?;
8335 let (first_si, remaining) = u16::try_parse(remaining)?;
8336 let (n_si, remaining) = u16::try_parse(remaining)?;
8337 let _ = remaining;
8338 Ok(GetCompatMapRequest {
8339 device_spec,
8340 groups,
8341 get_all_si,
8342 first_si,
8343 n_si,
8344 })
8345 }
8346 }
8347 impl Request for GetCompatMapRequest {
8348 type Reply = GetCompatMapReply;
8349 }
get_compat_map<Conn, A>(conn: &Conn, device_spec: DeviceSpec, groups: A, get_all_si: bool, first_si: u16, n_si: u16) -> Result<Cookie<'_, Conn, GetCompatMapReply>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<u8>,8350 pub fn get_compat_map<Conn, A>(conn: &Conn, device_spec: DeviceSpec, groups: A, get_all_si: bool, first_si: u16, n_si: u16) -> Result<Cookie<'_, Conn, GetCompatMapReply>, ConnectionError>
8351 where
8352 Conn: RequestConnection + ?Sized,
8353 A: Into<u8>,
8354 {
8355 let groups: u8 = groups.into();
8356 let request0 = GetCompatMapRequest {
8357 device_spec,
8358 groups,
8359 get_all_si,
8360 first_si,
8361 n_si,
8362 };
8363 request0.send(conn)
8364 }
8365
8366 #[derive(Debug, Clone, PartialEq, Eq)]
8367 pub struct GetCompatMapReply {
8368 pub device_id: u8,
8369 pub sequence: u16,
8370 pub length: u32,
8371 pub groups_rtrn: u8,
8372 pub first_si_rtrn: u16,
8373 pub n_total_si: u16,
8374 pub si_rtrn: Vec<SymInterpret>,
8375 pub group_rtrn: Vec<ModDef>,
8376 }
8377 impl TryParse for GetCompatMapReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>8378 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
8379 let remaining = initial_value;
8380 let (response_type, remaining) = u8::try_parse(remaining)?;
8381 let (device_id, remaining) = u8::try_parse(remaining)?;
8382 let (sequence, remaining) = u16::try_parse(remaining)?;
8383 let (length, remaining) = u32::try_parse(remaining)?;
8384 let (groups_rtrn, remaining) = u8::try_parse(remaining)?;
8385 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
8386 let (first_si_rtrn, remaining) = u16::try_parse(remaining)?;
8387 let (n_si_rtrn, remaining) = u16::try_parse(remaining)?;
8388 let (n_total_si, remaining) = u16::try_parse(remaining)?;
8389 let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?;
8390 let (si_rtrn, remaining) = crate::x11_utils::parse_list::<SymInterpret>(remaining, n_si_rtrn.try_to_usize()?)?;
8391 let (group_rtrn, remaining) = crate::x11_utils::parse_list::<ModDef>(remaining, groups_rtrn.count_ones().try_to_usize()?)?;
8392 if response_type != 1 {
8393 return Err(ParseError::InvalidValue);
8394 }
8395 let result = GetCompatMapReply { device_id, sequence, length, groups_rtrn, first_si_rtrn, n_total_si, si_rtrn, group_rtrn };
8396 let _ = remaining;
8397 let remaining = initial_value.get(32 + length as usize * 4..)
8398 .ok_or(ParseError::InsufficientData)?;
8399 Ok((result, remaining))
8400 }
8401 }
8402 impl GetCompatMapReply {
8403 /// Get the value of the `nSIRtrn` field.
8404 ///
8405 /// The `nSIRtrn` field is used as the length field of the `si_rtrn` field.
8406 /// This function computes the field's value again based on the length of the list.
8407 ///
8408 /// # Panics
8409 ///
8410 /// Panics if the value cannot be represented in the target type. This
8411 /// cannot happen with values of the struct received from the X11 server.
n_si_rtrn(&self) -> u168412 pub fn n_si_rtrn(&self) -> u16 {
8413 self.si_rtrn.len()
8414 .try_into().unwrap()
8415 }
8416 }
8417
8418 /// Opcode for the SetCompatMap request
8419 pub const SET_COMPAT_MAP_REQUEST: u8 = 11;
8420 #[derive(Debug, Clone, PartialEq, Eq)]
8421 pub struct SetCompatMapRequest<'input> {
8422 pub device_spec: DeviceSpec,
8423 pub recompute_actions: bool,
8424 pub truncate_si: bool,
8425 pub groups: u8,
8426 pub first_si: u16,
8427 pub si: Cow<'input, [SymInterpret]>,
8428 pub group_maps: Cow<'input, [ModDef]>,
8429 }
8430 impl<'input> SetCompatMapRequest<'input> {
8431 /// Serialize this request into bytes for the provided connection
serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,8432 fn serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
8433 where
8434 Conn: RequestConnection + ?Sized,
8435 {
8436 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
8437 .ok_or(ConnectionError::UnsupportedExtension)?;
8438 let length_so_far = 0;
8439 let device_spec_bytes = self.device_spec.serialize();
8440 let recompute_actions_bytes = self.recompute_actions.serialize();
8441 let truncate_si_bytes = self.truncate_si.serialize();
8442 let groups_bytes = self.groups.serialize();
8443 let first_si_bytes = self.first_si.serialize();
8444 let n_si = u16::try_from(self.si.len()).expect("`si` has too many elements");
8445 let n_si_bytes = n_si.serialize();
8446 let mut request0 = vec![
8447 extension_information.major_opcode,
8448 SET_COMPAT_MAP_REQUEST,
8449 0,
8450 0,
8451 device_spec_bytes[0],
8452 device_spec_bytes[1],
8453 0,
8454 recompute_actions_bytes[0],
8455 truncate_si_bytes[0],
8456 groups_bytes[0],
8457 first_si_bytes[0],
8458 first_si_bytes[1],
8459 n_si_bytes[0],
8460 n_si_bytes[1],
8461 0,
8462 0,
8463 ];
8464 let length_so_far = length_so_far + request0.len();
8465 let si_bytes = self.si.serialize();
8466 let length_so_far = length_so_far + si_bytes.len();
8467 assert_eq!(self.group_maps.len(), usize::try_from(self.groups.count_ones()).unwrap(), "`group_maps` has an incorrect length");
8468 let group_maps_bytes = self.group_maps.serialize();
8469 let length_so_far = length_so_far + group_maps_bytes.len();
8470 let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
8471 let length_so_far = length_so_far + padding0.len();
8472 assert_eq!(length_so_far % 4, 0);
8473 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
8474 request0[2..4].copy_from_slice(&length.to_ne_bytes());
8475 Ok((vec![request0.into(), si_bytes.into(), group_maps_bytes.into(), padding0.into()], vec![]))
8476 }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,8477 pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
8478 where
8479 Conn: RequestConnection + ?Sized,
8480 {
8481 let (bytes, fds) = self.serialize(conn)?;
8482 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
8483 conn.send_request_without_reply(&slices, fds)
8484 }
8485 /// 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>8486 pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
8487 if header.minor_opcode != SET_COMPAT_MAP_REQUEST {
8488 return Err(ParseError::InvalidValue);
8489 }
8490 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
8491 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
8492 let (recompute_actions, remaining) = bool::try_parse(remaining)?;
8493 let (truncate_si, remaining) = bool::try_parse(remaining)?;
8494 let (groups, remaining) = u8::try_parse(remaining)?;
8495 let (first_si, remaining) = u16::try_parse(remaining)?;
8496 let (n_si, remaining) = u16::try_parse(remaining)?;
8497 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
8498 let (si, remaining) = crate::x11_utils::parse_list::<SymInterpret>(remaining, n_si.try_to_usize()?)?;
8499 let (group_maps, remaining) = crate::x11_utils::parse_list::<ModDef>(remaining, groups.count_ones().try_to_usize()?)?;
8500 let _ = remaining;
8501 Ok(SetCompatMapRequest {
8502 device_spec,
8503 recompute_actions,
8504 truncate_si,
8505 groups,
8506 first_si,
8507 si: Cow::Owned(si),
8508 group_maps: Cow::Owned(group_maps),
8509 })
8510 }
8511 /// Clone all borrowed data in this SetCompatMapRequest.
into_owned(self) -> SetCompatMapRequest<'static>8512 pub fn into_owned(self) -> SetCompatMapRequest<'static> {
8513 SetCompatMapRequest {
8514 device_spec: self.device_spec,
8515 recompute_actions: self.recompute_actions,
8516 truncate_si: self.truncate_si,
8517 groups: self.groups,
8518 first_si: self.first_si,
8519 si: Cow::Owned(self.si.into_owned()),
8520 group_maps: Cow::Owned(self.group_maps.into_owned()),
8521 }
8522 }
8523 }
8524 impl<'input> Request for SetCompatMapRequest<'input> {
8525 type Reply = ();
8526 }
set_compat_map<'c, 'input, Conn, A>(conn: &'c Conn, device_spec: DeviceSpec, recompute_actions: bool, truncate_si: bool, groups: A, first_si: u16, si: &'input [SymInterpret], group_maps: &'input [ModDef]) -> Result<VoidCookie<'c, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<u8>,8527 pub fn set_compat_map<'c, 'input, Conn, A>(conn: &'c Conn, device_spec: DeviceSpec, recompute_actions: bool, truncate_si: bool, groups: A, first_si: u16, si: &'input [SymInterpret], group_maps: &'input [ModDef]) -> Result<VoidCookie<'c, Conn>, ConnectionError>
8528 where
8529 Conn: RequestConnection + ?Sized,
8530 A: Into<u8>,
8531 {
8532 let groups: u8 = groups.into();
8533 let request0 = SetCompatMapRequest {
8534 device_spec,
8535 recompute_actions,
8536 truncate_si,
8537 groups,
8538 first_si,
8539 si: Cow::Borrowed(si),
8540 group_maps: Cow::Borrowed(group_maps),
8541 };
8542 request0.send(conn)
8543 }
8544
8545 /// Opcode for the GetIndicatorState request
8546 pub const GET_INDICATOR_STATE_REQUEST: u8 = 12;
8547 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
8548 pub struct GetIndicatorStateRequest {
8549 pub device_spec: DeviceSpec,
8550 }
8551 impl GetIndicatorStateRequest {
8552 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,8553 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
8554 where
8555 Conn: RequestConnection + ?Sized,
8556 {
8557 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
8558 .ok_or(ConnectionError::UnsupportedExtension)?;
8559 let length_so_far = 0;
8560 let device_spec_bytes = self.device_spec.serialize();
8561 let mut request0 = vec![
8562 extension_information.major_opcode,
8563 GET_INDICATOR_STATE_REQUEST,
8564 0,
8565 0,
8566 device_spec_bytes[0],
8567 device_spec_bytes[1],
8568 0,
8569 0,
8570 ];
8571 let length_so_far = length_so_far + request0.len();
8572 assert_eq!(length_so_far % 4, 0);
8573 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
8574 request0[2..4].copy_from_slice(&length.to_ne_bytes());
8575 Ok((vec![request0.into()], vec![]))
8576 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetIndicatorStateReply>, ConnectionError> where Conn: RequestConnection + ?Sized,8577 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetIndicatorStateReply>, ConnectionError>
8578 where
8579 Conn: RequestConnection + ?Sized,
8580 {
8581 let (bytes, fds) = self.serialize(conn)?;
8582 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
8583 conn.send_request_with_reply(&slices, fds)
8584 }
8585 /// 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>8586 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
8587 if header.minor_opcode != GET_INDICATOR_STATE_REQUEST {
8588 return Err(ParseError::InvalidValue);
8589 }
8590 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
8591 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
8592 let _ = remaining;
8593 Ok(GetIndicatorStateRequest {
8594 device_spec,
8595 })
8596 }
8597 }
8598 impl Request for GetIndicatorStateRequest {
8599 type Reply = GetIndicatorStateReply;
8600 }
get_indicator_state<Conn>(conn: &Conn, device_spec: DeviceSpec) -> Result<Cookie<'_, Conn, GetIndicatorStateReply>, ConnectionError> where Conn: RequestConnection + ?Sized,8601 pub fn get_indicator_state<Conn>(conn: &Conn, device_spec: DeviceSpec) -> Result<Cookie<'_, Conn, GetIndicatorStateReply>, ConnectionError>
8602 where
8603 Conn: RequestConnection + ?Sized,
8604 {
8605 let request0 = GetIndicatorStateRequest {
8606 device_spec,
8607 };
8608 request0.send(conn)
8609 }
8610
8611 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
8612 pub struct GetIndicatorStateReply {
8613 pub device_id: u8,
8614 pub sequence: u16,
8615 pub length: u32,
8616 pub state: u32,
8617 }
8618 impl TryParse for GetIndicatorStateReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>8619 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
8620 let remaining = initial_value;
8621 let (response_type, remaining) = u8::try_parse(remaining)?;
8622 let (device_id, remaining) = u8::try_parse(remaining)?;
8623 let (sequence, remaining) = u16::try_parse(remaining)?;
8624 let (length, remaining) = u32::try_parse(remaining)?;
8625 let (state, remaining) = u32::try_parse(remaining)?;
8626 let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
8627 if response_type != 1 {
8628 return Err(ParseError::InvalidValue);
8629 }
8630 let result = GetIndicatorStateReply { device_id, sequence, length, state };
8631 let _ = remaining;
8632 let remaining = initial_value.get(32 + length as usize * 4..)
8633 .ok_or(ParseError::InsufficientData)?;
8634 Ok((result, remaining))
8635 }
8636 }
8637
8638 /// Opcode for the GetIndicatorMap request
8639 pub const GET_INDICATOR_MAP_REQUEST: u8 = 13;
8640 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
8641 pub struct GetIndicatorMapRequest {
8642 pub device_spec: DeviceSpec,
8643 pub which: u32,
8644 }
8645 impl GetIndicatorMapRequest {
8646 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,8647 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
8648 where
8649 Conn: RequestConnection + ?Sized,
8650 {
8651 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
8652 .ok_or(ConnectionError::UnsupportedExtension)?;
8653 let length_so_far = 0;
8654 let device_spec_bytes = self.device_spec.serialize();
8655 let which_bytes = self.which.serialize();
8656 let mut request0 = vec![
8657 extension_information.major_opcode,
8658 GET_INDICATOR_MAP_REQUEST,
8659 0,
8660 0,
8661 device_spec_bytes[0],
8662 device_spec_bytes[1],
8663 0,
8664 0,
8665 which_bytes[0],
8666 which_bytes[1],
8667 which_bytes[2],
8668 which_bytes[3],
8669 ];
8670 let length_so_far = length_so_far + request0.len();
8671 assert_eq!(length_so_far % 4, 0);
8672 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
8673 request0[2..4].copy_from_slice(&length.to_ne_bytes());
8674 Ok((vec![request0.into()], vec![]))
8675 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetIndicatorMapReply>, ConnectionError> where Conn: RequestConnection + ?Sized,8676 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetIndicatorMapReply>, ConnectionError>
8677 where
8678 Conn: RequestConnection + ?Sized,
8679 {
8680 let (bytes, fds) = self.serialize(conn)?;
8681 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
8682 conn.send_request_with_reply(&slices, fds)
8683 }
8684 /// 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>8685 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
8686 if header.minor_opcode != GET_INDICATOR_MAP_REQUEST {
8687 return Err(ParseError::InvalidValue);
8688 }
8689 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
8690 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
8691 let (which, remaining) = u32::try_parse(remaining)?;
8692 let _ = remaining;
8693 Ok(GetIndicatorMapRequest {
8694 device_spec,
8695 which,
8696 })
8697 }
8698 }
8699 impl Request for GetIndicatorMapRequest {
8700 type Reply = GetIndicatorMapReply;
8701 }
get_indicator_map<Conn>(conn: &Conn, device_spec: DeviceSpec, which: u32) -> Result<Cookie<'_, Conn, GetIndicatorMapReply>, ConnectionError> where Conn: RequestConnection + ?Sized,8702 pub fn get_indicator_map<Conn>(conn: &Conn, device_spec: DeviceSpec, which: u32) -> Result<Cookie<'_, Conn, GetIndicatorMapReply>, ConnectionError>
8703 where
8704 Conn: RequestConnection + ?Sized,
8705 {
8706 let request0 = GetIndicatorMapRequest {
8707 device_spec,
8708 which,
8709 };
8710 request0.send(conn)
8711 }
8712
8713 #[derive(Debug, Clone, PartialEq, Eq)]
8714 pub struct GetIndicatorMapReply {
8715 pub device_id: u8,
8716 pub sequence: u16,
8717 pub length: u32,
8718 pub which: u32,
8719 pub real_indicators: u32,
8720 pub n_indicators: u8,
8721 pub maps: Vec<IndicatorMap>,
8722 }
8723 impl TryParse for GetIndicatorMapReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>8724 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
8725 let remaining = initial_value;
8726 let (response_type, remaining) = u8::try_parse(remaining)?;
8727 let (device_id, remaining) = u8::try_parse(remaining)?;
8728 let (sequence, remaining) = u16::try_parse(remaining)?;
8729 let (length, remaining) = u32::try_parse(remaining)?;
8730 let (which, remaining) = u32::try_parse(remaining)?;
8731 let (real_indicators, remaining) = u32::try_parse(remaining)?;
8732 let (n_indicators, remaining) = u8::try_parse(remaining)?;
8733 let remaining = remaining.get(15..).ok_or(ParseError::InsufficientData)?;
8734 let (maps, remaining) = crate::x11_utils::parse_list::<IndicatorMap>(remaining, which.count_ones().try_to_usize()?)?;
8735 if response_type != 1 {
8736 return Err(ParseError::InvalidValue);
8737 }
8738 let result = GetIndicatorMapReply { device_id, sequence, length, which, real_indicators, n_indicators, maps };
8739 let _ = remaining;
8740 let remaining = initial_value.get(32 + length as usize * 4..)
8741 .ok_or(ParseError::InsufficientData)?;
8742 Ok((result, remaining))
8743 }
8744 }
8745
8746 /// Opcode for the SetIndicatorMap request
8747 pub const SET_INDICATOR_MAP_REQUEST: u8 = 14;
8748 #[derive(Debug, Clone, PartialEq, Eq)]
8749 pub struct SetIndicatorMapRequest<'input> {
8750 pub device_spec: DeviceSpec,
8751 pub which: u32,
8752 pub maps: Cow<'input, [IndicatorMap]>,
8753 }
8754 impl<'input> SetIndicatorMapRequest<'input> {
8755 /// Serialize this request into bytes for the provided connection
serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,8756 fn serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
8757 where
8758 Conn: RequestConnection + ?Sized,
8759 {
8760 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
8761 .ok_or(ConnectionError::UnsupportedExtension)?;
8762 let length_so_far = 0;
8763 let device_spec_bytes = self.device_spec.serialize();
8764 let which_bytes = self.which.serialize();
8765 let mut request0 = vec![
8766 extension_information.major_opcode,
8767 SET_INDICATOR_MAP_REQUEST,
8768 0,
8769 0,
8770 device_spec_bytes[0],
8771 device_spec_bytes[1],
8772 0,
8773 0,
8774 which_bytes[0],
8775 which_bytes[1],
8776 which_bytes[2],
8777 which_bytes[3],
8778 ];
8779 let length_so_far = length_so_far + request0.len();
8780 assert_eq!(self.maps.len(), usize::try_from(self.which.count_ones()).unwrap(), "`maps` has an incorrect length");
8781 let maps_bytes = self.maps.serialize();
8782 let length_so_far = length_so_far + maps_bytes.len();
8783 let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
8784 let length_so_far = length_so_far + padding0.len();
8785 assert_eq!(length_so_far % 4, 0);
8786 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
8787 request0[2..4].copy_from_slice(&length.to_ne_bytes());
8788 Ok((vec![request0.into(), maps_bytes.into(), padding0.into()], vec![]))
8789 }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,8790 pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
8791 where
8792 Conn: RequestConnection + ?Sized,
8793 {
8794 let (bytes, fds) = self.serialize(conn)?;
8795 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
8796 conn.send_request_without_reply(&slices, fds)
8797 }
8798 /// 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>8799 pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
8800 if header.minor_opcode != SET_INDICATOR_MAP_REQUEST {
8801 return Err(ParseError::InvalidValue);
8802 }
8803 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
8804 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
8805 let (which, remaining) = u32::try_parse(remaining)?;
8806 let (maps, remaining) = crate::x11_utils::parse_list::<IndicatorMap>(remaining, which.count_ones().try_to_usize()?)?;
8807 let _ = remaining;
8808 Ok(SetIndicatorMapRequest {
8809 device_spec,
8810 which,
8811 maps: Cow::Owned(maps),
8812 })
8813 }
8814 /// Clone all borrowed data in this SetIndicatorMapRequest.
into_owned(self) -> SetIndicatorMapRequest<'static>8815 pub fn into_owned(self) -> SetIndicatorMapRequest<'static> {
8816 SetIndicatorMapRequest {
8817 device_spec: self.device_spec,
8818 which: self.which,
8819 maps: Cow::Owned(self.maps.into_owned()),
8820 }
8821 }
8822 }
8823 impl<'input> Request for SetIndicatorMapRequest<'input> {
8824 type Reply = ();
8825 }
set_indicator_map<'c, 'input, Conn>(conn: &'c Conn, device_spec: DeviceSpec, which: u32, maps: &'input [IndicatorMap]) -> Result<VoidCookie<'c, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,8826 pub fn set_indicator_map<'c, 'input, Conn>(conn: &'c Conn, device_spec: DeviceSpec, which: u32, maps: &'input [IndicatorMap]) -> Result<VoidCookie<'c, Conn>, ConnectionError>
8827 where
8828 Conn: RequestConnection + ?Sized,
8829 {
8830 let request0 = SetIndicatorMapRequest {
8831 device_spec,
8832 which,
8833 maps: Cow::Borrowed(maps),
8834 };
8835 request0.send(conn)
8836 }
8837
8838 /// Opcode for the GetNamedIndicator request
8839 pub const GET_NAMED_INDICATOR_REQUEST: u8 = 15;
8840 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
8841 pub struct GetNamedIndicatorRequest {
8842 pub device_spec: DeviceSpec,
8843 pub led_class: LedClass,
8844 pub led_id: IDSpec,
8845 pub indicator: xproto::Atom,
8846 }
8847 impl GetNamedIndicatorRequest {
8848 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,8849 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
8850 where
8851 Conn: RequestConnection + ?Sized,
8852 {
8853 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
8854 .ok_or(ConnectionError::UnsupportedExtension)?;
8855 let length_so_far = 0;
8856 let device_spec_bytes = self.device_spec.serialize();
8857 let led_class_bytes = LedClassSpec::from(self.led_class).serialize();
8858 let led_id_bytes = self.led_id.serialize();
8859 let indicator_bytes = self.indicator.serialize();
8860 let mut request0 = vec![
8861 extension_information.major_opcode,
8862 GET_NAMED_INDICATOR_REQUEST,
8863 0,
8864 0,
8865 device_spec_bytes[0],
8866 device_spec_bytes[1],
8867 led_class_bytes[0],
8868 led_class_bytes[1],
8869 led_id_bytes[0],
8870 led_id_bytes[1],
8871 0,
8872 0,
8873 indicator_bytes[0],
8874 indicator_bytes[1],
8875 indicator_bytes[2],
8876 indicator_bytes[3],
8877 ];
8878 let length_so_far = length_so_far + request0.len();
8879 assert_eq!(length_so_far % 4, 0);
8880 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
8881 request0[2..4].copy_from_slice(&length.to_ne_bytes());
8882 Ok((vec![request0.into()], vec![]))
8883 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetNamedIndicatorReply>, ConnectionError> where Conn: RequestConnection + ?Sized,8884 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetNamedIndicatorReply>, ConnectionError>
8885 where
8886 Conn: RequestConnection + ?Sized,
8887 {
8888 let (bytes, fds) = self.serialize(conn)?;
8889 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
8890 conn.send_request_with_reply(&slices, fds)
8891 }
8892 /// 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>8893 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
8894 if header.minor_opcode != GET_NAMED_INDICATOR_REQUEST {
8895 return Err(ParseError::InvalidValue);
8896 }
8897 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
8898 let (led_class, remaining) = LedClassSpec::try_parse(remaining)?;
8899 let led_class = led_class.into();
8900 let (led_id, remaining) = IDSpec::try_parse(remaining)?;
8901 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
8902 let (indicator, remaining) = xproto::Atom::try_parse(remaining)?;
8903 let _ = remaining;
8904 Ok(GetNamedIndicatorRequest {
8905 device_spec,
8906 led_class,
8907 led_id,
8908 indicator,
8909 })
8910 }
8911 }
8912 impl Request for GetNamedIndicatorRequest {
8913 type Reply = GetNamedIndicatorReply;
8914 }
get_named_indicator<Conn, A>(conn: &Conn, device_spec: DeviceSpec, led_class: LedClass, led_id: A, indicator: xproto::Atom) -> Result<Cookie<'_, Conn, GetNamedIndicatorReply>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<IDSpec>,8915 pub fn get_named_indicator<Conn, A>(conn: &Conn, device_spec: DeviceSpec, led_class: LedClass, led_id: A, indicator: xproto::Atom) -> Result<Cookie<'_, Conn, GetNamedIndicatorReply>, ConnectionError>
8916 where
8917 Conn: RequestConnection + ?Sized,
8918 A: Into<IDSpec>,
8919 {
8920 let led_id: IDSpec = led_id.into();
8921 let request0 = GetNamedIndicatorRequest {
8922 device_spec,
8923 led_class,
8924 led_id,
8925 indicator,
8926 };
8927 request0.send(conn)
8928 }
8929
8930 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
8931 pub struct GetNamedIndicatorReply {
8932 pub device_id: u8,
8933 pub sequence: u16,
8934 pub length: u32,
8935 pub indicator: xproto::Atom,
8936 pub found: bool,
8937 pub on: bool,
8938 pub real_indicator: bool,
8939 pub ndx: u8,
8940 pub map_flags: u8,
8941 pub map_which_groups: u8,
8942 pub map_groups: u8,
8943 pub map_which_mods: u8,
8944 pub map_mods: u8,
8945 pub map_real_mods: u8,
8946 pub map_vmod: u16,
8947 pub map_ctrls: u32,
8948 pub supported: bool,
8949 }
8950 impl TryParse for GetNamedIndicatorReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>8951 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
8952 let remaining = initial_value;
8953 let (response_type, remaining) = u8::try_parse(remaining)?;
8954 let (device_id, remaining) = u8::try_parse(remaining)?;
8955 let (sequence, remaining) = u16::try_parse(remaining)?;
8956 let (length, remaining) = u32::try_parse(remaining)?;
8957 let (indicator, remaining) = xproto::Atom::try_parse(remaining)?;
8958 let (found, remaining) = bool::try_parse(remaining)?;
8959 let (on, remaining) = bool::try_parse(remaining)?;
8960 let (real_indicator, remaining) = bool::try_parse(remaining)?;
8961 let (ndx, remaining) = u8::try_parse(remaining)?;
8962 let (map_flags, remaining) = u8::try_parse(remaining)?;
8963 let (map_which_groups, remaining) = u8::try_parse(remaining)?;
8964 let (map_groups, remaining) = u8::try_parse(remaining)?;
8965 let (map_which_mods, remaining) = u8::try_parse(remaining)?;
8966 let (map_mods, remaining) = u8::try_parse(remaining)?;
8967 let (map_real_mods, remaining) = u8::try_parse(remaining)?;
8968 let (map_vmod, remaining) = u16::try_parse(remaining)?;
8969 let (map_ctrls, remaining) = u32::try_parse(remaining)?;
8970 let (supported, remaining) = bool::try_parse(remaining)?;
8971 let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?;
8972 if response_type != 1 {
8973 return Err(ParseError::InvalidValue);
8974 }
8975 let result = GetNamedIndicatorReply { device_id, sequence, length, indicator, found, on, real_indicator, ndx, map_flags, map_which_groups, map_groups, map_which_mods, map_mods, map_real_mods, map_vmod, map_ctrls, supported };
8976 let _ = remaining;
8977 let remaining = initial_value.get(32 + length as usize * 4..)
8978 .ok_or(ParseError::InsufficientData)?;
8979 Ok((result, remaining))
8980 }
8981 }
8982
8983 /// Opcode for the SetNamedIndicator request
8984 pub const SET_NAMED_INDICATOR_REQUEST: u8 = 16;
8985 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
8986 pub struct SetNamedIndicatorRequest {
8987 pub device_spec: DeviceSpec,
8988 pub led_class: LedClass,
8989 pub led_id: IDSpec,
8990 pub indicator: xproto::Atom,
8991 pub set_state: bool,
8992 pub on: bool,
8993 pub set_map: bool,
8994 pub create_map: bool,
8995 pub map_flags: u8,
8996 pub map_which_groups: u8,
8997 pub map_groups: u8,
8998 pub map_which_mods: u8,
8999 pub map_real_mods: u8,
9000 pub map_vmods: u16,
9001 pub map_ctrls: u32,
9002 }
9003 impl SetNamedIndicatorRequest {
9004 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,9005 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
9006 where
9007 Conn: RequestConnection + ?Sized,
9008 {
9009 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
9010 .ok_or(ConnectionError::UnsupportedExtension)?;
9011 let length_so_far = 0;
9012 let device_spec_bytes = self.device_spec.serialize();
9013 let led_class_bytes = LedClassSpec::from(self.led_class).serialize();
9014 let led_id_bytes = self.led_id.serialize();
9015 let indicator_bytes = self.indicator.serialize();
9016 let set_state_bytes = self.set_state.serialize();
9017 let on_bytes = self.on.serialize();
9018 let set_map_bytes = self.set_map.serialize();
9019 let create_map_bytes = self.create_map.serialize();
9020 let map_flags_bytes = self.map_flags.serialize();
9021 let map_which_groups_bytes = self.map_which_groups.serialize();
9022 let map_groups_bytes = self.map_groups.serialize();
9023 let map_which_mods_bytes = self.map_which_mods.serialize();
9024 let map_real_mods_bytes = self.map_real_mods.serialize();
9025 let map_vmods_bytes = self.map_vmods.serialize();
9026 let map_ctrls_bytes = self.map_ctrls.serialize();
9027 let mut request0 = vec![
9028 extension_information.major_opcode,
9029 SET_NAMED_INDICATOR_REQUEST,
9030 0,
9031 0,
9032 device_spec_bytes[0],
9033 device_spec_bytes[1],
9034 led_class_bytes[0],
9035 led_class_bytes[1],
9036 led_id_bytes[0],
9037 led_id_bytes[1],
9038 0,
9039 0,
9040 indicator_bytes[0],
9041 indicator_bytes[1],
9042 indicator_bytes[2],
9043 indicator_bytes[3],
9044 set_state_bytes[0],
9045 on_bytes[0],
9046 set_map_bytes[0],
9047 create_map_bytes[0],
9048 0,
9049 map_flags_bytes[0],
9050 map_which_groups_bytes[0],
9051 map_groups_bytes[0],
9052 map_which_mods_bytes[0],
9053 map_real_mods_bytes[0],
9054 map_vmods_bytes[0],
9055 map_vmods_bytes[1],
9056 map_ctrls_bytes[0],
9057 map_ctrls_bytes[1],
9058 map_ctrls_bytes[2],
9059 map_ctrls_bytes[3],
9060 ];
9061 let length_so_far = length_so_far + request0.len();
9062 assert_eq!(length_so_far % 4, 0);
9063 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
9064 request0[2..4].copy_from_slice(&length.to_ne_bytes());
9065 Ok((vec![request0.into()], vec![]))
9066 }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,9067 pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
9068 where
9069 Conn: RequestConnection + ?Sized,
9070 {
9071 let (bytes, fds) = self.serialize(conn)?;
9072 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
9073 conn.send_request_without_reply(&slices, fds)
9074 }
9075 /// 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>9076 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
9077 if header.minor_opcode != SET_NAMED_INDICATOR_REQUEST {
9078 return Err(ParseError::InvalidValue);
9079 }
9080 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
9081 let (led_class, remaining) = LedClassSpec::try_parse(remaining)?;
9082 let led_class = led_class.into();
9083 let (led_id, remaining) = IDSpec::try_parse(remaining)?;
9084 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
9085 let (indicator, remaining) = xproto::Atom::try_parse(remaining)?;
9086 let (set_state, remaining) = bool::try_parse(remaining)?;
9087 let (on, remaining) = bool::try_parse(remaining)?;
9088 let (set_map, remaining) = bool::try_parse(remaining)?;
9089 let (create_map, remaining) = bool::try_parse(remaining)?;
9090 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
9091 let (map_flags, remaining) = u8::try_parse(remaining)?;
9092 let (map_which_groups, remaining) = u8::try_parse(remaining)?;
9093 let (map_groups, remaining) = u8::try_parse(remaining)?;
9094 let (map_which_mods, remaining) = u8::try_parse(remaining)?;
9095 let (map_real_mods, remaining) = u8::try_parse(remaining)?;
9096 let (map_vmods, remaining) = u16::try_parse(remaining)?;
9097 let (map_ctrls, remaining) = u32::try_parse(remaining)?;
9098 let _ = remaining;
9099 Ok(SetNamedIndicatorRequest {
9100 device_spec,
9101 led_class,
9102 led_id,
9103 indicator,
9104 set_state,
9105 on,
9106 set_map,
9107 create_map,
9108 map_flags,
9109 map_which_groups,
9110 map_groups,
9111 map_which_mods,
9112 map_real_mods,
9113 map_vmods,
9114 map_ctrls,
9115 })
9116 }
9117 }
9118 impl Request for SetNamedIndicatorRequest {
9119 type Reply = ();
9120 }
set_named_indicator<Conn, A, B, C, D, E, F, G, H>(conn: &Conn, device_spec: DeviceSpec, led_class: LedClass, led_id: A, indicator: xproto::Atom, set_state: bool, on: bool, set_map: bool, create_map: bool, map_flags: B, map_which_groups: C, map_groups: D, map_which_mods: E, map_real_mods: F, map_vmods: G, map_ctrls: H) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<IDSpec>, B: Into<u8>, C: Into<u8>, D: Into<u8>, E: Into<u8>, F: Into<u8>, G: Into<u16>, H: Into<u32>,9121 pub fn set_named_indicator<Conn, A, B, C, D, E, F, G, H>(conn: &Conn, device_spec: DeviceSpec, led_class: LedClass, led_id: A, indicator: xproto::Atom, set_state: bool, on: bool, set_map: bool, create_map: bool, map_flags: B, map_which_groups: C, map_groups: D, map_which_mods: E, map_real_mods: F, map_vmods: G, map_ctrls: H) -> Result<VoidCookie<'_, Conn>, ConnectionError>
9122 where
9123 Conn: RequestConnection + ?Sized,
9124 A: Into<IDSpec>,
9125 B: Into<u8>,
9126 C: Into<u8>,
9127 D: Into<u8>,
9128 E: Into<u8>,
9129 F: Into<u8>,
9130 G: Into<u16>,
9131 H: Into<u32>,
9132 {
9133 let led_id: IDSpec = led_id.into();
9134 let map_flags: u8 = map_flags.into();
9135 let map_which_groups: u8 = map_which_groups.into();
9136 let map_groups: u8 = map_groups.into();
9137 let map_which_mods: u8 = map_which_mods.into();
9138 let map_real_mods: u8 = map_real_mods.into();
9139 let map_vmods: u16 = map_vmods.into();
9140 let map_ctrls: u32 = map_ctrls.into();
9141 let request0 = SetNamedIndicatorRequest {
9142 device_spec,
9143 led_class,
9144 led_id,
9145 indicator,
9146 set_state,
9147 on,
9148 set_map,
9149 create_map,
9150 map_flags,
9151 map_which_groups,
9152 map_groups,
9153 map_which_mods,
9154 map_real_mods,
9155 map_vmods,
9156 map_ctrls,
9157 };
9158 request0.send(conn)
9159 }
9160
9161 /// Opcode for the GetNames request
9162 pub const GET_NAMES_REQUEST: u8 = 17;
9163 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
9164 pub struct GetNamesRequest {
9165 pub device_spec: DeviceSpec,
9166 pub which: u32,
9167 }
9168 impl GetNamesRequest {
9169 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,9170 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
9171 where
9172 Conn: RequestConnection + ?Sized,
9173 {
9174 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
9175 .ok_or(ConnectionError::UnsupportedExtension)?;
9176 let length_so_far = 0;
9177 let device_spec_bytes = self.device_spec.serialize();
9178 let which_bytes = self.which.serialize();
9179 let mut request0 = vec![
9180 extension_information.major_opcode,
9181 GET_NAMES_REQUEST,
9182 0,
9183 0,
9184 device_spec_bytes[0],
9185 device_spec_bytes[1],
9186 0,
9187 0,
9188 which_bytes[0],
9189 which_bytes[1],
9190 which_bytes[2],
9191 which_bytes[3],
9192 ];
9193 let length_so_far = length_so_far + request0.len();
9194 assert_eq!(length_so_far % 4, 0);
9195 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
9196 request0[2..4].copy_from_slice(&length.to_ne_bytes());
9197 Ok((vec![request0.into()], vec![]))
9198 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetNamesReply>, ConnectionError> where Conn: RequestConnection + ?Sized,9199 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetNamesReply>, ConnectionError>
9200 where
9201 Conn: RequestConnection + ?Sized,
9202 {
9203 let (bytes, fds) = self.serialize(conn)?;
9204 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
9205 conn.send_request_with_reply(&slices, fds)
9206 }
9207 /// 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>9208 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
9209 if header.minor_opcode != GET_NAMES_REQUEST {
9210 return Err(ParseError::InvalidValue);
9211 }
9212 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
9213 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
9214 let (which, remaining) = u32::try_parse(remaining)?;
9215 let _ = remaining;
9216 Ok(GetNamesRequest {
9217 device_spec,
9218 which,
9219 })
9220 }
9221 }
9222 impl Request for GetNamesRequest {
9223 type Reply = GetNamesReply;
9224 }
get_names<Conn, A>(conn: &Conn, device_spec: DeviceSpec, which: A) -> Result<Cookie<'_, Conn, GetNamesReply>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<u32>,9225 pub fn get_names<Conn, A>(conn: &Conn, device_spec: DeviceSpec, which: A) -> Result<Cookie<'_, Conn, GetNamesReply>, ConnectionError>
9226 where
9227 Conn: RequestConnection + ?Sized,
9228 A: Into<u32>,
9229 {
9230 let which: u32 = which.into();
9231 let request0 = GetNamesRequest {
9232 device_spec,
9233 which,
9234 };
9235 request0.send(conn)
9236 }
9237
9238 #[derive(Debug, Clone, PartialEq, Eq)]
9239 pub struct GetNamesValueListBitcase8 {
9240 pub n_levels_per_type: Vec<u8>,
9241 pub kt_level_names: Vec<xproto::Atom>,
9242 }
9243 impl GetNamesValueListBitcase8 {
try_parse(remaining: &[u8], n_types: u8) -> Result<(Self, &[u8]), ParseError>9244 pub fn try_parse(remaining: &[u8], n_types: u8) -> Result<(Self, &[u8]), ParseError> {
9245 let value = remaining;
9246 let (n_levels_per_type, remaining) = crate::x11_utils::parse_u8_list(remaining, n_types.try_to_usize()?)?;
9247 let n_levels_per_type = n_levels_per_type.to_vec();
9248 // Align offset to multiple of 4
9249 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
9250 let misalignment = (4 - (offset % 4)) % 4;
9251 let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
9252 let (kt_level_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, n_levels_per_type.iter().try_fold(0u32, |acc, x| acc.checked_add(u32::from(*x)).ok_or(ParseError::InvalidExpression))?.try_to_usize()?)?;
9253 let result = GetNamesValueListBitcase8 { n_levels_per_type, kt_level_names };
9254 Ok((result, remaining))
9255 }
9256 }
9257 #[derive(Debug, Clone, PartialEq, Eq, Default)]
9258 pub struct GetNamesValueList {
9259 pub keycodes_name: Option<xproto::Atom>,
9260 pub geometry_name: Option<xproto::Atom>,
9261 pub symbols_name: Option<xproto::Atom>,
9262 pub phys_symbols_name: Option<xproto::Atom>,
9263 pub types_name: Option<xproto::Atom>,
9264 pub compat_name: Option<xproto::Atom>,
9265 pub type_names: Option<Vec<xproto::Atom>>,
9266 pub bitcase8: Option<GetNamesValueListBitcase8>,
9267 pub indicator_names: Option<Vec<xproto::Atom>>,
9268 pub virtual_mod_names: Option<Vec<xproto::Atom>>,
9269 pub groups: Option<Vec<xproto::Atom>>,
9270 pub key_names: Option<Vec<KeyName>>,
9271 pub key_aliases: Option<Vec<KeyAlias>>,
9272 pub radio_group_names: Option<Vec<xproto::Atom>>,
9273 }
9274 impl GetNamesValueList {
try_parse(value: &[u8], which: u32, n_types: u8, indicators: u32, virtual_mods: u16, group_names: u8, n_keys: u8, n_key_aliases: u8, n_radio_groups: u8) -> Result<(Self, &[u8]), ParseError>9275 fn try_parse(value: &[u8], which: u32, n_types: u8, indicators: u32, virtual_mods: u16, group_names: u8, n_keys: u8, n_key_aliases: u8, n_radio_groups: u8) -> Result<(Self, &[u8]), ParseError> {
9276 let switch_expr = which;
9277 let mut outer_remaining = value;
9278 let keycodes_name = if switch_expr & u32::from(NameDetail::KEYCODES) != 0 {
9279 let remaining = outer_remaining;
9280 let (keycodes_name, remaining) = xproto::Atom::try_parse(remaining)?;
9281 outer_remaining = remaining;
9282 Some(keycodes_name)
9283 } else {
9284 None
9285 };
9286 let geometry_name = if switch_expr & u32::from(NameDetail::GEOMETRY) != 0 {
9287 let remaining = outer_remaining;
9288 let (geometry_name, remaining) = xproto::Atom::try_parse(remaining)?;
9289 outer_remaining = remaining;
9290 Some(geometry_name)
9291 } else {
9292 None
9293 };
9294 let symbols_name = if switch_expr & u32::from(NameDetail::SYMBOLS) != 0 {
9295 let remaining = outer_remaining;
9296 let (symbols_name, remaining) = xproto::Atom::try_parse(remaining)?;
9297 outer_remaining = remaining;
9298 Some(symbols_name)
9299 } else {
9300 None
9301 };
9302 let phys_symbols_name = if switch_expr & u32::from(NameDetail::PHYS_SYMBOLS) != 0 {
9303 let remaining = outer_remaining;
9304 let (phys_symbols_name, remaining) = xproto::Atom::try_parse(remaining)?;
9305 outer_remaining = remaining;
9306 Some(phys_symbols_name)
9307 } else {
9308 None
9309 };
9310 let types_name = if switch_expr & u32::from(NameDetail::TYPES) != 0 {
9311 let remaining = outer_remaining;
9312 let (types_name, remaining) = xproto::Atom::try_parse(remaining)?;
9313 outer_remaining = remaining;
9314 Some(types_name)
9315 } else {
9316 None
9317 };
9318 let compat_name = if switch_expr & u32::from(NameDetail::COMPAT) != 0 {
9319 let remaining = outer_remaining;
9320 let (compat_name, remaining) = xproto::Atom::try_parse(remaining)?;
9321 outer_remaining = remaining;
9322 Some(compat_name)
9323 } else {
9324 None
9325 };
9326 let type_names = if switch_expr & u32::from(NameDetail::KEY_TYPE_NAMES) != 0 {
9327 let remaining = outer_remaining;
9328 let (type_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, n_types.try_to_usize()?)?;
9329 outer_remaining = remaining;
9330 Some(type_names)
9331 } else {
9332 None
9333 };
9334 let bitcase8 = if switch_expr & u32::from(NameDetail::KT_LEVEL_NAMES) != 0 {
9335 let (bitcase8, new_remaining) = GetNamesValueListBitcase8::try_parse(outer_remaining, n_types)?;
9336 outer_remaining = new_remaining;
9337 Some(bitcase8)
9338 } else {
9339 None
9340 };
9341 let indicator_names = if switch_expr & u32::from(NameDetail::INDICATOR_NAMES) != 0 {
9342 let remaining = outer_remaining;
9343 let (indicator_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, indicators.count_ones().try_to_usize()?)?;
9344 outer_remaining = remaining;
9345 Some(indicator_names)
9346 } else {
9347 None
9348 };
9349 let virtual_mod_names = if switch_expr & u32::from(NameDetail::VIRTUAL_MOD_NAMES) != 0 {
9350 let remaining = outer_remaining;
9351 let (virtual_mod_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, virtual_mods.count_ones().try_to_usize()?)?;
9352 outer_remaining = remaining;
9353 Some(virtual_mod_names)
9354 } else {
9355 None
9356 };
9357 let groups = if switch_expr & u32::from(NameDetail::GROUP_NAMES) != 0 {
9358 let remaining = outer_remaining;
9359 let (groups, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, group_names.count_ones().try_to_usize()?)?;
9360 outer_remaining = remaining;
9361 Some(groups)
9362 } else {
9363 None
9364 };
9365 let key_names = if switch_expr & u32::from(NameDetail::KEY_NAMES) != 0 {
9366 let remaining = outer_remaining;
9367 let (key_names, remaining) = crate::x11_utils::parse_list::<KeyName>(remaining, n_keys.try_to_usize()?)?;
9368 outer_remaining = remaining;
9369 Some(key_names)
9370 } else {
9371 None
9372 };
9373 let key_aliases = if switch_expr & u32::from(NameDetail::KEY_ALIASES) != 0 {
9374 let remaining = outer_remaining;
9375 let (key_aliases, remaining) = crate::x11_utils::parse_list::<KeyAlias>(remaining, n_key_aliases.try_to_usize()?)?;
9376 outer_remaining = remaining;
9377 Some(key_aliases)
9378 } else {
9379 None
9380 };
9381 let radio_group_names = if switch_expr & u32::from(NameDetail::RG_NAMES) != 0 {
9382 let remaining = outer_remaining;
9383 let (radio_group_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, n_radio_groups.try_to_usize()?)?;
9384 outer_remaining = remaining;
9385 Some(radio_group_names)
9386 } else {
9387 None
9388 };
9389 let result = GetNamesValueList { keycodes_name, geometry_name, symbols_name, phys_symbols_name, types_name, compat_name, type_names, bitcase8, indicator_names, virtual_mod_names, groups, key_names, key_aliases, radio_group_names };
9390 Ok((result, outer_remaining))
9391 }
9392 }
9393
9394 #[derive(Debug, Clone, PartialEq, Eq)]
9395 pub struct GetNamesReply {
9396 pub device_id: u8,
9397 pub sequence: u16,
9398 pub length: u32,
9399 pub min_key_code: xproto::Keycode,
9400 pub max_key_code: xproto::Keycode,
9401 pub n_types: u8,
9402 pub group_names: u8,
9403 pub virtual_mods: u16,
9404 pub first_key: xproto::Keycode,
9405 pub n_keys: u8,
9406 pub indicators: u32,
9407 pub n_radio_groups: u8,
9408 pub n_key_aliases: u8,
9409 pub n_kt_levels: u16,
9410 pub value_list: GetNamesValueList,
9411 }
9412 impl TryParse for GetNamesReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>9413 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
9414 let remaining = initial_value;
9415 let (response_type, remaining) = u8::try_parse(remaining)?;
9416 let (device_id, remaining) = u8::try_parse(remaining)?;
9417 let (sequence, remaining) = u16::try_parse(remaining)?;
9418 let (length, remaining) = u32::try_parse(remaining)?;
9419 let (which, remaining) = u32::try_parse(remaining)?;
9420 let (min_key_code, remaining) = xproto::Keycode::try_parse(remaining)?;
9421 let (max_key_code, remaining) = xproto::Keycode::try_parse(remaining)?;
9422 let (n_types, remaining) = u8::try_parse(remaining)?;
9423 let (group_names, remaining) = u8::try_parse(remaining)?;
9424 let (virtual_mods, remaining) = u16::try_parse(remaining)?;
9425 let (first_key, remaining) = xproto::Keycode::try_parse(remaining)?;
9426 let (n_keys, remaining) = u8::try_parse(remaining)?;
9427 let (indicators, remaining) = u32::try_parse(remaining)?;
9428 let (n_radio_groups, remaining) = u8::try_parse(remaining)?;
9429 let (n_key_aliases, remaining) = u8::try_parse(remaining)?;
9430 let (n_kt_levels, remaining) = u16::try_parse(remaining)?;
9431 let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?;
9432 let (value_list, remaining) = GetNamesValueList::try_parse(remaining, which, n_types, indicators, virtual_mods, group_names, n_keys, n_key_aliases, n_radio_groups)?;
9433 if response_type != 1 {
9434 return Err(ParseError::InvalidValue);
9435 }
9436 let result = GetNamesReply { device_id, sequence, length, min_key_code, max_key_code, n_types, group_names, virtual_mods, first_key, n_keys, indicators, n_radio_groups, n_key_aliases, n_kt_levels, value_list };
9437 let _ = remaining;
9438 let remaining = initial_value.get(32 + length as usize * 4..)
9439 .ok_or(ParseError::InsufficientData)?;
9440 Ok((result, remaining))
9441 }
9442 }
9443
9444 #[derive(Debug, Clone, PartialEq, Eq)]
9445 pub struct SetNamesAuxBitcase8 {
9446 pub n_levels_per_type: Vec<u8>,
9447 pub kt_level_names: Vec<xproto::Atom>,
9448 }
9449 impl SetNamesAuxBitcase8 {
try_parse(remaining: &[u8], n_types: u8) -> Result<(Self, &[u8]), ParseError>9450 pub fn try_parse(remaining: &[u8], n_types: u8) -> Result<(Self, &[u8]), ParseError> {
9451 let value = remaining;
9452 let (n_levels_per_type, remaining) = crate::x11_utils::parse_u8_list(remaining, n_types.try_to_usize()?)?;
9453 let n_levels_per_type = n_levels_per_type.to_vec();
9454 // Align offset to multiple of 4
9455 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
9456 let misalignment = (4 - (offset % 4)) % 4;
9457 let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
9458 let (kt_level_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, n_levels_per_type.iter().try_fold(0u32, |acc, x| acc.checked_add(u32::from(*x)).ok_or(ParseError::InvalidExpression))?.try_to_usize()?)?;
9459 let result = SetNamesAuxBitcase8 { n_levels_per_type, kt_level_names };
9460 Ok((result, remaining))
9461 }
9462 }
9463 impl SetNamesAuxBitcase8 {
9464 #[allow(dead_code)]
serialize(&self, n_types: u8) -> Vec<u8>9465 fn serialize(&self, n_types: u8) -> Vec<u8> {
9466 let mut result = Vec::new();
9467 self.serialize_into(&mut result, n_types);
9468 result
9469 }
serialize_into(&self, bytes: &mut Vec<u8>, n_types: u8)9470 fn serialize_into(&self, bytes: &mut Vec<u8>, n_types: u8) {
9471 assert_eq!(self.n_levels_per_type.len(), usize::try_from(n_types).unwrap(), "`n_levels_per_type` has an incorrect length");
9472 bytes.extend_from_slice(&self.n_levels_per_type);
9473 bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]);
9474 assert_eq!(self.kt_level_names.len(), usize::try_from(self.n_levels_per_type.iter().fold(0u32, |acc, x| acc.checked_add(u32::from(*x)).unwrap())).unwrap(), "`kt_level_names` has an incorrect length");
9475 self.kt_level_names.serialize_into(bytes);
9476 }
9477 }
9478 /// Auxiliary and optional information for the `set_names` function
9479 #[derive(Debug, Clone, PartialEq, Eq, Default)]
9480 pub struct SetNamesAux {
9481 pub keycodes_name: Option<xproto::Atom>,
9482 pub geometry_name: Option<xproto::Atom>,
9483 pub symbols_name: Option<xproto::Atom>,
9484 pub phys_symbols_name: Option<xproto::Atom>,
9485 pub types_name: Option<xproto::Atom>,
9486 pub compat_name: Option<xproto::Atom>,
9487 pub type_names: Option<Vec<xproto::Atom>>,
9488 pub bitcase8: Option<SetNamesAuxBitcase8>,
9489 pub indicator_names: Option<Vec<xproto::Atom>>,
9490 pub virtual_mod_names: Option<Vec<xproto::Atom>>,
9491 pub groups: Option<Vec<xproto::Atom>>,
9492 pub key_names: Option<Vec<KeyName>>,
9493 pub key_aliases: Option<Vec<KeyAlias>>,
9494 pub radio_group_names: Option<Vec<xproto::Atom>>,
9495 }
9496 impl SetNamesAux {
try_parse(value: &[u8], which: u32, n_types: u8, indicators: u32, virtual_mods: u16, group_names: u8, n_keys: u8, n_key_aliases: u8, n_radio_groups: u8) -> Result<(Self, &[u8]), ParseError>9497 fn try_parse(value: &[u8], which: u32, n_types: u8, indicators: u32, virtual_mods: u16, group_names: u8, n_keys: u8, n_key_aliases: u8, n_radio_groups: u8) -> Result<(Self, &[u8]), ParseError> {
9498 let switch_expr = which;
9499 let mut outer_remaining = value;
9500 let keycodes_name = if switch_expr & u32::from(NameDetail::KEYCODES) != 0 {
9501 let remaining = outer_remaining;
9502 let (keycodes_name, remaining) = xproto::Atom::try_parse(remaining)?;
9503 outer_remaining = remaining;
9504 Some(keycodes_name)
9505 } else {
9506 None
9507 };
9508 let geometry_name = if switch_expr & u32::from(NameDetail::GEOMETRY) != 0 {
9509 let remaining = outer_remaining;
9510 let (geometry_name, remaining) = xproto::Atom::try_parse(remaining)?;
9511 outer_remaining = remaining;
9512 Some(geometry_name)
9513 } else {
9514 None
9515 };
9516 let symbols_name = if switch_expr & u32::from(NameDetail::SYMBOLS) != 0 {
9517 let remaining = outer_remaining;
9518 let (symbols_name, remaining) = xproto::Atom::try_parse(remaining)?;
9519 outer_remaining = remaining;
9520 Some(symbols_name)
9521 } else {
9522 None
9523 };
9524 let phys_symbols_name = if switch_expr & u32::from(NameDetail::PHYS_SYMBOLS) != 0 {
9525 let remaining = outer_remaining;
9526 let (phys_symbols_name, remaining) = xproto::Atom::try_parse(remaining)?;
9527 outer_remaining = remaining;
9528 Some(phys_symbols_name)
9529 } else {
9530 None
9531 };
9532 let types_name = if switch_expr & u32::from(NameDetail::TYPES) != 0 {
9533 let remaining = outer_remaining;
9534 let (types_name, remaining) = xproto::Atom::try_parse(remaining)?;
9535 outer_remaining = remaining;
9536 Some(types_name)
9537 } else {
9538 None
9539 };
9540 let compat_name = if switch_expr & u32::from(NameDetail::COMPAT) != 0 {
9541 let remaining = outer_remaining;
9542 let (compat_name, remaining) = xproto::Atom::try_parse(remaining)?;
9543 outer_remaining = remaining;
9544 Some(compat_name)
9545 } else {
9546 None
9547 };
9548 let type_names = if switch_expr & u32::from(NameDetail::KEY_TYPE_NAMES) != 0 {
9549 let remaining = outer_remaining;
9550 let (type_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, n_types.try_to_usize()?)?;
9551 outer_remaining = remaining;
9552 Some(type_names)
9553 } else {
9554 None
9555 };
9556 let bitcase8 = if switch_expr & u32::from(NameDetail::KT_LEVEL_NAMES) != 0 {
9557 let (bitcase8, new_remaining) = SetNamesAuxBitcase8::try_parse(outer_remaining, n_types)?;
9558 outer_remaining = new_remaining;
9559 Some(bitcase8)
9560 } else {
9561 None
9562 };
9563 let indicator_names = if switch_expr & u32::from(NameDetail::INDICATOR_NAMES) != 0 {
9564 let remaining = outer_remaining;
9565 let (indicator_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, indicators.count_ones().try_to_usize()?)?;
9566 outer_remaining = remaining;
9567 Some(indicator_names)
9568 } else {
9569 None
9570 };
9571 let virtual_mod_names = if switch_expr & u32::from(NameDetail::VIRTUAL_MOD_NAMES) != 0 {
9572 let remaining = outer_remaining;
9573 let (virtual_mod_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, virtual_mods.count_ones().try_to_usize()?)?;
9574 outer_remaining = remaining;
9575 Some(virtual_mod_names)
9576 } else {
9577 None
9578 };
9579 let groups = if switch_expr & u32::from(NameDetail::GROUP_NAMES) != 0 {
9580 let remaining = outer_remaining;
9581 let (groups, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, group_names.count_ones().try_to_usize()?)?;
9582 outer_remaining = remaining;
9583 Some(groups)
9584 } else {
9585 None
9586 };
9587 let key_names = if switch_expr & u32::from(NameDetail::KEY_NAMES) != 0 {
9588 let remaining = outer_remaining;
9589 let (key_names, remaining) = crate::x11_utils::parse_list::<KeyName>(remaining, n_keys.try_to_usize()?)?;
9590 outer_remaining = remaining;
9591 Some(key_names)
9592 } else {
9593 None
9594 };
9595 let key_aliases = if switch_expr & u32::from(NameDetail::KEY_ALIASES) != 0 {
9596 let remaining = outer_remaining;
9597 let (key_aliases, remaining) = crate::x11_utils::parse_list::<KeyAlias>(remaining, n_key_aliases.try_to_usize()?)?;
9598 outer_remaining = remaining;
9599 Some(key_aliases)
9600 } else {
9601 None
9602 };
9603 let radio_group_names = if switch_expr & u32::from(NameDetail::RG_NAMES) != 0 {
9604 let remaining = outer_remaining;
9605 let (radio_group_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, n_radio_groups.try_to_usize()?)?;
9606 outer_remaining = remaining;
9607 Some(radio_group_names)
9608 } else {
9609 None
9610 };
9611 let result = SetNamesAux { keycodes_name, geometry_name, symbols_name, phys_symbols_name, types_name, compat_name, type_names, bitcase8, indicator_names, virtual_mod_names, groups, key_names, key_aliases, radio_group_names };
9612 Ok((result, outer_remaining))
9613 }
9614 }
9615 impl SetNamesAux {
9616 #[allow(dead_code)]
serialize(&self, which: u32, n_types: u8, indicators: u32, virtual_mods: u16, group_names: u8, n_keys: u8, n_key_aliases: u8, n_radio_groups: u8) -> Vec<u8>9617 fn serialize(&self, which: u32, n_types: u8, indicators: u32, virtual_mods: u16, group_names: u8, n_keys: u8, n_key_aliases: u8, n_radio_groups: u8) -> Vec<u8> {
9618 let mut result = Vec::new();
9619 self.serialize_into(&mut result, which, n_types, indicators, virtual_mods, group_names, n_keys, n_key_aliases, n_radio_groups);
9620 result
9621 }
serialize_into(&self, bytes: &mut Vec<u8>, which: u32, n_types: u8, indicators: u32, virtual_mods: u16, group_names: u8, n_keys: u8, n_key_aliases: u8, n_radio_groups: u8)9622 fn serialize_into(&self, bytes: &mut Vec<u8>, which: u32, n_types: u8, indicators: u32, virtual_mods: u16, group_names: u8, n_keys: u8, n_key_aliases: u8, n_radio_groups: u8) {
9623 assert_eq!(self.switch_expr(), which, "switch `values` has an inconsistent discriminant");
9624 if let Some(keycodes_name) = self.keycodes_name {
9625 keycodes_name.serialize_into(bytes);
9626 }
9627 if let Some(geometry_name) = self.geometry_name {
9628 geometry_name.serialize_into(bytes);
9629 }
9630 if let Some(symbols_name) = self.symbols_name {
9631 symbols_name.serialize_into(bytes);
9632 }
9633 if let Some(phys_symbols_name) = self.phys_symbols_name {
9634 phys_symbols_name.serialize_into(bytes);
9635 }
9636 if let Some(types_name) = self.types_name {
9637 types_name.serialize_into(bytes);
9638 }
9639 if let Some(compat_name) = self.compat_name {
9640 compat_name.serialize_into(bytes);
9641 }
9642 if let Some(ref type_names) = self.type_names {
9643 assert_eq!(type_names.len(), usize::try_from(n_types).unwrap(), "`type_names` has an incorrect length");
9644 type_names.serialize_into(bytes);
9645 }
9646 if let Some(ref bitcase8) = self.bitcase8 {
9647 bitcase8.serialize_into(bytes, n_types);
9648 }
9649 if let Some(ref indicator_names) = self.indicator_names {
9650 assert_eq!(indicator_names.len(), usize::try_from(indicators.count_ones()).unwrap(), "`indicator_names` has an incorrect length");
9651 indicator_names.serialize_into(bytes);
9652 }
9653 if let Some(ref virtual_mod_names) = self.virtual_mod_names {
9654 assert_eq!(virtual_mod_names.len(), usize::try_from(virtual_mods.count_ones()).unwrap(), "`virtual_mod_names` has an incorrect length");
9655 virtual_mod_names.serialize_into(bytes);
9656 }
9657 if let Some(ref groups) = self.groups {
9658 assert_eq!(groups.len(), usize::try_from(group_names.count_ones()).unwrap(), "`groups` has an incorrect length");
9659 groups.serialize_into(bytes);
9660 }
9661 if let Some(ref key_names) = self.key_names {
9662 assert_eq!(key_names.len(), usize::try_from(n_keys).unwrap(), "`key_names` has an incorrect length");
9663 key_names.serialize_into(bytes);
9664 }
9665 if let Some(ref key_aliases) = self.key_aliases {
9666 assert_eq!(key_aliases.len(), usize::try_from(n_key_aliases).unwrap(), "`key_aliases` has an incorrect length");
9667 key_aliases.serialize_into(bytes);
9668 }
9669 if let Some(ref radio_group_names) = self.radio_group_names {
9670 assert_eq!(radio_group_names.len(), usize::try_from(n_radio_groups).unwrap(), "`radio_group_names` has an incorrect length");
9671 radio_group_names.serialize_into(bytes);
9672 }
9673 }
9674 }
9675 impl SetNamesAux {
switch_expr(&self) -> u329676 fn switch_expr(&self) -> u32 {
9677 let mut expr_value = 0;
9678 if self.keycodes_name.is_some() {
9679 expr_value |= u32::from(NameDetail::KEYCODES);
9680 }
9681 if self.geometry_name.is_some() {
9682 expr_value |= u32::from(NameDetail::GEOMETRY);
9683 }
9684 if self.symbols_name.is_some() {
9685 expr_value |= u32::from(NameDetail::SYMBOLS);
9686 }
9687 if self.phys_symbols_name.is_some() {
9688 expr_value |= u32::from(NameDetail::PHYS_SYMBOLS);
9689 }
9690 if self.types_name.is_some() {
9691 expr_value |= u32::from(NameDetail::TYPES);
9692 }
9693 if self.compat_name.is_some() {
9694 expr_value |= u32::from(NameDetail::COMPAT);
9695 }
9696 if self.type_names.is_some() {
9697 expr_value |= u32::from(NameDetail::KEY_TYPE_NAMES);
9698 }
9699 if self.bitcase8.is_some() {
9700 expr_value |= u32::from(NameDetail::KT_LEVEL_NAMES);
9701 }
9702 if self.indicator_names.is_some() {
9703 expr_value |= u32::from(NameDetail::INDICATOR_NAMES);
9704 }
9705 if self.virtual_mod_names.is_some() {
9706 expr_value |= u32::from(NameDetail::VIRTUAL_MOD_NAMES);
9707 }
9708 if self.groups.is_some() {
9709 expr_value |= u32::from(NameDetail::GROUP_NAMES);
9710 }
9711 if self.key_names.is_some() {
9712 expr_value |= u32::from(NameDetail::KEY_NAMES);
9713 }
9714 if self.key_aliases.is_some() {
9715 expr_value |= u32::from(NameDetail::KEY_ALIASES);
9716 }
9717 if self.radio_group_names.is_some() {
9718 expr_value |= u32::from(NameDetail::RG_NAMES);
9719 }
9720 expr_value
9721 }
9722 }
9723 impl SetNamesAux {
9724 /// Create a new instance with all fields unset / not present.
new() -> Self9725 pub fn new() -> Self {
9726 Default::default()
9727 }
9728 /// Set the `keycodes_name` field of this structure.
keycodes_name<I>(mut self, value: I) -> Self where I: Into<Option<xproto::Atom>>9729 pub fn keycodes_name<I>(mut self, value: I) -> Self where I: Into<Option<xproto::Atom>> {
9730 self.keycodes_name = value.into();
9731 self
9732 }
9733 /// Set the `geometry_name` field of this structure.
geometry_name<I>(mut self, value: I) -> Self where I: Into<Option<xproto::Atom>>9734 pub fn geometry_name<I>(mut self, value: I) -> Self where I: Into<Option<xproto::Atom>> {
9735 self.geometry_name = value.into();
9736 self
9737 }
9738 /// Set the `symbols_name` field of this structure.
symbols_name<I>(mut self, value: I) -> Self where I: Into<Option<xproto::Atom>>9739 pub fn symbols_name<I>(mut self, value: I) -> Self where I: Into<Option<xproto::Atom>> {
9740 self.symbols_name = value.into();
9741 self
9742 }
9743 /// Set the `phys_symbols_name` field of this structure.
phys_symbols_name<I>(mut self, value: I) -> Self where I: Into<Option<xproto::Atom>>9744 pub fn phys_symbols_name<I>(mut self, value: I) -> Self where I: Into<Option<xproto::Atom>> {
9745 self.phys_symbols_name = value.into();
9746 self
9747 }
9748 /// Set the `types_name` field of this structure.
types_name<I>(mut self, value: I) -> Self where I: Into<Option<xproto::Atom>>9749 pub fn types_name<I>(mut self, value: I) -> Self where I: Into<Option<xproto::Atom>> {
9750 self.types_name = value.into();
9751 self
9752 }
9753 /// Set the `compat_name` field of this structure.
compat_name<I>(mut self, value: I) -> Self where I: Into<Option<xproto::Atom>>9754 pub fn compat_name<I>(mut self, value: I) -> Self where I: Into<Option<xproto::Atom>> {
9755 self.compat_name = value.into();
9756 self
9757 }
9758 /// Set the `type_names` field of this structure.
type_names<I>(mut self, value: I) -> Self where I: Into<Option<Vec<xproto::Atom>>>9759 pub fn type_names<I>(mut self, value: I) -> Self where I: Into<Option<Vec<xproto::Atom>>> {
9760 self.type_names = value.into();
9761 self
9762 }
9763 /// Set the `bitcase8` field of this structure.
bitcase8<I>(mut self, value: I) -> Self where I: Into<Option<SetNamesAuxBitcase8>>9764 pub fn bitcase8<I>(mut self, value: I) -> Self where I: Into<Option<SetNamesAuxBitcase8>> {
9765 self.bitcase8 = value.into();
9766 self
9767 }
9768 /// Set the `indicator_names` field of this structure.
indicator_names<I>(mut self, value: I) -> Self where I: Into<Option<Vec<xproto::Atom>>>9769 pub fn indicator_names<I>(mut self, value: I) -> Self where I: Into<Option<Vec<xproto::Atom>>> {
9770 self.indicator_names = value.into();
9771 self
9772 }
9773 /// Set the `virtual_mod_names` field of this structure.
virtual_mod_names<I>(mut self, value: I) -> Self where I: Into<Option<Vec<xproto::Atom>>>9774 pub fn virtual_mod_names<I>(mut self, value: I) -> Self where I: Into<Option<Vec<xproto::Atom>>> {
9775 self.virtual_mod_names = value.into();
9776 self
9777 }
9778 /// Set the `groups` field of this structure.
groups<I>(mut self, value: I) -> Self where I: Into<Option<Vec<xproto::Atom>>>9779 pub fn groups<I>(mut self, value: I) -> Self where I: Into<Option<Vec<xproto::Atom>>> {
9780 self.groups = value.into();
9781 self
9782 }
9783 /// Set the `key_names` field of this structure.
key_names<I>(mut self, value: I) -> Self where I: Into<Option<Vec<KeyName>>>9784 pub fn key_names<I>(mut self, value: I) -> Self where I: Into<Option<Vec<KeyName>>> {
9785 self.key_names = value.into();
9786 self
9787 }
9788 /// Set the `key_aliases` field of this structure.
key_aliases<I>(mut self, value: I) -> Self where I: Into<Option<Vec<KeyAlias>>>9789 pub fn key_aliases<I>(mut self, value: I) -> Self where I: Into<Option<Vec<KeyAlias>>> {
9790 self.key_aliases = value.into();
9791 self
9792 }
9793 /// Set the `radio_group_names` field of this structure.
radio_group_names<I>(mut self, value: I) -> Self where I: Into<Option<Vec<xproto::Atom>>>9794 pub fn radio_group_names<I>(mut self, value: I) -> Self where I: Into<Option<Vec<xproto::Atom>>> {
9795 self.radio_group_names = value.into();
9796 self
9797 }
9798 }
9799
9800 /// Opcode for the SetNames request
9801 pub const SET_NAMES_REQUEST: u8 = 18;
9802 #[derive(Debug, Clone, PartialEq, Eq)]
9803 pub struct SetNamesRequest<'input> {
9804 pub device_spec: DeviceSpec,
9805 pub virtual_mods: u16,
9806 pub first_type: u8,
9807 pub n_types: u8,
9808 pub first_kt_levelt: u8,
9809 pub n_kt_levels: u8,
9810 pub indicators: u32,
9811 pub group_names: u8,
9812 pub n_radio_groups: u8,
9813 pub first_key: xproto::Keycode,
9814 pub n_keys: u8,
9815 pub n_key_aliases: u8,
9816 pub total_kt_level_names: u16,
9817 pub values: Cow<'input, SetNamesAux>,
9818 }
9819 impl<'input> SetNamesRequest<'input> {
9820 /// Serialize this request into bytes for the provided connection
serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,9821 fn serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
9822 where
9823 Conn: RequestConnection + ?Sized,
9824 {
9825 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
9826 .ok_or(ConnectionError::UnsupportedExtension)?;
9827 let length_so_far = 0;
9828 let device_spec_bytes = self.device_spec.serialize();
9829 let virtual_mods_bytes = self.virtual_mods.serialize();
9830 let which = self.values.switch_expr();
9831 let which_bytes = which.serialize();
9832 let first_type_bytes = self.first_type.serialize();
9833 let n_types_bytes = self.n_types.serialize();
9834 let first_kt_levelt_bytes = self.first_kt_levelt.serialize();
9835 let n_kt_levels_bytes = self.n_kt_levels.serialize();
9836 let indicators_bytes = self.indicators.serialize();
9837 let group_names_bytes = self.group_names.serialize();
9838 let n_radio_groups_bytes = self.n_radio_groups.serialize();
9839 let first_key_bytes = self.first_key.serialize();
9840 let n_keys_bytes = self.n_keys.serialize();
9841 let n_key_aliases_bytes = self.n_key_aliases.serialize();
9842 let total_kt_level_names_bytes = self.total_kt_level_names.serialize();
9843 let mut request0 = vec![
9844 extension_information.major_opcode,
9845 SET_NAMES_REQUEST,
9846 0,
9847 0,
9848 device_spec_bytes[0],
9849 device_spec_bytes[1],
9850 virtual_mods_bytes[0],
9851 virtual_mods_bytes[1],
9852 which_bytes[0],
9853 which_bytes[1],
9854 which_bytes[2],
9855 which_bytes[3],
9856 first_type_bytes[0],
9857 n_types_bytes[0],
9858 first_kt_levelt_bytes[0],
9859 n_kt_levels_bytes[0],
9860 indicators_bytes[0],
9861 indicators_bytes[1],
9862 indicators_bytes[2],
9863 indicators_bytes[3],
9864 group_names_bytes[0],
9865 n_radio_groups_bytes[0],
9866 first_key_bytes[0],
9867 n_keys_bytes[0],
9868 n_key_aliases_bytes[0],
9869 0,
9870 total_kt_level_names_bytes[0],
9871 total_kt_level_names_bytes[1],
9872 ];
9873 let length_so_far = length_so_far + request0.len();
9874 let values_bytes = self.values.serialize(which, self.n_types, self.indicators, self.virtual_mods, self.group_names, self.n_keys, self.n_key_aliases, self.n_radio_groups);
9875 let length_so_far = length_so_far + values_bytes.len();
9876 let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
9877 let length_so_far = length_so_far + padding0.len();
9878 assert_eq!(length_so_far % 4, 0);
9879 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
9880 request0[2..4].copy_from_slice(&length.to_ne_bytes());
9881 Ok((vec![request0.into(), values_bytes.into(), padding0.into()], vec![]))
9882 }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,9883 pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
9884 where
9885 Conn: RequestConnection + ?Sized,
9886 {
9887 let (bytes, fds) = self.serialize(conn)?;
9888 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
9889 conn.send_request_without_reply(&slices, fds)
9890 }
9891 /// 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>9892 pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
9893 if header.minor_opcode != SET_NAMES_REQUEST {
9894 return Err(ParseError::InvalidValue);
9895 }
9896 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
9897 let (virtual_mods, remaining) = u16::try_parse(remaining)?;
9898 let (which, remaining) = u32::try_parse(remaining)?;
9899 let (first_type, remaining) = u8::try_parse(remaining)?;
9900 let (n_types, remaining) = u8::try_parse(remaining)?;
9901 let (first_kt_levelt, remaining) = u8::try_parse(remaining)?;
9902 let (n_kt_levels, remaining) = u8::try_parse(remaining)?;
9903 let (indicators, remaining) = u32::try_parse(remaining)?;
9904 let (group_names, remaining) = u8::try_parse(remaining)?;
9905 let (n_radio_groups, remaining) = u8::try_parse(remaining)?;
9906 let (first_key, remaining) = xproto::Keycode::try_parse(remaining)?;
9907 let (n_keys, remaining) = u8::try_parse(remaining)?;
9908 let (n_key_aliases, remaining) = u8::try_parse(remaining)?;
9909 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
9910 let (total_kt_level_names, remaining) = u16::try_parse(remaining)?;
9911 let (values, remaining) = SetNamesAux::try_parse(remaining, which, n_types, indicators, virtual_mods, group_names, n_keys, n_key_aliases, n_radio_groups)?;
9912 let _ = remaining;
9913 Ok(SetNamesRequest {
9914 device_spec,
9915 virtual_mods,
9916 first_type,
9917 n_types,
9918 first_kt_levelt,
9919 n_kt_levels,
9920 indicators,
9921 group_names,
9922 n_radio_groups,
9923 first_key,
9924 n_keys,
9925 n_key_aliases,
9926 total_kt_level_names,
9927 values: Cow::Owned(values),
9928 })
9929 }
9930 /// Clone all borrowed data in this SetNamesRequest.
into_owned(self) -> SetNamesRequest<'static>9931 pub fn into_owned(self) -> SetNamesRequest<'static> {
9932 SetNamesRequest {
9933 device_spec: self.device_spec,
9934 virtual_mods: self.virtual_mods,
9935 first_type: self.first_type,
9936 n_types: self.n_types,
9937 first_kt_levelt: self.first_kt_levelt,
9938 n_kt_levels: self.n_kt_levels,
9939 indicators: self.indicators,
9940 group_names: self.group_names,
9941 n_radio_groups: self.n_radio_groups,
9942 first_key: self.first_key,
9943 n_keys: self.n_keys,
9944 n_key_aliases: self.n_key_aliases,
9945 total_kt_level_names: self.total_kt_level_names,
9946 values: Cow::Owned(self.values.into_owned()),
9947 }
9948 }
9949 }
9950 impl<'input> Request for SetNamesRequest<'input> {
9951 type Reply = ();
9952 }
set_names<'c, 'input, Conn, A, B>(conn: &'c Conn, device_spec: DeviceSpec, virtual_mods: A, first_type: u8, n_types: u8, first_kt_levelt: u8, n_kt_levels: u8, indicators: u32, group_names: B, n_radio_groups: u8, first_key: xproto::Keycode, n_keys: u8, n_key_aliases: u8, total_kt_level_names: u16, values: &'input SetNamesAux) -> Result<VoidCookie<'c, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<u16>, B: Into<u8>,9953 pub fn set_names<'c, 'input, Conn, A, B>(conn: &'c Conn, device_spec: DeviceSpec, virtual_mods: A, first_type: u8, n_types: u8, first_kt_levelt: u8, n_kt_levels: u8, indicators: u32, group_names: B, n_radio_groups: u8, first_key: xproto::Keycode, n_keys: u8, n_key_aliases: u8, total_kt_level_names: u16, values: &'input SetNamesAux) -> Result<VoidCookie<'c, Conn>, ConnectionError>
9954 where
9955 Conn: RequestConnection + ?Sized,
9956 A: Into<u16>,
9957 B: Into<u8>,
9958 {
9959 let virtual_mods: u16 = virtual_mods.into();
9960 let group_names: u8 = group_names.into();
9961 let request0 = SetNamesRequest {
9962 device_spec,
9963 virtual_mods,
9964 first_type,
9965 n_types,
9966 first_kt_levelt,
9967 n_kt_levels,
9968 indicators,
9969 group_names,
9970 n_radio_groups,
9971 first_key,
9972 n_keys,
9973 n_key_aliases,
9974 total_kt_level_names,
9975 values: Cow::Borrowed(values),
9976 };
9977 request0.send(conn)
9978 }
9979
9980 /// Opcode for the PerClientFlags request
9981 pub const PER_CLIENT_FLAGS_REQUEST: u8 = 21;
9982 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
9983 pub struct PerClientFlagsRequest {
9984 pub device_spec: DeviceSpec,
9985 pub change: u32,
9986 pub value: u32,
9987 pub ctrls_to_change: u32,
9988 pub auto_ctrls: u32,
9989 pub auto_ctrls_values: u32,
9990 }
9991 impl PerClientFlagsRequest {
9992 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,9993 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
9994 where
9995 Conn: RequestConnection + ?Sized,
9996 {
9997 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
9998 .ok_or(ConnectionError::UnsupportedExtension)?;
9999 let length_so_far = 0;
10000 let device_spec_bytes = self.device_spec.serialize();
10001 let change_bytes = self.change.serialize();
10002 let value_bytes = self.value.serialize();
10003 let ctrls_to_change_bytes = self.ctrls_to_change.serialize();
10004 let auto_ctrls_bytes = self.auto_ctrls.serialize();
10005 let auto_ctrls_values_bytes = self.auto_ctrls_values.serialize();
10006 let mut request0 = vec![
10007 extension_information.major_opcode,
10008 PER_CLIENT_FLAGS_REQUEST,
10009 0,
10010 0,
10011 device_spec_bytes[0],
10012 device_spec_bytes[1],
10013 0,
10014 0,
10015 change_bytes[0],
10016 change_bytes[1],
10017 change_bytes[2],
10018 change_bytes[3],
10019 value_bytes[0],
10020 value_bytes[1],
10021 value_bytes[2],
10022 value_bytes[3],
10023 ctrls_to_change_bytes[0],
10024 ctrls_to_change_bytes[1],
10025 ctrls_to_change_bytes[2],
10026 ctrls_to_change_bytes[3],
10027 auto_ctrls_bytes[0],
10028 auto_ctrls_bytes[1],
10029 auto_ctrls_bytes[2],
10030 auto_ctrls_bytes[3],
10031 auto_ctrls_values_bytes[0],
10032 auto_ctrls_values_bytes[1],
10033 auto_ctrls_values_bytes[2],
10034 auto_ctrls_values_bytes[3],
10035 ];
10036 let length_so_far = length_so_far + request0.len();
10037 assert_eq!(length_so_far % 4, 0);
10038 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
10039 request0[2..4].copy_from_slice(&length.to_ne_bytes());
10040 Ok((vec![request0.into()], vec![]))
10041 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, PerClientFlagsReply>, ConnectionError> where Conn: RequestConnection + ?Sized,10042 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, PerClientFlagsReply>, ConnectionError>
10043 where
10044 Conn: RequestConnection + ?Sized,
10045 {
10046 let (bytes, fds) = self.serialize(conn)?;
10047 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
10048 conn.send_request_with_reply(&slices, fds)
10049 }
10050 /// 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>10051 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
10052 if header.minor_opcode != PER_CLIENT_FLAGS_REQUEST {
10053 return Err(ParseError::InvalidValue);
10054 }
10055 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
10056 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
10057 let (change, remaining) = u32::try_parse(remaining)?;
10058 let (value, remaining) = u32::try_parse(remaining)?;
10059 let (ctrls_to_change, remaining) = u32::try_parse(remaining)?;
10060 let (auto_ctrls, remaining) = u32::try_parse(remaining)?;
10061 let (auto_ctrls_values, remaining) = u32::try_parse(remaining)?;
10062 let _ = remaining;
10063 Ok(PerClientFlagsRequest {
10064 device_spec,
10065 change,
10066 value,
10067 ctrls_to_change,
10068 auto_ctrls,
10069 auto_ctrls_values,
10070 })
10071 }
10072 }
10073 impl Request for PerClientFlagsRequest {
10074 type Reply = PerClientFlagsReply;
10075 }
per_client_flags<Conn, A, B, C, D, E>(conn: &Conn, device_spec: DeviceSpec, change: A, value: B, ctrls_to_change: C, auto_ctrls: D, auto_ctrls_values: E) -> Result<Cookie<'_, Conn, PerClientFlagsReply>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<u32>, B: Into<u32>, C: Into<u32>, D: Into<u32>, E: Into<u32>,10076 pub fn per_client_flags<Conn, A, B, C, D, E>(conn: &Conn, device_spec: DeviceSpec, change: A, value: B, ctrls_to_change: C, auto_ctrls: D, auto_ctrls_values: E) -> Result<Cookie<'_, Conn, PerClientFlagsReply>, ConnectionError>
10077 where
10078 Conn: RequestConnection + ?Sized,
10079 A: Into<u32>,
10080 B: Into<u32>,
10081 C: Into<u32>,
10082 D: Into<u32>,
10083 E: Into<u32>,
10084 {
10085 let change: u32 = change.into();
10086 let value: u32 = value.into();
10087 let ctrls_to_change: u32 = ctrls_to_change.into();
10088 let auto_ctrls: u32 = auto_ctrls.into();
10089 let auto_ctrls_values: u32 = auto_ctrls_values.into();
10090 let request0 = PerClientFlagsRequest {
10091 device_spec,
10092 change,
10093 value,
10094 ctrls_to_change,
10095 auto_ctrls,
10096 auto_ctrls_values,
10097 };
10098 request0.send(conn)
10099 }
10100
10101 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
10102 pub struct PerClientFlagsReply {
10103 pub device_id: u8,
10104 pub sequence: u16,
10105 pub length: u32,
10106 pub supported: u32,
10107 pub value: u32,
10108 pub auto_ctrls: u32,
10109 pub auto_ctrls_values: u32,
10110 }
10111 impl TryParse for PerClientFlagsReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>10112 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
10113 let remaining = initial_value;
10114 let (response_type, remaining) = u8::try_parse(remaining)?;
10115 let (device_id, remaining) = u8::try_parse(remaining)?;
10116 let (sequence, remaining) = u16::try_parse(remaining)?;
10117 let (length, remaining) = u32::try_parse(remaining)?;
10118 let (supported, remaining) = u32::try_parse(remaining)?;
10119 let (value, remaining) = u32::try_parse(remaining)?;
10120 let (auto_ctrls, remaining) = u32::try_parse(remaining)?;
10121 let (auto_ctrls_values, remaining) = u32::try_parse(remaining)?;
10122 let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?;
10123 if response_type != 1 {
10124 return Err(ParseError::InvalidValue);
10125 }
10126 let result = PerClientFlagsReply { device_id, sequence, length, supported, value, auto_ctrls, auto_ctrls_values };
10127 let _ = remaining;
10128 let remaining = initial_value.get(32 + length as usize * 4..)
10129 .ok_or(ParseError::InsufficientData)?;
10130 Ok((result, remaining))
10131 }
10132 }
10133
10134 /// Opcode for the ListComponents request
10135 pub const LIST_COMPONENTS_REQUEST: u8 = 22;
10136 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
10137 pub struct ListComponentsRequest {
10138 pub device_spec: DeviceSpec,
10139 pub max_names: u16,
10140 }
10141 impl ListComponentsRequest {
10142 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,10143 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
10144 where
10145 Conn: RequestConnection + ?Sized,
10146 {
10147 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
10148 .ok_or(ConnectionError::UnsupportedExtension)?;
10149 let length_so_far = 0;
10150 let device_spec_bytes = self.device_spec.serialize();
10151 let max_names_bytes = self.max_names.serialize();
10152 let mut request0 = vec![
10153 extension_information.major_opcode,
10154 LIST_COMPONENTS_REQUEST,
10155 0,
10156 0,
10157 device_spec_bytes[0],
10158 device_spec_bytes[1],
10159 max_names_bytes[0],
10160 max_names_bytes[1],
10161 ];
10162 let length_so_far = length_so_far + request0.len();
10163 assert_eq!(length_so_far % 4, 0);
10164 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
10165 request0[2..4].copy_from_slice(&length.to_ne_bytes());
10166 Ok((vec![request0.into()], vec![]))
10167 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, ListComponentsReply>, ConnectionError> where Conn: RequestConnection + ?Sized,10168 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, ListComponentsReply>, ConnectionError>
10169 where
10170 Conn: RequestConnection + ?Sized,
10171 {
10172 let (bytes, fds) = self.serialize(conn)?;
10173 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
10174 conn.send_request_with_reply(&slices, fds)
10175 }
10176 /// 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>10177 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
10178 if header.minor_opcode != LIST_COMPONENTS_REQUEST {
10179 return Err(ParseError::InvalidValue);
10180 }
10181 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
10182 let (max_names, remaining) = u16::try_parse(remaining)?;
10183 let _ = remaining;
10184 Ok(ListComponentsRequest {
10185 device_spec,
10186 max_names,
10187 })
10188 }
10189 }
10190 impl Request for ListComponentsRequest {
10191 type Reply = ListComponentsReply;
10192 }
list_components<Conn>(conn: &Conn, device_spec: DeviceSpec, max_names: u16) -> Result<Cookie<'_, Conn, ListComponentsReply>, ConnectionError> where Conn: RequestConnection + ?Sized,10193 pub fn list_components<Conn>(conn: &Conn, device_spec: DeviceSpec, max_names: u16) -> Result<Cookie<'_, Conn, ListComponentsReply>, ConnectionError>
10194 where
10195 Conn: RequestConnection + ?Sized,
10196 {
10197 let request0 = ListComponentsRequest {
10198 device_spec,
10199 max_names,
10200 };
10201 request0.send(conn)
10202 }
10203
10204 #[derive(Debug, Clone, PartialEq, Eq)]
10205 pub struct ListComponentsReply {
10206 pub device_id: u8,
10207 pub sequence: u16,
10208 pub length: u32,
10209 pub extra: u16,
10210 pub keymaps: Vec<Listing>,
10211 pub keycodes: Vec<Listing>,
10212 pub types: Vec<Listing>,
10213 pub compat_maps: Vec<Listing>,
10214 pub symbols: Vec<Listing>,
10215 pub geometries: Vec<Listing>,
10216 }
10217 impl TryParse for ListComponentsReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>10218 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
10219 let remaining = initial_value;
10220 let (response_type, remaining) = u8::try_parse(remaining)?;
10221 let (device_id, remaining) = u8::try_parse(remaining)?;
10222 let (sequence, remaining) = u16::try_parse(remaining)?;
10223 let (length, remaining) = u32::try_parse(remaining)?;
10224 let (n_keymaps, remaining) = u16::try_parse(remaining)?;
10225 let (n_keycodes, remaining) = u16::try_parse(remaining)?;
10226 let (n_types, remaining) = u16::try_parse(remaining)?;
10227 let (n_compat_maps, remaining) = u16::try_parse(remaining)?;
10228 let (n_symbols, remaining) = u16::try_parse(remaining)?;
10229 let (n_geometries, remaining) = u16::try_parse(remaining)?;
10230 let (extra, remaining) = u16::try_parse(remaining)?;
10231 let remaining = remaining.get(10..).ok_or(ParseError::InsufficientData)?;
10232 let (keymaps, remaining) = crate::x11_utils::parse_list::<Listing>(remaining, n_keymaps.try_to_usize()?)?;
10233 let (keycodes, remaining) = crate::x11_utils::parse_list::<Listing>(remaining, n_keycodes.try_to_usize()?)?;
10234 let (types, remaining) = crate::x11_utils::parse_list::<Listing>(remaining, n_types.try_to_usize()?)?;
10235 let (compat_maps, remaining) = crate::x11_utils::parse_list::<Listing>(remaining, n_compat_maps.try_to_usize()?)?;
10236 let (symbols, remaining) = crate::x11_utils::parse_list::<Listing>(remaining, n_symbols.try_to_usize()?)?;
10237 let (geometries, remaining) = crate::x11_utils::parse_list::<Listing>(remaining, n_geometries.try_to_usize()?)?;
10238 if response_type != 1 {
10239 return Err(ParseError::InvalidValue);
10240 }
10241 let result = ListComponentsReply { device_id, sequence, length, extra, keymaps, keycodes, types, compat_maps, symbols, geometries };
10242 let _ = remaining;
10243 let remaining = initial_value.get(32 + length as usize * 4..)
10244 .ok_or(ParseError::InsufficientData)?;
10245 Ok((result, remaining))
10246 }
10247 }
10248 impl ListComponentsReply {
10249 /// Get the value of the `nKeymaps` field.
10250 ///
10251 /// The `nKeymaps` field is used as the length field of the `keymaps` field.
10252 /// This function computes the field's value again based on the length of the list.
10253 ///
10254 /// # Panics
10255 ///
10256 /// Panics if the value cannot be represented in the target type. This
10257 /// cannot happen with values of the struct received from the X11 server.
n_keymaps(&self) -> u1610258 pub fn n_keymaps(&self) -> u16 {
10259 self.keymaps.len()
10260 .try_into().unwrap()
10261 }
10262 /// Get the value of the `nKeycodes` field.
10263 ///
10264 /// The `nKeycodes` field is used as the length field of the `keycodes` field.
10265 /// This function computes the field's value again based on the length of the list.
10266 ///
10267 /// # Panics
10268 ///
10269 /// Panics if the value cannot be represented in the target type. This
10270 /// cannot happen with values of the struct received from the X11 server.
n_keycodes(&self) -> u1610271 pub fn n_keycodes(&self) -> u16 {
10272 self.keycodes.len()
10273 .try_into().unwrap()
10274 }
10275 /// Get the value of the `nTypes` field.
10276 ///
10277 /// The `nTypes` field is used as the length field of the `types` field.
10278 /// This function computes the field's value again based on the length of the list.
10279 ///
10280 /// # Panics
10281 ///
10282 /// Panics if the value cannot be represented in the target type. This
10283 /// cannot happen with values of the struct received from the X11 server.
n_types(&self) -> u1610284 pub fn n_types(&self) -> u16 {
10285 self.types.len()
10286 .try_into().unwrap()
10287 }
10288 /// Get the value of the `nCompatMaps` field.
10289 ///
10290 /// The `nCompatMaps` field is used as the length field of the `compatMaps` field.
10291 /// This function computes the field's value again based on the length of the list.
10292 ///
10293 /// # Panics
10294 ///
10295 /// Panics if the value cannot be represented in the target type. This
10296 /// cannot happen with values of the struct received from the X11 server.
n_compat_maps(&self) -> u1610297 pub fn n_compat_maps(&self) -> u16 {
10298 self.compat_maps.len()
10299 .try_into().unwrap()
10300 }
10301 /// Get the value of the `nSymbols` field.
10302 ///
10303 /// The `nSymbols` field is used as the length field of the `symbols` field.
10304 /// This function computes the field's value again based on the length of the list.
10305 ///
10306 /// # Panics
10307 ///
10308 /// Panics if the value cannot be represented in the target type. This
10309 /// cannot happen with values of the struct received from the X11 server.
n_symbols(&self) -> u1610310 pub fn n_symbols(&self) -> u16 {
10311 self.symbols.len()
10312 .try_into().unwrap()
10313 }
10314 /// Get the value of the `nGeometries` field.
10315 ///
10316 /// The `nGeometries` field is used as the length field of the `geometries` field.
10317 /// This function computes the field's value again based on the length of the list.
10318 ///
10319 /// # Panics
10320 ///
10321 /// Panics if the value cannot be represented in the target type. This
10322 /// cannot happen with values of the struct received from the X11 server.
n_geometries(&self) -> u1610323 pub fn n_geometries(&self) -> u16 {
10324 self.geometries.len()
10325 .try_into().unwrap()
10326 }
10327 }
10328
10329 /// Opcode for the GetKbdByName request
10330 pub const GET_KBD_BY_NAME_REQUEST: u8 = 23;
10331 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
10332 pub struct GetKbdByNameRequest {
10333 pub device_spec: DeviceSpec,
10334 pub need: u16,
10335 pub want: u16,
10336 pub load: bool,
10337 }
10338 impl GetKbdByNameRequest {
10339 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,10340 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
10341 where
10342 Conn: RequestConnection + ?Sized,
10343 {
10344 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
10345 .ok_or(ConnectionError::UnsupportedExtension)?;
10346 let length_so_far = 0;
10347 let device_spec_bytes = self.device_spec.serialize();
10348 let need_bytes = self.need.serialize();
10349 let want_bytes = self.want.serialize();
10350 let load_bytes = self.load.serialize();
10351 let mut request0 = vec![
10352 extension_information.major_opcode,
10353 GET_KBD_BY_NAME_REQUEST,
10354 0,
10355 0,
10356 device_spec_bytes[0],
10357 device_spec_bytes[1],
10358 need_bytes[0],
10359 need_bytes[1],
10360 want_bytes[0],
10361 want_bytes[1],
10362 load_bytes[0],
10363 0,
10364 ];
10365 let length_so_far = length_so_far + request0.len();
10366 assert_eq!(length_so_far % 4, 0);
10367 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
10368 request0[2..4].copy_from_slice(&length.to_ne_bytes());
10369 Ok((vec![request0.into()], vec![]))
10370 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetKbdByNameReply>, ConnectionError> where Conn: RequestConnection + ?Sized,10371 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetKbdByNameReply>, ConnectionError>
10372 where
10373 Conn: RequestConnection + ?Sized,
10374 {
10375 let (bytes, fds) = self.serialize(conn)?;
10376 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
10377 conn.send_request_with_reply(&slices, fds)
10378 }
10379 /// 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>10380 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
10381 if header.minor_opcode != GET_KBD_BY_NAME_REQUEST {
10382 return Err(ParseError::InvalidValue);
10383 }
10384 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
10385 let (need, remaining) = u16::try_parse(remaining)?;
10386 let (want, remaining) = u16::try_parse(remaining)?;
10387 let (load, remaining) = bool::try_parse(remaining)?;
10388 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
10389 let _ = remaining;
10390 Ok(GetKbdByNameRequest {
10391 device_spec,
10392 need,
10393 want,
10394 load,
10395 })
10396 }
10397 }
10398 impl Request for GetKbdByNameRequest {
10399 type Reply = GetKbdByNameReply;
10400 }
get_kbd_by_name<Conn, A, B>(conn: &Conn, device_spec: DeviceSpec, need: A, want: B, load: bool) -> Result<Cookie<'_, Conn, GetKbdByNameReply>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<u16>, B: Into<u16>,10401 pub fn get_kbd_by_name<Conn, A, B>(conn: &Conn, device_spec: DeviceSpec, need: A, want: B, load: bool) -> Result<Cookie<'_, Conn, GetKbdByNameReply>, ConnectionError>
10402 where
10403 Conn: RequestConnection + ?Sized,
10404 A: Into<u16>,
10405 B: Into<u16>,
10406 {
10407 let need: u16 = need.into();
10408 let want: u16 = want.into();
10409 let request0 = GetKbdByNameRequest {
10410 device_spec,
10411 need,
10412 want,
10413 load,
10414 };
10415 request0.send(conn)
10416 }
10417
10418 #[derive(Debug, Clone)]
10419 pub struct GetKbdByNameRepliesTypesMapBitcase3 {
10420 pub acts_rtrn_count: Vec<u8>,
10421 pub acts_rtrn_acts: Vec<Action>,
10422 }
10423 impl GetKbdByNameRepliesTypesMapBitcase3 {
try_parse(remaining: &[u8], n_key_actions: u8, total_actions: u16) -> Result<(Self, &[u8]), ParseError>10424 pub fn try_parse(remaining: &[u8], n_key_actions: u8, total_actions: u16) -> Result<(Self, &[u8]), ParseError> {
10425 let value = remaining;
10426 let (acts_rtrn_count, remaining) = crate::x11_utils::parse_u8_list(remaining, n_key_actions.try_to_usize()?)?;
10427 let acts_rtrn_count = acts_rtrn_count.to_vec();
10428 // Align offset to multiple of 4
10429 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
10430 let misalignment = (4 - (offset % 4)) % 4;
10431 let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
10432 let (acts_rtrn_acts, remaining) = crate::x11_utils::parse_list::<Action>(remaining, total_actions.try_to_usize()?)?;
10433 let result = GetKbdByNameRepliesTypesMapBitcase3 { acts_rtrn_count, acts_rtrn_acts };
10434 Ok((result, remaining))
10435 }
10436 }
10437 #[derive(Debug, Clone, Default)]
10438 pub struct GetKbdByNameRepliesTypesMap {
10439 pub types_rtrn: Option<Vec<KeyType>>,
10440 pub syms_rtrn: Option<Vec<KeySymMap>>,
10441 pub bitcase3: Option<GetKbdByNameRepliesTypesMapBitcase3>,
10442 pub behaviors_rtrn: Option<Vec<SetBehavior>>,
10443 pub vmods_rtrn: Option<Vec<u8>>,
10444 pub explicit_rtrn: Option<Vec<SetExplicit>>,
10445 pub modmap_rtrn: Option<Vec<KeyModMap>>,
10446 pub vmodmap_rtrn: Option<Vec<KeyVModMap>>,
10447 }
10448 impl GetKbdByNameRepliesTypesMap {
try_parse(value: &[u8], present: u16, n_types: u8, n_key_syms: u8, n_key_actions: u8, total_actions: u16, total_key_behaviors: u8, virtual_mods: u16, total_key_explicit: u8, total_mod_map_keys: u8, total_v_mod_map_keys: u8) -> Result<(Self, &[u8]), ParseError>10449 fn try_parse(value: &[u8], present: u16, n_types: u8, n_key_syms: u8, n_key_actions: u8, total_actions: u16, total_key_behaviors: u8, virtual_mods: u16, total_key_explicit: u8, total_mod_map_keys: u8, total_v_mod_map_keys: u8) -> Result<(Self, &[u8]), ParseError> {
10450 let switch_expr = u32::from(present);
10451 let mut outer_remaining = value;
10452 let types_rtrn = if switch_expr & u32::from(MapPart::KEY_TYPES) != 0 {
10453 let remaining = outer_remaining;
10454 let (types_rtrn, remaining) = crate::x11_utils::parse_list::<KeyType>(remaining, n_types.try_to_usize()?)?;
10455 outer_remaining = remaining;
10456 Some(types_rtrn)
10457 } else {
10458 None
10459 };
10460 let syms_rtrn = if switch_expr & u32::from(MapPart::KEY_SYMS) != 0 {
10461 let remaining = outer_remaining;
10462 let (syms_rtrn, remaining) = crate::x11_utils::parse_list::<KeySymMap>(remaining, n_key_syms.try_to_usize()?)?;
10463 outer_remaining = remaining;
10464 Some(syms_rtrn)
10465 } else {
10466 None
10467 };
10468 let bitcase3 = if switch_expr & u32::from(MapPart::KEY_ACTIONS) != 0 {
10469 let (bitcase3, new_remaining) = GetKbdByNameRepliesTypesMapBitcase3::try_parse(outer_remaining, n_key_actions, total_actions)?;
10470 outer_remaining = new_remaining;
10471 Some(bitcase3)
10472 } else {
10473 None
10474 };
10475 let behaviors_rtrn = if switch_expr & u32::from(MapPart::KEY_BEHAVIORS) != 0 {
10476 let remaining = outer_remaining;
10477 let (behaviors_rtrn, remaining) = crate::x11_utils::parse_list::<SetBehavior>(remaining, total_key_behaviors.try_to_usize()?)?;
10478 outer_remaining = remaining;
10479 Some(behaviors_rtrn)
10480 } else {
10481 None
10482 };
10483 let vmods_rtrn = if switch_expr & u32::from(MapPart::VIRTUAL_MODS) != 0 {
10484 let remaining = outer_remaining;
10485 let value = remaining;
10486 let (vmods_rtrn, remaining) = crate::x11_utils::parse_u8_list(remaining, virtual_mods.count_ones().try_to_usize()?)?;
10487 let vmods_rtrn = vmods_rtrn.to_vec();
10488 // Align offset to multiple of 4
10489 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
10490 let misalignment = (4 - (offset % 4)) % 4;
10491 let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
10492 outer_remaining = remaining;
10493 Some(vmods_rtrn)
10494 } else {
10495 None
10496 };
10497 let explicit_rtrn = if switch_expr & u32::from(MapPart::EXPLICIT_COMPONENTS) != 0 {
10498 let remaining = outer_remaining;
10499 let value = remaining;
10500 let (explicit_rtrn, remaining) = crate::x11_utils::parse_list::<SetExplicit>(remaining, total_key_explicit.try_to_usize()?)?;
10501 // Align offset to multiple of 4
10502 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
10503 let misalignment = (4 - (offset % 4)) % 4;
10504 let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
10505 outer_remaining = remaining;
10506 Some(explicit_rtrn)
10507 } else {
10508 None
10509 };
10510 let modmap_rtrn = if switch_expr & u32::from(MapPart::MODIFIER_MAP) != 0 {
10511 let remaining = outer_remaining;
10512 let value = remaining;
10513 let (modmap_rtrn, remaining) = crate::x11_utils::parse_list::<KeyModMap>(remaining, total_mod_map_keys.try_to_usize()?)?;
10514 // Align offset to multiple of 4
10515 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
10516 let misalignment = (4 - (offset % 4)) % 4;
10517 let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
10518 outer_remaining = remaining;
10519 Some(modmap_rtrn)
10520 } else {
10521 None
10522 };
10523 let vmodmap_rtrn = if switch_expr & u32::from(MapPart::VIRTUAL_MOD_MAP) != 0 {
10524 let remaining = outer_remaining;
10525 let (vmodmap_rtrn, remaining) = crate::x11_utils::parse_list::<KeyVModMap>(remaining, total_v_mod_map_keys.try_to_usize()?)?;
10526 outer_remaining = remaining;
10527 Some(vmodmap_rtrn)
10528 } else {
10529 None
10530 };
10531 let result = GetKbdByNameRepliesTypesMap { types_rtrn, syms_rtrn, bitcase3, behaviors_rtrn, vmods_rtrn, explicit_rtrn, modmap_rtrn, vmodmap_rtrn };
10532 Ok((result, outer_remaining))
10533 }
10534 }
10535
10536 #[derive(Debug, Clone)]
10537 pub struct GetKbdByNameRepliesTypes {
10538 pub getmap_type: u8,
10539 pub type_device_id: u8,
10540 pub getmap_sequence: u16,
10541 pub getmap_length: u32,
10542 pub type_min_key_code: xproto::Keycode,
10543 pub type_max_key_code: xproto::Keycode,
10544 pub first_type: u8,
10545 pub n_types: u8,
10546 pub total_types: u8,
10547 pub first_key_sym: xproto::Keycode,
10548 pub total_syms: u16,
10549 pub n_key_syms: u8,
10550 pub first_key_action: xproto::Keycode,
10551 pub total_actions: u16,
10552 pub n_key_actions: u8,
10553 pub first_key_behavior: xproto::Keycode,
10554 pub n_key_behaviors: u8,
10555 pub total_key_behaviors: u8,
10556 pub first_key_explicit: xproto::Keycode,
10557 pub n_key_explicit: u8,
10558 pub total_key_explicit: u8,
10559 pub first_mod_map_key: xproto::Keycode,
10560 pub n_mod_map_keys: u8,
10561 pub total_mod_map_keys: u8,
10562 pub first_v_mod_map_key: xproto::Keycode,
10563 pub n_v_mod_map_keys: u8,
10564 pub total_v_mod_map_keys: u8,
10565 pub virtual_mods: u16,
10566 pub map: GetKbdByNameRepliesTypesMap,
10567 }
10568 impl TryParse for GetKbdByNameRepliesTypes {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>10569 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
10570 let (getmap_type, remaining) = u8::try_parse(remaining)?;
10571 let (type_device_id, remaining) = u8::try_parse(remaining)?;
10572 let (getmap_sequence, remaining) = u16::try_parse(remaining)?;
10573 let (getmap_length, remaining) = u32::try_parse(remaining)?;
10574 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
10575 let (type_min_key_code, remaining) = xproto::Keycode::try_parse(remaining)?;
10576 let (type_max_key_code, remaining) = xproto::Keycode::try_parse(remaining)?;
10577 let (present, remaining) = u16::try_parse(remaining)?;
10578 let (first_type, remaining) = u8::try_parse(remaining)?;
10579 let (n_types, remaining) = u8::try_parse(remaining)?;
10580 let (total_types, remaining) = u8::try_parse(remaining)?;
10581 let (first_key_sym, remaining) = xproto::Keycode::try_parse(remaining)?;
10582 let (total_syms, remaining) = u16::try_parse(remaining)?;
10583 let (n_key_syms, remaining) = u8::try_parse(remaining)?;
10584 let (first_key_action, remaining) = xproto::Keycode::try_parse(remaining)?;
10585 let (total_actions, remaining) = u16::try_parse(remaining)?;
10586 let (n_key_actions, remaining) = u8::try_parse(remaining)?;
10587 let (first_key_behavior, remaining) = xproto::Keycode::try_parse(remaining)?;
10588 let (n_key_behaviors, remaining) = u8::try_parse(remaining)?;
10589 let (total_key_behaviors, remaining) = u8::try_parse(remaining)?;
10590 let (first_key_explicit, remaining) = xproto::Keycode::try_parse(remaining)?;
10591 let (n_key_explicit, remaining) = u8::try_parse(remaining)?;
10592 let (total_key_explicit, remaining) = u8::try_parse(remaining)?;
10593 let (first_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?;
10594 let (n_mod_map_keys, remaining) = u8::try_parse(remaining)?;
10595 let (total_mod_map_keys, remaining) = u8::try_parse(remaining)?;
10596 let (first_v_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?;
10597 let (n_v_mod_map_keys, remaining) = u8::try_parse(remaining)?;
10598 let (total_v_mod_map_keys, remaining) = u8::try_parse(remaining)?;
10599 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
10600 let (virtual_mods, remaining) = u16::try_parse(remaining)?;
10601 let (map, remaining) = GetKbdByNameRepliesTypesMap::try_parse(remaining, present, n_types, n_key_syms, n_key_actions, total_actions, total_key_behaviors, virtual_mods, total_key_explicit, total_mod_map_keys, total_v_mod_map_keys)?;
10602 let result = GetKbdByNameRepliesTypes { getmap_type, type_device_id, getmap_sequence, getmap_length, type_min_key_code, type_max_key_code, first_type, n_types, total_types, first_key_sym, total_syms, n_key_syms, first_key_action, total_actions, n_key_actions, first_key_behavior, n_key_behaviors, total_key_behaviors, first_key_explicit, n_key_explicit, total_key_explicit, first_mod_map_key, n_mod_map_keys, total_mod_map_keys, first_v_mod_map_key, n_v_mod_map_keys, total_v_mod_map_keys, virtual_mods, map };
10603 Ok((result, remaining))
10604 }
10605 }
10606 #[derive(Debug, Clone, PartialEq, Eq)]
10607 pub struct GetKbdByNameRepliesCompatMap {
10608 pub compatmap_type: u8,
10609 pub compat_device_id: u8,
10610 pub compatmap_sequence: u16,
10611 pub compatmap_length: u32,
10612 pub groups_rtrn: u8,
10613 pub first_si_rtrn: u16,
10614 pub n_total_si: u16,
10615 pub si_rtrn: Vec<SymInterpret>,
10616 pub group_rtrn: Vec<ModDef>,
10617 }
10618 impl TryParse for GetKbdByNameRepliesCompatMap {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>10619 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
10620 let (compatmap_type, remaining) = u8::try_parse(remaining)?;
10621 let (compat_device_id, remaining) = u8::try_parse(remaining)?;
10622 let (compatmap_sequence, remaining) = u16::try_parse(remaining)?;
10623 let (compatmap_length, remaining) = u32::try_parse(remaining)?;
10624 let (groups_rtrn, remaining) = u8::try_parse(remaining)?;
10625 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
10626 let (first_si_rtrn, remaining) = u16::try_parse(remaining)?;
10627 let (n_si_rtrn, remaining) = u16::try_parse(remaining)?;
10628 let (n_total_si, remaining) = u16::try_parse(remaining)?;
10629 let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?;
10630 let (si_rtrn, remaining) = crate::x11_utils::parse_list::<SymInterpret>(remaining, n_si_rtrn.try_to_usize()?)?;
10631 let (group_rtrn, remaining) = crate::x11_utils::parse_list::<ModDef>(remaining, groups_rtrn.count_ones().try_to_usize()?)?;
10632 let result = GetKbdByNameRepliesCompatMap { compatmap_type, compat_device_id, compatmap_sequence, compatmap_length, groups_rtrn, first_si_rtrn, n_total_si, si_rtrn, group_rtrn };
10633 Ok((result, remaining))
10634 }
10635 }
10636 impl GetKbdByNameRepliesCompatMap {
10637 /// Get the value of the `nSIRtrn` field.
10638 ///
10639 /// The `nSIRtrn` field is used as the length field of the `si_rtrn` field.
10640 /// This function computes the field's value again based on the length of the list.
10641 ///
10642 /// # Panics
10643 ///
10644 /// Panics if the value cannot be represented in the target type. This
10645 /// cannot happen with values of the struct received from the X11 server.
n_si_rtrn(&self) -> u1610646 pub fn n_si_rtrn(&self) -> u16 {
10647 self.si_rtrn.len()
10648 .try_into().unwrap()
10649 }
10650 }
10651 #[derive(Debug, Clone, PartialEq, Eq)]
10652 pub struct GetKbdByNameRepliesIndicatorMaps {
10653 pub indicatormap_type: u8,
10654 pub indicator_device_id: u8,
10655 pub indicatormap_sequence: u16,
10656 pub indicatormap_length: u32,
10657 pub which: u32,
10658 pub real_indicators: u32,
10659 pub maps: Vec<IndicatorMap>,
10660 }
10661 impl TryParse for GetKbdByNameRepliesIndicatorMaps {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>10662 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
10663 let (indicatormap_type, remaining) = u8::try_parse(remaining)?;
10664 let (indicator_device_id, remaining) = u8::try_parse(remaining)?;
10665 let (indicatormap_sequence, remaining) = u16::try_parse(remaining)?;
10666 let (indicatormap_length, remaining) = u32::try_parse(remaining)?;
10667 let (which, remaining) = u32::try_parse(remaining)?;
10668 let (real_indicators, remaining) = u32::try_parse(remaining)?;
10669 let (n_indicators, remaining) = u8::try_parse(remaining)?;
10670 let remaining = remaining.get(15..).ok_or(ParseError::InsufficientData)?;
10671 let (maps, remaining) = crate::x11_utils::parse_list::<IndicatorMap>(remaining, n_indicators.try_to_usize()?)?;
10672 let result = GetKbdByNameRepliesIndicatorMaps { indicatormap_type, indicator_device_id, indicatormap_sequence, indicatormap_length, which, real_indicators, maps };
10673 Ok((result, remaining))
10674 }
10675 }
10676 impl GetKbdByNameRepliesIndicatorMaps {
10677 /// Get the value of the `nIndicators` field.
10678 ///
10679 /// The `nIndicators` field is used as the length field of the `maps` field.
10680 /// This function computes the field's value again based on the length of the list.
10681 ///
10682 /// # Panics
10683 ///
10684 /// Panics if the value cannot be represented in the target type. This
10685 /// cannot happen with values of the struct received from the X11 server.
n_indicators(&self) -> u810686 pub fn n_indicators(&self) -> u8 {
10687 self.maps.len()
10688 .try_into().unwrap()
10689 }
10690 }
10691 #[derive(Debug, Clone, PartialEq, Eq)]
10692 pub struct GetKbdByNameRepliesKeyNamesValueListBitcase8 {
10693 pub n_levels_per_type: Vec<u8>,
10694 pub kt_level_names: Vec<xproto::Atom>,
10695 }
10696 impl GetKbdByNameRepliesKeyNamesValueListBitcase8 {
try_parse(remaining: &[u8], n_types: u8) -> Result<(Self, &[u8]), ParseError>10697 pub fn try_parse(remaining: &[u8], n_types: u8) -> Result<(Self, &[u8]), ParseError> {
10698 let value = remaining;
10699 let (n_levels_per_type, remaining) = crate::x11_utils::parse_u8_list(remaining, n_types.try_to_usize()?)?;
10700 let n_levels_per_type = n_levels_per_type.to_vec();
10701 // Align offset to multiple of 4
10702 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
10703 let misalignment = (4 - (offset % 4)) % 4;
10704 let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
10705 let (kt_level_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, n_levels_per_type.iter().try_fold(0u32, |acc, x| acc.checked_add(u32::from(*x)).ok_or(ParseError::InvalidExpression))?.try_to_usize()?)?;
10706 let result = GetKbdByNameRepliesKeyNamesValueListBitcase8 { n_levels_per_type, kt_level_names };
10707 Ok((result, remaining))
10708 }
10709 }
10710 #[derive(Debug, Clone, PartialEq, Eq, Default)]
10711 pub struct GetKbdByNameRepliesKeyNamesValueList {
10712 pub keycodes_name: Option<xproto::Atom>,
10713 pub geometry_name: Option<xproto::Atom>,
10714 pub symbols_name: Option<xproto::Atom>,
10715 pub phys_symbols_name: Option<xproto::Atom>,
10716 pub types_name: Option<xproto::Atom>,
10717 pub compat_name: Option<xproto::Atom>,
10718 pub type_names: Option<Vec<xproto::Atom>>,
10719 pub bitcase8: Option<GetKbdByNameRepliesKeyNamesValueListBitcase8>,
10720 pub indicator_names: Option<Vec<xproto::Atom>>,
10721 pub virtual_mod_names: Option<Vec<xproto::Atom>>,
10722 pub groups: Option<Vec<xproto::Atom>>,
10723 pub key_names: Option<Vec<KeyName>>,
10724 pub key_aliases: Option<Vec<KeyAlias>>,
10725 pub radio_group_names: Option<Vec<xproto::Atom>>,
10726 }
10727 impl GetKbdByNameRepliesKeyNamesValueList {
try_parse(value: &[u8], which: u32, n_types: u8, indicators: u32, virtual_mods: u16, group_names: u8, n_keys: u8, n_key_aliases: u8, n_radio_groups: u8) -> Result<(Self, &[u8]), ParseError>10728 fn try_parse(value: &[u8], which: u32, n_types: u8, indicators: u32, virtual_mods: u16, group_names: u8, n_keys: u8, n_key_aliases: u8, n_radio_groups: u8) -> Result<(Self, &[u8]), ParseError> {
10729 let switch_expr = which;
10730 let mut outer_remaining = value;
10731 let keycodes_name = if switch_expr & u32::from(NameDetail::KEYCODES) != 0 {
10732 let remaining = outer_remaining;
10733 let (keycodes_name, remaining) = xproto::Atom::try_parse(remaining)?;
10734 outer_remaining = remaining;
10735 Some(keycodes_name)
10736 } else {
10737 None
10738 };
10739 let geometry_name = if switch_expr & u32::from(NameDetail::GEOMETRY) != 0 {
10740 let remaining = outer_remaining;
10741 let (geometry_name, remaining) = xproto::Atom::try_parse(remaining)?;
10742 outer_remaining = remaining;
10743 Some(geometry_name)
10744 } else {
10745 None
10746 };
10747 let symbols_name = if switch_expr & u32::from(NameDetail::SYMBOLS) != 0 {
10748 let remaining = outer_remaining;
10749 let (symbols_name, remaining) = xproto::Atom::try_parse(remaining)?;
10750 outer_remaining = remaining;
10751 Some(symbols_name)
10752 } else {
10753 None
10754 };
10755 let phys_symbols_name = if switch_expr & u32::from(NameDetail::PHYS_SYMBOLS) != 0 {
10756 let remaining = outer_remaining;
10757 let (phys_symbols_name, remaining) = xproto::Atom::try_parse(remaining)?;
10758 outer_remaining = remaining;
10759 Some(phys_symbols_name)
10760 } else {
10761 None
10762 };
10763 let types_name = if switch_expr & u32::from(NameDetail::TYPES) != 0 {
10764 let remaining = outer_remaining;
10765 let (types_name, remaining) = xproto::Atom::try_parse(remaining)?;
10766 outer_remaining = remaining;
10767 Some(types_name)
10768 } else {
10769 None
10770 };
10771 let compat_name = if switch_expr & u32::from(NameDetail::COMPAT) != 0 {
10772 let remaining = outer_remaining;
10773 let (compat_name, remaining) = xproto::Atom::try_parse(remaining)?;
10774 outer_remaining = remaining;
10775 Some(compat_name)
10776 } else {
10777 None
10778 };
10779 let type_names = if switch_expr & u32::from(NameDetail::KEY_TYPE_NAMES) != 0 {
10780 let remaining = outer_remaining;
10781 let (type_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, n_types.try_to_usize()?)?;
10782 outer_remaining = remaining;
10783 Some(type_names)
10784 } else {
10785 None
10786 };
10787 let bitcase8 = if switch_expr & u32::from(NameDetail::KT_LEVEL_NAMES) != 0 {
10788 let (bitcase8, new_remaining) = GetKbdByNameRepliesKeyNamesValueListBitcase8::try_parse(outer_remaining, n_types)?;
10789 outer_remaining = new_remaining;
10790 Some(bitcase8)
10791 } else {
10792 None
10793 };
10794 let indicator_names = if switch_expr & u32::from(NameDetail::INDICATOR_NAMES) != 0 {
10795 let remaining = outer_remaining;
10796 let (indicator_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, indicators.count_ones().try_to_usize()?)?;
10797 outer_remaining = remaining;
10798 Some(indicator_names)
10799 } else {
10800 None
10801 };
10802 let virtual_mod_names = if switch_expr & u32::from(NameDetail::VIRTUAL_MOD_NAMES) != 0 {
10803 let remaining = outer_remaining;
10804 let (virtual_mod_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, virtual_mods.count_ones().try_to_usize()?)?;
10805 outer_remaining = remaining;
10806 Some(virtual_mod_names)
10807 } else {
10808 None
10809 };
10810 let groups = if switch_expr & u32::from(NameDetail::GROUP_NAMES) != 0 {
10811 let remaining = outer_remaining;
10812 let (groups, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, group_names.count_ones().try_to_usize()?)?;
10813 outer_remaining = remaining;
10814 Some(groups)
10815 } else {
10816 None
10817 };
10818 let key_names = if switch_expr & u32::from(NameDetail::KEY_NAMES) != 0 {
10819 let remaining = outer_remaining;
10820 let (key_names, remaining) = crate::x11_utils::parse_list::<KeyName>(remaining, n_keys.try_to_usize()?)?;
10821 outer_remaining = remaining;
10822 Some(key_names)
10823 } else {
10824 None
10825 };
10826 let key_aliases = if switch_expr & u32::from(NameDetail::KEY_ALIASES) != 0 {
10827 let remaining = outer_remaining;
10828 let (key_aliases, remaining) = crate::x11_utils::parse_list::<KeyAlias>(remaining, n_key_aliases.try_to_usize()?)?;
10829 outer_remaining = remaining;
10830 Some(key_aliases)
10831 } else {
10832 None
10833 };
10834 let radio_group_names = if switch_expr & u32::from(NameDetail::RG_NAMES) != 0 {
10835 let remaining = outer_remaining;
10836 let (radio_group_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, n_radio_groups.try_to_usize()?)?;
10837 outer_remaining = remaining;
10838 Some(radio_group_names)
10839 } else {
10840 None
10841 };
10842 let result = GetKbdByNameRepliesKeyNamesValueList { keycodes_name, geometry_name, symbols_name, phys_symbols_name, types_name, compat_name, type_names, bitcase8, indicator_names, virtual_mod_names, groups, key_names, key_aliases, radio_group_names };
10843 Ok((result, outer_remaining))
10844 }
10845 }
10846
10847 #[derive(Debug, Clone, PartialEq, Eq)]
10848 pub struct GetKbdByNameRepliesKeyNames {
10849 pub keyname_type: u8,
10850 pub key_device_id: u8,
10851 pub keyname_sequence: u16,
10852 pub keyname_length: u32,
10853 pub key_min_key_code: xproto::Keycode,
10854 pub key_max_key_code: xproto::Keycode,
10855 pub n_types: u8,
10856 pub group_names: u8,
10857 pub virtual_mods: u16,
10858 pub first_key: xproto::Keycode,
10859 pub n_keys: u8,
10860 pub indicators: u32,
10861 pub n_radio_groups: u8,
10862 pub n_key_aliases: u8,
10863 pub n_kt_levels: u16,
10864 pub value_list: GetKbdByNameRepliesKeyNamesValueList,
10865 }
10866 impl TryParse for GetKbdByNameRepliesKeyNames {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>10867 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
10868 let (keyname_type, remaining) = u8::try_parse(remaining)?;
10869 let (key_device_id, remaining) = u8::try_parse(remaining)?;
10870 let (keyname_sequence, remaining) = u16::try_parse(remaining)?;
10871 let (keyname_length, remaining) = u32::try_parse(remaining)?;
10872 let (which, remaining) = u32::try_parse(remaining)?;
10873 let (key_min_key_code, remaining) = xproto::Keycode::try_parse(remaining)?;
10874 let (key_max_key_code, remaining) = xproto::Keycode::try_parse(remaining)?;
10875 let (n_types, remaining) = u8::try_parse(remaining)?;
10876 let (group_names, remaining) = u8::try_parse(remaining)?;
10877 let (virtual_mods, remaining) = u16::try_parse(remaining)?;
10878 let (first_key, remaining) = xproto::Keycode::try_parse(remaining)?;
10879 let (n_keys, remaining) = u8::try_parse(remaining)?;
10880 let (indicators, remaining) = u32::try_parse(remaining)?;
10881 let (n_radio_groups, remaining) = u8::try_parse(remaining)?;
10882 let (n_key_aliases, remaining) = u8::try_parse(remaining)?;
10883 let (n_kt_levels, remaining) = u16::try_parse(remaining)?;
10884 let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?;
10885 let (value_list, remaining) = GetKbdByNameRepliesKeyNamesValueList::try_parse(remaining, which, n_types, indicators, virtual_mods, group_names, n_keys, n_key_aliases, n_radio_groups)?;
10886 let result = GetKbdByNameRepliesKeyNames { keyname_type, key_device_id, keyname_sequence, keyname_length, key_min_key_code, key_max_key_code, n_types, group_names, virtual_mods, first_key, n_keys, indicators, n_radio_groups, n_key_aliases, n_kt_levels, value_list };
10887 Ok((result, remaining))
10888 }
10889 }
10890 #[derive(Debug, Clone, PartialEq, Eq)]
10891 pub struct GetKbdByNameRepliesGeometry {
10892 pub geometry_type: u8,
10893 pub geometry_device_id: u8,
10894 pub geometry_sequence: u16,
10895 pub geometry_length: u32,
10896 pub name: xproto::Atom,
10897 pub geometry_found: bool,
10898 pub width_mm: u16,
10899 pub height_mm: u16,
10900 pub n_properties: u16,
10901 pub n_colors: u16,
10902 pub n_shapes: u16,
10903 pub n_sections: u16,
10904 pub n_doodads: u16,
10905 pub n_key_aliases: u16,
10906 pub base_color_ndx: u8,
10907 pub label_color_ndx: u8,
10908 pub label_font: CountedString16,
10909 }
10910 impl TryParse for GetKbdByNameRepliesGeometry {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>10911 fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
10912 let (geometry_type, remaining) = u8::try_parse(remaining)?;
10913 let (geometry_device_id, remaining) = u8::try_parse(remaining)?;
10914 let (geometry_sequence, remaining) = u16::try_parse(remaining)?;
10915 let (geometry_length, remaining) = u32::try_parse(remaining)?;
10916 let (name, remaining) = xproto::Atom::try_parse(remaining)?;
10917 let (geometry_found, remaining) = bool::try_parse(remaining)?;
10918 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
10919 let (width_mm, remaining) = u16::try_parse(remaining)?;
10920 let (height_mm, remaining) = u16::try_parse(remaining)?;
10921 let (n_properties, remaining) = u16::try_parse(remaining)?;
10922 let (n_colors, remaining) = u16::try_parse(remaining)?;
10923 let (n_shapes, remaining) = u16::try_parse(remaining)?;
10924 let (n_sections, remaining) = u16::try_parse(remaining)?;
10925 let (n_doodads, remaining) = u16::try_parse(remaining)?;
10926 let (n_key_aliases, remaining) = u16::try_parse(remaining)?;
10927 let (base_color_ndx, remaining) = u8::try_parse(remaining)?;
10928 let (label_color_ndx, remaining) = u8::try_parse(remaining)?;
10929 let (label_font, remaining) = CountedString16::try_parse(remaining)?;
10930 let result = GetKbdByNameRepliesGeometry { geometry_type, geometry_device_id, geometry_sequence, geometry_length, name, geometry_found, width_mm, height_mm, n_properties, n_colors, n_shapes, n_sections, n_doodads, n_key_aliases, base_color_ndx, label_color_ndx, label_font };
10931 Ok((result, remaining))
10932 }
10933 }
10934 #[derive(Debug, Clone, Default)]
10935 pub struct GetKbdByNameReplies {
10936 pub types: Option<GetKbdByNameRepliesTypes>,
10937 pub compat_map: Option<GetKbdByNameRepliesCompatMap>,
10938 pub indicator_maps: Option<GetKbdByNameRepliesIndicatorMaps>,
10939 pub key_names: Option<GetKbdByNameRepliesKeyNames>,
10940 pub geometry: Option<GetKbdByNameRepliesGeometry>,
10941 }
10942 impl GetKbdByNameReplies {
try_parse(value: &[u8], reported: u16) -> Result<(Self, &[u8]), ParseError>10943 fn try_parse(value: &[u8], reported: u16) -> Result<(Self, &[u8]), ParseError> {
10944 let switch_expr = u32::from(reported);
10945 let mut outer_remaining = value;
10946 let types = if switch_expr & u32::from(GBNDetail::TYPES) != 0 || switch_expr & u32::from(GBNDetail::CLIENT_SYMBOLS) != 0 || switch_expr & u32::from(GBNDetail::SERVER_SYMBOLS) != 0 {
10947 let (types, new_remaining) = GetKbdByNameRepliesTypes::try_parse(outer_remaining)?;
10948 outer_remaining = new_remaining;
10949 Some(types)
10950 } else {
10951 None
10952 };
10953 let compat_map = if switch_expr & u32::from(GBNDetail::COMPAT_MAP) != 0 {
10954 let (compat_map, new_remaining) = GetKbdByNameRepliesCompatMap::try_parse(outer_remaining)?;
10955 outer_remaining = new_remaining;
10956 Some(compat_map)
10957 } else {
10958 None
10959 };
10960 let indicator_maps = if switch_expr & u32::from(GBNDetail::INDICATOR_MAPS) != 0 {
10961 let (indicator_maps, new_remaining) = GetKbdByNameRepliesIndicatorMaps::try_parse(outer_remaining)?;
10962 outer_remaining = new_remaining;
10963 Some(indicator_maps)
10964 } else {
10965 None
10966 };
10967 let key_names = if switch_expr & u32::from(GBNDetail::KEY_NAMES) != 0 || switch_expr & u32::from(GBNDetail::OTHER_NAMES) != 0 {
10968 let (key_names, new_remaining) = GetKbdByNameRepliesKeyNames::try_parse(outer_remaining)?;
10969 outer_remaining = new_remaining;
10970 Some(key_names)
10971 } else {
10972 None
10973 };
10974 let geometry = if switch_expr & u32::from(GBNDetail::GEOMETRY) != 0 {
10975 let (geometry, new_remaining) = GetKbdByNameRepliesGeometry::try_parse(outer_remaining)?;
10976 outer_remaining = new_remaining;
10977 Some(geometry)
10978 } else {
10979 None
10980 };
10981 let result = GetKbdByNameReplies { types, compat_map, indicator_maps, key_names, geometry };
10982 Ok((result, outer_remaining))
10983 }
10984 }
10985
10986 #[derive(Debug, Clone)]
10987 pub struct GetKbdByNameReply {
10988 pub device_id: u8,
10989 pub sequence: u16,
10990 pub length: u32,
10991 pub min_key_code: xproto::Keycode,
10992 pub max_key_code: xproto::Keycode,
10993 pub loaded: bool,
10994 pub new_keyboard: bool,
10995 pub found: u16,
10996 pub reported: u16,
10997 pub replies: GetKbdByNameReplies,
10998 }
10999 impl TryParse for GetKbdByNameReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>11000 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
11001 let remaining = initial_value;
11002 let (response_type, remaining) = u8::try_parse(remaining)?;
11003 let (device_id, remaining) = u8::try_parse(remaining)?;
11004 let (sequence, remaining) = u16::try_parse(remaining)?;
11005 let (length, remaining) = u32::try_parse(remaining)?;
11006 let (min_key_code, remaining) = xproto::Keycode::try_parse(remaining)?;
11007 let (max_key_code, remaining) = xproto::Keycode::try_parse(remaining)?;
11008 let (loaded, remaining) = bool::try_parse(remaining)?;
11009 let (new_keyboard, remaining) = bool::try_parse(remaining)?;
11010 let (found, remaining) = u16::try_parse(remaining)?;
11011 let (reported, remaining) = u16::try_parse(remaining)?;
11012 let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?;
11013 let (replies, remaining) = GetKbdByNameReplies::try_parse(remaining, reported)?;
11014 if response_type != 1 {
11015 return Err(ParseError::InvalidValue);
11016 }
11017 let result = GetKbdByNameReply { device_id, sequence, length, min_key_code, max_key_code, loaded, new_keyboard, found, reported, replies };
11018 let _ = remaining;
11019 let remaining = initial_value.get(32 + length as usize * 4..)
11020 .ok_or(ParseError::InsufficientData)?;
11021 Ok((result, remaining))
11022 }
11023 }
11024
11025 /// Opcode for the GetDeviceInfo request
11026 pub const GET_DEVICE_INFO_REQUEST: u8 = 24;
11027 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
11028 pub struct GetDeviceInfoRequest {
11029 pub device_spec: DeviceSpec,
11030 pub wanted: u16,
11031 pub all_buttons: bool,
11032 pub first_button: u8,
11033 pub n_buttons: u8,
11034 pub led_class: LedClass,
11035 pub led_id: IDSpec,
11036 }
11037 impl GetDeviceInfoRequest {
11038 /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,11039 fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
11040 where
11041 Conn: RequestConnection + ?Sized,
11042 {
11043 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
11044 .ok_or(ConnectionError::UnsupportedExtension)?;
11045 let length_so_far = 0;
11046 let device_spec_bytes = self.device_spec.serialize();
11047 let wanted_bytes = self.wanted.serialize();
11048 let all_buttons_bytes = self.all_buttons.serialize();
11049 let first_button_bytes = self.first_button.serialize();
11050 let n_buttons_bytes = self.n_buttons.serialize();
11051 let led_class_bytes = LedClassSpec::from(self.led_class).serialize();
11052 let led_id_bytes = self.led_id.serialize();
11053 let mut request0 = vec![
11054 extension_information.major_opcode,
11055 GET_DEVICE_INFO_REQUEST,
11056 0,
11057 0,
11058 device_spec_bytes[0],
11059 device_spec_bytes[1],
11060 wanted_bytes[0],
11061 wanted_bytes[1],
11062 all_buttons_bytes[0],
11063 first_button_bytes[0],
11064 n_buttons_bytes[0],
11065 0,
11066 led_class_bytes[0],
11067 led_class_bytes[1],
11068 led_id_bytes[0],
11069 led_id_bytes[1],
11070 ];
11071 let length_so_far = length_so_far + request0.len();
11072 assert_eq!(length_so_far % 4, 0);
11073 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
11074 request0[2..4].copy_from_slice(&length.to_ne_bytes());
11075 Ok((vec![request0.into()], vec![]))
11076 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetDeviceInfoReply>, ConnectionError> where Conn: RequestConnection + ?Sized,11077 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetDeviceInfoReply>, ConnectionError>
11078 where
11079 Conn: RequestConnection + ?Sized,
11080 {
11081 let (bytes, fds) = self.serialize(conn)?;
11082 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
11083 conn.send_request_with_reply(&slices, fds)
11084 }
11085 /// 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>11086 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
11087 if header.minor_opcode != GET_DEVICE_INFO_REQUEST {
11088 return Err(ParseError::InvalidValue);
11089 }
11090 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
11091 let (wanted, remaining) = u16::try_parse(remaining)?;
11092 let (all_buttons, remaining) = bool::try_parse(remaining)?;
11093 let (first_button, remaining) = u8::try_parse(remaining)?;
11094 let (n_buttons, remaining) = u8::try_parse(remaining)?;
11095 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
11096 let (led_class, remaining) = LedClassSpec::try_parse(remaining)?;
11097 let led_class = led_class.into();
11098 let (led_id, remaining) = IDSpec::try_parse(remaining)?;
11099 let _ = remaining;
11100 Ok(GetDeviceInfoRequest {
11101 device_spec,
11102 wanted,
11103 all_buttons,
11104 first_button,
11105 n_buttons,
11106 led_class,
11107 led_id,
11108 })
11109 }
11110 }
11111 impl Request for GetDeviceInfoRequest {
11112 type Reply = GetDeviceInfoReply;
11113 }
get_device_info<Conn, A, B>(conn: &Conn, device_spec: DeviceSpec, wanted: A, all_buttons: bool, first_button: u8, n_buttons: u8, led_class: LedClass, led_id: B) -> Result<Cookie<'_, Conn, GetDeviceInfoReply>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<u16>, B: Into<IDSpec>,11114 pub fn get_device_info<Conn, A, B>(conn: &Conn, device_spec: DeviceSpec, wanted: A, all_buttons: bool, first_button: u8, n_buttons: u8, led_class: LedClass, led_id: B) -> Result<Cookie<'_, Conn, GetDeviceInfoReply>, ConnectionError>
11115 where
11116 Conn: RequestConnection + ?Sized,
11117 A: Into<u16>,
11118 B: Into<IDSpec>,
11119 {
11120 let wanted: u16 = wanted.into();
11121 let led_id: IDSpec = led_id.into();
11122 let request0 = GetDeviceInfoRequest {
11123 device_spec,
11124 wanted,
11125 all_buttons,
11126 first_button,
11127 n_buttons,
11128 led_class,
11129 led_id,
11130 };
11131 request0.send(conn)
11132 }
11133
11134 #[derive(Debug, Clone)]
11135 pub struct GetDeviceInfoReply {
11136 pub device_id: u8,
11137 pub sequence: u16,
11138 pub length: u32,
11139 pub present: u16,
11140 pub supported: u16,
11141 pub unsupported: u16,
11142 pub first_btn_wanted: u8,
11143 pub n_btns_wanted: u8,
11144 pub first_btn_rtrn: u8,
11145 pub total_btns: u8,
11146 pub has_own_state: bool,
11147 pub dflt_kbd_fb: u16,
11148 pub dflt_led_fb: u16,
11149 pub dev_type: xproto::Atom,
11150 pub name: Vec<String8>,
11151 pub btn_actions: Vec<Action>,
11152 pub leds: Vec<DeviceLedInfo>,
11153 }
11154 impl TryParse for GetDeviceInfoReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>11155 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
11156 let remaining = initial_value;
11157 let value = remaining;
11158 let (response_type, remaining) = u8::try_parse(remaining)?;
11159 let (device_id, remaining) = u8::try_parse(remaining)?;
11160 let (sequence, remaining) = u16::try_parse(remaining)?;
11161 let (length, remaining) = u32::try_parse(remaining)?;
11162 let (present, remaining) = u16::try_parse(remaining)?;
11163 let (supported, remaining) = u16::try_parse(remaining)?;
11164 let (unsupported, remaining) = u16::try_parse(remaining)?;
11165 let (n_device_led_f_bs, remaining) = u16::try_parse(remaining)?;
11166 let (first_btn_wanted, remaining) = u8::try_parse(remaining)?;
11167 let (n_btns_wanted, remaining) = u8::try_parse(remaining)?;
11168 let (first_btn_rtrn, remaining) = u8::try_parse(remaining)?;
11169 let (n_btns_rtrn, remaining) = u8::try_parse(remaining)?;
11170 let (total_btns, remaining) = u8::try_parse(remaining)?;
11171 let (has_own_state, remaining) = bool::try_parse(remaining)?;
11172 let (dflt_kbd_fb, remaining) = u16::try_parse(remaining)?;
11173 let (dflt_led_fb, remaining) = u16::try_parse(remaining)?;
11174 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
11175 let (dev_type, remaining) = xproto::Atom::try_parse(remaining)?;
11176 let (name_len, remaining) = u16::try_parse(remaining)?;
11177 let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?;
11178 let name = name.to_vec();
11179 // Align offset to multiple of 4
11180 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
11181 let misalignment = (4 - (offset % 4)) % 4;
11182 let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
11183 let (btn_actions, remaining) = crate::x11_utils::parse_list::<Action>(remaining, n_btns_rtrn.try_to_usize()?)?;
11184 let (leds, remaining) = crate::x11_utils::parse_list::<DeviceLedInfo>(remaining, n_device_led_f_bs.try_to_usize()?)?;
11185 if response_type != 1 {
11186 return Err(ParseError::InvalidValue);
11187 }
11188 let result = GetDeviceInfoReply { device_id, sequence, length, present, supported, unsupported, first_btn_wanted, n_btns_wanted, first_btn_rtrn, total_btns, has_own_state, dflt_kbd_fb, dflt_led_fb, dev_type, name, btn_actions, leds };
11189 let _ = remaining;
11190 let remaining = initial_value.get(32 + length as usize * 4..)
11191 .ok_or(ParseError::InsufficientData)?;
11192 Ok((result, remaining))
11193 }
11194 }
11195 impl GetDeviceInfoReply {
11196 /// Get the value of the `nDeviceLedFBs` field.
11197 ///
11198 /// The `nDeviceLedFBs` field is used as the length field of the `leds` field.
11199 /// This function computes the field's value again based on the length of the list.
11200 ///
11201 /// # Panics
11202 ///
11203 /// Panics if the value cannot be represented in the target type. This
11204 /// cannot happen with values of the struct received from the X11 server.
n_device_led_f_bs(&self) -> u1611205 pub fn n_device_led_f_bs(&self) -> u16 {
11206 self.leds.len()
11207 .try_into().unwrap()
11208 }
11209 /// Get the value of the `nBtnsRtrn` field.
11210 ///
11211 /// The `nBtnsRtrn` field is used as the length field of the `btnActions` field.
11212 /// This function computes the field's value again based on the length of the list.
11213 ///
11214 /// # Panics
11215 ///
11216 /// Panics if the value cannot be represented in the target type. This
11217 /// cannot happen with values of the struct received from the X11 server.
n_btns_rtrn(&self) -> u811218 pub fn n_btns_rtrn(&self) -> u8 {
11219 self.btn_actions.len()
11220 .try_into().unwrap()
11221 }
11222 /// Get the value of the `nameLen` field.
11223 ///
11224 /// The `nameLen` field is used as the length field of the `name` field.
11225 /// This function computes the field's value again based on the length of the list.
11226 ///
11227 /// # Panics
11228 ///
11229 /// Panics if the value cannot be represented in the target type. This
11230 /// cannot happen with values of the struct received from the X11 server.
name_len(&self) -> u1611231 pub fn name_len(&self) -> u16 {
11232 self.name.len()
11233 .try_into().unwrap()
11234 }
11235 }
11236
11237 /// Opcode for the SetDeviceInfo request
11238 pub const SET_DEVICE_INFO_REQUEST: u8 = 25;
11239 #[derive(Debug, Clone)]
11240 pub struct SetDeviceInfoRequest<'input> {
11241 pub device_spec: DeviceSpec,
11242 pub first_btn: u8,
11243 pub change: u16,
11244 pub btn_actions: Cow<'input, [Action]>,
11245 pub leds: Cow<'input, [DeviceLedInfo]>,
11246 }
11247 impl<'input> SetDeviceInfoRequest<'input> {
11248 /// Serialize this request into bytes for the provided connection
serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,11249 fn serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
11250 where
11251 Conn: RequestConnection + ?Sized,
11252 {
11253 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
11254 .ok_or(ConnectionError::UnsupportedExtension)?;
11255 let length_so_far = 0;
11256 let device_spec_bytes = self.device_spec.serialize();
11257 let first_btn_bytes = self.first_btn.serialize();
11258 let n_btns = u8::try_from(self.btn_actions.len()).expect("`btn_actions` has too many elements");
11259 let n_btns_bytes = n_btns.serialize();
11260 let change_bytes = self.change.serialize();
11261 let n_device_led_f_bs = u16::try_from(self.leds.len()).expect("`leds` has too many elements");
11262 let n_device_led_f_bs_bytes = n_device_led_f_bs.serialize();
11263 let mut request0 = vec![
11264 extension_information.major_opcode,
11265 SET_DEVICE_INFO_REQUEST,
11266 0,
11267 0,
11268 device_spec_bytes[0],
11269 device_spec_bytes[1],
11270 first_btn_bytes[0],
11271 n_btns_bytes[0],
11272 change_bytes[0],
11273 change_bytes[1],
11274 n_device_led_f_bs_bytes[0],
11275 n_device_led_f_bs_bytes[1],
11276 ];
11277 let length_so_far = length_so_far + request0.len();
11278 let btn_actions_bytes = self.btn_actions.serialize();
11279 let length_so_far = length_so_far + btn_actions_bytes.len();
11280 let leds_bytes = self.leds.serialize();
11281 let length_so_far = length_so_far + leds_bytes.len();
11282 let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
11283 let length_so_far = length_so_far + padding0.len();
11284 assert_eq!(length_so_far % 4, 0);
11285 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
11286 request0[2..4].copy_from_slice(&length.to_ne_bytes());
11287 Ok((vec![request0.into(), btn_actions_bytes.into(), leds_bytes.into(), padding0.into()], vec![]))
11288 }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,11289 pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
11290 where
11291 Conn: RequestConnection + ?Sized,
11292 {
11293 let (bytes, fds) = self.serialize(conn)?;
11294 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
11295 conn.send_request_without_reply(&slices, fds)
11296 }
11297 /// 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>11298 pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
11299 if header.minor_opcode != SET_DEVICE_INFO_REQUEST {
11300 return Err(ParseError::InvalidValue);
11301 }
11302 let (device_spec, remaining) = DeviceSpec::try_parse(value)?;
11303 let (first_btn, remaining) = u8::try_parse(remaining)?;
11304 let (n_btns, remaining) = u8::try_parse(remaining)?;
11305 let (change, remaining) = u16::try_parse(remaining)?;
11306 let (n_device_led_f_bs, remaining) = u16::try_parse(remaining)?;
11307 let (btn_actions, remaining) = crate::x11_utils::parse_list::<Action>(remaining, n_btns.try_to_usize()?)?;
11308 let (leds, remaining) = crate::x11_utils::parse_list::<DeviceLedInfo>(remaining, n_device_led_f_bs.try_to_usize()?)?;
11309 let _ = remaining;
11310 Ok(SetDeviceInfoRequest {
11311 device_spec,
11312 first_btn,
11313 change,
11314 btn_actions: Cow::Owned(btn_actions),
11315 leds: Cow::Owned(leds),
11316 })
11317 }
11318 /// Clone all borrowed data in this SetDeviceInfoRequest.
into_owned(self) -> SetDeviceInfoRequest<'static>11319 pub fn into_owned(self) -> SetDeviceInfoRequest<'static> {
11320 SetDeviceInfoRequest {
11321 device_spec: self.device_spec,
11322 first_btn: self.first_btn,
11323 change: self.change,
11324 btn_actions: Cow::Owned(self.btn_actions.into_owned()),
11325 leds: Cow::Owned(self.leds.into_owned()),
11326 }
11327 }
11328 }
11329 impl<'input> Request for SetDeviceInfoRequest<'input> {
11330 type Reply = ();
11331 }
set_device_info<'c, 'input, Conn, A>(conn: &'c Conn, device_spec: DeviceSpec, first_btn: u8, change: A, btn_actions: &'input [Action], leds: &'input [DeviceLedInfo]) -> Result<VoidCookie<'c, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<u16>,11332 pub fn set_device_info<'c, 'input, Conn, A>(conn: &'c Conn, device_spec: DeviceSpec, first_btn: u8, change: A, btn_actions: &'input [Action], leds: &'input [DeviceLedInfo]) -> Result<VoidCookie<'c, Conn>, ConnectionError>
11333 where
11334 Conn: RequestConnection + ?Sized,
11335 A: Into<u16>,
11336 {
11337 let change: u16 = change.into();
11338 let request0 = SetDeviceInfoRequest {
11339 device_spec,
11340 first_btn,
11341 change,
11342 btn_actions: Cow::Borrowed(btn_actions),
11343 leds: Cow::Borrowed(leds),
11344 };
11345 request0.send(conn)
11346 }
11347
11348 /// Opcode for the SetDebuggingFlags request
11349 pub const SET_DEBUGGING_FLAGS_REQUEST: u8 = 101;
11350 #[derive(Debug, Clone, PartialEq, Eq)]
11351 pub struct SetDebuggingFlagsRequest<'input> {
11352 pub affect_flags: u32,
11353 pub flags: u32,
11354 pub affect_ctrls: u32,
11355 pub ctrls: u32,
11356 pub message: Cow<'input, [String8]>,
11357 }
11358 impl<'input> SetDebuggingFlagsRequest<'input> {
11359 /// Serialize this request into bytes for the provided connection
serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,11360 fn serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
11361 where
11362 Conn: RequestConnection + ?Sized,
11363 {
11364 let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
11365 .ok_or(ConnectionError::UnsupportedExtension)?;
11366 let length_so_far = 0;
11367 let msg_length = u16::try_from(self.message.len()).expect("`message` has too many elements");
11368 let msg_length_bytes = msg_length.serialize();
11369 let affect_flags_bytes = self.affect_flags.serialize();
11370 let flags_bytes = self.flags.serialize();
11371 let affect_ctrls_bytes = self.affect_ctrls.serialize();
11372 let ctrls_bytes = self.ctrls.serialize();
11373 let mut request0 = vec![
11374 extension_information.major_opcode,
11375 SET_DEBUGGING_FLAGS_REQUEST,
11376 0,
11377 0,
11378 msg_length_bytes[0],
11379 msg_length_bytes[1],
11380 0,
11381 0,
11382 affect_flags_bytes[0],
11383 affect_flags_bytes[1],
11384 affect_flags_bytes[2],
11385 affect_flags_bytes[3],
11386 flags_bytes[0],
11387 flags_bytes[1],
11388 flags_bytes[2],
11389 flags_bytes[3],
11390 affect_ctrls_bytes[0],
11391 affect_ctrls_bytes[1],
11392 affect_ctrls_bytes[2],
11393 affect_ctrls_bytes[3],
11394 ctrls_bytes[0],
11395 ctrls_bytes[1],
11396 ctrls_bytes[2],
11397 ctrls_bytes[3],
11398 ];
11399 let length_so_far = length_so_far + request0.len();
11400 let length_so_far = length_so_far + self.message.len();
11401 let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
11402 let length_so_far = length_so_far + padding0.len();
11403 assert_eq!(length_so_far % 4, 0);
11404 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
11405 request0[2..4].copy_from_slice(&length.to_ne_bytes());
11406 Ok((vec![request0.into(), self.message, padding0.into()], vec![]))
11407 }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, SetDebuggingFlagsReply>, ConnectionError> where Conn: RequestConnection + ?Sized,11408 pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, SetDebuggingFlagsReply>, ConnectionError>
11409 where
11410 Conn: RequestConnection + ?Sized,
11411 {
11412 let (bytes, fds) = self.serialize(conn)?;
11413 let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
11414 conn.send_request_with_reply(&slices, fds)
11415 }
11416 /// 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>11417 pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
11418 if header.minor_opcode != SET_DEBUGGING_FLAGS_REQUEST {
11419 return Err(ParseError::InvalidValue);
11420 }
11421 let (msg_length, remaining) = u16::try_parse(value)?;
11422 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
11423 let (affect_flags, remaining) = u32::try_parse(remaining)?;
11424 let (flags, remaining) = u32::try_parse(remaining)?;
11425 let (affect_ctrls, remaining) = u32::try_parse(remaining)?;
11426 let (ctrls, remaining) = u32::try_parse(remaining)?;
11427 let (message, remaining) = crate::x11_utils::parse_u8_list(remaining, msg_length.try_to_usize()?)?;
11428 let _ = remaining;
11429 Ok(SetDebuggingFlagsRequest {
11430 affect_flags,
11431 flags,
11432 affect_ctrls,
11433 ctrls,
11434 message: Cow::Borrowed(message),
11435 })
11436 }
11437 /// Clone all borrowed data in this SetDebuggingFlagsRequest.
into_owned(self) -> SetDebuggingFlagsRequest<'static>11438 pub fn into_owned(self) -> SetDebuggingFlagsRequest<'static> {
11439 SetDebuggingFlagsRequest {
11440 affect_flags: self.affect_flags,
11441 flags: self.flags,
11442 affect_ctrls: self.affect_ctrls,
11443 ctrls: self.ctrls,
11444 message: Cow::Owned(self.message.into_owned()),
11445 }
11446 }
11447 }
11448 impl<'input> Request for SetDebuggingFlagsRequest<'input> {
11449 type Reply = SetDebuggingFlagsReply;
11450 }
set_debugging_flags<'c, 'input, Conn>(conn: &'c Conn, affect_flags: u32, flags: u32, affect_ctrls: u32, ctrls: u32, message: &'input [String8]) -> Result<Cookie<'c, Conn, SetDebuggingFlagsReply>, ConnectionError> where Conn: RequestConnection + ?Sized,11451 pub fn set_debugging_flags<'c, 'input, Conn>(conn: &'c Conn, affect_flags: u32, flags: u32, affect_ctrls: u32, ctrls: u32, message: &'input [String8]) -> Result<Cookie<'c, Conn, SetDebuggingFlagsReply>, ConnectionError>
11452 where
11453 Conn: RequestConnection + ?Sized,
11454 {
11455 let request0 = SetDebuggingFlagsRequest {
11456 affect_flags,
11457 flags,
11458 affect_ctrls,
11459 ctrls,
11460 message: Cow::Borrowed(message),
11461 };
11462 request0.send(conn)
11463 }
11464
11465 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
11466 pub struct SetDebuggingFlagsReply {
11467 pub sequence: u16,
11468 pub length: u32,
11469 pub current_flags: u32,
11470 pub current_ctrls: u32,
11471 pub supported_flags: u32,
11472 pub supported_ctrls: u32,
11473 }
11474 impl TryParse for SetDebuggingFlagsReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>11475 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
11476 let remaining = initial_value;
11477 let (response_type, remaining) = u8::try_parse(remaining)?;
11478 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
11479 let (sequence, remaining) = u16::try_parse(remaining)?;
11480 let (length, remaining) = u32::try_parse(remaining)?;
11481 let (current_flags, remaining) = u32::try_parse(remaining)?;
11482 let (current_ctrls, remaining) = u32::try_parse(remaining)?;
11483 let (supported_flags, remaining) = u32::try_parse(remaining)?;
11484 let (supported_ctrls, remaining) = u32::try_parse(remaining)?;
11485 let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?;
11486 if response_type != 1 {
11487 return Err(ParseError::InvalidValue);
11488 }
11489 let result = SetDebuggingFlagsReply { sequence, length, current_flags, current_ctrls, supported_flags, supported_ctrls };
11490 let _ = remaining;
11491 let remaining = initial_value.get(32 + length as usize * 4..)
11492 .ok_or(ParseError::InsufficientData)?;
11493 Ok((result, remaining))
11494 }
11495 }
11496
11497 /// Opcode for the NewKeyboardNotify event
11498 pub const NEW_KEYBOARD_NOTIFY_EVENT: u8 = 0;
11499 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
11500 pub struct NewKeyboardNotifyEvent {
11501 pub response_type: u8,
11502 pub xkb_type: u8,
11503 pub sequence: u16,
11504 pub time: xproto::Timestamp,
11505 pub device_id: u8,
11506 pub old_device_id: u8,
11507 pub min_key_code: xproto::Keycode,
11508 pub max_key_code: xproto::Keycode,
11509 pub old_min_key_code: xproto::Keycode,
11510 pub old_max_key_code: xproto::Keycode,
11511 pub request_major: u8,
11512 pub request_minor: u8,
11513 pub changed: u16,
11514 }
11515 impl TryParse for NewKeyboardNotifyEvent {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>11516 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
11517 let remaining = initial_value;
11518 let (response_type, remaining) = u8::try_parse(remaining)?;
11519 let (xkb_type, remaining) = u8::try_parse(remaining)?;
11520 let (sequence, remaining) = u16::try_parse(remaining)?;
11521 let (time, remaining) = xproto::Timestamp::try_parse(remaining)?;
11522 let (device_id, remaining) = u8::try_parse(remaining)?;
11523 let (old_device_id, remaining) = u8::try_parse(remaining)?;
11524 let (min_key_code, remaining) = xproto::Keycode::try_parse(remaining)?;
11525 let (max_key_code, remaining) = xproto::Keycode::try_parse(remaining)?;
11526 let (old_min_key_code, remaining) = xproto::Keycode::try_parse(remaining)?;
11527 let (old_max_key_code, remaining) = xproto::Keycode::try_parse(remaining)?;
11528 let (request_major, remaining) = u8::try_parse(remaining)?;
11529 let (request_minor, remaining) = u8::try_parse(remaining)?;
11530 let (changed, remaining) = u16::try_parse(remaining)?;
11531 let remaining = remaining.get(14..).ok_or(ParseError::InsufficientData)?;
11532 let result = NewKeyboardNotifyEvent { response_type, xkb_type, sequence, time, device_id, old_device_id, min_key_code, max_key_code, old_min_key_code, old_max_key_code, request_major, request_minor, changed };
11533 let _ = remaining;
11534 let remaining = initial_value.get(32..)
11535 .ok_or(ParseError::InsufficientData)?;
11536 Ok((result, remaining))
11537 }
11538 }
11539 impl From<&NewKeyboardNotifyEvent> for [u8; 32] {
from(input: &NewKeyboardNotifyEvent) -> Self11540 fn from(input: &NewKeyboardNotifyEvent) -> Self {
11541 let response_type_bytes = input.response_type.serialize();
11542 let xkb_type_bytes = input.xkb_type.serialize();
11543 let sequence_bytes = input.sequence.serialize();
11544 let time_bytes = input.time.serialize();
11545 let device_id_bytes = input.device_id.serialize();
11546 let old_device_id_bytes = input.old_device_id.serialize();
11547 let min_key_code_bytes = input.min_key_code.serialize();
11548 let max_key_code_bytes = input.max_key_code.serialize();
11549 let old_min_key_code_bytes = input.old_min_key_code.serialize();
11550 let old_max_key_code_bytes = input.old_max_key_code.serialize();
11551 let request_major_bytes = input.request_major.serialize();
11552 let request_minor_bytes = input.request_minor.serialize();
11553 let changed_bytes = input.changed.serialize();
11554 [
11555 response_type_bytes[0],
11556 xkb_type_bytes[0],
11557 sequence_bytes[0],
11558 sequence_bytes[1],
11559 time_bytes[0],
11560 time_bytes[1],
11561 time_bytes[2],
11562 time_bytes[3],
11563 device_id_bytes[0],
11564 old_device_id_bytes[0],
11565 min_key_code_bytes[0],
11566 max_key_code_bytes[0],
11567 old_min_key_code_bytes[0],
11568 old_max_key_code_bytes[0],
11569 request_major_bytes[0],
11570 request_minor_bytes[0],
11571 changed_bytes[0],
11572 changed_bytes[1],
11573 0,
11574 0,
11575 0,
11576 0,
11577 0,
11578 0,
11579 0,
11580 0,
11581 0,
11582 0,
11583 0,
11584 0,
11585 0,
11586 0,
11587 ]
11588 }
11589 }
11590 impl From<NewKeyboardNotifyEvent> for [u8; 32] {
from(input: NewKeyboardNotifyEvent) -> Self11591 fn from(input: NewKeyboardNotifyEvent) -> Self {
11592 Self::from(&input)
11593 }
11594 }
11595
11596 /// Opcode for the MapNotify event
11597 pub const MAP_NOTIFY_EVENT: u8 = 1;
11598 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
11599 pub struct MapNotifyEvent {
11600 pub response_type: u8,
11601 pub xkb_type: u8,
11602 pub sequence: u16,
11603 pub time: xproto::Timestamp,
11604 pub device_id: u8,
11605 pub ptr_btn_actions: u8,
11606 pub changed: u16,
11607 pub min_key_code: xproto::Keycode,
11608 pub max_key_code: xproto::Keycode,
11609 pub first_type: u8,
11610 pub n_types: u8,
11611 pub first_key_sym: xproto::Keycode,
11612 pub n_key_syms: u8,
11613 pub first_key_act: xproto::Keycode,
11614 pub n_key_acts: u8,
11615 pub first_key_behavior: xproto::Keycode,
11616 pub n_key_behavior: u8,
11617 pub first_key_explicit: xproto::Keycode,
11618 pub n_key_explicit: u8,
11619 pub first_mod_map_key: xproto::Keycode,
11620 pub n_mod_map_keys: u8,
11621 pub first_v_mod_map_key: xproto::Keycode,
11622 pub n_v_mod_map_keys: u8,
11623 pub virtual_mods: u16,
11624 }
11625 impl TryParse for MapNotifyEvent {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>11626 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
11627 let remaining = initial_value;
11628 let (response_type, remaining) = u8::try_parse(remaining)?;
11629 let (xkb_type, remaining) = u8::try_parse(remaining)?;
11630 let (sequence, remaining) = u16::try_parse(remaining)?;
11631 let (time, remaining) = xproto::Timestamp::try_parse(remaining)?;
11632 let (device_id, remaining) = u8::try_parse(remaining)?;
11633 let (ptr_btn_actions, remaining) = u8::try_parse(remaining)?;
11634 let (changed, remaining) = u16::try_parse(remaining)?;
11635 let (min_key_code, remaining) = xproto::Keycode::try_parse(remaining)?;
11636 let (max_key_code, remaining) = xproto::Keycode::try_parse(remaining)?;
11637 let (first_type, remaining) = u8::try_parse(remaining)?;
11638 let (n_types, remaining) = u8::try_parse(remaining)?;
11639 let (first_key_sym, remaining) = xproto::Keycode::try_parse(remaining)?;
11640 let (n_key_syms, remaining) = u8::try_parse(remaining)?;
11641 let (first_key_act, remaining) = xproto::Keycode::try_parse(remaining)?;
11642 let (n_key_acts, remaining) = u8::try_parse(remaining)?;
11643 let (first_key_behavior, remaining) = xproto::Keycode::try_parse(remaining)?;
11644 let (n_key_behavior, remaining) = u8::try_parse(remaining)?;
11645 let (first_key_explicit, remaining) = xproto::Keycode::try_parse(remaining)?;
11646 let (n_key_explicit, remaining) = u8::try_parse(remaining)?;
11647 let (first_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?;
11648 let (n_mod_map_keys, remaining) = u8::try_parse(remaining)?;
11649 let (first_v_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?;
11650 let (n_v_mod_map_keys, remaining) = u8::try_parse(remaining)?;
11651 let (virtual_mods, remaining) = u16::try_parse(remaining)?;
11652 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
11653 let result = MapNotifyEvent { response_type, xkb_type, sequence, time, device_id, ptr_btn_actions, changed, min_key_code, max_key_code, first_type, n_types, first_key_sym, n_key_syms, first_key_act, n_key_acts, first_key_behavior, n_key_behavior, first_key_explicit, n_key_explicit, first_mod_map_key, n_mod_map_keys, first_v_mod_map_key, n_v_mod_map_keys, virtual_mods };
11654 let _ = remaining;
11655 let remaining = initial_value.get(32..)
11656 .ok_or(ParseError::InsufficientData)?;
11657 Ok((result, remaining))
11658 }
11659 }
11660 impl From<&MapNotifyEvent> for [u8; 32] {
from(input: &MapNotifyEvent) -> Self11661 fn from(input: &MapNotifyEvent) -> Self {
11662 let response_type_bytes = input.response_type.serialize();
11663 let xkb_type_bytes = input.xkb_type.serialize();
11664 let sequence_bytes = input.sequence.serialize();
11665 let time_bytes = input.time.serialize();
11666 let device_id_bytes = input.device_id.serialize();
11667 let ptr_btn_actions_bytes = input.ptr_btn_actions.serialize();
11668 let changed_bytes = input.changed.serialize();
11669 let min_key_code_bytes = input.min_key_code.serialize();
11670 let max_key_code_bytes = input.max_key_code.serialize();
11671 let first_type_bytes = input.first_type.serialize();
11672 let n_types_bytes = input.n_types.serialize();
11673 let first_key_sym_bytes = input.first_key_sym.serialize();
11674 let n_key_syms_bytes = input.n_key_syms.serialize();
11675 let first_key_act_bytes = input.first_key_act.serialize();
11676 let n_key_acts_bytes = input.n_key_acts.serialize();
11677 let first_key_behavior_bytes = input.first_key_behavior.serialize();
11678 let n_key_behavior_bytes = input.n_key_behavior.serialize();
11679 let first_key_explicit_bytes = input.first_key_explicit.serialize();
11680 let n_key_explicit_bytes = input.n_key_explicit.serialize();
11681 let first_mod_map_key_bytes = input.first_mod_map_key.serialize();
11682 let n_mod_map_keys_bytes = input.n_mod_map_keys.serialize();
11683 let first_v_mod_map_key_bytes = input.first_v_mod_map_key.serialize();
11684 let n_v_mod_map_keys_bytes = input.n_v_mod_map_keys.serialize();
11685 let virtual_mods_bytes = input.virtual_mods.serialize();
11686 [
11687 response_type_bytes[0],
11688 xkb_type_bytes[0],
11689 sequence_bytes[0],
11690 sequence_bytes[1],
11691 time_bytes[0],
11692 time_bytes[1],
11693 time_bytes[2],
11694 time_bytes[3],
11695 device_id_bytes[0],
11696 ptr_btn_actions_bytes[0],
11697 changed_bytes[0],
11698 changed_bytes[1],
11699 min_key_code_bytes[0],
11700 max_key_code_bytes[0],
11701 first_type_bytes[0],
11702 n_types_bytes[0],
11703 first_key_sym_bytes[0],
11704 n_key_syms_bytes[0],
11705 first_key_act_bytes[0],
11706 n_key_acts_bytes[0],
11707 first_key_behavior_bytes[0],
11708 n_key_behavior_bytes[0],
11709 first_key_explicit_bytes[0],
11710 n_key_explicit_bytes[0],
11711 first_mod_map_key_bytes[0],
11712 n_mod_map_keys_bytes[0],
11713 first_v_mod_map_key_bytes[0],
11714 n_v_mod_map_keys_bytes[0],
11715 virtual_mods_bytes[0],
11716 virtual_mods_bytes[1],
11717 0,
11718 0,
11719 ]
11720 }
11721 }
11722 impl From<MapNotifyEvent> for [u8; 32] {
from(input: MapNotifyEvent) -> Self11723 fn from(input: MapNotifyEvent) -> Self {
11724 Self::from(&input)
11725 }
11726 }
11727
11728 /// Opcode for the StateNotify event
11729 pub const STATE_NOTIFY_EVENT: u8 = 2;
11730 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
11731 pub struct StateNotifyEvent {
11732 pub response_type: u8,
11733 pub xkb_type: u8,
11734 pub sequence: u16,
11735 pub time: xproto::Timestamp,
11736 pub device_id: u8,
11737 pub mods: u8,
11738 pub base_mods: u8,
11739 pub latched_mods: u8,
11740 pub locked_mods: u8,
11741 pub group: Group,
11742 pub base_group: i16,
11743 pub latched_group: i16,
11744 pub locked_group: Group,
11745 pub compat_state: u8,
11746 pub grab_mods: u8,
11747 pub compat_grab_mods: u8,
11748 pub lookup_mods: u8,
11749 pub compat_loockup_mods: u8,
11750 pub ptr_btn_state: u16,
11751 pub changed: u16,
11752 pub keycode: xproto::Keycode,
11753 pub event_type: u8,
11754 pub request_major: u8,
11755 pub request_minor: u8,
11756 }
11757 impl TryParse for StateNotifyEvent {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>11758 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
11759 let remaining = initial_value;
11760 let (response_type, remaining) = u8::try_parse(remaining)?;
11761 let (xkb_type, remaining) = u8::try_parse(remaining)?;
11762 let (sequence, remaining) = u16::try_parse(remaining)?;
11763 let (time, remaining) = xproto::Timestamp::try_parse(remaining)?;
11764 let (device_id, remaining) = u8::try_parse(remaining)?;
11765 let (mods, remaining) = u8::try_parse(remaining)?;
11766 let (base_mods, remaining) = u8::try_parse(remaining)?;
11767 let (latched_mods, remaining) = u8::try_parse(remaining)?;
11768 let (locked_mods, remaining) = u8::try_parse(remaining)?;
11769 let (group, remaining) = u8::try_parse(remaining)?;
11770 let (base_group, remaining) = i16::try_parse(remaining)?;
11771 let (latched_group, remaining) = i16::try_parse(remaining)?;
11772 let (locked_group, remaining) = u8::try_parse(remaining)?;
11773 let (compat_state, remaining) = u8::try_parse(remaining)?;
11774 let (grab_mods, remaining) = u8::try_parse(remaining)?;
11775 let (compat_grab_mods, remaining) = u8::try_parse(remaining)?;
11776 let (lookup_mods, remaining) = u8::try_parse(remaining)?;
11777 let (compat_loockup_mods, remaining) = u8::try_parse(remaining)?;
11778 let (ptr_btn_state, remaining) = u16::try_parse(remaining)?;
11779 let (changed, remaining) = u16::try_parse(remaining)?;
11780 let (keycode, remaining) = xproto::Keycode::try_parse(remaining)?;
11781 let (event_type, remaining) = u8::try_parse(remaining)?;
11782 let (request_major, remaining) = u8::try_parse(remaining)?;
11783 let (request_minor, remaining) = u8::try_parse(remaining)?;
11784 let group = group.into();
11785 let locked_group = locked_group.into();
11786 let result = StateNotifyEvent { response_type, xkb_type, sequence, time, device_id, mods, base_mods, latched_mods, locked_mods, group, base_group, latched_group, locked_group, compat_state, grab_mods, compat_grab_mods, lookup_mods, compat_loockup_mods, ptr_btn_state, changed, keycode, event_type, request_major, request_minor };
11787 let _ = remaining;
11788 let remaining = initial_value.get(32..)
11789 .ok_or(ParseError::InsufficientData)?;
11790 Ok((result, remaining))
11791 }
11792 }
11793 impl From<&StateNotifyEvent> for [u8; 32] {
from(input: &StateNotifyEvent) -> Self11794 fn from(input: &StateNotifyEvent) -> Self {
11795 let response_type_bytes = input.response_type.serialize();
11796 let xkb_type_bytes = input.xkb_type.serialize();
11797 let sequence_bytes = input.sequence.serialize();
11798 let time_bytes = input.time.serialize();
11799 let device_id_bytes = input.device_id.serialize();
11800 let mods_bytes = input.mods.serialize();
11801 let base_mods_bytes = input.base_mods.serialize();
11802 let latched_mods_bytes = input.latched_mods.serialize();
11803 let locked_mods_bytes = input.locked_mods.serialize();
11804 let group_bytes = u8::from(input.group).serialize();
11805 let base_group_bytes = input.base_group.serialize();
11806 let latched_group_bytes = input.latched_group.serialize();
11807 let locked_group_bytes = u8::from(input.locked_group).serialize();
11808 let compat_state_bytes = input.compat_state.serialize();
11809 let grab_mods_bytes = input.grab_mods.serialize();
11810 let compat_grab_mods_bytes = input.compat_grab_mods.serialize();
11811 let lookup_mods_bytes = input.lookup_mods.serialize();
11812 let compat_loockup_mods_bytes = input.compat_loockup_mods.serialize();
11813 let ptr_btn_state_bytes = input.ptr_btn_state.serialize();
11814 let changed_bytes = input.changed.serialize();
11815 let keycode_bytes = input.keycode.serialize();
11816 let event_type_bytes = input.event_type.serialize();
11817 let request_major_bytes = input.request_major.serialize();
11818 let request_minor_bytes = input.request_minor.serialize();
11819 [
11820 response_type_bytes[0],
11821 xkb_type_bytes[0],
11822 sequence_bytes[0],
11823 sequence_bytes[1],
11824 time_bytes[0],
11825 time_bytes[1],
11826 time_bytes[2],
11827 time_bytes[3],
11828 device_id_bytes[0],
11829 mods_bytes[0],
11830 base_mods_bytes[0],
11831 latched_mods_bytes[0],
11832 locked_mods_bytes[0],
11833 group_bytes[0],
11834 base_group_bytes[0],
11835 base_group_bytes[1],
11836 latched_group_bytes[0],
11837 latched_group_bytes[1],
11838 locked_group_bytes[0],
11839 compat_state_bytes[0],
11840 grab_mods_bytes[0],
11841 compat_grab_mods_bytes[0],
11842 lookup_mods_bytes[0],
11843 compat_loockup_mods_bytes[0],
11844 ptr_btn_state_bytes[0],
11845 ptr_btn_state_bytes[1],
11846 changed_bytes[0],
11847 changed_bytes[1],
11848 keycode_bytes[0],
11849 event_type_bytes[0],
11850 request_major_bytes[0],
11851 request_minor_bytes[0],
11852 ]
11853 }
11854 }
11855 impl From<StateNotifyEvent> for [u8; 32] {
from(input: StateNotifyEvent) -> Self11856 fn from(input: StateNotifyEvent) -> Self {
11857 Self::from(&input)
11858 }
11859 }
11860
11861 /// Opcode for the ControlsNotify event
11862 pub const CONTROLS_NOTIFY_EVENT: u8 = 3;
11863 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
11864 pub struct ControlsNotifyEvent {
11865 pub response_type: u8,
11866 pub xkb_type: u8,
11867 pub sequence: u16,
11868 pub time: xproto::Timestamp,
11869 pub device_id: u8,
11870 pub num_groups: u8,
11871 pub changed_controls: u32,
11872 pub enabled_controls: u32,
11873 pub enabled_control_changes: u32,
11874 pub keycode: xproto::Keycode,
11875 pub event_type: u8,
11876 pub request_major: u8,
11877 pub request_minor: u8,
11878 }
11879 impl TryParse for ControlsNotifyEvent {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>11880 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
11881 let remaining = initial_value;
11882 let (response_type, remaining) = u8::try_parse(remaining)?;
11883 let (xkb_type, remaining) = u8::try_parse(remaining)?;
11884 let (sequence, remaining) = u16::try_parse(remaining)?;
11885 let (time, remaining) = xproto::Timestamp::try_parse(remaining)?;
11886 let (device_id, remaining) = u8::try_parse(remaining)?;
11887 let (num_groups, remaining) = u8::try_parse(remaining)?;
11888 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
11889 let (changed_controls, remaining) = u32::try_parse(remaining)?;
11890 let (enabled_controls, remaining) = u32::try_parse(remaining)?;
11891 let (enabled_control_changes, remaining) = u32::try_parse(remaining)?;
11892 let (keycode, remaining) = xproto::Keycode::try_parse(remaining)?;
11893 let (event_type, remaining) = u8::try_parse(remaining)?;
11894 let (request_major, remaining) = u8::try_parse(remaining)?;
11895 let (request_minor, remaining) = u8::try_parse(remaining)?;
11896 let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?;
11897 let result = ControlsNotifyEvent { response_type, xkb_type, sequence, time, device_id, num_groups, changed_controls, enabled_controls, enabled_control_changes, keycode, event_type, request_major, request_minor };
11898 let _ = remaining;
11899 let remaining = initial_value.get(32..)
11900 .ok_or(ParseError::InsufficientData)?;
11901 Ok((result, remaining))
11902 }
11903 }
11904 impl From<&ControlsNotifyEvent> for [u8; 32] {
from(input: &ControlsNotifyEvent) -> Self11905 fn from(input: &ControlsNotifyEvent) -> Self {
11906 let response_type_bytes = input.response_type.serialize();
11907 let xkb_type_bytes = input.xkb_type.serialize();
11908 let sequence_bytes = input.sequence.serialize();
11909 let time_bytes = input.time.serialize();
11910 let device_id_bytes = input.device_id.serialize();
11911 let num_groups_bytes = input.num_groups.serialize();
11912 let changed_controls_bytes = input.changed_controls.serialize();
11913 let enabled_controls_bytes = input.enabled_controls.serialize();
11914 let enabled_control_changes_bytes = input.enabled_control_changes.serialize();
11915 let keycode_bytes = input.keycode.serialize();
11916 let event_type_bytes = input.event_type.serialize();
11917 let request_major_bytes = input.request_major.serialize();
11918 let request_minor_bytes = input.request_minor.serialize();
11919 [
11920 response_type_bytes[0],
11921 xkb_type_bytes[0],
11922 sequence_bytes[0],
11923 sequence_bytes[1],
11924 time_bytes[0],
11925 time_bytes[1],
11926 time_bytes[2],
11927 time_bytes[3],
11928 device_id_bytes[0],
11929 num_groups_bytes[0],
11930 0,
11931 0,
11932 changed_controls_bytes[0],
11933 changed_controls_bytes[1],
11934 changed_controls_bytes[2],
11935 changed_controls_bytes[3],
11936 enabled_controls_bytes[0],
11937 enabled_controls_bytes[1],
11938 enabled_controls_bytes[2],
11939 enabled_controls_bytes[3],
11940 enabled_control_changes_bytes[0],
11941 enabled_control_changes_bytes[1],
11942 enabled_control_changes_bytes[2],
11943 enabled_control_changes_bytes[3],
11944 keycode_bytes[0],
11945 event_type_bytes[0],
11946 request_major_bytes[0],
11947 request_minor_bytes[0],
11948 0,
11949 0,
11950 0,
11951 0,
11952 ]
11953 }
11954 }
11955 impl From<ControlsNotifyEvent> for [u8; 32] {
from(input: ControlsNotifyEvent) -> Self11956 fn from(input: ControlsNotifyEvent) -> Self {
11957 Self::from(&input)
11958 }
11959 }
11960
11961 /// Opcode for the IndicatorStateNotify event
11962 pub const INDICATOR_STATE_NOTIFY_EVENT: u8 = 4;
11963 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
11964 pub struct IndicatorStateNotifyEvent {
11965 pub response_type: u8,
11966 pub xkb_type: u8,
11967 pub sequence: u16,
11968 pub time: xproto::Timestamp,
11969 pub device_id: u8,
11970 pub state: u32,
11971 pub state_changed: u32,
11972 }
11973 impl TryParse for IndicatorStateNotifyEvent {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>11974 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
11975 let remaining = initial_value;
11976 let (response_type, remaining) = u8::try_parse(remaining)?;
11977 let (xkb_type, remaining) = u8::try_parse(remaining)?;
11978 let (sequence, remaining) = u16::try_parse(remaining)?;
11979 let (time, remaining) = xproto::Timestamp::try_parse(remaining)?;
11980 let (device_id, remaining) = u8::try_parse(remaining)?;
11981 let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?;
11982 let (state, remaining) = u32::try_parse(remaining)?;
11983 let (state_changed, remaining) = u32::try_parse(remaining)?;
11984 let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
11985 let result = IndicatorStateNotifyEvent { response_type, xkb_type, sequence, time, device_id, state, state_changed };
11986 let _ = remaining;
11987 let remaining = initial_value.get(32..)
11988 .ok_or(ParseError::InsufficientData)?;
11989 Ok((result, remaining))
11990 }
11991 }
11992 impl From<&IndicatorStateNotifyEvent> for [u8; 32] {
from(input: &IndicatorStateNotifyEvent) -> Self11993 fn from(input: &IndicatorStateNotifyEvent) -> Self {
11994 let response_type_bytes = input.response_type.serialize();
11995 let xkb_type_bytes = input.xkb_type.serialize();
11996 let sequence_bytes = input.sequence.serialize();
11997 let time_bytes = input.time.serialize();
11998 let device_id_bytes = input.device_id.serialize();
11999 let state_bytes = input.state.serialize();
12000 let state_changed_bytes = input.state_changed.serialize();
12001 [
12002 response_type_bytes[0],
12003 xkb_type_bytes[0],
12004 sequence_bytes[0],
12005 sequence_bytes[1],
12006 time_bytes[0],
12007 time_bytes[1],
12008 time_bytes[2],
12009 time_bytes[3],
12010 device_id_bytes[0],
12011 0,
12012 0,
12013 0,
12014 state_bytes[0],
12015 state_bytes[1],
12016 state_bytes[2],
12017 state_bytes[3],
12018 state_changed_bytes[0],
12019 state_changed_bytes[1],
12020 state_changed_bytes[2],
12021 state_changed_bytes[3],
12022 0,
12023 0,
12024 0,
12025 0,
12026 0,
12027 0,
12028 0,
12029 0,
12030 0,
12031 0,
12032 0,
12033 0,
12034 ]
12035 }
12036 }
12037 impl From<IndicatorStateNotifyEvent> for [u8; 32] {
from(input: IndicatorStateNotifyEvent) -> Self12038 fn from(input: IndicatorStateNotifyEvent) -> Self {
12039 Self::from(&input)
12040 }
12041 }
12042
12043 /// Opcode for the IndicatorMapNotify event
12044 pub const INDICATOR_MAP_NOTIFY_EVENT: u8 = 5;
12045 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
12046 pub struct IndicatorMapNotifyEvent {
12047 pub response_type: u8,
12048 pub xkb_type: u8,
12049 pub sequence: u16,
12050 pub time: xproto::Timestamp,
12051 pub device_id: u8,
12052 pub state: u32,
12053 pub map_changed: u32,
12054 }
12055 impl TryParse for IndicatorMapNotifyEvent {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>12056 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
12057 let remaining = initial_value;
12058 let (response_type, remaining) = u8::try_parse(remaining)?;
12059 let (xkb_type, remaining) = u8::try_parse(remaining)?;
12060 let (sequence, remaining) = u16::try_parse(remaining)?;
12061 let (time, remaining) = xproto::Timestamp::try_parse(remaining)?;
12062 let (device_id, remaining) = u8::try_parse(remaining)?;
12063 let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?;
12064 let (state, remaining) = u32::try_parse(remaining)?;
12065 let (map_changed, remaining) = u32::try_parse(remaining)?;
12066 let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
12067 let result = IndicatorMapNotifyEvent { response_type, xkb_type, sequence, time, device_id, state, map_changed };
12068 let _ = remaining;
12069 let remaining = initial_value.get(32..)
12070 .ok_or(ParseError::InsufficientData)?;
12071 Ok((result, remaining))
12072 }
12073 }
12074 impl From<&IndicatorMapNotifyEvent> for [u8; 32] {
from(input: &IndicatorMapNotifyEvent) -> Self12075 fn from(input: &IndicatorMapNotifyEvent) -> Self {
12076 let response_type_bytes = input.response_type.serialize();
12077 let xkb_type_bytes = input.xkb_type.serialize();
12078 let sequence_bytes = input.sequence.serialize();
12079 let time_bytes = input.time.serialize();
12080 let device_id_bytes = input.device_id.serialize();
12081 let state_bytes = input.state.serialize();
12082 let map_changed_bytes = input.map_changed.serialize();
12083 [
12084 response_type_bytes[0],
12085 xkb_type_bytes[0],
12086 sequence_bytes[0],
12087 sequence_bytes[1],
12088 time_bytes[0],
12089 time_bytes[1],
12090 time_bytes[2],
12091 time_bytes[3],
12092 device_id_bytes[0],
12093 0,
12094 0,
12095 0,
12096 state_bytes[0],
12097 state_bytes[1],
12098 state_bytes[2],
12099 state_bytes[3],
12100 map_changed_bytes[0],
12101 map_changed_bytes[1],
12102 map_changed_bytes[2],
12103 map_changed_bytes[3],
12104 0,
12105 0,
12106 0,
12107 0,
12108 0,
12109 0,
12110 0,
12111 0,
12112 0,
12113 0,
12114 0,
12115 0,
12116 ]
12117 }
12118 }
12119 impl From<IndicatorMapNotifyEvent> for [u8; 32] {
from(input: IndicatorMapNotifyEvent) -> Self12120 fn from(input: IndicatorMapNotifyEvent) -> Self {
12121 Self::from(&input)
12122 }
12123 }
12124
12125 /// Opcode for the NamesNotify event
12126 pub const NAMES_NOTIFY_EVENT: u8 = 6;
12127 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
12128 pub struct NamesNotifyEvent {
12129 pub response_type: u8,
12130 pub xkb_type: u8,
12131 pub sequence: u16,
12132 pub time: xproto::Timestamp,
12133 pub device_id: u8,
12134 pub changed: u16,
12135 pub first_type: u8,
12136 pub n_types: u8,
12137 pub first_level_name: u8,
12138 pub n_level_names: u8,
12139 pub n_radio_groups: u8,
12140 pub n_key_aliases: u8,
12141 pub changed_group_names: u8,
12142 pub changed_virtual_mods: u16,
12143 pub first_key: xproto::Keycode,
12144 pub n_keys: u8,
12145 pub changed_indicators: u32,
12146 }
12147 impl TryParse for NamesNotifyEvent {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>12148 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
12149 let remaining = initial_value;
12150 let (response_type, remaining) = u8::try_parse(remaining)?;
12151 let (xkb_type, remaining) = u8::try_parse(remaining)?;
12152 let (sequence, remaining) = u16::try_parse(remaining)?;
12153 let (time, remaining) = xproto::Timestamp::try_parse(remaining)?;
12154 let (device_id, remaining) = u8::try_parse(remaining)?;
12155 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
12156 let (changed, remaining) = u16::try_parse(remaining)?;
12157 let (first_type, remaining) = u8::try_parse(remaining)?;
12158 let (n_types, remaining) = u8::try_parse(remaining)?;
12159 let (first_level_name, remaining) = u8::try_parse(remaining)?;
12160 let (n_level_names, remaining) = u8::try_parse(remaining)?;
12161 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
12162 let (n_radio_groups, remaining) = u8::try_parse(remaining)?;
12163 let (n_key_aliases, remaining) = u8::try_parse(remaining)?;
12164 let (changed_group_names, remaining) = u8::try_parse(remaining)?;
12165 let (changed_virtual_mods, remaining) = u16::try_parse(remaining)?;
12166 let (first_key, remaining) = xproto::Keycode::try_parse(remaining)?;
12167 let (n_keys, remaining) = u8::try_parse(remaining)?;
12168 let (changed_indicators, remaining) = u32::try_parse(remaining)?;
12169 let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?;
12170 let result = NamesNotifyEvent { response_type, xkb_type, sequence, time, device_id, changed, first_type, n_types, first_level_name, n_level_names, n_radio_groups, n_key_aliases, changed_group_names, changed_virtual_mods, first_key, n_keys, changed_indicators };
12171 let _ = remaining;
12172 let remaining = initial_value.get(32..)
12173 .ok_or(ParseError::InsufficientData)?;
12174 Ok((result, remaining))
12175 }
12176 }
12177 impl From<&NamesNotifyEvent> for [u8; 32] {
from(input: &NamesNotifyEvent) -> Self12178 fn from(input: &NamesNotifyEvent) -> Self {
12179 let response_type_bytes = input.response_type.serialize();
12180 let xkb_type_bytes = input.xkb_type.serialize();
12181 let sequence_bytes = input.sequence.serialize();
12182 let time_bytes = input.time.serialize();
12183 let device_id_bytes = input.device_id.serialize();
12184 let changed_bytes = input.changed.serialize();
12185 let first_type_bytes = input.first_type.serialize();
12186 let n_types_bytes = input.n_types.serialize();
12187 let first_level_name_bytes = input.first_level_name.serialize();
12188 let n_level_names_bytes = input.n_level_names.serialize();
12189 let n_radio_groups_bytes = input.n_radio_groups.serialize();
12190 let n_key_aliases_bytes = input.n_key_aliases.serialize();
12191 let changed_group_names_bytes = input.changed_group_names.serialize();
12192 let changed_virtual_mods_bytes = input.changed_virtual_mods.serialize();
12193 let first_key_bytes = input.first_key.serialize();
12194 let n_keys_bytes = input.n_keys.serialize();
12195 let changed_indicators_bytes = input.changed_indicators.serialize();
12196 [
12197 response_type_bytes[0],
12198 xkb_type_bytes[0],
12199 sequence_bytes[0],
12200 sequence_bytes[1],
12201 time_bytes[0],
12202 time_bytes[1],
12203 time_bytes[2],
12204 time_bytes[3],
12205 device_id_bytes[0],
12206 0,
12207 changed_bytes[0],
12208 changed_bytes[1],
12209 first_type_bytes[0],
12210 n_types_bytes[0],
12211 first_level_name_bytes[0],
12212 n_level_names_bytes[0],
12213 0,
12214 n_radio_groups_bytes[0],
12215 n_key_aliases_bytes[0],
12216 changed_group_names_bytes[0],
12217 changed_virtual_mods_bytes[0],
12218 changed_virtual_mods_bytes[1],
12219 first_key_bytes[0],
12220 n_keys_bytes[0],
12221 changed_indicators_bytes[0],
12222 changed_indicators_bytes[1],
12223 changed_indicators_bytes[2],
12224 changed_indicators_bytes[3],
12225 0,
12226 0,
12227 0,
12228 0,
12229 ]
12230 }
12231 }
12232 impl From<NamesNotifyEvent> for [u8; 32] {
from(input: NamesNotifyEvent) -> Self12233 fn from(input: NamesNotifyEvent) -> Self {
12234 Self::from(&input)
12235 }
12236 }
12237
12238 /// Opcode for the CompatMapNotify event
12239 pub const COMPAT_MAP_NOTIFY_EVENT: u8 = 7;
12240 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
12241 pub struct CompatMapNotifyEvent {
12242 pub response_type: u8,
12243 pub xkb_type: u8,
12244 pub sequence: u16,
12245 pub time: xproto::Timestamp,
12246 pub device_id: u8,
12247 pub changed_groups: u8,
12248 pub first_si: u16,
12249 pub n_si: u16,
12250 pub n_total_si: u16,
12251 }
12252 impl TryParse for CompatMapNotifyEvent {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>12253 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
12254 let remaining = initial_value;
12255 let (response_type, remaining) = u8::try_parse(remaining)?;
12256 let (xkb_type, remaining) = u8::try_parse(remaining)?;
12257 let (sequence, remaining) = u16::try_parse(remaining)?;
12258 let (time, remaining) = xproto::Timestamp::try_parse(remaining)?;
12259 let (device_id, remaining) = u8::try_parse(remaining)?;
12260 let (changed_groups, remaining) = u8::try_parse(remaining)?;
12261 let (first_si, remaining) = u16::try_parse(remaining)?;
12262 let (n_si, remaining) = u16::try_parse(remaining)?;
12263 let (n_total_si, remaining) = u16::try_parse(remaining)?;
12264 let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?;
12265 let result = CompatMapNotifyEvent { response_type, xkb_type, sequence, time, device_id, changed_groups, first_si, n_si, n_total_si };
12266 let _ = remaining;
12267 let remaining = initial_value.get(32..)
12268 .ok_or(ParseError::InsufficientData)?;
12269 Ok((result, remaining))
12270 }
12271 }
12272 impl From<&CompatMapNotifyEvent> for [u8; 32] {
from(input: &CompatMapNotifyEvent) -> Self12273 fn from(input: &CompatMapNotifyEvent) -> Self {
12274 let response_type_bytes = input.response_type.serialize();
12275 let xkb_type_bytes = input.xkb_type.serialize();
12276 let sequence_bytes = input.sequence.serialize();
12277 let time_bytes = input.time.serialize();
12278 let device_id_bytes = input.device_id.serialize();
12279 let changed_groups_bytes = input.changed_groups.serialize();
12280 let first_si_bytes = input.first_si.serialize();
12281 let n_si_bytes = input.n_si.serialize();
12282 let n_total_si_bytes = input.n_total_si.serialize();
12283 [
12284 response_type_bytes[0],
12285 xkb_type_bytes[0],
12286 sequence_bytes[0],
12287 sequence_bytes[1],
12288 time_bytes[0],
12289 time_bytes[1],
12290 time_bytes[2],
12291 time_bytes[3],
12292 device_id_bytes[0],
12293 changed_groups_bytes[0],
12294 first_si_bytes[0],
12295 first_si_bytes[1],
12296 n_si_bytes[0],
12297 n_si_bytes[1],
12298 n_total_si_bytes[0],
12299 n_total_si_bytes[1],
12300 0,
12301 0,
12302 0,
12303 0,
12304 0,
12305 0,
12306 0,
12307 0,
12308 0,
12309 0,
12310 0,
12311 0,
12312 0,
12313 0,
12314 0,
12315 0,
12316 ]
12317 }
12318 }
12319 impl From<CompatMapNotifyEvent> for [u8; 32] {
from(input: CompatMapNotifyEvent) -> Self12320 fn from(input: CompatMapNotifyEvent) -> Self {
12321 Self::from(&input)
12322 }
12323 }
12324
12325 /// Opcode for the BellNotify event
12326 pub const BELL_NOTIFY_EVENT: u8 = 8;
12327 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
12328 pub struct BellNotifyEvent {
12329 pub response_type: u8,
12330 pub xkb_type: u8,
12331 pub sequence: u16,
12332 pub time: xproto::Timestamp,
12333 pub device_id: u8,
12334 pub bell_class: BellClassResult,
12335 pub bell_id: u8,
12336 pub percent: u8,
12337 pub pitch: u16,
12338 pub duration: u16,
12339 pub name: xproto::Atom,
12340 pub window: xproto::Window,
12341 pub event_only: bool,
12342 }
12343 impl TryParse for BellNotifyEvent {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>12344 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
12345 let remaining = initial_value;
12346 let (response_type, remaining) = u8::try_parse(remaining)?;
12347 let (xkb_type, remaining) = u8::try_parse(remaining)?;
12348 let (sequence, remaining) = u16::try_parse(remaining)?;
12349 let (time, remaining) = xproto::Timestamp::try_parse(remaining)?;
12350 let (device_id, remaining) = u8::try_parse(remaining)?;
12351 let (bell_class, remaining) = u8::try_parse(remaining)?;
12352 let (bell_id, remaining) = u8::try_parse(remaining)?;
12353 let (percent, remaining) = u8::try_parse(remaining)?;
12354 let (pitch, remaining) = u16::try_parse(remaining)?;
12355 let (duration, remaining) = u16::try_parse(remaining)?;
12356 let (name, remaining) = xproto::Atom::try_parse(remaining)?;
12357 let (window, remaining) = xproto::Window::try_parse(remaining)?;
12358 let (event_only, remaining) = bool::try_parse(remaining)?;
12359 let remaining = remaining.get(7..).ok_or(ParseError::InsufficientData)?;
12360 let bell_class = bell_class.into();
12361 let result = BellNotifyEvent { response_type, xkb_type, sequence, time, device_id, bell_class, bell_id, percent, pitch, duration, name, window, event_only };
12362 let _ = remaining;
12363 let remaining = initial_value.get(32..)
12364 .ok_or(ParseError::InsufficientData)?;
12365 Ok((result, remaining))
12366 }
12367 }
12368 impl From<&BellNotifyEvent> for [u8; 32] {
from(input: &BellNotifyEvent) -> Self12369 fn from(input: &BellNotifyEvent) -> Self {
12370 let response_type_bytes = input.response_type.serialize();
12371 let xkb_type_bytes = input.xkb_type.serialize();
12372 let sequence_bytes = input.sequence.serialize();
12373 let time_bytes = input.time.serialize();
12374 let device_id_bytes = input.device_id.serialize();
12375 let bell_class_bytes = u8::from(input.bell_class).serialize();
12376 let bell_id_bytes = input.bell_id.serialize();
12377 let percent_bytes = input.percent.serialize();
12378 let pitch_bytes = input.pitch.serialize();
12379 let duration_bytes = input.duration.serialize();
12380 let name_bytes = input.name.serialize();
12381 let window_bytes = input.window.serialize();
12382 let event_only_bytes = input.event_only.serialize();
12383 [
12384 response_type_bytes[0],
12385 xkb_type_bytes[0],
12386 sequence_bytes[0],
12387 sequence_bytes[1],
12388 time_bytes[0],
12389 time_bytes[1],
12390 time_bytes[2],
12391 time_bytes[3],
12392 device_id_bytes[0],
12393 bell_class_bytes[0],
12394 bell_id_bytes[0],
12395 percent_bytes[0],
12396 pitch_bytes[0],
12397 pitch_bytes[1],
12398 duration_bytes[0],
12399 duration_bytes[1],
12400 name_bytes[0],
12401 name_bytes[1],
12402 name_bytes[2],
12403 name_bytes[3],
12404 window_bytes[0],
12405 window_bytes[1],
12406 window_bytes[2],
12407 window_bytes[3],
12408 event_only_bytes[0],
12409 0,
12410 0,
12411 0,
12412 0,
12413 0,
12414 0,
12415 0,
12416 ]
12417 }
12418 }
12419 impl From<BellNotifyEvent> for [u8; 32] {
from(input: BellNotifyEvent) -> Self12420 fn from(input: BellNotifyEvent) -> Self {
12421 Self::from(&input)
12422 }
12423 }
12424
12425 /// Opcode for the ActionMessage event
12426 pub const ACTION_MESSAGE_EVENT: u8 = 9;
12427 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
12428 pub struct ActionMessageEvent {
12429 pub response_type: u8,
12430 pub xkb_type: u8,
12431 pub sequence: u16,
12432 pub time: xproto::Timestamp,
12433 pub device_id: u8,
12434 pub keycode: xproto::Keycode,
12435 pub press: bool,
12436 pub key_event_follows: bool,
12437 pub mods: u8,
12438 pub group: Group,
12439 pub message: [String8; 8],
12440 }
12441 impl TryParse for ActionMessageEvent {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>12442 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
12443 let remaining = initial_value;
12444 let (response_type, remaining) = u8::try_parse(remaining)?;
12445 let (xkb_type, remaining) = u8::try_parse(remaining)?;
12446 let (sequence, remaining) = u16::try_parse(remaining)?;
12447 let (time, remaining) = xproto::Timestamp::try_parse(remaining)?;
12448 let (device_id, remaining) = u8::try_parse(remaining)?;
12449 let (keycode, remaining) = xproto::Keycode::try_parse(remaining)?;
12450 let (press, remaining) = bool::try_parse(remaining)?;
12451 let (key_event_follows, remaining) = bool::try_parse(remaining)?;
12452 let (mods, remaining) = u8::try_parse(remaining)?;
12453 let (group, remaining) = u8::try_parse(remaining)?;
12454 let (message, remaining) = crate::x11_utils::parse_u8_list(remaining, 8)?;
12455 let message = <[u8; 8]>::try_from(message).unwrap();
12456 let remaining = remaining.get(10..).ok_or(ParseError::InsufficientData)?;
12457 let group = group.into();
12458 let result = ActionMessageEvent { response_type, xkb_type, sequence, time, device_id, keycode, press, key_event_follows, mods, group, message };
12459 let _ = remaining;
12460 let remaining = initial_value.get(32..)
12461 .ok_or(ParseError::InsufficientData)?;
12462 Ok((result, remaining))
12463 }
12464 }
12465 impl From<&ActionMessageEvent> for [u8; 32] {
from(input: &ActionMessageEvent) -> Self12466 fn from(input: &ActionMessageEvent) -> Self {
12467 let response_type_bytes = input.response_type.serialize();
12468 let xkb_type_bytes = input.xkb_type.serialize();
12469 let sequence_bytes = input.sequence.serialize();
12470 let time_bytes = input.time.serialize();
12471 let device_id_bytes = input.device_id.serialize();
12472 let keycode_bytes = input.keycode.serialize();
12473 let press_bytes = input.press.serialize();
12474 let key_event_follows_bytes = input.key_event_follows.serialize();
12475 let mods_bytes = input.mods.serialize();
12476 let group_bytes = u8::from(input.group).serialize();
12477 [
12478 response_type_bytes[0],
12479 xkb_type_bytes[0],
12480 sequence_bytes[0],
12481 sequence_bytes[1],
12482 time_bytes[0],
12483 time_bytes[1],
12484 time_bytes[2],
12485 time_bytes[3],
12486 device_id_bytes[0],
12487 keycode_bytes[0],
12488 press_bytes[0],
12489 key_event_follows_bytes[0],
12490 mods_bytes[0],
12491 group_bytes[0],
12492 input.message[0],
12493 input.message[1],
12494 input.message[2],
12495 input.message[3],
12496 input.message[4],
12497 input.message[5],
12498 input.message[6],
12499 input.message[7],
12500 0,
12501 0,
12502 0,
12503 0,
12504 0,
12505 0,
12506 0,
12507 0,
12508 0,
12509 0,
12510 ]
12511 }
12512 }
12513 impl From<ActionMessageEvent> for [u8; 32] {
from(input: ActionMessageEvent) -> Self12514 fn from(input: ActionMessageEvent) -> Self {
12515 Self::from(&input)
12516 }
12517 }
12518
12519 /// Opcode for the AccessXNotify event
12520 pub const ACCESS_X_NOTIFY_EVENT: u8 = 10;
12521 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
12522 pub struct AccessXNotifyEvent {
12523 pub response_type: u8,
12524 pub xkb_type: u8,
12525 pub sequence: u16,
12526 pub time: xproto::Timestamp,
12527 pub device_id: u8,
12528 pub keycode: xproto::Keycode,
12529 pub detailt: u16,
12530 pub slow_keys_delay: u16,
12531 pub debounce_delay: u16,
12532 }
12533 impl TryParse for AccessXNotifyEvent {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>12534 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
12535 let remaining = initial_value;
12536 let (response_type, remaining) = u8::try_parse(remaining)?;
12537 let (xkb_type, remaining) = u8::try_parse(remaining)?;
12538 let (sequence, remaining) = u16::try_parse(remaining)?;
12539 let (time, remaining) = xproto::Timestamp::try_parse(remaining)?;
12540 let (device_id, remaining) = u8::try_parse(remaining)?;
12541 let (keycode, remaining) = xproto::Keycode::try_parse(remaining)?;
12542 let (detailt, remaining) = u16::try_parse(remaining)?;
12543 let (slow_keys_delay, remaining) = u16::try_parse(remaining)?;
12544 let (debounce_delay, remaining) = u16::try_parse(remaining)?;
12545 let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?;
12546 let result = AccessXNotifyEvent { response_type, xkb_type, sequence, time, device_id, keycode, detailt, slow_keys_delay, debounce_delay };
12547 let _ = remaining;
12548 let remaining = initial_value.get(32..)
12549 .ok_or(ParseError::InsufficientData)?;
12550 Ok((result, remaining))
12551 }
12552 }
12553 impl From<&AccessXNotifyEvent> for [u8; 32] {
from(input: &AccessXNotifyEvent) -> Self12554 fn from(input: &AccessXNotifyEvent) -> Self {
12555 let response_type_bytes = input.response_type.serialize();
12556 let xkb_type_bytes = input.xkb_type.serialize();
12557 let sequence_bytes = input.sequence.serialize();
12558 let time_bytes = input.time.serialize();
12559 let device_id_bytes = input.device_id.serialize();
12560 let keycode_bytes = input.keycode.serialize();
12561 let detailt_bytes = input.detailt.serialize();
12562 let slow_keys_delay_bytes = input.slow_keys_delay.serialize();
12563 let debounce_delay_bytes = input.debounce_delay.serialize();
12564 [
12565 response_type_bytes[0],
12566 xkb_type_bytes[0],
12567 sequence_bytes[0],
12568 sequence_bytes[1],
12569 time_bytes[0],
12570 time_bytes[1],
12571 time_bytes[2],
12572 time_bytes[3],
12573 device_id_bytes[0],
12574 keycode_bytes[0],
12575 detailt_bytes[0],
12576 detailt_bytes[1],
12577 slow_keys_delay_bytes[0],
12578 slow_keys_delay_bytes[1],
12579 debounce_delay_bytes[0],
12580 debounce_delay_bytes[1],
12581 0,
12582 0,
12583 0,
12584 0,
12585 0,
12586 0,
12587 0,
12588 0,
12589 0,
12590 0,
12591 0,
12592 0,
12593 0,
12594 0,
12595 0,
12596 0,
12597 ]
12598 }
12599 }
12600 impl From<AccessXNotifyEvent> for [u8; 32] {
from(input: AccessXNotifyEvent) -> Self12601 fn from(input: AccessXNotifyEvent) -> Self {
12602 Self::from(&input)
12603 }
12604 }
12605
12606 /// Opcode for the ExtensionDeviceNotify event
12607 pub const EXTENSION_DEVICE_NOTIFY_EVENT: u8 = 11;
12608 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
12609 pub struct ExtensionDeviceNotifyEvent {
12610 pub response_type: u8,
12611 pub xkb_type: u8,
12612 pub sequence: u16,
12613 pub time: xproto::Timestamp,
12614 pub device_id: u8,
12615 pub reason: u16,
12616 pub led_class: LedClassResult,
12617 pub led_id: u16,
12618 pub leds_defined: u32,
12619 pub led_state: u32,
12620 pub first_button: u8,
12621 pub n_buttons: u8,
12622 pub supported: u16,
12623 pub unsupported: u16,
12624 }
12625 impl TryParse for ExtensionDeviceNotifyEvent {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>12626 fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
12627 let remaining = initial_value;
12628 let (response_type, remaining) = u8::try_parse(remaining)?;
12629 let (xkb_type, remaining) = u8::try_parse(remaining)?;
12630 let (sequence, remaining) = u16::try_parse(remaining)?;
12631 let (time, remaining) = xproto::Timestamp::try_parse(remaining)?;
12632 let (device_id, remaining) = u8::try_parse(remaining)?;
12633 let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
12634 let (reason, remaining) = u16::try_parse(remaining)?;
12635 let (led_class, remaining) = u16::try_parse(remaining)?;
12636 let (led_id, remaining) = u16::try_parse(remaining)?;
12637 let (leds_defined, remaining) = u32::try_parse(remaining)?;
12638 let (led_state, remaining) = u32::try_parse(remaining)?;
12639 let (first_button, remaining) = u8::try_parse(remaining)?;
12640 let (n_buttons, remaining) = u8::try_parse(remaining)?;
12641 let (supported, remaining) = u16::try_parse(remaining)?;
12642 let (unsupported, remaining) = u16::try_parse(remaining)?;
12643 let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
12644 let led_class = led_class.into();
12645 let result = ExtensionDeviceNotifyEvent { response_type, xkb_type, sequence, time, device_id, reason, led_class, led_id, leds_defined, led_state, first_button, n_buttons, supported, unsupported };
12646 let _ = remaining;
12647 let remaining = initial_value.get(32..)
12648 .ok_or(ParseError::InsufficientData)?;
12649 Ok((result, remaining))
12650 }
12651 }
12652 impl From<&ExtensionDeviceNotifyEvent> for [u8; 32] {
from(input: &ExtensionDeviceNotifyEvent) -> Self12653 fn from(input: &ExtensionDeviceNotifyEvent) -> Self {
12654 let response_type_bytes = input.response_type.serialize();
12655 let xkb_type_bytes = input.xkb_type.serialize();
12656 let sequence_bytes = input.sequence.serialize();
12657 let time_bytes = input.time.serialize();
12658 let device_id_bytes = input.device_id.serialize();
12659 let reason_bytes = input.reason.serialize();
12660 let led_class_bytes = u16::from(input.led_class).serialize();
12661 let led_id_bytes = input.led_id.serialize();
12662 let leds_defined_bytes = input.leds_defined.serialize();
12663 let led_state_bytes = input.led_state.serialize();
12664 let first_button_bytes = input.first_button.serialize();
12665 let n_buttons_bytes = input.n_buttons.serialize();
12666 let supported_bytes = input.supported.serialize();
12667 let unsupported_bytes = input.unsupported.serialize();
12668 [
12669 response_type_bytes[0],
12670 xkb_type_bytes[0],
12671 sequence_bytes[0],
12672 sequence_bytes[1],
12673 time_bytes[0],
12674 time_bytes[1],
12675 time_bytes[2],
12676 time_bytes[3],
12677 device_id_bytes[0],
12678 0,
12679 reason_bytes[0],
12680 reason_bytes[1],
12681 led_class_bytes[0],
12682 led_class_bytes[1],
12683 led_id_bytes[0],
12684 led_id_bytes[1],
12685 leds_defined_bytes[0],
12686 leds_defined_bytes[1],
12687 leds_defined_bytes[2],
12688 leds_defined_bytes[3],
12689 led_state_bytes[0],
12690 led_state_bytes[1],
12691 led_state_bytes[2],
12692 led_state_bytes[3],
12693 first_button_bytes[0],
12694 n_buttons_bytes[0],
12695 supported_bytes[0],
12696 supported_bytes[1],
12697 unsupported_bytes[0],
12698 unsupported_bytes[1],
12699 0,
12700 0,
12701 ]
12702 }
12703 }
12704 impl From<ExtensionDeviceNotifyEvent> for [u8; 32] {
from(input: ExtensionDeviceNotifyEvent) -> Self12705 fn from(input: ExtensionDeviceNotifyEvent) -> Self {
12706 Self::from(&input)
12707 }
12708 }
12709
12710 /// Extension trait defining the requests of this extension.
12711 pub trait ConnectionExt: RequestConnection {
xkb_use_extension(&self, wanted_major: u16, wanted_minor: u16) -> Result<Cookie<'_, Self, UseExtensionReply>, ConnectionError>12712 fn xkb_use_extension(&self, wanted_major: u16, wanted_minor: u16) -> Result<Cookie<'_, Self, UseExtensionReply>, ConnectionError>
12713 {
12714 use_extension(self, wanted_major, wanted_minor)
12715 }
xkb_select_events<'c, 'input, A, B, C, D>(&'c self, device_spec: DeviceSpec, clear: A, select_all: B, affect_map: C, map: D, details: &'input SelectEventsAux) -> Result<VoidCookie<'c, Self>, ConnectionError> where A: Into<u16>, B: Into<u16>, C: Into<u16>, D: Into<u16>,12716 fn xkb_select_events<'c, 'input, A, B, C, D>(&'c self, device_spec: DeviceSpec, clear: A, select_all: B, affect_map: C, map: D, details: &'input SelectEventsAux) -> Result<VoidCookie<'c, Self>, ConnectionError>
12717 where
12718 A: Into<u16>,
12719 B: Into<u16>,
12720 C: Into<u16>,
12721 D: Into<u16>,
12722 {
12723 select_events(self, device_spec, clear, select_all, affect_map, map, details)
12724 }
xkb_bell(&self, device_spec: DeviceSpec, bell_class: BellClassSpec, bell_id: IDSpec, percent: i8, force_sound: bool, event_only: bool, pitch: i16, duration: i16, name: xproto::Atom, window: xproto::Window) -> Result<VoidCookie<'_, Self>, ConnectionError>12725 fn xkb_bell(&self, device_spec: DeviceSpec, bell_class: BellClassSpec, bell_id: IDSpec, percent: i8, force_sound: bool, event_only: bool, pitch: i16, duration: i16, name: xproto::Atom, window: xproto::Window) -> Result<VoidCookie<'_, Self>, ConnectionError>
12726 {
12727 bell(self, device_spec, bell_class, bell_id, percent, force_sound, event_only, pitch, duration, name, window)
12728 }
xkb_get_state(&self, device_spec: DeviceSpec) -> Result<Cookie<'_, Self, GetStateReply>, ConnectionError>12729 fn xkb_get_state(&self, device_spec: DeviceSpec) -> Result<Cookie<'_, Self, GetStateReply>, ConnectionError>
12730 {
12731 get_state(self, device_spec)
12732 }
xkb_latch_lock_state<A, B, C>(&self, device_spec: DeviceSpec, affect_mod_locks: A, mod_locks: B, lock_group: bool, group_lock: Group, affect_mod_latches: C, latch_group: bool, group_latch: u16) -> Result<VoidCookie<'_, Self>, ConnectionError> where A: Into<u8>, B: Into<u8>, C: Into<u8>,12733 fn xkb_latch_lock_state<A, B, C>(&self, device_spec: DeviceSpec, affect_mod_locks: A, mod_locks: B, lock_group: bool, group_lock: Group, affect_mod_latches: C, latch_group: bool, group_latch: u16) -> Result<VoidCookie<'_, Self>, ConnectionError>
12734 where
12735 A: Into<u8>,
12736 B: Into<u8>,
12737 C: Into<u8>,
12738 {
12739 latch_lock_state(self, device_spec, affect_mod_locks, mod_locks, lock_group, group_lock, affect_mod_latches, latch_group, group_latch)
12740 }
xkb_get_controls(&self, device_spec: DeviceSpec) -> Result<Cookie<'_, Self, GetControlsReply>, ConnectionError>12741 fn xkb_get_controls(&self, device_spec: DeviceSpec) -> Result<Cookie<'_, Self, GetControlsReply>, ConnectionError>
12742 {
12743 get_controls(self, device_spec)
12744 }
xkb_set_controls<'c, 'input, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(&'c self, device_spec: DeviceSpec, affect_internal_real_mods: A, internal_real_mods: B, affect_ignore_lock_real_mods: C, ignore_lock_real_mods: D, affect_internal_virtual_mods: E, internal_virtual_mods: F, affect_ignore_lock_virtual_mods: G, ignore_lock_virtual_mods: H, mouse_keys_dflt_btn: u8, groups_wrap: u8, access_x_options: I, affect_enabled_controls: J, enabled_controls: K, change_controls: L, repeat_delay: u16, repeat_interval: u16, slow_keys_delay: u16, debounce_delay: u16, mouse_keys_delay: u16, mouse_keys_interval: u16, mouse_keys_time_to_max: u16, mouse_keys_max_speed: u16, mouse_keys_curve: i16, access_x_timeout: u16, access_x_timeout_mask: M, access_x_timeout_values: N, access_x_timeout_options_mask: O, access_x_timeout_options_values: P, per_key_repeat: &'input [u8; 32]) -> Result<VoidCookie<'c, Self>, ConnectionError> where A: Into<u8>, B: Into<u8>, C: Into<u8>, D: Into<u8>, E: Into<u16>, F: Into<u16>, G: Into<u16>, H: Into<u16>, I: Into<u16>, J: Into<u32>, K: Into<u32>, L: Into<u32>, M: Into<u32>, N: Into<u32>, O: Into<u16>, P: Into<u16>,12745 fn xkb_set_controls<'c, 'input, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(&'c self, device_spec: DeviceSpec, affect_internal_real_mods: A, internal_real_mods: B, affect_ignore_lock_real_mods: C, ignore_lock_real_mods: D, affect_internal_virtual_mods: E, internal_virtual_mods: F, affect_ignore_lock_virtual_mods: G, ignore_lock_virtual_mods: H, mouse_keys_dflt_btn: u8, groups_wrap: u8, access_x_options: I, affect_enabled_controls: J, enabled_controls: K, change_controls: L, repeat_delay: u16, repeat_interval: u16, slow_keys_delay: u16, debounce_delay: u16, mouse_keys_delay: u16, mouse_keys_interval: u16, mouse_keys_time_to_max: u16, mouse_keys_max_speed: u16, mouse_keys_curve: i16, access_x_timeout: u16, access_x_timeout_mask: M, access_x_timeout_values: N, access_x_timeout_options_mask: O, access_x_timeout_options_values: P, per_key_repeat: &'input [u8; 32]) -> Result<VoidCookie<'c, Self>, ConnectionError>
12746 where
12747 A: Into<u8>,
12748 B: Into<u8>,
12749 C: Into<u8>,
12750 D: Into<u8>,
12751 E: Into<u16>,
12752 F: Into<u16>,
12753 G: Into<u16>,
12754 H: Into<u16>,
12755 I: Into<u16>,
12756 J: Into<u32>,
12757 K: Into<u32>,
12758 L: Into<u32>,
12759 M: Into<u32>,
12760 N: Into<u32>,
12761 O: Into<u16>,
12762 P: Into<u16>,
12763 {
12764 set_controls(self, device_spec, affect_internal_real_mods, internal_real_mods, affect_ignore_lock_real_mods, ignore_lock_real_mods, affect_internal_virtual_mods, internal_virtual_mods, affect_ignore_lock_virtual_mods, ignore_lock_virtual_mods, mouse_keys_dflt_btn, groups_wrap, access_x_options, affect_enabled_controls, enabled_controls, change_controls, repeat_delay, repeat_interval, slow_keys_delay, debounce_delay, mouse_keys_delay, mouse_keys_interval, mouse_keys_time_to_max, mouse_keys_max_speed, mouse_keys_curve, access_x_timeout, access_x_timeout_mask, access_x_timeout_values, access_x_timeout_options_mask, access_x_timeout_options_values, per_key_repeat)
12765 }
xkb_get_map<A, B, C>(&self, device_spec: DeviceSpec, full: A, partial: B, first_type: u8, n_types: u8, first_key_sym: xproto::Keycode, n_key_syms: u8, first_key_action: xproto::Keycode, n_key_actions: u8, first_key_behavior: xproto::Keycode, n_key_behaviors: u8, virtual_mods: C, first_key_explicit: xproto::Keycode, n_key_explicit: u8, first_mod_map_key: xproto::Keycode, n_mod_map_keys: u8, first_v_mod_map_key: xproto::Keycode, n_v_mod_map_keys: u8) -> Result<Cookie<'_, Self, GetMapReply>, ConnectionError> where A: Into<u16>, B: Into<u16>, C: Into<u16>,12766 fn xkb_get_map<A, B, C>(&self, device_spec: DeviceSpec, full: A, partial: B, first_type: u8, n_types: u8, first_key_sym: xproto::Keycode, n_key_syms: u8, first_key_action: xproto::Keycode, n_key_actions: u8, first_key_behavior: xproto::Keycode, n_key_behaviors: u8, virtual_mods: C, first_key_explicit: xproto::Keycode, n_key_explicit: u8, first_mod_map_key: xproto::Keycode, n_mod_map_keys: u8, first_v_mod_map_key: xproto::Keycode, n_v_mod_map_keys: u8) -> Result<Cookie<'_, Self, GetMapReply>, ConnectionError>
12767 where
12768 A: Into<u16>,
12769 B: Into<u16>,
12770 C: Into<u16>,
12771 {
12772 get_map(self, device_spec, full, partial, first_type, n_types, first_key_sym, n_key_syms, first_key_action, n_key_actions, first_key_behavior, n_key_behaviors, virtual_mods, first_key_explicit, n_key_explicit, first_mod_map_key, n_mod_map_keys, first_v_mod_map_key, n_v_mod_map_keys)
12773 }
xkb_set_map<'c, 'input, A, B>(&'c self, device_spec: DeviceSpec, flags: A, min_key_code: xproto::Keycode, max_key_code: xproto::Keycode, first_type: u8, n_types: u8, first_key_sym: xproto::Keycode, n_key_syms: u8, total_syms: u16, first_key_action: xproto::Keycode, n_key_actions: u8, total_actions: u16, first_key_behavior: xproto::Keycode, n_key_behaviors: u8, total_key_behaviors: u8, first_key_explicit: xproto::Keycode, n_key_explicit: u8, total_key_explicit: u8, first_mod_map_key: xproto::Keycode, n_mod_map_keys: u8, total_mod_map_keys: u8, first_v_mod_map_key: xproto::Keycode, n_v_mod_map_keys: u8, total_v_mod_map_keys: u8, virtual_mods: B, values: &'input SetMapAux) -> Result<VoidCookie<'c, Self>, ConnectionError> where A: Into<u16>, B: Into<u16>,12774 fn xkb_set_map<'c, 'input, A, B>(&'c self, device_spec: DeviceSpec, flags: A, min_key_code: xproto::Keycode, max_key_code: xproto::Keycode, first_type: u8, n_types: u8, first_key_sym: xproto::Keycode, n_key_syms: u8, total_syms: u16, first_key_action: xproto::Keycode, n_key_actions: u8, total_actions: u16, first_key_behavior: xproto::Keycode, n_key_behaviors: u8, total_key_behaviors: u8, first_key_explicit: xproto::Keycode, n_key_explicit: u8, total_key_explicit: u8, first_mod_map_key: xproto::Keycode, n_mod_map_keys: u8, total_mod_map_keys: u8, first_v_mod_map_key: xproto::Keycode, n_v_mod_map_keys: u8, total_v_mod_map_keys: u8, virtual_mods: B, values: &'input SetMapAux) -> Result<VoidCookie<'c, Self>, ConnectionError>
12775 where
12776 A: Into<u16>,
12777 B: Into<u16>,
12778 {
12779 set_map(self, device_spec, flags, min_key_code, max_key_code, first_type, n_types, first_key_sym, n_key_syms, total_syms, first_key_action, n_key_actions, total_actions, first_key_behavior, n_key_behaviors, total_key_behaviors, first_key_explicit, n_key_explicit, total_key_explicit, first_mod_map_key, n_mod_map_keys, total_mod_map_keys, first_v_mod_map_key, n_v_mod_map_keys, total_v_mod_map_keys, virtual_mods, values)
12780 }
xkb_get_compat_map<A>(&self, device_spec: DeviceSpec, groups: A, get_all_si: bool, first_si: u16, n_si: u16) -> Result<Cookie<'_, Self, GetCompatMapReply>, ConnectionError> where A: Into<u8>,12781 fn xkb_get_compat_map<A>(&self, device_spec: DeviceSpec, groups: A, get_all_si: bool, first_si: u16, n_si: u16) -> Result<Cookie<'_, Self, GetCompatMapReply>, ConnectionError>
12782 where
12783 A: Into<u8>,
12784 {
12785 get_compat_map(self, device_spec, groups, get_all_si, first_si, n_si)
12786 }
xkb_set_compat_map<'c, 'input, A>(&'c self, device_spec: DeviceSpec, recompute_actions: bool, truncate_si: bool, groups: A, first_si: u16, si: &'input [SymInterpret], group_maps: &'input [ModDef]) -> Result<VoidCookie<'c, Self>, ConnectionError> where A: Into<u8>,12787 fn xkb_set_compat_map<'c, 'input, A>(&'c self, device_spec: DeviceSpec, recompute_actions: bool, truncate_si: bool, groups: A, first_si: u16, si: &'input [SymInterpret], group_maps: &'input [ModDef]) -> Result<VoidCookie<'c, Self>, ConnectionError>
12788 where
12789 A: Into<u8>,
12790 {
12791 set_compat_map(self, device_spec, recompute_actions, truncate_si, groups, first_si, si, group_maps)
12792 }
xkb_get_indicator_state(&self, device_spec: DeviceSpec) -> Result<Cookie<'_, Self, GetIndicatorStateReply>, ConnectionError>12793 fn xkb_get_indicator_state(&self, device_spec: DeviceSpec) -> Result<Cookie<'_, Self, GetIndicatorStateReply>, ConnectionError>
12794 {
12795 get_indicator_state(self, device_spec)
12796 }
xkb_get_indicator_map(&self, device_spec: DeviceSpec, which: u32) -> Result<Cookie<'_, Self, GetIndicatorMapReply>, ConnectionError>12797 fn xkb_get_indicator_map(&self, device_spec: DeviceSpec, which: u32) -> Result<Cookie<'_, Self, GetIndicatorMapReply>, ConnectionError>
12798 {
12799 get_indicator_map(self, device_spec, which)
12800 }
xkb_set_indicator_map<'c, 'input>(&'c self, device_spec: DeviceSpec, which: u32, maps: &'input [IndicatorMap]) -> Result<VoidCookie<'c, Self>, ConnectionError>12801 fn xkb_set_indicator_map<'c, 'input>(&'c self, device_spec: DeviceSpec, which: u32, maps: &'input [IndicatorMap]) -> Result<VoidCookie<'c, Self>, ConnectionError>
12802 {
12803 set_indicator_map(self, device_spec, which, maps)
12804 }
xkb_get_named_indicator<A>(&self, device_spec: DeviceSpec, led_class: LedClass, led_id: A, indicator: xproto::Atom) -> Result<Cookie<'_, Self, GetNamedIndicatorReply>, ConnectionError> where A: Into<IDSpec>,12805 fn xkb_get_named_indicator<A>(&self, device_spec: DeviceSpec, led_class: LedClass, led_id: A, indicator: xproto::Atom) -> Result<Cookie<'_, Self, GetNamedIndicatorReply>, ConnectionError>
12806 where
12807 A: Into<IDSpec>,
12808 {
12809 get_named_indicator(self, device_spec, led_class, led_id, indicator)
12810 }
xkb_set_named_indicator<A, B, C, D, E, F, G, H>(&self, device_spec: DeviceSpec, led_class: LedClass, led_id: A, indicator: xproto::Atom, set_state: bool, on: bool, set_map: bool, create_map: bool, map_flags: B, map_which_groups: C, map_groups: D, map_which_mods: E, map_real_mods: F, map_vmods: G, map_ctrls: H) -> Result<VoidCookie<'_, Self>, ConnectionError> where A: Into<IDSpec>, B: Into<u8>, C: Into<u8>, D: Into<u8>, E: Into<u8>, F: Into<u8>, G: Into<u16>, H: Into<u32>,12811 fn xkb_set_named_indicator<A, B, C, D, E, F, G, H>(&self, device_spec: DeviceSpec, led_class: LedClass, led_id: A, indicator: xproto::Atom, set_state: bool, on: bool, set_map: bool, create_map: bool, map_flags: B, map_which_groups: C, map_groups: D, map_which_mods: E, map_real_mods: F, map_vmods: G, map_ctrls: H) -> Result<VoidCookie<'_, Self>, ConnectionError>
12812 where
12813 A: Into<IDSpec>,
12814 B: Into<u8>,
12815 C: Into<u8>,
12816 D: Into<u8>,
12817 E: Into<u8>,
12818 F: Into<u8>,
12819 G: Into<u16>,
12820 H: Into<u32>,
12821 {
12822 set_named_indicator(self, device_spec, led_class, led_id, indicator, set_state, on, set_map, create_map, map_flags, map_which_groups, map_groups, map_which_mods, map_real_mods, map_vmods, map_ctrls)
12823 }
xkb_get_names<A>(&self, device_spec: DeviceSpec, which: A) -> Result<Cookie<'_, Self, GetNamesReply>, ConnectionError> where A: Into<u32>,12824 fn xkb_get_names<A>(&self, device_spec: DeviceSpec, which: A) -> Result<Cookie<'_, Self, GetNamesReply>, ConnectionError>
12825 where
12826 A: Into<u32>,
12827 {
12828 get_names(self, device_spec, which)
12829 }
xkb_set_names<'c, 'input, A, B>(&'c self, device_spec: DeviceSpec, virtual_mods: A, first_type: u8, n_types: u8, first_kt_levelt: u8, n_kt_levels: u8, indicators: u32, group_names: B, n_radio_groups: u8, first_key: xproto::Keycode, n_keys: u8, n_key_aliases: u8, total_kt_level_names: u16, values: &'input SetNamesAux) -> Result<VoidCookie<'c, Self>, ConnectionError> where A: Into<u16>, B: Into<u8>,12830 fn xkb_set_names<'c, 'input, A, B>(&'c self, device_spec: DeviceSpec, virtual_mods: A, first_type: u8, n_types: u8, first_kt_levelt: u8, n_kt_levels: u8, indicators: u32, group_names: B, n_radio_groups: u8, first_key: xproto::Keycode, n_keys: u8, n_key_aliases: u8, total_kt_level_names: u16, values: &'input SetNamesAux) -> Result<VoidCookie<'c, Self>, ConnectionError>
12831 where
12832 A: Into<u16>,
12833 B: Into<u8>,
12834 {
12835 set_names(self, device_spec, virtual_mods, first_type, n_types, first_kt_levelt, n_kt_levels, indicators, group_names, n_radio_groups, first_key, n_keys, n_key_aliases, total_kt_level_names, values)
12836 }
xkb_per_client_flags<A, B, C, D, E>(&self, device_spec: DeviceSpec, change: A, value: B, ctrls_to_change: C, auto_ctrls: D, auto_ctrls_values: E) -> Result<Cookie<'_, Self, PerClientFlagsReply>, ConnectionError> where A: Into<u32>, B: Into<u32>, C: Into<u32>, D: Into<u32>, E: Into<u32>,12837 fn xkb_per_client_flags<A, B, C, D, E>(&self, device_spec: DeviceSpec, change: A, value: B, ctrls_to_change: C, auto_ctrls: D, auto_ctrls_values: E) -> Result<Cookie<'_, Self, PerClientFlagsReply>, ConnectionError>
12838 where
12839 A: Into<u32>,
12840 B: Into<u32>,
12841 C: Into<u32>,
12842 D: Into<u32>,
12843 E: Into<u32>,
12844 {
12845 per_client_flags(self, device_spec, change, value, ctrls_to_change, auto_ctrls, auto_ctrls_values)
12846 }
xkb_list_components(&self, device_spec: DeviceSpec, max_names: u16) -> Result<Cookie<'_, Self, ListComponentsReply>, ConnectionError>12847 fn xkb_list_components(&self, device_spec: DeviceSpec, max_names: u16) -> Result<Cookie<'_, Self, ListComponentsReply>, ConnectionError>
12848 {
12849 list_components(self, device_spec, max_names)
12850 }
xkb_get_kbd_by_name<A, B>(&self, device_spec: DeviceSpec, need: A, want: B, load: bool) -> Result<Cookie<'_, Self, GetKbdByNameReply>, ConnectionError> where A: Into<u16>, B: Into<u16>,12851 fn xkb_get_kbd_by_name<A, B>(&self, device_spec: DeviceSpec, need: A, want: B, load: bool) -> Result<Cookie<'_, Self, GetKbdByNameReply>, ConnectionError>
12852 where
12853 A: Into<u16>,
12854 B: Into<u16>,
12855 {
12856 get_kbd_by_name(self, device_spec, need, want, load)
12857 }
xkb_get_device_info<A, B>(&self, device_spec: DeviceSpec, wanted: A, all_buttons: bool, first_button: u8, n_buttons: u8, led_class: LedClass, led_id: B) -> Result<Cookie<'_, Self, GetDeviceInfoReply>, ConnectionError> where A: Into<u16>, B: Into<IDSpec>,12858 fn xkb_get_device_info<A, B>(&self, device_spec: DeviceSpec, wanted: A, all_buttons: bool, first_button: u8, n_buttons: u8, led_class: LedClass, led_id: B) -> Result<Cookie<'_, Self, GetDeviceInfoReply>, ConnectionError>
12859 where
12860 A: Into<u16>,
12861 B: Into<IDSpec>,
12862 {
12863 get_device_info(self, device_spec, wanted, all_buttons, first_button, n_buttons, led_class, led_id)
12864 }
xkb_set_device_info<'c, 'input, A>(&'c self, device_spec: DeviceSpec, first_btn: u8, change: A, btn_actions: &'input [Action], leds: &'input [DeviceLedInfo]) -> Result<VoidCookie<'c, Self>, ConnectionError> where A: Into<u16>,12865 fn xkb_set_device_info<'c, 'input, A>(&'c self, device_spec: DeviceSpec, first_btn: u8, change: A, btn_actions: &'input [Action], leds: &'input [DeviceLedInfo]) -> Result<VoidCookie<'c, Self>, ConnectionError>
12866 where
12867 A: Into<u16>,
12868 {
12869 set_device_info(self, device_spec, first_btn, change, btn_actions, leds)
12870 }
xkb_set_debugging_flags<'c, 'input>(&'c self, affect_flags: u32, flags: u32, affect_ctrls: u32, ctrls: u32, message: &'input [String8]) -> Result<Cookie<'c, Self, SetDebuggingFlagsReply>, ConnectionError>12871 fn xkb_set_debugging_flags<'c, 'input>(&'c self, affect_flags: u32, flags: u32, affect_ctrls: u32, ctrls: u32, message: &'input [String8]) -> Result<Cookie<'c, Self, SetDebuggingFlagsReply>, ConnectionError>
12872 {
12873 set_debugging_flags(self, affect_flags, flags, affect_ctrls, ctrls, message)
12874 }
12875 }
12876
12877 impl<C: RequestConnection + ?Sized> ConnectionExt for C {}
12878