| 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 | // The code generator is simpler if it can always use conversions |
| 8 | #![allow (clippy::useless_conversion)] |
| 9 | |
| 10 | #[allow (unused_imports)] |
| 11 | use alloc::borrow::Cow; |
| 12 | #[allow (unused_imports)] |
| 13 | use core::convert::TryInto; |
| 14 | use alloc::vec; |
| 15 | use alloc::vec::Vec; |
| 16 | use core::convert::TryFrom; |
| 17 | use crate::errors::ParseError; |
| 18 | #[allow (unused_imports)] |
| 19 | use crate::x11_utils::TryIntoUSize; |
| 20 | use crate::BufWithFds; |
| 21 | #[allow (unused_imports)] |
| 22 | use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; |
| 23 | #[allow (unused_imports)] |
| 24 | use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; |
| 25 | #[allow (unused_imports)] |
| 26 | use super::xproto; |
| 27 | |
| 28 | /// The X11 name of the extension for QueryExtension |
| 29 | pub const X11_EXTENSION_NAME: &str = "XKEYBOARD" ; |
| 30 | |
| 31 | /// The version number of this extension that this client library supports. |
| 32 | /// |
| 33 | /// This constant contains the version number of this extension that is supported |
| 34 | /// by this build of x11rb. For most things, it does not make sense to use this |
| 35 | /// information. If you need to send a `QueryVersion`, it is recommended to instead |
| 36 | /// send the maximum version of the extension that you need. |
| 37 | pub const X11_XML_VERSION: (u32, u32) = (1, 0); |
| 38 | |
| 39 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 40 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 41 | pub struct Const(u8); |
| 42 | impl Const { |
| 43 | pub const MAX_LEGAL_KEY_CODE: Self = Self(255); |
| 44 | pub const PER_KEY_BIT_ARRAY_SIZE: Self = Self(32); |
| 45 | pub const KEY_NAME_LENGTH: Self = Self(4); |
| 46 | } |
| 47 | impl From<Const> for u8 { |
| 48 | #[inline ] |
| 49 | fn from(input: Const) -> Self { |
| 50 | input.0 |
| 51 | } |
| 52 | } |
| 53 | impl From<Const> for Option<u8> { |
| 54 | #[inline ] |
| 55 | fn from(input: Const) -> Self { |
| 56 | Some(input.0) |
| 57 | } |
| 58 | } |
| 59 | impl From<Const> for u16 { |
| 60 | #[inline ] |
| 61 | fn from(input: Const) -> Self { |
| 62 | u16::from(input.0) |
| 63 | } |
| 64 | } |
| 65 | impl From<Const> for Option<u16> { |
| 66 | #[inline ] |
| 67 | fn from(input: Const) -> Self { |
| 68 | Some(u16::from(input.0)) |
| 69 | } |
| 70 | } |
| 71 | impl From<Const> for u32 { |
| 72 | #[inline ] |
| 73 | fn from(input: Const) -> Self { |
| 74 | u32::from(input.0) |
| 75 | } |
| 76 | } |
| 77 | impl From<Const> for Option<u32> { |
| 78 | #[inline ] |
| 79 | fn from(input: Const) -> Self { |
| 80 | Some(u32::from(input.0)) |
| 81 | } |
| 82 | } |
| 83 | impl From<u8> for Const { |
| 84 | #[inline ] |
| 85 | fn from(value: u8) -> Self { |
| 86 | Self(value) |
| 87 | } |
| 88 | } |
| 89 | impl core::fmt::Debug for Const { |
| 90 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 91 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 92 | (Self::MAX_LEGAL_KEY_CODE.0.into(), "MAX_LEGAL_KEY_CODE" , "MaxLegalKeyCode" ), |
| 93 | (Self::PER_KEY_BIT_ARRAY_SIZE.0.into(), "PER_KEY_BIT_ARRAY_SIZE" , "PerKeyBitArraySize" ), |
| 94 | (Self::KEY_NAME_LENGTH.0.into(), "KEY_NAME_LENGTH" , "KeyNameLength" ), |
| 95 | ]; |
| 96 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 101 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 102 | pub struct EventType(u16); |
| 103 | impl EventType { |
| 104 | pub const NEW_KEYBOARD_NOTIFY: Self = Self(1 << 0); |
| 105 | pub const MAP_NOTIFY: Self = Self(1 << 1); |
| 106 | pub const STATE_NOTIFY: Self = Self(1 << 2); |
| 107 | pub const CONTROLS_NOTIFY: Self = Self(1 << 3); |
| 108 | pub const INDICATOR_STATE_NOTIFY: Self = Self(1 << 4); |
| 109 | pub const INDICATOR_MAP_NOTIFY: Self = Self(1 << 5); |
| 110 | pub const NAMES_NOTIFY: Self = Self(1 << 6); |
| 111 | pub const COMPAT_MAP_NOTIFY: Self = Self(1 << 7); |
| 112 | pub const BELL_NOTIFY: Self = Self(1 << 8); |
| 113 | pub const ACTION_MESSAGE: Self = Self(1 << 9); |
| 114 | pub const ACCESS_X_NOTIFY: Self = Self(1 << 10); |
| 115 | pub const EXTENSION_DEVICE_NOTIFY: Self = Self(1 << 11); |
| 116 | } |
| 117 | impl From<EventType> for u16 { |
| 118 | #[inline ] |
| 119 | fn from(input: EventType) -> Self { |
| 120 | input.0 |
| 121 | } |
| 122 | } |
| 123 | impl From<EventType> for Option<u16> { |
| 124 | #[inline ] |
| 125 | fn from(input: EventType) -> Self { |
| 126 | Some(input.0) |
| 127 | } |
| 128 | } |
| 129 | impl From<EventType> for u32 { |
| 130 | #[inline ] |
| 131 | fn from(input: EventType) -> Self { |
| 132 | u32::from(input.0) |
| 133 | } |
| 134 | } |
| 135 | impl From<EventType> for Option<u32> { |
| 136 | #[inline ] |
| 137 | fn from(input: EventType) -> Self { |
| 138 | Some(u32::from(input.0)) |
| 139 | } |
| 140 | } |
| 141 | impl From<u8> for EventType { |
| 142 | #[inline ] |
| 143 | fn from(value: u8) -> Self { |
| 144 | Self(value.into()) |
| 145 | } |
| 146 | } |
| 147 | impl From<u16> for EventType { |
| 148 | #[inline ] |
| 149 | fn from(value: u16) -> Self { |
| 150 | Self(value) |
| 151 | } |
| 152 | } |
| 153 | impl core::fmt::Debug for EventType { |
| 154 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 155 | let variants: [(u32, &'static str, &'static …); 12] = [ |
| 156 | (Self::NEW_KEYBOARD_NOTIFY.0.into(), "NEW_KEYBOARD_NOTIFY" , "NewKeyboardNotify" ), |
| 157 | (Self::MAP_NOTIFY.0.into(), "MAP_NOTIFY" , "MapNotify" ), |
| 158 | (Self::STATE_NOTIFY.0.into(), "STATE_NOTIFY" , "StateNotify" ), |
| 159 | (Self::CONTROLS_NOTIFY.0.into(), "CONTROLS_NOTIFY" , "ControlsNotify" ), |
| 160 | (Self::INDICATOR_STATE_NOTIFY.0.into(), "INDICATOR_STATE_NOTIFY" , "IndicatorStateNotify" ), |
| 161 | (Self::INDICATOR_MAP_NOTIFY.0.into(), "INDICATOR_MAP_NOTIFY" , "IndicatorMapNotify" ), |
| 162 | (Self::NAMES_NOTIFY.0.into(), "NAMES_NOTIFY" , "NamesNotify" ), |
| 163 | (Self::COMPAT_MAP_NOTIFY.0.into(), "COMPAT_MAP_NOTIFY" , "CompatMapNotify" ), |
| 164 | (Self::BELL_NOTIFY.0.into(), "BELL_NOTIFY" , "BellNotify" ), |
| 165 | (Self::ACTION_MESSAGE.0.into(), "ACTION_MESSAGE" , "ActionMessage" ), |
| 166 | (Self::ACCESS_X_NOTIFY.0.into(), "ACCESS_X_NOTIFY" , "AccessXNotify" ), |
| 167 | (Self::EXTENSION_DEVICE_NOTIFY.0.into(), "EXTENSION_DEVICE_NOTIFY" , "ExtensionDeviceNotify" ), |
| 168 | ]; |
| 169 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 170 | } |
| 171 | } |
| 172 | bitmask_binop!(EventType, u16); |
| 173 | |
| 174 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 175 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 176 | pub struct NKNDetail(u16); |
| 177 | impl NKNDetail { |
| 178 | pub const KEYCODES: Self = Self(1 << 0); |
| 179 | pub const GEOMETRY: Self = Self(1 << 1); |
| 180 | pub const DEVICE_ID: Self = Self(1 << 2); |
| 181 | } |
| 182 | impl From<NKNDetail> for u16 { |
| 183 | #[inline ] |
| 184 | fn from(input: NKNDetail) -> Self { |
| 185 | input.0 |
| 186 | } |
| 187 | } |
| 188 | impl From<NKNDetail> for Option<u16> { |
| 189 | #[inline ] |
| 190 | fn from(input: NKNDetail) -> Self { |
| 191 | Some(input.0) |
| 192 | } |
| 193 | } |
| 194 | impl From<NKNDetail> for u32 { |
| 195 | #[inline ] |
| 196 | fn from(input: NKNDetail) -> Self { |
| 197 | u32::from(input.0) |
| 198 | } |
| 199 | } |
| 200 | impl From<NKNDetail> for Option<u32> { |
| 201 | #[inline ] |
| 202 | fn from(input: NKNDetail) -> Self { |
| 203 | Some(u32::from(input.0)) |
| 204 | } |
| 205 | } |
| 206 | impl From<u8> for NKNDetail { |
| 207 | #[inline ] |
| 208 | fn from(value: u8) -> Self { |
| 209 | Self(value.into()) |
| 210 | } |
| 211 | } |
| 212 | impl From<u16> for NKNDetail { |
| 213 | #[inline ] |
| 214 | fn from(value: u16) -> Self { |
| 215 | Self(value) |
| 216 | } |
| 217 | } |
| 218 | impl core::fmt::Debug for NKNDetail { |
| 219 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 220 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 221 | (Self::KEYCODES.0.into(), "KEYCODES" , "Keycodes" ), |
| 222 | (Self::GEOMETRY.0.into(), "GEOMETRY" , "Geometry" ), |
| 223 | (Self::DEVICE_ID.0.into(), "DEVICE_ID" , "DeviceID" ), |
| 224 | ]; |
| 225 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 226 | } |
| 227 | } |
| 228 | bitmask_binop!(NKNDetail, u16); |
| 229 | |
| 230 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 231 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 232 | pub struct AXNDetail(u16); |
| 233 | impl AXNDetail { |
| 234 | pub const SK_PRESS: Self = Self(1 << 0); |
| 235 | pub const SK_ACCEPT: Self = Self(1 << 1); |
| 236 | pub const SK_REJECT: Self = Self(1 << 2); |
| 237 | pub const SK_RELEASE: Self = Self(1 << 3); |
| 238 | pub const BK_ACCEPT: Self = Self(1 << 4); |
| 239 | pub const BK_REJECT: Self = Self(1 << 5); |
| 240 | pub const AXK_WARNING: Self = Self(1 << 6); |
| 241 | } |
| 242 | impl From<AXNDetail> for u16 { |
| 243 | #[inline ] |
| 244 | fn from(input: AXNDetail) -> Self { |
| 245 | input.0 |
| 246 | } |
| 247 | } |
| 248 | impl From<AXNDetail> for Option<u16> { |
| 249 | #[inline ] |
| 250 | fn from(input: AXNDetail) -> Self { |
| 251 | Some(input.0) |
| 252 | } |
| 253 | } |
| 254 | impl From<AXNDetail> for u32 { |
| 255 | #[inline ] |
| 256 | fn from(input: AXNDetail) -> Self { |
| 257 | u32::from(input.0) |
| 258 | } |
| 259 | } |
| 260 | impl From<AXNDetail> for Option<u32> { |
| 261 | #[inline ] |
| 262 | fn from(input: AXNDetail) -> Self { |
| 263 | Some(u32::from(input.0)) |
| 264 | } |
| 265 | } |
| 266 | impl From<u8> for AXNDetail { |
| 267 | #[inline ] |
| 268 | fn from(value: u8) -> Self { |
| 269 | Self(value.into()) |
| 270 | } |
| 271 | } |
| 272 | impl From<u16> for AXNDetail { |
| 273 | #[inline ] |
| 274 | fn from(value: u16) -> Self { |
| 275 | Self(value) |
| 276 | } |
| 277 | } |
| 278 | impl core::fmt::Debug for AXNDetail { |
| 279 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 280 | let variants: [(u32, &'static str, &'static …); 7] = [ |
| 281 | (Self::SK_PRESS.0.into(), "SK_PRESS" , "SKPress" ), |
| 282 | (Self::SK_ACCEPT.0.into(), "SK_ACCEPT" , "SKAccept" ), |
| 283 | (Self::SK_REJECT.0.into(), "SK_REJECT" , "SKReject" ), |
| 284 | (Self::SK_RELEASE.0.into(), "SK_RELEASE" , "SKRelease" ), |
| 285 | (Self::BK_ACCEPT.0.into(), "BK_ACCEPT" , "BKAccept" ), |
| 286 | (Self::BK_REJECT.0.into(), "BK_REJECT" , "BKReject" ), |
| 287 | (Self::AXK_WARNING.0.into(), "AXK_WARNING" , "AXKWarning" ), |
| 288 | ]; |
| 289 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 290 | } |
| 291 | } |
| 292 | bitmask_binop!(AXNDetail, u16); |
| 293 | |
| 294 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 295 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 296 | pub struct MapPart(u16); |
| 297 | impl MapPart { |
| 298 | pub const KEY_TYPES: Self = Self(1 << 0); |
| 299 | pub const KEY_SYMS: Self = Self(1 << 1); |
| 300 | pub const MODIFIER_MAP: Self = Self(1 << 2); |
| 301 | pub const EXPLICIT_COMPONENTS: Self = Self(1 << 3); |
| 302 | pub const KEY_ACTIONS: Self = Self(1 << 4); |
| 303 | pub const KEY_BEHAVIORS: Self = Self(1 << 5); |
| 304 | pub const VIRTUAL_MODS: Self = Self(1 << 6); |
| 305 | pub const VIRTUAL_MOD_MAP: Self = Self(1 << 7); |
| 306 | } |
| 307 | impl From<MapPart> for u16 { |
| 308 | #[inline ] |
| 309 | fn from(input: MapPart) -> Self { |
| 310 | input.0 |
| 311 | } |
| 312 | } |
| 313 | impl From<MapPart> for Option<u16> { |
| 314 | #[inline ] |
| 315 | fn from(input: MapPart) -> Self { |
| 316 | Some(input.0) |
| 317 | } |
| 318 | } |
| 319 | impl From<MapPart> for u32 { |
| 320 | #[inline ] |
| 321 | fn from(input: MapPart) -> Self { |
| 322 | u32::from(input.0) |
| 323 | } |
| 324 | } |
| 325 | impl From<MapPart> for Option<u32> { |
| 326 | #[inline ] |
| 327 | fn from(input: MapPart) -> Self { |
| 328 | Some(u32::from(input.0)) |
| 329 | } |
| 330 | } |
| 331 | impl From<u8> for MapPart { |
| 332 | #[inline ] |
| 333 | fn from(value: u8) -> Self { |
| 334 | Self(value.into()) |
| 335 | } |
| 336 | } |
| 337 | impl From<u16> for MapPart { |
| 338 | #[inline ] |
| 339 | fn from(value: u16) -> Self { |
| 340 | Self(value) |
| 341 | } |
| 342 | } |
| 343 | impl core::fmt::Debug for MapPart { |
| 344 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 345 | let variants: [(u32, &'static str, &'static …); 8] = [ |
| 346 | (Self::KEY_TYPES.0.into(), "KEY_TYPES" , "KeyTypes" ), |
| 347 | (Self::KEY_SYMS.0.into(), "KEY_SYMS" , "KeySyms" ), |
| 348 | (Self::MODIFIER_MAP.0.into(), "MODIFIER_MAP" , "ModifierMap" ), |
| 349 | (Self::EXPLICIT_COMPONENTS.0.into(), "EXPLICIT_COMPONENTS" , "ExplicitComponents" ), |
| 350 | (Self::KEY_ACTIONS.0.into(), "KEY_ACTIONS" , "KeyActions" ), |
| 351 | (Self::KEY_BEHAVIORS.0.into(), "KEY_BEHAVIORS" , "KeyBehaviors" ), |
| 352 | (Self::VIRTUAL_MODS.0.into(), "VIRTUAL_MODS" , "VirtualMods" ), |
| 353 | (Self::VIRTUAL_MOD_MAP.0.into(), "VIRTUAL_MOD_MAP" , "VirtualModMap" ), |
| 354 | ]; |
| 355 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 356 | } |
| 357 | } |
| 358 | bitmask_binop!(MapPart, u16); |
| 359 | |
| 360 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 361 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 362 | pub struct SetMapFlags(u16); |
| 363 | impl SetMapFlags { |
| 364 | pub const RESIZE_TYPES: Self = Self(1 << 0); |
| 365 | pub const RECOMPUTE_ACTIONS: Self = Self(1 << 1); |
| 366 | } |
| 367 | impl From<SetMapFlags> for u16 { |
| 368 | #[inline ] |
| 369 | fn from(input: SetMapFlags) -> Self { |
| 370 | input.0 |
| 371 | } |
| 372 | } |
| 373 | impl From<SetMapFlags> for Option<u16> { |
| 374 | #[inline ] |
| 375 | fn from(input: SetMapFlags) -> Self { |
| 376 | Some(input.0) |
| 377 | } |
| 378 | } |
| 379 | impl From<SetMapFlags> for u32 { |
| 380 | #[inline ] |
| 381 | fn from(input: SetMapFlags) -> Self { |
| 382 | u32::from(input.0) |
| 383 | } |
| 384 | } |
| 385 | impl From<SetMapFlags> for Option<u32> { |
| 386 | #[inline ] |
| 387 | fn from(input: SetMapFlags) -> Self { |
| 388 | Some(u32::from(input.0)) |
| 389 | } |
| 390 | } |
| 391 | impl From<u8> for SetMapFlags { |
| 392 | #[inline ] |
| 393 | fn from(value: u8) -> Self { |
| 394 | Self(value.into()) |
| 395 | } |
| 396 | } |
| 397 | impl From<u16> for SetMapFlags { |
| 398 | #[inline ] |
| 399 | fn from(value: u16) -> Self { |
| 400 | Self(value) |
| 401 | } |
| 402 | } |
| 403 | impl core::fmt::Debug for SetMapFlags { |
| 404 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 405 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 406 | (Self::RESIZE_TYPES.0.into(), "RESIZE_TYPES" , "ResizeTypes" ), |
| 407 | (Self::RECOMPUTE_ACTIONS.0.into(), "RECOMPUTE_ACTIONS" , "RecomputeActions" ), |
| 408 | ]; |
| 409 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 410 | } |
| 411 | } |
| 412 | bitmask_binop!(SetMapFlags, u16); |
| 413 | |
| 414 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 415 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 416 | pub struct StatePart(u16); |
| 417 | impl StatePart { |
| 418 | pub const MODIFIER_STATE: Self = Self(1 << 0); |
| 419 | pub const MODIFIER_BASE: Self = Self(1 << 1); |
| 420 | pub const MODIFIER_LATCH: Self = Self(1 << 2); |
| 421 | pub const MODIFIER_LOCK: Self = Self(1 << 3); |
| 422 | pub const GROUP_STATE: Self = Self(1 << 4); |
| 423 | pub const GROUP_BASE: Self = Self(1 << 5); |
| 424 | pub const GROUP_LATCH: Self = Self(1 << 6); |
| 425 | pub const GROUP_LOCK: Self = Self(1 << 7); |
| 426 | pub const COMPAT_STATE: Self = Self(1 << 8); |
| 427 | pub const GRAB_MODS: Self = Self(1 << 9); |
| 428 | pub const COMPAT_GRAB_MODS: Self = Self(1 << 10); |
| 429 | pub const LOOKUP_MODS: Self = Self(1 << 11); |
| 430 | pub const COMPAT_LOOKUP_MODS: Self = Self(1 << 12); |
| 431 | pub const POINTER_BUTTONS: Self = Self(1 << 13); |
| 432 | } |
| 433 | impl From<StatePart> for u16 { |
| 434 | #[inline ] |
| 435 | fn from(input: StatePart) -> Self { |
| 436 | input.0 |
| 437 | } |
| 438 | } |
| 439 | impl From<StatePart> for Option<u16> { |
| 440 | #[inline ] |
| 441 | fn from(input: StatePart) -> Self { |
| 442 | Some(input.0) |
| 443 | } |
| 444 | } |
| 445 | impl From<StatePart> for u32 { |
| 446 | #[inline ] |
| 447 | fn from(input: StatePart) -> Self { |
| 448 | u32::from(input.0) |
| 449 | } |
| 450 | } |
| 451 | impl From<StatePart> for Option<u32> { |
| 452 | #[inline ] |
| 453 | fn from(input: StatePart) -> Self { |
| 454 | Some(u32::from(input.0)) |
| 455 | } |
| 456 | } |
| 457 | impl From<u8> for StatePart { |
| 458 | #[inline ] |
| 459 | fn from(value: u8) -> Self { |
| 460 | Self(value.into()) |
| 461 | } |
| 462 | } |
| 463 | impl From<u16> for StatePart { |
| 464 | #[inline ] |
| 465 | fn from(value: u16) -> Self { |
| 466 | Self(value) |
| 467 | } |
| 468 | } |
| 469 | impl core::fmt::Debug for StatePart { |
| 470 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 471 | let variants: [(u32, &'static str, &'static …); 14] = [ |
| 472 | (Self::MODIFIER_STATE.0.into(), "MODIFIER_STATE" , "ModifierState" ), |
| 473 | (Self::MODIFIER_BASE.0.into(), "MODIFIER_BASE" , "ModifierBase" ), |
| 474 | (Self::MODIFIER_LATCH.0.into(), "MODIFIER_LATCH" , "ModifierLatch" ), |
| 475 | (Self::MODIFIER_LOCK.0.into(), "MODIFIER_LOCK" , "ModifierLock" ), |
| 476 | (Self::GROUP_STATE.0.into(), "GROUP_STATE" , "GroupState" ), |
| 477 | (Self::GROUP_BASE.0.into(), "GROUP_BASE" , "GroupBase" ), |
| 478 | (Self::GROUP_LATCH.0.into(), "GROUP_LATCH" , "GroupLatch" ), |
| 479 | (Self::GROUP_LOCK.0.into(), "GROUP_LOCK" , "GroupLock" ), |
| 480 | (Self::COMPAT_STATE.0.into(), "COMPAT_STATE" , "CompatState" ), |
| 481 | (Self::GRAB_MODS.0.into(), "GRAB_MODS" , "GrabMods" ), |
| 482 | (Self::COMPAT_GRAB_MODS.0.into(), "COMPAT_GRAB_MODS" , "CompatGrabMods" ), |
| 483 | (Self::LOOKUP_MODS.0.into(), "LOOKUP_MODS" , "LookupMods" ), |
| 484 | (Self::COMPAT_LOOKUP_MODS.0.into(), "COMPAT_LOOKUP_MODS" , "CompatLookupMods" ), |
| 485 | (Self::POINTER_BUTTONS.0.into(), "POINTER_BUTTONS" , "PointerButtons" ), |
| 486 | ]; |
| 487 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 488 | } |
| 489 | } |
| 490 | bitmask_binop!(StatePart, u16); |
| 491 | |
| 492 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 493 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 494 | pub struct BoolCtrl(u32); |
| 495 | impl BoolCtrl { |
| 496 | pub const REPEAT_KEYS: Self = Self(1 << 0); |
| 497 | pub const SLOW_KEYS: Self = Self(1 << 1); |
| 498 | pub const BOUNCE_KEYS: Self = Self(1 << 2); |
| 499 | pub const STICKY_KEYS: Self = Self(1 << 3); |
| 500 | pub const MOUSE_KEYS: Self = Self(1 << 4); |
| 501 | pub const MOUSE_KEYS_ACCEL: Self = Self(1 << 5); |
| 502 | pub const ACCESS_X_KEYS: Self = Self(1 << 6); |
| 503 | pub const ACCESS_X_TIMEOUT_MASK: Self = Self(1 << 7); |
| 504 | pub const ACCESS_X_FEEDBACK_MASK: Self = Self(1 << 8); |
| 505 | pub const AUDIBLE_BELL_MASK: Self = Self(1 << 9); |
| 506 | pub const OVERLAY1_MASK: Self = Self(1 << 10); |
| 507 | pub const OVERLAY2_MASK: Self = Self(1 << 11); |
| 508 | pub const IGNORE_GROUP_LOCK_MASK: Self = Self(1 << 12); |
| 509 | } |
| 510 | impl From<BoolCtrl> for u32 { |
| 511 | #[inline ] |
| 512 | fn from(input: BoolCtrl) -> Self { |
| 513 | input.0 |
| 514 | } |
| 515 | } |
| 516 | impl From<BoolCtrl> for Option<u32> { |
| 517 | #[inline ] |
| 518 | fn from(input: BoolCtrl) -> Self { |
| 519 | Some(input.0) |
| 520 | } |
| 521 | } |
| 522 | impl From<u8> for BoolCtrl { |
| 523 | #[inline ] |
| 524 | fn from(value: u8) -> Self { |
| 525 | Self(value.into()) |
| 526 | } |
| 527 | } |
| 528 | impl From<u16> for BoolCtrl { |
| 529 | #[inline ] |
| 530 | fn from(value: u16) -> Self { |
| 531 | Self(value.into()) |
| 532 | } |
| 533 | } |
| 534 | impl From<u32> for BoolCtrl { |
| 535 | #[inline ] |
| 536 | fn from(value: u32) -> Self { |
| 537 | Self(value) |
| 538 | } |
| 539 | } |
| 540 | impl core::fmt::Debug for BoolCtrl { |
| 541 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 542 | let variants: [(u32, &'static str, &'static …); 13] = [ |
| 543 | (Self::REPEAT_KEYS.0, "REPEAT_KEYS" , "RepeatKeys" ), |
| 544 | (Self::SLOW_KEYS.0, "SLOW_KEYS" , "SlowKeys" ), |
| 545 | (Self::BOUNCE_KEYS.0, "BOUNCE_KEYS" , "BounceKeys" ), |
| 546 | (Self::STICKY_KEYS.0, "STICKY_KEYS" , "StickyKeys" ), |
| 547 | (Self::MOUSE_KEYS.0, "MOUSE_KEYS" , "MouseKeys" ), |
| 548 | (Self::MOUSE_KEYS_ACCEL.0, "MOUSE_KEYS_ACCEL" , "MouseKeysAccel" ), |
| 549 | (Self::ACCESS_X_KEYS.0, "ACCESS_X_KEYS" , "AccessXKeys" ), |
| 550 | (Self::ACCESS_X_TIMEOUT_MASK.0, "ACCESS_X_TIMEOUT_MASK" , "AccessXTimeoutMask" ), |
| 551 | (Self::ACCESS_X_FEEDBACK_MASK.0, "ACCESS_X_FEEDBACK_MASK" , "AccessXFeedbackMask" ), |
| 552 | (Self::AUDIBLE_BELL_MASK.0, "AUDIBLE_BELL_MASK" , "AudibleBellMask" ), |
| 553 | (Self::OVERLAY1_MASK.0, "OVERLAY1_MASK" , "Overlay1Mask" ), |
| 554 | (Self::OVERLAY2_MASK.0, "OVERLAY2_MASK" , "Overlay2Mask" ), |
| 555 | (Self::IGNORE_GROUP_LOCK_MASK.0, "IGNORE_GROUP_LOCK_MASK" , "IgnoreGroupLockMask" ), |
| 556 | ]; |
| 557 | pretty_print_bitmask(fmt, self.0, &variants) |
| 558 | } |
| 559 | } |
| 560 | bitmask_binop!(BoolCtrl, u32); |
| 561 | |
| 562 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 563 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 564 | pub struct Control(u32); |
| 565 | impl Control { |
| 566 | pub const GROUPS_WRAP: Self = Self(1 << 27); |
| 567 | pub const INTERNAL_MODS: Self = Self(1 << 28); |
| 568 | pub const IGNORE_LOCK_MODS: Self = Self(1 << 29); |
| 569 | pub const PER_KEY_REPEAT: Self = Self(1 << 30); |
| 570 | pub const CONTROLS_ENABLED: Self = Self(1 << 31); |
| 571 | } |
| 572 | impl From<Control> for u32 { |
| 573 | #[inline ] |
| 574 | fn from(input: Control) -> Self { |
| 575 | input.0 |
| 576 | } |
| 577 | } |
| 578 | impl From<Control> for Option<u32> { |
| 579 | #[inline ] |
| 580 | fn from(input: Control) -> Self { |
| 581 | Some(input.0) |
| 582 | } |
| 583 | } |
| 584 | impl From<u8> for Control { |
| 585 | #[inline ] |
| 586 | fn from(value: u8) -> Self { |
| 587 | Self(value.into()) |
| 588 | } |
| 589 | } |
| 590 | impl From<u16> for Control { |
| 591 | #[inline ] |
| 592 | fn from(value: u16) -> Self { |
| 593 | Self(value.into()) |
| 594 | } |
| 595 | } |
| 596 | impl From<u32> for Control { |
| 597 | #[inline ] |
| 598 | fn from(value: u32) -> Self { |
| 599 | Self(value) |
| 600 | } |
| 601 | } |
| 602 | impl core::fmt::Debug for Control { |
| 603 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 604 | let variants: [(u32, &'static str, &'static …); 5] = [ |
| 605 | (Self::GROUPS_WRAP.0, "GROUPS_WRAP" , "GroupsWrap" ), |
| 606 | (Self::INTERNAL_MODS.0, "INTERNAL_MODS" , "InternalMods" ), |
| 607 | (Self::IGNORE_LOCK_MODS.0, "IGNORE_LOCK_MODS" , "IgnoreLockMods" ), |
| 608 | (Self::PER_KEY_REPEAT.0, "PER_KEY_REPEAT" , "PerKeyRepeat" ), |
| 609 | (Self::CONTROLS_ENABLED.0, "CONTROLS_ENABLED" , "ControlsEnabled" ), |
| 610 | ]; |
| 611 | pretty_print_bitmask(fmt, self.0, &variants) |
| 612 | } |
| 613 | } |
| 614 | bitmask_binop!(Control, u32); |
| 615 | |
| 616 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 617 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 618 | pub struct AXOption(u16); |
| 619 | impl AXOption { |
| 620 | pub const SK_PRESS_FB: Self = Self(1 << 0); |
| 621 | pub const SK_ACCEPT_FB: Self = Self(1 << 1); |
| 622 | pub const FEATURE_FB: Self = Self(1 << 2); |
| 623 | pub const SLOW_WARN_FB: Self = Self(1 << 3); |
| 624 | pub const INDICATOR_FB: Self = Self(1 << 4); |
| 625 | pub const STICKY_KEYS_FB: Self = Self(1 << 5); |
| 626 | pub const TWO_KEYS: Self = Self(1 << 6); |
| 627 | pub const LATCH_TO_LOCK: Self = Self(1 << 7); |
| 628 | pub const SK_RELEASE_FB: Self = Self(1 << 8); |
| 629 | pub const SK_REJECT_FB: Self = Self(1 << 9); |
| 630 | pub const BK_REJECT_FB: Self = Self(1 << 10); |
| 631 | pub const DUMB_BELL: Self = Self(1 << 11); |
| 632 | } |
| 633 | impl From<AXOption> for u16 { |
| 634 | #[inline ] |
| 635 | fn from(input: AXOption) -> Self { |
| 636 | input.0 |
| 637 | } |
| 638 | } |
| 639 | impl From<AXOption> for Option<u16> { |
| 640 | #[inline ] |
| 641 | fn from(input: AXOption) -> Self { |
| 642 | Some(input.0) |
| 643 | } |
| 644 | } |
| 645 | impl From<AXOption> for u32 { |
| 646 | #[inline ] |
| 647 | fn from(input: AXOption) -> Self { |
| 648 | u32::from(input.0) |
| 649 | } |
| 650 | } |
| 651 | impl From<AXOption> for Option<u32> { |
| 652 | #[inline ] |
| 653 | fn from(input: AXOption) -> Self { |
| 654 | Some(u32::from(input.0)) |
| 655 | } |
| 656 | } |
| 657 | impl From<u8> for AXOption { |
| 658 | #[inline ] |
| 659 | fn from(value: u8) -> Self { |
| 660 | Self(value.into()) |
| 661 | } |
| 662 | } |
| 663 | impl From<u16> for AXOption { |
| 664 | #[inline ] |
| 665 | fn from(value: u16) -> Self { |
| 666 | Self(value) |
| 667 | } |
| 668 | } |
| 669 | impl core::fmt::Debug for AXOption { |
| 670 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 671 | let variants: [(u32, &'static str, &'static …); 12] = [ |
| 672 | (Self::SK_PRESS_FB.0.into(), "SK_PRESS_FB" , "SKPressFB" ), |
| 673 | (Self::SK_ACCEPT_FB.0.into(), "SK_ACCEPT_FB" , "SKAcceptFB" ), |
| 674 | (Self::FEATURE_FB.0.into(), "FEATURE_FB" , "FeatureFB" ), |
| 675 | (Self::SLOW_WARN_FB.0.into(), "SLOW_WARN_FB" , "SlowWarnFB" ), |
| 676 | (Self::INDICATOR_FB.0.into(), "INDICATOR_FB" , "IndicatorFB" ), |
| 677 | (Self::STICKY_KEYS_FB.0.into(), "STICKY_KEYS_FB" , "StickyKeysFB" ), |
| 678 | (Self::TWO_KEYS.0.into(), "TWO_KEYS" , "TwoKeys" ), |
| 679 | (Self::LATCH_TO_LOCK.0.into(), "LATCH_TO_LOCK" , "LatchToLock" ), |
| 680 | (Self::SK_RELEASE_FB.0.into(), "SK_RELEASE_FB" , "SKReleaseFB" ), |
| 681 | (Self::SK_REJECT_FB.0.into(), "SK_REJECT_FB" , "SKRejectFB" ), |
| 682 | (Self::BK_REJECT_FB.0.into(), "BK_REJECT_FB" , "BKRejectFB" ), |
| 683 | (Self::DUMB_BELL.0.into(), "DUMB_BELL" , "DumbBell" ), |
| 684 | ]; |
| 685 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 686 | } |
| 687 | } |
| 688 | bitmask_binop!(AXOption, u16); |
| 689 | |
| 690 | pub type DeviceSpec = u16; |
| 691 | |
| 692 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 693 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 694 | pub struct LedClassResult(u16); |
| 695 | impl LedClassResult { |
| 696 | pub const KBD_FEEDBACK_CLASS: Self = Self(0); |
| 697 | pub const LED_FEEDBACK_CLASS: Self = Self(4); |
| 698 | } |
| 699 | impl From<LedClassResult> for u16 { |
| 700 | #[inline ] |
| 701 | fn from(input: LedClassResult) -> Self { |
| 702 | input.0 |
| 703 | } |
| 704 | } |
| 705 | impl From<LedClassResult> for Option<u16> { |
| 706 | #[inline ] |
| 707 | fn from(input: LedClassResult) -> Self { |
| 708 | Some(input.0) |
| 709 | } |
| 710 | } |
| 711 | impl From<LedClassResult> for u32 { |
| 712 | #[inline ] |
| 713 | fn from(input: LedClassResult) -> Self { |
| 714 | u32::from(input.0) |
| 715 | } |
| 716 | } |
| 717 | impl From<LedClassResult> for Option<u32> { |
| 718 | #[inline ] |
| 719 | fn from(input: LedClassResult) -> Self { |
| 720 | Some(u32::from(input.0)) |
| 721 | } |
| 722 | } |
| 723 | impl From<u8> for LedClassResult { |
| 724 | #[inline ] |
| 725 | fn from(value: u8) -> Self { |
| 726 | Self(value.into()) |
| 727 | } |
| 728 | } |
| 729 | impl From<u16> for LedClassResult { |
| 730 | #[inline ] |
| 731 | fn from(value: u16) -> Self { |
| 732 | Self(value) |
| 733 | } |
| 734 | } |
| 735 | impl core::fmt::Debug for LedClassResult { |
| 736 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 737 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 738 | (Self::KBD_FEEDBACK_CLASS.0.into(), "KBD_FEEDBACK_CLASS" , "KbdFeedbackClass" ), |
| 739 | (Self::LED_FEEDBACK_CLASS.0.into(), "LED_FEEDBACK_CLASS" , "LedFeedbackClass" ), |
| 740 | ]; |
| 741 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 746 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 747 | pub struct LedClass(u16); |
| 748 | impl LedClass { |
| 749 | pub const KBD_FEEDBACK_CLASS: Self = Self(0); |
| 750 | pub const LED_FEEDBACK_CLASS: Self = Self(4); |
| 751 | pub const DFLT_XI_CLASS: Self = Self(768); |
| 752 | pub const ALL_XI_CLASSES: Self = Self(1280); |
| 753 | } |
| 754 | impl From<LedClass> for u16 { |
| 755 | #[inline ] |
| 756 | fn from(input: LedClass) -> Self { |
| 757 | input.0 |
| 758 | } |
| 759 | } |
| 760 | impl From<LedClass> for Option<u16> { |
| 761 | #[inline ] |
| 762 | fn from(input: LedClass) -> Self { |
| 763 | Some(input.0) |
| 764 | } |
| 765 | } |
| 766 | impl From<LedClass> for u32 { |
| 767 | #[inline ] |
| 768 | fn from(input: LedClass) -> Self { |
| 769 | u32::from(input.0) |
| 770 | } |
| 771 | } |
| 772 | impl From<LedClass> for Option<u32> { |
| 773 | #[inline ] |
| 774 | fn from(input: LedClass) -> Self { |
| 775 | Some(u32::from(input.0)) |
| 776 | } |
| 777 | } |
| 778 | impl From<u8> for LedClass { |
| 779 | #[inline ] |
| 780 | fn from(value: u8) -> Self { |
| 781 | Self(value.into()) |
| 782 | } |
| 783 | } |
| 784 | impl From<u16> for LedClass { |
| 785 | #[inline ] |
| 786 | fn from(value: u16) -> Self { |
| 787 | Self(value) |
| 788 | } |
| 789 | } |
| 790 | impl core::fmt::Debug for LedClass { |
| 791 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 792 | let variants: [(u32, &'static str, &'static …); 4] = [ |
| 793 | (Self::KBD_FEEDBACK_CLASS.0.into(), "KBD_FEEDBACK_CLASS" , "KbdFeedbackClass" ), |
| 794 | (Self::LED_FEEDBACK_CLASS.0.into(), "LED_FEEDBACK_CLASS" , "LedFeedbackClass" ), |
| 795 | (Self::DFLT_XI_CLASS.0.into(), "DFLT_XI_CLASS" , "DfltXIClass" ), |
| 796 | (Self::ALL_XI_CLASSES.0.into(), "ALL_XI_CLASSES" , "AllXIClasses" ), |
| 797 | ]; |
| 798 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | pub type LedClassSpec = u16; |
| 803 | |
| 804 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 805 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 806 | pub struct BellClassResult(u8); |
| 807 | impl BellClassResult { |
| 808 | pub const KBD_FEEDBACK_CLASS: Self = Self(0); |
| 809 | pub const BELL_FEEDBACK_CLASS: Self = Self(5); |
| 810 | } |
| 811 | impl From<BellClassResult> for u8 { |
| 812 | #[inline ] |
| 813 | fn from(input: BellClassResult) -> Self { |
| 814 | input.0 |
| 815 | } |
| 816 | } |
| 817 | impl From<BellClassResult> for Option<u8> { |
| 818 | #[inline ] |
| 819 | fn from(input: BellClassResult) -> Self { |
| 820 | Some(input.0) |
| 821 | } |
| 822 | } |
| 823 | impl From<BellClassResult> for u16 { |
| 824 | #[inline ] |
| 825 | fn from(input: BellClassResult) -> Self { |
| 826 | u16::from(input.0) |
| 827 | } |
| 828 | } |
| 829 | impl From<BellClassResult> for Option<u16> { |
| 830 | #[inline ] |
| 831 | fn from(input: BellClassResult) -> Self { |
| 832 | Some(u16::from(input.0)) |
| 833 | } |
| 834 | } |
| 835 | impl From<BellClassResult> for u32 { |
| 836 | #[inline ] |
| 837 | fn from(input: BellClassResult) -> Self { |
| 838 | u32::from(input.0) |
| 839 | } |
| 840 | } |
| 841 | impl From<BellClassResult> for Option<u32> { |
| 842 | #[inline ] |
| 843 | fn from(input: BellClassResult) -> Self { |
| 844 | Some(u32::from(input.0)) |
| 845 | } |
| 846 | } |
| 847 | impl From<u8> for BellClassResult { |
| 848 | #[inline ] |
| 849 | fn from(value: u8) -> Self { |
| 850 | Self(value) |
| 851 | } |
| 852 | } |
| 853 | impl core::fmt::Debug for BellClassResult { |
| 854 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 855 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 856 | (Self::KBD_FEEDBACK_CLASS.0.into(), "KBD_FEEDBACK_CLASS" , "KbdFeedbackClass" ), |
| 857 | (Self::BELL_FEEDBACK_CLASS.0.into(), "BELL_FEEDBACK_CLASS" , "BellFeedbackClass" ), |
| 858 | ]; |
| 859 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 864 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 865 | pub struct BellClass(u16); |
| 866 | impl BellClass { |
| 867 | pub const KBD_FEEDBACK_CLASS: Self = Self(0); |
| 868 | pub const BELL_FEEDBACK_CLASS: Self = Self(5); |
| 869 | pub const DFLT_XI_CLASS: Self = Self(768); |
| 870 | } |
| 871 | impl From<BellClass> for u16 { |
| 872 | #[inline ] |
| 873 | fn from(input: BellClass) -> Self { |
| 874 | input.0 |
| 875 | } |
| 876 | } |
| 877 | impl From<BellClass> for Option<u16> { |
| 878 | #[inline ] |
| 879 | fn from(input: BellClass) -> Self { |
| 880 | Some(input.0) |
| 881 | } |
| 882 | } |
| 883 | impl From<BellClass> for u32 { |
| 884 | #[inline ] |
| 885 | fn from(input: BellClass) -> Self { |
| 886 | u32::from(input.0) |
| 887 | } |
| 888 | } |
| 889 | impl From<BellClass> for Option<u32> { |
| 890 | #[inline ] |
| 891 | fn from(input: BellClass) -> Self { |
| 892 | Some(u32::from(input.0)) |
| 893 | } |
| 894 | } |
| 895 | impl From<u8> for BellClass { |
| 896 | #[inline ] |
| 897 | fn from(value: u8) -> Self { |
| 898 | Self(value.into()) |
| 899 | } |
| 900 | } |
| 901 | impl From<u16> for BellClass { |
| 902 | #[inline ] |
| 903 | fn from(value: u16) -> Self { |
| 904 | Self(value) |
| 905 | } |
| 906 | } |
| 907 | impl core::fmt::Debug for BellClass { |
| 908 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 909 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 910 | (Self::KBD_FEEDBACK_CLASS.0.into(), "KBD_FEEDBACK_CLASS" , "KbdFeedbackClass" ), |
| 911 | (Self::BELL_FEEDBACK_CLASS.0.into(), "BELL_FEEDBACK_CLASS" , "BellFeedbackClass" ), |
| 912 | (Self::DFLT_XI_CLASS.0.into(), "DFLT_XI_CLASS" , "DfltXIClass" ), |
| 913 | ]; |
| 914 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | pub type BellClassSpec = u16; |
| 919 | |
| 920 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 921 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 922 | pub struct ID(u16); |
| 923 | impl ID { |
| 924 | pub const USE_CORE_KBD: Self = Self(256); |
| 925 | pub const USE_CORE_PTR: Self = Self(512); |
| 926 | pub const DFLT_XI_CLASS: Self = Self(768); |
| 927 | pub const DFLT_XI_ID: Self = Self(1024); |
| 928 | pub const ALL_XI_CLASS: Self = Self(1280); |
| 929 | pub const ALL_XI_ID: Self = Self(1536); |
| 930 | pub const XI_NONE: Self = Self(65280); |
| 931 | } |
| 932 | impl From<ID> for u16 { |
| 933 | #[inline ] |
| 934 | fn from(input: ID) -> Self { |
| 935 | input.0 |
| 936 | } |
| 937 | } |
| 938 | impl From<ID> for Option<u16> { |
| 939 | #[inline ] |
| 940 | fn from(input: ID) -> Self { |
| 941 | Some(input.0) |
| 942 | } |
| 943 | } |
| 944 | impl From<ID> for u32 { |
| 945 | #[inline ] |
| 946 | fn from(input: ID) -> Self { |
| 947 | u32::from(input.0) |
| 948 | } |
| 949 | } |
| 950 | impl From<ID> for Option<u32> { |
| 951 | #[inline ] |
| 952 | fn from(input: ID) -> Self { |
| 953 | Some(u32::from(input.0)) |
| 954 | } |
| 955 | } |
| 956 | impl From<u8> for ID { |
| 957 | #[inline ] |
| 958 | fn from(value: u8) -> Self { |
| 959 | Self(value.into()) |
| 960 | } |
| 961 | } |
| 962 | impl From<u16> for ID { |
| 963 | #[inline ] |
| 964 | fn from(value: u16) -> Self { |
| 965 | Self(value) |
| 966 | } |
| 967 | } |
| 968 | impl core::fmt::Debug for ID { |
| 969 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 970 | let variants: [(u32, &'static str, &'static …); 7] = [ |
| 971 | (Self::USE_CORE_KBD.0.into(), "USE_CORE_KBD" , "UseCoreKbd" ), |
| 972 | (Self::USE_CORE_PTR.0.into(), "USE_CORE_PTR" , "UseCorePtr" ), |
| 973 | (Self::DFLT_XI_CLASS.0.into(), "DFLT_XI_CLASS" , "DfltXIClass" ), |
| 974 | (Self::DFLT_XI_ID.0.into(), "DFLT_XI_ID" , "DfltXIId" ), |
| 975 | (Self::ALL_XI_CLASS.0.into(), "ALL_XI_CLASS" , "AllXIClass" ), |
| 976 | (Self::ALL_XI_ID.0.into(), "ALL_XI_ID" , "AllXIId" ), |
| 977 | (Self::XI_NONE.0.into(), "XI_NONE" , "XINone" ), |
| 978 | ]; |
| 979 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | pub type IDSpec = u16; |
| 984 | |
| 985 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 986 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 987 | pub struct Group(u8); |
| 988 | impl Group { |
| 989 | pub const M1: Self = Self(0); |
| 990 | pub const M2: Self = Self(1); |
| 991 | pub const M3: Self = Self(2); |
| 992 | pub const M4: Self = Self(3); |
| 993 | } |
| 994 | impl From<Group> for u8 { |
| 995 | #[inline ] |
| 996 | fn from(input: Group) -> Self { |
| 997 | input.0 |
| 998 | } |
| 999 | } |
| 1000 | impl From<Group> for Option<u8> { |
| 1001 | #[inline ] |
| 1002 | fn from(input: Group) -> Self { |
| 1003 | Some(input.0) |
| 1004 | } |
| 1005 | } |
| 1006 | impl From<Group> for u16 { |
| 1007 | #[inline ] |
| 1008 | fn from(input: Group) -> Self { |
| 1009 | u16::from(input.0) |
| 1010 | } |
| 1011 | } |
| 1012 | impl From<Group> for Option<u16> { |
| 1013 | #[inline ] |
| 1014 | fn from(input: Group) -> Self { |
| 1015 | Some(u16::from(input.0)) |
| 1016 | } |
| 1017 | } |
| 1018 | impl From<Group> for u32 { |
| 1019 | #[inline ] |
| 1020 | fn from(input: Group) -> Self { |
| 1021 | u32::from(input.0) |
| 1022 | } |
| 1023 | } |
| 1024 | impl From<Group> for Option<u32> { |
| 1025 | #[inline ] |
| 1026 | fn from(input: Group) -> Self { |
| 1027 | Some(u32::from(input.0)) |
| 1028 | } |
| 1029 | } |
| 1030 | impl From<u8> for Group { |
| 1031 | #[inline ] |
| 1032 | fn from(value: u8) -> Self { |
| 1033 | Self(value) |
| 1034 | } |
| 1035 | } |
| 1036 | impl core::fmt::Debug for Group { |
| 1037 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1038 | let variants: [(u32, &'static str, &'static …); 4] = [ |
| 1039 | (Self::M1.0.into(), "M1" , "M1" ), |
| 1040 | (Self::M2.0.into(), "M2" , "M2" ), |
| 1041 | (Self::M3.0.into(), "M3" , "M3" ), |
| 1042 | (Self::M4.0.into(), "M4" , "M4" ), |
| 1043 | ]; |
| 1044 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1049 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1050 | pub struct Groups(u8); |
| 1051 | impl Groups { |
| 1052 | pub const ANY: Self = Self(254); |
| 1053 | pub const ALL: Self = Self(255); |
| 1054 | } |
| 1055 | impl From<Groups> for u8 { |
| 1056 | #[inline ] |
| 1057 | fn from(input: Groups) -> Self { |
| 1058 | input.0 |
| 1059 | } |
| 1060 | } |
| 1061 | impl From<Groups> for Option<u8> { |
| 1062 | #[inline ] |
| 1063 | fn from(input: Groups) -> Self { |
| 1064 | Some(input.0) |
| 1065 | } |
| 1066 | } |
| 1067 | impl From<Groups> for u16 { |
| 1068 | #[inline ] |
| 1069 | fn from(input: Groups) -> Self { |
| 1070 | u16::from(input.0) |
| 1071 | } |
| 1072 | } |
| 1073 | impl From<Groups> for Option<u16> { |
| 1074 | #[inline ] |
| 1075 | fn from(input: Groups) -> Self { |
| 1076 | Some(u16::from(input.0)) |
| 1077 | } |
| 1078 | } |
| 1079 | impl From<Groups> for u32 { |
| 1080 | #[inline ] |
| 1081 | fn from(input: Groups) -> Self { |
| 1082 | u32::from(input.0) |
| 1083 | } |
| 1084 | } |
| 1085 | impl From<Groups> for Option<u32> { |
| 1086 | #[inline ] |
| 1087 | fn from(input: Groups) -> Self { |
| 1088 | Some(u32::from(input.0)) |
| 1089 | } |
| 1090 | } |
| 1091 | impl From<u8> for Groups { |
| 1092 | #[inline ] |
| 1093 | fn from(value: u8) -> Self { |
| 1094 | Self(value) |
| 1095 | } |
| 1096 | } |
| 1097 | impl core::fmt::Debug for Groups { |
| 1098 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1099 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 1100 | (Self::ANY.0.into(), "ANY" , "Any" ), |
| 1101 | (Self::ALL.0.into(), "ALL" , "All" ), |
| 1102 | ]; |
| 1103 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1108 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1109 | pub struct SetOfGroup(u8); |
| 1110 | impl SetOfGroup { |
| 1111 | pub const GROUP1: Self = Self(1 << 0); |
| 1112 | pub const GROUP2: Self = Self(1 << 1); |
| 1113 | pub const GROUP3: Self = Self(1 << 2); |
| 1114 | pub const GROUP4: Self = Self(1 << 3); |
| 1115 | } |
| 1116 | impl From<SetOfGroup> for u8 { |
| 1117 | #[inline ] |
| 1118 | fn from(input: SetOfGroup) -> Self { |
| 1119 | input.0 |
| 1120 | } |
| 1121 | } |
| 1122 | impl From<SetOfGroup> for Option<u8> { |
| 1123 | #[inline ] |
| 1124 | fn from(input: SetOfGroup) -> Self { |
| 1125 | Some(input.0) |
| 1126 | } |
| 1127 | } |
| 1128 | impl From<SetOfGroup> for u16 { |
| 1129 | #[inline ] |
| 1130 | fn from(input: SetOfGroup) -> Self { |
| 1131 | u16::from(input.0) |
| 1132 | } |
| 1133 | } |
| 1134 | impl From<SetOfGroup> for Option<u16> { |
| 1135 | #[inline ] |
| 1136 | fn from(input: SetOfGroup) -> Self { |
| 1137 | Some(u16::from(input.0)) |
| 1138 | } |
| 1139 | } |
| 1140 | impl From<SetOfGroup> for u32 { |
| 1141 | #[inline ] |
| 1142 | fn from(input: SetOfGroup) -> Self { |
| 1143 | u32::from(input.0) |
| 1144 | } |
| 1145 | } |
| 1146 | impl From<SetOfGroup> for Option<u32> { |
| 1147 | #[inline ] |
| 1148 | fn from(input: SetOfGroup) -> Self { |
| 1149 | Some(u32::from(input.0)) |
| 1150 | } |
| 1151 | } |
| 1152 | impl From<u8> for SetOfGroup { |
| 1153 | #[inline ] |
| 1154 | fn from(value: u8) -> Self { |
| 1155 | Self(value) |
| 1156 | } |
| 1157 | } |
| 1158 | impl core::fmt::Debug for SetOfGroup { |
| 1159 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1160 | let variants: [(u32, &'static str, &'static …); 4] = [ |
| 1161 | (Self::GROUP1.0.into(), "GROUP1" , "Group1" ), |
| 1162 | (Self::GROUP2.0.into(), "GROUP2" , "Group2" ), |
| 1163 | (Self::GROUP3.0.into(), "GROUP3" , "Group3" ), |
| 1164 | (Self::GROUP4.0.into(), "GROUP4" , "Group4" ), |
| 1165 | ]; |
| 1166 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 1167 | } |
| 1168 | } |
| 1169 | bitmask_binop!(SetOfGroup, u8); |
| 1170 | |
| 1171 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1172 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1173 | pub struct SetOfGroups(u8); |
| 1174 | impl SetOfGroups { |
| 1175 | pub const ANY: Self = Self(1 << 7); |
| 1176 | } |
| 1177 | impl From<SetOfGroups> for u8 { |
| 1178 | #[inline ] |
| 1179 | fn from(input: SetOfGroups) -> Self { |
| 1180 | input.0 |
| 1181 | } |
| 1182 | } |
| 1183 | impl From<SetOfGroups> for Option<u8> { |
| 1184 | #[inline ] |
| 1185 | fn from(input: SetOfGroups) -> Self { |
| 1186 | Some(input.0) |
| 1187 | } |
| 1188 | } |
| 1189 | impl From<SetOfGroups> for u16 { |
| 1190 | #[inline ] |
| 1191 | fn from(input: SetOfGroups) -> Self { |
| 1192 | u16::from(input.0) |
| 1193 | } |
| 1194 | } |
| 1195 | impl From<SetOfGroups> for Option<u16> { |
| 1196 | #[inline ] |
| 1197 | fn from(input: SetOfGroups) -> Self { |
| 1198 | Some(u16::from(input.0)) |
| 1199 | } |
| 1200 | } |
| 1201 | impl From<SetOfGroups> for u32 { |
| 1202 | #[inline ] |
| 1203 | fn from(input: SetOfGroups) -> Self { |
| 1204 | u32::from(input.0) |
| 1205 | } |
| 1206 | } |
| 1207 | impl From<SetOfGroups> for Option<u32> { |
| 1208 | #[inline ] |
| 1209 | fn from(input: SetOfGroups) -> Self { |
| 1210 | Some(u32::from(input.0)) |
| 1211 | } |
| 1212 | } |
| 1213 | impl From<u8> for SetOfGroups { |
| 1214 | #[inline ] |
| 1215 | fn from(value: u8) -> Self { |
| 1216 | Self(value) |
| 1217 | } |
| 1218 | } |
| 1219 | impl core::fmt::Debug for SetOfGroups { |
| 1220 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1221 | let variants: [(u32, &'static str, &'static …); 1] = [ |
| 1222 | (Self::ANY.0.into(), "ANY" , "Any" ), |
| 1223 | ]; |
| 1224 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 1225 | } |
| 1226 | } |
| 1227 | bitmask_binop!(SetOfGroups, u8); |
| 1228 | |
| 1229 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1230 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1231 | pub struct GroupsWrap(u8); |
| 1232 | impl GroupsWrap { |
| 1233 | pub const WRAP_INTO_RANGE: Self = Self(0); |
| 1234 | pub const CLAMP_INTO_RANGE: Self = Self(1 << 6); |
| 1235 | pub const REDIRECT_INTO_RANGE: Self = Self(1 << 7); |
| 1236 | } |
| 1237 | impl From<GroupsWrap> for u8 { |
| 1238 | #[inline ] |
| 1239 | fn from(input: GroupsWrap) -> Self { |
| 1240 | input.0 |
| 1241 | } |
| 1242 | } |
| 1243 | impl From<GroupsWrap> for Option<u8> { |
| 1244 | #[inline ] |
| 1245 | fn from(input: GroupsWrap) -> Self { |
| 1246 | Some(input.0) |
| 1247 | } |
| 1248 | } |
| 1249 | impl From<GroupsWrap> for u16 { |
| 1250 | #[inline ] |
| 1251 | fn from(input: GroupsWrap) -> Self { |
| 1252 | u16::from(input.0) |
| 1253 | } |
| 1254 | } |
| 1255 | impl From<GroupsWrap> for Option<u16> { |
| 1256 | #[inline ] |
| 1257 | fn from(input: GroupsWrap) -> Self { |
| 1258 | Some(u16::from(input.0)) |
| 1259 | } |
| 1260 | } |
| 1261 | impl From<GroupsWrap> for u32 { |
| 1262 | #[inline ] |
| 1263 | fn from(input: GroupsWrap) -> Self { |
| 1264 | u32::from(input.0) |
| 1265 | } |
| 1266 | } |
| 1267 | impl From<GroupsWrap> for Option<u32> { |
| 1268 | #[inline ] |
| 1269 | fn from(input: GroupsWrap) -> Self { |
| 1270 | Some(u32::from(input.0)) |
| 1271 | } |
| 1272 | } |
| 1273 | impl From<u8> for GroupsWrap { |
| 1274 | #[inline ] |
| 1275 | fn from(value: u8) -> Self { |
| 1276 | Self(value) |
| 1277 | } |
| 1278 | } |
| 1279 | impl core::fmt::Debug for GroupsWrap { |
| 1280 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1281 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 1282 | (Self::WRAP_INTO_RANGE.0.into(), "WRAP_INTO_RANGE" , "WrapIntoRange" ), |
| 1283 | (Self::CLAMP_INTO_RANGE.0.into(), "CLAMP_INTO_RANGE" , "ClampIntoRange" ), |
| 1284 | (Self::REDIRECT_INTO_RANGE.0.into(), "REDIRECT_INTO_RANGE" , "RedirectIntoRange" ), |
| 1285 | ]; |
| 1286 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 1287 | } |
| 1288 | } |
| 1289 | bitmask_binop!(GroupsWrap, u8); |
| 1290 | |
| 1291 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1292 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1293 | pub struct VModsHigh(u8); |
| 1294 | impl VModsHigh { |
| 1295 | pub const M15: Self = Self(1 << 7); |
| 1296 | pub const M14: Self = Self(1 << 6); |
| 1297 | pub const M13: Self = Self(1 << 5); |
| 1298 | pub const M12: Self = Self(1 << 4); |
| 1299 | pub const M11: Self = Self(1 << 3); |
| 1300 | pub const M10: Self = Self(1 << 2); |
| 1301 | pub const M9: Self = Self(1 << 1); |
| 1302 | pub const M8: Self = Self(1 << 0); |
| 1303 | } |
| 1304 | impl From<VModsHigh> for u8 { |
| 1305 | #[inline ] |
| 1306 | fn from(input: VModsHigh) -> Self { |
| 1307 | input.0 |
| 1308 | } |
| 1309 | } |
| 1310 | impl From<VModsHigh> for Option<u8> { |
| 1311 | #[inline ] |
| 1312 | fn from(input: VModsHigh) -> Self { |
| 1313 | Some(input.0) |
| 1314 | } |
| 1315 | } |
| 1316 | impl From<VModsHigh> for u16 { |
| 1317 | #[inline ] |
| 1318 | fn from(input: VModsHigh) -> Self { |
| 1319 | u16::from(input.0) |
| 1320 | } |
| 1321 | } |
| 1322 | impl From<VModsHigh> for Option<u16> { |
| 1323 | #[inline ] |
| 1324 | fn from(input: VModsHigh) -> Self { |
| 1325 | Some(u16::from(input.0)) |
| 1326 | } |
| 1327 | } |
| 1328 | impl From<VModsHigh> for u32 { |
| 1329 | #[inline ] |
| 1330 | fn from(input: VModsHigh) -> Self { |
| 1331 | u32::from(input.0) |
| 1332 | } |
| 1333 | } |
| 1334 | impl From<VModsHigh> for Option<u32> { |
| 1335 | #[inline ] |
| 1336 | fn from(input: VModsHigh) -> Self { |
| 1337 | Some(u32::from(input.0)) |
| 1338 | } |
| 1339 | } |
| 1340 | impl From<u8> for VModsHigh { |
| 1341 | #[inline ] |
| 1342 | fn from(value: u8) -> Self { |
| 1343 | Self(value) |
| 1344 | } |
| 1345 | } |
| 1346 | impl core::fmt::Debug for VModsHigh { |
| 1347 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1348 | let variants: [(u32, &'static str, &'static …); 8] = [ |
| 1349 | (Self::M15.0.into(), "M15" , "M15" ), |
| 1350 | (Self::M14.0.into(), "M14" , "M14" ), |
| 1351 | (Self::M13.0.into(), "M13" , "M13" ), |
| 1352 | (Self::M12.0.into(), "M12" , "M12" ), |
| 1353 | (Self::M11.0.into(), "M11" , "M11" ), |
| 1354 | (Self::M10.0.into(), "M10" , "M10" ), |
| 1355 | (Self::M9.0.into(), "M9" , "M9" ), |
| 1356 | (Self::M8.0.into(), "M8" , "M8" ), |
| 1357 | ]; |
| 1358 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 1359 | } |
| 1360 | } |
| 1361 | bitmask_binop!(VModsHigh, u8); |
| 1362 | |
| 1363 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1364 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1365 | pub struct VModsLow(u8); |
| 1366 | impl VModsLow { |
| 1367 | pub const M7: Self = Self(1 << 7); |
| 1368 | pub const M6: Self = Self(1 << 6); |
| 1369 | pub const M5: Self = Self(1 << 5); |
| 1370 | pub const M4: Self = Self(1 << 4); |
| 1371 | pub const M3: Self = Self(1 << 3); |
| 1372 | pub const M2: Self = Self(1 << 2); |
| 1373 | pub const M1: Self = Self(1 << 1); |
| 1374 | pub const M0: Self = Self(1 << 0); |
| 1375 | } |
| 1376 | impl From<VModsLow> for u8 { |
| 1377 | #[inline ] |
| 1378 | fn from(input: VModsLow) -> Self { |
| 1379 | input.0 |
| 1380 | } |
| 1381 | } |
| 1382 | impl From<VModsLow> for Option<u8> { |
| 1383 | #[inline ] |
| 1384 | fn from(input: VModsLow) -> Self { |
| 1385 | Some(input.0) |
| 1386 | } |
| 1387 | } |
| 1388 | impl From<VModsLow> for u16 { |
| 1389 | #[inline ] |
| 1390 | fn from(input: VModsLow) -> Self { |
| 1391 | u16::from(input.0) |
| 1392 | } |
| 1393 | } |
| 1394 | impl From<VModsLow> for Option<u16> { |
| 1395 | #[inline ] |
| 1396 | fn from(input: VModsLow) -> Self { |
| 1397 | Some(u16::from(input.0)) |
| 1398 | } |
| 1399 | } |
| 1400 | impl From<VModsLow> for u32 { |
| 1401 | #[inline ] |
| 1402 | fn from(input: VModsLow) -> Self { |
| 1403 | u32::from(input.0) |
| 1404 | } |
| 1405 | } |
| 1406 | impl From<VModsLow> for Option<u32> { |
| 1407 | #[inline ] |
| 1408 | fn from(input: VModsLow) -> Self { |
| 1409 | Some(u32::from(input.0)) |
| 1410 | } |
| 1411 | } |
| 1412 | impl From<u8> for VModsLow { |
| 1413 | #[inline ] |
| 1414 | fn from(value: u8) -> Self { |
| 1415 | Self(value) |
| 1416 | } |
| 1417 | } |
| 1418 | impl core::fmt::Debug for VModsLow { |
| 1419 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1420 | let variants: [(u32, &'static str, &'static …); 8] = [ |
| 1421 | (Self::M7.0.into(), "M7" , "M7" ), |
| 1422 | (Self::M6.0.into(), "M6" , "M6" ), |
| 1423 | (Self::M5.0.into(), "M5" , "M5" ), |
| 1424 | (Self::M4.0.into(), "M4" , "M4" ), |
| 1425 | (Self::M3.0.into(), "M3" , "M3" ), |
| 1426 | (Self::M2.0.into(), "M2" , "M2" ), |
| 1427 | (Self::M1.0.into(), "M1" , "M1" ), |
| 1428 | (Self::M0.0.into(), "M0" , "M0" ), |
| 1429 | ]; |
| 1430 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 1431 | } |
| 1432 | } |
| 1433 | bitmask_binop!(VModsLow, u8); |
| 1434 | |
| 1435 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1436 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1437 | pub struct VMod(u16); |
| 1438 | impl VMod { |
| 1439 | pub const M15: Self = Self(1 << 15); |
| 1440 | pub const M14: Self = Self(1 << 14); |
| 1441 | pub const M13: Self = Self(1 << 13); |
| 1442 | pub const M12: Self = Self(1 << 12); |
| 1443 | pub const M11: Self = Self(1 << 11); |
| 1444 | pub const M10: Self = Self(1 << 10); |
| 1445 | pub const M9: Self = Self(1 << 9); |
| 1446 | pub const M8: Self = Self(1 << 8); |
| 1447 | pub const M7: Self = Self(1 << 7); |
| 1448 | pub const M6: Self = Self(1 << 6); |
| 1449 | pub const M5: Self = Self(1 << 5); |
| 1450 | pub const M4: Self = Self(1 << 4); |
| 1451 | pub const M3: Self = Self(1 << 3); |
| 1452 | pub const M2: Self = Self(1 << 2); |
| 1453 | pub const M1: Self = Self(1 << 1); |
| 1454 | pub const M0: Self = Self(1 << 0); |
| 1455 | } |
| 1456 | impl From<VMod> for u16 { |
| 1457 | #[inline ] |
| 1458 | fn from(input: VMod) -> Self { |
| 1459 | input.0 |
| 1460 | } |
| 1461 | } |
| 1462 | impl From<VMod> for Option<u16> { |
| 1463 | #[inline ] |
| 1464 | fn from(input: VMod) -> Self { |
| 1465 | Some(input.0) |
| 1466 | } |
| 1467 | } |
| 1468 | impl From<VMod> for u32 { |
| 1469 | #[inline ] |
| 1470 | fn from(input: VMod) -> Self { |
| 1471 | u32::from(input.0) |
| 1472 | } |
| 1473 | } |
| 1474 | impl From<VMod> for Option<u32> { |
| 1475 | #[inline ] |
| 1476 | fn from(input: VMod) -> Self { |
| 1477 | Some(u32::from(input.0)) |
| 1478 | } |
| 1479 | } |
| 1480 | impl From<u8> for VMod { |
| 1481 | #[inline ] |
| 1482 | fn from(value: u8) -> Self { |
| 1483 | Self(value.into()) |
| 1484 | } |
| 1485 | } |
| 1486 | impl From<u16> for VMod { |
| 1487 | #[inline ] |
| 1488 | fn from(value: u16) -> Self { |
| 1489 | Self(value) |
| 1490 | } |
| 1491 | } |
| 1492 | impl core::fmt::Debug for VMod { |
| 1493 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1494 | let variants: [(u32, &'static str, &'static …); 16] = [ |
| 1495 | (Self::M15.0.into(), "M15" , "M15" ), |
| 1496 | (Self::M14.0.into(), "M14" , "M14" ), |
| 1497 | (Self::M13.0.into(), "M13" , "M13" ), |
| 1498 | (Self::M12.0.into(), "M12" , "M12" ), |
| 1499 | (Self::M11.0.into(), "M11" , "M11" ), |
| 1500 | (Self::M10.0.into(), "M10" , "M10" ), |
| 1501 | (Self::M9.0.into(), "M9" , "M9" ), |
| 1502 | (Self::M8.0.into(), "M8" , "M8" ), |
| 1503 | (Self::M7.0.into(), "M7" , "M7" ), |
| 1504 | (Self::M6.0.into(), "M6" , "M6" ), |
| 1505 | (Self::M5.0.into(), "M5" , "M5" ), |
| 1506 | (Self::M4.0.into(), "M4" , "M4" ), |
| 1507 | (Self::M3.0.into(), "M3" , "M3" ), |
| 1508 | (Self::M2.0.into(), "M2" , "M2" ), |
| 1509 | (Self::M1.0.into(), "M1" , "M1" ), |
| 1510 | (Self::M0.0.into(), "M0" , "M0" ), |
| 1511 | ]; |
| 1512 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 1513 | } |
| 1514 | } |
| 1515 | bitmask_binop!(VMod, u16); |
| 1516 | |
| 1517 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1518 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1519 | pub struct Explicit(u8); |
| 1520 | impl Explicit { |
| 1521 | pub const V_MOD_MAP: Self = Self(1 << 7); |
| 1522 | pub const BEHAVIOR: Self = Self(1 << 6); |
| 1523 | pub const AUTO_REPEAT: Self = Self(1 << 5); |
| 1524 | pub const INTERPRET: Self = Self(1 << 4); |
| 1525 | pub const KEY_TYPE4: Self = Self(1 << 3); |
| 1526 | pub const KEY_TYPE3: Self = Self(1 << 2); |
| 1527 | pub const KEY_TYPE2: Self = Self(1 << 1); |
| 1528 | pub const KEY_TYPE1: Self = Self(1 << 0); |
| 1529 | } |
| 1530 | impl From<Explicit> for u8 { |
| 1531 | #[inline ] |
| 1532 | fn from(input: Explicit) -> Self { |
| 1533 | input.0 |
| 1534 | } |
| 1535 | } |
| 1536 | impl From<Explicit> for Option<u8> { |
| 1537 | #[inline ] |
| 1538 | fn from(input: Explicit) -> Self { |
| 1539 | Some(input.0) |
| 1540 | } |
| 1541 | } |
| 1542 | impl From<Explicit> for u16 { |
| 1543 | #[inline ] |
| 1544 | fn from(input: Explicit) -> Self { |
| 1545 | u16::from(input.0) |
| 1546 | } |
| 1547 | } |
| 1548 | impl From<Explicit> for Option<u16> { |
| 1549 | #[inline ] |
| 1550 | fn from(input: Explicit) -> Self { |
| 1551 | Some(u16::from(input.0)) |
| 1552 | } |
| 1553 | } |
| 1554 | impl From<Explicit> for u32 { |
| 1555 | #[inline ] |
| 1556 | fn from(input: Explicit) -> Self { |
| 1557 | u32::from(input.0) |
| 1558 | } |
| 1559 | } |
| 1560 | impl From<Explicit> for Option<u32> { |
| 1561 | #[inline ] |
| 1562 | fn from(input: Explicit) -> Self { |
| 1563 | Some(u32::from(input.0)) |
| 1564 | } |
| 1565 | } |
| 1566 | impl From<u8> for Explicit { |
| 1567 | #[inline ] |
| 1568 | fn from(value: u8) -> Self { |
| 1569 | Self(value) |
| 1570 | } |
| 1571 | } |
| 1572 | impl core::fmt::Debug for Explicit { |
| 1573 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1574 | let variants: [(u32, &'static str, &'static …); 8] = [ |
| 1575 | (Self::V_MOD_MAP.0.into(), "V_MOD_MAP" , "VModMap" ), |
| 1576 | (Self::BEHAVIOR.0.into(), "BEHAVIOR" , "Behavior" ), |
| 1577 | (Self::AUTO_REPEAT.0.into(), "AUTO_REPEAT" , "AutoRepeat" ), |
| 1578 | (Self::INTERPRET.0.into(), "INTERPRET" , "Interpret" ), |
| 1579 | (Self::KEY_TYPE4.0.into(), "KEY_TYPE4" , "KeyType4" ), |
| 1580 | (Self::KEY_TYPE3.0.into(), "KEY_TYPE3" , "KeyType3" ), |
| 1581 | (Self::KEY_TYPE2.0.into(), "KEY_TYPE2" , "KeyType2" ), |
| 1582 | (Self::KEY_TYPE1.0.into(), "KEY_TYPE1" , "KeyType1" ), |
| 1583 | ]; |
| 1584 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 1585 | } |
| 1586 | } |
| 1587 | bitmask_binop!(Explicit, u8); |
| 1588 | |
| 1589 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1590 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1591 | pub struct SymInterpretMatch(u8); |
| 1592 | impl SymInterpretMatch { |
| 1593 | pub const NONE_OF: Self = Self(0); |
| 1594 | pub const ANY_OF_OR_NONE: Self = Self(1); |
| 1595 | pub const ANY_OF: Self = Self(2); |
| 1596 | pub const ALL_OF: Self = Self(3); |
| 1597 | pub const EXACTLY: Self = Self(4); |
| 1598 | } |
| 1599 | impl From<SymInterpretMatch> for u8 { |
| 1600 | #[inline ] |
| 1601 | fn from(input: SymInterpretMatch) -> Self { |
| 1602 | input.0 |
| 1603 | } |
| 1604 | } |
| 1605 | impl From<SymInterpretMatch> for Option<u8> { |
| 1606 | #[inline ] |
| 1607 | fn from(input: SymInterpretMatch) -> Self { |
| 1608 | Some(input.0) |
| 1609 | } |
| 1610 | } |
| 1611 | impl From<SymInterpretMatch> for u16 { |
| 1612 | #[inline ] |
| 1613 | fn from(input: SymInterpretMatch) -> Self { |
| 1614 | u16::from(input.0) |
| 1615 | } |
| 1616 | } |
| 1617 | impl From<SymInterpretMatch> for Option<u16> { |
| 1618 | #[inline ] |
| 1619 | fn from(input: SymInterpretMatch) -> Self { |
| 1620 | Some(u16::from(input.0)) |
| 1621 | } |
| 1622 | } |
| 1623 | impl From<SymInterpretMatch> for u32 { |
| 1624 | #[inline ] |
| 1625 | fn from(input: SymInterpretMatch) -> Self { |
| 1626 | u32::from(input.0) |
| 1627 | } |
| 1628 | } |
| 1629 | impl From<SymInterpretMatch> for Option<u32> { |
| 1630 | #[inline ] |
| 1631 | fn from(input: SymInterpretMatch) -> Self { |
| 1632 | Some(u32::from(input.0)) |
| 1633 | } |
| 1634 | } |
| 1635 | impl From<u8> for SymInterpretMatch { |
| 1636 | #[inline ] |
| 1637 | fn from(value: u8) -> Self { |
| 1638 | Self(value) |
| 1639 | } |
| 1640 | } |
| 1641 | impl core::fmt::Debug for SymInterpretMatch { |
| 1642 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1643 | let variants: [(u32, &'static str, &'static …); 5] = [ |
| 1644 | (Self::NONE_OF.0.into(), "NONE_OF" , "NoneOf" ), |
| 1645 | (Self::ANY_OF_OR_NONE.0.into(), "ANY_OF_OR_NONE" , "AnyOfOrNone" ), |
| 1646 | (Self::ANY_OF.0.into(), "ANY_OF" , "AnyOf" ), |
| 1647 | (Self::ALL_OF.0.into(), "ALL_OF" , "AllOf" ), |
| 1648 | (Self::EXACTLY.0.into(), "EXACTLY" , "Exactly" ), |
| 1649 | ]; |
| 1650 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 1651 | } |
| 1652 | } |
| 1653 | |
| 1654 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1655 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 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 ] |
| 1663 | fn from(input: SymInterpMatch) -> Self { |
| 1664 | input.0 |
| 1665 | } |
| 1666 | } |
| 1667 | impl From<SymInterpMatch> for Option<u8> { |
| 1668 | #[inline ] |
| 1669 | fn from(input: SymInterpMatch) -> Self { |
| 1670 | Some(input.0) |
| 1671 | } |
| 1672 | } |
| 1673 | impl From<SymInterpMatch> for u16 { |
| 1674 | #[inline ] |
| 1675 | fn from(input: SymInterpMatch) -> Self { |
| 1676 | u16::from(input.0) |
| 1677 | } |
| 1678 | } |
| 1679 | impl From<SymInterpMatch> for Option<u16> { |
| 1680 | #[inline ] |
| 1681 | fn from(input: SymInterpMatch) -> Self { |
| 1682 | Some(u16::from(input.0)) |
| 1683 | } |
| 1684 | } |
| 1685 | impl From<SymInterpMatch> for u32 { |
| 1686 | #[inline ] |
| 1687 | fn from(input: SymInterpMatch) -> Self { |
| 1688 | u32::from(input.0) |
| 1689 | } |
| 1690 | } |
| 1691 | impl From<SymInterpMatch> for Option<u32> { |
| 1692 | #[inline ] |
| 1693 | fn from(input: SymInterpMatch) -> Self { |
| 1694 | Some(u32::from(input.0)) |
| 1695 | } |
| 1696 | } |
| 1697 | impl From<u8> for SymInterpMatch { |
| 1698 | #[inline ] |
| 1699 | fn from(value: u8) -> Self { |
| 1700 | Self(value) |
| 1701 | } |
| 1702 | } |
| 1703 | impl core::fmt::Debug for SymInterpMatch { |
| 1704 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1705 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 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, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1714 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1715 | pub struct IMFlag(u8); |
| 1716 | impl IMFlag { |
| 1717 | pub const NO_EXPLICIT: Self = Self(1 << 7); |
| 1718 | pub const NO_AUTOMATIC: Self = Self(1 << 6); |
| 1719 | pub const LED_DRIVES_KB: Self = Self(1 << 5); |
| 1720 | } |
| 1721 | impl From<IMFlag> for u8 { |
| 1722 | #[inline ] |
| 1723 | fn from(input: IMFlag) -> Self { |
| 1724 | input.0 |
| 1725 | } |
| 1726 | } |
| 1727 | impl From<IMFlag> for Option<u8> { |
| 1728 | #[inline ] |
| 1729 | fn from(input: IMFlag) -> Self { |
| 1730 | Some(input.0) |
| 1731 | } |
| 1732 | } |
| 1733 | impl From<IMFlag> for u16 { |
| 1734 | #[inline ] |
| 1735 | fn from(input: IMFlag) -> Self { |
| 1736 | u16::from(input.0) |
| 1737 | } |
| 1738 | } |
| 1739 | impl From<IMFlag> for Option<u16> { |
| 1740 | #[inline ] |
| 1741 | fn from(input: IMFlag) -> Self { |
| 1742 | Some(u16::from(input.0)) |
| 1743 | } |
| 1744 | } |
| 1745 | impl From<IMFlag> for u32 { |
| 1746 | #[inline ] |
| 1747 | fn from(input: IMFlag) -> Self { |
| 1748 | u32::from(input.0) |
| 1749 | } |
| 1750 | } |
| 1751 | impl From<IMFlag> for Option<u32> { |
| 1752 | #[inline ] |
| 1753 | fn from(input: IMFlag) -> Self { |
| 1754 | Some(u32::from(input.0)) |
| 1755 | } |
| 1756 | } |
| 1757 | impl From<u8> for IMFlag { |
| 1758 | #[inline ] |
| 1759 | fn from(value: u8) -> Self { |
| 1760 | Self(value) |
| 1761 | } |
| 1762 | } |
| 1763 | impl core::fmt::Debug for IMFlag { |
| 1764 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1765 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 1766 | (Self::NO_EXPLICIT.0.into(), "NO_EXPLICIT" , "NoExplicit" ), |
| 1767 | (Self::NO_AUTOMATIC.0.into(), "NO_AUTOMATIC" , "NoAutomatic" ), |
| 1768 | (Self::LED_DRIVES_KB.0.into(), "LED_DRIVES_KB" , "LEDDrivesKB" ), |
| 1769 | ]; |
| 1770 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 1771 | } |
| 1772 | } |
| 1773 | bitmask_binop!(IMFlag, u8); |
| 1774 | |
| 1775 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1776 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1777 | pub struct IMModsWhich(u8); |
| 1778 | impl IMModsWhich { |
| 1779 | pub const USE_COMPAT: Self = Self(1 << 4); |
| 1780 | pub const USE_EFFECTIVE: Self = Self(1 << 3); |
| 1781 | pub const USE_LOCKED: Self = Self(1 << 2); |
| 1782 | pub const USE_LATCHED: Self = Self(1 << 1); |
| 1783 | pub const USE_BASE: Self = Self(1 << 0); |
| 1784 | } |
| 1785 | impl From<IMModsWhich> for u8 { |
| 1786 | #[inline ] |
| 1787 | fn from(input: IMModsWhich) -> Self { |
| 1788 | input.0 |
| 1789 | } |
| 1790 | } |
| 1791 | impl From<IMModsWhich> for Option<u8> { |
| 1792 | #[inline ] |
| 1793 | fn from(input: IMModsWhich) -> Self { |
| 1794 | Some(input.0) |
| 1795 | } |
| 1796 | } |
| 1797 | impl From<IMModsWhich> for u16 { |
| 1798 | #[inline ] |
| 1799 | fn from(input: IMModsWhich) -> Self { |
| 1800 | u16::from(input.0) |
| 1801 | } |
| 1802 | } |
| 1803 | impl From<IMModsWhich> for Option<u16> { |
| 1804 | #[inline ] |
| 1805 | fn from(input: IMModsWhich) -> Self { |
| 1806 | Some(u16::from(input.0)) |
| 1807 | } |
| 1808 | } |
| 1809 | impl From<IMModsWhich> for u32 { |
| 1810 | #[inline ] |
| 1811 | fn from(input: IMModsWhich) -> Self { |
| 1812 | u32::from(input.0) |
| 1813 | } |
| 1814 | } |
| 1815 | impl From<IMModsWhich> for Option<u32> { |
| 1816 | #[inline ] |
| 1817 | fn from(input: IMModsWhich) -> Self { |
| 1818 | Some(u32::from(input.0)) |
| 1819 | } |
| 1820 | } |
| 1821 | impl From<u8> for IMModsWhich { |
| 1822 | #[inline ] |
| 1823 | fn from(value: u8) -> Self { |
| 1824 | Self(value) |
| 1825 | } |
| 1826 | } |
| 1827 | impl core::fmt::Debug for IMModsWhich { |
| 1828 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1829 | let variants: [(u32, &'static str, &'static …); 5] = [ |
| 1830 | (Self::USE_COMPAT.0.into(), "USE_COMPAT" , "UseCompat" ), |
| 1831 | (Self::USE_EFFECTIVE.0.into(), "USE_EFFECTIVE" , "UseEffective" ), |
| 1832 | (Self::USE_LOCKED.0.into(), "USE_LOCKED" , "UseLocked" ), |
| 1833 | (Self::USE_LATCHED.0.into(), "USE_LATCHED" , "UseLatched" ), |
| 1834 | (Self::USE_BASE.0.into(), "USE_BASE" , "UseBase" ), |
| 1835 | ]; |
| 1836 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 1837 | } |
| 1838 | } |
| 1839 | bitmask_binop!(IMModsWhich, u8); |
| 1840 | |
| 1841 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1842 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1843 | pub struct IMGroupsWhich(u8); |
| 1844 | impl IMGroupsWhich { |
| 1845 | pub const USE_COMPAT: Self = Self(1 << 4); |
| 1846 | pub const USE_EFFECTIVE: Self = Self(1 << 3); |
| 1847 | pub const USE_LOCKED: Self = Self(1 << 2); |
| 1848 | pub const USE_LATCHED: Self = Self(1 << 1); |
| 1849 | pub const USE_BASE: Self = Self(1 << 0); |
| 1850 | } |
| 1851 | impl From<IMGroupsWhich> for u8 { |
| 1852 | #[inline ] |
| 1853 | fn from(input: IMGroupsWhich) -> Self { |
| 1854 | input.0 |
| 1855 | } |
| 1856 | } |
| 1857 | impl From<IMGroupsWhich> for Option<u8> { |
| 1858 | #[inline ] |
| 1859 | fn from(input: IMGroupsWhich) -> Self { |
| 1860 | Some(input.0) |
| 1861 | } |
| 1862 | } |
| 1863 | impl From<IMGroupsWhich> for u16 { |
| 1864 | #[inline ] |
| 1865 | fn from(input: IMGroupsWhich) -> Self { |
| 1866 | u16::from(input.0) |
| 1867 | } |
| 1868 | } |
| 1869 | impl From<IMGroupsWhich> for Option<u16> { |
| 1870 | #[inline ] |
| 1871 | fn from(input: IMGroupsWhich) -> Self { |
| 1872 | Some(u16::from(input.0)) |
| 1873 | } |
| 1874 | } |
| 1875 | impl From<IMGroupsWhich> for u32 { |
| 1876 | #[inline ] |
| 1877 | fn from(input: IMGroupsWhich) -> Self { |
| 1878 | u32::from(input.0) |
| 1879 | } |
| 1880 | } |
| 1881 | impl From<IMGroupsWhich> for Option<u32> { |
| 1882 | #[inline ] |
| 1883 | fn from(input: IMGroupsWhich) -> Self { |
| 1884 | Some(u32::from(input.0)) |
| 1885 | } |
| 1886 | } |
| 1887 | impl From<u8> for IMGroupsWhich { |
| 1888 | #[inline ] |
| 1889 | fn from(value: u8) -> Self { |
| 1890 | Self(value) |
| 1891 | } |
| 1892 | } |
| 1893 | impl core::fmt::Debug for IMGroupsWhich { |
| 1894 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 1895 | let variants: [(u32, &'static str, &'static …); 5] = [ |
| 1896 | (Self::USE_COMPAT.0.into(), "USE_COMPAT" , "UseCompat" ), |
| 1897 | (Self::USE_EFFECTIVE.0.into(), "USE_EFFECTIVE" , "UseEffective" ), |
| 1898 | (Self::USE_LOCKED.0.into(), "USE_LOCKED" , "UseLocked" ), |
| 1899 | (Self::USE_LATCHED.0.into(), "USE_LATCHED" , "UseLatched" ), |
| 1900 | (Self::USE_BASE.0.into(), "USE_BASE" , "UseBase" ), |
| 1901 | ]; |
| 1902 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 1903 | } |
| 1904 | } |
| 1905 | bitmask_binop!(IMGroupsWhich, u8); |
| 1906 | |
| 1907 | #[derive (Clone, Copy, Default)] |
| 1908 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 1909 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1910 | pub struct IndicatorMap { |
| 1911 | pub flags: IMFlag, |
| 1912 | pub which_groups: IMGroupsWhich, |
| 1913 | pub groups: SetOfGroup, |
| 1914 | pub which_mods: IMModsWhich, |
| 1915 | pub mods: xproto::ModMask, |
| 1916 | pub real_mods: xproto::ModMask, |
| 1917 | pub vmods: VMod, |
| 1918 | pub ctrls: BoolCtrl, |
| 1919 | } |
| 1920 | impl_debug_if_no_extra_traits!(IndicatorMap, "IndicatorMap" ); |
| 1921 | impl TryParse for IndicatorMap { |
| 1922 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 1923 | let (flags: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 1924 | let (which_groups: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 1925 | let (groups: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 1926 | let (which_mods: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 1927 | let (mods: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 1928 | let (real_mods: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 1929 | let (vmods: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 1930 | let (ctrls: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 1931 | let flags: IMFlag = flags.into(); |
| 1932 | let which_groups: IMGroupsWhich = which_groups.into(); |
| 1933 | let groups: SetOfGroup = groups.into(); |
| 1934 | let which_mods: IMModsWhich = which_mods.into(); |
| 1935 | let mods: ModMask = mods.into(); |
| 1936 | let real_mods: ModMask = real_mods.into(); |
| 1937 | let vmods: VMod = vmods.into(); |
| 1938 | let ctrls: BoolCtrl = ctrls.into(); |
| 1939 | let result: IndicatorMap = IndicatorMap { flags, which_groups, groups, which_mods, mods, real_mods, vmods, ctrls }; |
| 1940 | Ok((result, remaining)) |
| 1941 | } |
| 1942 | } |
| 1943 | impl Serialize for IndicatorMap { |
| 1944 | type Bytes = [u8; 12]; |
| 1945 | fn serialize(&self) -> [u8; 12] { |
| 1946 | let flags_bytes = u8::from(self.flags).serialize(); |
| 1947 | let which_groups_bytes = u8::from(self.which_groups).serialize(); |
| 1948 | let groups_bytes = u8::from(self.groups).serialize(); |
| 1949 | let which_mods_bytes = u8::from(self.which_mods).serialize(); |
| 1950 | let mods_bytes = (u16::from(self.mods) as u8).serialize(); |
| 1951 | let real_mods_bytes = (u16::from(self.real_mods) as u8).serialize(); |
| 1952 | let vmods_bytes = u16::from(self.vmods).serialize(); |
| 1953 | let ctrls_bytes = u32::from(self.ctrls).serialize(); |
| 1954 | [ |
| 1955 | flags_bytes[0], |
| 1956 | which_groups_bytes[0], |
| 1957 | groups_bytes[0], |
| 1958 | which_mods_bytes[0], |
| 1959 | mods_bytes[0], |
| 1960 | real_mods_bytes[0], |
| 1961 | vmods_bytes[0], |
| 1962 | vmods_bytes[1], |
| 1963 | ctrls_bytes[0], |
| 1964 | ctrls_bytes[1], |
| 1965 | ctrls_bytes[2], |
| 1966 | ctrls_bytes[3], |
| 1967 | ] |
| 1968 | } |
| 1969 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 1970 | bytes.reserve(12); |
| 1971 | u8::from(self.flags).serialize_into(bytes); |
| 1972 | u8::from(self.which_groups).serialize_into(bytes); |
| 1973 | u8::from(self.groups).serialize_into(bytes); |
| 1974 | u8::from(self.which_mods).serialize_into(bytes); |
| 1975 | (u16::from(self.mods) as u8).serialize_into(bytes); |
| 1976 | (u16::from(self.real_mods) as u8).serialize_into(bytes); |
| 1977 | u16::from(self.vmods).serialize_into(bytes); |
| 1978 | u32::from(self.ctrls).serialize_into(bytes); |
| 1979 | } |
| 1980 | } |
| 1981 | |
| 1982 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 1983 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 1984 | pub struct CMDetail(u8); |
| 1985 | impl CMDetail { |
| 1986 | pub const SYM_INTERP: Self = Self(1 << 0); |
| 1987 | pub const GROUP_COMPAT: Self = Self(1 << 1); |
| 1988 | } |
| 1989 | impl From<CMDetail> for u8 { |
| 1990 | #[inline ] |
| 1991 | fn from(input: CMDetail) -> Self { |
| 1992 | input.0 |
| 1993 | } |
| 1994 | } |
| 1995 | impl From<CMDetail> for Option<u8> { |
| 1996 | #[inline ] |
| 1997 | fn from(input: CMDetail) -> Self { |
| 1998 | Some(input.0) |
| 1999 | } |
| 2000 | } |
| 2001 | impl From<CMDetail> for u16 { |
| 2002 | #[inline ] |
| 2003 | fn from(input: CMDetail) -> Self { |
| 2004 | u16::from(input.0) |
| 2005 | } |
| 2006 | } |
| 2007 | impl From<CMDetail> for Option<u16> { |
| 2008 | #[inline ] |
| 2009 | fn from(input: CMDetail) -> Self { |
| 2010 | Some(u16::from(input.0)) |
| 2011 | } |
| 2012 | } |
| 2013 | impl From<CMDetail> for u32 { |
| 2014 | #[inline ] |
| 2015 | fn from(input: CMDetail) -> Self { |
| 2016 | u32::from(input.0) |
| 2017 | } |
| 2018 | } |
| 2019 | impl From<CMDetail> for Option<u32> { |
| 2020 | #[inline ] |
| 2021 | fn from(input: CMDetail) -> Self { |
| 2022 | Some(u32::from(input.0)) |
| 2023 | } |
| 2024 | } |
| 2025 | impl From<u8> for CMDetail { |
| 2026 | #[inline ] |
| 2027 | fn from(value: u8) -> Self { |
| 2028 | Self(value) |
| 2029 | } |
| 2030 | } |
| 2031 | impl core::fmt::Debug for CMDetail { |
| 2032 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 2033 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 2034 | (Self::SYM_INTERP.0.into(), "SYM_INTERP" , "SymInterp" ), |
| 2035 | (Self::GROUP_COMPAT.0.into(), "GROUP_COMPAT" , "GroupCompat" ), |
| 2036 | ]; |
| 2037 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 2038 | } |
| 2039 | } |
| 2040 | bitmask_binop!(CMDetail, u8); |
| 2041 | |
| 2042 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 2043 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2044 | pub struct NameDetail(u32); |
| 2045 | impl NameDetail { |
| 2046 | pub const KEYCODES: Self = Self(1 << 0); |
| 2047 | pub const GEOMETRY: Self = Self(1 << 1); |
| 2048 | pub const SYMBOLS: Self = Self(1 << 2); |
| 2049 | pub const PHYS_SYMBOLS: Self = Self(1 << 3); |
| 2050 | pub const TYPES: Self = Self(1 << 4); |
| 2051 | pub const COMPAT: Self = Self(1 << 5); |
| 2052 | pub const KEY_TYPE_NAMES: Self = Self(1 << 6); |
| 2053 | pub const KT_LEVEL_NAMES: Self = Self(1 << 7); |
| 2054 | pub const INDICATOR_NAMES: Self = Self(1 << 8); |
| 2055 | pub const KEY_NAMES: Self = Self(1 << 9); |
| 2056 | pub const KEY_ALIASES: Self = Self(1 << 10); |
| 2057 | pub const VIRTUAL_MOD_NAMES: Self = Self(1 << 11); |
| 2058 | pub const GROUP_NAMES: Self = Self(1 << 12); |
| 2059 | pub const RG_NAMES: Self = Self(1 << 13); |
| 2060 | } |
| 2061 | impl From<NameDetail> for u32 { |
| 2062 | #[inline ] |
| 2063 | fn from(input: NameDetail) -> Self { |
| 2064 | input.0 |
| 2065 | } |
| 2066 | } |
| 2067 | impl From<NameDetail> for Option<u32> { |
| 2068 | #[inline ] |
| 2069 | fn from(input: NameDetail) -> Self { |
| 2070 | Some(input.0) |
| 2071 | } |
| 2072 | } |
| 2073 | impl From<u8> for NameDetail { |
| 2074 | #[inline ] |
| 2075 | fn from(value: u8) -> Self { |
| 2076 | Self(value.into()) |
| 2077 | } |
| 2078 | } |
| 2079 | impl From<u16> for NameDetail { |
| 2080 | #[inline ] |
| 2081 | fn from(value: u16) -> Self { |
| 2082 | Self(value.into()) |
| 2083 | } |
| 2084 | } |
| 2085 | impl From<u32> for NameDetail { |
| 2086 | #[inline ] |
| 2087 | fn from(value: u32) -> Self { |
| 2088 | Self(value) |
| 2089 | } |
| 2090 | } |
| 2091 | impl core::fmt::Debug for NameDetail { |
| 2092 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 2093 | let variants: [(u32, &'static str, &'static …); 14] = [ |
| 2094 | (Self::KEYCODES.0, "KEYCODES" , "Keycodes" ), |
| 2095 | (Self::GEOMETRY.0, "GEOMETRY" , "Geometry" ), |
| 2096 | (Self::SYMBOLS.0, "SYMBOLS" , "Symbols" ), |
| 2097 | (Self::PHYS_SYMBOLS.0, "PHYS_SYMBOLS" , "PhysSymbols" ), |
| 2098 | (Self::TYPES.0, "TYPES" , "Types" ), |
| 2099 | (Self::COMPAT.0, "COMPAT" , "Compat" ), |
| 2100 | (Self::KEY_TYPE_NAMES.0, "KEY_TYPE_NAMES" , "KeyTypeNames" ), |
| 2101 | (Self::KT_LEVEL_NAMES.0, "KT_LEVEL_NAMES" , "KTLevelNames" ), |
| 2102 | (Self::INDICATOR_NAMES.0, "INDICATOR_NAMES" , "IndicatorNames" ), |
| 2103 | (Self::KEY_NAMES.0, "KEY_NAMES" , "KeyNames" ), |
| 2104 | (Self::KEY_ALIASES.0, "KEY_ALIASES" , "KeyAliases" ), |
| 2105 | (Self::VIRTUAL_MOD_NAMES.0, "VIRTUAL_MOD_NAMES" , "VirtualModNames" ), |
| 2106 | (Self::GROUP_NAMES.0, "GROUP_NAMES" , "GroupNames" ), |
| 2107 | (Self::RG_NAMES.0, "RG_NAMES" , "RGNames" ), |
| 2108 | ]; |
| 2109 | pretty_print_bitmask(fmt, self.0, &variants) |
| 2110 | } |
| 2111 | } |
| 2112 | bitmask_binop!(NameDetail, u32); |
| 2113 | |
| 2114 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 2115 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2116 | pub struct GBNDetail(u16); |
| 2117 | impl GBNDetail { |
| 2118 | pub const TYPES: Self = Self(1 << 0); |
| 2119 | pub const COMPAT_MAP: Self = Self(1 << 1); |
| 2120 | pub const CLIENT_SYMBOLS: Self = Self(1 << 2); |
| 2121 | pub const SERVER_SYMBOLS: Self = Self(1 << 3); |
| 2122 | pub const INDICATOR_MAPS: Self = Self(1 << 4); |
| 2123 | pub const KEY_NAMES: Self = Self(1 << 5); |
| 2124 | pub const GEOMETRY: Self = Self(1 << 6); |
| 2125 | pub const OTHER_NAMES: Self = Self(1 << 7); |
| 2126 | } |
| 2127 | impl From<GBNDetail> for u16 { |
| 2128 | #[inline ] |
| 2129 | fn from(input: GBNDetail) -> Self { |
| 2130 | input.0 |
| 2131 | } |
| 2132 | } |
| 2133 | impl From<GBNDetail> for Option<u16> { |
| 2134 | #[inline ] |
| 2135 | fn from(input: GBNDetail) -> Self { |
| 2136 | Some(input.0) |
| 2137 | } |
| 2138 | } |
| 2139 | impl From<GBNDetail> for u32 { |
| 2140 | #[inline ] |
| 2141 | fn from(input: GBNDetail) -> Self { |
| 2142 | u32::from(input.0) |
| 2143 | } |
| 2144 | } |
| 2145 | impl From<GBNDetail> for Option<u32> { |
| 2146 | #[inline ] |
| 2147 | fn from(input: GBNDetail) -> Self { |
| 2148 | Some(u32::from(input.0)) |
| 2149 | } |
| 2150 | } |
| 2151 | impl From<u8> for GBNDetail { |
| 2152 | #[inline ] |
| 2153 | fn from(value: u8) -> Self { |
| 2154 | Self(value.into()) |
| 2155 | } |
| 2156 | } |
| 2157 | impl From<u16> for GBNDetail { |
| 2158 | #[inline ] |
| 2159 | fn from(value: u16) -> Self { |
| 2160 | Self(value) |
| 2161 | } |
| 2162 | } |
| 2163 | impl core::fmt::Debug for GBNDetail { |
| 2164 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 2165 | let variants: [(u32, &'static str, &'static …); 8] = [ |
| 2166 | (Self::TYPES.0.into(), "TYPES" , "Types" ), |
| 2167 | (Self::COMPAT_MAP.0.into(), "COMPAT_MAP" , "CompatMap" ), |
| 2168 | (Self::CLIENT_SYMBOLS.0.into(), "CLIENT_SYMBOLS" , "ClientSymbols" ), |
| 2169 | (Self::SERVER_SYMBOLS.0.into(), "SERVER_SYMBOLS" , "ServerSymbols" ), |
| 2170 | (Self::INDICATOR_MAPS.0.into(), "INDICATOR_MAPS" , "IndicatorMaps" ), |
| 2171 | (Self::KEY_NAMES.0.into(), "KEY_NAMES" , "KeyNames" ), |
| 2172 | (Self::GEOMETRY.0.into(), "GEOMETRY" , "Geometry" ), |
| 2173 | (Self::OTHER_NAMES.0.into(), "OTHER_NAMES" , "OtherNames" ), |
| 2174 | ]; |
| 2175 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 2176 | } |
| 2177 | } |
| 2178 | bitmask_binop!(GBNDetail, u16); |
| 2179 | |
| 2180 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 2181 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2182 | pub struct XIFeature(u16); |
| 2183 | impl XIFeature { |
| 2184 | pub const KEYBOARDS: Self = Self(1 << 0); |
| 2185 | pub const BUTTON_ACTIONS: Self = Self(1 << 1); |
| 2186 | pub const INDICATOR_NAMES: Self = Self(1 << 2); |
| 2187 | pub const INDICATOR_MAPS: Self = Self(1 << 3); |
| 2188 | pub const INDICATOR_STATE: Self = Self(1 << 4); |
| 2189 | } |
| 2190 | impl From<XIFeature> for u16 { |
| 2191 | #[inline ] |
| 2192 | fn from(input: XIFeature) -> Self { |
| 2193 | input.0 |
| 2194 | } |
| 2195 | } |
| 2196 | impl From<XIFeature> for Option<u16> { |
| 2197 | #[inline ] |
| 2198 | fn from(input: XIFeature) -> Self { |
| 2199 | Some(input.0) |
| 2200 | } |
| 2201 | } |
| 2202 | impl From<XIFeature> for u32 { |
| 2203 | #[inline ] |
| 2204 | fn from(input: XIFeature) -> Self { |
| 2205 | u32::from(input.0) |
| 2206 | } |
| 2207 | } |
| 2208 | impl From<XIFeature> for Option<u32> { |
| 2209 | #[inline ] |
| 2210 | fn from(input: XIFeature) -> Self { |
| 2211 | Some(u32::from(input.0)) |
| 2212 | } |
| 2213 | } |
| 2214 | impl From<u8> for XIFeature { |
| 2215 | #[inline ] |
| 2216 | fn from(value: u8) -> Self { |
| 2217 | Self(value.into()) |
| 2218 | } |
| 2219 | } |
| 2220 | impl From<u16> for XIFeature { |
| 2221 | #[inline ] |
| 2222 | fn from(value: u16) -> Self { |
| 2223 | Self(value) |
| 2224 | } |
| 2225 | } |
| 2226 | impl core::fmt::Debug for XIFeature { |
| 2227 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 2228 | let variants: [(u32, &'static str, &'static …); 5] = [ |
| 2229 | (Self::KEYBOARDS.0.into(), "KEYBOARDS" , "Keyboards" ), |
| 2230 | (Self::BUTTON_ACTIONS.0.into(), "BUTTON_ACTIONS" , "ButtonActions" ), |
| 2231 | (Self::INDICATOR_NAMES.0.into(), "INDICATOR_NAMES" , "IndicatorNames" ), |
| 2232 | (Self::INDICATOR_MAPS.0.into(), "INDICATOR_MAPS" , "IndicatorMaps" ), |
| 2233 | (Self::INDICATOR_STATE.0.into(), "INDICATOR_STATE" , "IndicatorState" ), |
| 2234 | ]; |
| 2235 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 2236 | } |
| 2237 | } |
| 2238 | bitmask_binop!(XIFeature, u16); |
| 2239 | |
| 2240 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 2241 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2242 | pub struct PerClientFlag(u32); |
| 2243 | impl PerClientFlag { |
| 2244 | pub const DETECTABLE_AUTO_REPEAT: Self = Self(1 << 0); |
| 2245 | pub const GRABS_USE_XKB_STATE: Self = Self(1 << 1); |
| 2246 | pub const AUTO_RESET_CONTROLS: Self = Self(1 << 2); |
| 2247 | pub const LOOKUP_STATE_WHEN_GRABBED: Self = Self(1 << 3); |
| 2248 | pub const SEND_EVENT_USES_XKB_STATE: Self = Self(1 << 4); |
| 2249 | } |
| 2250 | impl From<PerClientFlag> for u32 { |
| 2251 | #[inline ] |
| 2252 | fn from(input: PerClientFlag) -> Self { |
| 2253 | input.0 |
| 2254 | } |
| 2255 | } |
| 2256 | impl From<PerClientFlag> for Option<u32> { |
| 2257 | #[inline ] |
| 2258 | fn from(input: PerClientFlag) -> Self { |
| 2259 | Some(input.0) |
| 2260 | } |
| 2261 | } |
| 2262 | impl From<u8> for PerClientFlag { |
| 2263 | #[inline ] |
| 2264 | fn from(value: u8) -> Self { |
| 2265 | Self(value.into()) |
| 2266 | } |
| 2267 | } |
| 2268 | impl From<u16> for PerClientFlag { |
| 2269 | #[inline ] |
| 2270 | fn from(value: u16) -> Self { |
| 2271 | Self(value.into()) |
| 2272 | } |
| 2273 | } |
| 2274 | impl From<u32> for PerClientFlag { |
| 2275 | #[inline ] |
| 2276 | fn from(value: u32) -> Self { |
| 2277 | Self(value) |
| 2278 | } |
| 2279 | } |
| 2280 | impl core::fmt::Debug for PerClientFlag { |
| 2281 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 2282 | let variants: [(u32, &'static str, &'static …); 5] = [ |
| 2283 | (Self::DETECTABLE_AUTO_REPEAT.0, "DETECTABLE_AUTO_REPEAT" , "DetectableAutoRepeat" ), |
| 2284 | (Self::GRABS_USE_XKB_STATE.0, "GRABS_USE_XKB_STATE" , "GrabsUseXKBState" ), |
| 2285 | (Self::AUTO_RESET_CONTROLS.0, "AUTO_RESET_CONTROLS" , "AutoResetControls" ), |
| 2286 | (Self::LOOKUP_STATE_WHEN_GRABBED.0, "LOOKUP_STATE_WHEN_GRABBED" , "LookupStateWhenGrabbed" ), |
| 2287 | (Self::SEND_EVENT_USES_XKB_STATE.0, "SEND_EVENT_USES_XKB_STATE" , "SendEventUsesXKBState" ), |
| 2288 | ]; |
| 2289 | pretty_print_bitmask(fmt, self.0, &variants) |
| 2290 | } |
| 2291 | } |
| 2292 | bitmask_binop!(PerClientFlag, u32); |
| 2293 | |
| 2294 | #[derive (Clone, Copy, Default)] |
| 2295 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 2296 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2297 | pub struct ModDef { |
| 2298 | pub mask: xproto::ModMask, |
| 2299 | pub real_mods: xproto::ModMask, |
| 2300 | pub vmods: VMod, |
| 2301 | } |
| 2302 | impl_debug_if_no_extra_traits!(ModDef, "ModDef" ); |
| 2303 | impl TryParse for ModDef { |
| 2304 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 2305 | let (mask: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2306 | let (real_mods: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2307 | let (vmods: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2308 | let mask: ModMask = mask.into(); |
| 2309 | let real_mods: ModMask = real_mods.into(); |
| 2310 | let vmods: VMod = vmods.into(); |
| 2311 | let result: ModDef = ModDef { mask, real_mods, vmods }; |
| 2312 | Ok((result, remaining)) |
| 2313 | } |
| 2314 | } |
| 2315 | impl Serialize for ModDef { |
| 2316 | type Bytes = [u8; 4]; |
| 2317 | fn serialize(&self) -> [u8; 4] { |
| 2318 | let mask_bytes: [u8; 1] = (u16::from(self.mask) as u8).serialize(); |
| 2319 | let real_mods_bytes: [u8; 1] = (u16::from(self.real_mods) as u8).serialize(); |
| 2320 | let vmods_bytes: [u8; 2] = u16::from(self.vmods).serialize(); |
| 2321 | [ |
| 2322 | mask_bytes[0], |
| 2323 | real_mods_bytes[0], |
| 2324 | vmods_bytes[0], |
| 2325 | vmods_bytes[1], |
| 2326 | ] |
| 2327 | } |
| 2328 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 2329 | bytes.reserve(additional:4); |
| 2330 | (u16::from(self.mask) as u8).serialize_into(bytes); |
| 2331 | (u16::from(self.real_mods) as u8).serialize_into(bytes); |
| 2332 | u16::from(self.vmods).serialize_into(bytes); |
| 2333 | } |
| 2334 | } |
| 2335 | |
| 2336 | #[derive (Clone, Copy, Default)] |
| 2337 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 2338 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2339 | pub struct KeyName { |
| 2340 | pub name: [u8; 4], |
| 2341 | } |
| 2342 | impl_debug_if_no_extra_traits!(KeyName, "KeyName" ); |
| 2343 | impl TryParse for KeyName { |
| 2344 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 2345 | let (name: [u8; 4], remaining: &[u8]) = crate::x11_utils::parse_u8_array::<4>(data:remaining)?; |
| 2346 | let result: KeyName = KeyName { name }; |
| 2347 | Ok((result, remaining)) |
| 2348 | } |
| 2349 | } |
| 2350 | impl Serialize for KeyName { |
| 2351 | type Bytes = [u8; 4]; |
| 2352 | fn serialize(&self) -> [u8; 4] { |
| 2353 | [ |
| 2354 | self.name[0], |
| 2355 | self.name[1], |
| 2356 | self.name[2], |
| 2357 | self.name[3], |
| 2358 | ] |
| 2359 | } |
| 2360 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 2361 | bytes.reserve(additional:4); |
| 2362 | bytes.extend_from_slice(&self.name); |
| 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | #[derive (Clone, Copy, Default)] |
| 2367 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 2368 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2369 | pub struct KeyAlias { |
| 2370 | pub real: [u8; 4], |
| 2371 | pub alias: [u8; 4], |
| 2372 | } |
| 2373 | impl_debug_if_no_extra_traits!(KeyAlias, "KeyAlias" ); |
| 2374 | impl TryParse for KeyAlias { |
| 2375 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 2376 | let (real: [u8; 4], remaining: &[u8]) = crate::x11_utils::parse_u8_array::<4>(data:remaining)?; |
| 2377 | let (alias: [u8; 4], remaining: &[u8]) = crate::x11_utils::parse_u8_array::<4>(data:remaining)?; |
| 2378 | let result: KeyAlias = KeyAlias { real, alias }; |
| 2379 | Ok((result, remaining)) |
| 2380 | } |
| 2381 | } |
| 2382 | impl Serialize for KeyAlias { |
| 2383 | type Bytes = [u8; 8]; |
| 2384 | fn serialize(&self) -> [u8; 8] { |
| 2385 | [ |
| 2386 | self.real[0], |
| 2387 | self.real[1], |
| 2388 | self.real[2], |
| 2389 | self.real[3], |
| 2390 | self.alias[0], |
| 2391 | self.alias[1], |
| 2392 | self.alias[2], |
| 2393 | self.alias[3], |
| 2394 | ] |
| 2395 | } |
| 2396 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 2397 | bytes.reserve(additional:8); |
| 2398 | bytes.extend_from_slice(&self.real); |
| 2399 | bytes.extend_from_slice(&self.alias); |
| 2400 | } |
| 2401 | } |
| 2402 | |
| 2403 | #[derive (Clone, Default)] |
| 2404 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 2405 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2406 | pub struct CountedString16 { |
| 2407 | pub string: Vec<u8>, |
| 2408 | pub alignment_pad: Vec<u8>, |
| 2409 | } |
| 2410 | impl_debug_if_no_extra_traits!(CountedString16, "CountedString16" ); |
| 2411 | impl TryParse for CountedString16 { |
| 2412 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 2413 | let (length: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2414 | let (string: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data:remaining, list_length:length.try_to_usize()?)?; |
| 2415 | let string: Vec = string.to_vec(); |
| 2416 | let (alignment_pad: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data: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(err:ParseError::InvalidExpression)?.try_to_usize()?)?; |
| 2417 | let alignment_pad: Vec = alignment_pad.to_vec(); |
| 2418 | let result: CountedString16 = CountedString16 { string, alignment_pad }; |
| 2419 | Ok((result, remaining)) |
| 2420 | } |
| 2421 | } |
| 2422 | impl Serialize for CountedString16 { |
| 2423 | type Bytes = Vec<u8>; |
| 2424 | fn serialize(&self) -> Vec<u8> { |
| 2425 | let mut result: Vec = Vec::new(); |
| 2426 | self.serialize_into(&mut result); |
| 2427 | result |
| 2428 | } |
| 2429 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 2430 | let length: u16 = u16::try_from(self.string.len()).expect(msg:"`string` has too many elements" ); |
| 2431 | length.serialize_into(bytes); |
| 2432 | bytes.extend_from_slice(&self.string); |
| 2433 | 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" ); |
| 2434 | bytes.extend_from_slice(&self.alignment_pad); |
| 2435 | } |
| 2436 | } |
| 2437 | impl CountedString16 { |
| 2438 | /// Get the value of the `length` field. |
| 2439 | /// |
| 2440 | /// The `length` field is used as the length field of the `string` field. |
| 2441 | /// This function computes the field's value again based on the length of the list. |
| 2442 | /// |
| 2443 | /// # Panics |
| 2444 | /// |
| 2445 | /// Panics if the value cannot be represented in the target type. This |
| 2446 | /// cannot happen with values of the struct received from the X11 server. |
| 2447 | pub fn length(&self) -> u16 { |
| 2448 | self.string.len() |
| 2449 | .try_into().unwrap() |
| 2450 | } |
| 2451 | } |
| 2452 | |
| 2453 | #[derive (Clone, Copy, Default)] |
| 2454 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 2455 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2456 | pub struct KTMapEntry { |
| 2457 | pub active: bool, |
| 2458 | pub mods_mask: xproto::ModMask, |
| 2459 | pub level: u8, |
| 2460 | pub mods_mods: xproto::ModMask, |
| 2461 | pub mods_vmods: VMod, |
| 2462 | } |
| 2463 | impl_debug_if_no_extra_traits!(KTMapEntry, "KTMapEntry" ); |
| 2464 | impl TryParse for KTMapEntry { |
| 2465 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 2466 | let (active: bool, remaining: &[u8]) = bool::try_parse(remaining)?; |
| 2467 | let (mods_mask: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2468 | let (level: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2469 | let (mods_mods: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2470 | let (mods_vmods: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2471 | let remaining: &[u8] = remaining.get(2..).ok_or(err:ParseError::InsufficientData)?; |
| 2472 | let mods_mask: ModMask = mods_mask.into(); |
| 2473 | let mods_mods: ModMask = mods_mods.into(); |
| 2474 | let mods_vmods: VMod = mods_vmods.into(); |
| 2475 | let result: KTMapEntry = KTMapEntry { active, mods_mask, level, mods_mods, mods_vmods }; |
| 2476 | Ok((result, remaining)) |
| 2477 | } |
| 2478 | } |
| 2479 | impl Serialize for KTMapEntry { |
| 2480 | type Bytes = [u8; 8]; |
| 2481 | fn serialize(&self) -> [u8; 8] { |
| 2482 | let active_bytes = self.active.serialize(); |
| 2483 | let mods_mask_bytes = (u16::from(self.mods_mask) as u8).serialize(); |
| 2484 | let level_bytes = self.level.serialize(); |
| 2485 | let mods_mods_bytes = (u16::from(self.mods_mods) as u8).serialize(); |
| 2486 | let mods_vmods_bytes = u16::from(self.mods_vmods).serialize(); |
| 2487 | [ |
| 2488 | active_bytes[0], |
| 2489 | mods_mask_bytes[0], |
| 2490 | level_bytes[0], |
| 2491 | mods_mods_bytes[0], |
| 2492 | mods_vmods_bytes[0], |
| 2493 | mods_vmods_bytes[1], |
| 2494 | 0, |
| 2495 | 0, |
| 2496 | ] |
| 2497 | } |
| 2498 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 2499 | bytes.reserve(8); |
| 2500 | self.active.serialize_into(bytes); |
| 2501 | (u16::from(self.mods_mask) as u8).serialize_into(bytes); |
| 2502 | self.level.serialize_into(bytes); |
| 2503 | (u16::from(self.mods_mods) as u8).serialize_into(bytes); |
| 2504 | u16::from(self.mods_vmods).serialize_into(bytes); |
| 2505 | bytes.extend_from_slice(&[0; 2]); |
| 2506 | } |
| 2507 | } |
| 2508 | |
| 2509 | #[derive (Clone, Default)] |
| 2510 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 2511 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2512 | pub struct KeyType { |
| 2513 | pub mods_mask: xproto::ModMask, |
| 2514 | pub mods_mods: xproto::ModMask, |
| 2515 | pub mods_vmods: VMod, |
| 2516 | pub num_levels: u8, |
| 2517 | pub has_preserve: bool, |
| 2518 | pub map: Vec<KTMapEntry>, |
| 2519 | pub preserve: Vec<ModDef>, |
| 2520 | } |
| 2521 | impl_debug_if_no_extra_traits!(KeyType, "KeyType" ); |
| 2522 | impl TryParse for KeyType { |
| 2523 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 2524 | let (mods_mask: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2525 | let (mods_mods: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2526 | let (mods_vmods: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2527 | let (num_levels: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2528 | let (n_map_entries: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2529 | let (has_preserve: bool, remaining: &[u8]) = bool::try_parse(remaining)?; |
| 2530 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 2531 | let (map: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<KTMapEntry>(data:remaining, list_length:n_map_entries.try_to_usize()?)?; |
| 2532 | let (preserve: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<ModDef>(data:remaining, list_length:u32::from(has_preserve).checked_mul(u32::from(n_map_entries)).ok_or(err:ParseError::InvalidExpression)?.try_to_usize()?)?; |
| 2533 | let mods_mask: ModMask = mods_mask.into(); |
| 2534 | let mods_mods: ModMask = mods_mods.into(); |
| 2535 | let mods_vmods: VMod = mods_vmods.into(); |
| 2536 | let result: KeyType = KeyType { mods_mask, mods_mods, mods_vmods, num_levels, has_preserve, map, preserve }; |
| 2537 | Ok((result, remaining)) |
| 2538 | } |
| 2539 | } |
| 2540 | impl Serialize for KeyType { |
| 2541 | type Bytes = Vec<u8>; |
| 2542 | fn serialize(&self) -> Vec<u8> { |
| 2543 | let mut result: Vec = Vec::new(); |
| 2544 | self.serialize_into(&mut result); |
| 2545 | result |
| 2546 | } |
| 2547 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 2548 | bytes.reserve(additional:8); |
| 2549 | (u16::from(self.mods_mask) as u8).serialize_into(bytes); |
| 2550 | (u16::from(self.mods_mods) as u8).serialize_into(bytes); |
| 2551 | u16::from(self.mods_vmods).serialize_into(bytes); |
| 2552 | self.num_levels.serialize_into(bytes); |
| 2553 | let n_map_entries: u8 = u8::try_from(self.map.len()).expect(msg:"`map` has too many elements" ); |
| 2554 | n_map_entries.serialize_into(bytes); |
| 2555 | self.has_preserve.serialize_into(bytes); |
| 2556 | bytes.extend_from_slice(&[0; 1]); |
| 2557 | self.map.serialize_into(bytes); |
| 2558 | 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" ); |
| 2559 | self.preserve.serialize_into(bytes); |
| 2560 | } |
| 2561 | } |
| 2562 | impl KeyType { |
| 2563 | /// Get the value of the `nMapEntries` field. |
| 2564 | /// |
| 2565 | /// The `nMapEntries` field is used as the length field of the `map` field. |
| 2566 | /// This function computes the field's value again based on the length of the list. |
| 2567 | /// |
| 2568 | /// # Panics |
| 2569 | /// |
| 2570 | /// Panics if the value cannot be represented in the target type. This |
| 2571 | /// cannot happen with values of the struct received from the X11 server. |
| 2572 | pub fn n_map_entries(&self) -> u8 { |
| 2573 | self.map.len() |
| 2574 | .try_into().unwrap() |
| 2575 | } |
| 2576 | } |
| 2577 | |
| 2578 | #[derive (Clone, Default)] |
| 2579 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 2580 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2581 | pub struct KeySymMap { |
| 2582 | pub kt_index: [u8; 4], |
| 2583 | pub group_info: u8, |
| 2584 | pub width: u8, |
| 2585 | pub syms: Vec<xproto::Keysym>, |
| 2586 | } |
| 2587 | impl_debug_if_no_extra_traits!(KeySymMap, "KeySymMap" ); |
| 2588 | impl TryParse for KeySymMap { |
| 2589 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 2590 | let (kt_index: [u8; 4], remaining: &[u8]) = crate::x11_utils::parse_u8_array::<4>(data:remaining)?; |
| 2591 | let (group_info: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2592 | let (width: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2593 | let (n_syms: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 2594 | let (syms: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<xproto::Keysym>(data:remaining, list_length:n_syms.try_to_usize()?)?; |
| 2595 | let result: KeySymMap = KeySymMap { kt_index, group_info, width, syms }; |
| 2596 | Ok((result, remaining)) |
| 2597 | } |
| 2598 | } |
| 2599 | impl Serialize for KeySymMap { |
| 2600 | type Bytes = Vec<u8>; |
| 2601 | fn serialize(&self) -> Vec<u8> { |
| 2602 | let mut result: Vec = Vec::new(); |
| 2603 | self.serialize_into(&mut result); |
| 2604 | result |
| 2605 | } |
| 2606 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 2607 | bytes.reserve(additional:8); |
| 2608 | bytes.extend_from_slice(&self.kt_index); |
| 2609 | self.group_info.serialize_into(bytes); |
| 2610 | self.width.serialize_into(bytes); |
| 2611 | let n_syms: u16 = u16::try_from(self.syms.len()).expect(msg:"`syms` has too many elements" ); |
| 2612 | n_syms.serialize_into(bytes); |
| 2613 | self.syms.serialize_into(bytes); |
| 2614 | } |
| 2615 | } |
| 2616 | impl KeySymMap { |
| 2617 | /// Get the value of the `nSyms` field. |
| 2618 | /// |
| 2619 | /// The `nSyms` field is used as the length field of the `syms` field. |
| 2620 | /// This function computes the field's value again based on the length of the list. |
| 2621 | /// |
| 2622 | /// # Panics |
| 2623 | /// |
| 2624 | /// Panics if the value cannot be represented in the target type. This |
| 2625 | /// cannot happen with values of the struct received from the X11 server. |
| 2626 | pub fn n_syms(&self) -> u16 { |
| 2627 | self.syms.len() |
| 2628 | .try_into().unwrap() |
| 2629 | } |
| 2630 | } |
| 2631 | |
| 2632 | #[derive (Clone, Copy, Default)] |
| 2633 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 2634 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2635 | pub struct CommonBehavior { |
| 2636 | pub type_: u8, |
| 2637 | pub data: u8, |
| 2638 | } |
| 2639 | impl_debug_if_no_extra_traits!(CommonBehavior, "CommonBehavior" ); |
| 2640 | impl TryParse for CommonBehavior { |
| 2641 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 2642 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2643 | let (data: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2644 | let result: CommonBehavior = CommonBehavior { type_, data }; |
| 2645 | Ok((result, remaining)) |
| 2646 | } |
| 2647 | } |
| 2648 | impl Serialize for CommonBehavior { |
| 2649 | type Bytes = [u8; 2]; |
| 2650 | fn serialize(&self) -> [u8; 2] { |
| 2651 | let type_bytes: [u8; 1] = self.type_.serialize(); |
| 2652 | let data_bytes: [u8; 1] = self.data.serialize(); |
| 2653 | [ |
| 2654 | type_bytes[0], |
| 2655 | data_bytes[0], |
| 2656 | ] |
| 2657 | } |
| 2658 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 2659 | bytes.reserve(additional:2); |
| 2660 | self.type_.serialize_into(bytes); |
| 2661 | self.data.serialize_into(bytes); |
| 2662 | } |
| 2663 | } |
| 2664 | |
| 2665 | #[derive (Clone, Copy, Default)] |
| 2666 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 2667 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2668 | pub struct DefaultBehavior { |
| 2669 | pub type_: u8, |
| 2670 | } |
| 2671 | impl_debug_if_no_extra_traits!(DefaultBehavior, "DefaultBehavior" ); |
| 2672 | impl TryParse for DefaultBehavior { |
| 2673 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 2674 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2675 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 2676 | let result: DefaultBehavior = DefaultBehavior { type_ }; |
| 2677 | Ok((result, remaining)) |
| 2678 | } |
| 2679 | } |
| 2680 | impl Serialize for DefaultBehavior { |
| 2681 | type Bytes = [u8; 2]; |
| 2682 | fn serialize(&self) -> [u8; 2] { |
| 2683 | let type_bytes: [u8; 1] = self.type_.serialize(); |
| 2684 | [ |
| 2685 | type_bytes[0], |
| 2686 | 0, |
| 2687 | ] |
| 2688 | } |
| 2689 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 2690 | bytes.reserve(additional:2); |
| 2691 | self.type_.serialize_into(bytes); |
| 2692 | bytes.extend_from_slice(&[0; 1]); |
| 2693 | } |
| 2694 | } |
| 2695 | |
| 2696 | pub type LockBehavior = DefaultBehavior; |
| 2697 | |
| 2698 | #[derive (Clone, Copy, Default)] |
| 2699 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 2700 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2701 | pub struct RadioGroupBehavior { |
| 2702 | pub type_: u8, |
| 2703 | pub group: u8, |
| 2704 | } |
| 2705 | impl_debug_if_no_extra_traits!(RadioGroupBehavior, "RadioGroupBehavior" ); |
| 2706 | impl TryParse for RadioGroupBehavior { |
| 2707 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 2708 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2709 | let (group: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2710 | let result: RadioGroupBehavior = RadioGroupBehavior { type_, group }; |
| 2711 | Ok((result, remaining)) |
| 2712 | } |
| 2713 | } |
| 2714 | impl Serialize for RadioGroupBehavior { |
| 2715 | type Bytes = [u8; 2]; |
| 2716 | fn serialize(&self) -> [u8; 2] { |
| 2717 | let type_bytes: [u8; 1] = self.type_.serialize(); |
| 2718 | let group_bytes: [u8; 1] = self.group.serialize(); |
| 2719 | [ |
| 2720 | type_bytes[0], |
| 2721 | group_bytes[0], |
| 2722 | ] |
| 2723 | } |
| 2724 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 2725 | bytes.reserve(additional:2); |
| 2726 | self.type_.serialize_into(bytes); |
| 2727 | self.group.serialize_into(bytes); |
| 2728 | } |
| 2729 | } |
| 2730 | |
| 2731 | #[derive (Clone, Copy, Default)] |
| 2732 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 2733 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2734 | pub struct OverlayBehavior { |
| 2735 | pub type_: u8, |
| 2736 | pub key: xproto::Keycode, |
| 2737 | } |
| 2738 | impl_debug_if_no_extra_traits!(OverlayBehavior, "OverlayBehavior" ); |
| 2739 | impl TryParse for OverlayBehavior { |
| 2740 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 2741 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 2742 | let (key: u8, remaining: &[u8]) = xproto::Keycode::try_parse(remaining)?; |
| 2743 | let result: OverlayBehavior = OverlayBehavior { type_, key }; |
| 2744 | Ok((result, remaining)) |
| 2745 | } |
| 2746 | } |
| 2747 | impl Serialize for OverlayBehavior { |
| 2748 | type Bytes = [u8; 2]; |
| 2749 | fn serialize(&self) -> [u8; 2] { |
| 2750 | let type_bytes: [u8; 1] = self.type_.serialize(); |
| 2751 | let key_bytes: [u8; 1] = self.key.serialize(); |
| 2752 | [ |
| 2753 | type_bytes[0], |
| 2754 | key_bytes[0], |
| 2755 | ] |
| 2756 | } |
| 2757 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 2758 | bytes.reserve(additional:2); |
| 2759 | self.type_.serialize_into(bytes); |
| 2760 | self.key.serialize_into(bytes); |
| 2761 | } |
| 2762 | } |
| 2763 | |
| 2764 | pub type PermamentLockBehavior = LockBehavior; |
| 2765 | |
| 2766 | pub type PermamentRadioGroupBehavior = RadioGroupBehavior; |
| 2767 | |
| 2768 | pub type PermamentOverlayBehavior = OverlayBehavior; |
| 2769 | |
| 2770 | #[derive (Debug, Copy, Clone)] |
| 2771 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2772 | pub struct Behavior([u8; 2]); |
| 2773 | impl Behavior { |
| 2774 | pub fn as_common(&self) -> CommonBehavior { |
| 2775 | fn do_the_parse(remaining: &[u8]) -> Result<CommonBehavior, ParseError> { |
| 2776 | let (common, remaining) = CommonBehavior::try_parse(remaining)?; |
| 2777 | let _ = remaining; |
| 2778 | Ok(common) |
| 2779 | } |
| 2780 | do_the_parse(&self.0).unwrap() |
| 2781 | } |
| 2782 | pub fn as_default(&self) -> DefaultBehavior { |
| 2783 | fn do_the_parse(remaining: &[u8]) -> Result<DefaultBehavior, ParseError> { |
| 2784 | let (default, remaining) = DefaultBehavior::try_parse(remaining)?; |
| 2785 | let _ = remaining; |
| 2786 | Ok(default) |
| 2787 | } |
| 2788 | do_the_parse(&self.0).unwrap() |
| 2789 | } |
| 2790 | pub fn as_lock(&self) -> LockBehavior { |
| 2791 | fn do_the_parse(remaining: &[u8]) -> Result<LockBehavior, ParseError> { |
| 2792 | let (lock, remaining) = LockBehavior::try_parse(remaining)?; |
| 2793 | let _ = remaining; |
| 2794 | Ok(lock) |
| 2795 | } |
| 2796 | do_the_parse(&self.0).unwrap() |
| 2797 | } |
| 2798 | pub fn as_radio_group(&self) -> RadioGroupBehavior { |
| 2799 | fn do_the_parse(remaining: &[u8]) -> Result<RadioGroupBehavior, ParseError> { |
| 2800 | let (radio_group, remaining) = RadioGroupBehavior::try_parse(remaining)?; |
| 2801 | let _ = remaining; |
| 2802 | Ok(radio_group) |
| 2803 | } |
| 2804 | do_the_parse(&self.0).unwrap() |
| 2805 | } |
| 2806 | pub fn as_overlay1(&self) -> OverlayBehavior { |
| 2807 | fn do_the_parse(remaining: &[u8]) -> Result<OverlayBehavior, ParseError> { |
| 2808 | let (overlay1, remaining) = OverlayBehavior::try_parse(remaining)?; |
| 2809 | let _ = remaining; |
| 2810 | Ok(overlay1) |
| 2811 | } |
| 2812 | do_the_parse(&self.0).unwrap() |
| 2813 | } |
| 2814 | pub fn as_overlay2(&self) -> OverlayBehavior { |
| 2815 | fn do_the_parse(remaining: &[u8]) -> Result<OverlayBehavior, ParseError> { |
| 2816 | let (overlay2, remaining) = OverlayBehavior::try_parse(remaining)?; |
| 2817 | let _ = remaining; |
| 2818 | Ok(overlay2) |
| 2819 | } |
| 2820 | do_the_parse(&self.0).unwrap() |
| 2821 | } |
| 2822 | pub fn as_permament_lock(&self) -> PermamentLockBehavior { |
| 2823 | fn do_the_parse(remaining: &[u8]) -> Result<PermamentLockBehavior, ParseError> { |
| 2824 | let (permament_lock, remaining) = PermamentLockBehavior::try_parse(remaining)?; |
| 2825 | let _ = remaining; |
| 2826 | Ok(permament_lock) |
| 2827 | } |
| 2828 | do_the_parse(&self.0).unwrap() |
| 2829 | } |
| 2830 | pub fn as_permament_radio_group(&self) -> PermamentRadioGroupBehavior { |
| 2831 | fn do_the_parse(remaining: &[u8]) -> Result<PermamentRadioGroupBehavior, ParseError> { |
| 2832 | let (permament_radio_group, remaining) = PermamentRadioGroupBehavior::try_parse(remaining)?; |
| 2833 | let _ = remaining; |
| 2834 | Ok(permament_radio_group) |
| 2835 | } |
| 2836 | do_the_parse(&self.0).unwrap() |
| 2837 | } |
| 2838 | pub fn as_permament_overlay1(&self) -> PermamentOverlayBehavior { |
| 2839 | fn do_the_parse(remaining: &[u8]) -> Result<PermamentOverlayBehavior, ParseError> { |
| 2840 | let (permament_overlay1, remaining) = PermamentOverlayBehavior::try_parse(remaining)?; |
| 2841 | let _ = remaining; |
| 2842 | Ok(permament_overlay1) |
| 2843 | } |
| 2844 | do_the_parse(&self.0).unwrap() |
| 2845 | } |
| 2846 | pub fn as_permament_overlay2(&self) -> PermamentOverlayBehavior { |
| 2847 | fn do_the_parse(remaining: &[u8]) -> Result<PermamentOverlayBehavior, ParseError> { |
| 2848 | let (permament_overlay2, remaining) = PermamentOverlayBehavior::try_parse(remaining)?; |
| 2849 | let _ = remaining; |
| 2850 | Ok(permament_overlay2) |
| 2851 | } |
| 2852 | do_the_parse(&self.0).unwrap() |
| 2853 | } |
| 2854 | pub fn as_type(&self) -> u8 { |
| 2855 | fn do_the_parse(remaining: &[u8]) -> Result<u8, ParseError> { |
| 2856 | let (type_, remaining) = u8::try_parse(remaining)?; |
| 2857 | let _ = remaining; |
| 2858 | Ok(type_) |
| 2859 | } |
| 2860 | do_the_parse(&self.0).unwrap() |
| 2861 | } |
| 2862 | } |
| 2863 | impl Serialize for Behavior { |
| 2864 | type Bytes = [u8; 2]; |
| 2865 | fn serialize(&self) -> [u8; 2] { |
| 2866 | self.0 |
| 2867 | } |
| 2868 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 2869 | bytes.extend_from_slice(&self.0); |
| 2870 | } |
| 2871 | } |
| 2872 | impl TryParse for Behavior { |
| 2873 | fn try_parse(value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 2874 | let inner: [u8; 2] = valueResult<[u8; 2], TryFromSliceError>.get(..2) |
| 2875 | .ok_or(err:ParseError::InsufficientData)? |
| 2876 | .try_into() |
| 2877 | .unwrap(); |
| 2878 | let result: Behavior = Behavior(inner); |
| 2879 | Ok((result, &value[2..])) |
| 2880 | } |
| 2881 | } |
| 2882 | impl From<CommonBehavior> for Behavior { |
| 2883 | fn from(common: CommonBehavior) -> Self { |
| 2884 | let common_bytes: [u8; 2] = common.serialize(); |
| 2885 | Self(common_bytes) |
| 2886 | } |
| 2887 | } |
| 2888 | impl From<DefaultBehavior> for Behavior { |
| 2889 | fn from(default: DefaultBehavior) -> Self { |
| 2890 | let default_bytes: [u8; 2] = default.serialize(); |
| 2891 | Self(default_bytes) |
| 2892 | } |
| 2893 | } |
| 2894 | impl From<RadioGroupBehavior> for Behavior { |
| 2895 | fn from(radio_group: RadioGroupBehavior) -> Self { |
| 2896 | let radio_group_bytes: [u8; 2] = radio_group.serialize(); |
| 2897 | Self(radio_group_bytes) |
| 2898 | } |
| 2899 | } |
| 2900 | impl From<OverlayBehavior> for Behavior { |
| 2901 | fn from(overlay1: OverlayBehavior) -> Self { |
| 2902 | let overlay1_bytes: [u8; 2] = overlay1.serialize(); |
| 2903 | Self(overlay1_bytes) |
| 2904 | } |
| 2905 | } |
| 2906 | impl From<u8> for Behavior { |
| 2907 | fn from(type_: u8) -> Self { |
| 2908 | let type_bytes: [u8; 1] = type_.serialize(); |
| 2909 | let value: [u8; 2] = [ |
| 2910 | type_bytes[0], |
| 2911 | 0, |
| 2912 | ]; |
| 2913 | Self(value) |
| 2914 | } |
| 2915 | } |
| 2916 | |
| 2917 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 2918 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2919 | pub struct BehaviorType(u8); |
| 2920 | impl BehaviorType { |
| 2921 | pub const DEFAULT: Self = Self(0); |
| 2922 | pub const LOCK: Self = Self(1); |
| 2923 | pub const RADIO_GROUP: Self = Self(2); |
| 2924 | pub const OVERLAY1: Self = Self(3); |
| 2925 | pub const OVERLAY2: Self = Self(4); |
| 2926 | pub const PERMAMENT_LOCK: Self = Self(129); |
| 2927 | pub const PERMAMENT_RADIO_GROUP: Self = Self(130); |
| 2928 | pub const PERMAMENT_OVERLAY1: Self = Self(131); |
| 2929 | pub const PERMAMENT_OVERLAY2: Self = Self(132); |
| 2930 | } |
| 2931 | impl From<BehaviorType> for u8 { |
| 2932 | #[inline ] |
| 2933 | fn from(input: BehaviorType) -> Self { |
| 2934 | input.0 |
| 2935 | } |
| 2936 | } |
| 2937 | impl From<BehaviorType> for Option<u8> { |
| 2938 | #[inline ] |
| 2939 | fn from(input: BehaviorType) -> Self { |
| 2940 | Some(input.0) |
| 2941 | } |
| 2942 | } |
| 2943 | impl From<BehaviorType> for u16 { |
| 2944 | #[inline ] |
| 2945 | fn from(input: BehaviorType) -> Self { |
| 2946 | u16::from(input.0) |
| 2947 | } |
| 2948 | } |
| 2949 | impl From<BehaviorType> for Option<u16> { |
| 2950 | #[inline ] |
| 2951 | fn from(input: BehaviorType) -> Self { |
| 2952 | Some(u16::from(input.0)) |
| 2953 | } |
| 2954 | } |
| 2955 | impl From<BehaviorType> for u32 { |
| 2956 | #[inline ] |
| 2957 | fn from(input: BehaviorType) -> Self { |
| 2958 | u32::from(input.0) |
| 2959 | } |
| 2960 | } |
| 2961 | impl From<BehaviorType> for Option<u32> { |
| 2962 | #[inline ] |
| 2963 | fn from(input: BehaviorType) -> Self { |
| 2964 | Some(u32::from(input.0)) |
| 2965 | } |
| 2966 | } |
| 2967 | impl From<u8> for BehaviorType { |
| 2968 | #[inline ] |
| 2969 | fn from(value: u8) -> Self { |
| 2970 | Self(value) |
| 2971 | } |
| 2972 | } |
| 2973 | impl core::fmt::Debug for BehaviorType { |
| 2974 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 2975 | let variants: [(u32, &'static str, &'static …); 9] = [ |
| 2976 | (Self::DEFAULT.0.into(), "DEFAULT" , "Default" ), |
| 2977 | (Self::LOCK.0.into(), "LOCK" , "Lock" ), |
| 2978 | (Self::RADIO_GROUP.0.into(), "RADIO_GROUP" , "RadioGroup" ), |
| 2979 | (Self::OVERLAY1.0.into(), "OVERLAY1" , "Overlay1" ), |
| 2980 | (Self::OVERLAY2.0.into(), "OVERLAY2" , "Overlay2" ), |
| 2981 | (Self::PERMAMENT_LOCK.0.into(), "PERMAMENT_LOCK" , "PermamentLock" ), |
| 2982 | (Self::PERMAMENT_RADIO_GROUP.0.into(), "PERMAMENT_RADIO_GROUP" , "PermamentRadioGroup" ), |
| 2983 | (Self::PERMAMENT_OVERLAY1.0.into(), "PERMAMENT_OVERLAY1" , "PermamentOverlay1" ), |
| 2984 | (Self::PERMAMENT_OVERLAY2.0.into(), "PERMAMENT_OVERLAY2" , "PermamentOverlay2" ), |
| 2985 | ]; |
| 2986 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 2987 | } |
| 2988 | } |
| 2989 | |
| 2990 | #[derive (Clone, Copy)] |
| 2991 | #[cfg_attr (feature = "extra-traits" , derive(Debug))] |
| 2992 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 2993 | pub struct SetBehavior { |
| 2994 | pub keycode: xproto::Keycode, |
| 2995 | pub behavior: Behavior, |
| 2996 | } |
| 2997 | impl_debug_if_no_extra_traits!(SetBehavior, "SetBehavior" ); |
| 2998 | impl TryParse for SetBehavior { |
| 2999 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3000 | let (keycode: u8, remaining: &[u8]) = xproto::Keycode::try_parse(remaining)?; |
| 3001 | let (behavior: Behavior, remaining: &[u8]) = Behavior::try_parse(remaining)?; |
| 3002 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 3003 | let result: SetBehavior = SetBehavior { keycode, behavior }; |
| 3004 | Ok((result, remaining)) |
| 3005 | } |
| 3006 | } |
| 3007 | impl Serialize for SetBehavior { |
| 3008 | type Bytes = [u8; 4]; |
| 3009 | fn serialize(&self) -> [u8; 4] { |
| 3010 | let keycode_bytes: [u8; 1] = self.keycode.serialize(); |
| 3011 | let behavior_bytes: [u8; 2] = self.behavior.serialize(); |
| 3012 | [ |
| 3013 | keycode_bytes[0], |
| 3014 | behavior_bytes[0], |
| 3015 | behavior_bytes[1], |
| 3016 | 0, |
| 3017 | ] |
| 3018 | } |
| 3019 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3020 | bytes.reserve(additional:4); |
| 3021 | self.keycode.serialize_into(bytes); |
| 3022 | self.behavior.serialize_into(bytes); |
| 3023 | bytes.extend_from_slice(&[0; 1]); |
| 3024 | } |
| 3025 | } |
| 3026 | |
| 3027 | #[derive (Clone, Copy, Default)] |
| 3028 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3029 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3030 | pub struct SetExplicit { |
| 3031 | pub keycode: xproto::Keycode, |
| 3032 | pub explicit: Explicit, |
| 3033 | } |
| 3034 | impl_debug_if_no_extra_traits!(SetExplicit, "SetExplicit" ); |
| 3035 | impl TryParse for SetExplicit { |
| 3036 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3037 | let (keycode: u8, remaining: &[u8]) = xproto::Keycode::try_parse(remaining)?; |
| 3038 | let (explicit: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3039 | let explicit: Explicit = explicit.into(); |
| 3040 | let result: SetExplicit = SetExplicit { keycode, explicit }; |
| 3041 | Ok((result, remaining)) |
| 3042 | } |
| 3043 | } |
| 3044 | impl Serialize for SetExplicit { |
| 3045 | type Bytes = [u8; 2]; |
| 3046 | fn serialize(&self) -> [u8; 2] { |
| 3047 | let keycode_bytes: [u8; 1] = self.keycode.serialize(); |
| 3048 | let explicit_bytes: [u8; 1] = u8::from(self.explicit).serialize(); |
| 3049 | [ |
| 3050 | keycode_bytes[0], |
| 3051 | explicit_bytes[0], |
| 3052 | ] |
| 3053 | } |
| 3054 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3055 | bytes.reserve(additional:2); |
| 3056 | self.keycode.serialize_into(bytes); |
| 3057 | u8::from(self.explicit).serialize_into(bytes); |
| 3058 | } |
| 3059 | } |
| 3060 | |
| 3061 | #[derive (Clone, Copy, Default)] |
| 3062 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3063 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3064 | pub struct KeyModMap { |
| 3065 | pub keycode: xproto::Keycode, |
| 3066 | pub mods: xproto::ModMask, |
| 3067 | } |
| 3068 | impl_debug_if_no_extra_traits!(KeyModMap, "KeyModMap" ); |
| 3069 | impl TryParse for KeyModMap { |
| 3070 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3071 | let (keycode: u8, remaining: &[u8]) = xproto::Keycode::try_parse(remaining)?; |
| 3072 | let (mods: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3073 | let mods: ModMask = mods.into(); |
| 3074 | let result: KeyModMap = KeyModMap { keycode, mods }; |
| 3075 | Ok((result, remaining)) |
| 3076 | } |
| 3077 | } |
| 3078 | impl Serialize for KeyModMap { |
| 3079 | type Bytes = [u8; 2]; |
| 3080 | fn serialize(&self) -> [u8; 2] { |
| 3081 | let keycode_bytes: [u8; 1] = self.keycode.serialize(); |
| 3082 | let mods_bytes: [u8; 1] = (u16::from(self.mods) as u8).serialize(); |
| 3083 | [ |
| 3084 | keycode_bytes[0], |
| 3085 | mods_bytes[0], |
| 3086 | ] |
| 3087 | } |
| 3088 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3089 | bytes.reserve(additional:2); |
| 3090 | self.keycode.serialize_into(bytes); |
| 3091 | (u16::from(self.mods) as u8).serialize_into(bytes); |
| 3092 | } |
| 3093 | } |
| 3094 | |
| 3095 | #[derive (Clone, Copy, Default)] |
| 3096 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3097 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3098 | pub struct KeyVModMap { |
| 3099 | pub keycode: xproto::Keycode, |
| 3100 | pub vmods: VMod, |
| 3101 | } |
| 3102 | impl_debug_if_no_extra_traits!(KeyVModMap, "KeyVModMap" ); |
| 3103 | impl TryParse for KeyVModMap { |
| 3104 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3105 | let (keycode: u8, remaining: &[u8]) = xproto::Keycode::try_parse(remaining)?; |
| 3106 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 3107 | let (vmods: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 3108 | let vmods: VMod = vmods.into(); |
| 3109 | let result: KeyVModMap = KeyVModMap { keycode, vmods }; |
| 3110 | Ok((result, remaining)) |
| 3111 | } |
| 3112 | } |
| 3113 | impl Serialize for KeyVModMap { |
| 3114 | type Bytes = [u8; 4]; |
| 3115 | fn serialize(&self) -> [u8; 4] { |
| 3116 | let keycode_bytes: [u8; 1] = self.keycode.serialize(); |
| 3117 | let vmods_bytes: [u8; 2] = u16::from(self.vmods).serialize(); |
| 3118 | [ |
| 3119 | keycode_bytes[0], |
| 3120 | 0, |
| 3121 | vmods_bytes[0], |
| 3122 | vmods_bytes[1], |
| 3123 | ] |
| 3124 | } |
| 3125 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3126 | bytes.reserve(additional:4); |
| 3127 | self.keycode.serialize_into(bytes); |
| 3128 | bytes.extend_from_slice(&[0; 1]); |
| 3129 | u16::from(self.vmods).serialize_into(bytes); |
| 3130 | } |
| 3131 | } |
| 3132 | |
| 3133 | #[derive (Clone, Copy, Default)] |
| 3134 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3135 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3136 | pub struct KTSetMapEntry { |
| 3137 | pub level: u8, |
| 3138 | pub real_mods: xproto::ModMask, |
| 3139 | pub virtual_mods: VMod, |
| 3140 | } |
| 3141 | impl_debug_if_no_extra_traits!(KTSetMapEntry, "KTSetMapEntry" ); |
| 3142 | impl TryParse for KTSetMapEntry { |
| 3143 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3144 | let (level: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3145 | let (real_mods: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3146 | let (virtual_mods: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 3147 | let real_mods: ModMask = real_mods.into(); |
| 3148 | let virtual_mods: VMod = virtual_mods.into(); |
| 3149 | let result: KTSetMapEntry = KTSetMapEntry { level, real_mods, virtual_mods }; |
| 3150 | Ok((result, remaining)) |
| 3151 | } |
| 3152 | } |
| 3153 | impl Serialize for KTSetMapEntry { |
| 3154 | type Bytes = [u8; 4]; |
| 3155 | fn serialize(&self) -> [u8; 4] { |
| 3156 | let level_bytes: [u8; 1] = self.level.serialize(); |
| 3157 | let real_mods_bytes: [u8; 1] = (u16::from(self.real_mods) as u8).serialize(); |
| 3158 | let virtual_mods_bytes: [u8; 2] = u16::from(self.virtual_mods).serialize(); |
| 3159 | [ |
| 3160 | level_bytes[0], |
| 3161 | real_mods_bytes[0], |
| 3162 | virtual_mods_bytes[0], |
| 3163 | virtual_mods_bytes[1], |
| 3164 | ] |
| 3165 | } |
| 3166 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3167 | bytes.reserve(additional:4); |
| 3168 | self.level.serialize_into(bytes); |
| 3169 | (u16::from(self.real_mods) as u8).serialize_into(bytes); |
| 3170 | u16::from(self.virtual_mods).serialize_into(bytes); |
| 3171 | } |
| 3172 | } |
| 3173 | |
| 3174 | #[derive (Clone, Default)] |
| 3175 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3176 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3177 | pub struct SetKeyType { |
| 3178 | pub mask: xproto::ModMask, |
| 3179 | pub real_mods: xproto::ModMask, |
| 3180 | pub virtual_mods: VMod, |
| 3181 | pub num_levels: u8, |
| 3182 | pub preserve: bool, |
| 3183 | pub entries: Vec<KTSetMapEntry>, |
| 3184 | pub preserve_entries: Vec<KTSetMapEntry>, |
| 3185 | } |
| 3186 | impl_debug_if_no_extra_traits!(SetKeyType, "SetKeyType" ); |
| 3187 | impl TryParse for SetKeyType { |
| 3188 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3189 | let (mask: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3190 | let (real_mods: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3191 | let (virtual_mods: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 3192 | let (num_levels: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3193 | let (n_map_entries: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3194 | let (preserve: bool, remaining: &[u8]) = bool::try_parse(remaining)?; |
| 3195 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 3196 | let (entries: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<KTSetMapEntry>(data:remaining, list_length:n_map_entries.try_to_usize()?)?; |
| 3197 | let (preserve_entries: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<KTSetMapEntry>(data:remaining, list_length:u32::from(preserve).checked_mul(u32::from(n_map_entries)).ok_or(err:ParseError::InvalidExpression)?.try_to_usize()?)?; |
| 3198 | let mask: ModMask = mask.into(); |
| 3199 | let real_mods: ModMask = real_mods.into(); |
| 3200 | let virtual_mods: VMod = virtual_mods.into(); |
| 3201 | let result: SetKeyType = SetKeyType { mask, real_mods, virtual_mods, num_levels, preserve, entries, preserve_entries }; |
| 3202 | Ok((result, remaining)) |
| 3203 | } |
| 3204 | } |
| 3205 | impl Serialize for SetKeyType { |
| 3206 | type Bytes = Vec<u8>; |
| 3207 | fn serialize(&self) -> Vec<u8> { |
| 3208 | let mut result: Vec = Vec::new(); |
| 3209 | self.serialize_into(&mut result); |
| 3210 | result |
| 3211 | } |
| 3212 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3213 | bytes.reserve(additional:8); |
| 3214 | (u16::from(self.mask) as u8).serialize_into(bytes); |
| 3215 | (u16::from(self.real_mods) as u8).serialize_into(bytes); |
| 3216 | u16::from(self.virtual_mods).serialize_into(bytes); |
| 3217 | self.num_levels.serialize_into(bytes); |
| 3218 | let n_map_entries: u8 = u8::try_from(self.entries.len()).expect(msg:"`entries` has too many elements" ); |
| 3219 | n_map_entries.serialize_into(bytes); |
| 3220 | self.preserve.serialize_into(bytes); |
| 3221 | bytes.extend_from_slice(&[0; 1]); |
| 3222 | self.entries.serialize_into(bytes); |
| 3223 | 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" ); |
| 3224 | self.preserve_entries.serialize_into(bytes); |
| 3225 | } |
| 3226 | } |
| 3227 | impl SetKeyType { |
| 3228 | /// Get the value of the `nMapEntries` field. |
| 3229 | /// |
| 3230 | /// The `nMapEntries` field is used as the length field of the `entries` field. |
| 3231 | /// This function computes the field's value again based on the length of the list. |
| 3232 | /// |
| 3233 | /// # Panics |
| 3234 | /// |
| 3235 | /// Panics if the value cannot be represented in the target type. This |
| 3236 | /// cannot happen with values of the struct received from the X11 server. |
| 3237 | pub fn n_map_entries(&self) -> u8 { |
| 3238 | self.entries.len() |
| 3239 | .try_into().unwrap() |
| 3240 | } |
| 3241 | } |
| 3242 | |
| 3243 | pub type String8 = u8; |
| 3244 | |
| 3245 | #[derive (Clone, Default)] |
| 3246 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3247 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3248 | pub struct Outline { |
| 3249 | pub corner_radius: u8, |
| 3250 | pub points: Vec<xproto::Point>, |
| 3251 | } |
| 3252 | impl_debug_if_no_extra_traits!(Outline, "Outline" ); |
| 3253 | impl TryParse for Outline { |
| 3254 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3255 | let (n_points: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3256 | let (corner_radius: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3257 | let remaining: &[u8] = remaining.get(2..).ok_or(err:ParseError::InsufficientData)?; |
| 3258 | let (points: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<xproto::Point>(data:remaining, list_length:n_points.try_to_usize()?)?; |
| 3259 | let result: Outline = Outline { corner_radius, points }; |
| 3260 | Ok((result, remaining)) |
| 3261 | } |
| 3262 | } |
| 3263 | impl Serialize for Outline { |
| 3264 | type Bytes = Vec<u8>; |
| 3265 | fn serialize(&self) -> Vec<u8> { |
| 3266 | let mut result: Vec = Vec::new(); |
| 3267 | self.serialize_into(&mut result); |
| 3268 | result |
| 3269 | } |
| 3270 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3271 | bytes.reserve(additional:4); |
| 3272 | let n_points: u8 = u8::try_from(self.points.len()).expect(msg:"`points` has too many elements" ); |
| 3273 | n_points.serialize_into(bytes); |
| 3274 | self.corner_radius.serialize_into(bytes); |
| 3275 | bytes.extend_from_slice(&[0; 2]); |
| 3276 | self.points.serialize_into(bytes); |
| 3277 | } |
| 3278 | } |
| 3279 | impl Outline { |
| 3280 | /// Get the value of the `nPoints` field. |
| 3281 | /// |
| 3282 | /// The `nPoints` field is used as the length field of the `points` field. |
| 3283 | /// This function computes the field's value again based on the length of the list. |
| 3284 | /// |
| 3285 | /// # Panics |
| 3286 | /// |
| 3287 | /// Panics if the value cannot be represented in the target type. This |
| 3288 | /// cannot happen with values of the struct received from the X11 server. |
| 3289 | pub fn n_points(&self) -> u8 { |
| 3290 | self.points.len() |
| 3291 | .try_into().unwrap() |
| 3292 | } |
| 3293 | } |
| 3294 | |
| 3295 | #[derive (Clone, Default)] |
| 3296 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3297 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3298 | pub struct Shape { |
| 3299 | pub name: xproto::Atom, |
| 3300 | pub primary_ndx: u8, |
| 3301 | pub approx_ndx: u8, |
| 3302 | pub outlines: Vec<Outline>, |
| 3303 | } |
| 3304 | impl_debug_if_no_extra_traits!(Shape, "Shape" ); |
| 3305 | impl TryParse for Shape { |
| 3306 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3307 | let (name: u32, remaining: &[u8]) = xproto::Atom::try_parse(remaining)?; |
| 3308 | let (n_outlines: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3309 | let (primary_ndx: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3310 | let (approx_ndx: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3311 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 3312 | let (outlines: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<Outline>(data:remaining, list_length:n_outlines.try_to_usize()?)?; |
| 3313 | let result: Shape = Shape { name, primary_ndx, approx_ndx, outlines }; |
| 3314 | Ok((result, remaining)) |
| 3315 | } |
| 3316 | } |
| 3317 | impl Serialize for Shape { |
| 3318 | type Bytes = Vec<u8>; |
| 3319 | fn serialize(&self) -> Vec<u8> { |
| 3320 | let mut result: Vec = Vec::new(); |
| 3321 | self.serialize_into(&mut result); |
| 3322 | result |
| 3323 | } |
| 3324 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3325 | bytes.reserve(additional:8); |
| 3326 | self.name.serialize_into(bytes); |
| 3327 | let n_outlines: u8 = u8::try_from(self.outlines.len()).expect(msg:"`outlines` has too many elements" ); |
| 3328 | n_outlines.serialize_into(bytes); |
| 3329 | self.primary_ndx.serialize_into(bytes); |
| 3330 | self.approx_ndx.serialize_into(bytes); |
| 3331 | bytes.extend_from_slice(&[0; 1]); |
| 3332 | self.outlines.serialize_into(bytes); |
| 3333 | } |
| 3334 | } |
| 3335 | impl Shape { |
| 3336 | /// Get the value of the `nOutlines` field. |
| 3337 | /// |
| 3338 | /// The `nOutlines` field is used as the length field of the `outlines` field. |
| 3339 | /// This function computes the field's value again based on the length of the list. |
| 3340 | /// |
| 3341 | /// # Panics |
| 3342 | /// |
| 3343 | /// Panics if the value cannot be represented in the target type. This |
| 3344 | /// cannot happen with values of the struct received from the X11 server. |
| 3345 | pub fn n_outlines(&self) -> u8 { |
| 3346 | self.outlines.len() |
| 3347 | .try_into().unwrap() |
| 3348 | } |
| 3349 | } |
| 3350 | |
| 3351 | #[derive (Clone, Copy, Default)] |
| 3352 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3353 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3354 | pub struct Key { |
| 3355 | pub name: [String8; 4], |
| 3356 | pub gap: i16, |
| 3357 | pub shape_ndx: u8, |
| 3358 | pub color_ndx: u8, |
| 3359 | } |
| 3360 | impl_debug_if_no_extra_traits!(Key, "Key" ); |
| 3361 | impl TryParse for Key { |
| 3362 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3363 | let (name: [u8; 4], remaining: &[u8]) = crate::x11_utils::parse_u8_array::<4>(data:remaining)?; |
| 3364 | let (gap: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 3365 | let (shape_ndx: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3366 | let (color_ndx: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3367 | let result: Key = Key { name, gap, shape_ndx, color_ndx }; |
| 3368 | Ok((result, remaining)) |
| 3369 | } |
| 3370 | } |
| 3371 | impl Serialize for Key { |
| 3372 | type Bytes = [u8; 8]; |
| 3373 | fn serialize(&self) -> [u8; 8] { |
| 3374 | let gap_bytes = self.gap.serialize(); |
| 3375 | let shape_ndx_bytes = self.shape_ndx.serialize(); |
| 3376 | let color_ndx_bytes = self.color_ndx.serialize(); |
| 3377 | [ |
| 3378 | self.name[0], |
| 3379 | self.name[1], |
| 3380 | self.name[2], |
| 3381 | self.name[3], |
| 3382 | gap_bytes[0], |
| 3383 | gap_bytes[1], |
| 3384 | shape_ndx_bytes[0], |
| 3385 | color_ndx_bytes[0], |
| 3386 | ] |
| 3387 | } |
| 3388 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3389 | bytes.reserve(8); |
| 3390 | bytes.extend_from_slice(&self.name); |
| 3391 | self.gap.serialize_into(bytes); |
| 3392 | self.shape_ndx.serialize_into(bytes); |
| 3393 | self.color_ndx.serialize_into(bytes); |
| 3394 | } |
| 3395 | } |
| 3396 | |
| 3397 | #[derive (Clone, Copy, Default)] |
| 3398 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3399 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3400 | pub struct OverlayKey { |
| 3401 | pub over: [String8; 4], |
| 3402 | pub under: [String8; 4], |
| 3403 | } |
| 3404 | impl_debug_if_no_extra_traits!(OverlayKey, "OverlayKey" ); |
| 3405 | impl TryParse for OverlayKey { |
| 3406 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3407 | let (over: [u8; 4], remaining: &[u8]) = crate::x11_utils::parse_u8_array::<4>(data:remaining)?; |
| 3408 | let (under: [u8; 4], remaining: &[u8]) = crate::x11_utils::parse_u8_array::<4>(data:remaining)?; |
| 3409 | let result: OverlayKey = OverlayKey { over, under }; |
| 3410 | Ok((result, remaining)) |
| 3411 | } |
| 3412 | } |
| 3413 | impl Serialize for OverlayKey { |
| 3414 | type Bytes = [u8; 8]; |
| 3415 | fn serialize(&self) -> [u8; 8] { |
| 3416 | [ |
| 3417 | self.over[0], |
| 3418 | self.over[1], |
| 3419 | self.over[2], |
| 3420 | self.over[3], |
| 3421 | self.under[0], |
| 3422 | self.under[1], |
| 3423 | self.under[2], |
| 3424 | self.under[3], |
| 3425 | ] |
| 3426 | } |
| 3427 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3428 | bytes.reserve(additional:8); |
| 3429 | bytes.extend_from_slice(&self.over); |
| 3430 | bytes.extend_from_slice(&self.under); |
| 3431 | } |
| 3432 | } |
| 3433 | |
| 3434 | #[derive (Clone, Default)] |
| 3435 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3436 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3437 | pub struct OverlayRow { |
| 3438 | pub row_under: u8, |
| 3439 | pub keys: Vec<OverlayKey>, |
| 3440 | } |
| 3441 | impl_debug_if_no_extra_traits!(OverlayRow, "OverlayRow" ); |
| 3442 | impl TryParse for OverlayRow { |
| 3443 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3444 | let (row_under: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3445 | let (n_keys: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3446 | let remaining: &[u8] = remaining.get(2..).ok_or(err:ParseError::InsufficientData)?; |
| 3447 | let (keys: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<OverlayKey>(data:remaining, list_length:n_keys.try_to_usize()?)?; |
| 3448 | let result: OverlayRow = OverlayRow { row_under, keys }; |
| 3449 | Ok((result, remaining)) |
| 3450 | } |
| 3451 | } |
| 3452 | impl Serialize for OverlayRow { |
| 3453 | type Bytes = Vec<u8>; |
| 3454 | fn serialize(&self) -> Vec<u8> { |
| 3455 | let mut result: Vec = Vec::new(); |
| 3456 | self.serialize_into(&mut result); |
| 3457 | result |
| 3458 | } |
| 3459 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3460 | bytes.reserve(additional:4); |
| 3461 | self.row_under.serialize_into(bytes); |
| 3462 | let n_keys: u8 = u8::try_from(self.keys.len()).expect(msg:"`keys` has too many elements" ); |
| 3463 | n_keys.serialize_into(bytes); |
| 3464 | bytes.extend_from_slice(&[0; 2]); |
| 3465 | self.keys.serialize_into(bytes); |
| 3466 | } |
| 3467 | } |
| 3468 | impl OverlayRow { |
| 3469 | /// Get the value of the `nKeys` field. |
| 3470 | /// |
| 3471 | /// The `nKeys` field is used as the length field of the `keys` field. |
| 3472 | /// This function computes the field's value again based on the length of the list. |
| 3473 | /// |
| 3474 | /// # Panics |
| 3475 | /// |
| 3476 | /// Panics if the value cannot be represented in the target type. This |
| 3477 | /// cannot happen with values of the struct received from the X11 server. |
| 3478 | pub fn n_keys(&self) -> u8 { |
| 3479 | self.keys.len() |
| 3480 | .try_into().unwrap() |
| 3481 | } |
| 3482 | } |
| 3483 | |
| 3484 | #[derive (Clone, Default)] |
| 3485 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3486 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3487 | pub struct Overlay { |
| 3488 | pub name: xproto::Atom, |
| 3489 | pub rows: Vec<OverlayRow>, |
| 3490 | } |
| 3491 | impl_debug_if_no_extra_traits!(Overlay, "Overlay" ); |
| 3492 | impl TryParse for Overlay { |
| 3493 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3494 | let (name: u32, remaining: &[u8]) = xproto::Atom::try_parse(remaining)?; |
| 3495 | let (n_rows: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3496 | let remaining: &[u8] = remaining.get(3..).ok_or(err:ParseError::InsufficientData)?; |
| 3497 | let (rows: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<OverlayRow>(data:remaining, list_length:n_rows.try_to_usize()?)?; |
| 3498 | let result: Overlay = Overlay { name, rows }; |
| 3499 | Ok((result, remaining)) |
| 3500 | } |
| 3501 | } |
| 3502 | impl Serialize for Overlay { |
| 3503 | type Bytes = Vec<u8>; |
| 3504 | fn serialize(&self) -> Vec<u8> { |
| 3505 | let mut result: Vec = Vec::new(); |
| 3506 | self.serialize_into(&mut result); |
| 3507 | result |
| 3508 | } |
| 3509 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3510 | bytes.reserve(additional:8); |
| 3511 | self.name.serialize_into(bytes); |
| 3512 | let n_rows: u8 = u8::try_from(self.rows.len()).expect(msg:"`rows` has too many elements" ); |
| 3513 | n_rows.serialize_into(bytes); |
| 3514 | bytes.extend_from_slice(&[0; 3]); |
| 3515 | self.rows.serialize_into(bytes); |
| 3516 | } |
| 3517 | } |
| 3518 | impl Overlay { |
| 3519 | /// Get the value of the `nRows` field. |
| 3520 | /// |
| 3521 | /// The `nRows` field is used as the length field of the `rows` field. |
| 3522 | /// This function computes the field's value again based on the length of the list. |
| 3523 | /// |
| 3524 | /// # Panics |
| 3525 | /// |
| 3526 | /// Panics if the value cannot be represented in the target type. This |
| 3527 | /// cannot happen with values of the struct received from the X11 server. |
| 3528 | pub fn n_rows(&self) -> u8 { |
| 3529 | self.rows.len() |
| 3530 | .try_into().unwrap() |
| 3531 | } |
| 3532 | } |
| 3533 | |
| 3534 | #[derive (Clone, Default)] |
| 3535 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3536 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3537 | pub struct Row { |
| 3538 | pub top: i16, |
| 3539 | pub left: i16, |
| 3540 | pub vertical: bool, |
| 3541 | pub keys: Vec<Key>, |
| 3542 | } |
| 3543 | impl_debug_if_no_extra_traits!(Row, "Row" ); |
| 3544 | impl TryParse for Row { |
| 3545 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3546 | let (top: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 3547 | let (left: i16, remaining: &[u8]) = i16::try_parse(remaining)?; |
| 3548 | let (n_keys: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3549 | let (vertical: bool, remaining: &[u8]) = bool::try_parse(remaining)?; |
| 3550 | let remaining: &[u8] = remaining.get(2..).ok_or(err:ParseError::InsufficientData)?; |
| 3551 | let (keys: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<Key>(data:remaining, list_length:n_keys.try_to_usize()?)?; |
| 3552 | let result: Row = Row { top, left, vertical, keys }; |
| 3553 | Ok((result, remaining)) |
| 3554 | } |
| 3555 | } |
| 3556 | impl Serialize for Row { |
| 3557 | type Bytes = Vec<u8>; |
| 3558 | fn serialize(&self) -> Vec<u8> { |
| 3559 | let mut result: Vec = Vec::new(); |
| 3560 | self.serialize_into(&mut result); |
| 3561 | result |
| 3562 | } |
| 3563 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3564 | bytes.reserve(additional:8); |
| 3565 | self.top.serialize_into(bytes); |
| 3566 | self.left.serialize_into(bytes); |
| 3567 | let n_keys: u8 = u8::try_from(self.keys.len()).expect(msg:"`keys` has too many elements" ); |
| 3568 | n_keys.serialize_into(bytes); |
| 3569 | self.vertical.serialize_into(bytes); |
| 3570 | bytes.extend_from_slice(&[0; 2]); |
| 3571 | self.keys.serialize_into(bytes); |
| 3572 | } |
| 3573 | } |
| 3574 | impl Row { |
| 3575 | /// Get the value of the `nKeys` field. |
| 3576 | /// |
| 3577 | /// The `nKeys` field is used as the length field of the `keys` field. |
| 3578 | /// This function computes the field's value again based on the length of the list. |
| 3579 | /// |
| 3580 | /// # Panics |
| 3581 | /// |
| 3582 | /// Panics if the value cannot be represented in the target type. This |
| 3583 | /// cannot happen with values of the struct received from the X11 server. |
| 3584 | pub fn n_keys(&self) -> u8 { |
| 3585 | self.keys.len() |
| 3586 | .try_into().unwrap() |
| 3587 | } |
| 3588 | } |
| 3589 | |
| 3590 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 3591 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3592 | pub struct DoodadType(u8); |
| 3593 | impl DoodadType { |
| 3594 | pub const OUTLINE: Self = Self(1); |
| 3595 | pub const SOLID: Self = Self(2); |
| 3596 | pub const TEXT: Self = Self(3); |
| 3597 | pub const INDICATOR: Self = Self(4); |
| 3598 | pub const LOGO: Self = Self(5); |
| 3599 | } |
| 3600 | impl From<DoodadType> for u8 { |
| 3601 | #[inline ] |
| 3602 | fn from(input: DoodadType) -> Self { |
| 3603 | input.0 |
| 3604 | } |
| 3605 | } |
| 3606 | impl From<DoodadType> for Option<u8> { |
| 3607 | #[inline ] |
| 3608 | fn from(input: DoodadType) -> Self { |
| 3609 | Some(input.0) |
| 3610 | } |
| 3611 | } |
| 3612 | impl From<DoodadType> for u16 { |
| 3613 | #[inline ] |
| 3614 | fn from(input: DoodadType) -> Self { |
| 3615 | u16::from(input.0) |
| 3616 | } |
| 3617 | } |
| 3618 | impl From<DoodadType> for Option<u16> { |
| 3619 | #[inline ] |
| 3620 | fn from(input: DoodadType) -> Self { |
| 3621 | Some(u16::from(input.0)) |
| 3622 | } |
| 3623 | } |
| 3624 | impl From<DoodadType> for u32 { |
| 3625 | #[inline ] |
| 3626 | fn from(input: DoodadType) -> Self { |
| 3627 | u32::from(input.0) |
| 3628 | } |
| 3629 | } |
| 3630 | impl From<DoodadType> for Option<u32> { |
| 3631 | #[inline ] |
| 3632 | fn from(input: DoodadType) -> Self { |
| 3633 | Some(u32::from(input.0)) |
| 3634 | } |
| 3635 | } |
| 3636 | impl From<u8> for DoodadType { |
| 3637 | #[inline ] |
| 3638 | fn from(value: u8) -> Self { |
| 3639 | Self(value) |
| 3640 | } |
| 3641 | } |
| 3642 | impl core::fmt::Debug for DoodadType { |
| 3643 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 3644 | let variants: [(u32, &'static str, &'static …); 5] = [ |
| 3645 | (Self::OUTLINE.0.into(), "OUTLINE" , "Outline" ), |
| 3646 | (Self::SOLID.0.into(), "SOLID" , "Solid" ), |
| 3647 | (Self::TEXT.0.into(), "TEXT" , "Text" ), |
| 3648 | (Self::INDICATOR.0.into(), "INDICATOR" , "Indicator" ), |
| 3649 | (Self::LOGO.0.into(), "LOGO" , "Logo" ), |
| 3650 | ]; |
| 3651 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 3652 | } |
| 3653 | } |
| 3654 | |
| 3655 | #[derive (Clone, Default)] |
| 3656 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3657 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3658 | pub struct Listing { |
| 3659 | pub flags: u16, |
| 3660 | pub string: Vec<String8>, |
| 3661 | } |
| 3662 | impl_debug_if_no_extra_traits!(Listing, "Listing" ); |
| 3663 | impl TryParse for Listing { |
| 3664 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3665 | let value: &[u8] = remaining; |
| 3666 | let (flags: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 3667 | let (length: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 3668 | let (string: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data:remaining, list_length:length.try_to_usize()?)?; |
| 3669 | let string: Vec = string.to_vec(); |
| 3670 | // Align offset to multiple of 2 |
| 3671 | let offset: usize = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 3672 | let misalignment: usize = (2 - (offset % 2)) % 2; |
| 3673 | let remaining: &[u8] = remaining.get(misalignment..).ok_or(err:ParseError::InsufficientData)?; |
| 3674 | let result: Listing = Listing { flags, string }; |
| 3675 | Ok((result, remaining)) |
| 3676 | } |
| 3677 | } |
| 3678 | impl Serialize for Listing { |
| 3679 | type Bytes = Vec<u8>; |
| 3680 | fn serialize(&self) -> Vec<u8> { |
| 3681 | let mut result: Vec = Vec::new(); |
| 3682 | self.serialize_into(&mut result); |
| 3683 | result |
| 3684 | } |
| 3685 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3686 | bytes.reserve(additional:4); |
| 3687 | self.flags.serialize_into(bytes); |
| 3688 | let length: u16 = u16::try_from(self.string.len()).expect(msg:"`string` has too many elements" ); |
| 3689 | length.serialize_into(bytes); |
| 3690 | bytes.extend_from_slice(&self.string); |
| 3691 | bytes.extend_from_slice(&[0; 1][..(2 - (bytes.len() % 2)) % 2]); |
| 3692 | } |
| 3693 | } |
| 3694 | impl Listing { |
| 3695 | /// Get the value of the `length` field. |
| 3696 | /// |
| 3697 | /// The `length` field is used as the length field of the `string` field. |
| 3698 | /// This function computes the field's value again based on the length of the list. |
| 3699 | /// |
| 3700 | /// # Panics |
| 3701 | /// |
| 3702 | /// Panics if the value cannot be represented in the target type. This |
| 3703 | /// cannot happen with values of the struct received from the X11 server. |
| 3704 | pub fn length(&self) -> u16 { |
| 3705 | self.string.len() |
| 3706 | .try_into().unwrap() |
| 3707 | } |
| 3708 | } |
| 3709 | |
| 3710 | #[derive (Clone, Default)] |
| 3711 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3712 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3713 | pub struct DeviceLedInfo { |
| 3714 | pub led_class: LedClass, |
| 3715 | pub led_id: IDSpec, |
| 3716 | pub names_present: u32, |
| 3717 | pub maps_present: u32, |
| 3718 | pub phys_indicators: u32, |
| 3719 | pub state: u32, |
| 3720 | pub names: Vec<xproto::Atom>, |
| 3721 | pub maps: Vec<IndicatorMap>, |
| 3722 | } |
| 3723 | impl_debug_if_no_extra_traits!(DeviceLedInfo, "DeviceLedInfo" ); |
| 3724 | impl TryParse for DeviceLedInfo { |
| 3725 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3726 | let (led_class: u16, remaining: &[u8]) = LedClassSpec::try_parse(remaining)?; |
| 3727 | let (led_id: u16, remaining: &[u8]) = IDSpec::try_parse(remaining)?; |
| 3728 | let (names_present: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 3729 | let (maps_present: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 3730 | let (phys_indicators: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 3731 | let (state: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 3732 | let (names: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<xproto::Atom>(data:remaining, list_length:u32::from(names_present).count_ones().try_to_usize()?)?; |
| 3733 | let (maps: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<IndicatorMap>(data:remaining, list_length:u32::from(maps_present).count_ones().try_to_usize()?)?; |
| 3734 | let led_class: LedClass = led_class.into(); |
| 3735 | let result: DeviceLedInfo = DeviceLedInfo { led_class, led_id, names_present, maps_present, phys_indicators, state, names, maps }; |
| 3736 | Ok((result, remaining)) |
| 3737 | } |
| 3738 | } |
| 3739 | impl Serialize for DeviceLedInfo { |
| 3740 | type Bytes = Vec<u8>; |
| 3741 | fn serialize(&self) -> Vec<u8> { |
| 3742 | let mut result: Vec = Vec::new(); |
| 3743 | self.serialize_into(&mut result); |
| 3744 | result |
| 3745 | } |
| 3746 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 3747 | bytes.reserve(additional:20); |
| 3748 | LedClassSpec::from(self.led_class).serialize_into(bytes); |
| 3749 | self.led_id.serialize_into(bytes); |
| 3750 | self.names_present.serialize_into(bytes); |
| 3751 | self.maps_present.serialize_into(bytes); |
| 3752 | self.phys_indicators.serialize_into(bytes); |
| 3753 | self.state.serialize_into(bytes); |
| 3754 | assert_eq!(self.names.len(), usize::try_from(u32::from(self.names_present).count_ones()).unwrap(), "`names` has an incorrect length" ); |
| 3755 | self.names.serialize_into(bytes); |
| 3756 | assert_eq!(self.maps.len(), usize::try_from(u32::from(self.maps_present).count_ones()).unwrap(), "`maps` has an incorrect length" ); |
| 3757 | self.maps.serialize_into(bytes); |
| 3758 | } |
| 3759 | } |
| 3760 | |
| 3761 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 3762 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3763 | pub struct Error(u8); |
| 3764 | impl Error { |
| 3765 | pub const BAD_DEVICE: Self = Self(255); |
| 3766 | pub const BAD_CLASS: Self = Self(254); |
| 3767 | pub const BAD_ID: Self = Self(253); |
| 3768 | } |
| 3769 | impl From<Error> for u8 { |
| 3770 | #[inline ] |
| 3771 | fn from(input: Error) -> Self { |
| 3772 | input.0 |
| 3773 | } |
| 3774 | } |
| 3775 | impl From<Error> for Option<u8> { |
| 3776 | #[inline ] |
| 3777 | fn from(input: Error) -> Self { |
| 3778 | Some(input.0) |
| 3779 | } |
| 3780 | } |
| 3781 | impl From<Error> for u16 { |
| 3782 | #[inline ] |
| 3783 | fn from(input: Error) -> Self { |
| 3784 | u16::from(input.0) |
| 3785 | } |
| 3786 | } |
| 3787 | impl From<Error> for Option<u16> { |
| 3788 | #[inline ] |
| 3789 | fn from(input: Error) -> Self { |
| 3790 | Some(u16::from(input.0)) |
| 3791 | } |
| 3792 | } |
| 3793 | impl From<Error> for u32 { |
| 3794 | #[inline ] |
| 3795 | fn from(input: Error) -> Self { |
| 3796 | u32::from(input.0) |
| 3797 | } |
| 3798 | } |
| 3799 | impl From<Error> for Option<u32> { |
| 3800 | #[inline ] |
| 3801 | fn from(input: Error) -> Self { |
| 3802 | Some(u32::from(input.0)) |
| 3803 | } |
| 3804 | } |
| 3805 | impl From<u8> for Error { |
| 3806 | #[inline ] |
| 3807 | fn from(value: u8) -> Self { |
| 3808 | Self(value) |
| 3809 | } |
| 3810 | } |
| 3811 | impl core::fmt::Debug for Error { |
| 3812 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 3813 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 3814 | (Self::BAD_DEVICE.0.into(), "BAD_DEVICE" , "BadDevice" ), |
| 3815 | (Self::BAD_CLASS.0.into(), "BAD_CLASS" , "BadClass" ), |
| 3816 | (Self::BAD_ID.0.into(), "BAD_ID" , "BadId" ), |
| 3817 | ]; |
| 3818 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 3819 | } |
| 3820 | } |
| 3821 | |
| 3822 | /// Opcode for the Keyboard error |
| 3823 | pub const KEYBOARD_ERROR: u8 = 0; |
| 3824 | |
| 3825 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 3826 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3827 | pub struct SA(u8); |
| 3828 | impl SA { |
| 3829 | pub const CLEAR_LOCKS: Self = Self(1 << 0); |
| 3830 | pub const LATCH_TO_LOCK: Self = Self(1 << 1); |
| 3831 | pub const USE_MOD_MAP_MODS: Self = Self(1 << 2); |
| 3832 | pub const GROUP_ABSOLUTE: Self = Self(1 << 2); |
| 3833 | } |
| 3834 | impl From<SA> for u8 { |
| 3835 | #[inline ] |
| 3836 | fn from(input: SA) -> Self { |
| 3837 | input.0 |
| 3838 | } |
| 3839 | } |
| 3840 | impl From<SA> for Option<u8> { |
| 3841 | #[inline ] |
| 3842 | fn from(input: SA) -> Self { |
| 3843 | Some(input.0) |
| 3844 | } |
| 3845 | } |
| 3846 | impl From<SA> for u16 { |
| 3847 | #[inline ] |
| 3848 | fn from(input: SA) -> Self { |
| 3849 | u16::from(input.0) |
| 3850 | } |
| 3851 | } |
| 3852 | impl From<SA> for Option<u16> { |
| 3853 | #[inline ] |
| 3854 | fn from(input: SA) -> Self { |
| 3855 | Some(u16::from(input.0)) |
| 3856 | } |
| 3857 | } |
| 3858 | impl From<SA> for u32 { |
| 3859 | #[inline ] |
| 3860 | fn from(input: SA) -> Self { |
| 3861 | u32::from(input.0) |
| 3862 | } |
| 3863 | } |
| 3864 | impl From<SA> for Option<u32> { |
| 3865 | #[inline ] |
| 3866 | fn from(input: SA) -> Self { |
| 3867 | Some(u32::from(input.0)) |
| 3868 | } |
| 3869 | } |
| 3870 | impl From<u8> for SA { |
| 3871 | #[inline ] |
| 3872 | fn from(value: u8) -> Self { |
| 3873 | Self(value) |
| 3874 | } |
| 3875 | } |
| 3876 | impl core::fmt::Debug for SA { |
| 3877 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 3878 | let variants: [(u32, &'static str, &'static …); 4] = [ |
| 3879 | (Self::CLEAR_LOCKS.0.into(), "CLEAR_LOCKS" , "ClearLocks" ), |
| 3880 | (Self::LATCH_TO_LOCK.0.into(), "LATCH_TO_LOCK" , "LatchToLock" ), |
| 3881 | (Self::USE_MOD_MAP_MODS.0.into(), "USE_MOD_MAP_MODS" , "UseModMapMods" ), |
| 3882 | (Self::GROUP_ABSOLUTE.0.into(), "GROUP_ABSOLUTE" , "GroupAbsolute" ), |
| 3883 | ]; |
| 3884 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 3885 | } |
| 3886 | } |
| 3887 | bitmask_binop!(SA, u8); |
| 3888 | |
| 3889 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 3890 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3891 | pub struct SAType(u8); |
| 3892 | impl SAType { |
| 3893 | pub const NO_ACTION: Self = Self(0); |
| 3894 | pub const SET_MODS: Self = Self(1); |
| 3895 | pub const LATCH_MODS: Self = Self(2); |
| 3896 | pub const LOCK_MODS: Self = Self(3); |
| 3897 | pub const SET_GROUP: Self = Self(4); |
| 3898 | pub const LATCH_GROUP: Self = Self(5); |
| 3899 | pub const LOCK_GROUP: Self = Self(6); |
| 3900 | pub const MOVE_PTR: Self = Self(7); |
| 3901 | pub const PTR_BTN: Self = Self(8); |
| 3902 | pub const LOCK_PTR_BTN: Self = Self(9); |
| 3903 | pub const SET_PTR_DFLT: Self = Self(10); |
| 3904 | pub const ISO_LOCK: Self = Self(11); |
| 3905 | pub const TERMINATE: Self = Self(12); |
| 3906 | pub const SWITCH_SCREEN: Self = Self(13); |
| 3907 | pub const SET_CONTROLS: Self = Self(14); |
| 3908 | pub const LOCK_CONTROLS: Self = Self(15); |
| 3909 | pub const ACTION_MESSAGE: Self = Self(16); |
| 3910 | pub const REDIRECT_KEY: Self = Self(17); |
| 3911 | pub const DEVICE_BTN: Self = Self(18); |
| 3912 | pub const LOCK_DEVICE_BTN: Self = Self(19); |
| 3913 | pub const DEVICE_VALUATOR: Self = Self(20); |
| 3914 | } |
| 3915 | impl From<SAType> for u8 { |
| 3916 | #[inline ] |
| 3917 | fn from(input: SAType) -> Self { |
| 3918 | input.0 |
| 3919 | } |
| 3920 | } |
| 3921 | impl From<SAType> for Option<u8> { |
| 3922 | #[inline ] |
| 3923 | fn from(input: SAType) -> Self { |
| 3924 | Some(input.0) |
| 3925 | } |
| 3926 | } |
| 3927 | impl From<SAType> for u16 { |
| 3928 | #[inline ] |
| 3929 | fn from(input: SAType) -> Self { |
| 3930 | u16::from(input.0) |
| 3931 | } |
| 3932 | } |
| 3933 | impl From<SAType> for Option<u16> { |
| 3934 | #[inline ] |
| 3935 | fn from(input: SAType) -> Self { |
| 3936 | Some(u16::from(input.0)) |
| 3937 | } |
| 3938 | } |
| 3939 | impl From<SAType> for u32 { |
| 3940 | #[inline ] |
| 3941 | fn from(input: SAType) -> Self { |
| 3942 | u32::from(input.0) |
| 3943 | } |
| 3944 | } |
| 3945 | impl From<SAType> for Option<u32> { |
| 3946 | #[inline ] |
| 3947 | fn from(input: SAType) -> Self { |
| 3948 | Some(u32::from(input.0)) |
| 3949 | } |
| 3950 | } |
| 3951 | impl From<u8> for SAType { |
| 3952 | #[inline ] |
| 3953 | fn from(value: u8) -> Self { |
| 3954 | Self(value) |
| 3955 | } |
| 3956 | } |
| 3957 | impl core::fmt::Debug for SAType { |
| 3958 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 3959 | let variants = [ |
| 3960 | (Self::NO_ACTION.0.into(), "NO_ACTION" , "NoAction" ), |
| 3961 | (Self::SET_MODS.0.into(), "SET_MODS" , "SetMods" ), |
| 3962 | (Self::LATCH_MODS.0.into(), "LATCH_MODS" , "LatchMods" ), |
| 3963 | (Self::LOCK_MODS.0.into(), "LOCK_MODS" , "LockMods" ), |
| 3964 | (Self::SET_GROUP.0.into(), "SET_GROUP" , "SetGroup" ), |
| 3965 | (Self::LATCH_GROUP.0.into(), "LATCH_GROUP" , "LatchGroup" ), |
| 3966 | (Self::LOCK_GROUP.0.into(), "LOCK_GROUP" , "LockGroup" ), |
| 3967 | (Self::MOVE_PTR.0.into(), "MOVE_PTR" , "MovePtr" ), |
| 3968 | (Self::PTR_BTN.0.into(), "PTR_BTN" , "PtrBtn" ), |
| 3969 | (Self::LOCK_PTR_BTN.0.into(), "LOCK_PTR_BTN" , "LockPtrBtn" ), |
| 3970 | (Self::SET_PTR_DFLT.0.into(), "SET_PTR_DFLT" , "SetPtrDflt" ), |
| 3971 | (Self::ISO_LOCK.0.into(), "ISO_LOCK" , "ISOLock" ), |
| 3972 | (Self::TERMINATE.0.into(), "TERMINATE" , "Terminate" ), |
| 3973 | (Self::SWITCH_SCREEN.0.into(), "SWITCH_SCREEN" , "SwitchScreen" ), |
| 3974 | (Self::SET_CONTROLS.0.into(), "SET_CONTROLS" , "SetControls" ), |
| 3975 | (Self::LOCK_CONTROLS.0.into(), "LOCK_CONTROLS" , "LockControls" ), |
| 3976 | (Self::ACTION_MESSAGE.0.into(), "ACTION_MESSAGE" , "ActionMessage" ), |
| 3977 | (Self::REDIRECT_KEY.0.into(), "REDIRECT_KEY" , "RedirectKey" ), |
| 3978 | (Self::DEVICE_BTN.0.into(), "DEVICE_BTN" , "DeviceBtn" ), |
| 3979 | (Self::LOCK_DEVICE_BTN.0.into(), "LOCK_DEVICE_BTN" , "LockDeviceBtn" ), |
| 3980 | (Self::DEVICE_VALUATOR.0.into(), "DEVICE_VALUATOR" , "DeviceValuator" ), |
| 3981 | ]; |
| 3982 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 3983 | } |
| 3984 | } |
| 3985 | |
| 3986 | #[derive (Clone, Copy, Default)] |
| 3987 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 3988 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 3989 | pub struct SANoAction { |
| 3990 | pub type_: SAType, |
| 3991 | } |
| 3992 | impl_debug_if_no_extra_traits!(SANoAction, "SANoAction" ); |
| 3993 | impl TryParse for SANoAction { |
| 3994 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 3995 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 3996 | let remaining: &[u8] = remaining.get(7..).ok_or(err:ParseError::InsufficientData)?; |
| 3997 | let type_: SAType = type_.into(); |
| 3998 | let result: SANoAction = SANoAction { type_ }; |
| 3999 | Ok((result, remaining)) |
| 4000 | } |
| 4001 | } |
| 4002 | impl Serialize for SANoAction { |
| 4003 | type Bytes = [u8; 8]; |
| 4004 | fn serialize(&self) -> [u8; 8] { |
| 4005 | let type_bytes: [u8; 1] = u8::from(self.type_).serialize(); |
| 4006 | [ |
| 4007 | type_bytes[0], |
| 4008 | 0, |
| 4009 | 0, |
| 4010 | 0, |
| 4011 | 0, |
| 4012 | 0, |
| 4013 | 0, |
| 4014 | 0, |
| 4015 | ] |
| 4016 | } |
| 4017 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 4018 | bytes.reserve(additional:8); |
| 4019 | u8::from(self.type_).serialize_into(bytes); |
| 4020 | bytes.extend_from_slice(&[0; 7]); |
| 4021 | } |
| 4022 | } |
| 4023 | |
| 4024 | #[derive (Clone, Copy, Default)] |
| 4025 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 4026 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4027 | pub struct SASetMods { |
| 4028 | pub type_: SAType, |
| 4029 | pub flags: SA, |
| 4030 | pub mask: xproto::ModMask, |
| 4031 | pub real_mods: xproto::ModMask, |
| 4032 | pub vmods_high: VModsHigh, |
| 4033 | pub vmods_low: VModsLow, |
| 4034 | } |
| 4035 | impl_debug_if_no_extra_traits!(SASetMods, "SASetMods" ); |
| 4036 | impl TryParse for SASetMods { |
| 4037 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 4038 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4039 | let (flags: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4040 | let (mask: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4041 | let (real_mods: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4042 | let (vmods_high: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4043 | let (vmods_low: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4044 | let remaining: &[u8] = remaining.get(2..).ok_or(err:ParseError::InsufficientData)?; |
| 4045 | let type_: SAType = type_.into(); |
| 4046 | let flags: SA = flags.into(); |
| 4047 | let mask: ModMask = mask.into(); |
| 4048 | let real_mods: ModMask = real_mods.into(); |
| 4049 | let vmods_high: VModsHigh = vmods_high.into(); |
| 4050 | let vmods_low: VModsLow = vmods_low.into(); |
| 4051 | let result: SASetMods = SASetMods { type_, flags, mask, real_mods, vmods_high, vmods_low }; |
| 4052 | Ok((result, remaining)) |
| 4053 | } |
| 4054 | } |
| 4055 | impl Serialize for SASetMods { |
| 4056 | type Bytes = [u8; 8]; |
| 4057 | fn serialize(&self) -> [u8; 8] { |
| 4058 | let type_bytes = u8::from(self.type_).serialize(); |
| 4059 | let flags_bytes = u8::from(self.flags).serialize(); |
| 4060 | let mask_bytes = (u16::from(self.mask) as u8).serialize(); |
| 4061 | let real_mods_bytes = (u16::from(self.real_mods) as u8).serialize(); |
| 4062 | let vmods_high_bytes = u8::from(self.vmods_high).serialize(); |
| 4063 | let vmods_low_bytes = u8::from(self.vmods_low).serialize(); |
| 4064 | [ |
| 4065 | type_bytes[0], |
| 4066 | flags_bytes[0], |
| 4067 | mask_bytes[0], |
| 4068 | real_mods_bytes[0], |
| 4069 | vmods_high_bytes[0], |
| 4070 | vmods_low_bytes[0], |
| 4071 | 0, |
| 4072 | 0, |
| 4073 | ] |
| 4074 | } |
| 4075 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 4076 | bytes.reserve(8); |
| 4077 | u8::from(self.type_).serialize_into(bytes); |
| 4078 | u8::from(self.flags).serialize_into(bytes); |
| 4079 | (u16::from(self.mask) as u8).serialize_into(bytes); |
| 4080 | (u16::from(self.real_mods) as u8).serialize_into(bytes); |
| 4081 | u8::from(self.vmods_high).serialize_into(bytes); |
| 4082 | u8::from(self.vmods_low).serialize_into(bytes); |
| 4083 | bytes.extend_from_slice(&[0; 2]); |
| 4084 | } |
| 4085 | } |
| 4086 | |
| 4087 | pub type SALatchMods = SASetMods; |
| 4088 | |
| 4089 | pub type SALockMods = SASetMods; |
| 4090 | |
| 4091 | #[derive (Clone, Copy, Default)] |
| 4092 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 4093 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4094 | pub struct SASetGroup { |
| 4095 | pub type_: SAType, |
| 4096 | pub flags: SA, |
| 4097 | pub group: i8, |
| 4098 | } |
| 4099 | impl_debug_if_no_extra_traits!(SASetGroup, "SASetGroup" ); |
| 4100 | impl TryParse for SASetGroup { |
| 4101 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 4102 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4103 | let (flags: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4104 | let (group: i8, remaining: &[u8]) = i8::try_parse(remaining)?; |
| 4105 | let remaining: &[u8] = remaining.get(5..).ok_or(err:ParseError::InsufficientData)?; |
| 4106 | let type_: SAType = type_.into(); |
| 4107 | let flags: SA = flags.into(); |
| 4108 | let result: SASetGroup = SASetGroup { type_, flags, group }; |
| 4109 | Ok((result, remaining)) |
| 4110 | } |
| 4111 | } |
| 4112 | impl Serialize for SASetGroup { |
| 4113 | type Bytes = [u8; 8]; |
| 4114 | fn serialize(&self) -> [u8; 8] { |
| 4115 | let type_bytes = u8::from(self.type_).serialize(); |
| 4116 | let flags_bytes = u8::from(self.flags).serialize(); |
| 4117 | let group_bytes = self.group.serialize(); |
| 4118 | [ |
| 4119 | type_bytes[0], |
| 4120 | flags_bytes[0], |
| 4121 | group_bytes[0], |
| 4122 | 0, |
| 4123 | 0, |
| 4124 | 0, |
| 4125 | 0, |
| 4126 | 0, |
| 4127 | ] |
| 4128 | } |
| 4129 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 4130 | bytes.reserve(8); |
| 4131 | u8::from(self.type_).serialize_into(bytes); |
| 4132 | u8::from(self.flags).serialize_into(bytes); |
| 4133 | self.group.serialize_into(bytes); |
| 4134 | bytes.extend_from_slice(&[0; 5]); |
| 4135 | } |
| 4136 | } |
| 4137 | |
| 4138 | pub type SALatchGroup = SASetGroup; |
| 4139 | |
| 4140 | pub type SALockGroup = SASetGroup; |
| 4141 | |
| 4142 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 4143 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4144 | pub struct SAMovePtrFlag(u8); |
| 4145 | impl SAMovePtrFlag { |
| 4146 | pub const NO_ACCELERATION: Self = Self(1 << 0); |
| 4147 | pub const MOVE_ABSOLUTE_X: Self = Self(1 << 1); |
| 4148 | pub const MOVE_ABSOLUTE_Y: Self = Self(1 << 2); |
| 4149 | } |
| 4150 | impl From<SAMovePtrFlag> for u8 { |
| 4151 | #[inline ] |
| 4152 | fn from(input: SAMovePtrFlag) -> Self { |
| 4153 | input.0 |
| 4154 | } |
| 4155 | } |
| 4156 | impl From<SAMovePtrFlag> for Option<u8> { |
| 4157 | #[inline ] |
| 4158 | fn from(input: SAMovePtrFlag) -> Self { |
| 4159 | Some(input.0) |
| 4160 | } |
| 4161 | } |
| 4162 | impl From<SAMovePtrFlag> for u16 { |
| 4163 | #[inline ] |
| 4164 | fn from(input: SAMovePtrFlag) -> Self { |
| 4165 | u16::from(input.0) |
| 4166 | } |
| 4167 | } |
| 4168 | impl From<SAMovePtrFlag> for Option<u16> { |
| 4169 | #[inline ] |
| 4170 | fn from(input: SAMovePtrFlag) -> Self { |
| 4171 | Some(u16::from(input.0)) |
| 4172 | } |
| 4173 | } |
| 4174 | impl From<SAMovePtrFlag> for u32 { |
| 4175 | #[inline ] |
| 4176 | fn from(input: SAMovePtrFlag) -> Self { |
| 4177 | u32::from(input.0) |
| 4178 | } |
| 4179 | } |
| 4180 | impl From<SAMovePtrFlag> for Option<u32> { |
| 4181 | #[inline ] |
| 4182 | fn from(input: SAMovePtrFlag) -> Self { |
| 4183 | Some(u32::from(input.0)) |
| 4184 | } |
| 4185 | } |
| 4186 | impl From<u8> for SAMovePtrFlag { |
| 4187 | #[inline ] |
| 4188 | fn from(value: u8) -> Self { |
| 4189 | Self(value) |
| 4190 | } |
| 4191 | } |
| 4192 | impl core::fmt::Debug for SAMovePtrFlag { |
| 4193 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 4194 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 4195 | (Self::NO_ACCELERATION.0.into(), "NO_ACCELERATION" , "NoAcceleration" ), |
| 4196 | (Self::MOVE_ABSOLUTE_X.0.into(), "MOVE_ABSOLUTE_X" , "MoveAbsoluteX" ), |
| 4197 | (Self::MOVE_ABSOLUTE_Y.0.into(), "MOVE_ABSOLUTE_Y" , "MoveAbsoluteY" ), |
| 4198 | ]; |
| 4199 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 4200 | } |
| 4201 | } |
| 4202 | bitmask_binop!(SAMovePtrFlag, u8); |
| 4203 | |
| 4204 | #[derive (Clone, Copy, Default)] |
| 4205 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 4206 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4207 | pub struct SAMovePtr { |
| 4208 | pub type_: SAType, |
| 4209 | pub flags: SAMovePtrFlag, |
| 4210 | pub x_high: i8, |
| 4211 | pub x_low: u8, |
| 4212 | pub y_high: i8, |
| 4213 | pub y_low: u8, |
| 4214 | } |
| 4215 | impl_debug_if_no_extra_traits!(SAMovePtr, "SAMovePtr" ); |
| 4216 | impl TryParse for SAMovePtr { |
| 4217 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 4218 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4219 | let (flags: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4220 | let (x_high: i8, remaining: &[u8]) = i8::try_parse(remaining)?; |
| 4221 | let (x_low: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4222 | let (y_high: i8, remaining: &[u8]) = i8::try_parse(remaining)?; |
| 4223 | let (y_low: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4224 | let remaining: &[u8] = remaining.get(2..).ok_or(err:ParseError::InsufficientData)?; |
| 4225 | let type_: SAType = type_.into(); |
| 4226 | let flags: SAMovePtrFlag = flags.into(); |
| 4227 | let result: SAMovePtr = SAMovePtr { type_, flags, x_high, x_low, y_high, y_low }; |
| 4228 | Ok((result, remaining)) |
| 4229 | } |
| 4230 | } |
| 4231 | impl Serialize for SAMovePtr { |
| 4232 | type Bytes = [u8; 8]; |
| 4233 | fn serialize(&self) -> [u8; 8] { |
| 4234 | let type_bytes = u8::from(self.type_).serialize(); |
| 4235 | let flags_bytes = u8::from(self.flags).serialize(); |
| 4236 | let x_high_bytes = self.x_high.serialize(); |
| 4237 | let x_low_bytes = self.x_low.serialize(); |
| 4238 | let y_high_bytes = self.y_high.serialize(); |
| 4239 | let y_low_bytes = self.y_low.serialize(); |
| 4240 | [ |
| 4241 | type_bytes[0], |
| 4242 | flags_bytes[0], |
| 4243 | x_high_bytes[0], |
| 4244 | x_low_bytes[0], |
| 4245 | y_high_bytes[0], |
| 4246 | y_low_bytes[0], |
| 4247 | 0, |
| 4248 | 0, |
| 4249 | ] |
| 4250 | } |
| 4251 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 4252 | bytes.reserve(8); |
| 4253 | u8::from(self.type_).serialize_into(bytes); |
| 4254 | u8::from(self.flags).serialize_into(bytes); |
| 4255 | self.x_high.serialize_into(bytes); |
| 4256 | self.x_low.serialize_into(bytes); |
| 4257 | self.y_high.serialize_into(bytes); |
| 4258 | self.y_low.serialize_into(bytes); |
| 4259 | bytes.extend_from_slice(&[0; 2]); |
| 4260 | } |
| 4261 | } |
| 4262 | |
| 4263 | #[derive (Clone, Copy, Default)] |
| 4264 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 4265 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4266 | pub struct SAPtrBtn { |
| 4267 | pub type_: SAType, |
| 4268 | pub flags: u8, |
| 4269 | pub count: u8, |
| 4270 | pub button: u8, |
| 4271 | } |
| 4272 | impl_debug_if_no_extra_traits!(SAPtrBtn, "SAPtrBtn" ); |
| 4273 | impl TryParse for SAPtrBtn { |
| 4274 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 4275 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4276 | let (flags: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4277 | let (count: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4278 | let (button: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4279 | let remaining: &[u8] = remaining.get(4..).ok_or(err:ParseError::InsufficientData)?; |
| 4280 | let type_: SAType = type_.into(); |
| 4281 | let result: SAPtrBtn = SAPtrBtn { type_, flags, count, button }; |
| 4282 | Ok((result, remaining)) |
| 4283 | } |
| 4284 | } |
| 4285 | impl Serialize for SAPtrBtn { |
| 4286 | type Bytes = [u8; 8]; |
| 4287 | fn serialize(&self) -> [u8; 8] { |
| 4288 | let type_bytes = u8::from(self.type_).serialize(); |
| 4289 | let flags_bytes = self.flags.serialize(); |
| 4290 | let count_bytes = self.count.serialize(); |
| 4291 | let button_bytes = self.button.serialize(); |
| 4292 | [ |
| 4293 | type_bytes[0], |
| 4294 | flags_bytes[0], |
| 4295 | count_bytes[0], |
| 4296 | button_bytes[0], |
| 4297 | 0, |
| 4298 | 0, |
| 4299 | 0, |
| 4300 | 0, |
| 4301 | ] |
| 4302 | } |
| 4303 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 4304 | bytes.reserve(8); |
| 4305 | u8::from(self.type_).serialize_into(bytes); |
| 4306 | self.flags.serialize_into(bytes); |
| 4307 | self.count.serialize_into(bytes); |
| 4308 | self.button.serialize_into(bytes); |
| 4309 | bytes.extend_from_slice(&[0; 4]); |
| 4310 | } |
| 4311 | } |
| 4312 | |
| 4313 | #[derive (Clone, Copy, Default)] |
| 4314 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 4315 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4316 | pub struct SALockPtrBtn { |
| 4317 | pub type_: SAType, |
| 4318 | pub flags: u8, |
| 4319 | pub button: u8, |
| 4320 | } |
| 4321 | impl_debug_if_no_extra_traits!(SALockPtrBtn, "SALockPtrBtn" ); |
| 4322 | impl TryParse for SALockPtrBtn { |
| 4323 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 4324 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4325 | let (flags: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4326 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 4327 | let (button: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4328 | let remaining: &[u8] = remaining.get(4..).ok_or(err:ParseError::InsufficientData)?; |
| 4329 | let type_: SAType = type_.into(); |
| 4330 | let result: SALockPtrBtn = SALockPtrBtn { type_, flags, button }; |
| 4331 | Ok((result, remaining)) |
| 4332 | } |
| 4333 | } |
| 4334 | impl Serialize for SALockPtrBtn { |
| 4335 | type Bytes = [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 button_bytes = self.button.serialize(); |
| 4340 | [ |
| 4341 | type_bytes[0], |
| 4342 | flags_bytes[0], |
| 4343 | 0, |
| 4344 | button_bytes[0], |
| 4345 | 0, |
| 4346 | 0, |
| 4347 | 0, |
| 4348 | 0, |
| 4349 | ] |
| 4350 | } |
| 4351 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 4352 | bytes.reserve(8); |
| 4353 | u8::from(self.type_).serialize_into(bytes); |
| 4354 | self.flags.serialize_into(bytes); |
| 4355 | bytes.extend_from_slice(&[0; 1]); |
| 4356 | self.button.serialize_into(bytes); |
| 4357 | bytes.extend_from_slice(&[0; 4]); |
| 4358 | } |
| 4359 | } |
| 4360 | |
| 4361 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 4362 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4363 | pub struct SASetPtrDfltFlag(u8); |
| 4364 | impl SASetPtrDfltFlag { |
| 4365 | pub const DFLT_BTN_ABSOLUTE: Self = Self(1 << 2); |
| 4366 | pub const AFFECT_DFLT_BUTTON: Self = Self(1 << 0); |
| 4367 | } |
| 4368 | impl From<SASetPtrDfltFlag> for u8 { |
| 4369 | #[inline ] |
| 4370 | fn from(input: SASetPtrDfltFlag) -> Self { |
| 4371 | input.0 |
| 4372 | } |
| 4373 | } |
| 4374 | impl From<SASetPtrDfltFlag> for Option<u8> { |
| 4375 | #[inline ] |
| 4376 | fn from(input: SASetPtrDfltFlag) -> Self { |
| 4377 | Some(input.0) |
| 4378 | } |
| 4379 | } |
| 4380 | impl From<SASetPtrDfltFlag> for u16 { |
| 4381 | #[inline ] |
| 4382 | fn from(input: SASetPtrDfltFlag) -> Self { |
| 4383 | u16::from(input.0) |
| 4384 | } |
| 4385 | } |
| 4386 | impl From<SASetPtrDfltFlag> for Option<u16> { |
| 4387 | #[inline ] |
| 4388 | fn from(input: SASetPtrDfltFlag) -> Self { |
| 4389 | Some(u16::from(input.0)) |
| 4390 | } |
| 4391 | } |
| 4392 | impl From<SASetPtrDfltFlag> for u32 { |
| 4393 | #[inline ] |
| 4394 | fn from(input: SASetPtrDfltFlag) -> Self { |
| 4395 | u32::from(input.0) |
| 4396 | } |
| 4397 | } |
| 4398 | impl From<SASetPtrDfltFlag> for Option<u32> { |
| 4399 | #[inline ] |
| 4400 | fn from(input: SASetPtrDfltFlag) -> Self { |
| 4401 | Some(u32::from(input.0)) |
| 4402 | } |
| 4403 | } |
| 4404 | impl From<u8> for SASetPtrDfltFlag { |
| 4405 | #[inline ] |
| 4406 | fn from(value: u8) -> Self { |
| 4407 | Self(value) |
| 4408 | } |
| 4409 | } |
| 4410 | impl core::fmt::Debug for SASetPtrDfltFlag { |
| 4411 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 4412 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 4413 | (Self::DFLT_BTN_ABSOLUTE.0.into(), "DFLT_BTN_ABSOLUTE" , "DfltBtnAbsolute" ), |
| 4414 | (Self::AFFECT_DFLT_BUTTON.0.into(), "AFFECT_DFLT_BUTTON" , "AffectDfltButton" ), |
| 4415 | ]; |
| 4416 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 4417 | } |
| 4418 | } |
| 4419 | bitmask_binop!(SASetPtrDfltFlag, u8); |
| 4420 | |
| 4421 | #[derive (Clone, Copy, Default)] |
| 4422 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 4423 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4424 | pub struct SASetPtrDflt { |
| 4425 | pub type_: SAType, |
| 4426 | pub flags: SASetPtrDfltFlag, |
| 4427 | pub affect: SASetPtrDfltFlag, |
| 4428 | pub value: i8, |
| 4429 | } |
| 4430 | impl_debug_if_no_extra_traits!(SASetPtrDflt, "SASetPtrDflt" ); |
| 4431 | impl TryParse for SASetPtrDflt { |
| 4432 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 4433 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4434 | let (flags: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4435 | let (affect: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4436 | let (value: i8, remaining: &[u8]) = i8::try_parse(remaining)?; |
| 4437 | let remaining: &[u8] = remaining.get(4..).ok_or(err:ParseError::InsufficientData)?; |
| 4438 | let type_: SAType = type_.into(); |
| 4439 | let flags: SASetPtrDfltFlag = flags.into(); |
| 4440 | let affect: SASetPtrDfltFlag = affect.into(); |
| 4441 | let result: SASetPtrDflt = SASetPtrDflt { type_, flags, affect, value }; |
| 4442 | Ok((result, remaining)) |
| 4443 | } |
| 4444 | } |
| 4445 | impl Serialize for SASetPtrDflt { |
| 4446 | type Bytes = [u8; 8]; |
| 4447 | fn serialize(&self) -> [u8; 8] { |
| 4448 | let type_bytes = u8::from(self.type_).serialize(); |
| 4449 | let flags_bytes = u8::from(self.flags).serialize(); |
| 4450 | let affect_bytes = u8::from(self.affect).serialize(); |
| 4451 | let value_bytes = self.value.serialize(); |
| 4452 | [ |
| 4453 | type_bytes[0], |
| 4454 | flags_bytes[0], |
| 4455 | affect_bytes[0], |
| 4456 | value_bytes[0], |
| 4457 | 0, |
| 4458 | 0, |
| 4459 | 0, |
| 4460 | 0, |
| 4461 | ] |
| 4462 | } |
| 4463 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 4464 | bytes.reserve(8); |
| 4465 | u8::from(self.type_).serialize_into(bytes); |
| 4466 | u8::from(self.flags).serialize_into(bytes); |
| 4467 | u8::from(self.affect).serialize_into(bytes); |
| 4468 | self.value.serialize_into(bytes); |
| 4469 | bytes.extend_from_slice(&[0; 4]); |
| 4470 | } |
| 4471 | } |
| 4472 | |
| 4473 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 4474 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4475 | pub struct SAIsoLockFlag(u8); |
| 4476 | impl SAIsoLockFlag { |
| 4477 | pub const NO_LOCK: Self = Self(1 << 0); |
| 4478 | pub const NO_UNLOCK: Self = Self(1 << 1); |
| 4479 | pub const USE_MOD_MAP_MODS: Self = Self(1 << 2); |
| 4480 | pub const GROUP_ABSOLUTE: Self = Self(1 << 2); |
| 4481 | pub const ISO_DFLT_IS_GROUP: Self = Self(1 << 3); |
| 4482 | } |
| 4483 | impl From<SAIsoLockFlag> for u8 { |
| 4484 | #[inline ] |
| 4485 | fn from(input: SAIsoLockFlag) -> Self { |
| 4486 | input.0 |
| 4487 | } |
| 4488 | } |
| 4489 | impl From<SAIsoLockFlag> for Option<u8> { |
| 4490 | #[inline ] |
| 4491 | fn from(input: SAIsoLockFlag) -> Self { |
| 4492 | Some(input.0) |
| 4493 | } |
| 4494 | } |
| 4495 | impl From<SAIsoLockFlag> for u16 { |
| 4496 | #[inline ] |
| 4497 | fn from(input: SAIsoLockFlag) -> Self { |
| 4498 | u16::from(input.0) |
| 4499 | } |
| 4500 | } |
| 4501 | impl From<SAIsoLockFlag> for Option<u16> { |
| 4502 | #[inline ] |
| 4503 | fn from(input: SAIsoLockFlag) -> Self { |
| 4504 | Some(u16::from(input.0)) |
| 4505 | } |
| 4506 | } |
| 4507 | impl From<SAIsoLockFlag> for u32 { |
| 4508 | #[inline ] |
| 4509 | fn from(input: SAIsoLockFlag) -> Self { |
| 4510 | u32::from(input.0) |
| 4511 | } |
| 4512 | } |
| 4513 | impl From<SAIsoLockFlag> for Option<u32> { |
| 4514 | #[inline ] |
| 4515 | fn from(input: SAIsoLockFlag) -> Self { |
| 4516 | Some(u32::from(input.0)) |
| 4517 | } |
| 4518 | } |
| 4519 | impl From<u8> for SAIsoLockFlag { |
| 4520 | #[inline ] |
| 4521 | fn from(value: u8) -> Self { |
| 4522 | Self(value) |
| 4523 | } |
| 4524 | } |
| 4525 | impl core::fmt::Debug for SAIsoLockFlag { |
| 4526 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 4527 | let variants: [(u32, &'static str, &'static …); 5] = [ |
| 4528 | (Self::NO_LOCK.0.into(), "NO_LOCK" , "NoLock" ), |
| 4529 | (Self::NO_UNLOCK.0.into(), "NO_UNLOCK" , "NoUnlock" ), |
| 4530 | (Self::USE_MOD_MAP_MODS.0.into(), "USE_MOD_MAP_MODS" , "UseModMapMods" ), |
| 4531 | (Self::GROUP_ABSOLUTE.0.into(), "GROUP_ABSOLUTE" , "GroupAbsolute" ), |
| 4532 | (Self::ISO_DFLT_IS_GROUP.0.into(), "ISO_DFLT_IS_GROUP" , "ISODfltIsGroup" ), |
| 4533 | ]; |
| 4534 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 4535 | } |
| 4536 | } |
| 4537 | bitmask_binop!(SAIsoLockFlag, u8); |
| 4538 | |
| 4539 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 4540 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4541 | pub struct SAIsoLockNoAffect(u8); |
| 4542 | impl SAIsoLockNoAffect { |
| 4543 | pub const CTRLS: Self = Self(1 << 3); |
| 4544 | pub const PTR: Self = Self(1 << 4); |
| 4545 | pub const GROUP: Self = Self(1 << 5); |
| 4546 | pub const MODS: Self = Self(1 << 6); |
| 4547 | } |
| 4548 | impl From<SAIsoLockNoAffect> for u8 { |
| 4549 | #[inline ] |
| 4550 | fn from(input: SAIsoLockNoAffect) -> Self { |
| 4551 | input.0 |
| 4552 | } |
| 4553 | } |
| 4554 | impl From<SAIsoLockNoAffect> for Option<u8> { |
| 4555 | #[inline ] |
| 4556 | fn from(input: SAIsoLockNoAffect) -> Self { |
| 4557 | Some(input.0) |
| 4558 | } |
| 4559 | } |
| 4560 | impl From<SAIsoLockNoAffect> for u16 { |
| 4561 | #[inline ] |
| 4562 | fn from(input: SAIsoLockNoAffect) -> Self { |
| 4563 | u16::from(input.0) |
| 4564 | } |
| 4565 | } |
| 4566 | impl From<SAIsoLockNoAffect> for Option<u16> { |
| 4567 | #[inline ] |
| 4568 | fn from(input: SAIsoLockNoAffect) -> Self { |
| 4569 | Some(u16::from(input.0)) |
| 4570 | } |
| 4571 | } |
| 4572 | impl From<SAIsoLockNoAffect> for u32 { |
| 4573 | #[inline ] |
| 4574 | fn from(input: SAIsoLockNoAffect) -> Self { |
| 4575 | u32::from(input.0) |
| 4576 | } |
| 4577 | } |
| 4578 | impl From<SAIsoLockNoAffect> for Option<u32> { |
| 4579 | #[inline ] |
| 4580 | fn from(input: SAIsoLockNoAffect) -> Self { |
| 4581 | Some(u32::from(input.0)) |
| 4582 | } |
| 4583 | } |
| 4584 | impl From<u8> for SAIsoLockNoAffect { |
| 4585 | #[inline ] |
| 4586 | fn from(value: u8) -> Self { |
| 4587 | Self(value) |
| 4588 | } |
| 4589 | } |
| 4590 | impl core::fmt::Debug for SAIsoLockNoAffect { |
| 4591 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 4592 | let variants: [(u32, &'static str, &'static …); 4] = [ |
| 4593 | (Self::CTRLS.0.into(), "CTRLS" , "Ctrls" ), |
| 4594 | (Self::PTR.0.into(), "PTR" , "Ptr" ), |
| 4595 | (Self::GROUP.0.into(), "GROUP" , "Group" ), |
| 4596 | (Self::MODS.0.into(), "MODS" , "Mods" ), |
| 4597 | ]; |
| 4598 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 4599 | } |
| 4600 | } |
| 4601 | bitmask_binop!(SAIsoLockNoAffect, u8); |
| 4602 | |
| 4603 | #[derive (Clone, Copy, Default)] |
| 4604 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 4605 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4606 | pub struct SAIsoLock { |
| 4607 | pub type_: SAType, |
| 4608 | pub flags: SAIsoLockFlag, |
| 4609 | pub mask: xproto::ModMask, |
| 4610 | pub real_mods: xproto::ModMask, |
| 4611 | pub group: i8, |
| 4612 | pub affect: SAIsoLockNoAffect, |
| 4613 | pub vmods_high: VModsHigh, |
| 4614 | pub vmods_low: VModsLow, |
| 4615 | } |
| 4616 | impl_debug_if_no_extra_traits!(SAIsoLock, "SAIsoLock" ); |
| 4617 | impl TryParse for SAIsoLock { |
| 4618 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 4619 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4620 | let (flags: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4621 | let (mask: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4622 | let (real_mods: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4623 | let (group: i8, remaining: &[u8]) = i8::try_parse(remaining)?; |
| 4624 | let (affect: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4625 | let (vmods_high: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4626 | let (vmods_low: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4627 | let type_: SAType = type_.into(); |
| 4628 | let flags: SAIsoLockFlag = flags.into(); |
| 4629 | let mask: ModMask = mask.into(); |
| 4630 | let real_mods: ModMask = real_mods.into(); |
| 4631 | let affect: SAIsoLockNoAffect = affect.into(); |
| 4632 | let vmods_high: VModsHigh = vmods_high.into(); |
| 4633 | let vmods_low: VModsLow = vmods_low.into(); |
| 4634 | let result: SAIsoLock = SAIsoLock { type_, flags, mask, real_mods, group, affect, vmods_high, vmods_low }; |
| 4635 | Ok((result, remaining)) |
| 4636 | } |
| 4637 | } |
| 4638 | impl Serialize for SAIsoLock { |
| 4639 | type Bytes = [u8; 8]; |
| 4640 | fn serialize(&self) -> [u8; 8] { |
| 4641 | let type_bytes = u8::from(self.type_).serialize(); |
| 4642 | let flags_bytes = u8::from(self.flags).serialize(); |
| 4643 | let mask_bytes = (u16::from(self.mask) as u8).serialize(); |
| 4644 | let real_mods_bytes = (u16::from(self.real_mods) as u8).serialize(); |
| 4645 | let group_bytes = self.group.serialize(); |
| 4646 | let affect_bytes = u8::from(self.affect).serialize(); |
| 4647 | let vmods_high_bytes = u8::from(self.vmods_high).serialize(); |
| 4648 | let vmods_low_bytes = u8::from(self.vmods_low).serialize(); |
| 4649 | [ |
| 4650 | type_bytes[0], |
| 4651 | flags_bytes[0], |
| 4652 | mask_bytes[0], |
| 4653 | real_mods_bytes[0], |
| 4654 | group_bytes[0], |
| 4655 | affect_bytes[0], |
| 4656 | vmods_high_bytes[0], |
| 4657 | vmods_low_bytes[0], |
| 4658 | ] |
| 4659 | } |
| 4660 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 4661 | bytes.reserve(8); |
| 4662 | u8::from(self.type_).serialize_into(bytes); |
| 4663 | u8::from(self.flags).serialize_into(bytes); |
| 4664 | (u16::from(self.mask) as u8).serialize_into(bytes); |
| 4665 | (u16::from(self.real_mods) as u8).serialize_into(bytes); |
| 4666 | self.group.serialize_into(bytes); |
| 4667 | u8::from(self.affect).serialize_into(bytes); |
| 4668 | u8::from(self.vmods_high).serialize_into(bytes); |
| 4669 | u8::from(self.vmods_low).serialize_into(bytes); |
| 4670 | } |
| 4671 | } |
| 4672 | |
| 4673 | #[derive (Clone, Copy, Default)] |
| 4674 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 4675 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4676 | pub struct SATerminate { |
| 4677 | pub type_: SAType, |
| 4678 | } |
| 4679 | impl_debug_if_no_extra_traits!(SATerminate, "SATerminate" ); |
| 4680 | impl TryParse for SATerminate { |
| 4681 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 4682 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4683 | let remaining: &[u8] = remaining.get(7..).ok_or(err:ParseError::InsufficientData)?; |
| 4684 | let type_: SAType = type_.into(); |
| 4685 | let result: SATerminate = SATerminate { type_ }; |
| 4686 | Ok((result, remaining)) |
| 4687 | } |
| 4688 | } |
| 4689 | impl Serialize for SATerminate { |
| 4690 | type Bytes = [u8; 8]; |
| 4691 | fn serialize(&self) -> [u8; 8] { |
| 4692 | let type_bytes: [u8; 1] = u8::from(self.type_).serialize(); |
| 4693 | [ |
| 4694 | type_bytes[0], |
| 4695 | 0, |
| 4696 | 0, |
| 4697 | 0, |
| 4698 | 0, |
| 4699 | 0, |
| 4700 | 0, |
| 4701 | 0, |
| 4702 | ] |
| 4703 | } |
| 4704 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 4705 | bytes.reserve(additional:8); |
| 4706 | u8::from(self.type_).serialize_into(bytes); |
| 4707 | bytes.extend_from_slice(&[0; 7]); |
| 4708 | } |
| 4709 | } |
| 4710 | |
| 4711 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 4712 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4713 | pub struct SwitchScreenFlag(u8); |
| 4714 | impl SwitchScreenFlag { |
| 4715 | pub const APPLICATION: Self = Self(1 << 0); |
| 4716 | pub const ABSOLUTE: Self = Self(1 << 2); |
| 4717 | } |
| 4718 | impl From<SwitchScreenFlag> for u8 { |
| 4719 | #[inline ] |
| 4720 | fn from(input: SwitchScreenFlag) -> Self { |
| 4721 | input.0 |
| 4722 | } |
| 4723 | } |
| 4724 | impl From<SwitchScreenFlag> for Option<u8> { |
| 4725 | #[inline ] |
| 4726 | fn from(input: SwitchScreenFlag) -> Self { |
| 4727 | Some(input.0) |
| 4728 | } |
| 4729 | } |
| 4730 | impl From<SwitchScreenFlag> for u16 { |
| 4731 | #[inline ] |
| 4732 | fn from(input: SwitchScreenFlag) -> Self { |
| 4733 | u16::from(input.0) |
| 4734 | } |
| 4735 | } |
| 4736 | impl From<SwitchScreenFlag> for Option<u16> { |
| 4737 | #[inline ] |
| 4738 | fn from(input: SwitchScreenFlag) -> Self { |
| 4739 | Some(u16::from(input.0)) |
| 4740 | } |
| 4741 | } |
| 4742 | impl From<SwitchScreenFlag> for u32 { |
| 4743 | #[inline ] |
| 4744 | fn from(input: SwitchScreenFlag) -> Self { |
| 4745 | u32::from(input.0) |
| 4746 | } |
| 4747 | } |
| 4748 | impl From<SwitchScreenFlag> for Option<u32> { |
| 4749 | #[inline ] |
| 4750 | fn from(input: SwitchScreenFlag) -> Self { |
| 4751 | Some(u32::from(input.0)) |
| 4752 | } |
| 4753 | } |
| 4754 | impl From<u8> for SwitchScreenFlag { |
| 4755 | #[inline ] |
| 4756 | fn from(value: u8) -> Self { |
| 4757 | Self(value) |
| 4758 | } |
| 4759 | } |
| 4760 | impl core::fmt::Debug for SwitchScreenFlag { |
| 4761 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 4762 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 4763 | (Self::APPLICATION.0.into(), "APPLICATION" , "Application" ), |
| 4764 | (Self::ABSOLUTE.0.into(), "ABSOLUTE" , "Absolute" ), |
| 4765 | ]; |
| 4766 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 4767 | } |
| 4768 | } |
| 4769 | bitmask_binop!(SwitchScreenFlag, u8); |
| 4770 | |
| 4771 | #[derive (Clone, Copy, Default)] |
| 4772 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 4773 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4774 | pub struct SASwitchScreen { |
| 4775 | pub type_: SAType, |
| 4776 | pub flags: u8, |
| 4777 | pub new_screen: i8, |
| 4778 | } |
| 4779 | impl_debug_if_no_extra_traits!(SASwitchScreen, "SASwitchScreen" ); |
| 4780 | impl TryParse for SASwitchScreen { |
| 4781 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 4782 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4783 | let (flags: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4784 | let (new_screen: i8, remaining: &[u8]) = i8::try_parse(remaining)?; |
| 4785 | let remaining: &[u8] = remaining.get(5..).ok_or(err:ParseError::InsufficientData)?; |
| 4786 | let type_: SAType = type_.into(); |
| 4787 | let result: SASwitchScreen = SASwitchScreen { type_, flags, new_screen }; |
| 4788 | Ok((result, remaining)) |
| 4789 | } |
| 4790 | } |
| 4791 | impl Serialize for SASwitchScreen { |
| 4792 | type Bytes = [u8; 8]; |
| 4793 | fn serialize(&self) -> [u8; 8] { |
| 4794 | let type_bytes = u8::from(self.type_).serialize(); |
| 4795 | let flags_bytes = self.flags.serialize(); |
| 4796 | let new_screen_bytes = self.new_screen.serialize(); |
| 4797 | [ |
| 4798 | type_bytes[0], |
| 4799 | flags_bytes[0], |
| 4800 | new_screen_bytes[0], |
| 4801 | 0, |
| 4802 | 0, |
| 4803 | 0, |
| 4804 | 0, |
| 4805 | 0, |
| 4806 | ] |
| 4807 | } |
| 4808 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 4809 | bytes.reserve(8); |
| 4810 | u8::from(self.type_).serialize_into(bytes); |
| 4811 | self.flags.serialize_into(bytes); |
| 4812 | self.new_screen.serialize_into(bytes); |
| 4813 | bytes.extend_from_slice(&[0; 5]); |
| 4814 | } |
| 4815 | } |
| 4816 | |
| 4817 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 4818 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4819 | pub struct BoolCtrlsHigh(u8); |
| 4820 | impl BoolCtrlsHigh { |
| 4821 | pub const ACCESS_X_FEEDBACK: Self = Self(1 << 0); |
| 4822 | pub const AUDIBLE_BELL: Self = Self(1 << 1); |
| 4823 | pub const OVERLAY1: Self = Self(1 << 2); |
| 4824 | pub const OVERLAY2: Self = Self(1 << 3); |
| 4825 | pub const IGNORE_GROUP_LOCK: Self = Self(1 << 4); |
| 4826 | } |
| 4827 | impl From<BoolCtrlsHigh> for u8 { |
| 4828 | #[inline ] |
| 4829 | fn from(input: BoolCtrlsHigh) -> Self { |
| 4830 | input.0 |
| 4831 | } |
| 4832 | } |
| 4833 | impl From<BoolCtrlsHigh> for Option<u8> { |
| 4834 | #[inline ] |
| 4835 | fn from(input: BoolCtrlsHigh) -> Self { |
| 4836 | Some(input.0) |
| 4837 | } |
| 4838 | } |
| 4839 | impl From<BoolCtrlsHigh> for u16 { |
| 4840 | #[inline ] |
| 4841 | fn from(input: BoolCtrlsHigh) -> Self { |
| 4842 | u16::from(input.0) |
| 4843 | } |
| 4844 | } |
| 4845 | impl From<BoolCtrlsHigh> for Option<u16> { |
| 4846 | #[inline ] |
| 4847 | fn from(input: BoolCtrlsHigh) -> Self { |
| 4848 | Some(u16::from(input.0)) |
| 4849 | } |
| 4850 | } |
| 4851 | impl From<BoolCtrlsHigh> for u32 { |
| 4852 | #[inline ] |
| 4853 | fn from(input: BoolCtrlsHigh) -> Self { |
| 4854 | u32::from(input.0) |
| 4855 | } |
| 4856 | } |
| 4857 | impl From<BoolCtrlsHigh> for Option<u32> { |
| 4858 | #[inline ] |
| 4859 | fn from(input: BoolCtrlsHigh) -> Self { |
| 4860 | Some(u32::from(input.0)) |
| 4861 | } |
| 4862 | } |
| 4863 | impl From<u8> for BoolCtrlsHigh { |
| 4864 | #[inline ] |
| 4865 | fn from(value: u8) -> Self { |
| 4866 | Self(value) |
| 4867 | } |
| 4868 | } |
| 4869 | impl core::fmt::Debug for BoolCtrlsHigh { |
| 4870 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 4871 | let variants: [(u32, &'static str, &'static …); 5] = [ |
| 4872 | (Self::ACCESS_X_FEEDBACK.0.into(), "ACCESS_X_FEEDBACK" , "AccessXFeedback" ), |
| 4873 | (Self::AUDIBLE_BELL.0.into(), "AUDIBLE_BELL" , "AudibleBell" ), |
| 4874 | (Self::OVERLAY1.0.into(), "OVERLAY1" , "Overlay1" ), |
| 4875 | (Self::OVERLAY2.0.into(), "OVERLAY2" , "Overlay2" ), |
| 4876 | (Self::IGNORE_GROUP_LOCK.0.into(), "IGNORE_GROUP_LOCK" , "IgnoreGroupLock" ), |
| 4877 | ]; |
| 4878 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 4879 | } |
| 4880 | } |
| 4881 | bitmask_binop!(BoolCtrlsHigh, u8); |
| 4882 | |
| 4883 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 4884 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4885 | pub struct BoolCtrlsLow(u8); |
| 4886 | impl BoolCtrlsLow { |
| 4887 | pub const REPEAT_KEYS: Self = Self(1 << 0); |
| 4888 | pub const SLOW_KEYS: Self = Self(1 << 1); |
| 4889 | pub const BOUNCE_KEYS: Self = Self(1 << 2); |
| 4890 | pub const STICKY_KEYS: Self = Self(1 << 3); |
| 4891 | pub const MOUSE_KEYS: Self = Self(1 << 4); |
| 4892 | pub const MOUSE_KEYS_ACCEL: Self = Self(1 << 5); |
| 4893 | pub const ACCESS_X_KEYS: Self = Self(1 << 6); |
| 4894 | pub const ACCESS_X_TIMEOUT: Self = Self(1 << 7); |
| 4895 | } |
| 4896 | impl From<BoolCtrlsLow> for u8 { |
| 4897 | #[inline ] |
| 4898 | fn from(input: BoolCtrlsLow) -> Self { |
| 4899 | input.0 |
| 4900 | } |
| 4901 | } |
| 4902 | impl From<BoolCtrlsLow> for Option<u8> { |
| 4903 | #[inline ] |
| 4904 | fn from(input: BoolCtrlsLow) -> Self { |
| 4905 | Some(input.0) |
| 4906 | } |
| 4907 | } |
| 4908 | impl From<BoolCtrlsLow> for u16 { |
| 4909 | #[inline ] |
| 4910 | fn from(input: BoolCtrlsLow) -> Self { |
| 4911 | u16::from(input.0) |
| 4912 | } |
| 4913 | } |
| 4914 | impl From<BoolCtrlsLow> for Option<u16> { |
| 4915 | #[inline ] |
| 4916 | fn from(input: BoolCtrlsLow) -> Self { |
| 4917 | Some(u16::from(input.0)) |
| 4918 | } |
| 4919 | } |
| 4920 | impl From<BoolCtrlsLow> for u32 { |
| 4921 | #[inline ] |
| 4922 | fn from(input: BoolCtrlsLow) -> Self { |
| 4923 | u32::from(input.0) |
| 4924 | } |
| 4925 | } |
| 4926 | impl From<BoolCtrlsLow> for Option<u32> { |
| 4927 | #[inline ] |
| 4928 | fn from(input: BoolCtrlsLow) -> Self { |
| 4929 | Some(u32::from(input.0)) |
| 4930 | } |
| 4931 | } |
| 4932 | impl From<u8> for BoolCtrlsLow { |
| 4933 | #[inline ] |
| 4934 | fn from(value: u8) -> Self { |
| 4935 | Self(value) |
| 4936 | } |
| 4937 | } |
| 4938 | impl core::fmt::Debug for BoolCtrlsLow { |
| 4939 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 4940 | let variants: [(u32, &'static str, &'static …); 8] = [ |
| 4941 | (Self::REPEAT_KEYS.0.into(), "REPEAT_KEYS" , "RepeatKeys" ), |
| 4942 | (Self::SLOW_KEYS.0.into(), "SLOW_KEYS" , "SlowKeys" ), |
| 4943 | (Self::BOUNCE_KEYS.0.into(), "BOUNCE_KEYS" , "BounceKeys" ), |
| 4944 | (Self::STICKY_KEYS.0.into(), "STICKY_KEYS" , "StickyKeys" ), |
| 4945 | (Self::MOUSE_KEYS.0.into(), "MOUSE_KEYS" , "MouseKeys" ), |
| 4946 | (Self::MOUSE_KEYS_ACCEL.0.into(), "MOUSE_KEYS_ACCEL" , "MouseKeysAccel" ), |
| 4947 | (Self::ACCESS_X_KEYS.0.into(), "ACCESS_X_KEYS" , "AccessXKeys" ), |
| 4948 | (Self::ACCESS_X_TIMEOUT.0.into(), "ACCESS_X_TIMEOUT" , "AccessXTimeout" ), |
| 4949 | ]; |
| 4950 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 4951 | } |
| 4952 | } |
| 4953 | bitmask_binop!(BoolCtrlsLow, u8); |
| 4954 | |
| 4955 | #[derive (Clone, Copy, Default)] |
| 4956 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 4957 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 4958 | pub struct SASetControls { |
| 4959 | pub type_: SAType, |
| 4960 | pub bool_ctrls_high: BoolCtrlsHigh, |
| 4961 | pub bool_ctrls_low: BoolCtrlsLow, |
| 4962 | } |
| 4963 | impl_debug_if_no_extra_traits!(SASetControls, "SASetControls" ); |
| 4964 | impl TryParse for SASetControls { |
| 4965 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 4966 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4967 | let remaining: &[u8] = remaining.get(3..).ok_or(err:ParseError::InsufficientData)?; |
| 4968 | let (bool_ctrls_high: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4969 | let (bool_ctrls_low: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 4970 | let remaining: &[u8] = remaining.get(2..).ok_or(err:ParseError::InsufficientData)?; |
| 4971 | let type_: SAType = type_.into(); |
| 4972 | let bool_ctrls_high: BoolCtrlsHigh = bool_ctrls_high.into(); |
| 4973 | let bool_ctrls_low: BoolCtrlsLow = bool_ctrls_low.into(); |
| 4974 | let result: SASetControls = SASetControls { type_, bool_ctrls_high, bool_ctrls_low }; |
| 4975 | Ok((result, remaining)) |
| 4976 | } |
| 4977 | } |
| 4978 | impl Serialize for SASetControls { |
| 4979 | type Bytes = [u8; 8]; |
| 4980 | fn serialize(&self) -> [u8; 8] { |
| 4981 | let type_bytes = u8::from(self.type_).serialize(); |
| 4982 | let bool_ctrls_high_bytes = u8::from(self.bool_ctrls_high).serialize(); |
| 4983 | let bool_ctrls_low_bytes = u8::from(self.bool_ctrls_low).serialize(); |
| 4984 | [ |
| 4985 | type_bytes[0], |
| 4986 | 0, |
| 4987 | 0, |
| 4988 | 0, |
| 4989 | bool_ctrls_high_bytes[0], |
| 4990 | bool_ctrls_low_bytes[0], |
| 4991 | 0, |
| 4992 | 0, |
| 4993 | ] |
| 4994 | } |
| 4995 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 4996 | bytes.reserve(8); |
| 4997 | u8::from(self.type_).serialize_into(bytes); |
| 4998 | bytes.extend_from_slice(&[0; 3]); |
| 4999 | u8::from(self.bool_ctrls_high).serialize_into(bytes); |
| 5000 | u8::from(self.bool_ctrls_low).serialize_into(bytes); |
| 5001 | bytes.extend_from_slice(&[0; 2]); |
| 5002 | } |
| 5003 | } |
| 5004 | |
| 5005 | pub type SALockControls = SASetControls; |
| 5006 | |
| 5007 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 5008 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5009 | pub struct ActionMessageFlag(u8); |
| 5010 | impl ActionMessageFlag { |
| 5011 | pub const ON_PRESS: Self = Self(1 << 0); |
| 5012 | pub const ON_RELEASE: Self = Self(1 << 1); |
| 5013 | pub const GEN_KEY_EVENT: Self = Self(1 << 2); |
| 5014 | } |
| 5015 | impl From<ActionMessageFlag> for u8 { |
| 5016 | #[inline ] |
| 5017 | fn from(input: ActionMessageFlag) -> Self { |
| 5018 | input.0 |
| 5019 | } |
| 5020 | } |
| 5021 | impl From<ActionMessageFlag> for Option<u8> { |
| 5022 | #[inline ] |
| 5023 | fn from(input: ActionMessageFlag) -> Self { |
| 5024 | Some(input.0) |
| 5025 | } |
| 5026 | } |
| 5027 | impl From<ActionMessageFlag> for u16 { |
| 5028 | #[inline ] |
| 5029 | fn from(input: ActionMessageFlag) -> Self { |
| 5030 | u16::from(input.0) |
| 5031 | } |
| 5032 | } |
| 5033 | impl From<ActionMessageFlag> for Option<u16> { |
| 5034 | #[inline ] |
| 5035 | fn from(input: ActionMessageFlag) -> Self { |
| 5036 | Some(u16::from(input.0)) |
| 5037 | } |
| 5038 | } |
| 5039 | impl From<ActionMessageFlag> for u32 { |
| 5040 | #[inline ] |
| 5041 | fn from(input: ActionMessageFlag) -> Self { |
| 5042 | u32::from(input.0) |
| 5043 | } |
| 5044 | } |
| 5045 | impl From<ActionMessageFlag> for Option<u32> { |
| 5046 | #[inline ] |
| 5047 | fn from(input: ActionMessageFlag) -> Self { |
| 5048 | Some(u32::from(input.0)) |
| 5049 | } |
| 5050 | } |
| 5051 | impl From<u8> for ActionMessageFlag { |
| 5052 | #[inline ] |
| 5053 | fn from(value: u8) -> Self { |
| 5054 | Self(value) |
| 5055 | } |
| 5056 | } |
| 5057 | impl core::fmt::Debug for ActionMessageFlag { |
| 5058 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 5059 | let variants: [(u32, &'static str, &'static …); 3] = [ |
| 5060 | (Self::ON_PRESS.0.into(), "ON_PRESS" , "OnPress" ), |
| 5061 | (Self::ON_RELEASE.0.into(), "ON_RELEASE" , "OnRelease" ), |
| 5062 | (Self::GEN_KEY_EVENT.0.into(), "GEN_KEY_EVENT" , "GenKeyEvent" ), |
| 5063 | ]; |
| 5064 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 5065 | } |
| 5066 | } |
| 5067 | bitmask_binop!(ActionMessageFlag, u8); |
| 5068 | |
| 5069 | #[derive (Clone, Copy, Default)] |
| 5070 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 5071 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5072 | pub struct SAActionMessage { |
| 5073 | pub type_: SAType, |
| 5074 | pub flags: ActionMessageFlag, |
| 5075 | pub message: [u8; 6], |
| 5076 | } |
| 5077 | impl_debug_if_no_extra_traits!(SAActionMessage, "SAActionMessage" ); |
| 5078 | impl TryParse for SAActionMessage { |
| 5079 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 5080 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5081 | let (flags: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5082 | let (message: [u8; 6], remaining: &[u8]) = crate::x11_utils::parse_u8_array::<6>(data:remaining)?; |
| 5083 | let type_: SAType = type_.into(); |
| 5084 | let flags: ActionMessageFlag = flags.into(); |
| 5085 | let result: SAActionMessage = SAActionMessage { type_, flags, message }; |
| 5086 | Ok((result, remaining)) |
| 5087 | } |
| 5088 | } |
| 5089 | impl Serialize for SAActionMessage { |
| 5090 | type Bytes = [u8; 8]; |
| 5091 | fn serialize(&self) -> [u8; 8] { |
| 5092 | let type_bytes: [u8; 1] = u8::from(self.type_).serialize(); |
| 5093 | let flags_bytes: [u8; 1] = u8::from(self.flags).serialize(); |
| 5094 | [ |
| 5095 | type_bytes[0], |
| 5096 | flags_bytes[0], |
| 5097 | self.message[0], |
| 5098 | self.message[1], |
| 5099 | self.message[2], |
| 5100 | self.message[3], |
| 5101 | self.message[4], |
| 5102 | self.message[5], |
| 5103 | ] |
| 5104 | } |
| 5105 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 5106 | bytes.reserve(additional:8); |
| 5107 | u8::from(self.type_).serialize_into(bytes); |
| 5108 | u8::from(self.flags).serialize_into(bytes); |
| 5109 | bytes.extend_from_slice(&self.message); |
| 5110 | } |
| 5111 | } |
| 5112 | |
| 5113 | #[derive (Clone, Copy, Default)] |
| 5114 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 5115 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5116 | pub struct SARedirectKey { |
| 5117 | pub type_: SAType, |
| 5118 | pub newkey: xproto::Keycode, |
| 5119 | pub mask: xproto::ModMask, |
| 5120 | pub real_modifiers: xproto::ModMask, |
| 5121 | pub vmods_mask_high: VModsHigh, |
| 5122 | pub vmods_mask_low: VModsLow, |
| 5123 | pub vmods_high: VModsHigh, |
| 5124 | pub vmods_low: VModsLow, |
| 5125 | } |
| 5126 | impl_debug_if_no_extra_traits!(SARedirectKey, "SARedirectKey" ); |
| 5127 | impl TryParse for SARedirectKey { |
| 5128 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 5129 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5130 | let (newkey: u8, remaining: &[u8]) = xproto::Keycode::try_parse(remaining)?; |
| 5131 | let (mask: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5132 | let (real_modifiers: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5133 | let (vmods_mask_high: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5134 | let (vmods_mask_low: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5135 | let (vmods_high: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5136 | let (vmods_low: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5137 | let type_: SAType = type_.into(); |
| 5138 | let mask: ModMask = mask.into(); |
| 5139 | let real_modifiers: ModMask = real_modifiers.into(); |
| 5140 | let vmods_mask_high: VModsHigh = vmods_mask_high.into(); |
| 5141 | let vmods_mask_low: VModsLow = vmods_mask_low.into(); |
| 5142 | let vmods_high: VModsHigh = vmods_high.into(); |
| 5143 | let vmods_low: VModsLow = vmods_low.into(); |
| 5144 | let result: SARedirectKey = SARedirectKey { type_, newkey, mask, real_modifiers, vmods_mask_high, vmods_mask_low, vmods_high, vmods_low }; |
| 5145 | Ok((result, remaining)) |
| 5146 | } |
| 5147 | } |
| 5148 | impl Serialize for SARedirectKey { |
| 5149 | type Bytes = [u8; 8]; |
| 5150 | fn serialize(&self) -> [u8; 8] { |
| 5151 | let type_bytes = u8::from(self.type_).serialize(); |
| 5152 | let newkey_bytes = self.newkey.serialize(); |
| 5153 | let mask_bytes = (u16::from(self.mask) as u8).serialize(); |
| 5154 | let real_modifiers_bytes = (u16::from(self.real_modifiers) as u8).serialize(); |
| 5155 | let vmods_mask_high_bytes = u8::from(self.vmods_mask_high).serialize(); |
| 5156 | let vmods_mask_low_bytes = u8::from(self.vmods_mask_low).serialize(); |
| 5157 | let vmods_high_bytes = u8::from(self.vmods_high).serialize(); |
| 5158 | let vmods_low_bytes = u8::from(self.vmods_low).serialize(); |
| 5159 | [ |
| 5160 | type_bytes[0], |
| 5161 | newkey_bytes[0], |
| 5162 | mask_bytes[0], |
| 5163 | real_modifiers_bytes[0], |
| 5164 | vmods_mask_high_bytes[0], |
| 5165 | vmods_mask_low_bytes[0], |
| 5166 | vmods_high_bytes[0], |
| 5167 | vmods_low_bytes[0], |
| 5168 | ] |
| 5169 | } |
| 5170 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 5171 | bytes.reserve(8); |
| 5172 | u8::from(self.type_).serialize_into(bytes); |
| 5173 | self.newkey.serialize_into(bytes); |
| 5174 | (u16::from(self.mask) as u8).serialize_into(bytes); |
| 5175 | (u16::from(self.real_modifiers) as u8).serialize_into(bytes); |
| 5176 | u8::from(self.vmods_mask_high).serialize_into(bytes); |
| 5177 | u8::from(self.vmods_mask_low).serialize_into(bytes); |
| 5178 | u8::from(self.vmods_high).serialize_into(bytes); |
| 5179 | u8::from(self.vmods_low).serialize_into(bytes); |
| 5180 | } |
| 5181 | } |
| 5182 | |
| 5183 | #[derive (Clone, Copy, Default)] |
| 5184 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 5185 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5186 | pub struct SADeviceBtn { |
| 5187 | pub type_: SAType, |
| 5188 | pub flags: u8, |
| 5189 | pub count: u8, |
| 5190 | pub button: u8, |
| 5191 | pub device: u8, |
| 5192 | } |
| 5193 | impl_debug_if_no_extra_traits!(SADeviceBtn, "SADeviceBtn" ); |
| 5194 | impl TryParse for SADeviceBtn { |
| 5195 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 5196 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5197 | let (flags: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5198 | let (count: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5199 | let (button: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5200 | let (device: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5201 | let remaining: &[u8] = remaining.get(3..).ok_or(err:ParseError::InsufficientData)?; |
| 5202 | let type_: SAType = type_.into(); |
| 5203 | let result: SADeviceBtn = SADeviceBtn { type_, flags, count, button, device }; |
| 5204 | Ok((result, remaining)) |
| 5205 | } |
| 5206 | } |
| 5207 | impl Serialize for SADeviceBtn { |
| 5208 | type Bytes = [u8; 8]; |
| 5209 | fn serialize(&self) -> [u8; 8] { |
| 5210 | let type_bytes = u8::from(self.type_).serialize(); |
| 5211 | let flags_bytes = self.flags.serialize(); |
| 5212 | let count_bytes = self.count.serialize(); |
| 5213 | let button_bytes = self.button.serialize(); |
| 5214 | let device_bytes = self.device.serialize(); |
| 5215 | [ |
| 5216 | type_bytes[0], |
| 5217 | flags_bytes[0], |
| 5218 | count_bytes[0], |
| 5219 | button_bytes[0], |
| 5220 | device_bytes[0], |
| 5221 | 0, |
| 5222 | 0, |
| 5223 | 0, |
| 5224 | ] |
| 5225 | } |
| 5226 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 5227 | bytes.reserve(8); |
| 5228 | u8::from(self.type_).serialize_into(bytes); |
| 5229 | self.flags.serialize_into(bytes); |
| 5230 | self.count.serialize_into(bytes); |
| 5231 | self.button.serialize_into(bytes); |
| 5232 | self.device.serialize_into(bytes); |
| 5233 | bytes.extend_from_slice(&[0; 3]); |
| 5234 | } |
| 5235 | } |
| 5236 | |
| 5237 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 5238 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5239 | pub struct LockDeviceFlags(u8); |
| 5240 | impl LockDeviceFlags { |
| 5241 | pub const NO_LOCK: Self = Self(1 << 0); |
| 5242 | pub const NO_UNLOCK: Self = Self(1 << 1); |
| 5243 | } |
| 5244 | impl From<LockDeviceFlags> for u8 { |
| 5245 | #[inline ] |
| 5246 | fn from(input: LockDeviceFlags) -> Self { |
| 5247 | input.0 |
| 5248 | } |
| 5249 | } |
| 5250 | impl From<LockDeviceFlags> for Option<u8> { |
| 5251 | #[inline ] |
| 5252 | fn from(input: LockDeviceFlags) -> Self { |
| 5253 | Some(input.0) |
| 5254 | } |
| 5255 | } |
| 5256 | impl From<LockDeviceFlags> for u16 { |
| 5257 | #[inline ] |
| 5258 | fn from(input: LockDeviceFlags) -> Self { |
| 5259 | u16::from(input.0) |
| 5260 | } |
| 5261 | } |
| 5262 | impl From<LockDeviceFlags> for Option<u16> { |
| 5263 | #[inline ] |
| 5264 | fn from(input: LockDeviceFlags) -> Self { |
| 5265 | Some(u16::from(input.0)) |
| 5266 | } |
| 5267 | } |
| 5268 | impl From<LockDeviceFlags> for u32 { |
| 5269 | #[inline ] |
| 5270 | fn from(input: LockDeviceFlags) -> Self { |
| 5271 | u32::from(input.0) |
| 5272 | } |
| 5273 | } |
| 5274 | impl From<LockDeviceFlags> for Option<u32> { |
| 5275 | #[inline ] |
| 5276 | fn from(input: LockDeviceFlags) -> Self { |
| 5277 | Some(u32::from(input.0)) |
| 5278 | } |
| 5279 | } |
| 5280 | impl From<u8> for LockDeviceFlags { |
| 5281 | #[inline ] |
| 5282 | fn from(value: u8) -> Self { |
| 5283 | Self(value) |
| 5284 | } |
| 5285 | } |
| 5286 | impl core::fmt::Debug for LockDeviceFlags { |
| 5287 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 5288 | let variants: [(u32, &'static str, &'static …); 2] = [ |
| 5289 | (Self::NO_LOCK.0.into(), "NO_LOCK" , "NoLock" ), |
| 5290 | (Self::NO_UNLOCK.0.into(), "NO_UNLOCK" , "NoUnlock" ), |
| 5291 | ]; |
| 5292 | pretty_print_bitmask(fmt, self.0.into(), &variants) |
| 5293 | } |
| 5294 | } |
| 5295 | bitmask_binop!(LockDeviceFlags, u8); |
| 5296 | |
| 5297 | #[derive (Clone, Copy, Default)] |
| 5298 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 5299 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5300 | pub struct SALockDeviceBtn { |
| 5301 | pub type_: SAType, |
| 5302 | pub flags: LockDeviceFlags, |
| 5303 | pub button: u8, |
| 5304 | pub device: u8, |
| 5305 | } |
| 5306 | impl_debug_if_no_extra_traits!(SALockDeviceBtn, "SALockDeviceBtn" ); |
| 5307 | impl TryParse for SALockDeviceBtn { |
| 5308 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 5309 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5310 | let (flags: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5311 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 5312 | let (button: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5313 | let (device: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5314 | let remaining: &[u8] = remaining.get(3..).ok_or(err:ParseError::InsufficientData)?; |
| 5315 | let type_: SAType = type_.into(); |
| 5316 | let flags: LockDeviceFlags = flags.into(); |
| 5317 | let result: SALockDeviceBtn = SALockDeviceBtn { type_, flags, button, device }; |
| 5318 | Ok((result, remaining)) |
| 5319 | } |
| 5320 | } |
| 5321 | impl Serialize for SALockDeviceBtn { |
| 5322 | type Bytes = [u8; 8]; |
| 5323 | fn serialize(&self) -> [u8; 8] { |
| 5324 | let type_bytes = u8::from(self.type_).serialize(); |
| 5325 | let flags_bytes = u8::from(self.flags).serialize(); |
| 5326 | let button_bytes = self.button.serialize(); |
| 5327 | let device_bytes = self.device.serialize(); |
| 5328 | [ |
| 5329 | type_bytes[0], |
| 5330 | flags_bytes[0], |
| 5331 | 0, |
| 5332 | button_bytes[0], |
| 5333 | device_bytes[0], |
| 5334 | 0, |
| 5335 | 0, |
| 5336 | 0, |
| 5337 | ] |
| 5338 | } |
| 5339 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 5340 | bytes.reserve(8); |
| 5341 | u8::from(self.type_).serialize_into(bytes); |
| 5342 | u8::from(self.flags).serialize_into(bytes); |
| 5343 | bytes.extend_from_slice(&[0; 1]); |
| 5344 | self.button.serialize_into(bytes); |
| 5345 | self.device.serialize_into(bytes); |
| 5346 | bytes.extend_from_slice(&[0; 3]); |
| 5347 | } |
| 5348 | } |
| 5349 | |
| 5350 | #[derive (Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 5351 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5352 | pub struct SAValWhat(u8); |
| 5353 | impl SAValWhat { |
| 5354 | pub const IGNORE_VAL: Self = Self(0); |
| 5355 | pub const SET_VAL_MIN: Self = Self(1); |
| 5356 | pub const SET_VAL_CENTER: Self = Self(2); |
| 5357 | pub const SET_VAL_MAX: Self = Self(3); |
| 5358 | pub const SET_VAL_RELATIVE: Self = Self(4); |
| 5359 | pub const SET_VAL_ABSOLUTE: Self = Self(5); |
| 5360 | } |
| 5361 | impl From<SAValWhat> for u8 { |
| 5362 | #[inline ] |
| 5363 | fn from(input: SAValWhat) -> Self { |
| 5364 | input.0 |
| 5365 | } |
| 5366 | } |
| 5367 | impl From<SAValWhat> for Option<u8> { |
| 5368 | #[inline ] |
| 5369 | fn from(input: SAValWhat) -> Self { |
| 5370 | Some(input.0) |
| 5371 | } |
| 5372 | } |
| 5373 | impl From<SAValWhat> for u16 { |
| 5374 | #[inline ] |
| 5375 | fn from(input: SAValWhat) -> Self { |
| 5376 | u16::from(input.0) |
| 5377 | } |
| 5378 | } |
| 5379 | impl From<SAValWhat> for Option<u16> { |
| 5380 | #[inline ] |
| 5381 | fn from(input: SAValWhat) -> Self { |
| 5382 | Some(u16::from(input.0)) |
| 5383 | } |
| 5384 | } |
| 5385 | impl From<SAValWhat> for u32 { |
| 5386 | #[inline ] |
| 5387 | fn from(input: SAValWhat) -> Self { |
| 5388 | u32::from(input.0) |
| 5389 | } |
| 5390 | } |
| 5391 | impl From<SAValWhat> for Option<u32> { |
| 5392 | #[inline ] |
| 5393 | fn from(input: SAValWhat) -> Self { |
| 5394 | Some(u32::from(input.0)) |
| 5395 | } |
| 5396 | } |
| 5397 | impl From<u8> for SAValWhat { |
| 5398 | #[inline ] |
| 5399 | fn from(value: u8) -> Self { |
| 5400 | Self(value) |
| 5401 | } |
| 5402 | } |
| 5403 | impl core::fmt::Debug for SAValWhat { |
| 5404 | fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 5405 | let variants: [(u32, &'static str, &'static …); 6] = [ |
| 5406 | (Self::IGNORE_VAL.0.into(), "IGNORE_VAL" , "IgnoreVal" ), |
| 5407 | (Self::SET_VAL_MIN.0.into(), "SET_VAL_MIN" , "SetValMin" ), |
| 5408 | (Self::SET_VAL_CENTER.0.into(), "SET_VAL_CENTER" , "SetValCenter" ), |
| 5409 | (Self::SET_VAL_MAX.0.into(), "SET_VAL_MAX" , "SetValMax" ), |
| 5410 | (Self::SET_VAL_RELATIVE.0.into(), "SET_VAL_RELATIVE" , "SetValRelative" ), |
| 5411 | (Self::SET_VAL_ABSOLUTE.0.into(), "SET_VAL_ABSOLUTE" , "SetValAbsolute" ), |
| 5412 | ]; |
| 5413 | pretty_print_enum(fmt, self.0.into(), &variants) |
| 5414 | } |
| 5415 | } |
| 5416 | |
| 5417 | #[derive (Clone, Copy, Default)] |
| 5418 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 5419 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5420 | pub struct SADeviceValuator { |
| 5421 | pub type_: SAType, |
| 5422 | pub device: u8, |
| 5423 | pub val1what: SAValWhat, |
| 5424 | pub val1index: u8, |
| 5425 | pub val1value: u8, |
| 5426 | pub val2what: SAValWhat, |
| 5427 | pub val2index: u8, |
| 5428 | pub val2value: u8, |
| 5429 | } |
| 5430 | impl_debug_if_no_extra_traits!(SADeviceValuator, "SADeviceValuator" ); |
| 5431 | impl TryParse for SADeviceValuator { |
| 5432 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 5433 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5434 | let (device: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5435 | let (val1what: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5436 | let (val1index: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5437 | let (val1value: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5438 | let (val2what: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5439 | let (val2index: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5440 | let (val2value: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5441 | let type_: SAType = type_.into(); |
| 5442 | let val1what: SAValWhat = val1what.into(); |
| 5443 | let val2what: SAValWhat = val2what.into(); |
| 5444 | let result: SADeviceValuator = SADeviceValuator { type_, device, val1what, val1index, val1value, val2what, val2index, val2value }; |
| 5445 | Ok((result, remaining)) |
| 5446 | } |
| 5447 | } |
| 5448 | impl Serialize for SADeviceValuator { |
| 5449 | type Bytes = [u8; 8]; |
| 5450 | fn serialize(&self) -> [u8; 8] { |
| 5451 | let type_bytes = u8::from(self.type_).serialize(); |
| 5452 | let device_bytes = self.device.serialize(); |
| 5453 | let val1what_bytes = u8::from(self.val1what).serialize(); |
| 5454 | let val1index_bytes = self.val1index.serialize(); |
| 5455 | let val1value_bytes = self.val1value.serialize(); |
| 5456 | let val2what_bytes = u8::from(self.val2what).serialize(); |
| 5457 | let val2index_bytes = self.val2index.serialize(); |
| 5458 | let val2value_bytes = self.val2value.serialize(); |
| 5459 | [ |
| 5460 | type_bytes[0], |
| 5461 | device_bytes[0], |
| 5462 | val1what_bytes[0], |
| 5463 | val1index_bytes[0], |
| 5464 | val1value_bytes[0], |
| 5465 | val2what_bytes[0], |
| 5466 | val2index_bytes[0], |
| 5467 | val2value_bytes[0], |
| 5468 | ] |
| 5469 | } |
| 5470 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 5471 | bytes.reserve(8); |
| 5472 | u8::from(self.type_).serialize_into(bytes); |
| 5473 | self.device.serialize_into(bytes); |
| 5474 | u8::from(self.val1what).serialize_into(bytes); |
| 5475 | self.val1index.serialize_into(bytes); |
| 5476 | self.val1value.serialize_into(bytes); |
| 5477 | u8::from(self.val2what).serialize_into(bytes); |
| 5478 | self.val2index.serialize_into(bytes); |
| 5479 | self.val2value.serialize_into(bytes); |
| 5480 | } |
| 5481 | } |
| 5482 | |
| 5483 | #[derive (Clone, Copy, Default)] |
| 5484 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 5485 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5486 | pub struct SIAction { |
| 5487 | pub type_: SAType, |
| 5488 | pub data: [u8; 7], |
| 5489 | } |
| 5490 | impl_debug_if_no_extra_traits!(SIAction, "SIAction" ); |
| 5491 | impl TryParse for SIAction { |
| 5492 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 5493 | let (type_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5494 | let (data: [u8; 7], remaining: &[u8]) = crate::x11_utils::parse_u8_array::<7>(data:remaining)?; |
| 5495 | let type_: SAType = type_.into(); |
| 5496 | let result: SIAction = SIAction { type_, data }; |
| 5497 | Ok((result, remaining)) |
| 5498 | } |
| 5499 | } |
| 5500 | impl Serialize for SIAction { |
| 5501 | type Bytes = [u8; 8]; |
| 5502 | fn serialize(&self) -> [u8; 8] { |
| 5503 | let type_bytes: [u8; 1] = u8::from(self.type_).serialize(); |
| 5504 | [ |
| 5505 | type_bytes[0], |
| 5506 | self.data[0], |
| 5507 | self.data[1], |
| 5508 | self.data[2], |
| 5509 | self.data[3], |
| 5510 | self.data[4], |
| 5511 | self.data[5], |
| 5512 | self.data[6], |
| 5513 | ] |
| 5514 | } |
| 5515 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 5516 | bytes.reserve(additional:8); |
| 5517 | u8::from(self.type_).serialize_into(bytes); |
| 5518 | bytes.extend_from_slice(&self.data); |
| 5519 | } |
| 5520 | } |
| 5521 | |
| 5522 | #[derive (Clone, Copy, Default)] |
| 5523 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 5524 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5525 | pub struct SymInterpret { |
| 5526 | pub sym: xproto::Keysym, |
| 5527 | pub mods: xproto::ModMask, |
| 5528 | pub match_: u8, |
| 5529 | pub virtual_mod: VModsLow, |
| 5530 | pub flags: u8, |
| 5531 | pub action: SIAction, |
| 5532 | } |
| 5533 | impl_debug_if_no_extra_traits!(SymInterpret, "SymInterpret" ); |
| 5534 | impl TryParse for SymInterpret { |
| 5535 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 5536 | let (sym: u32, remaining: &[u8]) = xproto::Keysym::try_parse(remaining)?; |
| 5537 | let (mods: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5538 | let (match_: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5539 | let (virtual_mod: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5540 | let (flags: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5541 | let (action: SIAction, remaining: &[u8]) = SIAction::try_parse(remaining)?; |
| 5542 | let mods: ModMask = mods.into(); |
| 5543 | let virtual_mod: VModsLow = virtual_mod.into(); |
| 5544 | let result: SymInterpret = SymInterpret { sym, mods, match_, virtual_mod, flags, action }; |
| 5545 | Ok((result, remaining)) |
| 5546 | } |
| 5547 | } |
| 5548 | impl Serialize for SymInterpret { |
| 5549 | type Bytes = [u8; 16]; |
| 5550 | fn serialize(&self) -> [u8; 16] { |
| 5551 | let sym_bytes = self.sym.serialize(); |
| 5552 | let mods_bytes = (u16::from(self.mods) as u8).serialize(); |
| 5553 | let match_bytes = self.match_.serialize(); |
| 5554 | let virtual_mod_bytes = u8::from(self.virtual_mod).serialize(); |
| 5555 | let flags_bytes = self.flags.serialize(); |
| 5556 | let action_bytes = self.action.serialize(); |
| 5557 | [ |
| 5558 | sym_bytes[0], |
| 5559 | sym_bytes[1], |
| 5560 | sym_bytes[2], |
| 5561 | sym_bytes[3], |
| 5562 | mods_bytes[0], |
| 5563 | match_bytes[0], |
| 5564 | virtual_mod_bytes[0], |
| 5565 | flags_bytes[0], |
| 5566 | action_bytes[0], |
| 5567 | action_bytes[1], |
| 5568 | action_bytes[2], |
| 5569 | action_bytes[3], |
| 5570 | action_bytes[4], |
| 5571 | action_bytes[5], |
| 5572 | action_bytes[6], |
| 5573 | action_bytes[7], |
| 5574 | ] |
| 5575 | } |
| 5576 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 5577 | bytes.reserve(16); |
| 5578 | self.sym.serialize_into(bytes); |
| 5579 | (u16::from(self.mods) as u8).serialize_into(bytes); |
| 5580 | self.match_.serialize_into(bytes); |
| 5581 | u8::from(self.virtual_mod).serialize_into(bytes); |
| 5582 | self.flags.serialize_into(bytes); |
| 5583 | self.action.serialize_into(bytes); |
| 5584 | } |
| 5585 | } |
| 5586 | |
| 5587 | #[derive (Debug, Copy, Clone)] |
| 5588 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5589 | pub struct Action([u8; 8]); |
| 5590 | impl Action { |
| 5591 | pub fn as_noaction(&self) -> SANoAction { |
| 5592 | fn do_the_parse(remaining: &[u8]) -> Result<SANoAction, ParseError> { |
| 5593 | let (noaction, remaining) = SANoAction::try_parse(remaining)?; |
| 5594 | let _ = remaining; |
| 5595 | Ok(noaction) |
| 5596 | } |
| 5597 | do_the_parse(&self.0).unwrap() |
| 5598 | } |
| 5599 | pub fn as_setmods(&self) -> SASetMods { |
| 5600 | fn do_the_parse(remaining: &[u8]) -> Result<SASetMods, ParseError> { |
| 5601 | let (setmods, remaining) = SASetMods::try_parse(remaining)?; |
| 5602 | let _ = remaining; |
| 5603 | Ok(setmods) |
| 5604 | } |
| 5605 | do_the_parse(&self.0).unwrap() |
| 5606 | } |
| 5607 | pub fn as_latchmods(&self) -> SALatchMods { |
| 5608 | fn do_the_parse(remaining: &[u8]) -> Result<SALatchMods, ParseError> { |
| 5609 | let (latchmods, remaining) = SALatchMods::try_parse(remaining)?; |
| 5610 | let _ = remaining; |
| 5611 | Ok(latchmods) |
| 5612 | } |
| 5613 | do_the_parse(&self.0).unwrap() |
| 5614 | } |
| 5615 | pub fn as_lockmods(&self) -> SALockMods { |
| 5616 | fn do_the_parse(remaining: &[u8]) -> Result<SALockMods, ParseError> { |
| 5617 | let (lockmods, remaining) = SALockMods::try_parse(remaining)?; |
| 5618 | let _ = remaining; |
| 5619 | Ok(lockmods) |
| 5620 | } |
| 5621 | do_the_parse(&self.0).unwrap() |
| 5622 | } |
| 5623 | pub fn as_setgroup(&self) -> SASetGroup { |
| 5624 | fn do_the_parse(remaining: &[u8]) -> Result<SASetGroup, ParseError> { |
| 5625 | let (setgroup, remaining) = SASetGroup::try_parse(remaining)?; |
| 5626 | let _ = remaining; |
| 5627 | Ok(setgroup) |
| 5628 | } |
| 5629 | do_the_parse(&self.0).unwrap() |
| 5630 | } |
| 5631 | pub fn as_latchgroup(&self) -> SALatchGroup { |
| 5632 | fn do_the_parse(remaining: &[u8]) -> Result<SALatchGroup, ParseError> { |
| 5633 | let (latchgroup, remaining) = SALatchGroup::try_parse(remaining)?; |
| 5634 | let _ = remaining; |
| 5635 | Ok(latchgroup) |
| 5636 | } |
| 5637 | do_the_parse(&self.0).unwrap() |
| 5638 | } |
| 5639 | pub fn as_lockgroup(&self) -> SALockGroup { |
| 5640 | fn do_the_parse(remaining: &[u8]) -> Result<SALockGroup, ParseError> { |
| 5641 | let (lockgroup, remaining) = SALockGroup::try_parse(remaining)?; |
| 5642 | let _ = remaining; |
| 5643 | Ok(lockgroup) |
| 5644 | } |
| 5645 | do_the_parse(&self.0).unwrap() |
| 5646 | } |
| 5647 | pub fn as_moveptr(&self) -> SAMovePtr { |
| 5648 | fn do_the_parse(remaining: &[u8]) -> Result<SAMovePtr, ParseError> { |
| 5649 | let (moveptr, remaining) = SAMovePtr::try_parse(remaining)?; |
| 5650 | let _ = remaining; |
| 5651 | Ok(moveptr) |
| 5652 | } |
| 5653 | do_the_parse(&self.0).unwrap() |
| 5654 | } |
| 5655 | pub fn as_ptrbtn(&self) -> SAPtrBtn { |
| 5656 | fn do_the_parse(remaining: &[u8]) -> Result<SAPtrBtn, ParseError> { |
| 5657 | let (ptrbtn, remaining) = SAPtrBtn::try_parse(remaining)?; |
| 5658 | let _ = remaining; |
| 5659 | Ok(ptrbtn) |
| 5660 | } |
| 5661 | do_the_parse(&self.0).unwrap() |
| 5662 | } |
| 5663 | pub fn as_lockptrbtn(&self) -> SALockPtrBtn { |
| 5664 | fn do_the_parse(remaining: &[u8]) -> Result<SALockPtrBtn, ParseError> { |
| 5665 | let (lockptrbtn, remaining) = SALockPtrBtn::try_parse(remaining)?; |
| 5666 | let _ = remaining; |
| 5667 | Ok(lockptrbtn) |
| 5668 | } |
| 5669 | do_the_parse(&self.0).unwrap() |
| 5670 | } |
| 5671 | pub fn as_setptrdflt(&self) -> SASetPtrDflt { |
| 5672 | fn do_the_parse(remaining: &[u8]) -> Result<SASetPtrDflt, ParseError> { |
| 5673 | let (setptrdflt, remaining) = SASetPtrDflt::try_parse(remaining)?; |
| 5674 | let _ = remaining; |
| 5675 | Ok(setptrdflt) |
| 5676 | } |
| 5677 | do_the_parse(&self.0).unwrap() |
| 5678 | } |
| 5679 | pub fn as_isolock(&self) -> SAIsoLock { |
| 5680 | fn do_the_parse(remaining: &[u8]) -> Result<SAIsoLock, ParseError> { |
| 5681 | let (isolock, remaining) = SAIsoLock::try_parse(remaining)?; |
| 5682 | let _ = remaining; |
| 5683 | Ok(isolock) |
| 5684 | } |
| 5685 | do_the_parse(&self.0).unwrap() |
| 5686 | } |
| 5687 | pub fn as_terminate(&self) -> SATerminate { |
| 5688 | fn do_the_parse(remaining: &[u8]) -> Result<SATerminate, ParseError> { |
| 5689 | let (terminate, remaining) = SATerminate::try_parse(remaining)?; |
| 5690 | let _ = remaining; |
| 5691 | Ok(terminate) |
| 5692 | } |
| 5693 | do_the_parse(&self.0).unwrap() |
| 5694 | } |
| 5695 | pub fn as_switchscreen(&self) -> SASwitchScreen { |
| 5696 | fn do_the_parse(remaining: &[u8]) -> Result<SASwitchScreen, ParseError> { |
| 5697 | let (switchscreen, remaining) = SASwitchScreen::try_parse(remaining)?; |
| 5698 | let _ = remaining; |
| 5699 | Ok(switchscreen) |
| 5700 | } |
| 5701 | do_the_parse(&self.0).unwrap() |
| 5702 | } |
| 5703 | pub fn as_setcontrols(&self) -> SASetControls { |
| 5704 | fn do_the_parse(remaining: &[u8]) -> Result<SASetControls, ParseError> { |
| 5705 | let (setcontrols, remaining) = SASetControls::try_parse(remaining)?; |
| 5706 | let _ = remaining; |
| 5707 | Ok(setcontrols) |
| 5708 | } |
| 5709 | do_the_parse(&self.0).unwrap() |
| 5710 | } |
| 5711 | pub fn as_lockcontrols(&self) -> SALockControls { |
| 5712 | fn do_the_parse(remaining: &[u8]) -> Result<SALockControls, ParseError> { |
| 5713 | let (lockcontrols, remaining) = SALockControls::try_parse(remaining)?; |
| 5714 | let _ = remaining; |
| 5715 | Ok(lockcontrols) |
| 5716 | } |
| 5717 | do_the_parse(&self.0).unwrap() |
| 5718 | } |
| 5719 | pub fn as_message(&self) -> SAActionMessage { |
| 5720 | fn do_the_parse(remaining: &[u8]) -> Result<SAActionMessage, ParseError> { |
| 5721 | let (message, remaining) = SAActionMessage::try_parse(remaining)?; |
| 5722 | let _ = remaining; |
| 5723 | Ok(message) |
| 5724 | } |
| 5725 | do_the_parse(&self.0).unwrap() |
| 5726 | } |
| 5727 | pub fn as_redirect(&self) -> SARedirectKey { |
| 5728 | fn do_the_parse(remaining: &[u8]) -> Result<SARedirectKey, ParseError> { |
| 5729 | let (redirect, remaining) = SARedirectKey::try_parse(remaining)?; |
| 5730 | let _ = remaining; |
| 5731 | Ok(redirect) |
| 5732 | } |
| 5733 | do_the_parse(&self.0).unwrap() |
| 5734 | } |
| 5735 | pub fn as_devbtn(&self) -> SADeviceBtn { |
| 5736 | fn do_the_parse(remaining: &[u8]) -> Result<SADeviceBtn, ParseError> { |
| 5737 | let (devbtn, remaining) = SADeviceBtn::try_parse(remaining)?; |
| 5738 | let _ = remaining; |
| 5739 | Ok(devbtn) |
| 5740 | } |
| 5741 | do_the_parse(&self.0).unwrap() |
| 5742 | } |
| 5743 | pub fn as_lockdevbtn(&self) -> SALockDeviceBtn { |
| 5744 | fn do_the_parse(remaining: &[u8]) -> Result<SALockDeviceBtn, ParseError> { |
| 5745 | let (lockdevbtn, remaining) = SALockDeviceBtn::try_parse(remaining)?; |
| 5746 | let _ = remaining; |
| 5747 | Ok(lockdevbtn) |
| 5748 | } |
| 5749 | do_the_parse(&self.0).unwrap() |
| 5750 | } |
| 5751 | pub fn as_devval(&self) -> SADeviceValuator { |
| 5752 | fn do_the_parse(remaining: &[u8]) -> Result<SADeviceValuator, ParseError> { |
| 5753 | let (devval, remaining) = SADeviceValuator::try_parse(remaining)?; |
| 5754 | let _ = remaining; |
| 5755 | Ok(devval) |
| 5756 | } |
| 5757 | do_the_parse(&self.0).unwrap() |
| 5758 | } |
| 5759 | pub fn as_type(&self) -> SAType { |
| 5760 | fn do_the_parse(remaining: &[u8]) -> Result<SAType, ParseError> { |
| 5761 | let (type_, remaining) = u8::try_parse(remaining)?; |
| 5762 | let type_ = type_.into(); |
| 5763 | let _ = remaining; |
| 5764 | Ok(type_) |
| 5765 | } |
| 5766 | do_the_parse(&self.0).unwrap() |
| 5767 | } |
| 5768 | } |
| 5769 | impl Serialize for Action { |
| 5770 | type Bytes = [u8; 8]; |
| 5771 | fn serialize(&self) -> [u8; 8] { |
| 5772 | self.0 |
| 5773 | } |
| 5774 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 5775 | bytes.extend_from_slice(&self.0); |
| 5776 | } |
| 5777 | } |
| 5778 | impl TryParse for Action { |
| 5779 | fn try_parse(value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 5780 | let inner: [u8; 8] = valueResult<[u8; 8], TryFromSliceError>.get(..8) |
| 5781 | .ok_or(err:ParseError::InsufficientData)? |
| 5782 | .try_into() |
| 5783 | .unwrap(); |
| 5784 | let result: Action = Action(inner); |
| 5785 | Ok((result, &value[8..])) |
| 5786 | } |
| 5787 | } |
| 5788 | impl From<SANoAction> for Action { |
| 5789 | fn from(noaction: SANoAction) -> Self { |
| 5790 | let noaction_bytes: [u8; 8] = noaction.serialize(); |
| 5791 | Self(noaction_bytes) |
| 5792 | } |
| 5793 | } |
| 5794 | impl From<SASetMods> for Action { |
| 5795 | fn from(setmods: SASetMods) -> Self { |
| 5796 | let setmods_bytes: [u8; 8] = setmods.serialize(); |
| 5797 | Self(setmods_bytes) |
| 5798 | } |
| 5799 | } |
| 5800 | impl From<SASetGroup> for Action { |
| 5801 | fn from(setgroup: SASetGroup) -> Self { |
| 5802 | let setgroup_bytes: [u8; 8] = setgroup.serialize(); |
| 5803 | Self(setgroup_bytes) |
| 5804 | } |
| 5805 | } |
| 5806 | impl From<SAMovePtr> for Action { |
| 5807 | fn from(moveptr: SAMovePtr) -> Self { |
| 5808 | let moveptr_bytes: [u8; 8] = moveptr.serialize(); |
| 5809 | Self(moveptr_bytes) |
| 5810 | } |
| 5811 | } |
| 5812 | impl From<SAPtrBtn> for Action { |
| 5813 | fn from(ptrbtn: SAPtrBtn) -> Self { |
| 5814 | let ptrbtn_bytes: [u8; 8] = ptrbtn.serialize(); |
| 5815 | Self(ptrbtn_bytes) |
| 5816 | } |
| 5817 | } |
| 5818 | impl From<SALockPtrBtn> for Action { |
| 5819 | fn from(lockptrbtn: SALockPtrBtn) -> Self { |
| 5820 | let lockptrbtn_bytes: [u8; 8] = lockptrbtn.serialize(); |
| 5821 | Self(lockptrbtn_bytes) |
| 5822 | } |
| 5823 | } |
| 5824 | impl From<SASetPtrDflt> for Action { |
| 5825 | fn from(setptrdflt: SASetPtrDflt) -> Self { |
| 5826 | let setptrdflt_bytes: [u8; 8] = setptrdflt.serialize(); |
| 5827 | Self(setptrdflt_bytes) |
| 5828 | } |
| 5829 | } |
| 5830 | impl From<SAIsoLock> for Action { |
| 5831 | fn from(isolock: SAIsoLock) -> Self { |
| 5832 | let isolock_bytes: [u8; 8] = isolock.serialize(); |
| 5833 | Self(isolock_bytes) |
| 5834 | } |
| 5835 | } |
| 5836 | impl From<SATerminate> for Action { |
| 5837 | fn from(terminate: SATerminate) -> Self { |
| 5838 | let terminate_bytes: [u8; 8] = terminate.serialize(); |
| 5839 | Self(terminate_bytes) |
| 5840 | } |
| 5841 | } |
| 5842 | impl From<SASwitchScreen> for Action { |
| 5843 | fn from(switchscreen: SASwitchScreen) -> Self { |
| 5844 | let switchscreen_bytes: [u8; 8] = switchscreen.serialize(); |
| 5845 | Self(switchscreen_bytes) |
| 5846 | } |
| 5847 | } |
| 5848 | impl From<SASetControls> for Action { |
| 5849 | fn from(setcontrols: SASetControls) -> Self { |
| 5850 | let setcontrols_bytes: [u8; 8] = setcontrols.serialize(); |
| 5851 | Self(setcontrols_bytes) |
| 5852 | } |
| 5853 | } |
| 5854 | impl From<SAActionMessage> for Action { |
| 5855 | fn from(message: SAActionMessage) -> Self { |
| 5856 | let message_bytes: [u8; 8] = message.serialize(); |
| 5857 | Self(message_bytes) |
| 5858 | } |
| 5859 | } |
| 5860 | impl From<SARedirectKey> for Action { |
| 5861 | fn from(redirect: SARedirectKey) -> Self { |
| 5862 | let redirect_bytes: [u8; 8] = redirect.serialize(); |
| 5863 | Self(redirect_bytes) |
| 5864 | } |
| 5865 | } |
| 5866 | impl From<SADeviceBtn> for Action { |
| 5867 | fn from(devbtn: SADeviceBtn) -> Self { |
| 5868 | let devbtn_bytes: [u8; 8] = devbtn.serialize(); |
| 5869 | Self(devbtn_bytes) |
| 5870 | } |
| 5871 | } |
| 5872 | impl From<SALockDeviceBtn> for Action { |
| 5873 | fn from(lockdevbtn: SALockDeviceBtn) -> Self { |
| 5874 | let lockdevbtn_bytes: [u8; 8] = lockdevbtn.serialize(); |
| 5875 | Self(lockdevbtn_bytes) |
| 5876 | } |
| 5877 | } |
| 5878 | impl From<SADeviceValuator> for Action { |
| 5879 | fn from(devval: SADeviceValuator) -> Self { |
| 5880 | let devval_bytes: [u8; 8] = devval.serialize(); |
| 5881 | Self(devval_bytes) |
| 5882 | } |
| 5883 | } |
| 5884 | impl From<SAType> for Action { |
| 5885 | fn from(type_: SAType) -> Self { |
| 5886 | let type_bytes: [u8; 1] = u8::from(type_).serialize(); |
| 5887 | let value: [u8; 8] = [ |
| 5888 | type_bytes[0], |
| 5889 | 0, |
| 5890 | 0, |
| 5891 | 0, |
| 5892 | 0, |
| 5893 | 0, |
| 5894 | 0, |
| 5895 | 0, |
| 5896 | ]; |
| 5897 | Self(value) |
| 5898 | } |
| 5899 | } |
| 5900 | |
| 5901 | /// Opcode for the UseExtension request |
| 5902 | pub const USE_EXTENSION_REQUEST: u8 = 0; |
| 5903 | #[derive (Clone, Copy, Default)] |
| 5904 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 5905 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5906 | pub struct UseExtensionRequest { |
| 5907 | pub wanted_major: u16, |
| 5908 | pub wanted_minor: u16, |
| 5909 | } |
| 5910 | impl_debug_if_no_extra_traits!(UseExtensionRequest, "UseExtensionRequest" ); |
| 5911 | impl UseExtensionRequest { |
| 5912 | /// Serialize this request into bytes for the provided connection |
| 5913 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 5914 | let length_so_far = 0; |
| 5915 | let wanted_major_bytes = self.wanted_major.serialize(); |
| 5916 | let wanted_minor_bytes = self.wanted_minor.serialize(); |
| 5917 | let mut request0 = vec![ |
| 5918 | major_opcode, |
| 5919 | USE_EXTENSION_REQUEST, |
| 5920 | 0, |
| 5921 | 0, |
| 5922 | wanted_major_bytes[0], |
| 5923 | wanted_major_bytes[1], |
| 5924 | wanted_minor_bytes[0], |
| 5925 | wanted_minor_bytes[1], |
| 5926 | ]; |
| 5927 | let length_so_far = length_so_far + request0.len(); |
| 5928 | assert_eq!(length_so_far % 4, 0); |
| 5929 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 5930 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 5931 | ([request0.into()], vec![]) |
| 5932 | } |
| 5933 | /// Parse this request given its header, its body, and any fds that go along with it |
| 5934 | #[cfg (feature = "request-parsing" )] |
| 5935 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 5936 | if header.minor_opcode != USE_EXTENSION_REQUEST { |
| 5937 | return Err(ParseError::InvalidValue); |
| 5938 | } |
| 5939 | let (wanted_major, remaining) = u16::try_parse(value)?; |
| 5940 | let (wanted_minor, remaining) = u16::try_parse(remaining)?; |
| 5941 | let _ = remaining; |
| 5942 | Ok(UseExtensionRequest { |
| 5943 | wanted_major, |
| 5944 | wanted_minor, |
| 5945 | }) |
| 5946 | } |
| 5947 | } |
| 5948 | impl Request for UseExtensionRequest { |
| 5949 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 5950 | |
| 5951 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 5952 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 5953 | // Flatten the buffers into a single vector |
| 5954 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 5955 | (buf, fds) |
| 5956 | } |
| 5957 | } |
| 5958 | impl crate::x11_utils::ReplyRequest for UseExtensionRequest { |
| 5959 | type Reply = UseExtensionReply; |
| 5960 | } |
| 5961 | |
| 5962 | #[derive (Clone, Copy, Default)] |
| 5963 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 5964 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 5965 | pub struct UseExtensionReply { |
| 5966 | pub supported: bool, |
| 5967 | pub sequence: u16, |
| 5968 | pub length: u32, |
| 5969 | pub server_major: u16, |
| 5970 | pub server_minor: u16, |
| 5971 | } |
| 5972 | impl_debug_if_no_extra_traits!(UseExtensionReply, "UseExtensionReply" ); |
| 5973 | impl TryParse for UseExtensionReply { |
| 5974 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 5975 | let remaining: &[u8] = initial_value; |
| 5976 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 5977 | let (supported: bool, remaining: &[u8]) = bool::try_parse(remaining)?; |
| 5978 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 5979 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 5980 | let (server_major: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 5981 | let (server_minor: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 5982 | let remaining: &[u8] = remaining.get(20..).ok_or(err:ParseError::InsufficientData)?; |
| 5983 | if response_type != 1 { |
| 5984 | return Err(ParseError::InvalidValue); |
| 5985 | } |
| 5986 | let result: UseExtensionReply = UseExtensionReply { supported, sequence, length, server_major, server_minor }; |
| 5987 | let _ = remaining; |
| 5988 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 5989 | .ok_or(err:ParseError::InsufficientData)?; |
| 5990 | Ok((result, remaining)) |
| 5991 | } |
| 5992 | } |
| 5993 | impl Serialize for UseExtensionReply { |
| 5994 | type Bytes = [u8; 32]; |
| 5995 | fn serialize(&self) -> [u8; 32] { |
| 5996 | let response_type_bytes = &[1]; |
| 5997 | let supported_bytes = self.supported.serialize(); |
| 5998 | let sequence_bytes = self.sequence.serialize(); |
| 5999 | let length_bytes = self.length.serialize(); |
| 6000 | let server_major_bytes = self.server_major.serialize(); |
| 6001 | let server_minor_bytes = self.server_minor.serialize(); |
| 6002 | [ |
| 6003 | response_type_bytes[0], |
| 6004 | supported_bytes[0], |
| 6005 | sequence_bytes[0], |
| 6006 | sequence_bytes[1], |
| 6007 | length_bytes[0], |
| 6008 | length_bytes[1], |
| 6009 | length_bytes[2], |
| 6010 | length_bytes[3], |
| 6011 | server_major_bytes[0], |
| 6012 | server_major_bytes[1], |
| 6013 | server_minor_bytes[0], |
| 6014 | server_minor_bytes[1], |
| 6015 | 0, |
| 6016 | 0, |
| 6017 | 0, |
| 6018 | 0, |
| 6019 | 0, |
| 6020 | 0, |
| 6021 | 0, |
| 6022 | 0, |
| 6023 | 0, |
| 6024 | 0, |
| 6025 | 0, |
| 6026 | 0, |
| 6027 | 0, |
| 6028 | 0, |
| 6029 | 0, |
| 6030 | 0, |
| 6031 | 0, |
| 6032 | 0, |
| 6033 | 0, |
| 6034 | 0, |
| 6035 | ] |
| 6036 | } |
| 6037 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 6038 | bytes.reserve(32); |
| 6039 | let response_type_bytes = &[1]; |
| 6040 | bytes.push(response_type_bytes[0]); |
| 6041 | self.supported.serialize_into(bytes); |
| 6042 | self.sequence.serialize_into(bytes); |
| 6043 | self.length.serialize_into(bytes); |
| 6044 | self.server_major.serialize_into(bytes); |
| 6045 | self.server_minor.serialize_into(bytes); |
| 6046 | bytes.extend_from_slice(&[0; 20]); |
| 6047 | } |
| 6048 | } |
| 6049 | |
| 6050 | #[derive (Clone, Copy)] |
| 6051 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6052 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6053 | pub struct SelectEventsAuxNewKeyboardNotify { |
| 6054 | pub affect_new_keyboard: NKNDetail, |
| 6055 | pub new_keyboard_details: NKNDetail, |
| 6056 | } |
| 6057 | impl_debug_if_no_extra_traits!(SelectEventsAuxNewKeyboardNotify, "SelectEventsAuxNewKeyboardNotify" ); |
| 6058 | impl TryParse for SelectEventsAuxNewKeyboardNotify { |
| 6059 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 6060 | let (affect_new_keyboard: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 6061 | let (new_keyboard_details: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 6062 | let affect_new_keyboard: NKNDetail = affect_new_keyboard.into(); |
| 6063 | let new_keyboard_details: NKNDetail = new_keyboard_details.into(); |
| 6064 | let result: SelectEventsAuxNewKeyboardNotify = SelectEventsAuxNewKeyboardNotify { affect_new_keyboard, new_keyboard_details }; |
| 6065 | Ok((result, remaining)) |
| 6066 | } |
| 6067 | } |
| 6068 | impl Serialize for SelectEventsAuxNewKeyboardNotify { |
| 6069 | type Bytes = [u8; 4]; |
| 6070 | fn serialize(&self) -> [u8; 4] { |
| 6071 | let affect_new_keyboard_bytes: [u8; 2] = u16::from(self.affect_new_keyboard).serialize(); |
| 6072 | let new_keyboard_details_bytes: [u8; 2] = u16::from(self.new_keyboard_details).serialize(); |
| 6073 | [ |
| 6074 | affect_new_keyboard_bytes[0], |
| 6075 | affect_new_keyboard_bytes[1], |
| 6076 | new_keyboard_details_bytes[0], |
| 6077 | new_keyboard_details_bytes[1], |
| 6078 | ] |
| 6079 | } |
| 6080 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 6081 | bytes.reserve(additional:4); |
| 6082 | u16::from(self.affect_new_keyboard).serialize_into(bytes); |
| 6083 | u16::from(self.new_keyboard_details).serialize_into(bytes); |
| 6084 | } |
| 6085 | } |
| 6086 | #[derive (Clone, Copy)] |
| 6087 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6088 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6089 | pub struct SelectEventsAuxStateNotify { |
| 6090 | pub affect_state: StatePart, |
| 6091 | pub state_details: StatePart, |
| 6092 | } |
| 6093 | impl_debug_if_no_extra_traits!(SelectEventsAuxStateNotify, "SelectEventsAuxStateNotify" ); |
| 6094 | impl TryParse for SelectEventsAuxStateNotify { |
| 6095 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 6096 | let (affect_state: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 6097 | let (state_details: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 6098 | let affect_state: StatePart = affect_state.into(); |
| 6099 | let state_details: StatePart = state_details.into(); |
| 6100 | let result: SelectEventsAuxStateNotify = SelectEventsAuxStateNotify { affect_state, state_details }; |
| 6101 | Ok((result, remaining)) |
| 6102 | } |
| 6103 | } |
| 6104 | impl Serialize for SelectEventsAuxStateNotify { |
| 6105 | type Bytes = [u8; 4]; |
| 6106 | fn serialize(&self) -> [u8; 4] { |
| 6107 | let affect_state_bytes: [u8; 2] = u16::from(self.affect_state).serialize(); |
| 6108 | let state_details_bytes: [u8; 2] = u16::from(self.state_details).serialize(); |
| 6109 | [ |
| 6110 | affect_state_bytes[0], |
| 6111 | affect_state_bytes[1], |
| 6112 | state_details_bytes[0], |
| 6113 | state_details_bytes[1], |
| 6114 | ] |
| 6115 | } |
| 6116 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 6117 | bytes.reserve(additional:4); |
| 6118 | u16::from(self.affect_state).serialize_into(bytes); |
| 6119 | u16::from(self.state_details).serialize_into(bytes); |
| 6120 | } |
| 6121 | } |
| 6122 | #[derive (Clone, Copy)] |
| 6123 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6124 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6125 | pub struct SelectEventsAuxControlsNotify { |
| 6126 | pub affect_ctrls: Control, |
| 6127 | pub ctrl_details: Control, |
| 6128 | } |
| 6129 | impl_debug_if_no_extra_traits!(SelectEventsAuxControlsNotify, "SelectEventsAuxControlsNotify" ); |
| 6130 | impl TryParse for SelectEventsAuxControlsNotify { |
| 6131 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 6132 | let (affect_ctrls: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 6133 | let (ctrl_details: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 6134 | let affect_ctrls: Control = affect_ctrls.into(); |
| 6135 | let ctrl_details: Control = ctrl_details.into(); |
| 6136 | let result: SelectEventsAuxControlsNotify = SelectEventsAuxControlsNotify { affect_ctrls, ctrl_details }; |
| 6137 | Ok((result, remaining)) |
| 6138 | } |
| 6139 | } |
| 6140 | impl Serialize for SelectEventsAuxControlsNotify { |
| 6141 | type Bytes = [u8; 8]; |
| 6142 | fn serialize(&self) -> [u8; 8] { |
| 6143 | let affect_ctrls_bytes: [u8; 4] = u32::from(self.affect_ctrls).serialize(); |
| 6144 | let ctrl_details_bytes: [u8; 4] = u32::from(self.ctrl_details).serialize(); |
| 6145 | [ |
| 6146 | affect_ctrls_bytes[0], |
| 6147 | affect_ctrls_bytes[1], |
| 6148 | affect_ctrls_bytes[2], |
| 6149 | affect_ctrls_bytes[3], |
| 6150 | ctrl_details_bytes[0], |
| 6151 | ctrl_details_bytes[1], |
| 6152 | ctrl_details_bytes[2], |
| 6153 | ctrl_details_bytes[3], |
| 6154 | ] |
| 6155 | } |
| 6156 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 6157 | bytes.reserve(additional:8); |
| 6158 | u32::from(self.affect_ctrls).serialize_into(bytes); |
| 6159 | u32::from(self.ctrl_details).serialize_into(bytes); |
| 6160 | } |
| 6161 | } |
| 6162 | #[derive (Clone, Copy)] |
| 6163 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6164 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6165 | pub struct SelectEventsAuxIndicatorStateNotify { |
| 6166 | pub affect_indicator_state: u32, |
| 6167 | pub indicator_state_details: u32, |
| 6168 | } |
| 6169 | impl_debug_if_no_extra_traits!(SelectEventsAuxIndicatorStateNotify, "SelectEventsAuxIndicatorStateNotify" ); |
| 6170 | impl TryParse for SelectEventsAuxIndicatorStateNotify { |
| 6171 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 6172 | let (affect_indicator_state: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 6173 | let (indicator_state_details: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 6174 | let result: SelectEventsAuxIndicatorStateNotify = SelectEventsAuxIndicatorStateNotify { affect_indicator_state, indicator_state_details }; |
| 6175 | Ok((result, remaining)) |
| 6176 | } |
| 6177 | } |
| 6178 | impl Serialize for SelectEventsAuxIndicatorStateNotify { |
| 6179 | type Bytes = [u8; 8]; |
| 6180 | fn serialize(&self) -> [u8; 8] { |
| 6181 | let affect_indicator_state_bytes: [u8; 4] = self.affect_indicator_state.serialize(); |
| 6182 | let indicator_state_details_bytes: [u8; 4] = self.indicator_state_details.serialize(); |
| 6183 | [ |
| 6184 | affect_indicator_state_bytes[0], |
| 6185 | affect_indicator_state_bytes[1], |
| 6186 | affect_indicator_state_bytes[2], |
| 6187 | affect_indicator_state_bytes[3], |
| 6188 | indicator_state_details_bytes[0], |
| 6189 | indicator_state_details_bytes[1], |
| 6190 | indicator_state_details_bytes[2], |
| 6191 | indicator_state_details_bytes[3], |
| 6192 | ] |
| 6193 | } |
| 6194 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 6195 | bytes.reserve(additional:8); |
| 6196 | self.affect_indicator_state.serialize_into(bytes); |
| 6197 | self.indicator_state_details.serialize_into(bytes); |
| 6198 | } |
| 6199 | } |
| 6200 | #[derive (Clone, Copy)] |
| 6201 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6202 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6203 | pub struct SelectEventsAuxIndicatorMapNotify { |
| 6204 | pub affect_indicator_map: u32, |
| 6205 | pub indicator_map_details: u32, |
| 6206 | } |
| 6207 | impl_debug_if_no_extra_traits!(SelectEventsAuxIndicatorMapNotify, "SelectEventsAuxIndicatorMapNotify" ); |
| 6208 | impl TryParse for SelectEventsAuxIndicatorMapNotify { |
| 6209 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 6210 | let (affect_indicator_map: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 6211 | let (indicator_map_details: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 6212 | let result: SelectEventsAuxIndicatorMapNotify = SelectEventsAuxIndicatorMapNotify { affect_indicator_map, indicator_map_details }; |
| 6213 | Ok((result, remaining)) |
| 6214 | } |
| 6215 | } |
| 6216 | impl Serialize for SelectEventsAuxIndicatorMapNotify { |
| 6217 | type Bytes = [u8; 8]; |
| 6218 | fn serialize(&self) -> [u8; 8] { |
| 6219 | let affect_indicator_map_bytes: [u8; 4] = self.affect_indicator_map.serialize(); |
| 6220 | let indicator_map_details_bytes: [u8; 4] = self.indicator_map_details.serialize(); |
| 6221 | [ |
| 6222 | affect_indicator_map_bytes[0], |
| 6223 | affect_indicator_map_bytes[1], |
| 6224 | affect_indicator_map_bytes[2], |
| 6225 | affect_indicator_map_bytes[3], |
| 6226 | indicator_map_details_bytes[0], |
| 6227 | indicator_map_details_bytes[1], |
| 6228 | indicator_map_details_bytes[2], |
| 6229 | indicator_map_details_bytes[3], |
| 6230 | ] |
| 6231 | } |
| 6232 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 6233 | bytes.reserve(additional:8); |
| 6234 | self.affect_indicator_map.serialize_into(bytes); |
| 6235 | self.indicator_map_details.serialize_into(bytes); |
| 6236 | } |
| 6237 | } |
| 6238 | #[derive (Clone, Copy)] |
| 6239 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6240 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6241 | pub struct SelectEventsAuxNamesNotify { |
| 6242 | pub affect_names: NameDetail, |
| 6243 | pub names_details: NameDetail, |
| 6244 | } |
| 6245 | impl_debug_if_no_extra_traits!(SelectEventsAuxNamesNotify, "SelectEventsAuxNamesNotify" ); |
| 6246 | impl TryParse for SelectEventsAuxNamesNotify { |
| 6247 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 6248 | let (affect_names: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 6249 | let (names_details: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 6250 | let affect_names: NameDetail = affect_names.into(); |
| 6251 | let names_details: NameDetail = names_details.into(); |
| 6252 | let result: SelectEventsAuxNamesNotify = SelectEventsAuxNamesNotify { affect_names, names_details }; |
| 6253 | Ok((result, remaining)) |
| 6254 | } |
| 6255 | } |
| 6256 | impl Serialize for SelectEventsAuxNamesNotify { |
| 6257 | type Bytes = [u8; 4]; |
| 6258 | fn serialize(&self) -> [u8; 4] { |
| 6259 | let affect_names_bytes: [u8; 2] = (u32::from(self.affect_names) as u16).serialize(); |
| 6260 | let names_details_bytes: [u8; 2] = (u32::from(self.names_details) as u16).serialize(); |
| 6261 | [ |
| 6262 | affect_names_bytes[0], |
| 6263 | affect_names_bytes[1], |
| 6264 | names_details_bytes[0], |
| 6265 | names_details_bytes[1], |
| 6266 | ] |
| 6267 | } |
| 6268 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 6269 | bytes.reserve(additional:4); |
| 6270 | (u32::from(self.affect_names) as u16).serialize_into(bytes); |
| 6271 | (u32::from(self.names_details) as u16).serialize_into(bytes); |
| 6272 | } |
| 6273 | } |
| 6274 | #[derive (Clone, Copy)] |
| 6275 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6276 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6277 | pub struct SelectEventsAuxCompatMapNotify { |
| 6278 | pub affect_compat: CMDetail, |
| 6279 | pub compat_details: CMDetail, |
| 6280 | } |
| 6281 | impl_debug_if_no_extra_traits!(SelectEventsAuxCompatMapNotify, "SelectEventsAuxCompatMapNotify" ); |
| 6282 | impl TryParse for SelectEventsAuxCompatMapNotify { |
| 6283 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 6284 | let (affect_compat: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 6285 | let (compat_details: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 6286 | let affect_compat: CMDetail = affect_compat.into(); |
| 6287 | let compat_details: CMDetail = compat_details.into(); |
| 6288 | let result: SelectEventsAuxCompatMapNotify = SelectEventsAuxCompatMapNotify { affect_compat, compat_details }; |
| 6289 | Ok((result, remaining)) |
| 6290 | } |
| 6291 | } |
| 6292 | impl Serialize for SelectEventsAuxCompatMapNotify { |
| 6293 | type Bytes = [u8; 2]; |
| 6294 | fn serialize(&self) -> [u8; 2] { |
| 6295 | let affect_compat_bytes: [u8; 1] = u8::from(self.affect_compat).serialize(); |
| 6296 | let compat_details_bytes: [u8; 1] = u8::from(self.compat_details).serialize(); |
| 6297 | [ |
| 6298 | affect_compat_bytes[0], |
| 6299 | compat_details_bytes[0], |
| 6300 | ] |
| 6301 | } |
| 6302 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 6303 | bytes.reserve(additional:2); |
| 6304 | u8::from(self.affect_compat).serialize_into(bytes); |
| 6305 | u8::from(self.compat_details).serialize_into(bytes); |
| 6306 | } |
| 6307 | } |
| 6308 | #[derive (Clone, Copy)] |
| 6309 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6310 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6311 | pub struct SelectEventsAuxBellNotify { |
| 6312 | pub affect_bell: u8, |
| 6313 | pub bell_details: u8, |
| 6314 | } |
| 6315 | impl_debug_if_no_extra_traits!(SelectEventsAuxBellNotify, "SelectEventsAuxBellNotify" ); |
| 6316 | impl TryParse for SelectEventsAuxBellNotify { |
| 6317 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 6318 | let (affect_bell: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 6319 | let (bell_details: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 6320 | let result: SelectEventsAuxBellNotify = SelectEventsAuxBellNotify { affect_bell, bell_details }; |
| 6321 | Ok((result, remaining)) |
| 6322 | } |
| 6323 | } |
| 6324 | impl Serialize for SelectEventsAuxBellNotify { |
| 6325 | type Bytes = [u8; 2]; |
| 6326 | fn serialize(&self) -> [u8; 2] { |
| 6327 | let affect_bell_bytes: [u8; 1] = self.affect_bell.serialize(); |
| 6328 | let bell_details_bytes: [u8; 1] = self.bell_details.serialize(); |
| 6329 | [ |
| 6330 | affect_bell_bytes[0], |
| 6331 | bell_details_bytes[0], |
| 6332 | ] |
| 6333 | } |
| 6334 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 6335 | bytes.reserve(additional:2); |
| 6336 | self.affect_bell.serialize_into(bytes); |
| 6337 | self.bell_details.serialize_into(bytes); |
| 6338 | } |
| 6339 | } |
| 6340 | #[derive (Clone, Copy)] |
| 6341 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6342 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6343 | pub struct SelectEventsAuxActionMessage { |
| 6344 | pub affect_msg_details: u8, |
| 6345 | pub msg_details: u8, |
| 6346 | } |
| 6347 | impl_debug_if_no_extra_traits!(SelectEventsAuxActionMessage, "SelectEventsAuxActionMessage" ); |
| 6348 | impl TryParse for SelectEventsAuxActionMessage { |
| 6349 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 6350 | let (affect_msg_details: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 6351 | let (msg_details: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 6352 | let result: SelectEventsAuxActionMessage = SelectEventsAuxActionMessage { affect_msg_details, msg_details }; |
| 6353 | Ok((result, remaining)) |
| 6354 | } |
| 6355 | } |
| 6356 | impl Serialize for SelectEventsAuxActionMessage { |
| 6357 | type Bytes = [u8; 2]; |
| 6358 | fn serialize(&self) -> [u8; 2] { |
| 6359 | let affect_msg_details_bytes: [u8; 1] = self.affect_msg_details.serialize(); |
| 6360 | let msg_details_bytes: [u8; 1] = self.msg_details.serialize(); |
| 6361 | [ |
| 6362 | affect_msg_details_bytes[0], |
| 6363 | msg_details_bytes[0], |
| 6364 | ] |
| 6365 | } |
| 6366 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 6367 | bytes.reserve(additional:2); |
| 6368 | self.affect_msg_details.serialize_into(bytes); |
| 6369 | self.msg_details.serialize_into(bytes); |
| 6370 | } |
| 6371 | } |
| 6372 | #[derive (Clone, Copy)] |
| 6373 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6374 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6375 | pub struct SelectEventsAuxAccessXNotify { |
| 6376 | pub affect_access_x: AXNDetail, |
| 6377 | pub access_x_details: AXNDetail, |
| 6378 | } |
| 6379 | impl_debug_if_no_extra_traits!(SelectEventsAuxAccessXNotify, "SelectEventsAuxAccessXNotify" ); |
| 6380 | impl TryParse for SelectEventsAuxAccessXNotify { |
| 6381 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 6382 | let (affect_access_x: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 6383 | let (access_x_details: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 6384 | let affect_access_x: AXNDetail = affect_access_x.into(); |
| 6385 | let access_x_details: AXNDetail = access_x_details.into(); |
| 6386 | let result: SelectEventsAuxAccessXNotify = SelectEventsAuxAccessXNotify { affect_access_x, access_x_details }; |
| 6387 | Ok((result, remaining)) |
| 6388 | } |
| 6389 | } |
| 6390 | impl Serialize for SelectEventsAuxAccessXNotify { |
| 6391 | type Bytes = [u8; 4]; |
| 6392 | fn serialize(&self) -> [u8; 4] { |
| 6393 | let affect_access_x_bytes: [u8; 2] = u16::from(self.affect_access_x).serialize(); |
| 6394 | let access_x_details_bytes: [u8; 2] = u16::from(self.access_x_details).serialize(); |
| 6395 | [ |
| 6396 | affect_access_x_bytes[0], |
| 6397 | affect_access_x_bytes[1], |
| 6398 | access_x_details_bytes[0], |
| 6399 | access_x_details_bytes[1], |
| 6400 | ] |
| 6401 | } |
| 6402 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 6403 | bytes.reserve(additional:4); |
| 6404 | u16::from(self.affect_access_x).serialize_into(bytes); |
| 6405 | u16::from(self.access_x_details).serialize_into(bytes); |
| 6406 | } |
| 6407 | } |
| 6408 | #[derive (Clone, Copy)] |
| 6409 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6410 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6411 | pub struct SelectEventsAuxExtensionDeviceNotify { |
| 6412 | pub affect_ext_dev: XIFeature, |
| 6413 | pub extdev_details: XIFeature, |
| 6414 | } |
| 6415 | impl_debug_if_no_extra_traits!(SelectEventsAuxExtensionDeviceNotify, "SelectEventsAuxExtensionDeviceNotify" ); |
| 6416 | impl TryParse for SelectEventsAuxExtensionDeviceNotify { |
| 6417 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 6418 | let (affect_ext_dev: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 6419 | let (extdev_details: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 6420 | let affect_ext_dev: XIFeature = affect_ext_dev.into(); |
| 6421 | let extdev_details: XIFeature = extdev_details.into(); |
| 6422 | let result: SelectEventsAuxExtensionDeviceNotify = SelectEventsAuxExtensionDeviceNotify { affect_ext_dev, extdev_details }; |
| 6423 | Ok((result, remaining)) |
| 6424 | } |
| 6425 | } |
| 6426 | impl Serialize for SelectEventsAuxExtensionDeviceNotify { |
| 6427 | type Bytes = [u8; 4]; |
| 6428 | fn serialize(&self) -> [u8; 4] { |
| 6429 | let affect_ext_dev_bytes: [u8; 2] = u16::from(self.affect_ext_dev).serialize(); |
| 6430 | let extdev_details_bytes: [u8; 2] = u16::from(self.extdev_details).serialize(); |
| 6431 | [ |
| 6432 | affect_ext_dev_bytes[0], |
| 6433 | affect_ext_dev_bytes[1], |
| 6434 | extdev_details_bytes[0], |
| 6435 | extdev_details_bytes[1], |
| 6436 | ] |
| 6437 | } |
| 6438 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 6439 | bytes.reserve(additional:4); |
| 6440 | u16::from(self.affect_ext_dev).serialize_into(bytes); |
| 6441 | u16::from(self.extdev_details).serialize_into(bytes); |
| 6442 | } |
| 6443 | } |
| 6444 | /// Auxiliary and optional information for the `select_events` function |
| 6445 | #[derive (Clone, Copy, Default)] |
| 6446 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6447 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6448 | pub struct SelectEventsAux { |
| 6449 | pub new_keyboard_notify: Option<SelectEventsAuxNewKeyboardNotify>, |
| 6450 | pub state_notify: Option<SelectEventsAuxStateNotify>, |
| 6451 | pub controls_notify: Option<SelectEventsAuxControlsNotify>, |
| 6452 | pub indicator_state_notify: Option<SelectEventsAuxIndicatorStateNotify>, |
| 6453 | pub indicator_map_notify: Option<SelectEventsAuxIndicatorMapNotify>, |
| 6454 | pub names_notify: Option<SelectEventsAuxNamesNotify>, |
| 6455 | pub compat_map_notify: Option<SelectEventsAuxCompatMapNotify>, |
| 6456 | pub bell_notify: Option<SelectEventsAuxBellNotify>, |
| 6457 | pub action_message: Option<SelectEventsAuxActionMessage>, |
| 6458 | pub access_x_notify: Option<SelectEventsAuxAccessXNotify>, |
| 6459 | pub extension_device_notify: Option<SelectEventsAuxExtensionDeviceNotify>, |
| 6460 | } |
| 6461 | impl_debug_if_no_extra_traits!(SelectEventsAux, "SelectEventsAux" ); |
| 6462 | impl SelectEventsAux { |
| 6463 | #[cfg_attr (not(feature = "request-parsing" ), allow(dead_code))] |
| 6464 | fn try_parse(value: &[u8], affect_which: u16, clear: u16, select_all: u16) -> Result<(Self, &[u8]), ParseError> { |
| 6465 | let switch_expr = u16::from(affect_which) & ((!u16::from(clear)) & (!u16::from(select_all))); |
| 6466 | let mut outer_remaining = value; |
| 6467 | let new_keyboard_notify = if switch_expr & u16::from(EventType::NEW_KEYBOARD_NOTIFY) != 0 { |
| 6468 | let (new_keyboard_notify, new_remaining) = SelectEventsAuxNewKeyboardNotify::try_parse(outer_remaining)?; |
| 6469 | outer_remaining = new_remaining; |
| 6470 | Some(new_keyboard_notify) |
| 6471 | } else { |
| 6472 | None |
| 6473 | }; |
| 6474 | let state_notify = if switch_expr & u16::from(EventType::STATE_NOTIFY) != 0 { |
| 6475 | let (state_notify, new_remaining) = SelectEventsAuxStateNotify::try_parse(outer_remaining)?; |
| 6476 | outer_remaining = new_remaining; |
| 6477 | Some(state_notify) |
| 6478 | } else { |
| 6479 | None |
| 6480 | }; |
| 6481 | let controls_notify = if switch_expr & u16::from(EventType::CONTROLS_NOTIFY) != 0 { |
| 6482 | let (controls_notify, new_remaining) = SelectEventsAuxControlsNotify::try_parse(outer_remaining)?; |
| 6483 | outer_remaining = new_remaining; |
| 6484 | Some(controls_notify) |
| 6485 | } else { |
| 6486 | None |
| 6487 | }; |
| 6488 | let indicator_state_notify = if switch_expr & u16::from(EventType::INDICATOR_STATE_NOTIFY) != 0 { |
| 6489 | let (indicator_state_notify, new_remaining) = SelectEventsAuxIndicatorStateNotify::try_parse(outer_remaining)?; |
| 6490 | outer_remaining = new_remaining; |
| 6491 | Some(indicator_state_notify) |
| 6492 | } else { |
| 6493 | None |
| 6494 | }; |
| 6495 | let indicator_map_notify = if switch_expr & u16::from(EventType::INDICATOR_MAP_NOTIFY) != 0 { |
| 6496 | let (indicator_map_notify, new_remaining) = SelectEventsAuxIndicatorMapNotify::try_parse(outer_remaining)?; |
| 6497 | outer_remaining = new_remaining; |
| 6498 | Some(indicator_map_notify) |
| 6499 | } else { |
| 6500 | None |
| 6501 | }; |
| 6502 | let names_notify = if switch_expr & u16::from(EventType::NAMES_NOTIFY) != 0 { |
| 6503 | let (names_notify, new_remaining) = SelectEventsAuxNamesNotify::try_parse(outer_remaining)?; |
| 6504 | outer_remaining = new_remaining; |
| 6505 | Some(names_notify) |
| 6506 | } else { |
| 6507 | None |
| 6508 | }; |
| 6509 | let compat_map_notify = if switch_expr & u16::from(EventType::COMPAT_MAP_NOTIFY) != 0 { |
| 6510 | let (compat_map_notify, new_remaining) = SelectEventsAuxCompatMapNotify::try_parse(outer_remaining)?; |
| 6511 | outer_remaining = new_remaining; |
| 6512 | Some(compat_map_notify) |
| 6513 | } else { |
| 6514 | None |
| 6515 | }; |
| 6516 | let bell_notify = if switch_expr & u16::from(EventType::BELL_NOTIFY) != 0 { |
| 6517 | let (bell_notify, new_remaining) = SelectEventsAuxBellNotify::try_parse(outer_remaining)?; |
| 6518 | outer_remaining = new_remaining; |
| 6519 | Some(bell_notify) |
| 6520 | } else { |
| 6521 | None |
| 6522 | }; |
| 6523 | let action_message = if switch_expr & u16::from(EventType::ACTION_MESSAGE) != 0 { |
| 6524 | let (action_message, new_remaining) = SelectEventsAuxActionMessage::try_parse(outer_remaining)?; |
| 6525 | outer_remaining = new_remaining; |
| 6526 | Some(action_message) |
| 6527 | } else { |
| 6528 | None |
| 6529 | }; |
| 6530 | let access_x_notify = if switch_expr & u16::from(EventType::ACCESS_X_NOTIFY) != 0 { |
| 6531 | let (access_x_notify, new_remaining) = SelectEventsAuxAccessXNotify::try_parse(outer_remaining)?; |
| 6532 | outer_remaining = new_remaining; |
| 6533 | Some(access_x_notify) |
| 6534 | } else { |
| 6535 | None |
| 6536 | }; |
| 6537 | let extension_device_notify = if switch_expr & u16::from(EventType::EXTENSION_DEVICE_NOTIFY) != 0 { |
| 6538 | let (extension_device_notify, new_remaining) = SelectEventsAuxExtensionDeviceNotify::try_parse(outer_remaining)?; |
| 6539 | outer_remaining = new_remaining; |
| 6540 | Some(extension_device_notify) |
| 6541 | } else { |
| 6542 | None |
| 6543 | }; |
| 6544 | let result = SelectEventsAux { new_keyboard_notify, state_notify, controls_notify, indicator_state_notify, indicator_map_notify, names_notify, compat_map_notify, bell_notify, action_message, access_x_notify, extension_device_notify }; |
| 6545 | Ok((result, outer_remaining)) |
| 6546 | } |
| 6547 | } |
| 6548 | impl SelectEventsAux { |
| 6549 | #[allow (dead_code)] |
| 6550 | fn serialize(&self, affect_which: u16, clear: u16, select_all: u16) -> Vec<u8> { |
| 6551 | let mut result = Vec::new(); |
| 6552 | self.serialize_into(&mut result, u16::from(affect_which), u16::from(clear), u16::from(select_all)); |
| 6553 | result |
| 6554 | } |
| 6555 | fn serialize_into(&self, bytes: &mut Vec<u8>, affect_which: u16, clear: u16, select_all: u16) { |
| 6556 | assert_eq!(self.switch_expr(), u16::from(affect_which) & ((!u16::from(clear)) & (!u16::from(select_all))), "switch `details` has an inconsistent discriminant" ); |
| 6557 | if let Some(ref new_keyboard_notify) = self.new_keyboard_notify { |
| 6558 | new_keyboard_notify.serialize_into(bytes); |
| 6559 | } |
| 6560 | if let Some(ref state_notify) = self.state_notify { |
| 6561 | state_notify.serialize_into(bytes); |
| 6562 | } |
| 6563 | if let Some(ref controls_notify) = self.controls_notify { |
| 6564 | controls_notify.serialize_into(bytes); |
| 6565 | } |
| 6566 | if let Some(ref indicator_state_notify) = self.indicator_state_notify { |
| 6567 | indicator_state_notify.serialize_into(bytes); |
| 6568 | } |
| 6569 | if let Some(ref indicator_map_notify) = self.indicator_map_notify { |
| 6570 | indicator_map_notify.serialize_into(bytes); |
| 6571 | } |
| 6572 | if let Some(ref names_notify) = self.names_notify { |
| 6573 | names_notify.serialize_into(bytes); |
| 6574 | } |
| 6575 | if let Some(ref compat_map_notify) = self.compat_map_notify { |
| 6576 | compat_map_notify.serialize_into(bytes); |
| 6577 | } |
| 6578 | if let Some(ref bell_notify) = self.bell_notify { |
| 6579 | bell_notify.serialize_into(bytes); |
| 6580 | } |
| 6581 | if let Some(ref action_message) = self.action_message { |
| 6582 | action_message.serialize_into(bytes); |
| 6583 | } |
| 6584 | if let Some(ref access_x_notify) = self.access_x_notify { |
| 6585 | access_x_notify.serialize_into(bytes); |
| 6586 | } |
| 6587 | if let Some(ref extension_device_notify) = self.extension_device_notify { |
| 6588 | extension_device_notify.serialize_into(bytes); |
| 6589 | } |
| 6590 | } |
| 6591 | } |
| 6592 | impl SelectEventsAux { |
| 6593 | fn switch_expr(&self) -> u16 { |
| 6594 | let mut expr_value = 0; |
| 6595 | if self.new_keyboard_notify.is_some() { |
| 6596 | expr_value |= u16::from(EventType::NEW_KEYBOARD_NOTIFY); |
| 6597 | } |
| 6598 | if self.state_notify.is_some() { |
| 6599 | expr_value |= u16::from(EventType::STATE_NOTIFY); |
| 6600 | } |
| 6601 | if self.controls_notify.is_some() { |
| 6602 | expr_value |= u16::from(EventType::CONTROLS_NOTIFY); |
| 6603 | } |
| 6604 | if self.indicator_state_notify.is_some() { |
| 6605 | expr_value |= u16::from(EventType::INDICATOR_STATE_NOTIFY); |
| 6606 | } |
| 6607 | if self.indicator_map_notify.is_some() { |
| 6608 | expr_value |= u16::from(EventType::INDICATOR_MAP_NOTIFY); |
| 6609 | } |
| 6610 | if self.names_notify.is_some() { |
| 6611 | expr_value |= u16::from(EventType::NAMES_NOTIFY); |
| 6612 | } |
| 6613 | if self.compat_map_notify.is_some() { |
| 6614 | expr_value |= u16::from(EventType::COMPAT_MAP_NOTIFY); |
| 6615 | } |
| 6616 | if self.bell_notify.is_some() { |
| 6617 | expr_value |= u16::from(EventType::BELL_NOTIFY); |
| 6618 | } |
| 6619 | if self.action_message.is_some() { |
| 6620 | expr_value |= u16::from(EventType::ACTION_MESSAGE); |
| 6621 | } |
| 6622 | if self.access_x_notify.is_some() { |
| 6623 | expr_value |= u16::from(EventType::ACCESS_X_NOTIFY); |
| 6624 | } |
| 6625 | if self.extension_device_notify.is_some() { |
| 6626 | expr_value |= u16::from(EventType::EXTENSION_DEVICE_NOTIFY); |
| 6627 | } |
| 6628 | expr_value |
| 6629 | } |
| 6630 | } |
| 6631 | impl SelectEventsAux { |
| 6632 | /// Create a new instance with all fields unset / not present. |
| 6633 | pub fn new() -> Self { |
| 6634 | Default::default() |
| 6635 | } |
| 6636 | /// Set the `new_keyboard_notify` field of this structure. |
| 6637 | #[must_use ] |
| 6638 | pub fn new_keyboard_notify<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxNewKeyboardNotify>> { |
| 6639 | self.new_keyboard_notify = value.into(); |
| 6640 | self |
| 6641 | } |
| 6642 | /// Set the `state_notify` field of this structure. |
| 6643 | #[must_use ] |
| 6644 | pub fn state_notify<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxStateNotify>> { |
| 6645 | self.state_notify = value.into(); |
| 6646 | self |
| 6647 | } |
| 6648 | /// Set the `controls_notify` field of this structure. |
| 6649 | #[must_use ] |
| 6650 | pub fn controls_notify<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxControlsNotify>> { |
| 6651 | self.controls_notify = value.into(); |
| 6652 | self |
| 6653 | } |
| 6654 | /// Set the `indicator_state_notify` field of this structure. |
| 6655 | #[must_use ] |
| 6656 | pub fn indicator_state_notify<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxIndicatorStateNotify>> { |
| 6657 | self.indicator_state_notify = value.into(); |
| 6658 | self |
| 6659 | } |
| 6660 | /// Set the `indicator_map_notify` field of this structure. |
| 6661 | #[must_use ] |
| 6662 | pub fn indicator_map_notify<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxIndicatorMapNotify>> { |
| 6663 | self.indicator_map_notify = value.into(); |
| 6664 | self |
| 6665 | } |
| 6666 | /// Set the `names_notify` field of this structure. |
| 6667 | #[must_use ] |
| 6668 | pub fn names_notify<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxNamesNotify>> { |
| 6669 | self.names_notify = value.into(); |
| 6670 | self |
| 6671 | } |
| 6672 | /// Set the `compat_map_notify` field of this structure. |
| 6673 | #[must_use ] |
| 6674 | pub fn compat_map_notify<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxCompatMapNotify>> { |
| 6675 | self.compat_map_notify = value.into(); |
| 6676 | self |
| 6677 | } |
| 6678 | /// Set the `bell_notify` field of this structure. |
| 6679 | #[must_use ] |
| 6680 | pub fn bell_notify<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxBellNotify>> { |
| 6681 | self.bell_notify = value.into(); |
| 6682 | self |
| 6683 | } |
| 6684 | /// Set the `action_message` field of this structure. |
| 6685 | #[must_use ] |
| 6686 | pub fn action_message<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxActionMessage>> { |
| 6687 | self.action_message = value.into(); |
| 6688 | self |
| 6689 | } |
| 6690 | /// Set the `access_x_notify` field of this structure. |
| 6691 | #[must_use ] |
| 6692 | pub fn access_x_notify<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxAccessXNotify>> { |
| 6693 | self.access_x_notify = value.into(); |
| 6694 | self |
| 6695 | } |
| 6696 | /// Set the `extension_device_notify` field of this structure. |
| 6697 | #[must_use ] |
| 6698 | pub fn extension_device_notify<I>(mut self, value: I) -> Self where I: Into<Option<SelectEventsAuxExtensionDeviceNotify>> { |
| 6699 | self.extension_device_notify = value.into(); |
| 6700 | self |
| 6701 | } |
| 6702 | } |
| 6703 | |
| 6704 | /// Opcode for the SelectEvents request |
| 6705 | pub const SELECT_EVENTS_REQUEST: u8 = 1; |
| 6706 | #[derive (Clone, Default)] |
| 6707 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6708 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6709 | pub struct SelectEventsRequest<'input> { |
| 6710 | pub device_spec: DeviceSpec, |
| 6711 | pub clear: EventType, |
| 6712 | pub select_all: EventType, |
| 6713 | pub affect_map: MapPart, |
| 6714 | pub map: MapPart, |
| 6715 | pub details: Cow<'input, SelectEventsAux>, |
| 6716 | } |
| 6717 | impl_debug_if_no_extra_traits!(SelectEventsRequest<'_>, "SelectEventsRequest" ); |
| 6718 | impl<'input> SelectEventsRequest<'input> { |
| 6719 | /// Serialize this request into bytes for the provided connection |
| 6720 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 6721 | let length_so_far = 0; |
| 6722 | let device_spec_bytes = self.device_spec.serialize(); |
| 6723 | let affect_which: u16 = self.details.switch_expr() | (u16::from(self.clear) | u16::from(self.select_all)); |
| 6724 | let affect_which_bytes = affect_which.serialize(); |
| 6725 | let clear_bytes = u16::from(self.clear).serialize(); |
| 6726 | let select_all_bytes = u16::from(self.select_all).serialize(); |
| 6727 | let affect_map_bytes = u16::from(self.affect_map).serialize(); |
| 6728 | let map_bytes = u16::from(self.map).serialize(); |
| 6729 | let mut request0 = vec![ |
| 6730 | major_opcode, |
| 6731 | SELECT_EVENTS_REQUEST, |
| 6732 | 0, |
| 6733 | 0, |
| 6734 | device_spec_bytes[0], |
| 6735 | device_spec_bytes[1], |
| 6736 | affect_which_bytes[0], |
| 6737 | affect_which_bytes[1], |
| 6738 | clear_bytes[0], |
| 6739 | clear_bytes[1], |
| 6740 | select_all_bytes[0], |
| 6741 | select_all_bytes[1], |
| 6742 | affect_map_bytes[0], |
| 6743 | affect_map_bytes[1], |
| 6744 | map_bytes[0], |
| 6745 | map_bytes[1], |
| 6746 | ]; |
| 6747 | let length_so_far = length_so_far + request0.len(); |
| 6748 | let details_bytes = self.details.serialize(u16::from(affect_which), u16::from(self.clear), u16::from(self.select_all)); |
| 6749 | let length_so_far = length_so_far + details_bytes.len(); |
| 6750 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 6751 | let length_so_far = length_so_far + padding0.len(); |
| 6752 | assert_eq!(length_so_far % 4, 0); |
| 6753 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 6754 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 6755 | ([request0.into(), details_bytes.into(), padding0.into()], vec![]) |
| 6756 | } |
| 6757 | /// Parse this request given its header, its body, and any fds that go along with it |
| 6758 | #[cfg (feature = "request-parsing" )] |
| 6759 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 6760 | if header.minor_opcode != SELECT_EVENTS_REQUEST { |
| 6761 | return Err(ParseError::InvalidValue); |
| 6762 | } |
| 6763 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 6764 | let (affect_which, remaining) = u16::try_parse(remaining)?; |
| 6765 | let (clear, remaining) = u16::try_parse(remaining)?; |
| 6766 | let clear = clear.into(); |
| 6767 | let (select_all, remaining) = u16::try_parse(remaining)?; |
| 6768 | let select_all = select_all.into(); |
| 6769 | let (affect_map, remaining) = u16::try_parse(remaining)?; |
| 6770 | let affect_map = affect_map.into(); |
| 6771 | let (map, remaining) = u16::try_parse(remaining)?; |
| 6772 | let map = map.into(); |
| 6773 | let (details, remaining) = SelectEventsAux::try_parse(remaining, u16::from(affect_which), u16::from(clear), u16::from(select_all))?; |
| 6774 | let _ = remaining; |
| 6775 | Ok(SelectEventsRequest { |
| 6776 | device_spec, |
| 6777 | clear, |
| 6778 | select_all, |
| 6779 | affect_map, |
| 6780 | map, |
| 6781 | details: Cow::Owned(details), |
| 6782 | }) |
| 6783 | } |
| 6784 | /// Clone all borrowed data in this SelectEventsRequest. |
| 6785 | pub fn into_owned(self) -> SelectEventsRequest<'static> { |
| 6786 | SelectEventsRequest { |
| 6787 | device_spec: self.device_spec, |
| 6788 | clear: self.clear, |
| 6789 | select_all: self.select_all, |
| 6790 | affect_map: self.affect_map, |
| 6791 | map: self.map, |
| 6792 | details: Cow::Owned(self.details.into_owned()), |
| 6793 | } |
| 6794 | } |
| 6795 | } |
| 6796 | impl<'input> Request for SelectEventsRequest<'input> { |
| 6797 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 6798 | |
| 6799 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 6800 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(major_opcode); |
| 6801 | // Flatten the buffers into a single vector |
| 6802 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 6803 | (buf, fds) |
| 6804 | } |
| 6805 | } |
| 6806 | impl<'input> crate::x11_utils::VoidRequest for SelectEventsRequest<'input> { |
| 6807 | } |
| 6808 | |
| 6809 | /// Opcode for the Bell request |
| 6810 | pub const BELL_REQUEST: u8 = 3; |
| 6811 | #[derive (Clone, Copy, Default)] |
| 6812 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6813 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6814 | pub struct BellRequest { |
| 6815 | pub device_spec: DeviceSpec, |
| 6816 | pub bell_class: BellClassSpec, |
| 6817 | pub bell_id: IDSpec, |
| 6818 | pub percent: i8, |
| 6819 | pub force_sound: bool, |
| 6820 | pub event_only: bool, |
| 6821 | pub pitch: i16, |
| 6822 | pub duration: i16, |
| 6823 | pub name: xproto::Atom, |
| 6824 | pub window: xproto::Window, |
| 6825 | } |
| 6826 | impl_debug_if_no_extra_traits!(BellRequest, "BellRequest" ); |
| 6827 | impl BellRequest { |
| 6828 | /// Serialize this request into bytes for the provided connection |
| 6829 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 6830 | let length_so_far = 0; |
| 6831 | let device_spec_bytes = self.device_spec.serialize(); |
| 6832 | let bell_class_bytes = self.bell_class.serialize(); |
| 6833 | let bell_id_bytes = self.bell_id.serialize(); |
| 6834 | let percent_bytes = self.percent.serialize(); |
| 6835 | let force_sound_bytes = self.force_sound.serialize(); |
| 6836 | let event_only_bytes = self.event_only.serialize(); |
| 6837 | let pitch_bytes = self.pitch.serialize(); |
| 6838 | let duration_bytes = self.duration.serialize(); |
| 6839 | let name_bytes = self.name.serialize(); |
| 6840 | let window_bytes = self.window.serialize(); |
| 6841 | let mut request0 = vec![ |
| 6842 | major_opcode, |
| 6843 | BELL_REQUEST, |
| 6844 | 0, |
| 6845 | 0, |
| 6846 | device_spec_bytes[0], |
| 6847 | device_spec_bytes[1], |
| 6848 | bell_class_bytes[0], |
| 6849 | bell_class_bytes[1], |
| 6850 | bell_id_bytes[0], |
| 6851 | bell_id_bytes[1], |
| 6852 | percent_bytes[0], |
| 6853 | force_sound_bytes[0], |
| 6854 | event_only_bytes[0], |
| 6855 | 0, |
| 6856 | pitch_bytes[0], |
| 6857 | pitch_bytes[1], |
| 6858 | duration_bytes[0], |
| 6859 | duration_bytes[1], |
| 6860 | 0, |
| 6861 | 0, |
| 6862 | name_bytes[0], |
| 6863 | name_bytes[1], |
| 6864 | name_bytes[2], |
| 6865 | name_bytes[3], |
| 6866 | window_bytes[0], |
| 6867 | window_bytes[1], |
| 6868 | window_bytes[2], |
| 6869 | window_bytes[3], |
| 6870 | ]; |
| 6871 | let length_so_far = length_so_far + request0.len(); |
| 6872 | assert_eq!(length_so_far % 4, 0); |
| 6873 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 6874 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 6875 | ([request0.into()], vec![]) |
| 6876 | } |
| 6877 | /// Parse this request given its header, its body, and any fds that go along with it |
| 6878 | #[cfg (feature = "request-parsing" )] |
| 6879 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 6880 | if header.minor_opcode != BELL_REQUEST { |
| 6881 | return Err(ParseError::InvalidValue); |
| 6882 | } |
| 6883 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 6884 | let (bell_class, remaining) = BellClassSpec::try_parse(remaining)?; |
| 6885 | let (bell_id, remaining) = IDSpec::try_parse(remaining)?; |
| 6886 | let (percent, remaining) = i8::try_parse(remaining)?; |
| 6887 | let (force_sound, remaining) = bool::try_parse(remaining)?; |
| 6888 | let (event_only, remaining) = bool::try_parse(remaining)?; |
| 6889 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 6890 | let (pitch, remaining) = i16::try_parse(remaining)?; |
| 6891 | let (duration, remaining) = i16::try_parse(remaining)?; |
| 6892 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 6893 | let (name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 6894 | let (window, remaining) = xproto::Window::try_parse(remaining)?; |
| 6895 | let _ = remaining; |
| 6896 | Ok(BellRequest { |
| 6897 | device_spec, |
| 6898 | bell_class, |
| 6899 | bell_id, |
| 6900 | percent, |
| 6901 | force_sound, |
| 6902 | event_only, |
| 6903 | pitch, |
| 6904 | duration, |
| 6905 | name, |
| 6906 | window, |
| 6907 | }) |
| 6908 | } |
| 6909 | } |
| 6910 | impl Request for BellRequest { |
| 6911 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 6912 | |
| 6913 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 6914 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 6915 | // Flatten the buffers into a single vector |
| 6916 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 6917 | (buf, fds) |
| 6918 | } |
| 6919 | } |
| 6920 | impl crate::x11_utils::VoidRequest for BellRequest { |
| 6921 | } |
| 6922 | |
| 6923 | /// Opcode for the GetState request |
| 6924 | pub const GET_STATE_REQUEST: u8 = 4; |
| 6925 | #[derive (Clone, Copy, Default)] |
| 6926 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6927 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6928 | pub struct GetStateRequest { |
| 6929 | pub device_spec: DeviceSpec, |
| 6930 | } |
| 6931 | impl_debug_if_no_extra_traits!(GetStateRequest, "GetStateRequest" ); |
| 6932 | impl GetStateRequest { |
| 6933 | /// Serialize this request into bytes for the provided connection |
| 6934 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 6935 | let length_so_far = 0; |
| 6936 | let device_spec_bytes = self.device_spec.serialize(); |
| 6937 | let mut request0 = vec![ |
| 6938 | major_opcode, |
| 6939 | GET_STATE_REQUEST, |
| 6940 | 0, |
| 6941 | 0, |
| 6942 | device_spec_bytes[0], |
| 6943 | device_spec_bytes[1], |
| 6944 | 0, |
| 6945 | 0, |
| 6946 | ]; |
| 6947 | let length_so_far = length_so_far + request0.len(); |
| 6948 | assert_eq!(length_so_far % 4, 0); |
| 6949 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 6950 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 6951 | ([request0.into()], vec![]) |
| 6952 | } |
| 6953 | /// Parse this request given its header, its body, and any fds that go along with it |
| 6954 | #[cfg (feature = "request-parsing" )] |
| 6955 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 6956 | if header.minor_opcode != GET_STATE_REQUEST { |
| 6957 | return Err(ParseError::InvalidValue); |
| 6958 | } |
| 6959 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 6960 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 6961 | let _ = remaining; |
| 6962 | Ok(GetStateRequest { |
| 6963 | device_spec, |
| 6964 | }) |
| 6965 | } |
| 6966 | } |
| 6967 | impl Request for GetStateRequest { |
| 6968 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 6969 | |
| 6970 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 6971 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 6972 | // Flatten the buffers into a single vector |
| 6973 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 6974 | (buf, fds) |
| 6975 | } |
| 6976 | } |
| 6977 | impl crate::x11_utils::ReplyRequest for GetStateRequest { |
| 6978 | type Reply = GetStateReply; |
| 6979 | } |
| 6980 | |
| 6981 | #[derive (Clone, Copy, Default)] |
| 6982 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 6983 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 6984 | pub struct GetStateReply { |
| 6985 | pub device_id: u8, |
| 6986 | pub sequence: u16, |
| 6987 | pub length: u32, |
| 6988 | pub mods: xproto::ModMask, |
| 6989 | pub base_mods: xproto::ModMask, |
| 6990 | pub latched_mods: xproto::ModMask, |
| 6991 | pub locked_mods: xproto::ModMask, |
| 6992 | pub group: Group, |
| 6993 | pub locked_group: Group, |
| 6994 | pub base_group: i16, |
| 6995 | pub latched_group: i16, |
| 6996 | pub compat_state: xproto::ModMask, |
| 6997 | pub grab_mods: xproto::ModMask, |
| 6998 | pub compat_grab_mods: xproto::ModMask, |
| 6999 | pub lookup_mods: xproto::ModMask, |
| 7000 | pub compat_lookup_mods: xproto::ModMask, |
| 7001 | pub ptr_btn_state: xproto::KeyButMask, |
| 7002 | } |
| 7003 | impl_debug_if_no_extra_traits!(GetStateReply, "GetStateReply" ); |
| 7004 | impl TryParse for GetStateReply { |
| 7005 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 7006 | let remaining = initial_value; |
| 7007 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 7008 | let (device_id, remaining) = u8::try_parse(remaining)?; |
| 7009 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 7010 | let (length, remaining) = u32::try_parse(remaining)?; |
| 7011 | let (mods, remaining) = u8::try_parse(remaining)?; |
| 7012 | let (base_mods, remaining) = u8::try_parse(remaining)?; |
| 7013 | let (latched_mods, remaining) = u8::try_parse(remaining)?; |
| 7014 | let (locked_mods, remaining) = u8::try_parse(remaining)?; |
| 7015 | let (group, remaining) = u8::try_parse(remaining)?; |
| 7016 | let (locked_group, remaining) = u8::try_parse(remaining)?; |
| 7017 | let (base_group, remaining) = i16::try_parse(remaining)?; |
| 7018 | let (latched_group, remaining) = i16::try_parse(remaining)?; |
| 7019 | let (compat_state, remaining) = u8::try_parse(remaining)?; |
| 7020 | let (grab_mods, remaining) = u8::try_parse(remaining)?; |
| 7021 | let (compat_grab_mods, remaining) = u8::try_parse(remaining)?; |
| 7022 | let (lookup_mods, remaining) = u8::try_parse(remaining)?; |
| 7023 | let (compat_lookup_mods, remaining) = u8::try_parse(remaining)?; |
| 7024 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 7025 | let (ptr_btn_state, remaining) = u16::try_parse(remaining)?; |
| 7026 | let remaining = remaining.get(6..).ok_or(ParseError::InsufficientData)?; |
| 7027 | if response_type != 1 { |
| 7028 | return Err(ParseError::InvalidValue); |
| 7029 | } |
| 7030 | let mods = mods.into(); |
| 7031 | let base_mods = base_mods.into(); |
| 7032 | let latched_mods = latched_mods.into(); |
| 7033 | let locked_mods = locked_mods.into(); |
| 7034 | let group = group.into(); |
| 7035 | let locked_group = locked_group.into(); |
| 7036 | let compat_state = compat_state.into(); |
| 7037 | let grab_mods = grab_mods.into(); |
| 7038 | let compat_grab_mods = compat_grab_mods.into(); |
| 7039 | let lookup_mods = lookup_mods.into(); |
| 7040 | let compat_lookup_mods = compat_lookup_mods.into(); |
| 7041 | let ptr_btn_state = ptr_btn_state.into(); |
| 7042 | 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 }; |
| 7043 | let _ = remaining; |
| 7044 | let remaining = initial_value.get(32 + length as usize * 4..) |
| 7045 | .ok_or(ParseError::InsufficientData)?; |
| 7046 | Ok((result, remaining)) |
| 7047 | } |
| 7048 | } |
| 7049 | impl Serialize for GetStateReply { |
| 7050 | type Bytes = [u8; 32]; |
| 7051 | fn serialize(&self) -> [u8; 32] { |
| 7052 | let response_type_bytes = &[1]; |
| 7053 | let device_id_bytes = self.device_id.serialize(); |
| 7054 | let sequence_bytes = self.sequence.serialize(); |
| 7055 | let length_bytes = self.length.serialize(); |
| 7056 | let mods_bytes = (u16::from(self.mods) as u8).serialize(); |
| 7057 | let base_mods_bytes = (u16::from(self.base_mods) as u8).serialize(); |
| 7058 | let latched_mods_bytes = (u16::from(self.latched_mods) as u8).serialize(); |
| 7059 | let locked_mods_bytes = (u16::from(self.locked_mods) as u8).serialize(); |
| 7060 | let group_bytes = u8::from(self.group).serialize(); |
| 7061 | let locked_group_bytes = u8::from(self.locked_group).serialize(); |
| 7062 | let base_group_bytes = self.base_group.serialize(); |
| 7063 | let latched_group_bytes = self.latched_group.serialize(); |
| 7064 | let compat_state_bytes = (u16::from(self.compat_state) as u8).serialize(); |
| 7065 | let grab_mods_bytes = (u16::from(self.grab_mods) as u8).serialize(); |
| 7066 | let compat_grab_mods_bytes = (u16::from(self.compat_grab_mods) as u8).serialize(); |
| 7067 | let lookup_mods_bytes = (u16::from(self.lookup_mods) as u8).serialize(); |
| 7068 | let compat_lookup_mods_bytes = (u16::from(self.compat_lookup_mods) as u8).serialize(); |
| 7069 | let ptr_btn_state_bytes = u16::from(self.ptr_btn_state).serialize(); |
| 7070 | [ |
| 7071 | response_type_bytes[0], |
| 7072 | device_id_bytes[0], |
| 7073 | sequence_bytes[0], |
| 7074 | sequence_bytes[1], |
| 7075 | length_bytes[0], |
| 7076 | length_bytes[1], |
| 7077 | length_bytes[2], |
| 7078 | length_bytes[3], |
| 7079 | mods_bytes[0], |
| 7080 | base_mods_bytes[0], |
| 7081 | latched_mods_bytes[0], |
| 7082 | locked_mods_bytes[0], |
| 7083 | group_bytes[0], |
| 7084 | locked_group_bytes[0], |
| 7085 | base_group_bytes[0], |
| 7086 | base_group_bytes[1], |
| 7087 | latched_group_bytes[0], |
| 7088 | latched_group_bytes[1], |
| 7089 | compat_state_bytes[0], |
| 7090 | grab_mods_bytes[0], |
| 7091 | compat_grab_mods_bytes[0], |
| 7092 | lookup_mods_bytes[0], |
| 7093 | compat_lookup_mods_bytes[0], |
| 7094 | 0, |
| 7095 | ptr_btn_state_bytes[0], |
| 7096 | ptr_btn_state_bytes[1], |
| 7097 | 0, |
| 7098 | 0, |
| 7099 | 0, |
| 7100 | 0, |
| 7101 | 0, |
| 7102 | 0, |
| 7103 | ] |
| 7104 | } |
| 7105 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 7106 | bytes.reserve(32); |
| 7107 | let response_type_bytes = &[1]; |
| 7108 | bytes.push(response_type_bytes[0]); |
| 7109 | self.device_id.serialize_into(bytes); |
| 7110 | self.sequence.serialize_into(bytes); |
| 7111 | self.length.serialize_into(bytes); |
| 7112 | (u16::from(self.mods) as u8).serialize_into(bytes); |
| 7113 | (u16::from(self.base_mods) as u8).serialize_into(bytes); |
| 7114 | (u16::from(self.latched_mods) as u8).serialize_into(bytes); |
| 7115 | (u16::from(self.locked_mods) as u8).serialize_into(bytes); |
| 7116 | u8::from(self.group).serialize_into(bytes); |
| 7117 | u8::from(self.locked_group).serialize_into(bytes); |
| 7118 | self.base_group.serialize_into(bytes); |
| 7119 | self.latched_group.serialize_into(bytes); |
| 7120 | (u16::from(self.compat_state) as u8).serialize_into(bytes); |
| 7121 | (u16::from(self.grab_mods) as u8).serialize_into(bytes); |
| 7122 | (u16::from(self.compat_grab_mods) as u8).serialize_into(bytes); |
| 7123 | (u16::from(self.lookup_mods) as u8).serialize_into(bytes); |
| 7124 | (u16::from(self.compat_lookup_mods) as u8).serialize_into(bytes); |
| 7125 | bytes.extend_from_slice(&[0; 1]); |
| 7126 | u16::from(self.ptr_btn_state).serialize_into(bytes); |
| 7127 | bytes.extend_from_slice(&[0; 6]); |
| 7128 | } |
| 7129 | } |
| 7130 | |
| 7131 | /// Opcode for the LatchLockState request |
| 7132 | pub const LATCH_LOCK_STATE_REQUEST: u8 = 5; |
| 7133 | #[derive (Clone, Copy, Default)] |
| 7134 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 7135 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 7136 | pub struct LatchLockStateRequest { |
| 7137 | pub device_spec: DeviceSpec, |
| 7138 | pub affect_mod_locks: xproto::ModMask, |
| 7139 | pub mod_locks: xproto::ModMask, |
| 7140 | pub lock_group: bool, |
| 7141 | pub group_lock: Group, |
| 7142 | pub affect_mod_latches: xproto::ModMask, |
| 7143 | pub latch_group: bool, |
| 7144 | pub group_latch: u16, |
| 7145 | } |
| 7146 | impl_debug_if_no_extra_traits!(LatchLockStateRequest, "LatchLockStateRequest" ); |
| 7147 | impl LatchLockStateRequest { |
| 7148 | /// Serialize this request into bytes for the provided connection |
| 7149 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 7150 | let length_so_far = 0; |
| 7151 | let device_spec_bytes = self.device_spec.serialize(); |
| 7152 | let affect_mod_locks_bytes = (u16::from(self.affect_mod_locks) as u8).serialize(); |
| 7153 | let mod_locks_bytes = (u16::from(self.mod_locks) as u8).serialize(); |
| 7154 | let lock_group_bytes = self.lock_group.serialize(); |
| 7155 | let group_lock_bytes = u8::from(self.group_lock).serialize(); |
| 7156 | let affect_mod_latches_bytes = (u16::from(self.affect_mod_latches) as u8).serialize(); |
| 7157 | let latch_group_bytes = self.latch_group.serialize(); |
| 7158 | let group_latch_bytes = self.group_latch.serialize(); |
| 7159 | let mut request0 = vec![ |
| 7160 | major_opcode, |
| 7161 | LATCH_LOCK_STATE_REQUEST, |
| 7162 | 0, |
| 7163 | 0, |
| 7164 | device_spec_bytes[0], |
| 7165 | device_spec_bytes[1], |
| 7166 | affect_mod_locks_bytes[0], |
| 7167 | mod_locks_bytes[0], |
| 7168 | lock_group_bytes[0], |
| 7169 | group_lock_bytes[0], |
| 7170 | affect_mod_latches_bytes[0], |
| 7171 | 0, |
| 7172 | 0, |
| 7173 | latch_group_bytes[0], |
| 7174 | group_latch_bytes[0], |
| 7175 | group_latch_bytes[1], |
| 7176 | ]; |
| 7177 | let length_so_far = length_so_far + request0.len(); |
| 7178 | assert_eq!(length_so_far % 4, 0); |
| 7179 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 7180 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 7181 | ([request0.into()], vec![]) |
| 7182 | } |
| 7183 | /// Parse this request given its header, its body, and any fds that go along with it |
| 7184 | #[cfg (feature = "request-parsing" )] |
| 7185 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 7186 | if header.minor_opcode != LATCH_LOCK_STATE_REQUEST { |
| 7187 | return Err(ParseError::InvalidValue); |
| 7188 | } |
| 7189 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 7190 | let (affect_mod_locks, remaining) = u8::try_parse(remaining)?; |
| 7191 | let affect_mod_locks = affect_mod_locks.into(); |
| 7192 | let (mod_locks, remaining) = u8::try_parse(remaining)?; |
| 7193 | let mod_locks = mod_locks.into(); |
| 7194 | let (lock_group, remaining) = bool::try_parse(remaining)?; |
| 7195 | let (group_lock, remaining) = u8::try_parse(remaining)?; |
| 7196 | let group_lock = group_lock.into(); |
| 7197 | let (affect_mod_latches, remaining) = u8::try_parse(remaining)?; |
| 7198 | let affect_mod_latches = affect_mod_latches.into(); |
| 7199 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 7200 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 7201 | let (latch_group, remaining) = bool::try_parse(remaining)?; |
| 7202 | let (group_latch, remaining) = u16::try_parse(remaining)?; |
| 7203 | let _ = remaining; |
| 7204 | Ok(LatchLockStateRequest { |
| 7205 | device_spec, |
| 7206 | affect_mod_locks, |
| 7207 | mod_locks, |
| 7208 | lock_group, |
| 7209 | group_lock, |
| 7210 | affect_mod_latches, |
| 7211 | latch_group, |
| 7212 | group_latch, |
| 7213 | }) |
| 7214 | } |
| 7215 | } |
| 7216 | impl Request for LatchLockStateRequest { |
| 7217 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 7218 | |
| 7219 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 7220 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 7221 | // Flatten the buffers into a single vector |
| 7222 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 7223 | (buf, fds) |
| 7224 | } |
| 7225 | } |
| 7226 | impl crate::x11_utils::VoidRequest for LatchLockStateRequest { |
| 7227 | } |
| 7228 | |
| 7229 | /// Opcode for the GetControls request |
| 7230 | pub const GET_CONTROLS_REQUEST: u8 = 6; |
| 7231 | #[derive (Clone, Copy, Default)] |
| 7232 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 7233 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 7234 | pub struct GetControlsRequest { |
| 7235 | pub device_spec: DeviceSpec, |
| 7236 | } |
| 7237 | impl_debug_if_no_extra_traits!(GetControlsRequest, "GetControlsRequest" ); |
| 7238 | impl GetControlsRequest { |
| 7239 | /// Serialize this request into bytes for the provided connection |
| 7240 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 7241 | let length_so_far = 0; |
| 7242 | let device_spec_bytes = self.device_spec.serialize(); |
| 7243 | let mut request0 = vec![ |
| 7244 | major_opcode, |
| 7245 | GET_CONTROLS_REQUEST, |
| 7246 | 0, |
| 7247 | 0, |
| 7248 | device_spec_bytes[0], |
| 7249 | device_spec_bytes[1], |
| 7250 | 0, |
| 7251 | 0, |
| 7252 | ]; |
| 7253 | let length_so_far = length_so_far + request0.len(); |
| 7254 | assert_eq!(length_so_far % 4, 0); |
| 7255 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 7256 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 7257 | ([request0.into()], vec![]) |
| 7258 | } |
| 7259 | /// Parse this request given its header, its body, and any fds that go along with it |
| 7260 | #[cfg (feature = "request-parsing" )] |
| 7261 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 7262 | if header.minor_opcode != GET_CONTROLS_REQUEST { |
| 7263 | return Err(ParseError::InvalidValue); |
| 7264 | } |
| 7265 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 7266 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 7267 | let _ = remaining; |
| 7268 | Ok(GetControlsRequest { |
| 7269 | device_spec, |
| 7270 | }) |
| 7271 | } |
| 7272 | } |
| 7273 | impl Request for GetControlsRequest { |
| 7274 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 7275 | |
| 7276 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 7277 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 7278 | // Flatten the buffers into a single vector |
| 7279 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 7280 | (buf, fds) |
| 7281 | } |
| 7282 | } |
| 7283 | impl crate::x11_utils::ReplyRequest for GetControlsRequest { |
| 7284 | type Reply = GetControlsReply; |
| 7285 | } |
| 7286 | |
| 7287 | #[derive (Clone, Copy, Default)] |
| 7288 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 7289 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 7290 | pub struct GetControlsReply { |
| 7291 | pub device_id: u8, |
| 7292 | pub sequence: u16, |
| 7293 | pub length: u32, |
| 7294 | pub mouse_keys_dflt_btn: u8, |
| 7295 | pub num_groups: u8, |
| 7296 | pub groups_wrap: u8, |
| 7297 | pub internal_mods_mask: xproto::ModMask, |
| 7298 | pub ignore_lock_mods_mask: xproto::ModMask, |
| 7299 | pub internal_mods_real_mods: xproto::ModMask, |
| 7300 | pub ignore_lock_mods_real_mods: xproto::ModMask, |
| 7301 | pub internal_mods_vmods: VMod, |
| 7302 | pub ignore_lock_mods_vmods: VMod, |
| 7303 | pub repeat_delay: u16, |
| 7304 | pub repeat_interval: u16, |
| 7305 | pub slow_keys_delay: u16, |
| 7306 | pub debounce_delay: u16, |
| 7307 | pub mouse_keys_delay: u16, |
| 7308 | pub mouse_keys_interval: u16, |
| 7309 | pub mouse_keys_time_to_max: u16, |
| 7310 | pub mouse_keys_max_speed: u16, |
| 7311 | pub mouse_keys_curve: i16, |
| 7312 | pub access_x_option: AXOption, |
| 7313 | pub access_x_timeout: u16, |
| 7314 | pub access_x_timeout_options_mask: AXOption, |
| 7315 | pub access_x_timeout_options_values: AXOption, |
| 7316 | pub access_x_timeout_mask: BoolCtrl, |
| 7317 | pub access_x_timeout_values: BoolCtrl, |
| 7318 | pub enabled_controls: BoolCtrl, |
| 7319 | pub per_key_repeat: [u8; 32], |
| 7320 | } |
| 7321 | impl_debug_if_no_extra_traits!(GetControlsReply, "GetControlsReply" ); |
| 7322 | impl TryParse for GetControlsReply { |
| 7323 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 7324 | let remaining = initial_value; |
| 7325 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 7326 | let (device_id, remaining) = u8::try_parse(remaining)?; |
| 7327 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 7328 | let (length, remaining) = u32::try_parse(remaining)?; |
| 7329 | let (mouse_keys_dflt_btn, remaining) = u8::try_parse(remaining)?; |
| 7330 | let (num_groups, remaining) = u8::try_parse(remaining)?; |
| 7331 | let (groups_wrap, remaining) = u8::try_parse(remaining)?; |
| 7332 | let (internal_mods_mask, remaining) = u8::try_parse(remaining)?; |
| 7333 | let (ignore_lock_mods_mask, remaining) = u8::try_parse(remaining)?; |
| 7334 | let (internal_mods_real_mods, remaining) = u8::try_parse(remaining)?; |
| 7335 | let (ignore_lock_mods_real_mods, remaining) = u8::try_parse(remaining)?; |
| 7336 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 7337 | let (internal_mods_vmods, remaining) = u16::try_parse(remaining)?; |
| 7338 | let (ignore_lock_mods_vmods, remaining) = u16::try_parse(remaining)?; |
| 7339 | let (repeat_delay, remaining) = u16::try_parse(remaining)?; |
| 7340 | let (repeat_interval, remaining) = u16::try_parse(remaining)?; |
| 7341 | let (slow_keys_delay, remaining) = u16::try_parse(remaining)?; |
| 7342 | let (debounce_delay, remaining) = u16::try_parse(remaining)?; |
| 7343 | let (mouse_keys_delay, remaining) = u16::try_parse(remaining)?; |
| 7344 | let (mouse_keys_interval, remaining) = u16::try_parse(remaining)?; |
| 7345 | let (mouse_keys_time_to_max, remaining) = u16::try_parse(remaining)?; |
| 7346 | let (mouse_keys_max_speed, remaining) = u16::try_parse(remaining)?; |
| 7347 | let (mouse_keys_curve, remaining) = i16::try_parse(remaining)?; |
| 7348 | let (access_x_option, remaining) = u16::try_parse(remaining)?; |
| 7349 | let (access_x_timeout, remaining) = u16::try_parse(remaining)?; |
| 7350 | let (access_x_timeout_options_mask, remaining) = u16::try_parse(remaining)?; |
| 7351 | let (access_x_timeout_options_values, remaining) = u16::try_parse(remaining)?; |
| 7352 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 7353 | let (access_x_timeout_mask, remaining) = u32::try_parse(remaining)?; |
| 7354 | let (access_x_timeout_values, remaining) = u32::try_parse(remaining)?; |
| 7355 | let (enabled_controls, remaining) = u32::try_parse(remaining)?; |
| 7356 | let (per_key_repeat, remaining) = crate::x11_utils::parse_u8_array::<32>(remaining)?; |
| 7357 | if response_type != 1 { |
| 7358 | return Err(ParseError::InvalidValue); |
| 7359 | } |
| 7360 | let internal_mods_mask = internal_mods_mask.into(); |
| 7361 | let ignore_lock_mods_mask = ignore_lock_mods_mask.into(); |
| 7362 | let internal_mods_real_mods = internal_mods_real_mods.into(); |
| 7363 | let ignore_lock_mods_real_mods = ignore_lock_mods_real_mods.into(); |
| 7364 | let internal_mods_vmods = internal_mods_vmods.into(); |
| 7365 | let ignore_lock_mods_vmods = ignore_lock_mods_vmods.into(); |
| 7366 | let access_x_option = access_x_option.into(); |
| 7367 | let access_x_timeout_options_mask = access_x_timeout_options_mask.into(); |
| 7368 | let access_x_timeout_options_values = access_x_timeout_options_values.into(); |
| 7369 | let access_x_timeout_mask = access_x_timeout_mask.into(); |
| 7370 | let access_x_timeout_values = access_x_timeout_values.into(); |
| 7371 | let enabled_controls = enabled_controls.into(); |
| 7372 | 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 }; |
| 7373 | let _ = remaining; |
| 7374 | let remaining = initial_value.get(32 + length as usize * 4..) |
| 7375 | .ok_or(ParseError::InsufficientData)?; |
| 7376 | Ok((result, remaining)) |
| 7377 | } |
| 7378 | } |
| 7379 | impl Serialize for GetControlsReply { |
| 7380 | type Bytes = [u8; 92]; |
| 7381 | fn serialize(&self) -> [u8; 92] { |
| 7382 | let response_type_bytes = &[1]; |
| 7383 | let device_id_bytes = self.device_id.serialize(); |
| 7384 | let sequence_bytes = self.sequence.serialize(); |
| 7385 | let length_bytes = self.length.serialize(); |
| 7386 | let mouse_keys_dflt_btn_bytes = self.mouse_keys_dflt_btn.serialize(); |
| 7387 | let num_groups_bytes = self.num_groups.serialize(); |
| 7388 | let groups_wrap_bytes = self.groups_wrap.serialize(); |
| 7389 | let internal_mods_mask_bytes = (u16::from(self.internal_mods_mask) as u8).serialize(); |
| 7390 | let ignore_lock_mods_mask_bytes = (u16::from(self.ignore_lock_mods_mask) as u8).serialize(); |
| 7391 | let internal_mods_real_mods_bytes = (u16::from(self.internal_mods_real_mods) as u8).serialize(); |
| 7392 | let ignore_lock_mods_real_mods_bytes = (u16::from(self.ignore_lock_mods_real_mods) as u8).serialize(); |
| 7393 | let internal_mods_vmods_bytes = u16::from(self.internal_mods_vmods).serialize(); |
| 7394 | let ignore_lock_mods_vmods_bytes = u16::from(self.ignore_lock_mods_vmods).serialize(); |
| 7395 | let repeat_delay_bytes = self.repeat_delay.serialize(); |
| 7396 | let repeat_interval_bytes = self.repeat_interval.serialize(); |
| 7397 | let slow_keys_delay_bytes = self.slow_keys_delay.serialize(); |
| 7398 | let debounce_delay_bytes = self.debounce_delay.serialize(); |
| 7399 | let mouse_keys_delay_bytes = self.mouse_keys_delay.serialize(); |
| 7400 | let mouse_keys_interval_bytes = self.mouse_keys_interval.serialize(); |
| 7401 | let mouse_keys_time_to_max_bytes = self.mouse_keys_time_to_max.serialize(); |
| 7402 | let mouse_keys_max_speed_bytes = self.mouse_keys_max_speed.serialize(); |
| 7403 | let mouse_keys_curve_bytes = self.mouse_keys_curve.serialize(); |
| 7404 | let access_x_option_bytes = u16::from(self.access_x_option).serialize(); |
| 7405 | let access_x_timeout_bytes = self.access_x_timeout.serialize(); |
| 7406 | let access_x_timeout_options_mask_bytes = u16::from(self.access_x_timeout_options_mask).serialize(); |
| 7407 | let access_x_timeout_options_values_bytes = u16::from(self.access_x_timeout_options_values).serialize(); |
| 7408 | let access_x_timeout_mask_bytes = u32::from(self.access_x_timeout_mask).serialize(); |
| 7409 | let access_x_timeout_values_bytes = u32::from(self.access_x_timeout_values).serialize(); |
| 7410 | let enabled_controls_bytes = u32::from(self.enabled_controls).serialize(); |
| 7411 | [ |
| 7412 | response_type_bytes[0], |
| 7413 | device_id_bytes[0], |
| 7414 | sequence_bytes[0], |
| 7415 | sequence_bytes[1], |
| 7416 | length_bytes[0], |
| 7417 | length_bytes[1], |
| 7418 | length_bytes[2], |
| 7419 | length_bytes[3], |
| 7420 | mouse_keys_dflt_btn_bytes[0], |
| 7421 | num_groups_bytes[0], |
| 7422 | groups_wrap_bytes[0], |
| 7423 | internal_mods_mask_bytes[0], |
| 7424 | ignore_lock_mods_mask_bytes[0], |
| 7425 | internal_mods_real_mods_bytes[0], |
| 7426 | ignore_lock_mods_real_mods_bytes[0], |
| 7427 | 0, |
| 7428 | internal_mods_vmods_bytes[0], |
| 7429 | internal_mods_vmods_bytes[1], |
| 7430 | ignore_lock_mods_vmods_bytes[0], |
| 7431 | ignore_lock_mods_vmods_bytes[1], |
| 7432 | repeat_delay_bytes[0], |
| 7433 | repeat_delay_bytes[1], |
| 7434 | repeat_interval_bytes[0], |
| 7435 | repeat_interval_bytes[1], |
| 7436 | slow_keys_delay_bytes[0], |
| 7437 | slow_keys_delay_bytes[1], |
| 7438 | debounce_delay_bytes[0], |
| 7439 | debounce_delay_bytes[1], |
| 7440 | mouse_keys_delay_bytes[0], |
| 7441 | mouse_keys_delay_bytes[1], |
| 7442 | mouse_keys_interval_bytes[0], |
| 7443 | mouse_keys_interval_bytes[1], |
| 7444 | mouse_keys_time_to_max_bytes[0], |
| 7445 | mouse_keys_time_to_max_bytes[1], |
| 7446 | mouse_keys_max_speed_bytes[0], |
| 7447 | mouse_keys_max_speed_bytes[1], |
| 7448 | mouse_keys_curve_bytes[0], |
| 7449 | mouse_keys_curve_bytes[1], |
| 7450 | access_x_option_bytes[0], |
| 7451 | access_x_option_bytes[1], |
| 7452 | access_x_timeout_bytes[0], |
| 7453 | access_x_timeout_bytes[1], |
| 7454 | access_x_timeout_options_mask_bytes[0], |
| 7455 | access_x_timeout_options_mask_bytes[1], |
| 7456 | access_x_timeout_options_values_bytes[0], |
| 7457 | access_x_timeout_options_values_bytes[1], |
| 7458 | 0, |
| 7459 | 0, |
| 7460 | access_x_timeout_mask_bytes[0], |
| 7461 | access_x_timeout_mask_bytes[1], |
| 7462 | access_x_timeout_mask_bytes[2], |
| 7463 | access_x_timeout_mask_bytes[3], |
| 7464 | access_x_timeout_values_bytes[0], |
| 7465 | access_x_timeout_values_bytes[1], |
| 7466 | access_x_timeout_values_bytes[2], |
| 7467 | access_x_timeout_values_bytes[3], |
| 7468 | enabled_controls_bytes[0], |
| 7469 | enabled_controls_bytes[1], |
| 7470 | enabled_controls_bytes[2], |
| 7471 | enabled_controls_bytes[3], |
| 7472 | self.per_key_repeat[0], |
| 7473 | self.per_key_repeat[1], |
| 7474 | self.per_key_repeat[2], |
| 7475 | self.per_key_repeat[3], |
| 7476 | self.per_key_repeat[4], |
| 7477 | self.per_key_repeat[5], |
| 7478 | self.per_key_repeat[6], |
| 7479 | self.per_key_repeat[7], |
| 7480 | self.per_key_repeat[8], |
| 7481 | self.per_key_repeat[9], |
| 7482 | self.per_key_repeat[10], |
| 7483 | self.per_key_repeat[11], |
| 7484 | self.per_key_repeat[12], |
| 7485 | self.per_key_repeat[13], |
| 7486 | self.per_key_repeat[14], |
| 7487 | self.per_key_repeat[15], |
| 7488 | self.per_key_repeat[16], |
| 7489 | self.per_key_repeat[17], |
| 7490 | self.per_key_repeat[18], |
| 7491 | self.per_key_repeat[19], |
| 7492 | self.per_key_repeat[20], |
| 7493 | self.per_key_repeat[21], |
| 7494 | self.per_key_repeat[22], |
| 7495 | self.per_key_repeat[23], |
| 7496 | self.per_key_repeat[24], |
| 7497 | self.per_key_repeat[25], |
| 7498 | self.per_key_repeat[26], |
| 7499 | self.per_key_repeat[27], |
| 7500 | self.per_key_repeat[28], |
| 7501 | self.per_key_repeat[29], |
| 7502 | self.per_key_repeat[30], |
| 7503 | self.per_key_repeat[31], |
| 7504 | ] |
| 7505 | } |
| 7506 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 7507 | bytes.reserve(92); |
| 7508 | let response_type_bytes = &[1]; |
| 7509 | bytes.push(response_type_bytes[0]); |
| 7510 | self.device_id.serialize_into(bytes); |
| 7511 | self.sequence.serialize_into(bytes); |
| 7512 | self.length.serialize_into(bytes); |
| 7513 | self.mouse_keys_dflt_btn.serialize_into(bytes); |
| 7514 | self.num_groups.serialize_into(bytes); |
| 7515 | self.groups_wrap.serialize_into(bytes); |
| 7516 | (u16::from(self.internal_mods_mask) as u8).serialize_into(bytes); |
| 7517 | (u16::from(self.ignore_lock_mods_mask) as u8).serialize_into(bytes); |
| 7518 | (u16::from(self.internal_mods_real_mods) as u8).serialize_into(bytes); |
| 7519 | (u16::from(self.ignore_lock_mods_real_mods) as u8).serialize_into(bytes); |
| 7520 | bytes.extend_from_slice(&[0; 1]); |
| 7521 | u16::from(self.internal_mods_vmods).serialize_into(bytes); |
| 7522 | u16::from(self.ignore_lock_mods_vmods).serialize_into(bytes); |
| 7523 | self.repeat_delay.serialize_into(bytes); |
| 7524 | self.repeat_interval.serialize_into(bytes); |
| 7525 | self.slow_keys_delay.serialize_into(bytes); |
| 7526 | self.debounce_delay.serialize_into(bytes); |
| 7527 | self.mouse_keys_delay.serialize_into(bytes); |
| 7528 | self.mouse_keys_interval.serialize_into(bytes); |
| 7529 | self.mouse_keys_time_to_max.serialize_into(bytes); |
| 7530 | self.mouse_keys_max_speed.serialize_into(bytes); |
| 7531 | self.mouse_keys_curve.serialize_into(bytes); |
| 7532 | u16::from(self.access_x_option).serialize_into(bytes); |
| 7533 | self.access_x_timeout.serialize_into(bytes); |
| 7534 | u16::from(self.access_x_timeout_options_mask).serialize_into(bytes); |
| 7535 | u16::from(self.access_x_timeout_options_values).serialize_into(bytes); |
| 7536 | bytes.extend_from_slice(&[0; 2]); |
| 7537 | u32::from(self.access_x_timeout_mask).serialize_into(bytes); |
| 7538 | u32::from(self.access_x_timeout_values).serialize_into(bytes); |
| 7539 | u32::from(self.enabled_controls).serialize_into(bytes); |
| 7540 | bytes.extend_from_slice(&self.per_key_repeat); |
| 7541 | } |
| 7542 | } |
| 7543 | |
| 7544 | /// Opcode for the SetControls request |
| 7545 | pub const SET_CONTROLS_REQUEST: u8 = 7; |
| 7546 | #[derive (Clone, Default)] |
| 7547 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 7548 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 7549 | pub struct SetControlsRequest<'input> { |
| 7550 | pub device_spec: DeviceSpec, |
| 7551 | pub affect_internal_real_mods: xproto::ModMask, |
| 7552 | pub internal_real_mods: xproto::ModMask, |
| 7553 | pub affect_ignore_lock_real_mods: xproto::ModMask, |
| 7554 | pub ignore_lock_real_mods: xproto::ModMask, |
| 7555 | pub affect_internal_virtual_mods: VMod, |
| 7556 | pub internal_virtual_mods: VMod, |
| 7557 | pub affect_ignore_lock_virtual_mods: VMod, |
| 7558 | pub ignore_lock_virtual_mods: VMod, |
| 7559 | pub mouse_keys_dflt_btn: u8, |
| 7560 | pub groups_wrap: u8, |
| 7561 | pub access_x_options: AXOption, |
| 7562 | pub affect_enabled_controls: BoolCtrl, |
| 7563 | pub enabled_controls: BoolCtrl, |
| 7564 | pub change_controls: Control, |
| 7565 | pub repeat_delay: u16, |
| 7566 | pub repeat_interval: u16, |
| 7567 | pub slow_keys_delay: u16, |
| 7568 | pub debounce_delay: u16, |
| 7569 | pub mouse_keys_delay: u16, |
| 7570 | pub mouse_keys_interval: u16, |
| 7571 | pub mouse_keys_time_to_max: u16, |
| 7572 | pub mouse_keys_max_speed: u16, |
| 7573 | pub mouse_keys_curve: i16, |
| 7574 | pub access_x_timeout: u16, |
| 7575 | pub access_x_timeout_mask: BoolCtrl, |
| 7576 | pub access_x_timeout_values: BoolCtrl, |
| 7577 | pub access_x_timeout_options_mask: AXOption, |
| 7578 | pub access_x_timeout_options_values: AXOption, |
| 7579 | pub per_key_repeat: Cow<'input, [u8; 32]>, |
| 7580 | } |
| 7581 | impl_debug_if_no_extra_traits!(SetControlsRequest<'_>, "SetControlsRequest" ); |
| 7582 | impl<'input> SetControlsRequest<'input> { |
| 7583 | /// Serialize this request into bytes for the provided connection |
| 7584 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 2]> { |
| 7585 | let length_so_far = 0; |
| 7586 | let device_spec_bytes = self.device_spec.serialize(); |
| 7587 | let affect_internal_real_mods_bytes = (u16::from(self.affect_internal_real_mods) as u8).serialize(); |
| 7588 | let internal_real_mods_bytes = (u16::from(self.internal_real_mods) as u8).serialize(); |
| 7589 | let affect_ignore_lock_real_mods_bytes = (u16::from(self.affect_ignore_lock_real_mods) as u8).serialize(); |
| 7590 | let ignore_lock_real_mods_bytes = (u16::from(self.ignore_lock_real_mods) as u8).serialize(); |
| 7591 | let affect_internal_virtual_mods_bytes = u16::from(self.affect_internal_virtual_mods).serialize(); |
| 7592 | let internal_virtual_mods_bytes = u16::from(self.internal_virtual_mods).serialize(); |
| 7593 | let affect_ignore_lock_virtual_mods_bytes = u16::from(self.affect_ignore_lock_virtual_mods).serialize(); |
| 7594 | let ignore_lock_virtual_mods_bytes = u16::from(self.ignore_lock_virtual_mods).serialize(); |
| 7595 | let mouse_keys_dflt_btn_bytes = self.mouse_keys_dflt_btn.serialize(); |
| 7596 | let groups_wrap_bytes = self.groups_wrap.serialize(); |
| 7597 | let access_x_options_bytes = u16::from(self.access_x_options).serialize(); |
| 7598 | let affect_enabled_controls_bytes = u32::from(self.affect_enabled_controls).serialize(); |
| 7599 | let enabled_controls_bytes = u32::from(self.enabled_controls).serialize(); |
| 7600 | let change_controls_bytes = u32::from(self.change_controls).serialize(); |
| 7601 | let repeat_delay_bytes = self.repeat_delay.serialize(); |
| 7602 | let repeat_interval_bytes = self.repeat_interval.serialize(); |
| 7603 | let slow_keys_delay_bytes = self.slow_keys_delay.serialize(); |
| 7604 | let debounce_delay_bytes = self.debounce_delay.serialize(); |
| 7605 | let mouse_keys_delay_bytes = self.mouse_keys_delay.serialize(); |
| 7606 | let mouse_keys_interval_bytes = self.mouse_keys_interval.serialize(); |
| 7607 | let mouse_keys_time_to_max_bytes = self.mouse_keys_time_to_max.serialize(); |
| 7608 | let mouse_keys_max_speed_bytes = self.mouse_keys_max_speed.serialize(); |
| 7609 | let mouse_keys_curve_bytes = self.mouse_keys_curve.serialize(); |
| 7610 | let access_x_timeout_bytes = self.access_x_timeout.serialize(); |
| 7611 | let access_x_timeout_mask_bytes = u32::from(self.access_x_timeout_mask).serialize(); |
| 7612 | let access_x_timeout_values_bytes = u32::from(self.access_x_timeout_values).serialize(); |
| 7613 | let access_x_timeout_options_mask_bytes = u16::from(self.access_x_timeout_options_mask).serialize(); |
| 7614 | let access_x_timeout_options_values_bytes = u16::from(self.access_x_timeout_options_values).serialize(); |
| 7615 | let mut request0 = vec![ |
| 7616 | major_opcode, |
| 7617 | SET_CONTROLS_REQUEST, |
| 7618 | 0, |
| 7619 | 0, |
| 7620 | device_spec_bytes[0], |
| 7621 | device_spec_bytes[1], |
| 7622 | affect_internal_real_mods_bytes[0], |
| 7623 | internal_real_mods_bytes[0], |
| 7624 | affect_ignore_lock_real_mods_bytes[0], |
| 7625 | ignore_lock_real_mods_bytes[0], |
| 7626 | affect_internal_virtual_mods_bytes[0], |
| 7627 | affect_internal_virtual_mods_bytes[1], |
| 7628 | internal_virtual_mods_bytes[0], |
| 7629 | internal_virtual_mods_bytes[1], |
| 7630 | affect_ignore_lock_virtual_mods_bytes[0], |
| 7631 | affect_ignore_lock_virtual_mods_bytes[1], |
| 7632 | ignore_lock_virtual_mods_bytes[0], |
| 7633 | ignore_lock_virtual_mods_bytes[1], |
| 7634 | mouse_keys_dflt_btn_bytes[0], |
| 7635 | groups_wrap_bytes[0], |
| 7636 | access_x_options_bytes[0], |
| 7637 | access_x_options_bytes[1], |
| 7638 | 0, |
| 7639 | 0, |
| 7640 | affect_enabled_controls_bytes[0], |
| 7641 | affect_enabled_controls_bytes[1], |
| 7642 | affect_enabled_controls_bytes[2], |
| 7643 | affect_enabled_controls_bytes[3], |
| 7644 | enabled_controls_bytes[0], |
| 7645 | enabled_controls_bytes[1], |
| 7646 | enabled_controls_bytes[2], |
| 7647 | enabled_controls_bytes[3], |
| 7648 | change_controls_bytes[0], |
| 7649 | change_controls_bytes[1], |
| 7650 | change_controls_bytes[2], |
| 7651 | change_controls_bytes[3], |
| 7652 | repeat_delay_bytes[0], |
| 7653 | repeat_delay_bytes[1], |
| 7654 | repeat_interval_bytes[0], |
| 7655 | repeat_interval_bytes[1], |
| 7656 | slow_keys_delay_bytes[0], |
| 7657 | slow_keys_delay_bytes[1], |
| 7658 | debounce_delay_bytes[0], |
| 7659 | debounce_delay_bytes[1], |
| 7660 | mouse_keys_delay_bytes[0], |
| 7661 | mouse_keys_delay_bytes[1], |
| 7662 | mouse_keys_interval_bytes[0], |
| 7663 | mouse_keys_interval_bytes[1], |
| 7664 | mouse_keys_time_to_max_bytes[0], |
| 7665 | mouse_keys_time_to_max_bytes[1], |
| 7666 | mouse_keys_max_speed_bytes[0], |
| 7667 | mouse_keys_max_speed_bytes[1], |
| 7668 | mouse_keys_curve_bytes[0], |
| 7669 | mouse_keys_curve_bytes[1], |
| 7670 | access_x_timeout_bytes[0], |
| 7671 | access_x_timeout_bytes[1], |
| 7672 | access_x_timeout_mask_bytes[0], |
| 7673 | access_x_timeout_mask_bytes[1], |
| 7674 | access_x_timeout_mask_bytes[2], |
| 7675 | access_x_timeout_mask_bytes[3], |
| 7676 | access_x_timeout_values_bytes[0], |
| 7677 | access_x_timeout_values_bytes[1], |
| 7678 | access_x_timeout_values_bytes[2], |
| 7679 | access_x_timeout_values_bytes[3], |
| 7680 | access_x_timeout_options_mask_bytes[0], |
| 7681 | access_x_timeout_options_mask_bytes[1], |
| 7682 | access_x_timeout_options_values_bytes[0], |
| 7683 | access_x_timeout_options_values_bytes[1], |
| 7684 | ]; |
| 7685 | let length_so_far = length_so_far + request0.len(); |
| 7686 | let length_so_far = length_so_far + self.per_key_repeat.len(); |
| 7687 | assert_eq!(length_so_far % 4, 0); |
| 7688 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 7689 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 7690 | ([request0.into(), Cow::Owned(self.per_key_repeat.to_vec())], vec![]) |
| 7691 | } |
| 7692 | /// Parse this request given its header, its body, and any fds that go along with it |
| 7693 | #[cfg (feature = "request-parsing" )] |
| 7694 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 7695 | if header.minor_opcode != SET_CONTROLS_REQUEST { |
| 7696 | return Err(ParseError::InvalidValue); |
| 7697 | } |
| 7698 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 7699 | let (affect_internal_real_mods, remaining) = u8::try_parse(remaining)?; |
| 7700 | let affect_internal_real_mods = affect_internal_real_mods.into(); |
| 7701 | let (internal_real_mods, remaining) = u8::try_parse(remaining)?; |
| 7702 | let internal_real_mods = internal_real_mods.into(); |
| 7703 | let (affect_ignore_lock_real_mods, remaining) = u8::try_parse(remaining)?; |
| 7704 | let affect_ignore_lock_real_mods = affect_ignore_lock_real_mods.into(); |
| 7705 | let (ignore_lock_real_mods, remaining) = u8::try_parse(remaining)?; |
| 7706 | let ignore_lock_real_mods = ignore_lock_real_mods.into(); |
| 7707 | let (affect_internal_virtual_mods, remaining) = u16::try_parse(remaining)?; |
| 7708 | let affect_internal_virtual_mods = affect_internal_virtual_mods.into(); |
| 7709 | let (internal_virtual_mods, remaining) = u16::try_parse(remaining)?; |
| 7710 | let internal_virtual_mods = internal_virtual_mods.into(); |
| 7711 | let (affect_ignore_lock_virtual_mods, remaining) = u16::try_parse(remaining)?; |
| 7712 | let affect_ignore_lock_virtual_mods = affect_ignore_lock_virtual_mods.into(); |
| 7713 | let (ignore_lock_virtual_mods, remaining) = u16::try_parse(remaining)?; |
| 7714 | let ignore_lock_virtual_mods = ignore_lock_virtual_mods.into(); |
| 7715 | let (mouse_keys_dflt_btn, remaining) = u8::try_parse(remaining)?; |
| 7716 | let (groups_wrap, remaining) = u8::try_parse(remaining)?; |
| 7717 | let (access_x_options, remaining) = u16::try_parse(remaining)?; |
| 7718 | let access_x_options = access_x_options.into(); |
| 7719 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 7720 | let (affect_enabled_controls, remaining) = u32::try_parse(remaining)?; |
| 7721 | let affect_enabled_controls = affect_enabled_controls.into(); |
| 7722 | let (enabled_controls, remaining) = u32::try_parse(remaining)?; |
| 7723 | let enabled_controls = enabled_controls.into(); |
| 7724 | let (change_controls, remaining) = u32::try_parse(remaining)?; |
| 7725 | let change_controls = change_controls.into(); |
| 7726 | let (repeat_delay, remaining) = u16::try_parse(remaining)?; |
| 7727 | let (repeat_interval, remaining) = u16::try_parse(remaining)?; |
| 7728 | let (slow_keys_delay, remaining) = u16::try_parse(remaining)?; |
| 7729 | let (debounce_delay, remaining) = u16::try_parse(remaining)?; |
| 7730 | let (mouse_keys_delay, remaining) = u16::try_parse(remaining)?; |
| 7731 | let (mouse_keys_interval, remaining) = u16::try_parse(remaining)?; |
| 7732 | let (mouse_keys_time_to_max, remaining) = u16::try_parse(remaining)?; |
| 7733 | let (mouse_keys_max_speed, remaining) = u16::try_parse(remaining)?; |
| 7734 | let (mouse_keys_curve, remaining) = i16::try_parse(remaining)?; |
| 7735 | let (access_x_timeout, remaining) = u16::try_parse(remaining)?; |
| 7736 | let (access_x_timeout_mask, remaining) = u32::try_parse(remaining)?; |
| 7737 | let access_x_timeout_mask = access_x_timeout_mask.into(); |
| 7738 | let (access_x_timeout_values, remaining) = u32::try_parse(remaining)?; |
| 7739 | let access_x_timeout_values = access_x_timeout_values.into(); |
| 7740 | let (access_x_timeout_options_mask, remaining) = u16::try_parse(remaining)?; |
| 7741 | let access_x_timeout_options_mask = access_x_timeout_options_mask.into(); |
| 7742 | let (access_x_timeout_options_values, remaining) = u16::try_parse(remaining)?; |
| 7743 | let access_x_timeout_options_values = access_x_timeout_options_values.into(); |
| 7744 | let (per_key_repeat, remaining) = crate::x11_utils::parse_u8_array_ref::<32>(remaining)?; |
| 7745 | let _ = remaining; |
| 7746 | Ok(SetControlsRequest { |
| 7747 | device_spec, |
| 7748 | affect_internal_real_mods, |
| 7749 | internal_real_mods, |
| 7750 | affect_ignore_lock_real_mods, |
| 7751 | ignore_lock_real_mods, |
| 7752 | affect_internal_virtual_mods, |
| 7753 | internal_virtual_mods, |
| 7754 | affect_ignore_lock_virtual_mods, |
| 7755 | ignore_lock_virtual_mods, |
| 7756 | mouse_keys_dflt_btn, |
| 7757 | groups_wrap, |
| 7758 | access_x_options, |
| 7759 | affect_enabled_controls, |
| 7760 | enabled_controls, |
| 7761 | change_controls, |
| 7762 | repeat_delay, |
| 7763 | repeat_interval, |
| 7764 | slow_keys_delay, |
| 7765 | debounce_delay, |
| 7766 | mouse_keys_delay, |
| 7767 | mouse_keys_interval, |
| 7768 | mouse_keys_time_to_max, |
| 7769 | mouse_keys_max_speed, |
| 7770 | mouse_keys_curve, |
| 7771 | access_x_timeout, |
| 7772 | access_x_timeout_mask, |
| 7773 | access_x_timeout_values, |
| 7774 | access_x_timeout_options_mask, |
| 7775 | access_x_timeout_options_values, |
| 7776 | per_key_repeat: Cow::Borrowed(per_key_repeat), |
| 7777 | }) |
| 7778 | } |
| 7779 | /// Clone all borrowed data in this SetControlsRequest. |
| 7780 | pub fn into_owned(self) -> SetControlsRequest<'static> { |
| 7781 | SetControlsRequest { |
| 7782 | device_spec: self.device_spec, |
| 7783 | affect_internal_real_mods: self.affect_internal_real_mods, |
| 7784 | internal_real_mods: self.internal_real_mods, |
| 7785 | affect_ignore_lock_real_mods: self.affect_ignore_lock_real_mods, |
| 7786 | ignore_lock_real_mods: self.ignore_lock_real_mods, |
| 7787 | affect_internal_virtual_mods: self.affect_internal_virtual_mods, |
| 7788 | internal_virtual_mods: self.internal_virtual_mods, |
| 7789 | affect_ignore_lock_virtual_mods: self.affect_ignore_lock_virtual_mods, |
| 7790 | ignore_lock_virtual_mods: self.ignore_lock_virtual_mods, |
| 7791 | mouse_keys_dflt_btn: self.mouse_keys_dflt_btn, |
| 7792 | groups_wrap: self.groups_wrap, |
| 7793 | access_x_options: self.access_x_options, |
| 7794 | affect_enabled_controls: self.affect_enabled_controls, |
| 7795 | enabled_controls: self.enabled_controls, |
| 7796 | change_controls: self.change_controls, |
| 7797 | repeat_delay: self.repeat_delay, |
| 7798 | repeat_interval: self.repeat_interval, |
| 7799 | slow_keys_delay: self.slow_keys_delay, |
| 7800 | debounce_delay: self.debounce_delay, |
| 7801 | mouse_keys_delay: self.mouse_keys_delay, |
| 7802 | mouse_keys_interval: self.mouse_keys_interval, |
| 7803 | mouse_keys_time_to_max: self.mouse_keys_time_to_max, |
| 7804 | mouse_keys_max_speed: self.mouse_keys_max_speed, |
| 7805 | mouse_keys_curve: self.mouse_keys_curve, |
| 7806 | access_x_timeout: self.access_x_timeout, |
| 7807 | access_x_timeout_mask: self.access_x_timeout_mask, |
| 7808 | access_x_timeout_values: self.access_x_timeout_values, |
| 7809 | access_x_timeout_options_mask: self.access_x_timeout_options_mask, |
| 7810 | access_x_timeout_options_values: self.access_x_timeout_options_values, |
| 7811 | per_key_repeat: Cow::Owned(self.per_key_repeat.into_owned()), |
| 7812 | } |
| 7813 | } |
| 7814 | } |
| 7815 | impl<'input> Request for SetControlsRequest<'input> { |
| 7816 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 7817 | |
| 7818 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 7819 | let (bufs: [Cow<'_, [u8]>; 2], fds: Vec) = self.serialize(major_opcode); |
| 7820 | // Flatten the buffers into a single vector |
| 7821 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 7822 | (buf, fds) |
| 7823 | } |
| 7824 | } |
| 7825 | impl<'input> crate::x11_utils::VoidRequest for SetControlsRequest<'input> { |
| 7826 | } |
| 7827 | |
| 7828 | /// Opcode for the GetMap request |
| 7829 | pub const GET_MAP_REQUEST: u8 = 8; |
| 7830 | #[derive (Clone, Copy, Default)] |
| 7831 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 7832 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 7833 | pub struct GetMapRequest { |
| 7834 | pub device_spec: DeviceSpec, |
| 7835 | pub full: MapPart, |
| 7836 | pub partial: MapPart, |
| 7837 | pub first_type: u8, |
| 7838 | pub n_types: u8, |
| 7839 | pub first_key_sym: xproto::Keycode, |
| 7840 | pub n_key_syms: u8, |
| 7841 | pub first_key_action: xproto::Keycode, |
| 7842 | pub n_key_actions: u8, |
| 7843 | pub first_key_behavior: xproto::Keycode, |
| 7844 | pub n_key_behaviors: u8, |
| 7845 | pub virtual_mods: VMod, |
| 7846 | pub first_key_explicit: xproto::Keycode, |
| 7847 | pub n_key_explicit: u8, |
| 7848 | pub first_mod_map_key: xproto::Keycode, |
| 7849 | pub n_mod_map_keys: u8, |
| 7850 | pub first_v_mod_map_key: xproto::Keycode, |
| 7851 | pub n_v_mod_map_keys: u8, |
| 7852 | } |
| 7853 | impl_debug_if_no_extra_traits!(GetMapRequest, "GetMapRequest" ); |
| 7854 | impl GetMapRequest { |
| 7855 | /// Serialize this request into bytes for the provided connection |
| 7856 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 7857 | let length_so_far = 0; |
| 7858 | let device_spec_bytes = self.device_spec.serialize(); |
| 7859 | let full_bytes = u16::from(self.full).serialize(); |
| 7860 | let partial_bytes = u16::from(self.partial).serialize(); |
| 7861 | let first_type_bytes = self.first_type.serialize(); |
| 7862 | let n_types_bytes = self.n_types.serialize(); |
| 7863 | let first_key_sym_bytes = self.first_key_sym.serialize(); |
| 7864 | let n_key_syms_bytes = self.n_key_syms.serialize(); |
| 7865 | let first_key_action_bytes = self.first_key_action.serialize(); |
| 7866 | let n_key_actions_bytes = self.n_key_actions.serialize(); |
| 7867 | let first_key_behavior_bytes = self.first_key_behavior.serialize(); |
| 7868 | let n_key_behaviors_bytes = self.n_key_behaviors.serialize(); |
| 7869 | let virtual_mods_bytes = u16::from(self.virtual_mods).serialize(); |
| 7870 | let first_key_explicit_bytes = self.first_key_explicit.serialize(); |
| 7871 | let n_key_explicit_bytes = self.n_key_explicit.serialize(); |
| 7872 | let first_mod_map_key_bytes = self.first_mod_map_key.serialize(); |
| 7873 | let n_mod_map_keys_bytes = self.n_mod_map_keys.serialize(); |
| 7874 | let first_v_mod_map_key_bytes = self.first_v_mod_map_key.serialize(); |
| 7875 | let n_v_mod_map_keys_bytes = self.n_v_mod_map_keys.serialize(); |
| 7876 | let mut request0 = vec![ |
| 7877 | major_opcode, |
| 7878 | GET_MAP_REQUEST, |
| 7879 | 0, |
| 7880 | 0, |
| 7881 | device_spec_bytes[0], |
| 7882 | device_spec_bytes[1], |
| 7883 | full_bytes[0], |
| 7884 | full_bytes[1], |
| 7885 | partial_bytes[0], |
| 7886 | partial_bytes[1], |
| 7887 | first_type_bytes[0], |
| 7888 | n_types_bytes[0], |
| 7889 | first_key_sym_bytes[0], |
| 7890 | n_key_syms_bytes[0], |
| 7891 | first_key_action_bytes[0], |
| 7892 | n_key_actions_bytes[0], |
| 7893 | first_key_behavior_bytes[0], |
| 7894 | n_key_behaviors_bytes[0], |
| 7895 | virtual_mods_bytes[0], |
| 7896 | virtual_mods_bytes[1], |
| 7897 | first_key_explicit_bytes[0], |
| 7898 | n_key_explicit_bytes[0], |
| 7899 | first_mod_map_key_bytes[0], |
| 7900 | n_mod_map_keys_bytes[0], |
| 7901 | first_v_mod_map_key_bytes[0], |
| 7902 | n_v_mod_map_keys_bytes[0], |
| 7903 | 0, |
| 7904 | 0, |
| 7905 | ]; |
| 7906 | let length_so_far = length_so_far + request0.len(); |
| 7907 | assert_eq!(length_so_far % 4, 0); |
| 7908 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 7909 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 7910 | ([request0.into()], vec![]) |
| 7911 | } |
| 7912 | /// Parse this request given its header, its body, and any fds that go along with it |
| 7913 | #[cfg (feature = "request-parsing" )] |
| 7914 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 7915 | if header.minor_opcode != GET_MAP_REQUEST { |
| 7916 | return Err(ParseError::InvalidValue); |
| 7917 | } |
| 7918 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 7919 | let (full, remaining) = u16::try_parse(remaining)?; |
| 7920 | let full = full.into(); |
| 7921 | let (partial, remaining) = u16::try_parse(remaining)?; |
| 7922 | let partial = partial.into(); |
| 7923 | let (first_type, remaining) = u8::try_parse(remaining)?; |
| 7924 | let (n_types, remaining) = u8::try_parse(remaining)?; |
| 7925 | let (first_key_sym, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 7926 | let (n_key_syms, remaining) = u8::try_parse(remaining)?; |
| 7927 | let (first_key_action, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 7928 | let (n_key_actions, remaining) = u8::try_parse(remaining)?; |
| 7929 | let (first_key_behavior, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 7930 | let (n_key_behaviors, remaining) = u8::try_parse(remaining)?; |
| 7931 | let (virtual_mods, remaining) = u16::try_parse(remaining)?; |
| 7932 | let virtual_mods = virtual_mods.into(); |
| 7933 | let (first_key_explicit, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 7934 | let (n_key_explicit, remaining) = u8::try_parse(remaining)?; |
| 7935 | let (first_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 7936 | let (n_mod_map_keys, remaining) = u8::try_parse(remaining)?; |
| 7937 | let (first_v_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 7938 | let (n_v_mod_map_keys, remaining) = u8::try_parse(remaining)?; |
| 7939 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 7940 | let _ = remaining; |
| 7941 | Ok(GetMapRequest { |
| 7942 | device_spec, |
| 7943 | full, |
| 7944 | partial, |
| 7945 | first_type, |
| 7946 | n_types, |
| 7947 | first_key_sym, |
| 7948 | n_key_syms, |
| 7949 | first_key_action, |
| 7950 | n_key_actions, |
| 7951 | first_key_behavior, |
| 7952 | n_key_behaviors, |
| 7953 | virtual_mods, |
| 7954 | first_key_explicit, |
| 7955 | n_key_explicit, |
| 7956 | first_mod_map_key, |
| 7957 | n_mod_map_keys, |
| 7958 | first_v_mod_map_key, |
| 7959 | n_v_mod_map_keys, |
| 7960 | }) |
| 7961 | } |
| 7962 | } |
| 7963 | impl Request for GetMapRequest { |
| 7964 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 7965 | |
| 7966 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 7967 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 7968 | // Flatten the buffers into a single vector |
| 7969 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 7970 | (buf, fds) |
| 7971 | } |
| 7972 | } |
| 7973 | impl crate::x11_utils::ReplyRequest for GetMapRequest { |
| 7974 | type Reply = GetMapReply; |
| 7975 | } |
| 7976 | |
| 7977 | #[derive (Clone)] |
| 7978 | #[cfg_attr (feature = "extra-traits" , derive(Debug))] |
| 7979 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 7980 | pub struct GetMapMapKeyActions { |
| 7981 | pub acts_rtrn_count: Vec<u8>, |
| 7982 | pub acts_rtrn_acts: Vec<Action>, |
| 7983 | } |
| 7984 | impl_debug_if_no_extra_traits!(GetMapMapKeyActions, "GetMapMapKeyActions" ); |
| 7985 | impl GetMapMapKeyActions { |
| 7986 | pub fn try_parse(remaining: &[u8], n_key_actions: u8, total_actions: u16) -> Result<(Self, &[u8]), ParseError> { |
| 7987 | let value: &[u8] = remaining; |
| 7988 | let (acts_rtrn_count: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data:remaining, list_length:n_key_actions.try_to_usize()?)?; |
| 7989 | let acts_rtrn_count: Vec = acts_rtrn_count.to_vec(); |
| 7990 | // Align offset to multiple of 4 |
| 7991 | let offset: usize = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 7992 | let misalignment: usize = (4 - (offset % 4)) % 4; |
| 7993 | let remaining: &[u8] = remaining.get(misalignment..).ok_or(err:ParseError::InsufficientData)?; |
| 7994 | let (acts_rtrn_acts: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<Action>(data:remaining, list_length:total_actions.try_to_usize()?)?; |
| 7995 | let result: GetMapMapKeyActions = GetMapMapKeyActions { acts_rtrn_count, acts_rtrn_acts }; |
| 7996 | Ok((result, remaining)) |
| 7997 | } |
| 7998 | } |
| 7999 | impl GetMapMapKeyActions { |
| 8000 | #[allow (dead_code)] |
| 8001 | fn serialize(&self, n_key_actions: u8, total_actions: u16) -> Vec<u8> { |
| 8002 | let mut result: Vec = Vec::new(); |
| 8003 | self.serialize_into(&mut result, n_key_actions:u8::from(n_key_actions), total_actions:u16::from(total_actions)); |
| 8004 | result |
| 8005 | } |
| 8006 | fn serialize_into(&self, bytes: &mut Vec<u8>, n_key_actions: u8, total_actions: u16) { |
| 8007 | assert_eq!(self.acts_rtrn_count.len(), usize::try_from(n_key_actions).unwrap(), "`acts_rtrn_count` has an incorrect length" ); |
| 8008 | bytes.extend_from_slice(&self.acts_rtrn_count); |
| 8009 | bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]); |
| 8010 | assert_eq!(self.acts_rtrn_acts.len(), usize::try_from(total_actions).unwrap(), "`acts_rtrn_acts` has an incorrect length" ); |
| 8011 | self.acts_rtrn_acts.serialize_into(bytes); |
| 8012 | } |
| 8013 | } |
| 8014 | #[derive (Clone, Default)] |
| 8015 | #[cfg_attr (feature = "extra-traits" , derive(Debug))] |
| 8016 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8017 | pub struct GetMapMap { |
| 8018 | pub types_rtrn: Option<Vec<KeyType>>, |
| 8019 | pub syms_rtrn: Option<Vec<KeySymMap>>, |
| 8020 | pub key_actions: Option<GetMapMapKeyActions>, |
| 8021 | pub behaviors_rtrn: Option<Vec<SetBehavior>>, |
| 8022 | pub vmods_rtrn: Option<Vec<xproto::ModMask>>, |
| 8023 | pub explicit_rtrn: Option<Vec<SetExplicit>>, |
| 8024 | pub modmap_rtrn: Option<Vec<KeyModMap>>, |
| 8025 | pub vmodmap_rtrn: Option<Vec<KeyVModMap>>, |
| 8026 | } |
| 8027 | impl_debug_if_no_extra_traits!(GetMapMap, "GetMapMap" ); |
| 8028 | impl GetMapMap { |
| 8029 | #[cfg_attr (not(feature = "request-parsing" ), allow(dead_code))] |
| 8030 | 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> { |
| 8031 | let switch_expr = u16::from(present); |
| 8032 | let mut outer_remaining = value; |
| 8033 | let types_rtrn = if switch_expr & u16::from(MapPart::KEY_TYPES) != 0 { |
| 8034 | let remaining = outer_remaining; |
| 8035 | let (types_rtrn, remaining) = crate::x11_utils::parse_list::<KeyType>(remaining, n_types.try_to_usize()?)?; |
| 8036 | outer_remaining = remaining; |
| 8037 | Some(types_rtrn) |
| 8038 | } else { |
| 8039 | None |
| 8040 | }; |
| 8041 | let syms_rtrn = if switch_expr & u16::from(MapPart::KEY_SYMS) != 0 { |
| 8042 | let remaining = outer_remaining; |
| 8043 | let (syms_rtrn, remaining) = crate::x11_utils::parse_list::<KeySymMap>(remaining, n_key_syms.try_to_usize()?)?; |
| 8044 | outer_remaining = remaining; |
| 8045 | Some(syms_rtrn) |
| 8046 | } else { |
| 8047 | None |
| 8048 | }; |
| 8049 | let key_actions = if switch_expr & u16::from(MapPart::KEY_ACTIONS) != 0 { |
| 8050 | let (key_actions, new_remaining) = GetMapMapKeyActions::try_parse(outer_remaining, n_key_actions, total_actions)?; |
| 8051 | outer_remaining = new_remaining; |
| 8052 | Some(key_actions) |
| 8053 | } else { |
| 8054 | None |
| 8055 | }; |
| 8056 | let behaviors_rtrn = if switch_expr & u16::from(MapPart::KEY_BEHAVIORS) != 0 { |
| 8057 | let remaining = outer_remaining; |
| 8058 | let (behaviors_rtrn, remaining) = crate::x11_utils::parse_list::<SetBehavior>(remaining, total_key_behaviors.try_to_usize()?)?; |
| 8059 | outer_remaining = remaining; |
| 8060 | Some(behaviors_rtrn) |
| 8061 | } else { |
| 8062 | None |
| 8063 | }; |
| 8064 | let vmods_rtrn = if switch_expr & u16::from(MapPart::VIRTUAL_MODS) != 0 { |
| 8065 | let remaining = outer_remaining; |
| 8066 | let value = remaining; |
| 8067 | let mut remaining = remaining; |
| 8068 | let list_length = u32::from(virtual_mods).count_ones().try_to_usize()?; |
| 8069 | let mut vmods_rtrn = Vec::with_capacity(list_length); |
| 8070 | for _ in 0..list_length { |
| 8071 | let (v, new_remaining) = u8::try_parse(remaining)?; |
| 8072 | let v = v.into(); |
| 8073 | remaining = new_remaining; |
| 8074 | vmods_rtrn.push(v); |
| 8075 | } |
| 8076 | // Align offset to multiple of 4 |
| 8077 | let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 8078 | let misalignment = (4 - (offset % 4)) % 4; |
| 8079 | let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; |
| 8080 | outer_remaining = remaining; |
| 8081 | Some(vmods_rtrn) |
| 8082 | } else { |
| 8083 | None |
| 8084 | }; |
| 8085 | let explicit_rtrn = if switch_expr & u16::from(MapPart::EXPLICIT_COMPONENTS) != 0 { |
| 8086 | let remaining = outer_remaining; |
| 8087 | let value = remaining; |
| 8088 | let (explicit_rtrn, remaining) = crate::x11_utils::parse_list::<SetExplicit>(remaining, total_key_explicit.try_to_usize()?)?; |
| 8089 | // Align offset to multiple of 4 |
| 8090 | let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 8091 | let misalignment = (4 - (offset % 4)) % 4; |
| 8092 | let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; |
| 8093 | outer_remaining = remaining; |
| 8094 | Some(explicit_rtrn) |
| 8095 | } else { |
| 8096 | None |
| 8097 | }; |
| 8098 | let modmap_rtrn = if switch_expr & u16::from(MapPart::MODIFIER_MAP) != 0 { |
| 8099 | let remaining = outer_remaining; |
| 8100 | let value = remaining; |
| 8101 | let (modmap_rtrn, remaining) = crate::x11_utils::parse_list::<KeyModMap>(remaining, total_mod_map_keys.try_to_usize()?)?; |
| 8102 | // Align offset to multiple of 4 |
| 8103 | let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 8104 | let misalignment = (4 - (offset % 4)) % 4; |
| 8105 | let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; |
| 8106 | outer_remaining = remaining; |
| 8107 | Some(modmap_rtrn) |
| 8108 | } else { |
| 8109 | None |
| 8110 | }; |
| 8111 | let vmodmap_rtrn = if switch_expr & u16::from(MapPart::VIRTUAL_MOD_MAP) != 0 { |
| 8112 | let remaining = outer_remaining; |
| 8113 | let (vmodmap_rtrn, remaining) = crate::x11_utils::parse_list::<KeyVModMap>(remaining, total_v_mod_map_keys.try_to_usize()?)?; |
| 8114 | outer_remaining = remaining; |
| 8115 | Some(vmodmap_rtrn) |
| 8116 | } else { |
| 8117 | None |
| 8118 | }; |
| 8119 | let result = GetMapMap { types_rtrn, syms_rtrn, key_actions, behaviors_rtrn, vmods_rtrn, explicit_rtrn, modmap_rtrn, vmodmap_rtrn }; |
| 8120 | Ok((result, outer_remaining)) |
| 8121 | } |
| 8122 | } |
| 8123 | impl GetMapMap { |
| 8124 | #[allow (dead_code)] |
| 8125 | 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> { |
| 8126 | let mut result = Vec::new(); |
| 8127 | self.serialize_into(&mut result, u16::from(present), u8::from(n_types), u8::from(n_key_syms), u8::from(n_key_actions), u16::from(total_actions), u8::from(total_key_behaviors), u16::from(virtual_mods), u8::from(total_key_explicit), u8::from(total_mod_map_keys), u8::from(total_v_mod_map_keys)); |
| 8128 | result |
| 8129 | } |
| 8130 | 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) { |
| 8131 | assert_eq!(self.switch_expr(), u16::from(present), "switch `map` has an inconsistent discriminant" ); |
| 8132 | if let Some(ref types_rtrn) = self.types_rtrn { |
| 8133 | assert_eq!(types_rtrn.len(), usize::try_from(n_types).unwrap(), "`types_rtrn` has an incorrect length" ); |
| 8134 | types_rtrn.serialize_into(bytes); |
| 8135 | } |
| 8136 | if let Some(ref syms_rtrn) = self.syms_rtrn { |
| 8137 | assert_eq!(syms_rtrn.len(), usize::try_from(n_key_syms).unwrap(), "`syms_rtrn` has an incorrect length" ); |
| 8138 | syms_rtrn.serialize_into(bytes); |
| 8139 | } |
| 8140 | if let Some(ref key_actions) = self.key_actions { |
| 8141 | key_actions.serialize_into(bytes, u8::from(n_key_actions), u16::from(total_actions)); |
| 8142 | } |
| 8143 | if let Some(ref behaviors_rtrn) = self.behaviors_rtrn { |
| 8144 | assert_eq!(behaviors_rtrn.len(), usize::try_from(total_key_behaviors).unwrap(), "`behaviors_rtrn` has an incorrect length" ); |
| 8145 | behaviors_rtrn.serialize_into(bytes); |
| 8146 | } |
| 8147 | if let Some(ref vmods_rtrn) = self.vmods_rtrn { |
| 8148 | assert_eq!(vmods_rtrn.len(), usize::try_from(u32::from(virtual_mods).count_ones()).unwrap(), "`vmods_rtrn` has an incorrect length" ); |
| 8149 | for element in vmods_rtrn.iter().copied() { |
| 8150 | (u16::from(element) as u8).serialize_into(bytes); |
| 8151 | } |
| 8152 | bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]); |
| 8153 | } |
| 8154 | if let Some(ref explicit_rtrn) = self.explicit_rtrn { |
| 8155 | assert_eq!(explicit_rtrn.len(), usize::try_from(total_key_explicit).unwrap(), "`explicit_rtrn` has an incorrect length" ); |
| 8156 | explicit_rtrn.serialize_into(bytes); |
| 8157 | bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]); |
| 8158 | } |
| 8159 | if let Some(ref modmap_rtrn) = self.modmap_rtrn { |
| 8160 | assert_eq!(modmap_rtrn.len(), usize::try_from(total_mod_map_keys).unwrap(), "`modmap_rtrn` has an incorrect length" ); |
| 8161 | modmap_rtrn.serialize_into(bytes); |
| 8162 | bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]); |
| 8163 | } |
| 8164 | if let Some(ref vmodmap_rtrn) = self.vmodmap_rtrn { |
| 8165 | assert_eq!(vmodmap_rtrn.len(), usize::try_from(total_v_mod_map_keys).unwrap(), "`vmodmap_rtrn` has an incorrect length" ); |
| 8166 | vmodmap_rtrn.serialize_into(bytes); |
| 8167 | } |
| 8168 | } |
| 8169 | } |
| 8170 | impl GetMapMap { |
| 8171 | fn switch_expr(&self) -> u16 { |
| 8172 | let mut expr_value = 0; |
| 8173 | if self.types_rtrn.is_some() { |
| 8174 | expr_value |= u16::from(MapPart::KEY_TYPES); |
| 8175 | } |
| 8176 | if self.syms_rtrn.is_some() { |
| 8177 | expr_value |= u16::from(MapPart::KEY_SYMS); |
| 8178 | } |
| 8179 | if self.key_actions.is_some() { |
| 8180 | expr_value |= u16::from(MapPart::KEY_ACTIONS); |
| 8181 | } |
| 8182 | if self.behaviors_rtrn.is_some() { |
| 8183 | expr_value |= u16::from(MapPart::KEY_BEHAVIORS); |
| 8184 | } |
| 8185 | if self.vmods_rtrn.is_some() { |
| 8186 | expr_value |= u16::from(MapPart::VIRTUAL_MODS); |
| 8187 | } |
| 8188 | if self.explicit_rtrn.is_some() { |
| 8189 | expr_value |= u16::from(MapPart::EXPLICIT_COMPONENTS); |
| 8190 | } |
| 8191 | if self.modmap_rtrn.is_some() { |
| 8192 | expr_value |= u16::from(MapPart::MODIFIER_MAP); |
| 8193 | } |
| 8194 | if self.vmodmap_rtrn.is_some() { |
| 8195 | expr_value |= u16::from(MapPart::VIRTUAL_MOD_MAP); |
| 8196 | } |
| 8197 | expr_value |
| 8198 | } |
| 8199 | } |
| 8200 | |
| 8201 | #[derive (Clone)] |
| 8202 | #[cfg_attr (feature = "extra-traits" , derive(Debug))] |
| 8203 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8204 | pub struct GetMapReply { |
| 8205 | pub device_id: u8, |
| 8206 | pub sequence: u16, |
| 8207 | pub length: u32, |
| 8208 | pub min_key_code: xproto::Keycode, |
| 8209 | pub max_key_code: xproto::Keycode, |
| 8210 | pub first_type: u8, |
| 8211 | pub n_types: u8, |
| 8212 | pub total_types: u8, |
| 8213 | pub first_key_sym: xproto::Keycode, |
| 8214 | pub total_syms: u16, |
| 8215 | pub n_key_syms: u8, |
| 8216 | pub first_key_action: xproto::Keycode, |
| 8217 | pub total_actions: u16, |
| 8218 | pub n_key_actions: u8, |
| 8219 | pub first_key_behavior: xproto::Keycode, |
| 8220 | pub n_key_behaviors: u8, |
| 8221 | pub total_key_behaviors: u8, |
| 8222 | pub first_key_explicit: xproto::Keycode, |
| 8223 | pub n_key_explicit: u8, |
| 8224 | pub total_key_explicit: u8, |
| 8225 | pub first_mod_map_key: xproto::Keycode, |
| 8226 | pub n_mod_map_keys: u8, |
| 8227 | pub total_mod_map_keys: u8, |
| 8228 | pub first_v_mod_map_key: xproto::Keycode, |
| 8229 | pub n_v_mod_map_keys: u8, |
| 8230 | pub total_v_mod_map_keys: u8, |
| 8231 | pub virtual_mods: VMod, |
| 8232 | pub map: GetMapMap, |
| 8233 | } |
| 8234 | impl_debug_if_no_extra_traits!(GetMapReply, "GetMapReply" ); |
| 8235 | impl TryParse for GetMapReply { |
| 8236 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 8237 | let remaining = initial_value; |
| 8238 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 8239 | let (device_id, remaining) = u8::try_parse(remaining)?; |
| 8240 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 8241 | let (length, remaining) = u32::try_parse(remaining)?; |
| 8242 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 8243 | let (min_key_code, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 8244 | let (max_key_code, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 8245 | let (present, remaining) = u16::try_parse(remaining)?; |
| 8246 | let (first_type, remaining) = u8::try_parse(remaining)?; |
| 8247 | let (n_types, remaining) = u8::try_parse(remaining)?; |
| 8248 | let (total_types, remaining) = u8::try_parse(remaining)?; |
| 8249 | let (first_key_sym, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 8250 | let (total_syms, remaining) = u16::try_parse(remaining)?; |
| 8251 | let (n_key_syms, remaining) = u8::try_parse(remaining)?; |
| 8252 | let (first_key_action, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 8253 | let (total_actions, remaining) = u16::try_parse(remaining)?; |
| 8254 | let (n_key_actions, remaining) = u8::try_parse(remaining)?; |
| 8255 | let (first_key_behavior, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 8256 | let (n_key_behaviors, remaining) = u8::try_parse(remaining)?; |
| 8257 | let (total_key_behaviors, remaining) = u8::try_parse(remaining)?; |
| 8258 | let (first_key_explicit, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 8259 | let (n_key_explicit, remaining) = u8::try_parse(remaining)?; |
| 8260 | let (total_key_explicit, remaining) = u8::try_parse(remaining)?; |
| 8261 | let (first_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 8262 | let (n_mod_map_keys, remaining) = u8::try_parse(remaining)?; |
| 8263 | let (total_mod_map_keys, remaining) = u8::try_parse(remaining)?; |
| 8264 | let (first_v_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 8265 | let (n_v_mod_map_keys, remaining) = u8::try_parse(remaining)?; |
| 8266 | let (total_v_mod_map_keys, remaining) = u8::try_parse(remaining)?; |
| 8267 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 8268 | let (virtual_mods, remaining) = u16::try_parse(remaining)?; |
| 8269 | let (map, remaining) = GetMapMap::try_parse(remaining, u16::from(present), u8::from(n_types), u8::from(n_key_syms), u8::from(n_key_actions), u16::from(total_actions), u8::from(total_key_behaviors), u16::from(virtual_mods), u8::from(total_key_explicit), u8::from(total_mod_map_keys), u8::from(total_v_mod_map_keys))?; |
| 8270 | if response_type != 1 { |
| 8271 | return Err(ParseError::InvalidValue); |
| 8272 | } |
| 8273 | let virtual_mods = virtual_mods.into(); |
| 8274 | 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 }; |
| 8275 | let _ = remaining; |
| 8276 | let remaining = initial_value.get(32 + length as usize * 4..) |
| 8277 | .ok_or(ParseError::InsufficientData)?; |
| 8278 | Ok((result, remaining)) |
| 8279 | } |
| 8280 | } |
| 8281 | impl Serialize for GetMapReply { |
| 8282 | type Bytes = Vec<u8>; |
| 8283 | fn serialize(&self) -> Vec<u8> { |
| 8284 | let mut result = Vec::new(); |
| 8285 | self.serialize_into(&mut result); |
| 8286 | result |
| 8287 | } |
| 8288 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 8289 | bytes.reserve(40); |
| 8290 | let response_type_bytes = &[1]; |
| 8291 | bytes.push(response_type_bytes[0]); |
| 8292 | self.device_id.serialize_into(bytes); |
| 8293 | self.sequence.serialize_into(bytes); |
| 8294 | self.length.serialize_into(bytes); |
| 8295 | bytes.extend_from_slice(&[0; 2]); |
| 8296 | self.min_key_code.serialize_into(bytes); |
| 8297 | self.max_key_code.serialize_into(bytes); |
| 8298 | let present: u16 = self.map.switch_expr(); |
| 8299 | present.serialize_into(bytes); |
| 8300 | self.first_type.serialize_into(bytes); |
| 8301 | self.n_types.serialize_into(bytes); |
| 8302 | self.total_types.serialize_into(bytes); |
| 8303 | self.first_key_sym.serialize_into(bytes); |
| 8304 | self.total_syms.serialize_into(bytes); |
| 8305 | self.n_key_syms.serialize_into(bytes); |
| 8306 | self.first_key_action.serialize_into(bytes); |
| 8307 | self.total_actions.serialize_into(bytes); |
| 8308 | self.n_key_actions.serialize_into(bytes); |
| 8309 | self.first_key_behavior.serialize_into(bytes); |
| 8310 | self.n_key_behaviors.serialize_into(bytes); |
| 8311 | self.total_key_behaviors.serialize_into(bytes); |
| 8312 | self.first_key_explicit.serialize_into(bytes); |
| 8313 | self.n_key_explicit.serialize_into(bytes); |
| 8314 | self.total_key_explicit.serialize_into(bytes); |
| 8315 | self.first_mod_map_key.serialize_into(bytes); |
| 8316 | self.n_mod_map_keys.serialize_into(bytes); |
| 8317 | self.total_mod_map_keys.serialize_into(bytes); |
| 8318 | self.first_v_mod_map_key.serialize_into(bytes); |
| 8319 | self.n_v_mod_map_keys.serialize_into(bytes); |
| 8320 | self.total_v_mod_map_keys.serialize_into(bytes); |
| 8321 | bytes.extend_from_slice(&[0; 1]); |
| 8322 | u16::from(self.virtual_mods).serialize_into(bytes); |
| 8323 | self.map.serialize_into(bytes, u16::from(present), u8::from(self.n_types), u8::from(self.n_key_syms), u8::from(self.n_key_actions), u16::from(self.total_actions), u8::from(self.total_key_behaviors), u16::from(self.virtual_mods), u8::from(self.total_key_explicit), u8::from(self.total_mod_map_keys), u8::from(self.total_v_mod_map_keys)); |
| 8324 | } |
| 8325 | } |
| 8326 | |
| 8327 | #[derive (Clone)] |
| 8328 | #[cfg_attr (feature = "extra-traits" , derive(Debug))] |
| 8329 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8330 | pub struct SetMapAuxKeyActions { |
| 8331 | pub actions_count: Vec<u8>, |
| 8332 | pub actions: Vec<Action>, |
| 8333 | } |
| 8334 | impl_debug_if_no_extra_traits!(SetMapAuxKeyActions, "SetMapAuxKeyActions" ); |
| 8335 | impl SetMapAuxKeyActions { |
| 8336 | pub fn try_parse(remaining: &[u8], n_key_actions: u8, total_actions: u16) -> Result<(Self, &[u8]), ParseError> { |
| 8337 | let value: &[u8] = remaining; |
| 8338 | let (actions_count: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data:remaining, list_length:n_key_actions.try_to_usize()?)?; |
| 8339 | let actions_count: Vec = actions_count.to_vec(); |
| 8340 | // Align offset to multiple of 4 |
| 8341 | let offset: usize = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 8342 | let misalignment: usize = (4 - (offset % 4)) % 4; |
| 8343 | let remaining: &[u8] = remaining.get(misalignment..).ok_or(err:ParseError::InsufficientData)?; |
| 8344 | let (actions: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<Action>(data:remaining, list_length:total_actions.try_to_usize()?)?; |
| 8345 | let result: SetMapAuxKeyActions = SetMapAuxKeyActions { actions_count, actions }; |
| 8346 | Ok((result, remaining)) |
| 8347 | } |
| 8348 | } |
| 8349 | impl SetMapAuxKeyActions { |
| 8350 | #[allow (dead_code)] |
| 8351 | fn serialize(&self, n_key_actions: u8, total_actions: u16) -> Vec<u8> { |
| 8352 | let mut result: Vec = Vec::new(); |
| 8353 | self.serialize_into(&mut result, n_key_actions:u8::from(n_key_actions), total_actions:u16::from(total_actions)); |
| 8354 | result |
| 8355 | } |
| 8356 | fn serialize_into(&self, bytes: &mut Vec<u8>, n_key_actions: u8, total_actions: u16) { |
| 8357 | assert_eq!(self.actions_count.len(), usize::try_from(n_key_actions).unwrap(), "`actions_count` has an incorrect length" ); |
| 8358 | bytes.extend_from_slice(&self.actions_count); |
| 8359 | bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]); |
| 8360 | assert_eq!(self.actions.len(), usize::try_from(total_actions).unwrap(), "`actions` has an incorrect length" ); |
| 8361 | self.actions.serialize_into(bytes); |
| 8362 | } |
| 8363 | } |
| 8364 | /// Auxiliary and optional information for the `set_map` function |
| 8365 | #[derive (Clone, Default)] |
| 8366 | #[cfg_attr (feature = "extra-traits" , derive(Debug))] |
| 8367 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8368 | pub struct SetMapAux { |
| 8369 | pub types: Option<Vec<SetKeyType>>, |
| 8370 | pub syms: Option<Vec<KeySymMap>>, |
| 8371 | pub key_actions: Option<SetMapAuxKeyActions>, |
| 8372 | pub behaviors: Option<Vec<SetBehavior>>, |
| 8373 | pub vmods: Option<Vec<u8>>, |
| 8374 | pub explicit: Option<Vec<SetExplicit>>, |
| 8375 | pub modmap: Option<Vec<KeyModMap>>, |
| 8376 | pub vmodmap: Option<Vec<KeyVModMap>>, |
| 8377 | } |
| 8378 | impl_debug_if_no_extra_traits!(SetMapAux, "SetMapAux" ); |
| 8379 | impl SetMapAux { |
| 8380 | #[cfg_attr (not(feature = "request-parsing" ), allow(dead_code))] |
| 8381 | 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> { |
| 8382 | let switch_expr = u16::from(present); |
| 8383 | let mut outer_remaining = value; |
| 8384 | let types = if switch_expr & u16::from(MapPart::KEY_TYPES) != 0 { |
| 8385 | let remaining = outer_remaining; |
| 8386 | let (types, remaining) = crate::x11_utils::parse_list::<SetKeyType>(remaining, n_types.try_to_usize()?)?; |
| 8387 | outer_remaining = remaining; |
| 8388 | Some(types) |
| 8389 | } else { |
| 8390 | None |
| 8391 | }; |
| 8392 | let syms = if switch_expr & u16::from(MapPart::KEY_SYMS) != 0 { |
| 8393 | let remaining = outer_remaining; |
| 8394 | let (syms, remaining) = crate::x11_utils::parse_list::<KeySymMap>(remaining, n_key_syms.try_to_usize()?)?; |
| 8395 | outer_remaining = remaining; |
| 8396 | Some(syms) |
| 8397 | } else { |
| 8398 | None |
| 8399 | }; |
| 8400 | let key_actions = if switch_expr & u16::from(MapPart::KEY_ACTIONS) != 0 { |
| 8401 | let (key_actions, new_remaining) = SetMapAuxKeyActions::try_parse(outer_remaining, n_key_actions, total_actions)?; |
| 8402 | outer_remaining = new_remaining; |
| 8403 | Some(key_actions) |
| 8404 | } else { |
| 8405 | None |
| 8406 | }; |
| 8407 | let behaviors = if switch_expr & u16::from(MapPart::KEY_BEHAVIORS) != 0 { |
| 8408 | let remaining = outer_remaining; |
| 8409 | let (behaviors, remaining) = crate::x11_utils::parse_list::<SetBehavior>(remaining, total_key_behaviors.try_to_usize()?)?; |
| 8410 | outer_remaining = remaining; |
| 8411 | Some(behaviors) |
| 8412 | } else { |
| 8413 | None |
| 8414 | }; |
| 8415 | let vmods = if switch_expr & u16::from(MapPart::VIRTUAL_MODS) != 0 { |
| 8416 | let remaining = outer_remaining; |
| 8417 | let value = remaining; |
| 8418 | let (vmods, remaining) = crate::x11_utils::parse_u8_list(remaining, u32::from(virtual_mods).count_ones().try_to_usize()?)?; |
| 8419 | let vmods = vmods.to_vec(); |
| 8420 | // Align offset to multiple of 4 |
| 8421 | let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 8422 | let misalignment = (4 - (offset % 4)) % 4; |
| 8423 | let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; |
| 8424 | outer_remaining = remaining; |
| 8425 | Some(vmods) |
| 8426 | } else { |
| 8427 | None |
| 8428 | }; |
| 8429 | let explicit = if switch_expr & u16::from(MapPart::EXPLICIT_COMPONENTS) != 0 { |
| 8430 | let remaining = outer_remaining; |
| 8431 | let (explicit, remaining) = crate::x11_utils::parse_list::<SetExplicit>(remaining, total_key_explicit.try_to_usize()?)?; |
| 8432 | outer_remaining = remaining; |
| 8433 | Some(explicit) |
| 8434 | } else { |
| 8435 | None |
| 8436 | }; |
| 8437 | let modmap = if switch_expr & u16::from(MapPart::MODIFIER_MAP) != 0 { |
| 8438 | let remaining = outer_remaining; |
| 8439 | let (modmap, remaining) = crate::x11_utils::parse_list::<KeyModMap>(remaining, total_mod_map_keys.try_to_usize()?)?; |
| 8440 | outer_remaining = remaining; |
| 8441 | Some(modmap) |
| 8442 | } else { |
| 8443 | None |
| 8444 | }; |
| 8445 | let vmodmap = if switch_expr & u16::from(MapPart::VIRTUAL_MOD_MAP) != 0 { |
| 8446 | let remaining = outer_remaining; |
| 8447 | let (vmodmap, remaining) = crate::x11_utils::parse_list::<KeyVModMap>(remaining, total_v_mod_map_keys.try_to_usize()?)?; |
| 8448 | outer_remaining = remaining; |
| 8449 | Some(vmodmap) |
| 8450 | } else { |
| 8451 | None |
| 8452 | }; |
| 8453 | let result = SetMapAux { types, syms, key_actions, behaviors, vmods, explicit, modmap, vmodmap }; |
| 8454 | Ok((result, outer_remaining)) |
| 8455 | } |
| 8456 | } |
| 8457 | impl SetMapAux { |
| 8458 | #[allow (dead_code)] |
| 8459 | 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> { |
| 8460 | let mut result = Vec::new(); |
| 8461 | self.serialize_into(&mut result, u16::from(present), u8::from(n_types), u8::from(n_key_syms), u8::from(n_key_actions), u16::from(total_actions), u8::from(total_key_behaviors), u16::from(virtual_mods), u8::from(total_key_explicit), u8::from(total_mod_map_keys), u8::from(total_v_mod_map_keys)); |
| 8462 | result |
| 8463 | } |
| 8464 | 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) { |
| 8465 | assert_eq!(self.switch_expr(), u16::from(present), "switch `values` has an inconsistent discriminant" ); |
| 8466 | if let Some(ref types) = self.types { |
| 8467 | assert_eq!(types.len(), usize::try_from(n_types).unwrap(), "`types` has an incorrect length" ); |
| 8468 | types.serialize_into(bytes); |
| 8469 | } |
| 8470 | if let Some(ref syms) = self.syms { |
| 8471 | assert_eq!(syms.len(), usize::try_from(n_key_syms).unwrap(), "`syms` has an incorrect length" ); |
| 8472 | syms.serialize_into(bytes); |
| 8473 | } |
| 8474 | if let Some(ref key_actions) = self.key_actions { |
| 8475 | key_actions.serialize_into(bytes, u8::from(n_key_actions), u16::from(total_actions)); |
| 8476 | } |
| 8477 | if let Some(ref behaviors) = self.behaviors { |
| 8478 | assert_eq!(behaviors.len(), usize::try_from(total_key_behaviors).unwrap(), "`behaviors` has an incorrect length" ); |
| 8479 | behaviors.serialize_into(bytes); |
| 8480 | } |
| 8481 | if let Some(ref vmods) = self.vmods { |
| 8482 | assert_eq!(vmods.len(), usize::try_from(u32::from(virtual_mods).count_ones()).unwrap(), "`vmods` has an incorrect length" ); |
| 8483 | bytes.extend_from_slice(&vmods); |
| 8484 | bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]); |
| 8485 | } |
| 8486 | if let Some(ref explicit) = self.explicit { |
| 8487 | assert_eq!(explicit.len(), usize::try_from(total_key_explicit).unwrap(), "`explicit` has an incorrect length" ); |
| 8488 | explicit.serialize_into(bytes); |
| 8489 | } |
| 8490 | if let Some(ref modmap) = self.modmap { |
| 8491 | assert_eq!(modmap.len(), usize::try_from(total_mod_map_keys).unwrap(), "`modmap` has an incorrect length" ); |
| 8492 | modmap.serialize_into(bytes); |
| 8493 | } |
| 8494 | if let Some(ref vmodmap) = self.vmodmap { |
| 8495 | assert_eq!(vmodmap.len(), usize::try_from(total_v_mod_map_keys).unwrap(), "`vmodmap` has an incorrect length" ); |
| 8496 | vmodmap.serialize_into(bytes); |
| 8497 | } |
| 8498 | } |
| 8499 | } |
| 8500 | impl SetMapAux { |
| 8501 | fn switch_expr(&self) -> u16 { |
| 8502 | let mut expr_value = 0; |
| 8503 | if self.types.is_some() { |
| 8504 | expr_value |= u16::from(MapPart::KEY_TYPES); |
| 8505 | } |
| 8506 | if self.syms.is_some() { |
| 8507 | expr_value |= u16::from(MapPart::KEY_SYMS); |
| 8508 | } |
| 8509 | if self.key_actions.is_some() { |
| 8510 | expr_value |= u16::from(MapPart::KEY_ACTIONS); |
| 8511 | } |
| 8512 | if self.behaviors.is_some() { |
| 8513 | expr_value |= u16::from(MapPart::KEY_BEHAVIORS); |
| 8514 | } |
| 8515 | if self.vmods.is_some() { |
| 8516 | expr_value |= u16::from(MapPart::VIRTUAL_MODS); |
| 8517 | } |
| 8518 | if self.explicit.is_some() { |
| 8519 | expr_value |= u16::from(MapPart::EXPLICIT_COMPONENTS); |
| 8520 | } |
| 8521 | if self.modmap.is_some() { |
| 8522 | expr_value |= u16::from(MapPart::MODIFIER_MAP); |
| 8523 | } |
| 8524 | if self.vmodmap.is_some() { |
| 8525 | expr_value |= u16::from(MapPart::VIRTUAL_MOD_MAP); |
| 8526 | } |
| 8527 | expr_value |
| 8528 | } |
| 8529 | } |
| 8530 | impl SetMapAux { |
| 8531 | /// Create a new instance with all fields unset / not present. |
| 8532 | pub fn new() -> Self { |
| 8533 | Default::default() |
| 8534 | } |
| 8535 | /// Set the `types` field of this structure. |
| 8536 | #[must_use ] |
| 8537 | pub fn types<I>(mut self, value: I) -> Self where I: Into<Option<Vec<SetKeyType>>> { |
| 8538 | self.types = value.into(); |
| 8539 | self |
| 8540 | } |
| 8541 | /// Set the `syms` field of this structure. |
| 8542 | #[must_use ] |
| 8543 | pub fn syms<I>(mut self, value: I) -> Self where I: Into<Option<Vec<KeySymMap>>> { |
| 8544 | self.syms = value.into(); |
| 8545 | self |
| 8546 | } |
| 8547 | /// Set the `key_actions` field of this structure. |
| 8548 | #[must_use ] |
| 8549 | pub fn key_actions<I>(mut self, value: I) -> Self where I: Into<Option<SetMapAuxKeyActions>> { |
| 8550 | self.key_actions = value.into(); |
| 8551 | self |
| 8552 | } |
| 8553 | /// Set the `behaviors` field of this structure. |
| 8554 | #[must_use ] |
| 8555 | pub fn behaviors<I>(mut self, value: I) -> Self where I: Into<Option<Vec<SetBehavior>>> { |
| 8556 | self.behaviors = value.into(); |
| 8557 | self |
| 8558 | } |
| 8559 | /// Set the `vmods` field of this structure. |
| 8560 | #[must_use ] |
| 8561 | pub fn vmods<I>(mut self, value: I) -> Self where I: Into<Option<Vec<u8>>> { |
| 8562 | self.vmods = value.into(); |
| 8563 | self |
| 8564 | } |
| 8565 | /// Set the `explicit` field of this structure. |
| 8566 | #[must_use ] |
| 8567 | pub fn explicit<I>(mut self, value: I) -> Self where I: Into<Option<Vec<SetExplicit>>> { |
| 8568 | self.explicit = value.into(); |
| 8569 | self |
| 8570 | } |
| 8571 | /// Set the `modmap` field of this structure. |
| 8572 | #[must_use ] |
| 8573 | pub fn modmap<I>(mut self, value: I) -> Self where I: Into<Option<Vec<KeyModMap>>> { |
| 8574 | self.modmap = value.into(); |
| 8575 | self |
| 8576 | } |
| 8577 | /// Set the `vmodmap` field of this structure. |
| 8578 | #[must_use ] |
| 8579 | pub fn vmodmap<I>(mut self, value: I) -> Self where I: Into<Option<Vec<KeyVModMap>>> { |
| 8580 | self.vmodmap = value.into(); |
| 8581 | self |
| 8582 | } |
| 8583 | } |
| 8584 | |
| 8585 | /// Opcode for the SetMap request |
| 8586 | pub const SET_MAP_REQUEST: u8 = 9; |
| 8587 | #[derive (Clone)] |
| 8588 | #[cfg_attr (feature = "extra-traits" , derive(Debug))] |
| 8589 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8590 | pub struct SetMapRequest<'input> { |
| 8591 | pub device_spec: DeviceSpec, |
| 8592 | pub flags: SetMapFlags, |
| 8593 | pub min_key_code: xproto::Keycode, |
| 8594 | pub max_key_code: xproto::Keycode, |
| 8595 | pub first_type: u8, |
| 8596 | pub n_types: u8, |
| 8597 | pub first_key_sym: xproto::Keycode, |
| 8598 | pub n_key_syms: u8, |
| 8599 | pub total_syms: u16, |
| 8600 | pub first_key_action: xproto::Keycode, |
| 8601 | pub n_key_actions: u8, |
| 8602 | pub total_actions: u16, |
| 8603 | pub first_key_behavior: xproto::Keycode, |
| 8604 | pub n_key_behaviors: u8, |
| 8605 | pub total_key_behaviors: u8, |
| 8606 | pub first_key_explicit: xproto::Keycode, |
| 8607 | pub n_key_explicit: u8, |
| 8608 | pub total_key_explicit: u8, |
| 8609 | pub first_mod_map_key: xproto::Keycode, |
| 8610 | pub n_mod_map_keys: u8, |
| 8611 | pub total_mod_map_keys: u8, |
| 8612 | pub first_v_mod_map_key: xproto::Keycode, |
| 8613 | pub n_v_mod_map_keys: u8, |
| 8614 | pub total_v_mod_map_keys: u8, |
| 8615 | pub virtual_mods: VMod, |
| 8616 | pub values: Cow<'input, SetMapAux>, |
| 8617 | } |
| 8618 | impl_debug_if_no_extra_traits!(SetMapRequest<'_>, "SetMapRequest" ); |
| 8619 | impl<'input> SetMapRequest<'input> { |
| 8620 | /// Serialize this request into bytes for the provided connection |
| 8621 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 8622 | let length_so_far = 0; |
| 8623 | let device_spec_bytes = self.device_spec.serialize(); |
| 8624 | let present: u16 = self.values.switch_expr(); |
| 8625 | let present_bytes = present.serialize(); |
| 8626 | let flags_bytes = u16::from(self.flags).serialize(); |
| 8627 | let min_key_code_bytes = self.min_key_code.serialize(); |
| 8628 | let max_key_code_bytes = self.max_key_code.serialize(); |
| 8629 | let first_type_bytes = self.first_type.serialize(); |
| 8630 | let n_types_bytes = self.n_types.serialize(); |
| 8631 | let first_key_sym_bytes = self.first_key_sym.serialize(); |
| 8632 | let n_key_syms_bytes = self.n_key_syms.serialize(); |
| 8633 | let total_syms_bytes = self.total_syms.serialize(); |
| 8634 | let first_key_action_bytes = self.first_key_action.serialize(); |
| 8635 | let n_key_actions_bytes = self.n_key_actions.serialize(); |
| 8636 | let total_actions_bytes = self.total_actions.serialize(); |
| 8637 | let first_key_behavior_bytes = self.first_key_behavior.serialize(); |
| 8638 | let n_key_behaviors_bytes = self.n_key_behaviors.serialize(); |
| 8639 | let total_key_behaviors_bytes = self.total_key_behaviors.serialize(); |
| 8640 | let first_key_explicit_bytes = self.first_key_explicit.serialize(); |
| 8641 | let n_key_explicit_bytes = self.n_key_explicit.serialize(); |
| 8642 | let total_key_explicit_bytes = self.total_key_explicit.serialize(); |
| 8643 | let first_mod_map_key_bytes = self.first_mod_map_key.serialize(); |
| 8644 | let n_mod_map_keys_bytes = self.n_mod_map_keys.serialize(); |
| 8645 | let total_mod_map_keys_bytes = self.total_mod_map_keys.serialize(); |
| 8646 | let first_v_mod_map_key_bytes = self.first_v_mod_map_key.serialize(); |
| 8647 | let n_v_mod_map_keys_bytes = self.n_v_mod_map_keys.serialize(); |
| 8648 | let total_v_mod_map_keys_bytes = self.total_v_mod_map_keys.serialize(); |
| 8649 | let virtual_mods_bytes = u16::from(self.virtual_mods).serialize(); |
| 8650 | let mut request0 = vec![ |
| 8651 | major_opcode, |
| 8652 | SET_MAP_REQUEST, |
| 8653 | 0, |
| 8654 | 0, |
| 8655 | device_spec_bytes[0], |
| 8656 | device_spec_bytes[1], |
| 8657 | present_bytes[0], |
| 8658 | present_bytes[1], |
| 8659 | flags_bytes[0], |
| 8660 | flags_bytes[1], |
| 8661 | min_key_code_bytes[0], |
| 8662 | max_key_code_bytes[0], |
| 8663 | first_type_bytes[0], |
| 8664 | n_types_bytes[0], |
| 8665 | first_key_sym_bytes[0], |
| 8666 | n_key_syms_bytes[0], |
| 8667 | total_syms_bytes[0], |
| 8668 | total_syms_bytes[1], |
| 8669 | first_key_action_bytes[0], |
| 8670 | n_key_actions_bytes[0], |
| 8671 | total_actions_bytes[0], |
| 8672 | total_actions_bytes[1], |
| 8673 | first_key_behavior_bytes[0], |
| 8674 | n_key_behaviors_bytes[0], |
| 8675 | total_key_behaviors_bytes[0], |
| 8676 | first_key_explicit_bytes[0], |
| 8677 | n_key_explicit_bytes[0], |
| 8678 | total_key_explicit_bytes[0], |
| 8679 | first_mod_map_key_bytes[0], |
| 8680 | n_mod_map_keys_bytes[0], |
| 8681 | total_mod_map_keys_bytes[0], |
| 8682 | first_v_mod_map_key_bytes[0], |
| 8683 | n_v_mod_map_keys_bytes[0], |
| 8684 | total_v_mod_map_keys_bytes[0], |
| 8685 | virtual_mods_bytes[0], |
| 8686 | virtual_mods_bytes[1], |
| 8687 | ]; |
| 8688 | let length_so_far = length_so_far + request0.len(); |
| 8689 | let values_bytes = self.values.serialize(u16::from(present), u8::from(self.n_types), u8::from(self.n_key_syms), u8::from(self.n_key_actions), u16::from(self.total_actions), u8::from(self.total_key_behaviors), u16::from(self.virtual_mods), u8::from(self.total_key_explicit), u8::from(self.total_mod_map_keys), u8::from(self.total_v_mod_map_keys)); |
| 8690 | let length_so_far = length_so_far + values_bytes.len(); |
| 8691 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 8692 | let length_so_far = length_so_far + padding0.len(); |
| 8693 | assert_eq!(length_so_far % 4, 0); |
| 8694 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 8695 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 8696 | ([request0.into(), values_bytes.into(), padding0.into()], vec![]) |
| 8697 | } |
| 8698 | /// Parse this request given its header, its body, and any fds that go along with it |
| 8699 | #[cfg (feature = "request-parsing" )] |
| 8700 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 8701 | if header.minor_opcode != SET_MAP_REQUEST { |
| 8702 | return Err(ParseError::InvalidValue); |
| 8703 | } |
| 8704 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 8705 | let (present, remaining) = u16::try_parse(remaining)?; |
| 8706 | let (flags, remaining) = u16::try_parse(remaining)?; |
| 8707 | let flags = flags.into(); |
| 8708 | let (min_key_code, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 8709 | let (max_key_code, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 8710 | let (first_type, remaining) = u8::try_parse(remaining)?; |
| 8711 | let (n_types, remaining) = u8::try_parse(remaining)?; |
| 8712 | let (first_key_sym, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 8713 | let (n_key_syms, remaining) = u8::try_parse(remaining)?; |
| 8714 | let (total_syms, remaining) = u16::try_parse(remaining)?; |
| 8715 | let (first_key_action, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 8716 | let (n_key_actions, remaining) = u8::try_parse(remaining)?; |
| 8717 | let (total_actions, remaining) = u16::try_parse(remaining)?; |
| 8718 | let (first_key_behavior, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 8719 | let (n_key_behaviors, remaining) = u8::try_parse(remaining)?; |
| 8720 | let (total_key_behaviors, remaining) = u8::try_parse(remaining)?; |
| 8721 | let (first_key_explicit, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 8722 | let (n_key_explicit, remaining) = u8::try_parse(remaining)?; |
| 8723 | let (total_key_explicit, remaining) = u8::try_parse(remaining)?; |
| 8724 | let (first_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 8725 | let (n_mod_map_keys, remaining) = u8::try_parse(remaining)?; |
| 8726 | let (total_mod_map_keys, remaining) = u8::try_parse(remaining)?; |
| 8727 | let (first_v_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 8728 | let (n_v_mod_map_keys, remaining) = u8::try_parse(remaining)?; |
| 8729 | let (total_v_mod_map_keys, remaining) = u8::try_parse(remaining)?; |
| 8730 | let (virtual_mods, remaining) = u16::try_parse(remaining)?; |
| 8731 | let virtual_mods = virtual_mods.into(); |
| 8732 | let (values, remaining) = SetMapAux::try_parse(remaining, u16::from(present), u8::from(n_types), u8::from(n_key_syms), u8::from(n_key_actions), u16::from(total_actions), u8::from(total_key_behaviors), u16::from(virtual_mods), u8::from(total_key_explicit), u8::from(total_mod_map_keys), u8::from(total_v_mod_map_keys))?; |
| 8733 | let _ = remaining; |
| 8734 | Ok(SetMapRequest { |
| 8735 | device_spec, |
| 8736 | flags, |
| 8737 | min_key_code, |
| 8738 | max_key_code, |
| 8739 | first_type, |
| 8740 | n_types, |
| 8741 | first_key_sym, |
| 8742 | n_key_syms, |
| 8743 | total_syms, |
| 8744 | first_key_action, |
| 8745 | n_key_actions, |
| 8746 | total_actions, |
| 8747 | first_key_behavior, |
| 8748 | n_key_behaviors, |
| 8749 | total_key_behaviors, |
| 8750 | first_key_explicit, |
| 8751 | n_key_explicit, |
| 8752 | total_key_explicit, |
| 8753 | first_mod_map_key, |
| 8754 | n_mod_map_keys, |
| 8755 | total_mod_map_keys, |
| 8756 | first_v_mod_map_key, |
| 8757 | n_v_mod_map_keys, |
| 8758 | total_v_mod_map_keys, |
| 8759 | virtual_mods, |
| 8760 | values: Cow::Owned(values), |
| 8761 | }) |
| 8762 | } |
| 8763 | /// Clone all borrowed data in this SetMapRequest. |
| 8764 | pub fn into_owned(self) -> SetMapRequest<'static> { |
| 8765 | SetMapRequest { |
| 8766 | device_spec: self.device_spec, |
| 8767 | flags: self.flags, |
| 8768 | min_key_code: self.min_key_code, |
| 8769 | max_key_code: self.max_key_code, |
| 8770 | first_type: self.first_type, |
| 8771 | n_types: self.n_types, |
| 8772 | first_key_sym: self.first_key_sym, |
| 8773 | n_key_syms: self.n_key_syms, |
| 8774 | total_syms: self.total_syms, |
| 8775 | first_key_action: self.first_key_action, |
| 8776 | n_key_actions: self.n_key_actions, |
| 8777 | total_actions: self.total_actions, |
| 8778 | first_key_behavior: self.first_key_behavior, |
| 8779 | n_key_behaviors: self.n_key_behaviors, |
| 8780 | total_key_behaviors: self.total_key_behaviors, |
| 8781 | first_key_explicit: self.first_key_explicit, |
| 8782 | n_key_explicit: self.n_key_explicit, |
| 8783 | total_key_explicit: self.total_key_explicit, |
| 8784 | first_mod_map_key: self.first_mod_map_key, |
| 8785 | n_mod_map_keys: self.n_mod_map_keys, |
| 8786 | total_mod_map_keys: self.total_mod_map_keys, |
| 8787 | first_v_mod_map_key: self.first_v_mod_map_key, |
| 8788 | n_v_mod_map_keys: self.n_v_mod_map_keys, |
| 8789 | total_v_mod_map_keys: self.total_v_mod_map_keys, |
| 8790 | virtual_mods: self.virtual_mods, |
| 8791 | values: Cow::Owned(self.values.into_owned()), |
| 8792 | } |
| 8793 | } |
| 8794 | } |
| 8795 | impl<'input> Request for SetMapRequest<'input> { |
| 8796 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 8797 | |
| 8798 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 8799 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(major_opcode); |
| 8800 | // Flatten the buffers into a single vector |
| 8801 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 8802 | (buf, fds) |
| 8803 | } |
| 8804 | } |
| 8805 | impl<'input> crate::x11_utils::VoidRequest for SetMapRequest<'input> { |
| 8806 | } |
| 8807 | |
| 8808 | /// Opcode for the GetCompatMap request |
| 8809 | pub const GET_COMPAT_MAP_REQUEST: u8 = 10; |
| 8810 | #[derive (Clone, Copy, Default)] |
| 8811 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 8812 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8813 | pub struct GetCompatMapRequest { |
| 8814 | pub device_spec: DeviceSpec, |
| 8815 | pub groups: SetOfGroup, |
| 8816 | pub get_all_si: bool, |
| 8817 | pub first_si: u16, |
| 8818 | pub n_si: u16, |
| 8819 | } |
| 8820 | impl_debug_if_no_extra_traits!(GetCompatMapRequest, "GetCompatMapRequest" ); |
| 8821 | impl GetCompatMapRequest { |
| 8822 | /// Serialize this request into bytes for the provided connection |
| 8823 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 8824 | let length_so_far = 0; |
| 8825 | let device_spec_bytes = self.device_spec.serialize(); |
| 8826 | let groups_bytes = u8::from(self.groups).serialize(); |
| 8827 | let get_all_si_bytes = self.get_all_si.serialize(); |
| 8828 | let first_si_bytes = self.first_si.serialize(); |
| 8829 | let n_si_bytes = self.n_si.serialize(); |
| 8830 | let mut request0 = vec![ |
| 8831 | major_opcode, |
| 8832 | GET_COMPAT_MAP_REQUEST, |
| 8833 | 0, |
| 8834 | 0, |
| 8835 | device_spec_bytes[0], |
| 8836 | device_spec_bytes[1], |
| 8837 | groups_bytes[0], |
| 8838 | get_all_si_bytes[0], |
| 8839 | first_si_bytes[0], |
| 8840 | first_si_bytes[1], |
| 8841 | n_si_bytes[0], |
| 8842 | n_si_bytes[1], |
| 8843 | ]; |
| 8844 | let length_so_far = length_so_far + request0.len(); |
| 8845 | assert_eq!(length_so_far % 4, 0); |
| 8846 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 8847 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 8848 | ([request0.into()], vec![]) |
| 8849 | } |
| 8850 | /// Parse this request given its header, its body, and any fds that go along with it |
| 8851 | #[cfg (feature = "request-parsing" )] |
| 8852 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 8853 | if header.minor_opcode != GET_COMPAT_MAP_REQUEST { |
| 8854 | return Err(ParseError::InvalidValue); |
| 8855 | } |
| 8856 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 8857 | let (groups, remaining) = u8::try_parse(remaining)?; |
| 8858 | let groups = groups.into(); |
| 8859 | let (get_all_si, remaining) = bool::try_parse(remaining)?; |
| 8860 | let (first_si, remaining) = u16::try_parse(remaining)?; |
| 8861 | let (n_si, remaining) = u16::try_parse(remaining)?; |
| 8862 | let _ = remaining; |
| 8863 | Ok(GetCompatMapRequest { |
| 8864 | device_spec, |
| 8865 | groups, |
| 8866 | get_all_si, |
| 8867 | first_si, |
| 8868 | n_si, |
| 8869 | }) |
| 8870 | } |
| 8871 | } |
| 8872 | impl Request for GetCompatMapRequest { |
| 8873 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 8874 | |
| 8875 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 8876 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 8877 | // Flatten the buffers into a single vector |
| 8878 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 8879 | (buf, fds) |
| 8880 | } |
| 8881 | } |
| 8882 | impl crate::x11_utils::ReplyRequest for GetCompatMapRequest { |
| 8883 | type Reply = GetCompatMapReply; |
| 8884 | } |
| 8885 | |
| 8886 | #[derive (Clone, Default)] |
| 8887 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 8888 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8889 | pub struct GetCompatMapReply { |
| 8890 | pub device_id: u8, |
| 8891 | pub sequence: u16, |
| 8892 | pub length: u32, |
| 8893 | pub groups_rtrn: SetOfGroup, |
| 8894 | pub first_si_rtrn: u16, |
| 8895 | pub n_total_si: u16, |
| 8896 | pub si_rtrn: Vec<SymInterpret>, |
| 8897 | pub group_rtrn: Vec<ModDef>, |
| 8898 | } |
| 8899 | impl_debug_if_no_extra_traits!(GetCompatMapReply, "GetCompatMapReply" ); |
| 8900 | impl TryParse for GetCompatMapReply { |
| 8901 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 8902 | let remaining = initial_value; |
| 8903 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 8904 | let (device_id, remaining) = u8::try_parse(remaining)?; |
| 8905 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 8906 | let (length, remaining) = u32::try_parse(remaining)?; |
| 8907 | let (groups_rtrn, remaining) = u8::try_parse(remaining)?; |
| 8908 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 8909 | let (first_si_rtrn, remaining) = u16::try_parse(remaining)?; |
| 8910 | let (n_si_rtrn, remaining) = u16::try_parse(remaining)?; |
| 8911 | let (n_total_si, remaining) = u16::try_parse(remaining)?; |
| 8912 | let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?; |
| 8913 | let (si_rtrn, remaining) = crate::x11_utils::parse_list::<SymInterpret>(remaining, n_si_rtrn.try_to_usize()?)?; |
| 8914 | let (group_rtrn, remaining) = crate::x11_utils::parse_list::<ModDef>(remaining, u32::from(groups_rtrn).count_ones().try_to_usize()?)?; |
| 8915 | if response_type != 1 { |
| 8916 | return Err(ParseError::InvalidValue); |
| 8917 | } |
| 8918 | let groups_rtrn = groups_rtrn.into(); |
| 8919 | let result = GetCompatMapReply { device_id, sequence, length, groups_rtrn, first_si_rtrn, n_total_si, si_rtrn, group_rtrn }; |
| 8920 | let _ = remaining; |
| 8921 | let remaining = initial_value.get(32 + length as usize * 4..) |
| 8922 | .ok_or(ParseError::InsufficientData)?; |
| 8923 | Ok((result, remaining)) |
| 8924 | } |
| 8925 | } |
| 8926 | impl Serialize for GetCompatMapReply { |
| 8927 | type Bytes = Vec<u8>; |
| 8928 | fn serialize(&self) -> Vec<u8> { |
| 8929 | let mut result = Vec::new(); |
| 8930 | self.serialize_into(&mut result); |
| 8931 | result |
| 8932 | } |
| 8933 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 8934 | bytes.reserve(32); |
| 8935 | let response_type_bytes = &[1]; |
| 8936 | bytes.push(response_type_bytes[0]); |
| 8937 | self.device_id.serialize_into(bytes); |
| 8938 | self.sequence.serialize_into(bytes); |
| 8939 | self.length.serialize_into(bytes); |
| 8940 | u8::from(self.groups_rtrn).serialize_into(bytes); |
| 8941 | bytes.extend_from_slice(&[0; 1]); |
| 8942 | self.first_si_rtrn.serialize_into(bytes); |
| 8943 | let n_si_rtrn = u16::try_from(self.si_rtrn.len()).expect("`si_rtrn` has too many elements" ); |
| 8944 | n_si_rtrn.serialize_into(bytes); |
| 8945 | self.n_total_si.serialize_into(bytes); |
| 8946 | bytes.extend_from_slice(&[0; 16]); |
| 8947 | self.si_rtrn.serialize_into(bytes); |
| 8948 | assert_eq!(self.group_rtrn.len(), usize::try_from(u32::from(self.groups_rtrn).count_ones()).unwrap(), "`group_rtrn` has an incorrect length" ); |
| 8949 | self.group_rtrn.serialize_into(bytes); |
| 8950 | } |
| 8951 | } |
| 8952 | impl GetCompatMapReply { |
| 8953 | /// Get the value of the `nSIRtrn` field. |
| 8954 | /// |
| 8955 | /// The `nSIRtrn` field is used as the length field of the `si_rtrn` field. |
| 8956 | /// This function computes the field's value again based on the length of the list. |
| 8957 | /// |
| 8958 | /// # Panics |
| 8959 | /// |
| 8960 | /// Panics if the value cannot be represented in the target type. This |
| 8961 | /// cannot happen with values of the struct received from the X11 server. |
| 8962 | pub fn n_si_rtrn(&self) -> u16 { |
| 8963 | self.si_rtrn.len() |
| 8964 | .try_into().unwrap() |
| 8965 | } |
| 8966 | } |
| 8967 | |
| 8968 | /// Opcode for the SetCompatMap request |
| 8969 | pub const SET_COMPAT_MAP_REQUEST: u8 = 11; |
| 8970 | #[derive (Clone, Default)] |
| 8971 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 8972 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 8973 | pub struct SetCompatMapRequest<'input> { |
| 8974 | pub device_spec: DeviceSpec, |
| 8975 | pub recompute_actions: bool, |
| 8976 | pub truncate_si: bool, |
| 8977 | pub groups: SetOfGroup, |
| 8978 | pub first_si: u16, |
| 8979 | pub si: Cow<'input, [SymInterpret]>, |
| 8980 | pub group_maps: Cow<'input, [ModDef]>, |
| 8981 | } |
| 8982 | impl_debug_if_no_extra_traits!(SetCompatMapRequest<'_>, "SetCompatMapRequest" ); |
| 8983 | impl<'input> SetCompatMapRequest<'input> { |
| 8984 | /// Serialize this request into bytes for the provided connection |
| 8985 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 4]> { |
| 8986 | let length_so_far = 0; |
| 8987 | let device_spec_bytes = self.device_spec.serialize(); |
| 8988 | let recompute_actions_bytes = self.recompute_actions.serialize(); |
| 8989 | let truncate_si_bytes = self.truncate_si.serialize(); |
| 8990 | let groups_bytes = u8::from(self.groups).serialize(); |
| 8991 | let first_si_bytes = self.first_si.serialize(); |
| 8992 | let n_si = u16::try_from(self.si.len()).expect("`si` has too many elements" ); |
| 8993 | let n_si_bytes = n_si.serialize(); |
| 8994 | let mut request0 = vec![ |
| 8995 | major_opcode, |
| 8996 | SET_COMPAT_MAP_REQUEST, |
| 8997 | 0, |
| 8998 | 0, |
| 8999 | device_spec_bytes[0], |
| 9000 | device_spec_bytes[1], |
| 9001 | 0, |
| 9002 | recompute_actions_bytes[0], |
| 9003 | truncate_si_bytes[0], |
| 9004 | groups_bytes[0], |
| 9005 | first_si_bytes[0], |
| 9006 | first_si_bytes[1], |
| 9007 | n_si_bytes[0], |
| 9008 | n_si_bytes[1], |
| 9009 | 0, |
| 9010 | 0, |
| 9011 | ]; |
| 9012 | let length_so_far = length_so_far + request0.len(); |
| 9013 | let si_bytes = self.si.serialize(); |
| 9014 | let length_so_far = length_so_far + si_bytes.len(); |
| 9015 | assert_eq!(self.group_maps.len(), usize::try_from(u32::from(self.groups).count_ones()).unwrap(), "`group_maps` has an incorrect length" ); |
| 9016 | let group_maps_bytes = self.group_maps.serialize(); |
| 9017 | let length_so_far = length_so_far + group_maps_bytes.len(); |
| 9018 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 9019 | let length_so_far = length_so_far + padding0.len(); |
| 9020 | assert_eq!(length_so_far % 4, 0); |
| 9021 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 9022 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 9023 | ([request0.into(), si_bytes.into(), group_maps_bytes.into(), padding0.into()], vec![]) |
| 9024 | } |
| 9025 | /// Parse this request given its header, its body, and any fds that go along with it |
| 9026 | #[cfg (feature = "request-parsing" )] |
| 9027 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 9028 | if header.minor_opcode != SET_COMPAT_MAP_REQUEST { |
| 9029 | return Err(ParseError::InvalidValue); |
| 9030 | } |
| 9031 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 9032 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 9033 | let (recompute_actions, remaining) = bool::try_parse(remaining)?; |
| 9034 | let (truncate_si, remaining) = bool::try_parse(remaining)?; |
| 9035 | let (groups, remaining) = u8::try_parse(remaining)?; |
| 9036 | let groups = groups.into(); |
| 9037 | let (first_si, remaining) = u16::try_parse(remaining)?; |
| 9038 | let (n_si, remaining) = u16::try_parse(remaining)?; |
| 9039 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 9040 | let (si, remaining) = crate::x11_utils::parse_list::<SymInterpret>(remaining, n_si.try_to_usize()?)?; |
| 9041 | let (group_maps, remaining) = crate::x11_utils::parse_list::<ModDef>(remaining, u32::from(groups).count_ones().try_to_usize()?)?; |
| 9042 | let _ = remaining; |
| 9043 | Ok(SetCompatMapRequest { |
| 9044 | device_spec, |
| 9045 | recompute_actions, |
| 9046 | truncate_si, |
| 9047 | groups, |
| 9048 | first_si, |
| 9049 | si: Cow::Owned(si), |
| 9050 | group_maps: Cow::Owned(group_maps), |
| 9051 | }) |
| 9052 | } |
| 9053 | /// Clone all borrowed data in this SetCompatMapRequest. |
| 9054 | pub fn into_owned(self) -> SetCompatMapRequest<'static> { |
| 9055 | SetCompatMapRequest { |
| 9056 | device_spec: self.device_spec, |
| 9057 | recompute_actions: self.recompute_actions, |
| 9058 | truncate_si: self.truncate_si, |
| 9059 | groups: self.groups, |
| 9060 | first_si: self.first_si, |
| 9061 | si: Cow::Owned(self.si.into_owned()), |
| 9062 | group_maps: Cow::Owned(self.group_maps.into_owned()), |
| 9063 | } |
| 9064 | } |
| 9065 | } |
| 9066 | impl<'input> Request for SetCompatMapRequest<'input> { |
| 9067 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 9068 | |
| 9069 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 9070 | let (bufs: [Cow<'_, [u8]>; 4], fds: Vec) = self.serialize(major_opcode); |
| 9071 | // Flatten the buffers into a single vector |
| 9072 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 9073 | (buf, fds) |
| 9074 | } |
| 9075 | } |
| 9076 | impl<'input> crate::x11_utils::VoidRequest for SetCompatMapRequest<'input> { |
| 9077 | } |
| 9078 | |
| 9079 | /// Opcode for the GetIndicatorState request |
| 9080 | pub const GET_INDICATOR_STATE_REQUEST: u8 = 12; |
| 9081 | #[derive (Clone, Copy, Default)] |
| 9082 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9083 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9084 | pub struct GetIndicatorStateRequest { |
| 9085 | pub device_spec: DeviceSpec, |
| 9086 | } |
| 9087 | impl_debug_if_no_extra_traits!(GetIndicatorStateRequest, "GetIndicatorStateRequest" ); |
| 9088 | impl GetIndicatorStateRequest { |
| 9089 | /// Serialize this request into bytes for the provided connection |
| 9090 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 9091 | let length_so_far = 0; |
| 9092 | let device_spec_bytes = self.device_spec.serialize(); |
| 9093 | let mut request0 = vec![ |
| 9094 | major_opcode, |
| 9095 | GET_INDICATOR_STATE_REQUEST, |
| 9096 | 0, |
| 9097 | 0, |
| 9098 | device_spec_bytes[0], |
| 9099 | device_spec_bytes[1], |
| 9100 | 0, |
| 9101 | 0, |
| 9102 | ]; |
| 9103 | let length_so_far = length_so_far + request0.len(); |
| 9104 | assert_eq!(length_so_far % 4, 0); |
| 9105 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 9106 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 9107 | ([request0.into()], vec![]) |
| 9108 | } |
| 9109 | /// Parse this request given its header, its body, and any fds that go along with it |
| 9110 | #[cfg (feature = "request-parsing" )] |
| 9111 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 9112 | if header.minor_opcode != GET_INDICATOR_STATE_REQUEST { |
| 9113 | return Err(ParseError::InvalidValue); |
| 9114 | } |
| 9115 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 9116 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 9117 | let _ = remaining; |
| 9118 | Ok(GetIndicatorStateRequest { |
| 9119 | device_spec, |
| 9120 | }) |
| 9121 | } |
| 9122 | } |
| 9123 | impl Request for GetIndicatorStateRequest { |
| 9124 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 9125 | |
| 9126 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 9127 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 9128 | // Flatten the buffers into a single vector |
| 9129 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 9130 | (buf, fds) |
| 9131 | } |
| 9132 | } |
| 9133 | impl crate::x11_utils::ReplyRequest for GetIndicatorStateRequest { |
| 9134 | type Reply = GetIndicatorStateReply; |
| 9135 | } |
| 9136 | |
| 9137 | #[derive (Clone, Copy, Default)] |
| 9138 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9139 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9140 | pub struct GetIndicatorStateReply { |
| 9141 | pub device_id: u8, |
| 9142 | pub sequence: u16, |
| 9143 | pub length: u32, |
| 9144 | pub state: u32, |
| 9145 | } |
| 9146 | impl_debug_if_no_extra_traits!(GetIndicatorStateReply, "GetIndicatorStateReply" ); |
| 9147 | impl TryParse for GetIndicatorStateReply { |
| 9148 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 9149 | let remaining: &[u8] = initial_value; |
| 9150 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 9151 | let (device_id: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 9152 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 9153 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 9154 | let (state: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 9155 | let remaining: &[u8] = remaining.get(20..).ok_or(err:ParseError::InsufficientData)?; |
| 9156 | if response_type != 1 { |
| 9157 | return Err(ParseError::InvalidValue); |
| 9158 | } |
| 9159 | let result: GetIndicatorStateReply = GetIndicatorStateReply { device_id, sequence, length, state }; |
| 9160 | let _ = remaining; |
| 9161 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 9162 | .ok_or(err:ParseError::InsufficientData)?; |
| 9163 | Ok((result, remaining)) |
| 9164 | } |
| 9165 | } |
| 9166 | impl Serialize for GetIndicatorStateReply { |
| 9167 | type Bytes = [u8; 32]; |
| 9168 | fn serialize(&self) -> [u8; 32] { |
| 9169 | let response_type_bytes = &[1]; |
| 9170 | let device_id_bytes = self.device_id.serialize(); |
| 9171 | let sequence_bytes = self.sequence.serialize(); |
| 9172 | let length_bytes = self.length.serialize(); |
| 9173 | let state_bytes = self.state.serialize(); |
| 9174 | [ |
| 9175 | response_type_bytes[0], |
| 9176 | device_id_bytes[0], |
| 9177 | sequence_bytes[0], |
| 9178 | sequence_bytes[1], |
| 9179 | length_bytes[0], |
| 9180 | length_bytes[1], |
| 9181 | length_bytes[2], |
| 9182 | length_bytes[3], |
| 9183 | state_bytes[0], |
| 9184 | state_bytes[1], |
| 9185 | state_bytes[2], |
| 9186 | state_bytes[3], |
| 9187 | 0, |
| 9188 | 0, |
| 9189 | 0, |
| 9190 | 0, |
| 9191 | 0, |
| 9192 | 0, |
| 9193 | 0, |
| 9194 | 0, |
| 9195 | 0, |
| 9196 | 0, |
| 9197 | 0, |
| 9198 | 0, |
| 9199 | 0, |
| 9200 | 0, |
| 9201 | 0, |
| 9202 | 0, |
| 9203 | 0, |
| 9204 | 0, |
| 9205 | 0, |
| 9206 | 0, |
| 9207 | ] |
| 9208 | } |
| 9209 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 9210 | bytes.reserve(32); |
| 9211 | let response_type_bytes = &[1]; |
| 9212 | bytes.push(response_type_bytes[0]); |
| 9213 | self.device_id.serialize_into(bytes); |
| 9214 | self.sequence.serialize_into(bytes); |
| 9215 | self.length.serialize_into(bytes); |
| 9216 | self.state.serialize_into(bytes); |
| 9217 | bytes.extend_from_slice(&[0; 20]); |
| 9218 | } |
| 9219 | } |
| 9220 | |
| 9221 | /// Opcode for the GetIndicatorMap request |
| 9222 | pub const GET_INDICATOR_MAP_REQUEST: u8 = 13; |
| 9223 | #[derive (Clone, Copy, Default)] |
| 9224 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9225 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9226 | pub struct GetIndicatorMapRequest { |
| 9227 | pub device_spec: DeviceSpec, |
| 9228 | pub which: u32, |
| 9229 | } |
| 9230 | impl_debug_if_no_extra_traits!(GetIndicatorMapRequest, "GetIndicatorMapRequest" ); |
| 9231 | impl GetIndicatorMapRequest { |
| 9232 | /// Serialize this request into bytes for the provided connection |
| 9233 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 9234 | let length_so_far = 0; |
| 9235 | let device_spec_bytes = self.device_spec.serialize(); |
| 9236 | let which_bytes = self.which.serialize(); |
| 9237 | let mut request0 = vec![ |
| 9238 | major_opcode, |
| 9239 | GET_INDICATOR_MAP_REQUEST, |
| 9240 | 0, |
| 9241 | 0, |
| 9242 | device_spec_bytes[0], |
| 9243 | device_spec_bytes[1], |
| 9244 | 0, |
| 9245 | 0, |
| 9246 | which_bytes[0], |
| 9247 | which_bytes[1], |
| 9248 | which_bytes[2], |
| 9249 | which_bytes[3], |
| 9250 | ]; |
| 9251 | let length_so_far = length_so_far + request0.len(); |
| 9252 | assert_eq!(length_so_far % 4, 0); |
| 9253 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 9254 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 9255 | ([request0.into()], vec![]) |
| 9256 | } |
| 9257 | /// Parse this request given its header, its body, and any fds that go along with it |
| 9258 | #[cfg (feature = "request-parsing" )] |
| 9259 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 9260 | if header.minor_opcode != GET_INDICATOR_MAP_REQUEST { |
| 9261 | return Err(ParseError::InvalidValue); |
| 9262 | } |
| 9263 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 9264 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 9265 | let (which, remaining) = u32::try_parse(remaining)?; |
| 9266 | let _ = remaining; |
| 9267 | Ok(GetIndicatorMapRequest { |
| 9268 | device_spec, |
| 9269 | which, |
| 9270 | }) |
| 9271 | } |
| 9272 | } |
| 9273 | impl Request for GetIndicatorMapRequest { |
| 9274 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 9275 | |
| 9276 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 9277 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 9278 | // Flatten the buffers into a single vector |
| 9279 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 9280 | (buf, fds) |
| 9281 | } |
| 9282 | } |
| 9283 | impl crate::x11_utils::ReplyRequest for GetIndicatorMapRequest { |
| 9284 | type Reply = GetIndicatorMapReply; |
| 9285 | } |
| 9286 | |
| 9287 | #[derive (Clone, Default)] |
| 9288 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9289 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9290 | pub struct GetIndicatorMapReply { |
| 9291 | pub device_id: u8, |
| 9292 | pub sequence: u16, |
| 9293 | pub length: u32, |
| 9294 | pub which: u32, |
| 9295 | pub real_indicators: u32, |
| 9296 | pub n_indicators: u8, |
| 9297 | pub maps: Vec<IndicatorMap>, |
| 9298 | } |
| 9299 | impl_debug_if_no_extra_traits!(GetIndicatorMapReply, "GetIndicatorMapReply" ); |
| 9300 | impl TryParse for GetIndicatorMapReply { |
| 9301 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 9302 | let remaining: &[u8] = initial_value; |
| 9303 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 9304 | let (device_id: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 9305 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 9306 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 9307 | let (which: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 9308 | let (real_indicators: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 9309 | let (n_indicators: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 9310 | let remaining: &[u8] = remaining.get(15..).ok_or(err:ParseError::InsufficientData)?; |
| 9311 | let (maps: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<IndicatorMap>(data:remaining, list_length:u32::from(which).count_ones().try_to_usize()?)?; |
| 9312 | if response_type != 1 { |
| 9313 | return Err(ParseError::InvalidValue); |
| 9314 | } |
| 9315 | let result: GetIndicatorMapReply = GetIndicatorMapReply { device_id, sequence, length, which, real_indicators, n_indicators, maps }; |
| 9316 | let _ = remaining; |
| 9317 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 9318 | .ok_or(err:ParseError::InsufficientData)?; |
| 9319 | Ok((result, remaining)) |
| 9320 | } |
| 9321 | } |
| 9322 | impl Serialize for GetIndicatorMapReply { |
| 9323 | type Bytes = Vec<u8>; |
| 9324 | fn serialize(&self) -> Vec<u8> { |
| 9325 | let mut result: Vec = Vec::new(); |
| 9326 | self.serialize_into(&mut result); |
| 9327 | result |
| 9328 | } |
| 9329 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 9330 | bytes.reserve(additional:32); |
| 9331 | let response_type_bytes: &[u8; 1] = &[1]; |
| 9332 | bytes.push(response_type_bytes[0]); |
| 9333 | self.device_id.serialize_into(bytes); |
| 9334 | self.sequence.serialize_into(bytes); |
| 9335 | self.length.serialize_into(bytes); |
| 9336 | self.which.serialize_into(bytes); |
| 9337 | self.real_indicators.serialize_into(bytes); |
| 9338 | self.n_indicators.serialize_into(bytes); |
| 9339 | bytes.extend_from_slice(&[0; 15]); |
| 9340 | assert_eq!(self.maps.len(), usize::try_from(u32::from(self.which).count_ones()).unwrap(), "`maps` has an incorrect length" ); |
| 9341 | self.maps.serialize_into(bytes); |
| 9342 | } |
| 9343 | } |
| 9344 | |
| 9345 | /// Opcode for the SetIndicatorMap request |
| 9346 | pub const SET_INDICATOR_MAP_REQUEST: u8 = 14; |
| 9347 | #[derive (Clone, Default)] |
| 9348 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9349 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9350 | pub struct SetIndicatorMapRequest<'input> { |
| 9351 | pub device_spec: DeviceSpec, |
| 9352 | pub which: u32, |
| 9353 | pub maps: Cow<'input, [IndicatorMap]>, |
| 9354 | } |
| 9355 | impl_debug_if_no_extra_traits!(SetIndicatorMapRequest<'_>, "SetIndicatorMapRequest" ); |
| 9356 | impl<'input> SetIndicatorMapRequest<'input> { |
| 9357 | /// Serialize this request into bytes for the provided connection |
| 9358 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 9359 | let length_so_far = 0; |
| 9360 | let device_spec_bytes = self.device_spec.serialize(); |
| 9361 | let which_bytes = self.which.serialize(); |
| 9362 | let mut request0 = vec![ |
| 9363 | major_opcode, |
| 9364 | SET_INDICATOR_MAP_REQUEST, |
| 9365 | 0, |
| 9366 | 0, |
| 9367 | device_spec_bytes[0], |
| 9368 | device_spec_bytes[1], |
| 9369 | 0, |
| 9370 | 0, |
| 9371 | which_bytes[0], |
| 9372 | which_bytes[1], |
| 9373 | which_bytes[2], |
| 9374 | which_bytes[3], |
| 9375 | ]; |
| 9376 | let length_so_far = length_so_far + request0.len(); |
| 9377 | assert_eq!(self.maps.len(), usize::try_from(u32::from(self.which).count_ones()).unwrap(), "`maps` has an incorrect length" ); |
| 9378 | let maps_bytes = self.maps.serialize(); |
| 9379 | let length_so_far = length_so_far + maps_bytes.len(); |
| 9380 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 9381 | let length_so_far = length_so_far + padding0.len(); |
| 9382 | assert_eq!(length_so_far % 4, 0); |
| 9383 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 9384 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 9385 | ([request0.into(), maps_bytes.into(), padding0.into()], vec![]) |
| 9386 | } |
| 9387 | /// Parse this request given its header, its body, and any fds that go along with it |
| 9388 | #[cfg (feature = "request-parsing" )] |
| 9389 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 9390 | if header.minor_opcode != SET_INDICATOR_MAP_REQUEST { |
| 9391 | return Err(ParseError::InvalidValue); |
| 9392 | } |
| 9393 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 9394 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 9395 | let (which, remaining) = u32::try_parse(remaining)?; |
| 9396 | let (maps, remaining) = crate::x11_utils::parse_list::<IndicatorMap>(remaining, u32::from(which).count_ones().try_to_usize()?)?; |
| 9397 | let _ = remaining; |
| 9398 | Ok(SetIndicatorMapRequest { |
| 9399 | device_spec, |
| 9400 | which, |
| 9401 | maps: Cow::Owned(maps), |
| 9402 | }) |
| 9403 | } |
| 9404 | /// Clone all borrowed data in this SetIndicatorMapRequest. |
| 9405 | pub fn into_owned(self) -> SetIndicatorMapRequest<'static> { |
| 9406 | SetIndicatorMapRequest { |
| 9407 | device_spec: self.device_spec, |
| 9408 | which: self.which, |
| 9409 | maps: Cow::Owned(self.maps.into_owned()), |
| 9410 | } |
| 9411 | } |
| 9412 | } |
| 9413 | impl<'input> Request for SetIndicatorMapRequest<'input> { |
| 9414 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 9415 | |
| 9416 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 9417 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(major_opcode); |
| 9418 | // Flatten the buffers into a single vector |
| 9419 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 9420 | (buf, fds) |
| 9421 | } |
| 9422 | } |
| 9423 | impl<'input> crate::x11_utils::VoidRequest for SetIndicatorMapRequest<'input> { |
| 9424 | } |
| 9425 | |
| 9426 | /// Opcode for the GetNamedIndicator request |
| 9427 | pub const GET_NAMED_INDICATOR_REQUEST: u8 = 15; |
| 9428 | #[derive (Clone, Copy, Default)] |
| 9429 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9430 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9431 | pub struct GetNamedIndicatorRequest { |
| 9432 | pub device_spec: DeviceSpec, |
| 9433 | pub led_class: LedClass, |
| 9434 | pub led_id: IDSpec, |
| 9435 | pub indicator: xproto::Atom, |
| 9436 | } |
| 9437 | impl_debug_if_no_extra_traits!(GetNamedIndicatorRequest, "GetNamedIndicatorRequest" ); |
| 9438 | impl GetNamedIndicatorRequest { |
| 9439 | /// Serialize this request into bytes for the provided connection |
| 9440 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 9441 | let length_so_far = 0; |
| 9442 | let device_spec_bytes = self.device_spec.serialize(); |
| 9443 | let led_class_bytes = LedClassSpec::from(self.led_class).serialize(); |
| 9444 | let led_id_bytes = self.led_id.serialize(); |
| 9445 | let indicator_bytes = self.indicator.serialize(); |
| 9446 | let mut request0 = vec![ |
| 9447 | major_opcode, |
| 9448 | GET_NAMED_INDICATOR_REQUEST, |
| 9449 | 0, |
| 9450 | 0, |
| 9451 | device_spec_bytes[0], |
| 9452 | device_spec_bytes[1], |
| 9453 | led_class_bytes[0], |
| 9454 | led_class_bytes[1], |
| 9455 | led_id_bytes[0], |
| 9456 | led_id_bytes[1], |
| 9457 | 0, |
| 9458 | 0, |
| 9459 | indicator_bytes[0], |
| 9460 | indicator_bytes[1], |
| 9461 | indicator_bytes[2], |
| 9462 | indicator_bytes[3], |
| 9463 | ]; |
| 9464 | let length_so_far = length_so_far + request0.len(); |
| 9465 | assert_eq!(length_so_far % 4, 0); |
| 9466 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 9467 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 9468 | ([request0.into()], vec![]) |
| 9469 | } |
| 9470 | /// Parse this request given its header, its body, and any fds that go along with it |
| 9471 | #[cfg (feature = "request-parsing" )] |
| 9472 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 9473 | if header.minor_opcode != GET_NAMED_INDICATOR_REQUEST { |
| 9474 | return Err(ParseError::InvalidValue); |
| 9475 | } |
| 9476 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 9477 | let (led_class, remaining) = LedClassSpec::try_parse(remaining)?; |
| 9478 | let led_class = led_class.into(); |
| 9479 | let (led_id, remaining) = IDSpec::try_parse(remaining)?; |
| 9480 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 9481 | let (indicator, remaining) = xproto::Atom::try_parse(remaining)?; |
| 9482 | let _ = remaining; |
| 9483 | Ok(GetNamedIndicatorRequest { |
| 9484 | device_spec, |
| 9485 | led_class, |
| 9486 | led_id, |
| 9487 | indicator, |
| 9488 | }) |
| 9489 | } |
| 9490 | } |
| 9491 | impl Request for GetNamedIndicatorRequest { |
| 9492 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 9493 | |
| 9494 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 9495 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 9496 | // Flatten the buffers into a single vector |
| 9497 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 9498 | (buf, fds) |
| 9499 | } |
| 9500 | } |
| 9501 | impl crate::x11_utils::ReplyRequest for GetNamedIndicatorRequest { |
| 9502 | type Reply = GetNamedIndicatorReply; |
| 9503 | } |
| 9504 | |
| 9505 | #[derive (Clone, Copy, Default)] |
| 9506 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9507 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9508 | pub struct GetNamedIndicatorReply { |
| 9509 | pub device_id: u8, |
| 9510 | pub sequence: u16, |
| 9511 | pub length: u32, |
| 9512 | pub indicator: xproto::Atom, |
| 9513 | pub found: bool, |
| 9514 | pub on: bool, |
| 9515 | pub real_indicator: bool, |
| 9516 | pub ndx: u8, |
| 9517 | pub map_flags: IMFlag, |
| 9518 | pub map_which_groups: IMGroupsWhich, |
| 9519 | pub map_groups: SetOfGroups, |
| 9520 | pub map_which_mods: IMModsWhich, |
| 9521 | pub map_mods: xproto::ModMask, |
| 9522 | pub map_real_mods: xproto::ModMask, |
| 9523 | pub map_vmod: VMod, |
| 9524 | pub map_ctrls: BoolCtrl, |
| 9525 | pub supported: bool, |
| 9526 | } |
| 9527 | impl_debug_if_no_extra_traits!(GetNamedIndicatorReply, "GetNamedIndicatorReply" ); |
| 9528 | impl TryParse for GetNamedIndicatorReply { |
| 9529 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 9530 | let remaining = initial_value; |
| 9531 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 9532 | let (device_id, remaining) = u8::try_parse(remaining)?; |
| 9533 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 9534 | let (length, remaining) = u32::try_parse(remaining)?; |
| 9535 | let (indicator, remaining) = xproto::Atom::try_parse(remaining)?; |
| 9536 | let (found, remaining) = bool::try_parse(remaining)?; |
| 9537 | let (on, remaining) = bool::try_parse(remaining)?; |
| 9538 | let (real_indicator, remaining) = bool::try_parse(remaining)?; |
| 9539 | let (ndx, remaining) = u8::try_parse(remaining)?; |
| 9540 | let (map_flags, remaining) = u8::try_parse(remaining)?; |
| 9541 | let (map_which_groups, remaining) = u8::try_parse(remaining)?; |
| 9542 | let (map_groups, remaining) = u8::try_parse(remaining)?; |
| 9543 | let (map_which_mods, remaining) = u8::try_parse(remaining)?; |
| 9544 | let (map_mods, remaining) = u8::try_parse(remaining)?; |
| 9545 | let (map_real_mods, remaining) = u8::try_parse(remaining)?; |
| 9546 | let (map_vmod, remaining) = u16::try_parse(remaining)?; |
| 9547 | let (map_ctrls, remaining) = u32::try_parse(remaining)?; |
| 9548 | let (supported, remaining) = bool::try_parse(remaining)?; |
| 9549 | let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; |
| 9550 | if response_type != 1 { |
| 9551 | return Err(ParseError::InvalidValue); |
| 9552 | } |
| 9553 | let map_flags = map_flags.into(); |
| 9554 | let map_which_groups = map_which_groups.into(); |
| 9555 | let map_groups = map_groups.into(); |
| 9556 | let map_which_mods = map_which_mods.into(); |
| 9557 | let map_mods = map_mods.into(); |
| 9558 | let map_real_mods = map_real_mods.into(); |
| 9559 | let map_vmod = map_vmod.into(); |
| 9560 | let map_ctrls = map_ctrls.into(); |
| 9561 | 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 }; |
| 9562 | let _ = remaining; |
| 9563 | let remaining = initial_value.get(32 + length as usize * 4..) |
| 9564 | .ok_or(ParseError::InsufficientData)?; |
| 9565 | Ok((result, remaining)) |
| 9566 | } |
| 9567 | } |
| 9568 | impl Serialize for GetNamedIndicatorReply { |
| 9569 | type Bytes = [u8; 32]; |
| 9570 | fn serialize(&self) -> [u8; 32] { |
| 9571 | let response_type_bytes = &[1]; |
| 9572 | let device_id_bytes = self.device_id.serialize(); |
| 9573 | let sequence_bytes = self.sequence.serialize(); |
| 9574 | let length_bytes = self.length.serialize(); |
| 9575 | let indicator_bytes = self.indicator.serialize(); |
| 9576 | let found_bytes = self.found.serialize(); |
| 9577 | let on_bytes = self.on.serialize(); |
| 9578 | let real_indicator_bytes = self.real_indicator.serialize(); |
| 9579 | let ndx_bytes = self.ndx.serialize(); |
| 9580 | let map_flags_bytes = u8::from(self.map_flags).serialize(); |
| 9581 | let map_which_groups_bytes = u8::from(self.map_which_groups).serialize(); |
| 9582 | let map_groups_bytes = u8::from(self.map_groups).serialize(); |
| 9583 | let map_which_mods_bytes = u8::from(self.map_which_mods).serialize(); |
| 9584 | let map_mods_bytes = (u16::from(self.map_mods) as u8).serialize(); |
| 9585 | let map_real_mods_bytes = (u16::from(self.map_real_mods) as u8).serialize(); |
| 9586 | let map_vmod_bytes = u16::from(self.map_vmod).serialize(); |
| 9587 | let map_ctrls_bytes = u32::from(self.map_ctrls).serialize(); |
| 9588 | let supported_bytes = self.supported.serialize(); |
| 9589 | [ |
| 9590 | response_type_bytes[0], |
| 9591 | device_id_bytes[0], |
| 9592 | sequence_bytes[0], |
| 9593 | sequence_bytes[1], |
| 9594 | length_bytes[0], |
| 9595 | length_bytes[1], |
| 9596 | length_bytes[2], |
| 9597 | length_bytes[3], |
| 9598 | indicator_bytes[0], |
| 9599 | indicator_bytes[1], |
| 9600 | indicator_bytes[2], |
| 9601 | indicator_bytes[3], |
| 9602 | found_bytes[0], |
| 9603 | on_bytes[0], |
| 9604 | real_indicator_bytes[0], |
| 9605 | ndx_bytes[0], |
| 9606 | map_flags_bytes[0], |
| 9607 | map_which_groups_bytes[0], |
| 9608 | map_groups_bytes[0], |
| 9609 | map_which_mods_bytes[0], |
| 9610 | map_mods_bytes[0], |
| 9611 | map_real_mods_bytes[0], |
| 9612 | map_vmod_bytes[0], |
| 9613 | map_vmod_bytes[1], |
| 9614 | map_ctrls_bytes[0], |
| 9615 | map_ctrls_bytes[1], |
| 9616 | map_ctrls_bytes[2], |
| 9617 | map_ctrls_bytes[3], |
| 9618 | supported_bytes[0], |
| 9619 | 0, |
| 9620 | 0, |
| 9621 | 0, |
| 9622 | ] |
| 9623 | } |
| 9624 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 9625 | bytes.reserve(32); |
| 9626 | let response_type_bytes = &[1]; |
| 9627 | bytes.push(response_type_bytes[0]); |
| 9628 | self.device_id.serialize_into(bytes); |
| 9629 | self.sequence.serialize_into(bytes); |
| 9630 | self.length.serialize_into(bytes); |
| 9631 | self.indicator.serialize_into(bytes); |
| 9632 | self.found.serialize_into(bytes); |
| 9633 | self.on.serialize_into(bytes); |
| 9634 | self.real_indicator.serialize_into(bytes); |
| 9635 | self.ndx.serialize_into(bytes); |
| 9636 | u8::from(self.map_flags).serialize_into(bytes); |
| 9637 | u8::from(self.map_which_groups).serialize_into(bytes); |
| 9638 | u8::from(self.map_groups).serialize_into(bytes); |
| 9639 | u8::from(self.map_which_mods).serialize_into(bytes); |
| 9640 | (u16::from(self.map_mods) as u8).serialize_into(bytes); |
| 9641 | (u16::from(self.map_real_mods) as u8).serialize_into(bytes); |
| 9642 | u16::from(self.map_vmod).serialize_into(bytes); |
| 9643 | u32::from(self.map_ctrls).serialize_into(bytes); |
| 9644 | self.supported.serialize_into(bytes); |
| 9645 | bytes.extend_from_slice(&[0; 3]); |
| 9646 | } |
| 9647 | } |
| 9648 | |
| 9649 | /// Opcode for the SetNamedIndicator request |
| 9650 | pub const SET_NAMED_INDICATOR_REQUEST: u8 = 16; |
| 9651 | #[derive (Clone, Copy, Default)] |
| 9652 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9653 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9654 | pub struct SetNamedIndicatorRequest { |
| 9655 | pub device_spec: DeviceSpec, |
| 9656 | pub led_class: LedClass, |
| 9657 | pub led_id: IDSpec, |
| 9658 | pub indicator: xproto::Atom, |
| 9659 | pub set_state: bool, |
| 9660 | pub on: bool, |
| 9661 | pub set_map: bool, |
| 9662 | pub create_map: bool, |
| 9663 | pub map_flags: IMFlag, |
| 9664 | pub map_which_groups: IMGroupsWhich, |
| 9665 | pub map_groups: SetOfGroups, |
| 9666 | pub map_which_mods: IMModsWhich, |
| 9667 | pub map_real_mods: xproto::ModMask, |
| 9668 | pub map_vmods: VMod, |
| 9669 | pub map_ctrls: BoolCtrl, |
| 9670 | } |
| 9671 | impl_debug_if_no_extra_traits!(SetNamedIndicatorRequest, "SetNamedIndicatorRequest" ); |
| 9672 | impl SetNamedIndicatorRequest { |
| 9673 | /// Serialize this request into bytes for the provided connection |
| 9674 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 9675 | let length_so_far = 0; |
| 9676 | let device_spec_bytes = self.device_spec.serialize(); |
| 9677 | let led_class_bytes = LedClassSpec::from(self.led_class).serialize(); |
| 9678 | let led_id_bytes = self.led_id.serialize(); |
| 9679 | let indicator_bytes = self.indicator.serialize(); |
| 9680 | let set_state_bytes = self.set_state.serialize(); |
| 9681 | let on_bytes = self.on.serialize(); |
| 9682 | let set_map_bytes = self.set_map.serialize(); |
| 9683 | let create_map_bytes = self.create_map.serialize(); |
| 9684 | let map_flags_bytes = u8::from(self.map_flags).serialize(); |
| 9685 | let map_which_groups_bytes = u8::from(self.map_which_groups).serialize(); |
| 9686 | let map_groups_bytes = u8::from(self.map_groups).serialize(); |
| 9687 | let map_which_mods_bytes = u8::from(self.map_which_mods).serialize(); |
| 9688 | let map_real_mods_bytes = (u16::from(self.map_real_mods) as u8).serialize(); |
| 9689 | let map_vmods_bytes = u16::from(self.map_vmods).serialize(); |
| 9690 | let map_ctrls_bytes = u32::from(self.map_ctrls).serialize(); |
| 9691 | let mut request0 = vec![ |
| 9692 | major_opcode, |
| 9693 | SET_NAMED_INDICATOR_REQUEST, |
| 9694 | 0, |
| 9695 | 0, |
| 9696 | device_spec_bytes[0], |
| 9697 | device_spec_bytes[1], |
| 9698 | led_class_bytes[0], |
| 9699 | led_class_bytes[1], |
| 9700 | led_id_bytes[0], |
| 9701 | led_id_bytes[1], |
| 9702 | 0, |
| 9703 | 0, |
| 9704 | indicator_bytes[0], |
| 9705 | indicator_bytes[1], |
| 9706 | indicator_bytes[2], |
| 9707 | indicator_bytes[3], |
| 9708 | set_state_bytes[0], |
| 9709 | on_bytes[0], |
| 9710 | set_map_bytes[0], |
| 9711 | create_map_bytes[0], |
| 9712 | 0, |
| 9713 | map_flags_bytes[0], |
| 9714 | map_which_groups_bytes[0], |
| 9715 | map_groups_bytes[0], |
| 9716 | map_which_mods_bytes[0], |
| 9717 | map_real_mods_bytes[0], |
| 9718 | map_vmods_bytes[0], |
| 9719 | map_vmods_bytes[1], |
| 9720 | map_ctrls_bytes[0], |
| 9721 | map_ctrls_bytes[1], |
| 9722 | map_ctrls_bytes[2], |
| 9723 | map_ctrls_bytes[3], |
| 9724 | ]; |
| 9725 | let length_so_far = length_so_far + request0.len(); |
| 9726 | assert_eq!(length_so_far % 4, 0); |
| 9727 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 9728 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 9729 | ([request0.into()], vec![]) |
| 9730 | } |
| 9731 | /// Parse this request given its header, its body, and any fds that go along with it |
| 9732 | #[cfg (feature = "request-parsing" )] |
| 9733 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 9734 | if header.minor_opcode != SET_NAMED_INDICATOR_REQUEST { |
| 9735 | return Err(ParseError::InvalidValue); |
| 9736 | } |
| 9737 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 9738 | let (led_class, remaining) = LedClassSpec::try_parse(remaining)?; |
| 9739 | let led_class = led_class.into(); |
| 9740 | let (led_id, remaining) = IDSpec::try_parse(remaining)?; |
| 9741 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 9742 | let (indicator, remaining) = xproto::Atom::try_parse(remaining)?; |
| 9743 | let (set_state, remaining) = bool::try_parse(remaining)?; |
| 9744 | let (on, remaining) = bool::try_parse(remaining)?; |
| 9745 | let (set_map, remaining) = bool::try_parse(remaining)?; |
| 9746 | let (create_map, remaining) = bool::try_parse(remaining)?; |
| 9747 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 9748 | let (map_flags, remaining) = u8::try_parse(remaining)?; |
| 9749 | let map_flags = map_flags.into(); |
| 9750 | let (map_which_groups, remaining) = u8::try_parse(remaining)?; |
| 9751 | let map_which_groups = map_which_groups.into(); |
| 9752 | let (map_groups, remaining) = u8::try_parse(remaining)?; |
| 9753 | let map_groups = map_groups.into(); |
| 9754 | let (map_which_mods, remaining) = u8::try_parse(remaining)?; |
| 9755 | let map_which_mods = map_which_mods.into(); |
| 9756 | let (map_real_mods, remaining) = u8::try_parse(remaining)?; |
| 9757 | let map_real_mods = map_real_mods.into(); |
| 9758 | let (map_vmods, remaining) = u16::try_parse(remaining)?; |
| 9759 | let map_vmods = map_vmods.into(); |
| 9760 | let (map_ctrls, remaining) = u32::try_parse(remaining)?; |
| 9761 | let map_ctrls = map_ctrls.into(); |
| 9762 | let _ = remaining; |
| 9763 | Ok(SetNamedIndicatorRequest { |
| 9764 | device_spec, |
| 9765 | led_class, |
| 9766 | led_id, |
| 9767 | indicator, |
| 9768 | set_state, |
| 9769 | on, |
| 9770 | set_map, |
| 9771 | create_map, |
| 9772 | map_flags, |
| 9773 | map_which_groups, |
| 9774 | map_groups, |
| 9775 | map_which_mods, |
| 9776 | map_real_mods, |
| 9777 | map_vmods, |
| 9778 | map_ctrls, |
| 9779 | }) |
| 9780 | } |
| 9781 | } |
| 9782 | impl Request for SetNamedIndicatorRequest { |
| 9783 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 9784 | |
| 9785 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 9786 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 9787 | // Flatten the buffers into a single vector |
| 9788 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 9789 | (buf, fds) |
| 9790 | } |
| 9791 | } |
| 9792 | impl crate::x11_utils::VoidRequest for SetNamedIndicatorRequest { |
| 9793 | } |
| 9794 | |
| 9795 | /// Opcode for the GetNames request |
| 9796 | pub const GET_NAMES_REQUEST: u8 = 17; |
| 9797 | #[derive (Clone, Copy, Default)] |
| 9798 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9799 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9800 | pub struct GetNamesRequest { |
| 9801 | pub device_spec: DeviceSpec, |
| 9802 | pub which: NameDetail, |
| 9803 | } |
| 9804 | impl_debug_if_no_extra_traits!(GetNamesRequest, "GetNamesRequest" ); |
| 9805 | impl GetNamesRequest { |
| 9806 | /// Serialize this request into bytes for the provided connection |
| 9807 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 9808 | let length_so_far = 0; |
| 9809 | let device_spec_bytes = self.device_spec.serialize(); |
| 9810 | let which_bytes = u32::from(self.which).serialize(); |
| 9811 | let mut request0 = vec![ |
| 9812 | major_opcode, |
| 9813 | GET_NAMES_REQUEST, |
| 9814 | 0, |
| 9815 | 0, |
| 9816 | device_spec_bytes[0], |
| 9817 | device_spec_bytes[1], |
| 9818 | 0, |
| 9819 | 0, |
| 9820 | which_bytes[0], |
| 9821 | which_bytes[1], |
| 9822 | which_bytes[2], |
| 9823 | which_bytes[3], |
| 9824 | ]; |
| 9825 | let length_so_far = length_so_far + request0.len(); |
| 9826 | assert_eq!(length_so_far % 4, 0); |
| 9827 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 9828 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 9829 | ([request0.into()], vec![]) |
| 9830 | } |
| 9831 | /// Parse this request given its header, its body, and any fds that go along with it |
| 9832 | #[cfg (feature = "request-parsing" )] |
| 9833 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 9834 | if header.minor_opcode != GET_NAMES_REQUEST { |
| 9835 | return Err(ParseError::InvalidValue); |
| 9836 | } |
| 9837 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 9838 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 9839 | let (which, remaining) = u32::try_parse(remaining)?; |
| 9840 | let which = which.into(); |
| 9841 | let _ = remaining; |
| 9842 | Ok(GetNamesRequest { |
| 9843 | device_spec, |
| 9844 | which, |
| 9845 | }) |
| 9846 | } |
| 9847 | } |
| 9848 | impl Request for GetNamesRequest { |
| 9849 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 9850 | |
| 9851 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 9852 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 9853 | // Flatten the buffers into a single vector |
| 9854 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 9855 | (buf, fds) |
| 9856 | } |
| 9857 | } |
| 9858 | impl crate::x11_utils::ReplyRequest for GetNamesRequest { |
| 9859 | type Reply = GetNamesReply; |
| 9860 | } |
| 9861 | |
| 9862 | #[derive (Clone)] |
| 9863 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9864 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9865 | pub struct GetNamesValueListKTLevelNames { |
| 9866 | pub n_levels_per_type: Vec<u8>, |
| 9867 | pub kt_level_names: Vec<xproto::Atom>, |
| 9868 | } |
| 9869 | impl_debug_if_no_extra_traits!(GetNamesValueListKTLevelNames, "GetNamesValueListKTLevelNames" ); |
| 9870 | impl GetNamesValueListKTLevelNames { |
| 9871 | pub fn try_parse(remaining: &[u8], n_types: u8) -> Result<(Self, &[u8]), ParseError> { |
| 9872 | let value: &[u8] = remaining; |
| 9873 | let (n_levels_per_type: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data:remaining, list_length:n_types.try_to_usize()?)?; |
| 9874 | let n_levels_per_type: Vec = n_levels_per_type.to_vec(); |
| 9875 | // Align offset to multiple of 4 |
| 9876 | let offset: usize = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 9877 | let misalignment: usize = (4 - (offset % 4)) % 4; |
| 9878 | let remaining: &[u8] = remaining.get(misalignment..).ok_or(err:ParseError::InsufficientData)?; |
| 9879 | let (kt_level_names: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<xproto::Atom>(data:remaining, list_length:n_levels_per_type.iter().try_fold(init:0u32, |acc: u32, x: &u8| acc.checked_add(u32::from(*x)).ok_or(err:ParseError::InvalidExpression))?.try_to_usize()?)?; |
| 9880 | let result: GetNamesValueListKTLevelNames = GetNamesValueListKTLevelNames { n_levels_per_type, kt_level_names }; |
| 9881 | Ok((result, remaining)) |
| 9882 | } |
| 9883 | } |
| 9884 | impl GetNamesValueListKTLevelNames { |
| 9885 | #[allow (dead_code)] |
| 9886 | fn serialize(&self, n_types: u8) -> Vec<u8> { |
| 9887 | let mut result: Vec = Vec::new(); |
| 9888 | self.serialize_into(&mut result, n_types:u8::from(n_types)); |
| 9889 | result |
| 9890 | } |
| 9891 | fn serialize_into(&self, bytes: &mut Vec<u8>, n_types: u8) { |
| 9892 | assert_eq!(self.n_levels_per_type.len(), usize::try_from(n_types).unwrap(), "`n_levels_per_type` has an incorrect length" ); |
| 9893 | bytes.extend_from_slice(&self.n_levels_per_type); |
| 9894 | bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]); |
| 9895 | 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" ); |
| 9896 | self.kt_level_names.serialize_into(bytes); |
| 9897 | } |
| 9898 | } |
| 9899 | #[derive (Clone, Default)] |
| 9900 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 9901 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 9902 | pub struct GetNamesValueList { |
| 9903 | pub keycodes_name: Option<xproto::Atom>, |
| 9904 | pub geometry_name: Option<xproto::Atom>, |
| 9905 | pub symbols_name: Option<xproto::Atom>, |
| 9906 | pub phys_symbols_name: Option<xproto::Atom>, |
| 9907 | pub types_name: Option<xproto::Atom>, |
| 9908 | pub compat_name: Option<xproto::Atom>, |
| 9909 | pub type_names: Option<Vec<xproto::Atom>>, |
| 9910 | pub kt_level_names: Option<GetNamesValueListKTLevelNames>, |
| 9911 | pub indicator_names: Option<Vec<xproto::Atom>>, |
| 9912 | pub virtual_mod_names: Option<Vec<xproto::Atom>>, |
| 9913 | pub groups: Option<Vec<xproto::Atom>>, |
| 9914 | pub key_names: Option<Vec<KeyName>>, |
| 9915 | pub key_aliases: Option<Vec<KeyAlias>>, |
| 9916 | pub radio_group_names: Option<Vec<xproto::Atom>>, |
| 9917 | } |
| 9918 | impl_debug_if_no_extra_traits!(GetNamesValueList, "GetNamesValueList" ); |
| 9919 | impl GetNamesValueList { |
| 9920 | #[cfg_attr (not(feature = "request-parsing" ), allow(dead_code))] |
| 9921 | 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> { |
| 9922 | let switch_expr = u32::from(which); |
| 9923 | let mut outer_remaining = value; |
| 9924 | let keycodes_name = if switch_expr & u32::from(NameDetail::KEYCODES) != 0 { |
| 9925 | let remaining = outer_remaining; |
| 9926 | let (keycodes_name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 9927 | outer_remaining = remaining; |
| 9928 | Some(keycodes_name) |
| 9929 | } else { |
| 9930 | None |
| 9931 | }; |
| 9932 | let geometry_name = if switch_expr & u32::from(NameDetail::GEOMETRY) != 0 { |
| 9933 | let remaining = outer_remaining; |
| 9934 | let (geometry_name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 9935 | outer_remaining = remaining; |
| 9936 | Some(geometry_name) |
| 9937 | } else { |
| 9938 | None |
| 9939 | }; |
| 9940 | let symbols_name = if switch_expr & u32::from(NameDetail::SYMBOLS) != 0 { |
| 9941 | let remaining = outer_remaining; |
| 9942 | let (symbols_name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 9943 | outer_remaining = remaining; |
| 9944 | Some(symbols_name) |
| 9945 | } else { |
| 9946 | None |
| 9947 | }; |
| 9948 | let phys_symbols_name = if switch_expr & u32::from(NameDetail::PHYS_SYMBOLS) != 0 { |
| 9949 | let remaining = outer_remaining; |
| 9950 | let (phys_symbols_name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 9951 | outer_remaining = remaining; |
| 9952 | Some(phys_symbols_name) |
| 9953 | } else { |
| 9954 | None |
| 9955 | }; |
| 9956 | let types_name = if switch_expr & u32::from(NameDetail::TYPES) != 0 { |
| 9957 | let remaining = outer_remaining; |
| 9958 | let (types_name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 9959 | outer_remaining = remaining; |
| 9960 | Some(types_name) |
| 9961 | } else { |
| 9962 | None |
| 9963 | }; |
| 9964 | let compat_name = if switch_expr & u32::from(NameDetail::COMPAT) != 0 { |
| 9965 | let remaining = outer_remaining; |
| 9966 | let (compat_name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 9967 | outer_remaining = remaining; |
| 9968 | Some(compat_name) |
| 9969 | } else { |
| 9970 | None |
| 9971 | }; |
| 9972 | let type_names = if switch_expr & u32::from(NameDetail::KEY_TYPE_NAMES) != 0 { |
| 9973 | let remaining = outer_remaining; |
| 9974 | let (type_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, n_types.try_to_usize()?)?; |
| 9975 | outer_remaining = remaining; |
| 9976 | Some(type_names) |
| 9977 | } else { |
| 9978 | None |
| 9979 | }; |
| 9980 | let kt_level_names = if switch_expr & u32::from(NameDetail::KT_LEVEL_NAMES) != 0 { |
| 9981 | let (kt_level_names, new_remaining) = GetNamesValueListKTLevelNames::try_parse(outer_remaining, n_types)?; |
| 9982 | outer_remaining = new_remaining; |
| 9983 | Some(kt_level_names) |
| 9984 | } else { |
| 9985 | None |
| 9986 | }; |
| 9987 | let indicator_names = if switch_expr & u32::from(NameDetail::INDICATOR_NAMES) != 0 { |
| 9988 | let remaining = outer_remaining; |
| 9989 | let (indicator_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, u32::from(indicators).count_ones().try_to_usize()?)?; |
| 9990 | outer_remaining = remaining; |
| 9991 | Some(indicator_names) |
| 9992 | } else { |
| 9993 | None |
| 9994 | }; |
| 9995 | let virtual_mod_names = if switch_expr & u32::from(NameDetail::VIRTUAL_MOD_NAMES) != 0 { |
| 9996 | let remaining = outer_remaining; |
| 9997 | let (virtual_mod_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, u32::from(virtual_mods).count_ones().try_to_usize()?)?; |
| 9998 | outer_remaining = remaining; |
| 9999 | Some(virtual_mod_names) |
| 10000 | } else { |
| 10001 | None |
| 10002 | }; |
| 10003 | let groups = if switch_expr & u32::from(NameDetail::GROUP_NAMES) != 0 { |
| 10004 | let remaining = outer_remaining; |
| 10005 | let (groups, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, u32::from(group_names).count_ones().try_to_usize()?)?; |
| 10006 | outer_remaining = remaining; |
| 10007 | Some(groups) |
| 10008 | } else { |
| 10009 | None |
| 10010 | }; |
| 10011 | let key_names = if switch_expr & u32::from(NameDetail::KEY_NAMES) != 0 { |
| 10012 | let remaining = outer_remaining; |
| 10013 | let (key_names, remaining) = crate::x11_utils::parse_list::<KeyName>(remaining, n_keys.try_to_usize()?)?; |
| 10014 | outer_remaining = remaining; |
| 10015 | Some(key_names) |
| 10016 | } else { |
| 10017 | None |
| 10018 | }; |
| 10019 | let key_aliases = if switch_expr & u32::from(NameDetail::KEY_ALIASES) != 0 { |
| 10020 | let remaining = outer_remaining; |
| 10021 | let (key_aliases, remaining) = crate::x11_utils::parse_list::<KeyAlias>(remaining, n_key_aliases.try_to_usize()?)?; |
| 10022 | outer_remaining = remaining; |
| 10023 | Some(key_aliases) |
| 10024 | } else { |
| 10025 | None |
| 10026 | }; |
| 10027 | let radio_group_names = if switch_expr & u32::from(NameDetail::RG_NAMES) != 0 { |
| 10028 | let remaining = outer_remaining; |
| 10029 | let (radio_group_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, n_radio_groups.try_to_usize()?)?; |
| 10030 | outer_remaining = remaining; |
| 10031 | Some(radio_group_names) |
| 10032 | } else { |
| 10033 | None |
| 10034 | }; |
| 10035 | let result = GetNamesValueList { keycodes_name, geometry_name, symbols_name, phys_symbols_name, types_name, compat_name, type_names, kt_level_names, indicator_names, virtual_mod_names, groups, key_names, key_aliases, radio_group_names }; |
| 10036 | Ok((result, outer_remaining)) |
| 10037 | } |
| 10038 | } |
| 10039 | impl GetNamesValueList { |
| 10040 | #[allow (dead_code)] |
| 10041 | 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> { |
| 10042 | let mut result = Vec::new(); |
| 10043 | self.serialize_into(&mut result, u32::from(which), u8::from(n_types), u32::from(indicators), u16::from(virtual_mods), u8::from(group_names), u8::from(n_keys), u8::from(n_key_aliases), u8::from(n_radio_groups)); |
| 10044 | result |
| 10045 | } |
| 10046 | 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) { |
| 10047 | assert_eq!(self.switch_expr(), u32::from(which), "switch `value_list` has an inconsistent discriminant" ); |
| 10048 | if let Some(keycodes_name) = self.keycodes_name { |
| 10049 | keycodes_name.serialize_into(bytes); |
| 10050 | } |
| 10051 | if let Some(geometry_name) = self.geometry_name { |
| 10052 | geometry_name.serialize_into(bytes); |
| 10053 | } |
| 10054 | if let Some(symbols_name) = self.symbols_name { |
| 10055 | symbols_name.serialize_into(bytes); |
| 10056 | } |
| 10057 | if let Some(phys_symbols_name) = self.phys_symbols_name { |
| 10058 | phys_symbols_name.serialize_into(bytes); |
| 10059 | } |
| 10060 | if let Some(types_name) = self.types_name { |
| 10061 | types_name.serialize_into(bytes); |
| 10062 | } |
| 10063 | if let Some(compat_name) = self.compat_name { |
| 10064 | compat_name.serialize_into(bytes); |
| 10065 | } |
| 10066 | if let Some(ref type_names) = self.type_names { |
| 10067 | assert_eq!(type_names.len(), usize::try_from(n_types).unwrap(), "`type_names` has an incorrect length" ); |
| 10068 | type_names.serialize_into(bytes); |
| 10069 | } |
| 10070 | if let Some(ref kt_level_names) = self.kt_level_names { |
| 10071 | kt_level_names.serialize_into(bytes, u8::from(n_types)); |
| 10072 | } |
| 10073 | if let Some(ref indicator_names) = self.indicator_names { |
| 10074 | assert_eq!(indicator_names.len(), usize::try_from(u32::from(indicators).count_ones()).unwrap(), "`indicator_names` has an incorrect length" ); |
| 10075 | indicator_names.serialize_into(bytes); |
| 10076 | } |
| 10077 | if let Some(ref virtual_mod_names) = self.virtual_mod_names { |
| 10078 | assert_eq!(virtual_mod_names.len(), usize::try_from(u32::from(virtual_mods).count_ones()).unwrap(), "`virtual_mod_names` has an incorrect length" ); |
| 10079 | virtual_mod_names.serialize_into(bytes); |
| 10080 | } |
| 10081 | if let Some(ref groups) = self.groups { |
| 10082 | assert_eq!(groups.len(), usize::try_from(u32::from(group_names).count_ones()).unwrap(), "`groups` has an incorrect length" ); |
| 10083 | groups.serialize_into(bytes); |
| 10084 | } |
| 10085 | if let Some(ref key_names) = self.key_names { |
| 10086 | assert_eq!(key_names.len(), usize::try_from(n_keys).unwrap(), "`key_names` has an incorrect length" ); |
| 10087 | key_names.serialize_into(bytes); |
| 10088 | } |
| 10089 | if let Some(ref key_aliases) = self.key_aliases { |
| 10090 | assert_eq!(key_aliases.len(), usize::try_from(n_key_aliases).unwrap(), "`key_aliases` has an incorrect length" ); |
| 10091 | key_aliases.serialize_into(bytes); |
| 10092 | } |
| 10093 | if let Some(ref radio_group_names) = self.radio_group_names { |
| 10094 | assert_eq!(radio_group_names.len(), usize::try_from(n_radio_groups).unwrap(), "`radio_group_names` has an incorrect length" ); |
| 10095 | radio_group_names.serialize_into(bytes); |
| 10096 | } |
| 10097 | } |
| 10098 | } |
| 10099 | impl GetNamesValueList { |
| 10100 | fn switch_expr(&self) -> u32 { |
| 10101 | let mut expr_value = 0; |
| 10102 | if self.keycodes_name.is_some() { |
| 10103 | expr_value |= u32::from(NameDetail::KEYCODES); |
| 10104 | } |
| 10105 | if self.geometry_name.is_some() { |
| 10106 | expr_value |= u32::from(NameDetail::GEOMETRY); |
| 10107 | } |
| 10108 | if self.symbols_name.is_some() { |
| 10109 | expr_value |= u32::from(NameDetail::SYMBOLS); |
| 10110 | } |
| 10111 | if self.phys_symbols_name.is_some() { |
| 10112 | expr_value |= u32::from(NameDetail::PHYS_SYMBOLS); |
| 10113 | } |
| 10114 | if self.types_name.is_some() { |
| 10115 | expr_value |= u32::from(NameDetail::TYPES); |
| 10116 | } |
| 10117 | if self.compat_name.is_some() { |
| 10118 | expr_value |= u32::from(NameDetail::COMPAT); |
| 10119 | } |
| 10120 | if self.type_names.is_some() { |
| 10121 | expr_value |= u32::from(NameDetail::KEY_TYPE_NAMES); |
| 10122 | } |
| 10123 | if self.kt_level_names.is_some() { |
| 10124 | expr_value |= u32::from(NameDetail::KT_LEVEL_NAMES); |
| 10125 | } |
| 10126 | if self.indicator_names.is_some() { |
| 10127 | expr_value |= u32::from(NameDetail::INDICATOR_NAMES); |
| 10128 | } |
| 10129 | if self.virtual_mod_names.is_some() { |
| 10130 | expr_value |= u32::from(NameDetail::VIRTUAL_MOD_NAMES); |
| 10131 | } |
| 10132 | if self.groups.is_some() { |
| 10133 | expr_value |= u32::from(NameDetail::GROUP_NAMES); |
| 10134 | } |
| 10135 | if self.key_names.is_some() { |
| 10136 | expr_value |= u32::from(NameDetail::KEY_NAMES); |
| 10137 | } |
| 10138 | if self.key_aliases.is_some() { |
| 10139 | expr_value |= u32::from(NameDetail::KEY_ALIASES); |
| 10140 | } |
| 10141 | if self.radio_group_names.is_some() { |
| 10142 | expr_value |= u32::from(NameDetail::RG_NAMES); |
| 10143 | } |
| 10144 | expr_value |
| 10145 | } |
| 10146 | } |
| 10147 | |
| 10148 | #[derive (Clone, Default)] |
| 10149 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 10150 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 10151 | pub struct GetNamesReply { |
| 10152 | pub device_id: u8, |
| 10153 | pub sequence: u16, |
| 10154 | pub length: u32, |
| 10155 | pub min_key_code: xproto::Keycode, |
| 10156 | pub max_key_code: xproto::Keycode, |
| 10157 | pub n_types: u8, |
| 10158 | pub group_names: SetOfGroup, |
| 10159 | pub virtual_mods: VMod, |
| 10160 | pub first_key: xproto::Keycode, |
| 10161 | pub n_keys: u8, |
| 10162 | pub indicators: u32, |
| 10163 | pub n_radio_groups: u8, |
| 10164 | pub n_key_aliases: u8, |
| 10165 | pub n_kt_levels: u16, |
| 10166 | pub value_list: GetNamesValueList, |
| 10167 | } |
| 10168 | impl_debug_if_no_extra_traits!(GetNamesReply, "GetNamesReply" ); |
| 10169 | impl TryParse for GetNamesReply { |
| 10170 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 10171 | let remaining = initial_value; |
| 10172 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 10173 | let (device_id, remaining) = u8::try_parse(remaining)?; |
| 10174 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 10175 | let (length, remaining) = u32::try_parse(remaining)?; |
| 10176 | let (which, remaining) = u32::try_parse(remaining)?; |
| 10177 | let (min_key_code, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 10178 | let (max_key_code, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 10179 | let (n_types, remaining) = u8::try_parse(remaining)?; |
| 10180 | let (group_names, remaining) = u8::try_parse(remaining)?; |
| 10181 | let (virtual_mods, remaining) = u16::try_parse(remaining)?; |
| 10182 | let (first_key, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 10183 | let (n_keys, remaining) = u8::try_parse(remaining)?; |
| 10184 | let (indicators, remaining) = u32::try_parse(remaining)?; |
| 10185 | let (n_radio_groups, remaining) = u8::try_parse(remaining)?; |
| 10186 | let (n_key_aliases, remaining) = u8::try_parse(remaining)?; |
| 10187 | let (n_kt_levels, remaining) = u16::try_parse(remaining)?; |
| 10188 | let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; |
| 10189 | let (value_list, remaining) = GetNamesValueList::try_parse(remaining, u32::from(which), u8::from(n_types), u32::from(indicators), u16::from(virtual_mods), u8::from(group_names), u8::from(n_keys), u8::from(n_key_aliases), u8::from(n_radio_groups))?; |
| 10190 | if response_type != 1 { |
| 10191 | return Err(ParseError::InvalidValue); |
| 10192 | } |
| 10193 | let group_names = group_names.into(); |
| 10194 | let virtual_mods = virtual_mods.into(); |
| 10195 | 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 }; |
| 10196 | let _ = remaining; |
| 10197 | let remaining = initial_value.get(32 + length as usize * 4..) |
| 10198 | .ok_or(ParseError::InsufficientData)?; |
| 10199 | Ok((result, remaining)) |
| 10200 | } |
| 10201 | } |
| 10202 | impl Serialize for GetNamesReply { |
| 10203 | type Bytes = Vec<u8>; |
| 10204 | fn serialize(&self) -> Vec<u8> { |
| 10205 | let mut result = Vec::new(); |
| 10206 | self.serialize_into(&mut result); |
| 10207 | result |
| 10208 | } |
| 10209 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 10210 | bytes.reserve(32); |
| 10211 | let response_type_bytes = &[1]; |
| 10212 | bytes.push(response_type_bytes[0]); |
| 10213 | self.device_id.serialize_into(bytes); |
| 10214 | self.sequence.serialize_into(bytes); |
| 10215 | self.length.serialize_into(bytes); |
| 10216 | let which: u32 = self.value_list.switch_expr(); |
| 10217 | which.serialize_into(bytes); |
| 10218 | self.min_key_code.serialize_into(bytes); |
| 10219 | self.max_key_code.serialize_into(bytes); |
| 10220 | self.n_types.serialize_into(bytes); |
| 10221 | u8::from(self.group_names).serialize_into(bytes); |
| 10222 | u16::from(self.virtual_mods).serialize_into(bytes); |
| 10223 | self.first_key.serialize_into(bytes); |
| 10224 | self.n_keys.serialize_into(bytes); |
| 10225 | self.indicators.serialize_into(bytes); |
| 10226 | self.n_radio_groups.serialize_into(bytes); |
| 10227 | self.n_key_aliases.serialize_into(bytes); |
| 10228 | self.n_kt_levels.serialize_into(bytes); |
| 10229 | bytes.extend_from_slice(&[0; 4]); |
| 10230 | self.value_list.serialize_into(bytes, u32::from(which), u8::from(self.n_types), u32::from(self.indicators), u16::from(self.virtual_mods), u8::from(self.group_names), u8::from(self.n_keys), u8::from(self.n_key_aliases), u8::from(self.n_radio_groups)); |
| 10231 | } |
| 10232 | } |
| 10233 | |
| 10234 | #[derive (Clone)] |
| 10235 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 10236 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 10237 | pub struct SetNamesAuxKTLevelNames { |
| 10238 | pub n_levels_per_type: Vec<u8>, |
| 10239 | pub kt_level_names: Vec<xproto::Atom>, |
| 10240 | } |
| 10241 | impl_debug_if_no_extra_traits!(SetNamesAuxKTLevelNames, "SetNamesAuxKTLevelNames" ); |
| 10242 | impl SetNamesAuxKTLevelNames { |
| 10243 | pub fn try_parse(remaining: &[u8], n_types: u8) -> Result<(Self, &[u8]), ParseError> { |
| 10244 | let value: &[u8] = remaining; |
| 10245 | let (n_levels_per_type: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data:remaining, list_length:n_types.try_to_usize()?)?; |
| 10246 | let n_levels_per_type: Vec = n_levels_per_type.to_vec(); |
| 10247 | // Align offset to multiple of 4 |
| 10248 | let offset: usize = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 10249 | let misalignment: usize = (4 - (offset % 4)) % 4; |
| 10250 | let remaining: &[u8] = remaining.get(misalignment..).ok_or(err:ParseError::InsufficientData)?; |
| 10251 | let (kt_level_names: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<xproto::Atom>(data:remaining, list_length:n_levels_per_type.iter().try_fold(init:0u32, |acc: u32, x: &u8| acc.checked_add(u32::from(*x)).ok_or(err:ParseError::InvalidExpression))?.try_to_usize()?)?; |
| 10252 | let result: SetNamesAuxKTLevelNames = SetNamesAuxKTLevelNames { n_levels_per_type, kt_level_names }; |
| 10253 | Ok((result, remaining)) |
| 10254 | } |
| 10255 | } |
| 10256 | impl SetNamesAuxKTLevelNames { |
| 10257 | #[allow (dead_code)] |
| 10258 | fn serialize(&self, n_types: u8) -> Vec<u8> { |
| 10259 | let mut result: Vec = Vec::new(); |
| 10260 | self.serialize_into(&mut result, n_types:u8::from(n_types)); |
| 10261 | result |
| 10262 | } |
| 10263 | fn serialize_into(&self, bytes: &mut Vec<u8>, n_types: u8) { |
| 10264 | assert_eq!(self.n_levels_per_type.len(), usize::try_from(n_types).unwrap(), "`n_levels_per_type` has an incorrect length" ); |
| 10265 | bytes.extend_from_slice(&self.n_levels_per_type); |
| 10266 | bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]); |
| 10267 | 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" ); |
| 10268 | self.kt_level_names.serialize_into(bytes); |
| 10269 | } |
| 10270 | } |
| 10271 | /// Auxiliary and optional information for the `set_names` function |
| 10272 | #[derive (Clone, Default)] |
| 10273 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 10274 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 10275 | pub struct SetNamesAux { |
| 10276 | pub keycodes_name: Option<xproto::Atom>, |
| 10277 | pub geometry_name: Option<xproto::Atom>, |
| 10278 | pub symbols_name: Option<xproto::Atom>, |
| 10279 | pub phys_symbols_name: Option<xproto::Atom>, |
| 10280 | pub types_name: Option<xproto::Atom>, |
| 10281 | pub compat_name: Option<xproto::Atom>, |
| 10282 | pub type_names: Option<Vec<xproto::Atom>>, |
| 10283 | pub kt_level_names: Option<SetNamesAuxKTLevelNames>, |
| 10284 | pub indicator_names: Option<Vec<xproto::Atom>>, |
| 10285 | pub virtual_mod_names: Option<Vec<xproto::Atom>>, |
| 10286 | pub groups: Option<Vec<xproto::Atom>>, |
| 10287 | pub key_names: Option<Vec<KeyName>>, |
| 10288 | pub key_aliases: Option<Vec<KeyAlias>>, |
| 10289 | pub radio_group_names: Option<Vec<xproto::Atom>>, |
| 10290 | } |
| 10291 | impl_debug_if_no_extra_traits!(SetNamesAux, "SetNamesAux" ); |
| 10292 | impl SetNamesAux { |
| 10293 | #[cfg_attr (not(feature = "request-parsing" ), allow(dead_code))] |
| 10294 | 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> { |
| 10295 | let switch_expr = u32::from(which); |
| 10296 | let mut outer_remaining = value; |
| 10297 | let keycodes_name = if switch_expr & u32::from(NameDetail::KEYCODES) != 0 { |
| 10298 | let remaining = outer_remaining; |
| 10299 | let (keycodes_name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 10300 | outer_remaining = remaining; |
| 10301 | Some(keycodes_name) |
| 10302 | } else { |
| 10303 | None |
| 10304 | }; |
| 10305 | let geometry_name = if switch_expr & u32::from(NameDetail::GEOMETRY) != 0 { |
| 10306 | let remaining = outer_remaining; |
| 10307 | let (geometry_name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 10308 | outer_remaining = remaining; |
| 10309 | Some(geometry_name) |
| 10310 | } else { |
| 10311 | None |
| 10312 | }; |
| 10313 | let symbols_name = if switch_expr & u32::from(NameDetail::SYMBOLS) != 0 { |
| 10314 | let remaining = outer_remaining; |
| 10315 | let (symbols_name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 10316 | outer_remaining = remaining; |
| 10317 | Some(symbols_name) |
| 10318 | } else { |
| 10319 | None |
| 10320 | }; |
| 10321 | let phys_symbols_name = if switch_expr & u32::from(NameDetail::PHYS_SYMBOLS) != 0 { |
| 10322 | let remaining = outer_remaining; |
| 10323 | let (phys_symbols_name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 10324 | outer_remaining = remaining; |
| 10325 | Some(phys_symbols_name) |
| 10326 | } else { |
| 10327 | None |
| 10328 | }; |
| 10329 | let types_name = if switch_expr & u32::from(NameDetail::TYPES) != 0 { |
| 10330 | let remaining = outer_remaining; |
| 10331 | let (types_name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 10332 | outer_remaining = remaining; |
| 10333 | Some(types_name) |
| 10334 | } else { |
| 10335 | None |
| 10336 | }; |
| 10337 | let compat_name = if switch_expr & u32::from(NameDetail::COMPAT) != 0 { |
| 10338 | let remaining = outer_remaining; |
| 10339 | let (compat_name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 10340 | outer_remaining = remaining; |
| 10341 | Some(compat_name) |
| 10342 | } else { |
| 10343 | None |
| 10344 | }; |
| 10345 | let type_names = if switch_expr & u32::from(NameDetail::KEY_TYPE_NAMES) != 0 { |
| 10346 | let remaining = outer_remaining; |
| 10347 | let (type_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, n_types.try_to_usize()?)?; |
| 10348 | outer_remaining = remaining; |
| 10349 | Some(type_names) |
| 10350 | } else { |
| 10351 | None |
| 10352 | }; |
| 10353 | let kt_level_names = if switch_expr & u32::from(NameDetail::KT_LEVEL_NAMES) != 0 { |
| 10354 | let (kt_level_names, new_remaining) = SetNamesAuxKTLevelNames::try_parse(outer_remaining, n_types)?; |
| 10355 | outer_remaining = new_remaining; |
| 10356 | Some(kt_level_names) |
| 10357 | } else { |
| 10358 | None |
| 10359 | }; |
| 10360 | let indicator_names = if switch_expr & u32::from(NameDetail::INDICATOR_NAMES) != 0 { |
| 10361 | let remaining = outer_remaining; |
| 10362 | let (indicator_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, u32::from(indicators).count_ones().try_to_usize()?)?; |
| 10363 | outer_remaining = remaining; |
| 10364 | Some(indicator_names) |
| 10365 | } else { |
| 10366 | None |
| 10367 | }; |
| 10368 | let virtual_mod_names = if switch_expr & u32::from(NameDetail::VIRTUAL_MOD_NAMES) != 0 { |
| 10369 | let remaining = outer_remaining; |
| 10370 | let (virtual_mod_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, u32::from(virtual_mods).count_ones().try_to_usize()?)?; |
| 10371 | outer_remaining = remaining; |
| 10372 | Some(virtual_mod_names) |
| 10373 | } else { |
| 10374 | None |
| 10375 | }; |
| 10376 | let groups = if switch_expr & u32::from(NameDetail::GROUP_NAMES) != 0 { |
| 10377 | let remaining = outer_remaining; |
| 10378 | let (groups, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, u32::from(group_names).count_ones().try_to_usize()?)?; |
| 10379 | outer_remaining = remaining; |
| 10380 | Some(groups) |
| 10381 | } else { |
| 10382 | None |
| 10383 | }; |
| 10384 | let key_names = if switch_expr & u32::from(NameDetail::KEY_NAMES) != 0 { |
| 10385 | let remaining = outer_remaining; |
| 10386 | let (key_names, remaining) = crate::x11_utils::parse_list::<KeyName>(remaining, n_keys.try_to_usize()?)?; |
| 10387 | outer_remaining = remaining; |
| 10388 | Some(key_names) |
| 10389 | } else { |
| 10390 | None |
| 10391 | }; |
| 10392 | let key_aliases = if switch_expr & u32::from(NameDetail::KEY_ALIASES) != 0 { |
| 10393 | let remaining = outer_remaining; |
| 10394 | let (key_aliases, remaining) = crate::x11_utils::parse_list::<KeyAlias>(remaining, n_key_aliases.try_to_usize()?)?; |
| 10395 | outer_remaining = remaining; |
| 10396 | Some(key_aliases) |
| 10397 | } else { |
| 10398 | None |
| 10399 | }; |
| 10400 | let radio_group_names = if switch_expr & u32::from(NameDetail::RG_NAMES) != 0 { |
| 10401 | let remaining = outer_remaining; |
| 10402 | let (radio_group_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, n_radio_groups.try_to_usize()?)?; |
| 10403 | outer_remaining = remaining; |
| 10404 | Some(radio_group_names) |
| 10405 | } else { |
| 10406 | None |
| 10407 | }; |
| 10408 | let result = SetNamesAux { keycodes_name, geometry_name, symbols_name, phys_symbols_name, types_name, compat_name, type_names, kt_level_names, indicator_names, virtual_mod_names, groups, key_names, key_aliases, radio_group_names }; |
| 10409 | Ok((result, outer_remaining)) |
| 10410 | } |
| 10411 | } |
| 10412 | impl SetNamesAux { |
| 10413 | #[allow (dead_code)] |
| 10414 | 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> { |
| 10415 | let mut result = Vec::new(); |
| 10416 | self.serialize_into(&mut result, u32::from(which), u8::from(n_types), u32::from(indicators), u16::from(virtual_mods), u8::from(group_names), u8::from(n_keys), u8::from(n_key_aliases), u8::from(n_radio_groups)); |
| 10417 | result |
| 10418 | } |
| 10419 | 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) { |
| 10420 | assert_eq!(self.switch_expr(), u32::from(which), "switch `values` has an inconsistent discriminant" ); |
| 10421 | if let Some(keycodes_name) = self.keycodes_name { |
| 10422 | keycodes_name.serialize_into(bytes); |
| 10423 | } |
| 10424 | if let Some(geometry_name) = self.geometry_name { |
| 10425 | geometry_name.serialize_into(bytes); |
| 10426 | } |
| 10427 | if let Some(symbols_name) = self.symbols_name { |
| 10428 | symbols_name.serialize_into(bytes); |
| 10429 | } |
| 10430 | if let Some(phys_symbols_name) = self.phys_symbols_name { |
| 10431 | phys_symbols_name.serialize_into(bytes); |
| 10432 | } |
| 10433 | if let Some(types_name) = self.types_name { |
| 10434 | types_name.serialize_into(bytes); |
| 10435 | } |
| 10436 | if let Some(compat_name) = self.compat_name { |
| 10437 | compat_name.serialize_into(bytes); |
| 10438 | } |
| 10439 | if let Some(ref type_names) = self.type_names { |
| 10440 | assert_eq!(type_names.len(), usize::try_from(n_types).unwrap(), "`type_names` has an incorrect length" ); |
| 10441 | type_names.serialize_into(bytes); |
| 10442 | } |
| 10443 | if let Some(ref kt_level_names) = self.kt_level_names { |
| 10444 | kt_level_names.serialize_into(bytes, u8::from(n_types)); |
| 10445 | } |
| 10446 | if let Some(ref indicator_names) = self.indicator_names { |
| 10447 | assert_eq!(indicator_names.len(), usize::try_from(u32::from(indicators).count_ones()).unwrap(), "`indicator_names` has an incorrect length" ); |
| 10448 | indicator_names.serialize_into(bytes); |
| 10449 | } |
| 10450 | if let Some(ref virtual_mod_names) = self.virtual_mod_names { |
| 10451 | assert_eq!(virtual_mod_names.len(), usize::try_from(u32::from(virtual_mods).count_ones()).unwrap(), "`virtual_mod_names` has an incorrect length" ); |
| 10452 | virtual_mod_names.serialize_into(bytes); |
| 10453 | } |
| 10454 | if let Some(ref groups) = self.groups { |
| 10455 | assert_eq!(groups.len(), usize::try_from(u32::from(group_names).count_ones()).unwrap(), "`groups` has an incorrect length" ); |
| 10456 | groups.serialize_into(bytes); |
| 10457 | } |
| 10458 | if let Some(ref key_names) = self.key_names { |
| 10459 | assert_eq!(key_names.len(), usize::try_from(n_keys).unwrap(), "`key_names` has an incorrect length" ); |
| 10460 | key_names.serialize_into(bytes); |
| 10461 | } |
| 10462 | if let Some(ref key_aliases) = self.key_aliases { |
| 10463 | assert_eq!(key_aliases.len(), usize::try_from(n_key_aliases).unwrap(), "`key_aliases` has an incorrect length" ); |
| 10464 | key_aliases.serialize_into(bytes); |
| 10465 | } |
| 10466 | if let Some(ref radio_group_names) = self.radio_group_names { |
| 10467 | assert_eq!(radio_group_names.len(), usize::try_from(n_radio_groups).unwrap(), "`radio_group_names` has an incorrect length" ); |
| 10468 | radio_group_names.serialize_into(bytes); |
| 10469 | } |
| 10470 | } |
| 10471 | } |
| 10472 | impl SetNamesAux { |
| 10473 | fn switch_expr(&self) -> u32 { |
| 10474 | let mut expr_value = 0; |
| 10475 | if self.keycodes_name.is_some() { |
| 10476 | expr_value |= u32::from(NameDetail::KEYCODES); |
| 10477 | } |
| 10478 | if self.geometry_name.is_some() { |
| 10479 | expr_value |= u32::from(NameDetail::GEOMETRY); |
| 10480 | } |
| 10481 | if self.symbols_name.is_some() { |
| 10482 | expr_value |= u32::from(NameDetail::SYMBOLS); |
| 10483 | } |
| 10484 | if self.phys_symbols_name.is_some() { |
| 10485 | expr_value |= u32::from(NameDetail::PHYS_SYMBOLS); |
| 10486 | } |
| 10487 | if self.types_name.is_some() { |
| 10488 | expr_value |= u32::from(NameDetail::TYPES); |
| 10489 | } |
| 10490 | if self.compat_name.is_some() { |
| 10491 | expr_value |= u32::from(NameDetail::COMPAT); |
| 10492 | } |
| 10493 | if self.type_names.is_some() { |
| 10494 | expr_value |= u32::from(NameDetail::KEY_TYPE_NAMES); |
| 10495 | } |
| 10496 | if self.kt_level_names.is_some() { |
| 10497 | expr_value |= u32::from(NameDetail::KT_LEVEL_NAMES); |
| 10498 | } |
| 10499 | if self.indicator_names.is_some() { |
| 10500 | expr_value |= u32::from(NameDetail::INDICATOR_NAMES); |
| 10501 | } |
| 10502 | if self.virtual_mod_names.is_some() { |
| 10503 | expr_value |= u32::from(NameDetail::VIRTUAL_MOD_NAMES); |
| 10504 | } |
| 10505 | if self.groups.is_some() { |
| 10506 | expr_value |= u32::from(NameDetail::GROUP_NAMES); |
| 10507 | } |
| 10508 | if self.key_names.is_some() { |
| 10509 | expr_value |= u32::from(NameDetail::KEY_NAMES); |
| 10510 | } |
| 10511 | if self.key_aliases.is_some() { |
| 10512 | expr_value |= u32::from(NameDetail::KEY_ALIASES); |
| 10513 | } |
| 10514 | if self.radio_group_names.is_some() { |
| 10515 | expr_value |= u32::from(NameDetail::RG_NAMES); |
| 10516 | } |
| 10517 | expr_value |
| 10518 | } |
| 10519 | } |
| 10520 | impl SetNamesAux { |
| 10521 | /// Create a new instance with all fields unset / not present. |
| 10522 | pub fn new() -> Self { |
| 10523 | Default::default() |
| 10524 | } |
| 10525 | /// Set the `keycodes_name` field of this structure. |
| 10526 | #[must_use ] |
| 10527 | pub fn keycodes_name<I>(mut self, value: I) -> Self where I: Into<Option<xproto::Atom>> { |
| 10528 | self.keycodes_name = value.into(); |
| 10529 | self |
| 10530 | } |
| 10531 | /// Set the `geometry_name` field of this structure. |
| 10532 | #[must_use ] |
| 10533 | pub fn geometry_name<I>(mut self, value: I) -> Self where I: Into<Option<xproto::Atom>> { |
| 10534 | self.geometry_name = value.into(); |
| 10535 | self |
| 10536 | } |
| 10537 | /// Set the `symbols_name` field of this structure. |
| 10538 | #[must_use ] |
| 10539 | pub fn symbols_name<I>(mut self, value: I) -> Self where I: Into<Option<xproto::Atom>> { |
| 10540 | self.symbols_name = value.into(); |
| 10541 | self |
| 10542 | } |
| 10543 | /// Set the `phys_symbols_name` field of this structure. |
| 10544 | #[must_use ] |
| 10545 | pub fn phys_symbols_name<I>(mut self, value: I) -> Self where I: Into<Option<xproto::Atom>> { |
| 10546 | self.phys_symbols_name = value.into(); |
| 10547 | self |
| 10548 | } |
| 10549 | /// Set the `types_name` field of this structure. |
| 10550 | #[must_use ] |
| 10551 | pub fn types_name<I>(mut self, value: I) -> Self where I: Into<Option<xproto::Atom>> { |
| 10552 | self.types_name = value.into(); |
| 10553 | self |
| 10554 | } |
| 10555 | /// Set the `compat_name` field of this structure. |
| 10556 | #[must_use ] |
| 10557 | pub fn compat_name<I>(mut self, value: I) -> Self where I: Into<Option<xproto::Atom>> { |
| 10558 | self.compat_name = value.into(); |
| 10559 | self |
| 10560 | } |
| 10561 | /// Set the `type_names` field of this structure. |
| 10562 | #[must_use ] |
| 10563 | pub fn type_names<I>(mut self, value: I) -> Self where I: Into<Option<Vec<xproto::Atom>>> { |
| 10564 | self.type_names = value.into(); |
| 10565 | self |
| 10566 | } |
| 10567 | /// Set the `kt_level_names` field of this structure. |
| 10568 | #[must_use ] |
| 10569 | pub fn kt_level_names<I>(mut self, value: I) -> Self where I: Into<Option<SetNamesAuxKTLevelNames>> { |
| 10570 | self.kt_level_names = value.into(); |
| 10571 | self |
| 10572 | } |
| 10573 | /// Set the `indicator_names` field of this structure. |
| 10574 | #[must_use ] |
| 10575 | pub fn indicator_names<I>(mut self, value: I) -> Self where I: Into<Option<Vec<xproto::Atom>>> { |
| 10576 | self.indicator_names = value.into(); |
| 10577 | self |
| 10578 | } |
| 10579 | /// Set the `virtual_mod_names` field of this structure. |
| 10580 | #[must_use ] |
| 10581 | pub fn virtual_mod_names<I>(mut self, value: I) -> Self where I: Into<Option<Vec<xproto::Atom>>> { |
| 10582 | self.virtual_mod_names = value.into(); |
| 10583 | self |
| 10584 | } |
| 10585 | /// Set the `groups` field of this structure. |
| 10586 | #[must_use ] |
| 10587 | pub fn groups<I>(mut self, value: I) -> Self where I: Into<Option<Vec<xproto::Atom>>> { |
| 10588 | self.groups = value.into(); |
| 10589 | self |
| 10590 | } |
| 10591 | /// Set the `key_names` field of this structure. |
| 10592 | #[must_use ] |
| 10593 | pub fn key_names<I>(mut self, value: I) -> Self where I: Into<Option<Vec<KeyName>>> { |
| 10594 | self.key_names = value.into(); |
| 10595 | self |
| 10596 | } |
| 10597 | /// Set the `key_aliases` field of this structure. |
| 10598 | #[must_use ] |
| 10599 | pub fn key_aliases<I>(mut self, value: I) -> Self where I: Into<Option<Vec<KeyAlias>>> { |
| 10600 | self.key_aliases = value.into(); |
| 10601 | self |
| 10602 | } |
| 10603 | /// Set the `radio_group_names` field of this structure. |
| 10604 | #[must_use ] |
| 10605 | pub fn radio_group_names<I>(mut self, value: I) -> Self where I: Into<Option<Vec<xproto::Atom>>> { |
| 10606 | self.radio_group_names = value.into(); |
| 10607 | self |
| 10608 | } |
| 10609 | } |
| 10610 | |
| 10611 | /// Opcode for the SetNames request |
| 10612 | pub const SET_NAMES_REQUEST: u8 = 18; |
| 10613 | #[derive (Clone, Default)] |
| 10614 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 10615 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 10616 | pub struct SetNamesRequest<'input> { |
| 10617 | pub device_spec: DeviceSpec, |
| 10618 | pub virtual_mods: VMod, |
| 10619 | pub first_type: u8, |
| 10620 | pub n_types: u8, |
| 10621 | pub first_kt_levelt: u8, |
| 10622 | pub n_kt_levels: u8, |
| 10623 | pub indicators: u32, |
| 10624 | pub group_names: SetOfGroup, |
| 10625 | pub n_radio_groups: u8, |
| 10626 | pub first_key: xproto::Keycode, |
| 10627 | pub n_keys: u8, |
| 10628 | pub n_key_aliases: u8, |
| 10629 | pub total_kt_level_names: u16, |
| 10630 | pub values: Cow<'input, SetNamesAux>, |
| 10631 | } |
| 10632 | impl_debug_if_no_extra_traits!(SetNamesRequest<'_>, "SetNamesRequest" ); |
| 10633 | impl<'input> SetNamesRequest<'input> { |
| 10634 | /// Serialize this request into bytes for the provided connection |
| 10635 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 10636 | let length_so_far = 0; |
| 10637 | let device_spec_bytes = self.device_spec.serialize(); |
| 10638 | let virtual_mods_bytes = u16::from(self.virtual_mods).serialize(); |
| 10639 | let which: u32 = self.values.switch_expr(); |
| 10640 | let which_bytes = which.serialize(); |
| 10641 | let first_type_bytes = self.first_type.serialize(); |
| 10642 | let n_types_bytes = self.n_types.serialize(); |
| 10643 | let first_kt_levelt_bytes = self.first_kt_levelt.serialize(); |
| 10644 | let n_kt_levels_bytes = self.n_kt_levels.serialize(); |
| 10645 | let indicators_bytes = self.indicators.serialize(); |
| 10646 | let group_names_bytes = u8::from(self.group_names).serialize(); |
| 10647 | let n_radio_groups_bytes = self.n_radio_groups.serialize(); |
| 10648 | let first_key_bytes = self.first_key.serialize(); |
| 10649 | let n_keys_bytes = self.n_keys.serialize(); |
| 10650 | let n_key_aliases_bytes = self.n_key_aliases.serialize(); |
| 10651 | let total_kt_level_names_bytes = self.total_kt_level_names.serialize(); |
| 10652 | let mut request0 = vec![ |
| 10653 | major_opcode, |
| 10654 | SET_NAMES_REQUEST, |
| 10655 | 0, |
| 10656 | 0, |
| 10657 | device_spec_bytes[0], |
| 10658 | device_spec_bytes[1], |
| 10659 | virtual_mods_bytes[0], |
| 10660 | virtual_mods_bytes[1], |
| 10661 | which_bytes[0], |
| 10662 | which_bytes[1], |
| 10663 | which_bytes[2], |
| 10664 | which_bytes[3], |
| 10665 | first_type_bytes[0], |
| 10666 | n_types_bytes[0], |
| 10667 | first_kt_levelt_bytes[0], |
| 10668 | n_kt_levels_bytes[0], |
| 10669 | indicators_bytes[0], |
| 10670 | indicators_bytes[1], |
| 10671 | indicators_bytes[2], |
| 10672 | indicators_bytes[3], |
| 10673 | group_names_bytes[0], |
| 10674 | n_radio_groups_bytes[0], |
| 10675 | first_key_bytes[0], |
| 10676 | n_keys_bytes[0], |
| 10677 | n_key_aliases_bytes[0], |
| 10678 | 0, |
| 10679 | total_kt_level_names_bytes[0], |
| 10680 | total_kt_level_names_bytes[1], |
| 10681 | ]; |
| 10682 | let length_so_far = length_so_far + request0.len(); |
| 10683 | let values_bytes = self.values.serialize(u32::from(which), u8::from(self.n_types), u32::from(self.indicators), u16::from(self.virtual_mods), u8::from(self.group_names), u8::from(self.n_keys), u8::from(self.n_key_aliases), u8::from(self.n_radio_groups)); |
| 10684 | let length_so_far = length_so_far + values_bytes.len(); |
| 10685 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 10686 | let length_so_far = length_so_far + padding0.len(); |
| 10687 | assert_eq!(length_so_far % 4, 0); |
| 10688 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 10689 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 10690 | ([request0.into(), values_bytes.into(), padding0.into()], vec![]) |
| 10691 | } |
| 10692 | /// Parse this request given its header, its body, and any fds that go along with it |
| 10693 | #[cfg (feature = "request-parsing" )] |
| 10694 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 10695 | if header.minor_opcode != SET_NAMES_REQUEST { |
| 10696 | return Err(ParseError::InvalidValue); |
| 10697 | } |
| 10698 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 10699 | let (virtual_mods, remaining) = u16::try_parse(remaining)?; |
| 10700 | let virtual_mods = virtual_mods.into(); |
| 10701 | let (which, remaining) = u32::try_parse(remaining)?; |
| 10702 | let (first_type, remaining) = u8::try_parse(remaining)?; |
| 10703 | let (n_types, remaining) = u8::try_parse(remaining)?; |
| 10704 | let (first_kt_levelt, remaining) = u8::try_parse(remaining)?; |
| 10705 | let (n_kt_levels, remaining) = u8::try_parse(remaining)?; |
| 10706 | let (indicators, remaining) = u32::try_parse(remaining)?; |
| 10707 | let (group_names, remaining) = u8::try_parse(remaining)?; |
| 10708 | let group_names = group_names.into(); |
| 10709 | let (n_radio_groups, remaining) = u8::try_parse(remaining)?; |
| 10710 | let (first_key, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 10711 | let (n_keys, remaining) = u8::try_parse(remaining)?; |
| 10712 | let (n_key_aliases, remaining) = u8::try_parse(remaining)?; |
| 10713 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 10714 | let (total_kt_level_names, remaining) = u16::try_parse(remaining)?; |
| 10715 | let (values, remaining) = SetNamesAux::try_parse(remaining, u32::from(which), u8::from(n_types), u32::from(indicators), u16::from(virtual_mods), u8::from(group_names), u8::from(n_keys), u8::from(n_key_aliases), u8::from(n_radio_groups))?; |
| 10716 | let _ = remaining; |
| 10717 | Ok(SetNamesRequest { |
| 10718 | device_spec, |
| 10719 | virtual_mods, |
| 10720 | first_type, |
| 10721 | n_types, |
| 10722 | first_kt_levelt, |
| 10723 | n_kt_levels, |
| 10724 | indicators, |
| 10725 | group_names, |
| 10726 | n_radio_groups, |
| 10727 | first_key, |
| 10728 | n_keys, |
| 10729 | n_key_aliases, |
| 10730 | total_kt_level_names, |
| 10731 | values: Cow::Owned(values), |
| 10732 | }) |
| 10733 | } |
| 10734 | /// Clone all borrowed data in this SetNamesRequest. |
| 10735 | pub fn into_owned(self) -> SetNamesRequest<'static> { |
| 10736 | SetNamesRequest { |
| 10737 | device_spec: self.device_spec, |
| 10738 | virtual_mods: self.virtual_mods, |
| 10739 | first_type: self.first_type, |
| 10740 | n_types: self.n_types, |
| 10741 | first_kt_levelt: self.first_kt_levelt, |
| 10742 | n_kt_levels: self.n_kt_levels, |
| 10743 | indicators: self.indicators, |
| 10744 | group_names: self.group_names, |
| 10745 | n_radio_groups: self.n_radio_groups, |
| 10746 | first_key: self.first_key, |
| 10747 | n_keys: self.n_keys, |
| 10748 | n_key_aliases: self.n_key_aliases, |
| 10749 | total_kt_level_names: self.total_kt_level_names, |
| 10750 | values: Cow::Owned(self.values.into_owned()), |
| 10751 | } |
| 10752 | } |
| 10753 | } |
| 10754 | impl<'input> Request for SetNamesRequest<'input> { |
| 10755 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 10756 | |
| 10757 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 10758 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(major_opcode); |
| 10759 | // Flatten the buffers into a single vector |
| 10760 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 10761 | (buf, fds) |
| 10762 | } |
| 10763 | } |
| 10764 | impl<'input> crate::x11_utils::VoidRequest for SetNamesRequest<'input> { |
| 10765 | } |
| 10766 | |
| 10767 | /// Opcode for the PerClientFlags request |
| 10768 | pub const PER_CLIENT_FLAGS_REQUEST: u8 = 21; |
| 10769 | #[derive (Clone, Copy, Default)] |
| 10770 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 10771 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 10772 | pub struct PerClientFlagsRequest { |
| 10773 | pub device_spec: DeviceSpec, |
| 10774 | pub change: PerClientFlag, |
| 10775 | pub value: PerClientFlag, |
| 10776 | pub ctrls_to_change: BoolCtrl, |
| 10777 | pub auto_ctrls: BoolCtrl, |
| 10778 | pub auto_ctrls_values: BoolCtrl, |
| 10779 | } |
| 10780 | impl_debug_if_no_extra_traits!(PerClientFlagsRequest, "PerClientFlagsRequest" ); |
| 10781 | impl PerClientFlagsRequest { |
| 10782 | /// Serialize this request into bytes for the provided connection |
| 10783 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 10784 | let length_so_far = 0; |
| 10785 | let device_spec_bytes = self.device_spec.serialize(); |
| 10786 | let change_bytes = u32::from(self.change).serialize(); |
| 10787 | let value_bytes = u32::from(self.value).serialize(); |
| 10788 | let ctrls_to_change_bytes = u32::from(self.ctrls_to_change).serialize(); |
| 10789 | let auto_ctrls_bytes = u32::from(self.auto_ctrls).serialize(); |
| 10790 | let auto_ctrls_values_bytes = u32::from(self.auto_ctrls_values).serialize(); |
| 10791 | let mut request0 = vec![ |
| 10792 | major_opcode, |
| 10793 | PER_CLIENT_FLAGS_REQUEST, |
| 10794 | 0, |
| 10795 | 0, |
| 10796 | device_spec_bytes[0], |
| 10797 | device_spec_bytes[1], |
| 10798 | 0, |
| 10799 | 0, |
| 10800 | change_bytes[0], |
| 10801 | change_bytes[1], |
| 10802 | change_bytes[2], |
| 10803 | change_bytes[3], |
| 10804 | value_bytes[0], |
| 10805 | value_bytes[1], |
| 10806 | value_bytes[2], |
| 10807 | value_bytes[3], |
| 10808 | ctrls_to_change_bytes[0], |
| 10809 | ctrls_to_change_bytes[1], |
| 10810 | ctrls_to_change_bytes[2], |
| 10811 | ctrls_to_change_bytes[3], |
| 10812 | auto_ctrls_bytes[0], |
| 10813 | auto_ctrls_bytes[1], |
| 10814 | auto_ctrls_bytes[2], |
| 10815 | auto_ctrls_bytes[3], |
| 10816 | auto_ctrls_values_bytes[0], |
| 10817 | auto_ctrls_values_bytes[1], |
| 10818 | auto_ctrls_values_bytes[2], |
| 10819 | auto_ctrls_values_bytes[3], |
| 10820 | ]; |
| 10821 | let length_so_far = length_so_far + request0.len(); |
| 10822 | assert_eq!(length_so_far % 4, 0); |
| 10823 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 10824 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 10825 | ([request0.into()], vec![]) |
| 10826 | } |
| 10827 | /// Parse this request given its header, its body, and any fds that go along with it |
| 10828 | #[cfg (feature = "request-parsing" )] |
| 10829 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 10830 | if header.minor_opcode != PER_CLIENT_FLAGS_REQUEST { |
| 10831 | return Err(ParseError::InvalidValue); |
| 10832 | } |
| 10833 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 10834 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 10835 | let (change, remaining) = u32::try_parse(remaining)?; |
| 10836 | let change = change.into(); |
| 10837 | let (value, remaining) = u32::try_parse(remaining)?; |
| 10838 | let value = value.into(); |
| 10839 | let (ctrls_to_change, remaining) = u32::try_parse(remaining)?; |
| 10840 | let ctrls_to_change = ctrls_to_change.into(); |
| 10841 | let (auto_ctrls, remaining) = u32::try_parse(remaining)?; |
| 10842 | let auto_ctrls = auto_ctrls.into(); |
| 10843 | let (auto_ctrls_values, remaining) = u32::try_parse(remaining)?; |
| 10844 | let auto_ctrls_values = auto_ctrls_values.into(); |
| 10845 | let _ = remaining; |
| 10846 | Ok(PerClientFlagsRequest { |
| 10847 | device_spec, |
| 10848 | change, |
| 10849 | value, |
| 10850 | ctrls_to_change, |
| 10851 | auto_ctrls, |
| 10852 | auto_ctrls_values, |
| 10853 | }) |
| 10854 | } |
| 10855 | } |
| 10856 | impl Request for PerClientFlagsRequest { |
| 10857 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 10858 | |
| 10859 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 10860 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 10861 | // Flatten the buffers into a single vector |
| 10862 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 10863 | (buf, fds) |
| 10864 | } |
| 10865 | } |
| 10866 | impl crate::x11_utils::ReplyRequest for PerClientFlagsRequest { |
| 10867 | type Reply = PerClientFlagsReply; |
| 10868 | } |
| 10869 | |
| 10870 | #[derive (Clone, Copy, Default)] |
| 10871 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 10872 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 10873 | pub struct PerClientFlagsReply { |
| 10874 | pub device_id: u8, |
| 10875 | pub sequence: u16, |
| 10876 | pub length: u32, |
| 10877 | pub supported: PerClientFlag, |
| 10878 | pub value: PerClientFlag, |
| 10879 | pub auto_ctrls: BoolCtrl, |
| 10880 | pub auto_ctrls_values: BoolCtrl, |
| 10881 | } |
| 10882 | impl_debug_if_no_extra_traits!(PerClientFlagsReply, "PerClientFlagsReply" ); |
| 10883 | impl TryParse for PerClientFlagsReply { |
| 10884 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 10885 | let remaining = initial_value; |
| 10886 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 10887 | let (device_id, remaining) = u8::try_parse(remaining)?; |
| 10888 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 10889 | let (length, remaining) = u32::try_parse(remaining)?; |
| 10890 | let (supported, remaining) = u32::try_parse(remaining)?; |
| 10891 | let (value, remaining) = u32::try_parse(remaining)?; |
| 10892 | let (auto_ctrls, remaining) = u32::try_parse(remaining)?; |
| 10893 | let (auto_ctrls_values, remaining) = u32::try_parse(remaining)?; |
| 10894 | let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?; |
| 10895 | if response_type != 1 { |
| 10896 | return Err(ParseError::InvalidValue); |
| 10897 | } |
| 10898 | let supported = supported.into(); |
| 10899 | let value = value.into(); |
| 10900 | let auto_ctrls = auto_ctrls.into(); |
| 10901 | let auto_ctrls_values = auto_ctrls_values.into(); |
| 10902 | let result = PerClientFlagsReply { device_id, sequence, length, supported, value, auto_ctrls, auto_ctrls_values }; |
| 10903 | let _ = remaining; |
| 10904 | let remaining = initial_value.get(32 + length as usize * 4..) |
| 10905 | .ok_or(ParseError::InsufficientData)?; |
| 10906 | Ok((result, remaining)) |
| 10907 | } |
| 10908 | } |
| 10909 | impl Serialize for PerClientFlagsReply { |
| 10910 | type Bytes = [u8; 32]; |
| 10911 | fn serialize(&self) -> [u8; 32] { |
| 10912 | let response_type_bytes = &[1]; |
| 10913 | let device_id_bytes = self.device_id.serialize(); |
| 10914 | let sequence_bytes = self.sequence.serialize(); |
| 10915 | let length_bytes = self.length.serialize(); |
| 10916 | let supported_bytes = u32::from(self.supported).serialize(); |
| 10917 | let value_bytes = u32::from(self.value).serialize(); |
| 10918 | let auto_ctrls_bytes = u32::from(self.auto_ctrls).serialize(); |
| 10919 | let auto_ctrls_values_bytes = u32::from(self.auto_ctrls_values).serialize(); |
| 10920 | [ |
| 10921 | response_type_bytes[0], |
| 10922 | device_id_bytes[0], |
| 10923 | sequence_bytes[0], |
| 10924 | sequence_bytes[1], |
| 10925 | length_bytes[0], |
| 10926 | length_bytes[1], |
| 10927 | length_bytes[2], |
| 10928 | length_bytes[3], |
| 10929 | supported_bytes[0], |
| 10930 | supported_bytes[1], |
| 10931 | supported_bytes[2], |
| 10932 | supported_bytes[3], |
| 10933 | value_bytes[0], |
| 10934 | value_bytes[1], |
| 10935 | value_bytes[2], |
| 10936 | value_bytes[3], |
| 10937 | auto_ctrls_bytes[0], |
| 10938 | auto_ctrls_bytes[1], |
| 10939 | auto_ctrls_bytes[2], |
| 10940 | auto_ctrls_bytes[3], |
| 10941 | auto_ctrls_values_bytes[0], |
| 10942 | auto_ctrls_values_bytes[1], |
| 10943 | auto_ctrls_values_bytes[2], |
| 10944 | auto_ctrls_values_bytes[3], |
| 10945 | 0, |
| 10946 | 0, |
| 10947 | 0, |
| 10948 | 0, |
| 10949 | 0, |
| 10950 | 0, |
| 10951 | 0, |
| 10952 | 0, |
| 10953 | ] |
| 10954 | } |
| 10955 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 10956 | bytes.reserve(32); |
| 10957 | let response_type_bytes = &[1]; |
| 10958 | bytes.push(response_type_bytes[0]); |
| 10959 | self.device_id.serialize_into(bytes); |
| 10960 | self.sequence.serialize_into(bytes); |
| 10961 | self.length.serialize_into(bytes); |
| 10962 | u32::from(self.supported).serialize_into(bytes); |
| 10963 | u32::from(self.value).serialize_into(bytes); |
| 10964 | u32::from(self.auto_ctrls).serialize_into(bytes); |
| 10965 | u32::from(self.auto_ctrls_values).serialize_into(bytes); |
| 10966 | bytes.extend_from_slice(&[0; 8]); |
| 10967 | } |
| 10968 | } |
| 10969 | |
| 10970 | /// Opcode for the ListComponents request |
| 10971 | pub const LIST_COMPONENTS_REQUEST: u8 = 22; |
| 10972 | #[derive (Clone, Copy, Default)] |
| 10973 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 10974 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 10975 | pub struct ListComponentsRequest { |
| 10976 | pub device_spec: DeviceSpec, |
| 10977 | pub max_names: u16, |
| 10978 | } |
| 10979 | impl_debug_if_no_extra_traits!(ListComponentsRequest, "ListComponentsRequest" ); |
| 10980 | impl ListComponentsRequest { |
| 10981 | /// Serialize this request into bytes for the provided connection |
| 10982 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 10983 | let length_so_far = 0; |
| 10984 | let device_spec_bytes = self.device_spec.serialize(); |
| 10985 | let max_names_bytes = self.max_names.serialize(); |
| 10986 | let mut request0 = vec![ |
| 10987 | major_opcode, |
| 10988 | LIST_COMPONENTS_REQUEST, |
| 10989 | 0, |
| 10990 | 0, |
| 10991 | device_spec_bytes[0], |
| 10992 | device_spec_bytes[1], |
| 10993 | max_names_bytes[0], |
| 10994 | max_names_bytes[1], |
| 10995 | ]; |
| 10996 | let length_so_far = length_so_far + request0.len(); |
| 10997 | assert_eq!(length_so_far % 4, 0); |
| 10998 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 10999 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 11000 | ([request0.into()], vec![]) |
| 11001 | } |
| 11002 | /// Parse this request given its header, its body, and any fds that go along with it |
| 11003 | #[cfg (feature = "request-parsing" )] |
| 11004 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 11005 | if header.minor_opcode != LIST_COMPONENTS_REQUEST { |
| 11006 | return Err(ParseError::InvalidValue); |
| 11007 | } |
| 11008 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 11009 | let (max_names, remaining) = u16::try_parse(remaining)?; |
| 11010 | let _ = remaining; |
| 11011 | Ok(ListComponentsRequest { |
| 11012 | device_spec, |
| 11013 | max_names, |
| 11014 | }) |
| 11015 | } |
| 11016 | } |
| 11017 | impl Request for ListComponentsRequest { |
| 11018 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 11019 | |
| 11020 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 11021 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 11022 | // Flatten the buffers into a single vector |
| 11023 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 11024 | (buf, fds) |
| 11025 | } |
| 11026 | } |
| 11027 | impl crate::x11_utils::ReplyRequest for ListComponentsRequest { |
| 11028 | type Reply = ListComponentsReply; |
| 11029 | } |
| 11030 | |
| 11031 | #[derive (Clone, Default)] |
| 11032 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 11033 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11034 | pub struct ListComponentsReply { |
| 11035 | pub device_id: u8, |
| 11036 | pub sequence: u16, |
| 11037 | pub length: u32, |
| 11038 | pub extra: u16, |
| 11039 | pub keymaps: Vec<Listing>, |
| 11040 | pub keycodes: Vec<Listing>, |
| 11041 | pub types: Vec<Listing>, |
| 11042 | pub compat_maps: Vec<Listing>, |
| 11043 | pub symbols: Vec<Listing>, |
| 11044 | pub geometries: Vec<Listing>, |
| 11045 | } |
| 11046 | impl_debug_if_no_extra_traits!(ListComponentsReply, "ListComponentsReply" ); |
| 11047 | impl TryParse for ListComponentsReply { |
| 11048 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 11049 | let remaining = initial_value; |
| 11050 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 11051 | let (device_id, remaining) = u8::try_parse(remaining)?; |
| 11052 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 11053 | let (length, remaining) = u32::try_parse(remaining)?; |
| 11054 | let (n_keymaps, remaining) = u16::try_parse(remaining)?; |
| 11055 | let (n_keycodes, remaining) = u16::try_parse(remaining)?; |
| 11056 | let (n_types, remaining) = u16::try_parse(remaining)?; |
| 11057 | let (n_compat_maps, remaining) = u16::try_parse(remaining)?; |
| 11058 | let (n_symbols, remaining) = u16::try_parse(remaining)?; |
| 11059 | let (n_geometries, remaining) = u16::try_parse(remaining)?; |
| 11060 | let (extra, remaining) = u16::try_parse(remaining)?; |
| 11061 | let remaining = remaining.get(10..).ok_or(ParseError::InsufficientData)?; |
| 11062 | let (keymaps, remaining) = crate::x11_utils::parse_list::<Listing>(remaining, n_keymaps.try_to_usize()?)?; |
| 11063 | let (keycodes, remaining) = crate::x11_utils::parse_list::<Listing>(remaining, n_keycodes.try_to_usize()?)?; |
| 11064 | let (types, remaining) = crate::x11_utils::parse_list::<Listing>(remaining, n_types.try_to_usize()?)?; |
| 11065 | let (compat_maps, remaining) = crate::x11_utils::parse_list::<Listing>(remaining, n_compat_maps.try_to_usize()?)?; |
| 11066 | let (symbols, remaining) = crate::x11_utils::parse_list::<Listing>(remaining, n_symbols.try_to_usize()?)?; |
| 11067 | let (geometries, remaining) = crate::x11_utils::parse_list::<Listing>(remaining, n_geometries.try_to_usize()?)?; |
| 11068 | if response_type != 1 { |
| 11069 | return Err(ParseError::InvalidValue); |
| 11070 | } |
| 11071 | let result = ListComponentsReply { device_id, sequence, length, extra, keymaps, keycodes, types, compat_maps, symbols, geometries }; |
| 11072 | let _ = remaining; |
| 11073 | let remaining = initial_value.get(32 + length as usize * 4..) |
| 11074 | .ok_or(ParseError::InsufficientData)?; |
| 11075 | Ok((result, remaining)) |
| 11076 | } |
| 11077 | } |
| 11078 | impl Serialize for ListComponentsReply { |
| 11079 | type Bytes = Vec<u8>; |
| 11080 | fn serialize(&self) -> Vec<u8> { |
| 11081 | let mut result = Vec::new(); |
| 11082 | self.serialize_into(&mut result); |
| 11083 | result |
| 11084 | } |
| 11085 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 11086 | bytes.reserve(32); |
| 11087 | let response_type_bytes = &[1]; |
| 11088 | bytes.push(response_type_bytes[0]); |
| 11089 | self.device_id.serialize_into(bytes); |
| 11090 | self.sequence.serialize_into(bytes); |
| 11091 | self.length.serialize_into(bytes); |
| 11092 | let n_keymaps = u16::try_from(self.keymaps.len()).expect("`keymaps` has too many elements" ); |
| 11093 | n_keymaps.serialize_into(bytes); |
| 11094 | let n_keycodes = u16::try_from(self.keycodes.len()).expect("`keycodes` has too many elements" ); |
| 11095 | n_keycodes.serialize_into(bytes); |
| 11096 | let n_types = u16::try_from(self.types.len()).expect("`types` has too many elements" ); |
| 11097 | n_types.serialize_into(bytes); |
| 11098 | let n_compat_maps = u16::try_from(self.compat_maps.len()).expect("`compat_maps` has too many elements" ); |
| 11099 | n_compat_maps.serialize_into(bytes); |
| 11100 | let n_symbols = u16::try_from(self.symbols.len()).expect("`symbols` has too many elements" ); |
| 11101 | n_symbols.serialize_into(bytes); |
| 11102 | let n_geometries = u16::try_from(self.geometries.len()).expect("`geometries` has too many elements" ); |
| 11103 | n_geometries.serialize_into(bytes); |
| 11104 | self.extra.serialize_into(bytes); |
| 11105 | bytes.extend_from_slice(&[0; 10]); |
| 11106 | self.keymaps.serialize_into(bytes); |
| 11107 | self.keycodes.serialize_into(bytes); |
| 11108 | self.types.serialize_into(bytes); |
| 11109 | self.compat_maps.serialize_into(bytes); |
| 11110 | self.symbols.serialize_into(bytes); |
| 11111 | self.geometries.serialize_into(bytes); |
| 11112 | } |
| 11113 | } |
| 11114 | impl ListComponentsReply { |
| 11115 | /// Get the value of the `nKeymaps` field. |
| 11116 | /// |
| 11117 | /// The `nKeymaps` field is used as the length field of the `keymaps` field. |
| 11118 | /// This function computes the field's value again based on the length of the list. |
| 11119 | /// |
| 11120 | /// # Panics |
| 11121 | /// |
| 11122 | /// Panics if the value cannot be represented in the target type. This |
| 11123 | /// cannot happen with values of the struct received from the X11 server. |
| 11124 | pub fn n_keymaps(&self) -> u16 { |
| 11125 | self.keymaps.len() |
| 11126 | .try_into().unwrap() |
| 11127 | } |
| 11128 | /// Get the value of the `nKeycodes` field. |
| 11129 | /// |
| 11130 | /// The `nKeycodes` field is used as the length field of the `keycodes` field. |
| 11131 | /// This function computes the field's value again based on the length of the list. |
| 11132 | /// |
| 11133 | /// # Panics |
| 11134 | /// |
| 11135 | /// Panics if the value cannot be represented in the target type. This |
| 11136 | /// cannot happen with values of the struct received from the X11 server. |
| 11137 | pub fn n_keycodes(&self) -> u16 { |
| 11138 | self.keycodes.len() |
| 11139 | .try_into().unwrap() |
| 11140 | } |
| 11141 | /// Get the value of the `nTypes` field. |
| 11142 | /// |
| 11143 | /// The `nTypes` field is used as the length field of the `types` field. |
| 11144 | /// This function computes the field's value again based on the length of the list. |
| 11145 | /// |
| 11146 | /// # Panics |
| 11147 | /// |
| 11148 | /// Panics if the value cannot be represented in the target type. This |
| 11149 | /// cannot happen with values of the struct received from the X11 server. |
| 11150 | pub fn n_types(&self) -> u16 { |
| 11151 | self.types.len() |
| 11152 | .try_into().unwrap() |
| 11153 | } |
| 11154 | /// Get the value of the `nCompatMaps` field. |
| 11155 | /// |
| 11156 | /// The `nCompatMaps` field is used as the length field of the `compatMaps` field. |
| 11157 | /// This function computes the field's value again based on the length of the list. |
| 11158 | /// |
| 11159 | /// # Panics |
| 11160 | /// |
| 11161 | /// Panics if the value cannot be represented in the target type. This |
| 11162 | /// cannot happen with values of the struct received from the X11 server. |
| 11163 | pub fn n_compat_maps(&self) -> u16 { |
| 11164 | self.compat_maps.len() |
| 11165 | .try_into().unwrap() |
| 11166 | } |
| 11167 | /// Get the value of the `nSymbols` field. |
| 11168 | /// |
| 11169 | /// The `nSymbols` field is used as the length field of the `symbols` field. |
| 11170 | /// This function computes the field's value again based on the length of the list. |
| 11171 | /// |
| 11172 | /// # Panics |
| 11173 | /// |
| 11174 | /// Panics if the value cannot be represented in the target type. This |
| 11175 | /// cannot happen with values of the struct received from the X11 server. |
| 11176 | pub fn n_symbols(&self) -> u16 { |
| 11177 | self.symbols.len() |
| 11178 | .try_into().unwrap() |
| 11179 | } |
| 11180 | /// Get the value of the `nGeometries` field. |
| 11181 | /// |
| 11182 | /// The `nGeometries` field is used as the length field of the `geometries` field. |
| 11183 | /// This function computes the field's value again based on the length of the list. |
| 11184 | /// |
| 11185 | /// # Panics |
| 11186 | /// |
| 11187 | /// Panics if the value cannot be represented in the target type. This |
| 11188 | /// cannot happen with values of the struct received from the X11 server. |
| 11189 | pub fn n_geometries(&self) -> u16 { |
| 11190 | self.geometries.len() |
| 11191 | .try_into().unwrap() |
| 11192 | } |
| 11193 | } |
| 11194 | |
| 11195 | /// Opcode for the GetKbdByName request |
| 11196 | pub const GET_KBD_BY_NAME_REQUEST: u8 = 23; |
| 11197 | #[derive (Clone, Copy, Default)] |
| 11198 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 11199 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11200 | pub struct GetKbdByNameRequest { |
| 11201 | pub device_spec: DeviceSpec, |
| 11202 | pub need: GBNDetail, |
| 11203 | pub want: GBNDetail, |
| 11204 | pub load: bool, |
| 11205 | } |
| 11206 | impl_debug_if_no_extra_traits!(GetKbdByNameRequest, "GetKbdByNameRequest" ); |
| 11207 | impl GetKbdByNameRequest { |
| 11208 | /// Serialize this request into bytes for the provided connection |
| 11209 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 11210 | let length_so_far = 0; |
| 11211 | let device_spec_bytes = self.device_spec.serialize(); |
| 11212 | let need_bytes = u16::from(self.need).serialize(); |
| 11213 | let want_bytes = u16::from(self.want).serialize(); |
| 11214 | let load_bytes = self.load.serialize(); |
| 11215 | let mut request0 = vec![ |
| 11216 | major_opcode, |
| 11217 | GET_KBD_BY_NAME_REQUEST, |
| 11218 | 0, |
| 11219 | 0, |
| 11220 | device_spec_bytes[0], |
| 11221 | device_spec_bytes[1], |
| 11222 | need_bytes[0], |
| 11223 | need_bytes[1], |
| 11224 | want_bytes[0], |
| 11225 | want_bytes[1], |
| 11226 | load_bytes[0], |
| 11227 | 0, |
| 11228 | ]; |
| 11229 | let length_so_far = length_so_far + request0.len(); |
| 11230 | assert_eq!(length_so_far % 4, 0); |
| 11231 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 11232 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 11233 | ([request0.into()], vec![]) |
| 11234 | } |
| 11235 | /// Parse this request given its header, its body, and any fds that go along with it |
| 11236 | #[cfg (feature = "request-parsing" )] |
| 11237 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 11238 | if header.minor_opcode != GET_KBD_BY_NAME_REQUEST { |
| 11239 | return Err(ParseError::InvalidValue); |
| 11240 | } |
| 11241 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 11242 | let (need, remaining) = u16::try_parse(remaining)?; |
| 11243 | let need = need.into(); |
| 11244 | let (want, remaining) = u16::try_parse(remaining)?; |
| 11245 | let want = want.into(); |
| 11246 | let (load, remaining) = bool::try_parse(remaining)?; |
| 11247 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 11248 | let _ = remaining; |
| 11249 | Ok(GetKbdByNameRequest { |
| 11250 | device_spec, |
| 11251 | need, |
| 11252 | want, |
| 11253 | load, |
| 11254 | }) |
| 11255 | } |
| 11256 | } |
| 11257 | impl Request for GetKbdByNameRequest { |
| 11258 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 11259 | |
| 11260 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 11261 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 11262 | // Flatten the buffers into a single vector |
| 11263 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 11264 | (buf, fds) |
| 11265 | } |
| 11266 | } |
| 11267 | impl crate::x11_utils::ReplyRequest for GetKbdByNameRequest { |
| 11268 | type Reply = GetKbdByNameReply; |
| 11269 | } |
| 11270 | |
| 11271 | #[derive (Clone)] |
| 11272 | #[cfg_attr (feature = "extra-traits" , derive(Debug))] |
| 11273 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11274 | pub struct GetKbdByNameRepliesTypesMapKeyActions { |
| 11275 | pub acts_rtrn_count: Vec<u8>, |
| 11276 | pub acts_rtrn_acts: Vec<Action>, |
| 11277 | } |
| 11278 | impl_debug_if_no_extra_traits!(GetKbdByNameRepliesTypesMapKeyActions, "GetKbdByNameRepliesTypesMapKeyActions" ); |
| 11279 | impl GetKbdByNameRepliesTypesMapKeyActions { |
| 11280 | pub fn try_parse(remaining: &[u8], n_key_actions: u8, total_actions: u16) -> Result<(Self, &[u8]), ParseError> { |
| 11281 | let value: &[u8] = remaining; |
| 11282 | let (acts_rtrn_count: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data:remaining, list_length:n_key_actions.try_to_usize()?)?; |
| 11283 | let acts_rtrn_count: Vec = acts_rtrn_count.to_vec(); |
| 11284 | // Align offset to multiple of 4 |
| 11285 | let offset: usize = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 11286 | let misalignment: usize = (4 - (offset % 4)) % 4; |
| 11287 | let remaining: &[u8] = remaining.get(misalignment..).ok_or(err:ParseError::InsufficientData)?; |
| 11288 | let (acts_rtrn_acts: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<Action>(data:remaining, list_length:total_actions.try_to_usize()?)?; |
| 11289 | let result: GetKbdByNameRepliesTypesMapKeyActions = GetKbdByNameRepliesTypesMapKeyActions { acts_rtrn_count, acts_rtrn_acts }; |
| 11290 | Ok((result, remaining)) |
| 11291 | } |
| 11292 | } |
| 11293 | impl GetKbdByNameRepliesTypesMapKeyActions { |
| 11294 | #[allow (dead_code)] |
| 11295 | fn serialize(&self, n_key_actions: u8, total_actions: u16) -> Vec<u8> { |
| 11296 | let mut result: Vec = Vec::new(); |
| 11297 | self.serialize_into(&mut result, n_key_actions:u8::from(n_key_actions), total_actions:u16::from(total_actions)); |
| 11298 | result |
| 11299 | } |
| 11300 | fn serialize_into(&self, bytes: &mut Vec<u8>, n_key_actions: u8, total_actions: u16) { |
| 11301 | assert_eq!(self.acts_rtrn_count.len(), usize::try_from(n_key_actions).unwrap(), "`acts_rtrn_count` has an incorrect length" ); |
| 11302 | bytes.extend_from_slice(&self.acts_rtrn_count); |
| 11303 | bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]); |
| 11304 | assert_eq!(self.acts_rtrn_acts.len(), usize::try_from(total_actions).unwrap(), "`acts_rtrn_acts` has an incorrect length" ); |
| 11305 | self.acts_rtrn_acts.serialize_into(bytes); |
| 11306 | } |
| 11307 | } |
| 11308 | #[derive (Clone, Default)] |
| 11309 | #[cfg_attr (feature = "extra-traits" , derive(Debug))] |
| 11310 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11311 | pub struct GetKbdByNameRepliesTypesMap { |
| 11312 | pub types_rtrn: Option<Vec<KeyType>>, |
| 11313 | pub syms_rtrn: Option<Vec<KeySymMap>>, |
| 11314 | pub key_actions: Option<GetKbdByNameRepliesTypesMapKeyActions>, |
| 11315 | pub behaviors_rtrn: Option<Vec<SetBehavior>>, |
| 11316 | pub vmods_rtrn: Option<Vec<xproto::ModMask>>, |
| 11317 | pub explicit_rtrn: Option<Vec<SetExplicit>>, |
| 11318 | pub modmap_rtrn: Option<Vec<KeyModMap>>, |
| 11319 | pub vmodmap_rtrn: Option<Vec<KeyVModMap>>, |
| 11320 | } |
| 11321 | impl_debug_if_no_extra_traits!(GetKbdByNameRepliesTypesMap, "GetKbdByNameRepliesTypesMap" ); |
| 11322 | impl GetKbdByNameRepliesTypesMap { |
| 11323 | #[cfg_attr (not(feature = "request-parsing" ), allow(dead_code))] |
| 11324 | 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> { |
| 11325 | let switch_expr = u16::from(present); |
| 11326 | let mut outer_remaining = value; |
| 11327 | let types_rtrn = if switch_expr & u16::from(MapPart::KEY_TYPES) != 0 { |
| 11328 | let remaining = outer_remaining; |
| 11329 | let (types_rtrn, remaining) = crate::x11_utils::parse_list::<KeyType>(remaining, n_types.try_to_usize()?)?; |
| 11330 | outer_remaining = remaining; |
| 11331 | Some(types_rtrn) |
| 11332 | } else { |
| 11333 | None |
| 11334 | }; |
| 11335 | let syms_rtrn = if switch_expr & u16::from(MapPart::KEY_SYMS) != 0 { |
| 11336 | let remaining = outer_remaining; |
| 11337 | let (syms_rtrn, remaining) = crate::x11_utils::parse_list::<KeySymMap>(remaining, n_key_syms.try_to_usize()?)?; |
| 11338 | outer_remaining = remaining; |
| 11339 | Some(syms_rtrn) |
| 11340 | } else { |
| 11341 | None |
| 11342 | }; |
| 11343 | let key_actions = if switch_expr & u16::from(MapPart::KEY_ACTIONS) != 0 { |
| 11344 | let (key_actions, new_remaining) = GetKbdByNameRepliesTypesMapKeyActions::try_parse(outer_remaining, n_key_actions, total_actions)?; |
| 11345 | outer_remaining = new_remaining; |
| 11346 | Some(key_actions) |
| 11347 | } else { |
| 11348 | None |
| 11349 | }; |
| 11350 | let behaviors_rtrn = if switch_expr & u16::from(MapPart::KEY_BEHAVIORS) != 0 { |
| 11351 | let remaining = outer_remaining; |
| 11352 | let (behaviors_rtrn, remaining) = crate::x11_utils::parse_list::<SetBehavior>(remaining, total_key_behaviors.try_to_usize()?)?; |
| 11353 | outer_remaining = remaining; |
| 11354 | Some(behaviors_rtrn) |
| 11355 | } else { |
| 11356 | None |
| 11357 | }; |
| 11358 | let vmods_rtrn = if switch_expr & u16::from(MapPart::VIRTUAL_MODS) != 0 { |
| 11359 | let remaining = outer_remaining; |
| 11360 | let value = remaining; |
| 11361 | let mut remaining = remaining; |
| 11362 | let list_length = u32::from(virtual_mods).count_ones().try_to_usize()?; |
| 11363 | let mut vmods_rtrn = Vec::with_capacity(list_length); |
| 11364 | for _ in 0..list_length { |
| 11365 | let (v, new_remaining) = u8::try_parse(remaining)?; |
| 11366 | let v = v.into(); |
| 11367 | remaining = new_remaining; |
| 11368 | vmods_rtrn.push(v); |
| 11369 | } |
| 11370 | // Align offset to multiple of 4 |
| 11371 | let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 11372 | let misalignment = (4 - (offset % 4)) % 4; |
| 11373 | let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; |
| 11374 | outer_remaining = remaining; |
| 11375 | Some(vmods_rtrn) |
| 11376 | } else { |
| 11377 | None |
| 11378 | }; |
| 11379 | let explicit_rtrn = if switch_expr & u16::from(MapPart::EXPLICIT_COMPONENTS) != 0 { |
| 11380 | let remaining = outer_remaining; |
| 11381 | let value = remaining; |
| 11382 | let (explicit_rtrn, remaining) = crate::x11_utils::parse_list::<SetExplicit>(remaining, total_key_explicit.try_to_usize()?)?; |
| 11383 | // Align offset to multiple of 4 |
| 11384 | let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 11385 | let misalignment = (4 - (offset % 4)) % 4; |
| 11386 | let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; |
| 11387 | outer_remaining = remaining; |
| 11388 | Some(explicit_rtrn) |
| 11389 | } else { |
| 11390 | None |
| 11391 | }; |
| 11392 | let modmap_rtrn = if switch_expr & u16::from(MapPart::MODIFIER_MAP) != 0 { |
| 11393 | let remaining = outer_remaining; |
| 11394 | let value = remaining; |
| 11395 | let (modmap_rtrn, remaining) = crate::x11_utils::parse_list::<KeyModMap>(remaining, total_mod_map_keys.try_to_usize()?)?; |
| 11396 | // Align offset to multiple of 4 |
| 11397 | let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 11398 | let misalignment = (4 - (offset % 4)) % 4; |
| 11399 | let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; |
| 11400 | outer_remaining = remaining; |
| 11401 | Some(modmap_rtrn) |
| 11402 | } else { |
| 11403 | None |
| 11404 | }; |
| 11405 | let vmodmap_rtrn = if switch_expr & u16::from(MapPart::VIRTUAL_MOD_MAP) != 0 { |
| 11406 | let remaining = outer_remaining; |
| 11407 | let (vmodmap_rtrn, remaining) = crate::x11_utils::parse_list::<KeyVModMap>(remaining, total_v_mod_map_keys.try_to_usize()?)?; |
| 11408 | outer_remaining = remaining; |
| 11409 | Some(vmodmap_rtrn) |
| 11410 | } else { |
| 11411 | None |
| 11412 | }; |
| 11413 | let result = GetKbdByNameRepliesTypesMap { types_rtrn, syms_rtrn, key_actions, behaviors_rtrn, vmods_rtrn, explicit_rtrn, modmap_rtrn, vmodmap_rtrn }; |
| 11414 | Ok((result, outer_remaining)) |
| 11415 | } |
| 11416 | } |
| 11417 | impl GetKbdByNameRepliesTypesMap { |
| 11418 | #[allow (dead_code)] |
| 11419 | 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> { |
| 11420 | let mut result = Vec::new(); |
| 11421 | self.serialize_into(&mut result, u16::from(present), u8::from(n_types), u8::from(n_key_syms), u8::from(n_key_actions), u16::from(total_actions), u8::from(total_key_behaviors), u16::from(virtual_mods), u8::from(total_key_explicit), u8::from(total_mod_map_keys), u8::from(total_v_mod_map_keys)); |
| 11422 | result |
| 11423 | } |
| 11424 | 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) { |
| 11425 | assert_eq!(self.switch_expr(), u16::from(present), "switch `map` has an inconsistent discriminant" ); |
| 11426 | if let Some(ref types_rtrn) = self.types_rtrn { |
| 11427 | assert_eq!(types_rtrn.len(), usize::try_from(n_types).unwrap(), "`types_rtrn` has an incorrect length" ); |
| 11428 | types_rtrn.serialize_into(bytes); |
| 11429 | } |
| 11430 | if let Some(ref syms_rtrn) = self.syms_rtrn { |
| 11431 | assert_eq!(syms_rtrn.len(), usize::try_from(n_key_syms).unwrap(), "`syms_rtrn` has an incorrect length" ); |
| 11432 | syms_rtrn.serialize_into(bytes); |
| 11433 | } |
| 11434 | if let Some(ref key_actions) = self.key_actions { |
| 11435 | key_actions.serialize_into(bytes, u8::from(n_key_actions), u16::from(total_actions)); |
| 11436 | } |
| 11437 | if let Some(ref behaviors_rtrn) = self.behaviors_rtrn { |
| 11438 | assert_eq!(behaviors_rtrn.len(), usize::try_from(total_key_behaviors).unwrap(), "`behaviors_rtrn` has an incorrect length" ); |
| 11439 | behaviors_rtrn.serialize_into(bytes); |
| 11440 | } |
| 11441 | if let Some(ref vmods_rtrn) = self.vmods_rtrn { |
| 11442 | assert_eq!(vmods_rtrn.len(), usize::try_from(u32::from(virtual_mods).count_ones()).unwrap(), "`vmods_rtrn` has an incorrect length" ); |
| 11443 | for element in vmods_rtrn.iter().copied() { |
| 11444 | (u16::from(element) as u8).serialize_into(bytes); |
| 11445 | } |
| 11446 | bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]); |
| 11447 | } |
| 11448 | if let Some(ref explicit_rtrn) = self.explicit_rtrn { |
| 11449 | assert_eq!(explicit_rtrn.len(), usize::try_from(total_key_explicit).unwrap(), "`explicit_rtrn` has an incorrect length" ); |
| 11450 | explicit_rtrn.serialize_into(bytes); |
| 11451 | bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]); |
| 11452 | } |
| 11453 | if let Some(ref modmap_rtrn) = self.modmap_rtrn { |
| 11454 | assert_eq!(modmap_rtrn.len(), usize::try_from(total_mod_map_keys).unwrap(), "`modmap_rtrn` has an incorrect length" ); |
| 11455 | modmap_rtrn.serialize_into(bytes); |
| 11456 | bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]); |
| 11457 | } |
| 11458 | if let Some(ref vmodmap_rtrn) = self.vmodmap_rtrn { |
| 11459 | assert_eq!(vmodmap_rtrn.len(), usize::try_from(total_v_mod_map_keys).unwrap(), "`vmodmap_rtrn` has an incorrect length" ); |
| 11460 | vmodmap_rtrn.serialize_into(bytes); |
| 11461 | } |
| 11462 | } |
| 11463 | } |
| 11464 | impl GetKbdByNameRepliesTypesMap { |
| 11465 | fn switch_expr(&self) -> u16 { |
| 11466 | let mut expr_value = 0; |
| 11467 | if self.types_rtrn.is_some() { |
| 11468 | expr_value |= u16::from(MapPart::KEY_TYPES); |
| 11469 | } |
| 11470 | if self.syms_rtrn.is_some() { |
| 11471 | expr_value |= u16::from(MapPart::KEY_SYMS); |
| 11472 | } |
| 11473 | if self.key_actions.is_some() { |
| 11474 | expr_value |= u16::from(MapPart::KEY_ACTIONS); |
| 11475 | } |
| 11476 | if self.behaviors_rtrn.is_some() { |
| 11477 | expr_value |= u16::from(MapPart::KEY_BEHAVIORS); |
| 11478 | } |
| 11479 | if self.vmods_rtrn.is_some() { |
| 11480 | expr_value |= u16::from(MapPart::VIRTUAL_MODS); |
| 11481 | } |
| 11482 | if self.explicit_rtrn.is_some() { |
| 11483 | expr_value |= u16::from(MapPart::EXPLICIT_COMPONENTS); |
| 11484 | } |
| 11485 | if self.modmap_rtrn.is_some() { |
| 11486 | expr_value |= u16::from(MapPart::MODIFIER_MAP); |
| 11487 | } |
| 11488 | if self.vmodmap_rtrn.is_some() { |
| 11489 | expr_value |= u16::from(MapPart::VIRTUAL_MOD_MAP); |
| 11490 | } |
| 11491 | expr_value |
| 11492 | } |
| 11493 | } |
| 11494 | |
| 11495 | #[derive (Clone)] |
| 11496 | #[cfg_attr (feature = "extra-traits" , derive(Debug))] |
| 11497 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11498 | pub struct GetKbdByNameRepliesTypes { |
| 11499 | pub getmap_type: u8, |
| 11500 | pub type_device_id: u8, |
| 11501 | pub getmap_sequence: u16, |
| 11502 | pub getmap_length: u32, |
| 11503 | pub type_min_key_code: xproto::Keycode, |
| 11504 | pub type_max_key_code: xproto::Keycode, |
| 11505 | pub first_type: u8, |
| 11506 | pub n_types: u8, |
| 11507 | pub total_types: u8, |
| 11508 | pub first_key_sym: xproto::Keycode, |
| 11509 | pub total_syms: u16, |
| 11510 | pub n_key_syms: u8, |
| 11511 | pub first_key_action: xproto::Keycode, |
| 11512 | pub total_actions: u16, |
| 11513 | pub n_key_actions: u8, |
| 11514 | pub first_key_behavior: xproto::Keycode, |
| 11515 | pub n_key_behaviors: u8, |
| 11516 | pub total_key_behaviors: u8, |
| 11517 | pub first_key_explicit: xproto::Keycode, |
| 11518 | pub n_key_explicit: u8, |
| 11519 | pub total_key_explicit: u8, |
| 11520 | pub first_mod_map_key: xproto::Keycode, |
| 11521 | pub n_mod_map_keys: u8, |
| 11522 | pub total_mod_map_keys: u8, |
| 11523 | pub first_v_mod_map_key: xproto::Keycode, |
| 11524 | pub n_v_mod_map_keys: u8, |
| 11525 | pub total_v_mod_map_keys: u8, |
| 11526 | pub virtual_mods: VMod, |
| 11527 | pub map: GetKbdByNameRepliesTypesMap, |
| 11528 | } |
| 11529 | impl_debug_if_no_extra_traits!(GetKbdByNameRepliesTypes, "GetKbdByNameRepliesTypes" ); |
| 11530 | impl TryParse for GetKbdByNameRepliesTypes { |
| 11531 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 11532 | let (getmap_type, remaining) = u8::try_parse(remaining)?; |
| 11533 | let (type_device_id, remaining) = u8::try_parse(remaining)?; |
| 11534 | let (getmap_sequence, remaining) = u16::try_parse(remaining)?; |
| 11535 | let (getmap_length, remaining) = u32::try_parse(remaining)?; |
| 11536 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 11537 | let (type_min_key_code, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 11538 | let (type_max_key_code, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 11539 | let (present, remaining) = u16::try_parse(remaining)?; |
| 11540 | let (first_type, remaining) = u8::try_parse(remaining)?; |
| 11541 | let (n_types, remaining) = u8::try_parse(remaining)?; |
| 11542 | let (total_types, remaining) = u8::try_parse(remaining)?; |
| 11543 | let (first_key_sym, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 11544 | let (total_syms, remaining) = u16::try_parse(remaining)?; |
| 11545 | let (n_key_syms, remaining) = u8::try_parse(remaining)?; |
| 11546 | let (first_key_action, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 11547 | let (total_actions, remaining) = u16::try_parse(remaining)?; |
| 11548 | let (n_key_actions, remaining) = u8::try_parse(remaining)?; |
| 11549 | let (first_key_behavior, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 11550 | let (n_key_behaviors, remaining) = u8::try_parse(remaining)?; |
| 11551 | let (total_key_behaviors, remaining) = u8::try_parse(remaining)?; |
| 11552 | let (first_key_explicit, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 11553 | let (n_key_explicit, remaining) = u8::try_parse(remaining)?; |
| 11554 | let (total_key_explicit, remaining) = u8::try_parse(remaining)?; |
| 11555 | let (first_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 11556 | let (n_mod_map_keys, remaining) = u8::try_parse(remaining)?; |
| 11557 | let (total_mod_map_keys, remaining) = u8::try_parse(remaining)?; |
| 11558 | let (first_v_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 11559 | let (n_v_mod_map_keys, remaining) = u8::try_parse(remaining)?; |
| 11560 | let (total_v_mod_map_keys, remaining) = u8::try_parse(remaining)?; |
| 11561 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 11562 | let (virtual_mods, remaining) = u16::try_parse(remaining)?; |
| 11563 | let (map, remaining) = GetKbdByNameRepliesTypesMap::try_parse(remaining, u16::from(present), u8::from(n_types), u8::from(n_key_syms), u8::from(n_key_actions), u16::from(total_actions), u8::from(total_key_behaviors), u16::from(virtual_mods), u8::from(total_key_explicit), u8::from(total_mod_map_keys), u8::from(total_v_mod_map_keys))?; |
| 11564 | let virtual_mods = virtual_mods.into(); |
| 11565 | 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 }; |
| 11566 | Ok((result, remaining)) |
| 11567 | } |
| 11568 | } |
| 11569 | impl Serialize for GetKbdByNameRepliesTypes { |
| 11570 | type Bytes = Vec<u8>; |
| 11571 | fn serialize(&self) -> Vec<u8> { |
| 11572 | let mut result = Vec::new(); |
| 11573 | self.serialize_into(&mut result); |
| 11574 | result |
| 11575 | } |
| 11576 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 11577 | bytes.reserve(40); |
| 11578 | self.getmap_type.serialize_into(bytes); |
| 11579 | self.type_device_id.serialize_into(bytes); |
| 11580 | self.getmap_sequence.serialize_into(bytes); |
| 11581 | self.getmap_length.serialize_into(bytes); |
| 11582 | bytes.extend_from_slice(&[0; 2]); |
| 11583 | self.type_min_key_code.serialize_into(bytes); |
| 11584 | self.type_max_key_code.serialize_into(bytes); |
| 11585 | let present: u16 = self.map.switch_expr(); |
| 11586 | present.serialize_into(bytes); |
| 11587 | self.first_type.serialize_into(bytes); |
| 11588 | self.n_types.serialize_into(bytes); |
| 11589 | self.total_types.serialize_into(bytes); |
| 11590 | self.first_key_sym.serialize_into(bytes); |
| 11591 | self.total_syms.serialize_into(bytes); |
| 11592 | self.n_key_syms.serialize_into(bytes); |
| 11593 | self.first_key_action.serialize_into(bytes); |
| 11594 | self.total_actions.serialize_into(bytes); |
| 11595 | self.n_key_actions.serialize_into(bytes); |
| 11596 | self.first_key_behavior.serialize_into(bytes); |
| 11597 | self.n_key_behaviors.serialize_into(bytes); |
| 11598 | self.total_key_behaviors.serialize_into(bytes); |
| 11599 | self.first_key_explicit.serialize_into(bytes); |
| 11600 | self.n_key_explicit.serialize_into(bytes); |
| 11601 | self.total_key_explicit.serialize_into(bytes); |
| 11602 | self.first_mod_map_key.serialize_into(bytes); |
| 11603 | self.n_mod_map_keys.serialize_into(bytes); |
| 11604 | self.total_mod_map_keys.serialize_into(bytes); |
| 11605 | self.first_v_mod_map_key.serialize_into(bytes); |
| 11606 | self.n_v_mod_map_keys.serialize_into(bytes); |
| 11607 | self.total_v_mod_map_keys.serialize_into(bytes); |
| 11608 | bytes.extend_from_slice(&[0; 1]); |
| 11609 | u16::from(self.virtual_mods).serialize_into(bytes); |
| 11610 | self.map.serialize_into(bytes, u16::from(present), u8::from(self.n_types), u8::from(self.n_key_syms), u8::from(self.n_key_actions), u16::from(self.total_actions), u8::from(self.total_key_behaviors), u16::from(self.virtual_mods), u8::from(self.total_key_explicit), u8::from(self.total_mod_map_keys), u8::from(self.total_v_mod_map_keys)); |
| 11611 | } |
| 11612 | } |
| 11613 | #[derive (Clone)] |
| 11614 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 11615 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11616 | pub struct GetKbdByNameRepliesCompatMap { |
| 11617 | pub compatmap_type: u8, |
| 11618 | pub compat_device_id: u8, |
| 11619 | pub compatmap_sequence: u16, |
| 11620 | pub compatmap_length: u32, |
| 11621 | pub groups_rtrn: SetOfGroup, |
| 11622 | pub first_si_rtrn: u16, |
| 11623 | pub n_total_si: u16, |
| 11624 | pub si_rtrn: Vec<SymInterpret>, |
| 11625 | pub group_rtrn: Vec<ModDef>, |
| 11626 | } |
| 11627 | impl_debug_if_no_extra_traits!(GetKbdByNameRepliesCompatMap, "GetKbdByNameRepliesCompatMap" ); |
| 11628 | impl TryParse for GetKbdByNameRepliesCompatMap { |
| 11629 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 11630 | let (compatmap_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 11631 | let (compat_device_id: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 11632 | let (compatmap_sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 11633 | let (compatmap_length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 11634 | let (groups_rtrn: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 11635 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 11636 | let (first_si_rtrn: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 11637 | let (n_si_rtrn: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 11638 | let (n_total_si: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 11639 | let remaining: &[u8] = remaining.get(16..).ok_or(err:ParseError::InsufficientData)?; |
| 11640 | let (si_rtrn: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<SymInterpret>(data:remaining, list_length:n_si_rtrn.try_to_usize()?)?; |
| 11641 | let (group_rtrn: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<ModDef>(data:remaining, list_length:u32::from(groups_rtrn).count_ones().try_to_usize()?)?; |
| 11642 | let groups_rtrn: SetOfGroup = groups_rtrn.into(); |
| 11643 | let result: GetKbdByNameRepliesCompatMap = GetKbdByNameRepliesCompatMap { compatmap_type, compat_device_id, compatmap_sequence, compatmap_length, groups_rtrn, first_si_rtrn, n_total_si, si_rtrn, group_rtrn }; |
| 11644 | Ok((result, remaining)) |
| 11645 | } |
| 11646 | } |
| 11647 | impl Serialize for GetKbdByNameRepliesCompatMap { |
| 11648 | type Bytes = Vec<u8>; |
| 11649 | fn serialize(&self) -> Vec<u8> { |
| 11650 | let mut result = Vec::new(); |
| 11651 | self.serialize_into(&mut result); |
| 11652 | result |
| 11653 | } |
| 11654 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 11655 | bytes.reserve(32); |
| 11656 | self.compatmap_type.serialize_into(bytes); |
| 11657 | self.compat_device_id.serialize_into(bytes); |
| 11658 | self.compatmap_sequence.serialize_into(bytes); |
| 11659 | self.compatmap_length.serialize_into(bytes); |
| 11660 | u8::from(self.groups_rtrn).serialize_into(bytes); |
| 11661 | bytes.extend_from_slice(&[0; 1]); |
| 11662 | self.first_si_rtrn.serialize_into(bytes); |
| 11663 | let n_si_rtrn = u16::try_from(self.si_rtrn.len()).expect("`si_rtrn` has too many elements" ); |
| 11664 | n_si_rtrn.serialize_into(bytes); |
| 11665 | self.n_total_si.serialize_into(bytes); |
| 11666 | bytes.extend_from_slice(&[0; 16]); |
| 11667 | self.si_rtrn.serialize_into(bytes); |
| 11668 | assert_eq!(self.group_rtrn.len(), usize::try_from(u32::from(self.groups_rtrn).count_ones()).unwrap(), "`group_rtrn` has an incorrect length" ); |
| 11669 | self.group_rtrn.serialize_into(bytes); |
| 11670 | } |
| 11671 | } |
| 11672 | impl GetKbdByNameRepliesCompatMap { |
| 11673 | /// Get the value of the `nSIRtrn` field. |
| 11674 | /// |
| 11675 | /// The `nSIRtrn` field is used as the length field of the `si_rtrn` field. |
| 11676 | /// This function computes the field's value again based on the length of the list. |
| 11677 | /// |
| 11678 | /// # Panics |
| 11679 | /// |
| 11680 | /// Panics if the value cannot be represented in the target type. This |
| 11681 | /// cannot happen with values of the struct received from the X11 server. |
| 11682 | pub fn n_si_rtrn(&self) -> u16 { |
| 11683 | self.si_rtrn.len() |
| 11684 | .try_into().unwrap() |
| 11685 | } |
| 11686 | } |
| 11687 | #[derive (Clone)] |
| 11688 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 11689 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11690 | pub struct GetKbdByNameRepliesIndicatorMaps { |
| 11691 | pub indicatormap_type: u8, |
| 11692 | pub indicator_device_id: u8, |
| 11693 | pub indicatormap_sequence: u16, |
| 11694 | pub indicatormap_length: u32, |
| 11695 | pub which: u32, |
| 11696 | pub real_indicators: u32, |
| 11697 | pub maps: Vec<IndicatorMap>, |
| 11698 | } |
| 11699 | impl_debug_if_no_extra_traits!(GetKbdByNameRepliesIndicatorMaps, "GetKbdByNameRepliesIndicatorMaps" ); |
| 11700 | impl TryParse for GetKbdByNameRepliesIndicatorMaps { |
| 11701 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 11702 | let (indicatormap_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 11703 | let (indicator_device_id: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 11704 | let (indicatormap_sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 11705 | let (indicatormap_length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 11706 | let (which: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 11707 | let (real_indicators: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 11708 | let (n_indicators: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 11709 | let remaining: &[u8] = remaining.get(15..).ok_or(err:ParseError::InsufficientData)?; |
| 11710 | let (maps: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<IndicatorMap>(data:remaining, list_length:n_indicators.try_to_usize()?)?; |
| 11711 | let result: GetKbdByNameRepliesIndicatorMaps = GetKbdByNameRepliesIndicatorMaps { indicatormap_type, indicator_device_id, indicatormap_sequence, indicatormap_length, which, real_indicators, maps }; |
| 11712 | Ok((result, remaining)) |
| 11713 | } |
| 11714 | } |
| 11715 | impl Serialize for GetKbdByNameRepliesIndicatorMaps { |
| 11716 | type Bytes = Vec<u8>; |
| 11717 | fn serialize(&self) -> Vec<u8> { |
| 11718 | let mut result: Vec = Vec::new(); |
| 11719 | self.serialize_into(&mut result); |
| 11720 | result |
| 11721 | } |
| 11722 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 11723 | bytes.reserve(additional:32); |
| 11724 | self.indicatormap_type.serialize_into(bytes); |
| 11725 | self.indicator_device_id.serialize_into(bytes); |
| 11726 | self.indicatormap_sequence.serialize_into(bytes); |
| 11727 | self.indicatormap_length.serialize_into(bytes); |
| 11728 | self.which.serialize_into(bytes); |
| 11729 | self.real_indicators.serialize_into(bytes); |
| 11730 | let n_indicators: u8 = u8::try_from(self.maps.len()).expect(msg:"`maps` has too many elements" ); |
| 11731 | n_indicators.serialize_into(bytes); |
| 11732 | bytes.extend_from_slice(&[0; 15]); |
| 11733 | self.maps.serialize_into(bytes); |
| 11734 | } |
| 11735 | } |
| 11736 | impl GetKbdByNameRepliesIndicatorMaps { |
| 11737 | /// Get the value of the `nIndicators` field. |
| 11738 | /// |
| 11739 | /// The `nIndicators` field is used as the length field of the `maps` field. |
| 11740 | /// This function computes the field's value again based on the length of the list. |
| 11741 | /// |
| 11742 | /// # Panics |
| 11743 | /// |
| 11744 | /// Panics if the value cannot be represented in the target type. This |
| 11745 | /// cannot happen with values of the struct received from the X11 server. |
| 11746 | pub fn n_indicators(&self) -> u8 { |
| 11747 | self.maps.len() |
| 11748 | .try_into().unwrap() |
| 11749 | } |
| 11750 | } |
| 11751 | #[derive (Clone)] |
| 11752 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 11753 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11754 | pub struct GetKbdByNameRepliesKeyNamesValueListKTLevelNames { |
| 11755 | pub n_levels_per_type: Vec<u8>, |
| 11756 | pub kt_level_names: Vec<xproto::Atom>, |
| 11757 | } |
| 11758 | impl_debug_if_no_extra_traits!(GetKbdByNameRepliesKeyNamesValueListKTLevelNames, "GetKbdByNameRepliesKeyNamesValueListKTLevelNames" ); |
| 11759 | impl GetKbdByNameRepliesKeyNamesValueListKTLevelNames { |
| 11760 | pub fn try_parse(remaining: &[u8], n_types: u8) -> Result<(Self, &[u8]), ParseError> { |
| 11761 | let value: &[u8] = remaining; |
| 11762 | let (n_levels_per_type: &[u8], remaining: &[u8]) = crate::x11_utils::parse_u8_list(data:remaining, list_length:n_types.try_to_usize()?)?; |
| 11763 | let n_levels_per_type: Vec = n_levels_per_type.to_vec(); |
| 11764 | // Align offset to multiple of 4 |
| 11765 | let offset: usize = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 11766 | let misalignment: usize = (4 - (offset % 4)) % 4; |
| 11767 | let remaining: &[u8] = remaining.get(misalignment..).ok_or(err:ParseError::InsufficientData)?; |
| 11768 | let (kt_level_names: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<xproto::Atom>(data:remaining, list_length:n_levels_per_type.iter().try_fold(init:0u32, |acc: u32, x: &u8| acc.checked_add(u32::from(*x)).ok_or(err:ParseError::InvalidExpression))?.try_to_usize()?)?; |
| 11769 | let result: GetKbdByNameRepliesKeyNamesValueListKTLevelNames = GetKbdByNameRepliesKeyNamesValueListKTLevelNames { n_levels_per_type, kt_level_names }; |
| 11770 | Ok((result, remaining)) |
| 11771 | } |
| 11772 | } |
| 11773 | impl GetKbdByNameRepliesKeyNamesValueListKTLevelNames { |
| 11774 | #[allow (dead_code)] |
| 11775 | fn serialize(&self, n_types: u8) -> Vec<u8> { |
| 11776 | let mut result: Vec = Vec::new(); |
| 11777 | self.serialize_into(&mut result, n_types:u8::from(n_types)); |
| 11778 | result |
| 11779 | } |
| 11780 | fn serialize_into(&self, bytes: &mut Vec<u8>, n_types: u8) { |
| 11781 | assert_eq!(self.n_levels_per_type.len(), usize::try_from(n_types).unwrap(), "`n_levels_per_type` has an incorrect length" ); |
| 11782 | bytes.extend_from_slice(&self.n_levels_per_type); |
| 11783 | bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]); |
| 11784 | 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" ); |
| 11785 | self.kt_level_names.serialize_into(bytes); |
| 11786 | } |
| 11787 | } |
| 11788 | #[derive (Clone, Default)] |
| 11789 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 11790 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11791 | pub struct GetKbdByNameRepliesKeyNamesValueList { |
| 11792 | pub keycodes_name: Option<xproto::Atom>, |
| 11793 | pub geometry_name: Option<xproto::Atom>, |
| 11794 | pub symbols_name: Option<xproto::Atom>, |
| 11795 | pub phys_symbols_name: Option<xproto::Atom>, |
| 11796 | pub types_name: Option<xproto::Atom>, |
| 11797 | pub compat_name: Option<xproto::Atom>, |
| 11798 | pub type_names: Option<Vec<xproto::Atom>>, |
| 11799 | pub kt_level_names: Option<GetKbdByNameRepliesKeyNamesValueListKTLevelNames>, |
| 11800 | pub indicator_names: Option<Vec<xproto::Atom>>, |
| 11801 | pub virtual_mod_names: Option<Vec<xproto::Atom>>, |
| 11802 | pub groups: Option<Vec<xproto::Atom>>, |
| 11803 | pub key_names: Option<Vec<KeyName>>, |
| 11804 | pub key_aliases: Option<Vec<KeyAlias>>, |
| 11805 | pub radio_group_names: Option<Vec<xproto::Atom>>, |
| 11806 | } |
| 11807 | impl_debug_if_no_extra_traits!(GetKbdByNameRepliesKeyNamesValueList, "GetKbdByNameRepliesKeyNamesValueList" ); |
| 11808 | impl GetKbdByNameRepliesKeyNamesValueList { |
| 11809 | #[cfg_attr (not(feature = "request-parsing" ), allow(dead_code))] |
| 11810 | 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> { |
| 11811 | let switch_expr = u32::from(which); |
| 11812 | let mut outer_remaining = value; |
| 11813 | let keycodes_name = if switch_expr & u32::from(NameDetail::KEYCODES) != 0 { |
| 11814 | let remaining = outer_remaining; |
| 11815 | let (keycodes_name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 11816 | outer_remaining = remaining; |
| 11817 | Some(keycodes_name) |
| 11818 | } else { |
| 11819 | None |
| 11820 | }; |
| 11821 | let geometry_name = if switch_expr & u32::from(NameDetail::GEOMETRY) != 0 { |
| 11822 | let remaining = outer_remaining; |
| 11823 | let (geometry_name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 11824 | outer_remaining = remaining; |
| 11825 | Some(geometry_name) |
| 11826 | } else { |
| 11827 | None |
| 11828 | }; |
| 11829 | let symbols_name = if switch_expr & u32::from(NameDetail::SYMBOLS) != 0 { |
| 11830 | let remaining = outer_remaining; |
| 11831 | let (symbols_name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 11832 | outer_remaining = remaining; |
| 11833 | Some(symbols_name) |
| 11834 | } else { |
| 11835 | None |
| 11836 | }; |
| 11837 | let phys_symbols_name = if switch_expr & u32::from(NameDetail::PHYS_SYMBOLS) != 0 { |
| 11838 | let remaining = outer_remaining; |
| 11839 | let (phys_symbols_name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 11840 | outer_remaining = remaining; |
| 11841 | Some(phys_symbols_name) |
| 11842 | } else { |
| 11843 | None |
| 11844 | }; |
| 11845 | let types_name = if switch_expr & u32::from(NameDetail::TYPES) != 0 { |
| 11846 | let remaining = outer_remaining; |
| 11847 | let (types_name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 11848 | outer_remaining = remaining; |
| 11849 | Some(types_name) |
| 11850 | } else { |
| 11851 | None |
| 11852 | }; |
| 11853 | let compat_name = if switch_expr & u32::from(NameDetail::COMPAT) != 0 { |
| 11854 | let remaining = outer_remaining; |
| 11855 | let (compat_name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 11856 | outer_remaining = remaining; |
| 11857 | Some(compat_name) |
| 11858 | } else { |
| 11859 | None |
| 11860 | }; |
| 11861 | let type_names = if switch_expr & u32::from(NameDetail::KEY_TYPE_NAMES) != 0 { |
| 11862 | let remaining = outer_remaining; |
| 11863 | let (type_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, n_types.try_to_usize()?)?; |
| 11864 | outer_remaining = remaining; |
| 11865 | Some(type_names) |
| 11866 | } else { |
| 11867 | None |
| 11868 | }; |
| 11869 | let kt_level_names = if switch_expr & u32::from(NameDetail::KT_LEVEL_NAMES) != 0 { |
| 11870 | let (kt_level_names, new_remaining) = GetKbdByNameRepliesKeyNamesValueListKTLevelNames::try_parse(outer_remaining, n_types)?; |
| 11871 | outer_remaining = new_remaining; |
| 11872 | Some(kt_level_names) |
| 11873 | } else { |
| 11874 | None |
| 11875 | }; |
| 11876 | let indicator_names = if switch_expr & u32::from(NameDetail::INDICATOR_NAMES) != 0 { |
| 11877 | let remaining = outer_remaining; |
| 11878 | let (indicator_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, u32::from(indicators).count_ones().try_to_usize()?)?; |
| 11879 | outer_remaining = remaining; |
| 11880 | Some(indicator_names) |
| 11881 | } else { |
| 11882 | None |
| 11883 | }; |
| 11884 | let virtual_mod_names = if switch_expr & u32::from(NameDetail::VIRTUAL_MOD_NAMES) != 0 { |
| 11885 | let remaining = outer_remaining; |
| 11886 | let (virtual_mod_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, u32::from(virtual_mods).count_ones().try_to_usize()?)?; |
| 11887 | outer_remaining = remaining; |
| 11888 | Some(virtual_mod_names) |
| 11889 | } else { |
| 11890 | None |
| 11891 | }; |
| 11892 | let groups = if switch_expr & u32::from(NameDetail::GROUP_NAMES) != 0 { |
| 11893 | let remaining = outer_remaining; |
| 11894 | let (groups, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, u32::from(group_names).count_ones().try_to_usize()?)?; |
| 11895 | outer_remaining = remaining; |
| 11896 | Some(groups) |
| 11897 | } else { |
| 11898 | None |
| 11899 | }; |
| 11900 | let key_names = if switch_expr & u32::from(NameDetail::KEY_NAMES) != 0 { |
| 11901 | let remaining = outer_remaining; |
| 11902 | let (key_names, remaining) = crate::x11_utils::parse_list::<KeyName>(remaining, n_keys.try_to_usize()?)?; |
| 11903 | outer_remaining = remaining; |
| 11904 | Some(key_names) |
| 11905 | } else { |
| 11906 | None |
| 11907 | }; |
| 11908 | let key_aliases = if switch_expr & u32::from(NameDetail::KEY_ALIASES) != 0 { |
| 11909 | let remaining = outer_remaining; |
| 11910 | let (key_aliases, remaining) = crate::x11_utils::parse_list::<KeyAlias>(remaining, n_key_aliases.try_to_usize()?)?; |
| 11911 | outer_remaining = remaining; |
| 11912 | Some(key_aliases) |
| 11913 | } else { |
| 11914 | None |
| 11915 | }; |
| 11916 | let radio_group_names = if switch_expr & u32::from(NameDetail::RG_NAMES) != 0 { |
| 11917 | let remaining = outer_remaining; |
| 11918 | let (radio_group_names, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, n_radio_groups.try_to_usize()?)?; |
| 11919 | outer_remaining = remaining; |
| 11920 | Some(radio_group_names) |
| 11921 | } else { |
| 11922 | None |
| 11923 | }; |
| 11924 | let result = GetKbdByNameRepliesKeyNamesValueList { keycodes_name, geometry_name, symbols_name, phys_symbols_name, types_name, compat_name, type_names, kt_level_names, indicator_names, virtual_mod_names, groups, key_names, key_aliases, radio_group_names }; |
| 11925 | Ok((result, outer_remaining)) |
| 11926 | } |
| 11927 | } |
| 11928 | impl GetKbdByNameRepliesKeyNamesValueList { |
| 11929 | #[allow (dead_code)] |
| 11930 | 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> { |
| 11931 | let mut result = Vec::new(); |
| 11932 | self.serialize_into(&mut result, u32::from(which), u8::from(n_types), u32::from(indicators), u16::from(virtual_mods), u8::from(group_names), u8::from(n_keys), u8::from(n_key_aliases), u8::from(n_radio_groups)); |
| 11933 | result |
| 11934 | } |
| 11935 | 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) { |
| 11936 | assert_eq!(self.switch_expr(), u32::from(which), "switch `value_list` has an inconsistent discriminant" ); |
| 11937 | if let Some(keycodes_name) = self.keycodes_name { |
| 11938 | keycodes_name.serialize_into(bytes); |
| 11939 | } |
| 11940 | if let Some(geometry_name) = self.geometry_name { |
| 11941 | geometry_name.serialize_into(bytes); |
| 11942 | } |
| 11943 | if let Some(symbols_name) = self.symbols_name { |
| 11944 | symbols_name.serialize_into(bytes); |
| 11945 | } |
| 11946 | if let Some(phys_symbols_name) = self.phys_symbols_name { |
| 11947 | phys_symbols_name.serialize_into(bytes); |
| 11948 | } |
| 11949 | if let Some(types_name) = self.types_name { |
| 11950 | types_name.serialize_into(bytes); |
| 11951 | } |
| 11952 | if let Some(compat_name) = self.compat_name { |
| 11953 | compat_name.serialize_into(bytes); |
| 11954 | } |
| 11955 | if let Some(ref type_names) = self.type_names { |
| 11956 | assert_eq!(type_names.len(), usize::try_from(n_types).unwrap(), "`type_names` has an incorrect length" ); |
| 11957 | type_names.serialize_into(bytes); |
| 11958 | } |
| 11959 | if let Some(ref kt_level_names) = self.kt_level_names { |
| 11960 | kt_level_names.serialize_into(bytes, u8::from(n_types)); |
| 11961 | } |
| 11962 | if let Some(ref indicator_names) = self.indicator_names { |
| 11963 | assert_eq!(indicator_names.len(), usize::try_from(u32::from(indicators).count_ones()).unwrap(), "`indicator_names` has an incorrect length" ); |
| 11964 | indicator_names.serialize_into(bytes); |
| 11965 | } |
| 11966 | if let Some(ref virtual_mod_names) = self.virtual_mod_names { |
| 11967 | assert_eq!(virtual_mod_names.len(), usize::try_from(u32::from(virtual_mods).count_ones()).unwrap(), "`virtual_mod_names` has an incorrect length" ); |
| 11968 | virtual_mod_names.serialize_into(bytes); |
| 11969 | } |
| 11970 | if let Some(ref groups) = self.groups { |
| 11971 | assert_eq!(groups.len(), usize::try_from(u32::from(group_names).count_ones()).unwrap(), "`groups` has an incorrect length" ); |
| 11972 | groups.serialize_into(bytes); |
| 11973 | } |
| 11974 | if let Some(ref key_names) = self.key_names { |
| 11975 | assert_eq!(key_names.len(), usize::try_from(n_keys).unwrap(), "`key_names` has an incorrect length" ); |
| 11976 | key_names.serialize_into(bytes); |
| 11977 | } |
| 11978 | if let Some(ref key_aliases) = self.key_aliases { |
| 11979 | assert_eq!(key_aliases.len(), usize::try_from(n_key_aliases).unwrap(), "`key_aliases` has an incorrect length" ); |
| 11980 | key_aliases.serialize_into(bytes); |
| 11981 | } |
| 11982 | if let Some(ref radio_group_names) = self.radio_group_names { |
| 11983 | assert_eq!(radio_group_names.len(), usize::try_from(n_radio_groups).unwrap(), "`radio_group_names` has an incorrect length" ); |
| 11984 | radio_group_names.serialize_into(bytes); |
| 11985 | } |
| 11986 | } |
| 11987 | } |
| 11988 | impl GetKbdByNameRepliesKeyNamesValueList { |
| 11989 | fn switch_expr(&self) -> u32 { |
| 11990 | let mut expr_value = 0; |
| 11991 | if self.keycodes_name.is_some() { |
| 11992 | expr_value |= u32::from(NameDetail::KEYCODES); |
| 11993 | } |
| 11994 | if self.geometry_name.is_some() { |
| 11995 | expr_value |= u32::from(NameDetail::GEOMETRY); |
| 11996 | } |
| 11997 | if self.symbols_name.is_some() { |
| 11998 | expr_value |= u32::from(NameDetail::SYMBOLS); |
| 11999 | } |
| 12000 | if self.phys_symbols_name.is_some() { |
| 12001 | expr_value |= u32::from(NameDetail::PHYS_SYMBOLS); |
| 12002 | } |
| 12003 | if self.types_name.is_some() { |
| 12004 | expr_value |= u32::from(NameDetail::TYPES); |
| 12005 | } |
| 12006 | if self.compat_name.is_some() { |
| 12007 | expr_value |= u32::from(NameDetail::COMPAT); |
| 12008 | } |
| 12009 | if self.type_names.is_some() { |
| 12010 | expr_value |= u32::from(NameDetail::KEY_TYPE_NAMES); |
| 12011 | } |
| 12012 | if self.kt_level_names.is_some() { |
| 12013 | expr_value |= u32::from(NameDetail::KT_LEVEL_NAMES); |
| 12014 | } |
| 12015 | if self.indicator_names.is_some() { |
| 12016 | expr_value |= u32::from(NameDetail::INDICATOR_NAMES); |
| 12017 | } |
| 12018 | if self.virtual_mod_names.is_some() { |
| 12019 | expr_value |= u32::from(NameDetail::VIRTUAL_MOD_NAMES); |
| 12020 | } |
| 12021 | if self.groups.is_some() { |
| 12022 | expr_value |= u32::from(NameDetail::GROUP_NAMES); |
| 12023 | } |
| 12024 | if self.key_names.is_some() { |
| 12025 | expr_value |= u32::from(NameDetail::KEY_NAMES); |
| 12026 | } |
| 12027 | if self.key_aliases.is_some() { |
| 12028 | expr_value |= u32::from(NameDetail::KEY_ALIASES); |
| 12029 | } |
| 12030 | if self.radio_group_names.is_some() { |
| 12031 | expr_value |= u32::from(NameDetail::RG_NAMES); |
| 12032 | } |
| 12033 | expr_value |
| 12034 | } |
| 12035 | } |
| 12036 | |
| 12037 | #[derive (Clone)] |
| 12038 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 12039 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12040 | pub struct GetKbdByNameRepliesKeyNames { |
| 12041 | pub keyname_type: u8, |
| 12042 | pub key_device_id: u8, |
| 12043 | pub keyname_sequence: u16, |
| 12044 | pub keyname_length: u32, |
| 12045 | pub key_min_key_code: xproto::Keycode, |
| 12046 | pub key_max_key_code: xproto::Keycode, |
| 12047 | pub n_types: u8, |
| 12048 | pub group_names: SetOfGroup, |
| 12049 | pub virtual_mods: VMod, |
| 12050 | pub first_key: xproto::Keycode, |
| 12051 | pub n_keys: u8, |
| 12052 | pub indicators: u32, |
| 12053 | pub n_radio_groups: u8, |
| 12054 | pub n_key_aliases: u8, |
| 12055 | pub n_kt_levels: u16, |
| 12056 | pub value_list: GetKbdByNameRepliesKeyNamesValueList, |
| 12057 | } |
| 12058 | impl_debug_if_no_extra_traits!(GetKbdByNameRepliesKeyNames, "GetKbdByNameRepliesKeyNames" ); |
| 12059 | impl TryParse for GetKbdByNameRepliesKeyNames { |
| 12060 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 12061 | let (keyname_type, remaining) = u8::try_parse(remaining)?; |
| 12062 | let (key_device_id, remaining) = u8::try_parse(remaining)?; |
| 12063 | let (keyname_sequence, remaining) = u16::try_parse(remaining)?; |
| 12064 | let (keyname_length, remaining) = u32::try_parse(remaining)?; |
| 12065 | let (which, remaining) = u32::try_parse(remaining)?; |
| 12066 | let (key_min_key_code, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 12067 | let (key_max_key_code, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 12068 | let (n_types, remaining) = u8::try_parse(remaining)?; |
| 12069 | let (group_names, remaining) = u8::try_parse(remaining)?; |
| 12070 | let (virtual_mods, remaining) = u16::try_parse(remaining)?; |
| 12071 | let (first_key, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 12072 | let (n_keys, remaining) = u8::try_parse(remaining)?; |
| 12073 | let (indicators, remaining) = u32::try_parse(remaining)?; |
| 12074 | let (n_radio_groups, remaining) = u8::try_parse(remaining)?; |
| 12075 | let (n_key_aliases, remaining) = u8::try_parse(remaining)?; |
| 12076 | let (n_kt_levels, remaining) = u16::try_parse(remaining)?; |
| 12077 | let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; |
| 12078 | let (value_list, remaining) = GetKbdByNameRepliesKeyNamesValueList::try_parse(remaining, u32::from(which), u8::from(n_types), u32::from(indicators), u16::from(virtual_mods), u8::from(group_names), u8::from(n_keys), u8::from(n_key_aliases), u8::from(n_radio_groups))?; |
| 12079 | let group_names = group_names.into(); |
| 12080 | let virtual_mods = virtual_mods.into(); |
| 12081 | 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 }; |
| 12082 | Ok((result, remaining)) |
| 12083 | } |
| 12084 | } |
| 12085 | impl Serialize for GetKbdByNameRepliesKeyNames { |
| 12086 | type Bytes = Vec<u8>; |
| 12087 | fn serialize(&self) -> Vec<u8> { |
| 12088 | let mut result = Vec::new(); |
| 12089 | self.serialize_into(&mut result); |
| 12090 | result |
| 12091 | } |
| 12092 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 12093 | bytes.reserve(32); |
| 12094 | self.keyname_type.serialize_into(bytes); |
| 12095 | self.key_device_id.serialize_into(bytes); |
| 12096 | self.keyname_sequence.serialize_into(bytes); |
| 12097 | self.keyname_length.serialize_into(bytes); |
| 12098 | let which: u32 = self.value_list.switch_expr(); |
| 12099 | which.serialize_into(bytes); |
| 12100 | self.key_min_key_code.serialize_into(bytes); |
| 12101 | self.key_max_key_code.serialize_into(bytes); |
| 12102 | self.n_types.serialize_into(bytes); |
| 12103 | u8::from(self.group_names).serialize_into(bytes); |
| 12104 | u16::from(self.virtual_mods).serialize_into(bytes); |
| 12105 | self.first_key.serialize_into(bytes); |
| 12106 | self.n_keys.serialize_into(bytes); |
| 12107 | self.indicators.serialize_into(bytes); |
| 12108 | self.n_radio_groups.serialize_into(bytes); |
| 12109 | self.n_key_aliases.serialize_into(bytes); |
| 12110 | self.n_kt_levels.serialize_into(bytes); |
| 12111 | bytes.extend_from_slice(&[0; 4]); |
| 12112 | self.value_list.serialize_into(bytes, u32::from(which), u8::from(self.n_types), u32::from(self.indicators), u16::from(self.virtual_mods), u8::from(self.group_names), u8::from(self.n_keys), u8::from(self.n_key_aliases), u8::from(self.n_radio_groups)); |
| 12113 | } |
| 12114 | } |
| 12115 | #[derive (Clone)] |
| 12116 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 12117 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12118 | pub struct GetKbdByNameRepliesGeometry { |
| 12119 | pub geometry_type: u8, |
| 12120 | pub geometry_device_id: u8, |
| 12121 | pub geometry_sequence: u16, |
| 12122 | pub geometry_length: u32, |
| 12123 | pub name: xproto::Atom, |
| 12124 | pub geometry_found: bool, |
| 12125 | pub width_mm: u16, |
| 12126 | pub height_mm: u16, |
| 12127 | pub n_properties: u16, |
| 12128 | pub n_colors: u16, |
| 12129 | pub n_shapes: u16, |
| 12130 | pub n_sections: u16, |
| 12131 | pub n_doodads: u16, |
| 12132 | pub n_key_aliases: u16, |
| 12133 | pub base_color_ndx: u8, |
| 12134 | pub label_color_ndx: u8, |
| 12135 | pub label_font: CountedString16, |
| 12136 | } |
| 12137 | impl_debug_if_no_extra_traits!(GetKbdByNameRepliesGeometry, "GetKbdByNameRepliesGeometry" ); |
| 12138 | impl TryParse for GetKbdByNameRepliesGeometry { |
| 12139 | fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 12140 | let (geometry_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 12141 | let (geometry_device_id: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 12142 | let (geometry_sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 12143 | let (geometry_length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 12144 | let (name: u32, remaining: &[u8]) = xproto::Atom::try_parse(remaining)?; |
| 12145 | let (geometry_found: bool, remaining: &[u8]) = bool::try_parse(remaining)?; |
| 12146 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 12147 | let (width_mm: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 12148 | let (height_mm: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 12149 | let (n_properties: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 12150 | let (n_colors: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 12151 | let (n_shapes: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 12152 | let (n_sections: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 12153 | let (n_doodads: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 12154 | let (n_key_aliases: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 12155 | let (base_color_ndx: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 12156 | let (label_color_ndx: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 12157 | let (label_font: CountedString16, remaining: &[u8]) = CountedString16::try_parse(remaining)?; |
| 12158 | let result: GetKbdByNameRepliesGeometry = 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 }; |
| 12159 | Ok((result, remaining)) |
| 12160 | } |
| 12161 | } |
| 12162 | impl Serialize for GetKbdByNameRepliesGeometry { |
| 12163 | type Bytes = Vec<u8>; |
| 12164 | fn serialize(&self) -> Vec<u8> { |
| 12165 | let mut result = Vec::new(); |
| 12166 | self.serialize_into(&mut result); |
| 12167 | result |
| 12168 | } |
| 12169 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 12170 | bytes.reserve(32); |
| 12171 | self.geometry_type.serialize_into(bytes); |
| 12172 | self.geometry_device_id.serialize_into(bytes); |
| 12173 | self.geometry_sequence.serialize_into(bytes); |
| 12174 | self.geometry_length.serialize_into(bytes); |
| 12175 | self.name.serialize_into(bytes); |
| 12176 | self.geometry_found.serialize_into(bytes); |
| 12177 | bytes.extend_from_slice(&[0; 1]); |
| 12178 | self.width_mm.serialize_into(bytes); |
| 12179 | self.height_mm.serialize_into(bytes); |
| 12180 | self.n_properties.serialize_into(bytes); |
| 12181 | self.n_colors.serialize_into(bytes); |
| 12182 | self.n_shapes.serialize_into(bytes); |
| 12183 | self.n_sections.serialize_into(bytes); |
| 12184 | self.n_doodads.serialize_into(bytes); |
| 12185 | self.n_key_aliases.serialize_into(bytes); |
| 12186 | self.base_color_ndx.serialize_into(bytes); |
| 12187 | self.label_color_ndx.serialize_into(bytes); |
| 12188 | self.label_font.serialize_into(bytes); |
| 12189 | } |
| 12190 | } |
| 12191 | #[derive (Clone, Default)] |
| 12192 | #[cfg_attr (feature = "extra-traits" , derive(Debug))] |
| 12193 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12194 | pub struct GetKbdByNameReplies { |
| 12195 | pub types: Option<GetKbdByNameRepliesTypes>, |
| 12196 | pub compat_map: Option<GetKbdByNameRepliesCompatMap>, |
| 12197 | pub indicator_maps: Option<GetKbdByNameRepliesIndicatorMaps>, |
| 12198 | pub key_names: Option<GetKbdByNameRepliesKeyNames>, |
| 12199 | pub geometry: Option<GetKbdByNameRepliesGeometry>, |
| 12200 | } |
| 12201 | impl_debug_if_no_extra_traits!(GetKbdByNameReplies, "GetKbdByNameReplies" ); |
| 12202 | impl GetKbdByNameReplies { |
| 12203 | #[cfg_attr (not(feature = "request-parsing" ), allow(dead_code))] |
| 12204 | fn try_parse(value: &[u8], reported: u16) -> Result<(Self, &[u8]), ParseError> { |
| 12205 | let switch_expr = u16::from(reported); |
| 12206 | let mut outer_remaining = value; |
| 12207 | let types = if switch_expr & u16::from(GBNDetail::TYPES) != 0 || switch_expr & u16::from(GBNDetail::CLIENT_SYMBOLS) != 0 || switch_expr & u16::from(GBNDetail::SERVER_SYMBOLS) != 0 { |
| 12208 | let (types, new_remaining) = GetKbdByNameRepliesTypes::try_parse(outer_remaining)?; |
| 12209 | outer_remaining = new_remaining; |
| 12210 | Some(types) |
| 12211 | } else { |
| 12212 | None |
| 12213 | }; |
| 12214 | let compat_map = if switch_expr & u16::from(GBNDetail::COMPAT_MAP) != 0 { |
| 12215 | let (compat_map, new_remaining) = GetKbdByNameRepliesCompatMap::try_parse(outer_remaining)?; |
| 12216 | outer_remaining = new_remaining; |
| 12217 | Some(compat_map) |
| 12218 | } else { |
| 12219 | None |
| 12220 | }; |
| 12221 | let indicator_maps = if switch_expr & u16::from(GBNDetail::INDICATOR_MAPS) != 0 { |
| 12222 | let (indicator_maps, new_remaining) = GetKbdByNameRepliesIndicatorMaps::try_parse(outer_remaining)?; |
| 12223 | outer_remaining = new_remaining; |
| 12224 | Some(indicator_maps) |
| 12225 | } else { |
| 12226 | None |
| 12227 | }; |
| 12228 | let key_names = if switch_expr & u16::from(GBNDetail::KEY_NAMES) != 0 || switch_expr & u16::from(GBNDetail::OTHER_NAMES) != 0 { |
| 12229 | let (key_names, new_remaining) = GetKbdByNameRepliesKeyNames::try_parse(outer_remaining)?; |
| 12230 | outer_remaining = new_remaining; |
| 12231 | Some(key_names) |
| 12232 | } else { |
| 12233 | None |
| 12234 | }; |
| 12235 | let geometry = if switch_expr & u16::from(GBNDetail::GEOMETRY) != 0 { |
| 12236 | let (geometry, new_remaining) = GetKbdByNameRepliesGeometry::try_parse(outer_remaining)?; |
| 12237 | outer_remaining = new_remaining; |
| 12238 | Some(geometry) |
| 12239 | } else { |
| 12240 | None |
| 12241 | }; |
| 12242 | let result = GetKbdByNameReplies { types, compat_map, indicator_maps, key_names, geometry }; |
| 12243 | Ok((result, outer_remaining)) |
| 12244 | } |
| 12245 | } |
| 12246 | impl GetKbdByNameReplies { |
| 12247 | #[allow (dead_code)] |
| 12248 | fn serialize(&self, reported: u16) -> Vec<u8> { |
| 12249 | let mut result = Vec::new(); |
| 12250 | self.serialize_into(&mut result, u16::from(reported)); |
| 12251 | result |
| 12252 | } |
| 12253 | fn serialize_into(&self, bytes: &mut Vec<u8>, reported: u16) { |
| 12254 | let _ = reported; |
| 12255 | if let Some(ref types) = self.types { |
| 12256 | types.serialize_into(bytes); |
| 12257 | } |
| 12258 | if let Some(ref compat_map) = self.compat_map { |
| 12259 | compat_map.serialize_into(bytes); |
| 12260 | } |
| 12261 | if let Some(ref indicator_maps) = self.indicator_maps { |
| 12262 | indicator_maps.serialize_into(bytes); |
| 12263 | } |
| 12264 | if let Some(ref key_names) = self.key_names { |
| 12265 | key_names.serialize_into(bytes); |
| 12266 | } |
| 12267 | if let Some(ref geometry) = self.geometry { |
| 12268 | geometry.serialize_into(bytes); |
| 12269 | } |
| 12270 | } |
| 12271 | } |
| 12272 | |
| 12273 | #[derive (Clone)] |
| 12274 | #[cfg_attr (feature = "extra-traits" , derive(Debug))] |
| 12275 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12276 | pub struct GetKbdByNameReply { |
| 12277 | pub device_id: u8, |
| 12278 | pub sequence: u16, |
| 12279 | pub length: u32, |
| 12280 | pub min_key_code: xproto::Keycode, |
| 12281 | pub max_key_code: xproto::Keycode, |
| 12282 | pub loaded: bool, |
| 12283 | pub new_keyboard: bool, |
| 12284 | pub found: GBNDetail, |
| 12285 | pub reported: GBNDetail, |
| 12286 | pub replies: GetKbdByNameReplies, |
| 12287 | } |
| 12288 | impl_debug_if_no_extra_traits!(GetKbdByNameReply, "GetKbdByNameReply" ); |
| 12289 | impl TryParse for GetKbdByNameReply { |
| 12290 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 12291 | let remaining = initial_value; |
| 12292 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 12293 | let (device_id, remaining) = u8::try_parse(remaining)?; |
| 12294 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 12295 | let (length, remaining) = u32::try_parse(remaining)?; |
| 12296 | let (min_key_code, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 12297 | let (max_key_code, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 12298 | let (loaded, remaining) = bool::try_parse(remaining)?; |
| 12299 | let (new_keyboard, remaining) = bool::try_parse(remaining)?; |
| 12300 | let (found, remaining) = u16::try_parse(remaining)?; |
| 12301 | let (reported, remaining) = u16::try_parse(remaining)?; |
| 12302 | let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?; |
| 12303 | let (replies, remaining) = GetKbdByNameReplies::try_parse(remaining, u16::from(reported))?; |
| 12304 | if response_type != 1 { |
| 12305 | return Err(ParseError::InvalidValue); |
| 12306 | } |
| 12307 | let found = found.into(); |
| 12308 | let reported = reported.into(); |
| 12309 | let result = GetKbdByNameReply { device_id, sequence, length, min_key_code, max_key_code, loaded, new_keyboard, found, reported, replies }; |
| 12310 | let _ = remaining; |
| 12311 | let remaining = initial_value.get(32 + length as usize * 4..) |
| 12312 | .ok_or(ParseError::InsufficientData)?; |
| 12313 | Ok((result, remaining)) |
| 12314 | } |
| 12315 | } |
| 12316 | impl Serialize for GetKbdByNameReply { |
| 12317 | type Bytes = Vec<u8>; |
| 12318 | fn serialize(&self) -> Vec<u8> { |
| 12319 | let mut result: Vec = Vec::new(); |
| 12320 | self.serialize_into(&mut result); |
| 12321 | result |
| 12322 | } |
| 12323 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 12324 | bytes.reserve(additional:32); |
| 12325 | let response_type_bytes: &[u8; 1] = &[1]; |
| 12326 | bytes.push(response_type_bytes[0]); |
| 12327 | self.device_id.serialize_into(bytes); |
| 12328 | self.sequence.serialize_into(bytes); |
| 12329 | self.length.serialize_into(bytes); |
| 12330 | self.min_key_code.serialize_into(bytes); |
| 12331 | self.max_key_code.serialize_into(bytes); |
| 12332 | self.loaded.serialize_into(bytes); |
| 12333 | self.new_keyboard.serialize_into(bytes); |
| 12334 | u16::from(self.found).serialize_into(bytes); |
| 12335 | u16::from(self.reported).serialize_into(bytes); |
| 12336 | bytes.extend_from_slice(&[0; 16]); |
| 12337 | self.replies.serialize_into(bytes, reported:u16::from(self.reported)); |
| 12338 | } |
| 12339 | } |
| 12340 | |
| 12341 | /// Opcode for the GetDeviceInfo request |
| 12342 | pub const GET_DEVICE_INFO_REQUEST: u8 = 24; |
| 12343 | #[derive (Clone, Copy, Default)] |
| 12344 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 12345 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12346 | pub struct GetDeviceInfoRequest { |
| 12347 | pub device_spec: DeviceSpec, |
| 12348 | pub wanted: XIFeature, |
| 12349 | pub all_buttons: bool, |
| 12350 | pub first_button: u8, |
| 12351 | pub n_buttons: u8, |
| 12352 | pub led_class: LedClass, |
| 12353 | pub led_id: IDSpec, |
| 12354 | } |
| 12355 | impl_debug_if_no_extra_traits!(GetDeviceInfoRequest, "GetDeviceInfoRequest" ); |
| 12356 | impl GetDeviceInfoRequest { |
| 12357 | /// Serialize this request into bytes for the provided connection |
| 12358 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
| 12359 | let length_so_far = 0; |
| 12360 | let device_spec_bytes = self.device_spec.serialize(); |
| 12361 | let wanted_bytes = u16::from(self.wanted).serialize(); |
| 12362 | let all_buttons_bytes = self.all_buttons.serialize(); |
| 12363 | let first_button_bytes = self.first_button.serialize(); |
| 12364 | let n_buttons_bytes = self.n_buttons.serialize(); |
| 12365 | let led_class_bytes = LedClassSpec::from(self.led_class).serialize(); |
| 12366 | let led_id_bytes = self.led_id.serialize(); |
| 12367 | let mut request0 = vec![ |
| 12368 | major_opcode, |
| 12369 | GET_DEVICE_INFO_REQUEST, |
| 12370 | 0, |
| 12371 | 0, |
| 12372 | device_spec_bytes[0], |
| 12373 | device_spec_bytes[1], |
| 12374 | wanted_bytes[0], |
| 12375 | wanted_bytes[1], |
| 12376 | all_buttons_bytes[0], |
| 12377 | first_button_bytes[0], |
| 12378 | n_buttons_bytes[0], |
| 12379 | 0, |
| 12380 | led_class_bytes[0], |
| 12381 | led_class_bytes[1], |
| 12382 | led_id_bytes[0], |
| 12383 | led_id_bytes[1], |
| 12384 | ]; |
| 12385 | let length_so_far = length_so_far + request0.len(); |
| 12386 | assert_eq!(length_so_far % 4, 0); |
| 12387 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 12388 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 12389 | ([request0.into()], vec![]) |
| 12390 | } |
| 12391 | /// Parse this request given its header, its body, and any fds that go along with it |
| 12392 | #[cfg (feature = "request-parsing" )] |
| 12393 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
| 12394 | if header.minor_opcode != GET_DEVICE_INFO_REQUEST { |
| 12395 | return Err(ParseError::InvalidValue); |
| 12396 | } |
| 12397 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 12398 | let (wanted, remaining) = u16::try_parse(remaining)?; |
| 12399 | let wanted = wanted.into(); |
| 12400 | let (all_buttons, remaining) = bool::try_parse(remaining)?; |
| 12401 | let (first_button, remaining) = u8::try_parse(remaining)?; |
| 12402 | let (n_buttons, remaining) = u8::try_parse(remaining)?; |
| 12403 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 12404 | let (led_class, remaining) = LedClassSpec::try_parse(remaining)?; |
| 12405 | let led_class = led_class.into(); |
| 12406 | let (led_id, remaining) = IDSpec::try_parse(remaining)?; |
| 12407 | let _ = remaining; |
| 12408 | Ok(GetDeviceInfoRequest { |
| 12409 | device_spec, |
| 12410 | wanted, |
| 12411 | all_buttons, |
| 12412 | first_button, |
| 12413 | n_buttons, |
| 12414 | led_class, |
| 12415 | led_id, |
| 12416 | }) |
| 12417 | } |
| 12418 | } |
| 12419 | impl Request for GetDeviceInfoRequest { |
| 12420 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 12421 | |
| 12422 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 12423 | let (bufs: [Cow<'static, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
| 12424 | // Flatten the buffers into a single vector |
| 12425 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 12426 | (buf, fds) |
| 12427 | } |
| 12428 | } |
| 12429 | impl crate::x11_utils::ReplyRequest for GetDeviceInfoRequest { |
| 12430 | type Reply = GetDeviceInfoReply; |
| 12431 | } |
| 12432 | |
| 12433 | #[derive (Clone)] |
| 12434 | #[cfg_attr (feature = "extra-traits" , derive(Debug))] |
| 12435 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12436 | pub struct GetDeviceInfoReply { |
| 12437 | pub device_id: u8, |
| 12438 | pub sequence: u16, |
| 12439 | pub length: u32, |
| 12440 | pub present: XIFeature, |
| 12441 | pub supported: XIFeature, |
| 12442 | pub unsupported: XIFeature, |
| 12443 | pub first_btn_wanted: u8, |
| 12444 | pub n_btns_wanted: u8, |
| 12445 | pub first_btn_rtrn: u8, |
| 12446 | pub total_btns: u8, |
| 12447 | pub has_own_state: bool, |
| 12448 | pub dflt_kbd_fb: u16, |
| 12449 | pub dflt_led_fb: u16, |
| 12450 | pub dev_type: xproto::Atom, |
| 12451 | pub name: Vec<String8>, |
| 12452 | pub btn_actions: Vec<Action>, |
| 12453 | pub leds: Vec<DeviceLedInfo>, |
| 12454 | } |
| 12455 | impl_debug_if_no_extra_traits!(GetDeviceInfoReply, "GetDeviceInfoReply" ); |
| 12456 | impl TryParse for GetDeviceInfoReply { |
| 12457 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 12458 | let remaining = initial_value; |
| 12459 | let value = remaining; |
| 12460 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 12461 | let (device_id, remaining) = u8::try_parse(remaining)?; |
| 12462 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 12463 | let (length, remaining) = u32::try_parse(remaining)?; |
| 12464 | let (present, remaining) = u16::try_parse(remaining)?; |
| 12465 | let (supported, remaining) = u16::try_parse(remaining)?; |
| 12466 | let (unsupported, remaining) = u16::try_parse(remaining)?; |
| 12467 | let (n_device_led_f_bs, remaining) = u16::try_parse(remaining)?; |
| 12468 | let (first_btn_wanted, remaining) = u8::try_parse(remaining)?; |
| 12469 | let (n_btns_wanted, remaining) = u8::try_parse(remaining)?; |
| 12470 | let (first_btn_rtrn, remaining) = u8::try_parse(remaining)?; |
| 12471 | let (n_btns_rtrn, remaining) = u8::try_parse(remaining)?; |
| 12472 | let (total_btns, remaining) = u8::try_parse(remaining)?; |
| 12473 | let (has_own_state, remaining) = bool::try_parse(remaining)?; |
| 12474 | let (dflt_kbd_fb, remaining) = u16::try_parse(remaining)?; |
| 12475 | let (dflt_led_fb, remaining) = u16::try_parse(remaining)?; |
| 12476 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 12477 | let (dev_type, remaining) = xproto::Atom::try_parse(remaining)?; |
| 12478 | let (name_len, remaining) = u16::try_parse(remaining)?; |
| 12479 | let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; |
| 12480 | let name = name.to_vec(); |
| 12481 | // Align offset to multiple of 4 |
| 12482 | let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; |
| 12483 | let misalignment = (4 - (offset % 4)) % 4; |
| 12484 | let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; |
| 12485 | let (btn_actions, remaining) = crate::x11_utils::parse_list::<Action>(remaining, n_btns_rtrn.try_to_usize()?)?; |
| 12486 | let (leds, remaining) = crate::x11_utils::parse_list::<DeviceLedInfo>(remaining, n_device_led_f_bs.try_to_usize()?)?; |
| 12487 | if response_type != 1 { |
| 12488 | return Err(ParseError::InvalidValue); |
| 12489 | } |
| 12490 | let present = present.into(); |
| 12491 | let supported = supported.into(); |
| 12492 | let unsupported = unsupported.into(); |
| 12493 | 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 }; |
| 12494 | let _ = remaining; |
| 12495 | let remaining = initial_value.get(32 + length as usize * 4..) |
| 12496 | .ok_or(ParseError::InsufficientData)?; |
| 12497 | Ok((result, remaining)) |
| 12498 | } |
| 12499 | } |
| 12500 | impl Serialize for GetDeviceInfoReply { |
| 12501 | type Bytes = Vec<u8>; |
| 12502 | fn serialize(&self) -> Vec<u8> { |
| 12503 | let mut result = Vec::new(); |
| 12504 | self.serialize_into(&mut result); |
| 12505 | result |
| 12506 | } |
| 12507 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 12508 | bytes.reserve(34); |
| 12509 | let response_type_bytes = &[1]; |
| 12510 | bytes.push(response_type_bytes[0]); |
| 12511 | self.device_id.serialize_into(bytes); |
| 12512 | self.sequence.serialize_into(bytes); |
| 12513 | self.length.serialize_into(bytes); |
| 12514 | u16::from(self.present).serialize_into(bytes); |
| 12515 | u16::from(self.supported).serialize_into(bytes); |
| 12516 | u16::from(self.unsupported).serialize_into(bytes); |
| 12517 | let n_device_led_f_bs = u16::try_from(self.leds.len()).expect("`leds` has too many elements" ); |
| 12518 | n_device_led_f_bs.serialize_into(bytes); |
| 12519 | self.first_btn_wanted.serialize_into(bytes); |
| 12520 | self.n_btns_wanted.serialize_into(bytes); |
| 12521 | self.first_btn_rtrn.serialize_into(bytes); |
| 12522 | let n_btns_rtrn = u8::try_from(self.btn_actions.len()).expect("`btn_actions` has too many elements" ); |
| 12523 | n_btns_rtrn.serialize_into(bytes); |
| 12524 | self.total_btns.serialize_into(bytes); |
| 12525 | self.has_own_state.serialize_into(bytes); |
| 12526 | self.dflt_kbd_fb.serialize_into(bytes); |
| 12527 | self.dflt_led_fb.serialize_into(bytes); |
| 12528 | bytes.extend_from_slice(&[0; 2]); |
| 12529 | self.dev_type.serialize_into(bytes); |
| 12530 | let name_len = u16::try_from(self.name.len()).expect("`name` has too many elements" ); |
| 12531 | name_len.serialize_into(bytes); |
| 12532 | bytes.extend_from_slice(&self.name); |
| 12533 | bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]); |
| 12534 | self.btn_actions.serialize_into(bytes); |
| 12535 | self.leds.serialize_into(bytes); |
| 12536 | } |
| 12537 | } |
| 12538 | impl GetDeviceInfoReply { |
| 12539 | /// Get the value of the `nDeviceLedFBs` field. |
| 12540 | /// |
| 12541 | /// The `nDeviceLedFBs` field is used as the length field of the `leds` field. |
| 12542 | /// This function computes the field's value again based on the length of the list. |
| 12543 | /// |
| 12544 | /// # Panics |
| 12545 | /// |
| 12546 | /// Panics if the value cannot be represented in the target type. This |
| 12547 | /// cannot happen with values of the struct received from the X11 server. |
| 12548 | pub fn n_device_led_f_bs(&self) -> u16 { |
| 12549 | self.leds.len() |
| 12550 | .try_into().unwrap() |
| 12551 | } |
| 12552 | /// Get the value of the `nBtnsRtrn` field. |
| 12553 | /// |
| 12554 | /// The `nBtnsRtrn` field is used as the length field of the `btnActions` field. |
| 12555 | /// This function computes the field's value again based on the length of the list. |
| 12556 | /// |
| 12557 | /// # Panics |
| 12558 | /// |
| 12559 | /// Panics if the value cannot be represented in the target type. This |
| 12560 | /// cannot happen with values of the struct received from the X11 server. |
| 12561 | pub fn n_btns_rtrn(&self) -> u8 { |
| 12562 | self.btn_actions.len() |
| 12563 | .try_into().unwrap() |
| 12564 | } |
| 12565 | /// Get the value of the `nameLen` field. |
| 12566 | /// |
| 12567 | /// The `nameLen` field is used as the length field of the `name` field. |
| 12568 | /// This function computes the field's value again based on the length of the list. |
| 12569 | /// |
| 12570 | /// # Panics |
| 12571 | /// |
| 12572 | /// Panics if the value cannot be represented in the target type. This |
| 12573 | /// cannot happen with values of the struct received from the X11 server. |
| 12574 | pub fn name_len(&self) -> u16 { |
| 12575 | self.name.len() |
| 12576 | .try_into().unwrap() |
| 12577 | } |
| 12578 | } |
| 12579 | |
| 12580 | /// Opcode for the SetDeviceInfo request |
| 12581 | pub const SET_DEVICE_INFO_REQUEST: u8 = 25; |
| 12582 | #[derive (Clone)] |
| 12583 | #[cfg_attr (feature = "extra-traits" , derive(Debug))] |
| 12584 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12585 | pub struct SetDeviceInfoRequest<'input> { |
| 12586 | pub device_spec: DeviceSpec, |
| 12587 | pub first_btn: u8, |
| 12588 | pub change: XIFeature, |
| 12589 | pub btn_actions: Cow<'input, [Action]>, |
| 12590 | pub leds: Cow<'input, [DeviceLedInfo]>, |
| 12591 | } |
| 12592 | impl_debug_if_no_extra_traits!(SetDeviceInfoRequest<'_>, "SetDeviceInfoRequest" ); |
| 12593 | impl<'input> SetDeviceInfoRequest<'input> { |
| 12594 | /// Serialize this request into bytes for the provided connection |
| 12595 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 4]> { |
| 12596 | let length_so_far = 0; |
| 12597 | let device_spec_bytes = self.device_spec.serialize(); |
| 12598 | let first_btn_bytes = self.first_btn.serialize(); |
| 12599 | let n_btns = u8::try_from(self.btn_actions.len()).expect("`btn_actions` has too many elements" ); |
| 12600 | let n_btns_bytes = n_btns.serialize(); |
| 12601 | let change_bytes = u16::from(self.change).serialize(); |
| 12602 | let n_device_led_f_bs = u16::try_from(self.leds.len()).expect("`leds` has too many elements" ); |
| 12603 | let n_device_led_f_bs_bytes = n_device_led_f_bs.serialize(); |
| 12604 | let mut request0 = vec![ |
| 12605 | major_opcode, |
| 12606 | SET_DEVICE_INFO_REQUEST, |
| 12607 | 0, |
| 12608 | 0, |
| 12609 | device_spec_bytes[0], |
| 12610 | device_spec_bytes[1], |
| 12611 | first_btn_bytes[0], |
| 12612 | n_btns_bytes[0], |
| 12613 | change_bytes[0], |
| 12614 | change_bytes[1], |
| 12615 | n_device_led_f_bs_bytes[0], |
| 12616 | n_device_led_f_bs_bytes[1], |
| 12617 | ]; |
| 12618 | let length_so_far = length_so_far + request0.len(); |
| 12619 | let btn_actions_bytes = self.btn_actions.serialize(); |
| 12620 | let length_so_far = length_so_far + btn_actions_bytes.len(); |
| 12621 | let leds_bytes = self.leds.serialize(); |
| 12622 | let length_so_far = length_so_far + leds_bytes.len(); |
| 12623 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 12624 | let length_so_far = length_so_far + padding0.len(); |
| 12625 | assert_eq!(length_so_far % 4, 0); |
| 12626 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 12627 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 12628 | ([request0.into(), btn_actions_bytes.into(), leds_bytes.into(), padding0.into()], vec![]) |
| 12629 | } |
| 12630 | /// Parse this request given its header, its body, and any fds that go along with it |
| 12631 | #[cfg (feature = "request-parsing" )] |
| 12632 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 12633 | if header.minor_opcode != SET_DEVICE_INFO_REQUEST { |
| 12634 | return Err(ParseError::InvalidValue); |
| 12635 | } |
| 12636 | let (device_spec, remaining) = DeviceSpec::try_parse(value)?; |
| 12637 | let (first_btn, remaining) = u8::try_parse(remaining)?; |
| 12638 | let (n_btns, remaining) = u8::try_parse(remaining)?; |
| 12639 | let (change, remaining) = u16::try_parse(remaining)?; |
| 12640 | let change = change.into(); |
| 12641 | let (n_device_led_f_bs, remaining) = u16::try_parse(remaining)?; |
| 12642 | let (btn_actions, remaining) = crate::x11_utils::parse_list::<Action>(remaining, n_btns.try_to_usize()?)?; |
| 12643 | let (leds, remaining) = crate::x11_utils::parse_list::<DeviceLedInfo>(remaining, n_device_led_f_bs.try_to_usize()?)?; |
| 12644 | let _ = remaining; |
| 12645 | Ok(SetDeviceInfoRequest { |
| 12646 | device_spec, |
| 12647 | first_btn, |
| 12648 | change, |
| 12649 | btn_actions: Cow::Owned(btn_actions), |
| 12650 | leds: Cow::Owned(leds), |
| 12651 | }) |
| 12652 | } |
| 12653 | /// Clone all borrowed data in this SetDeviceInfoRequest. |
| 12654 | pub fn into_owned(self) -> SetDeviceInfoRequest<'static> { |
| 12655 | SetDeviceInfoRequest { |
| 12656 | device_spec: self.device_spec, |
| 12657 | first_btn: self.first_btn, |
| 12658 | change: self.change, |
| 12659 | btn_actions: Cow::Owned(self.btn_actions.into_owned()), |
| 12660 | leds: Cow::Owned(self.leds.into_owned()), |
| 12661 | } |
| 12662 | } |
| 12663 | } |
| 12664 | impl<'input> Request for SetDeviceInfoRequest<'input> { |
| 12665 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 12666 | |
| 12667 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 12668 | let (bufs: [Cow<'_, [u8]>; 4], fds: Vec) = self.serialize(major_opcode); |
| 12669 | // Flatten the buffers into a single vector |
| 12670 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 12671 | (buf, fds) |
| 12672 | } |
| 12673 | } |
| 12674 | impl<'input> crate::x11_utils::VoidRequest for SetDeviceInfoRequest<'input> { |
| 12675 | } |
| 12676 | |
| 12677 | /// Opcode for the SetDebuggingFlags request |
| 12678 | pub const SET_DEBUGGING_FLAGS_REQUEST: u8 = 101; |
| 12679 | #[derive (Clone, Default)] |
| 12680 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 12681 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12682 | pub struct SetDebuggingFlagsRequest<'input> { |
| 12683 | pub affect_flags: u32, |
| 12684 | pub flags: u32, |
| 12685 | pub affect_ctrls: u32, |
| 12686 | pub ctrls: u32, |
| 12687 | pub message: Cow<'input, [String8]>, |
| 12688 | } |
| 12689 | impl_debug_if_no_extra_traits!(SetDebuggingFlagsRequest<'_>, "SetDebuggingFlagsRequest" ); |
| 12690 | impl<'input> SetDebuggingFlagsRequest<'input> { |
| 12691 | /// Serialize this request into bytes for the provided connection |
| 12692 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> { |
| 12693 | let length_so_far = 0; |
| 12694 | let msg_length = u16::try_from(self.message.len()).expect("`message` has too many elements" ); |
| 12695 | let msg_length_bytes = msg_length.serialize(); |
| 12696 | let affect_flags_bytes = self.affect_flags.serialize(); |
| 12697 | let flags_bytes = self.flags.serialize(); |
| 12698 | let affect_ctrls_bytes = self.affect_ctrls.serialize(); |
| 12699 | let ctrls_bytes = self.ctrls.serialize(); |
| 12700 | let mut request0 = vec![ |
| 12701 | major_opcode, |
| 12702 | SET_DEBUGGING_FLAGS_REQUEST, |
| 12703 | 0, |
| 12704 | 0, |
| 12705 | msg_length_bytes[0], |
| 12706 | msg_length_bytes[1], |
| 12707 | 0, |
| 12708 | 0, |
| 12709 | affect_flags_bytes[0], |
| 12710 | affect_flags_bytes[1], |
| 12711 | affect_flags_bytes[2], |
| 12712 | affect_flags_bytes[3], |
| 12713 | flags_bytes[0], |
| 12714 | flags_bytes[1], |
| 12715 | flags_bytes[2], |
| 12716 | flags_bytes[3], |
| 12717 | affect_ctrls_bytes[0], |
| 12718 | affect_ctrls_bytes[1], |
| 12719 | affect_ctrls_bytes[2], |
| 12720 | affect_ctrls_bytes[3], |
| 12721 | ctrls_bytes[0], |
| 12722 | ctrls_bytes[1], |
| 12723 | ctrls_bytes[2], |
| 12724 | ctrls_bytes[3], |
| 12725 | ]; |
| 12726 | let length_so_far = length_so_far + request0.len(); |
| 12727 | let length_so_far = length_so_far + self.message.len(); |
| 12728 | let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4]; |
| 12729 | let length_so_far = length_so_far + padding0.len(); |
| 12730 | assert_eq!(length_so_far % 4, 0); |
| 12731 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
| 12732 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
| 12733 | ([request0.into(), self.message, padding0.into()], vec![]) |
| 12734 | } |
| 12735 | /// Parse this request given its header, its body, and any fds that go along with it |
| 12736 | #[cfg (feature = "request-parsing" )] |
| 12737 | pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> { |
| 12738 | if header.minor_opcode != SET_DEBUGGING_FLAGS_REQUEST { |
| 12739 | return Err(ParseError::InvalidValue); |
| 12740 | } |
| 12741 | let (msg_length, remaining) = u16::try_parse(value)?; |
| 12742 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 12743 | let (affect_flags, remaining) = u32::try_parse(remaining)?; |
| 12744 | let (flags, remaining) = u32::try_parse(remaining)?; |
| 12745 | let (affect_ctrls, remaining) = u32::try_parse(remaining)?; |
| 12746 | let (ctrls, remaining) = u32::try_parse(remaining)?; |
| 12747 | let (message, remaining) = crate::x11_utils::parse_u8_list(remaining, msg_length.try_to_usize()?)?; |
| 12748 | let _ = remaining; |
| 12749 | Ok(SetDebuggingFlagsRequest { |
| 12750 | affect_flags, |
| 12751 | flags, |
| 12752 | affect_ctrls, |
| 12753 | ctrls, |
| 12754 | message: Cow::Borrowed(message), |
| 12755 | }) |
| 12756 | } |
| 12757 | /// Clone all borrowed data in this SetDebuggingFlagsRequest. |
| 12758 | pub fn into_owned(self) -> SetDebuggingFlagsRequest<'static> { |
| 12759 | SetDebuggingFlagsRequest { |
| 12760 | affect_flags: self.affect_flags, |
| 12761 | flags: self.flags, |
| 12762 | affect_ctrls: self.affect_ctrls, |
| 12763 | ctrls: self.ctrls, |
| 12764 | message: Cow::Owned(self.message.into_owned()), |
| 12765 | } |
| 12766 | } |
| 12767 | } |
| 12768 | impl<'input> Request for SetDebuggingFlagsRequest<'input> { |
| 12769 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
| 12770 | |
| 12771 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
| 12772 | let (bufs: [Cow<'_, [u8]>; 3], fds: Vec) = self.serialize(major_opcode); |
| 12773 | // Flatten the buffers into a single vector |
| 12774 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
| 12775 | (buf, fds) |
| 12776 | } |
| 12777 | } |
| 12778 | impl<'input> crate::x11_utils::ReplyRequest for SetDebuggingFlagsRequest<'input> { |
| 12779 | type Reply = SetDebuggingFlagsReply; |
| 12780 | } |
| 12781 | |
| 12782 | #[derive (Clone, Copy, Default)] |
| 12783 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 12784 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12785 | pub struct SetDebuggingFlagsReply { |
| 12786 | pub sequence: u16, |
| 12787 | pub length: u32, |
| 12788 | pub current_flags: u32, |
| 12789 | pub current_ctrls: u32, |
| 12790 | pub supported_flags: u32, |
| 12791 | pub supported_ctrls: u32, |
| 12792 | } |
| 12793 | impl_debug_if_no_extra_traits!(SetDebuggingFlagsReply, "SetDebuggingFlagsReply" ); |
| 12794 | impl TryParse for SetDebuggingFlagsReply { |
| 12795 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 12796 | let remaining: &[u8] = initial_value; |
| 12797 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 12798 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
| 12799 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 12800 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 12801 | let (current_flags: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 12802 | let (current_ctrls: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 12803 | let (supported_flags: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 12804 | let (supported_ctrls: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 12805 | let remaining: &[u8] = remaining.get(8..).ok_or(err:ParseError::InsufficientData)?; |
| 12806 | if response_type != 1 { |
| 12807 | return Err(ParseError::InvalidValue); |
| 12808 | } |
| 12809 | let result: SetDebuggingFlagsReply = SetDebuggingFlagsReply { sequence, length, current_flags, current_ctrls, supported_flags, supported_ctrls }; |
| 12810 | let _ = remaining; |
| 12811 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
| 12812 | .ok_or(err:ParseError::InsufficientData)?; |
| 12813 | Ok((result, remaining)) |
| 12814 | } |
| 12815 | } |
| 12816 | impl Serialize for SetDebuggingFlagsReply { |
| 12817 | type Bytes = [u8; 32]; |
| 12818 | fn serialize(&self) -> [u8; 32] { |
| 12819 | let response_type_bytes = &[1]; |
| 12820 | let sequence_bytes = self.sequence.serialize(); |
| 12821 | let length_bytes = self.length.serialize(); |
| 12822 | let current_flags_bytes = self.current_flags.serialize(); |
| 12823 | let current_ctrls_bytes = self.current_ctrls.serialize(); |
| 12824 | let supported_flags_bytes = self.supported_flags.serialize(); |
| 12825 | let supported_ctrls_bytes = self.supported_ctrls.serialize(); |
| 12826 | [ |
| 12827 | response_type_bytes[0], |
| 12828 | 0, |
| 12829 | sequence_bytes[0], |
| 12830 | sequence_bytes[1], |
| 12831 | length_bytes[0], |
| 12832 | length_bytes[1], |
| 12833 | length_bytes[2], |
| 12834 | length_bytes[3], |
| 12835 | current_flags_bytes[0], |
| 12836 | current_flags_bytes[1], |
| 12837 | current_flags_bytes[2], |
| 12838 | current_flags_bytes[3], |
| 12839 | current_ctrls_bytes[0], |
| 12840 | current_ctrls_bytes[1], |
| 12841 | current_ctrls_bytes[2], |
| 12842 | current_ctrls_bytes[3], |
| 12843 | supported_flags_bytes[0], |
| 12844 | supported_flags_bytes[1], |
| 12845 | supported_flags_bytes[2], |
| 12846 | supported_flags_bytes[3], |
| 12847 | supported_ctrls_bytes[0], |
| 12848 | supported_ctrls_bytes[1], |
| 12849 | supported_ctrls_bytes[2], |
| 12850 | supported_ctrls_bytes[3], |
| 12851 | 0, |
| 12852 | 0, |
| 12853 | 0, |
| 12854 | 0, |
| 12855 | 0, |
| 12856 | 0, |
| 12857 | 0, |
| 12858 | 0, |
| 12859 | ] |
| 12860 | } |
| 12861 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 12862 | bytes.reserve(32); |
| 12863 | let response_type_bytes = &[1]; |
| 12864 | bytes.push(response_type_bytes[0]); |
| 12865 | bytes.extend_from_slice(&[0; 1]); |
| 12866 | self.sequence.serialize_into(bytes); |
| 12867 | self.length.serialize_into(bytes); |
| 12868 | self.current_flags.serialize_into(bytes); |
| 12869 | self.current_ctrls.serialize_into(bytes); |
| 12870 | self.supported_flags.serialize_into(bytes); |
| 12871 | self.supported_ctrls.serialize_into(bytes); |
| 12872 | bytes.extend_from_slice(&[0; 8]); |
| 12873 | } |
| 12874 | } |
| 12875 | |
| 12876 | /// Opcode for the NewKeyboardNotify event |
| 12877 | pub const NEW_KEYBOARD_NOTIFY_EVENT: u8 = 0; |
| 12878 | #[derive (Clone, Copy, Default)] |
| 12879 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 12880 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 12881 | pub struct NewKeyboardNotifyEvent { |
| 12882 | pub response_type: u8, |
| 12883 | pub xkb_type: u8, |
| 12884 | pub sequence: u16, |
| 12885 | pub time: xproto::Timestamp, |
| 12886 | pub device_id: u8, |
| 12887 | pub old_device_id: u8, |
| 12888 | pub min_key_code: xproto::Keycode, |
| 12889 | pub max_key_code: xproto::Keycode, |
| 12890 | pub old_min_key_code: xproto::Keycode, |
| 12891 | pub old_max_key_code: xproto::Keycode, |
| 12892 | pub request_major: u8, |
| 12893 | pub request_minor: u8, |
| 12894 | pub changed: NKNDetail, |
| 12895 | } |
| 12896 | impl_debug_if_no_extra_traits!(NewKeyboardNotifyEvent, "NewKeyboardNotifyEvent" ); |
| 12897 | impl TryParse for NewKeyboardNotifyEvent { |
| 12898 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 12899 | let remaining = initial_value; |
| 12900 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 12901 | let (xkb_type, remaining) = u8::try_parse(remaining)?; |
| 12902 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 12903 | let (time, remaining) = xproto::Timestamp::try_parse(remaining)?; |
| 12904 | let (device_id, remaining) = u8::try_parse(remaining)?; |
| 12905 | let (old_device_id, remaining) = u8::try_parse(remaining)?; |
| 12906 | let (min_key_code, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 12907 | let (max_key_code, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 12908 | let (old_min_key_code, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 12909 | let (old_max_key_code, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 12910 | let (request_major, remaining) = u8::try_parse(remaining)?; |
| 12911 | let (request_minor, remaining) = u8::try_parse(remaining)?; |
| 12912 | let (changed, remaining) = u16::try_parse(remaining)?; |
| 12913 | let remaining = remaining.get(14..).ok_or(ParseError::InsufficientData)?; |
| 12914 | let changed = changed.into(); |
| 12915 | 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 }; |
| 12916 | let _ = remaining; |
| 12917 | let remaining = initial_value.get(32..) |
| 12918 | .ok_or(ParseError::InsufficientData)?; |
| 12919 | Ok((result, remaining)) |
| 12920 | } |
| 12921 | } |
| 12922 | impl Serialize for NewKeyboardNotifyEvent { |
| 12923 | type Bytes = [u8; 32]; |
| 12924 | fn serialize(&self) -> [u8; 32] { |
| 12925 | let response_type_bytes = self.response_type.serialize(); |
| 12926 | let xkb_type_bytes = self.xkb_type.serialize(); |
| 12927 | let sequence_bytes = self.sequence.serialize(); |
| 12928 | let time_bytes = self.time.serialize(); |
| 12929 | let device_id_bytes = self.device_id.serialize(); |
| 12930 | let old_device_id_bytes = self.old_device_id.serialize(); |
| 12931 | let min_key_code_bytes = self.min_key_code.serialize(); |
| 12932 | let max_key_code_bytes = self.max_key_code.serialize(); |
| 12933 | let old_min_key_code_bytes = self.old_min_key_code.serialize(); |
| 12934 | let old_max_key_code_bytes = self.old_max_key_code.serialize(); |
| 12935 | let request_major_bytes = self.request_major.serialize(); |
| 12936 | let request_minor_bytes = self.request_minor.serialize(); |
| 12937 | let changed_bytes = u16::from(self.changed).serialize(); |
| 12938 | [ |
| 12939 | response_type_bytes[0], |
| 12940 | xkb_type_bytes[0], |
| 12941 | sequence_bytes[0], |
| 12942 | sequence_bytes[1], |
| 12943 | time_bytes[0], |
| 12944 | time_bytes[1], |
| 12945 | time_bytes[2], |
| 12946 | time_bytes[3], |
| 12947 | device_id_bytes[0], |
| 12948 | old_device_id_bytes[0], |
| 12949 | min_key_code_bytes[0], |
| 12950 | max_key_code_bytes[0], |
| 12951 | old_min_key_code_bytes[0], |
| 12952 | old_max_key_code_bytes[0], |
| 12953 | request_major_bytes[0], |
| 12954 | request_minor_bytes[0], |
| 12955 | changed_bytes[0], |
| 12956 | changed_bytes[1], |
| 12957 | 0, |
| 12958 | 0, |
| 12959 | 0, |
| 12960 | 0, |
| 12961 | 0, |
| 12962 | 0, |
| 12963 | 0, |
| 12964 | 0, |
| 12965 | 0, |
| 12966 | 0, |
| 12967 | 0, |
| 12968 | 0, |
| 12969 | 0, |
| 12970 | 0, |
| 12971 | ] |
| 12972 | } |
| 12973 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 12974 | bytes.reserve(32); |
| 12975 | self.response_type.serialize_into(bytes); |
| 12976 | self.xkb_type.serialize_into(bytes); |
| 12977 | self.sequence.serialize_into(bytes); |
| 12978 | self.time.serialize_into(bytes); |
| 12979 | self.device_id.serialize_into(bytes); |
| 12980 | self.old_device_id.serialize_into(bytes); |
| 12981 | self.min_key_code.serialize_into(bytes); |
| 12982 | self.max_key_code.serialize_into(bytes); |
| 12983 | self.old_min_key_code.serialize_into(bytes); |
| 12984 | self.old_max_key_code.serialize_into(bytes); |
| 12985 | self.request_major.serialize_into(bytes); |
| 12986 | self.request_minor.serialize_into(bytes); |
| 12987 | u16::from(self.changed).serialize_into(bytes); |
| 12988 | bytes.extend_from_slice(&[0; 14]); |
| 12989 | } |
| 12990 | } |
| 12991 | impl From<&NewKeyboardNotifyEvent> for [u8; 32] { |
| 12992 | fn from(input: &NewKeyboardNotifyEvent) -> Self { |
| 12993 | let response_type_bytes = input.response_type.serialize(); |
| 12994 | let xkb_type_bytes = input.xkb_type.serialize(); |
| 12995 | let sequence_bytes = input.sequence.serialize(); |
| 12996 | let time_bytes = input.time.serialize(); |
| 12997 | let device_id_bytes = input.device_id.serialize(); |
| 12998 | let old_device_id_bytes = input.old_device_id.serialize(); |
| 12999 | let min_key_code_bytes = input.min_key_code.serialize(); |
| 13000 | let max_key_code_bytes = input.max_key_code.serialize(); |
| 13001 | let old_min_key_code_bytes = input.old_min_key_code.serialize(); |
| 13002 | let old_max_key_code_bytes = input.old_max_key_code.serialize(); |
| 13003 | let request_major_bytes = input.request_major.serialize(); |
| 13004 | let request_minor_bytes = input.request_minor.serialize(); |
| 13005 | let changed_bytes = u16::from(input.changed).serialize(); |
| 13006 | [ |
| 13007 | response_type_bytes[0], |
| 13008 | xkb_type_bytes[0], |
| 13009 | sequence_bytes[0], |
| 13010 | sequence_bytes[1], |
| 13011 | time_bytes[0], |
| 13012 | time_bytes[1], |
| 13013 | time_bytes[2], |
| 13014 | time_bytes[3], |
| 13015 | device_id_bytes[0], |
| 13016 | old_device_id_bytes[0], |
| 13017 | min_key_code_bytes[0], |
| 13018 | max_key_code_bytes[0], |
| 13019 | old_min_key_code_bytes[0], |
| 13020 | old_max_key_code_bytes[0], |
| 13021 | request_major_bytes[0], |
| 13022 | request_minor_bytes[0], |
| 13023 | changed_bytes[0], |
| 13024 | changed_bytes[1], |
| 13025 | 0, |
| 13026 | 0, |
| 13027 | 0, |
| 13028 | 0, |
| 13029 | 0, |
| 13030 | 0, |
| 13031 | 0, |
| 13032 | 0, |
| 13033 | 0, |
| 13034 | 0, |
| 13035 | 0, |
| 13036 | 0, |
| 13037 | 0, |
| 13038 | 0, |
| 13039 | ] |
| 13040 | } |
| 13041 | } |
| 13042 | impl From<NewKeyboardNotifyEvent> for [u8; 32] { |
| 13043 | fn from(input: NewKeyboardNotifyEvent) -> Self { |
| 13044 | Self::from(&input) |
| 13045 | } |
| 13046 | } |
| 13047 | |
| 13048 | /// Opcode for the MapNotify event |
| 13049 | pub const MAP_NOTIFY_EVENT: u8 = 1; |
| 13050 | #[derive (Clone, Copy, Default)] |
| 13051 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 13052 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 13053 | pub struct MapNotifyEvent { |
| 13054 | pub response_type: u8, |
| 13055 | pub xkb_type: u8, |
| 13056 | pub sequence: u16, |
| 13057 | pub time: xproto::Timestamp, |
| 13058 | pub device_id: u8, |
| 13059 | pub ptr_btn_actions: u8, |
| 13060 | pub changed: MapPart, |
| 13061 | pub min_key_code: xproto::Keycode, |
| 13062 | pub max_key_code: xproto::Keycode, |
| 13063 | pub first_type: u8, |
| 13064 | pub n_types: u8, |
| 13065 | pub first_key_sym: xproto::Keycode, |
| 13066 | pub n_key_syms: u8, |
| 13067 | pub first_key_act: xproto::Keycode, |
| 13068 | pub n_key_acts: u8, |
| 13069 | pub first_key_behavior: xproto::Keycode, |
| 13070 | pub n_key_behavior: u8, |
| 13071 | pub first_key_explicit: xproto::Keycode, |
| 13072 | pub n_key_explicit: u8, |
| 13073 | pub first_mod_map_key: xproto::Keycode, |
| 13074 | pub n_mod_map_keys: u8, |
| 13075 | pub first_v_mod_map_key: xproto::Keycode, |
| 13076 | pub n_v_mod_map_keys: u8, |
| 13077 | pub virtual_mods: VMod, |
| 13078 | } |
| 13079 | impl_debug_if_no_extra_traits!(MapNotifyEvent, "MapNotifyEvent" ); |
| 13080 | impl TryParse for MapNotifyEvent { |
| 13081 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 13082 | let remaining = initial_value; |
| 13083 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 13084 | let (xkb_type, remaining) = u8::try_parse(remaining)?; |
| 13085 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 13086 | let (time, remaining) = xproto::Timestamp::try_parse(remaining)?; |
| 13087 | let (device_id, remaining) = u8::try_parse(remaining)?; |
| 13088 | let (ptr_btn_actions, remaining) = u8::try_parse(remaining)?; |
| 13089 | let (changed, remaining) = u16::try_parse(remaining)?; |
| 13090 | let (min_key_code, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 13091 | let (max_key_code, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 13092 | let (first_type, remaining) = u8::try_parse(remaining)?; |
| 13093 | let (n_types, remaining) = u8::try_parse(remaining)?; |
| 13094 | let (first_key_sym, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 13095 | let (n_key_syms, remaining) = u8::try_parse(remaining)?; |
| 13096 | let (first_key_act, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 13097 | let (n_key_acts, remaining) = u8::try_parse(remaining)?; |
| 13098 | let (first_key_behavior, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 13099 | let (n_key_behavior, remaining) = u8::try_parse(remaining)?; |
| 13100 | let (first_key_explicit, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 13101 | let (n_key_explicit, remaining) = u8::try_parse(remaining)?; |
| 13102 | let (first_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 13103 | let (n_mod_map_keys, remaining) = u8::try_parse(remaining)?; |
| 13104 | let (first_v_mod_map_key, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 13105 | let (n_v_mod_map_keys, remaining) = u8::try_parse(remaining)?; |
| 13106 | let (virtual_mods, remaining) = u16::try_parse(remaining)?; |
| 13107 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 13108 | let changed = changed.into(); |
| 13109 | let virtual_mods = virtual_mods.into(); |
| 13110 | 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 }; |
| 13111 | let _ = remaining; |
| 13112 | let remaining = initial_value.get(32..) |
| 13113 | .ok_or(ParseError::InsufficientData)?; |
| 13114 | Ok((result, remaining)) |
| 13115 | } |
| 13116 | } |
| 13117 | impl Serialize for MapNotifyEvent { |
| 13118 | type Bytes = [u8; 32]; |
| 13119 | fn serialize(&self) -> [u8; 32] { |
| 13120 | let response_type_bytes = self.response_type.serialize(); |
| 13121 | let xkb_type_bytes = self.xkb_type.serialize(); |
| 13122 | let sequence_bytes = self.sequence.serialize(); |
| 13123 | let time_bytes = self.time.serialize(); |
| 13124 | let device_id_bytes = self.device_id.serialize(); |
| 13125 | let ptr_btn_actions_bytes = self.ptr_btn_actions.serialize(); |
| 13126 | let changed_bytes = u16::from(self.changed).serialize(); |
| 13127 | let min_key_code_bytes = self.min_key_code.serialize(); |
| 13128 | let max_key_code_bytes = self.max_key_code.serialize(); |
| 13129 | let first_type_bytes = self.first_type.serialize(); |
| 13130 | let n_types_bytes = self.n_types.serialize(); |
| 13131 | let first_key_sym_bytes = self.first_key_sym.serialize(); |
| 13132 | let n_key_syms_bytes = self.n_key_syms.serialize(); |
| 13133 | let first_key_act_bytes = self.first_key_act.serialize(); |
| 13134 | let n_key_acts_bytes = self.n_key_acts.serialize(); |
| 13135 | let first_key_behavior_bytes = self.first_key_behavior.serialize(); |
| 13136 | let n_key_behavior_bytes = self.n_key_behavior.serialize(); |
| 13137 | let first_key_explicit_bytes = self.first_key_explicit.serialize(); |
| 13138 | let n_key_explicit_bytes = self.n_key_explicit.serialize(); |
| 13139 | let first_mod_map_key_bytes = self.first_mod_map_key.serialize(); |
| 13140 | let n_mod_map_keys_bytes = self.n_mod_map_keys.serialize(); |
| 13141 | let first_v_mod_map_key_bytes = self.first_v_mod_map_key.serialize(); |
| 13142 | let n_v_mod_map_keys_bytes = self.n_v_mod_map_keys.serialize(); |
| 13143 | let virtual_mods_bytes = u16::from(self.virtual_mods).serialize(); |
| 13144 | [ |
| 13145 | response_type_bytes[0], |
| 13146 | xkb_type_bytes[0], |
| 13147 | sequence_bytes[0], |
| 13148 | sequence_bytes[1], |
| 13149 | time_bytes[0], |
| 13150 | time_bytes[1], |
| 13151 | time_bytes[2], |
| 13152 | time_bytes[3], |
| 13153 | device_id_bytes[0], |
| 13154 | ptr_btn_actions_bytes[0], |
| 13155 | changed_bytes[0], |
| 13156 | changed_bytes[1], |
| 13157 | min_key_code_bytes[0], |
| 13158 | max_key_code_bytes[0], |
| 13159 | first_type_bytes[0], |
| 13160 | n_types_bytes[0], |
| 13161 | first_key_sym_bytes[0], |
| 13162 | n_key_syms_bytes[0], |
| 13163 | first_key_act_bytes[0], |
| 13164 | n_key_acts_bytes[0], |
| 13165 | first_key_behavior_bytes[0], |
| 13166 | n_key_behavior_bytes[0], |
| 13167 | first_key_explicit_bytes[0], |
| 13168 | n_key_explicit_bytes[0], |
| 13169 | first_mod_map_key_bytes[0], |
| 13170 | n_mod_map_keys_bytes[0], |
| 13171 | first_v_mod_map_key_bytes[0], |
| 13172 | n_v_mod_map_keys_bytes[0], |
| 13173 | virtual_mods_bytes[0], |
| 13174 | virtual_mods_bytes[1], |
| 13175 | 0, |
| 13176 | 0, |
| 13177 | ] |
| 13178 | } |
| 13179 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 13180 | bytes.reserve(32); |
| 13181 | self.response_type.serialize_into(bytes); |
| 13182 | self.xkb_type.serialize_into(bytes); |
| 13183 | self.sequence.serialize_into(bytes); |
| 13184 | self.time.serialize_into(bytes); |
| 13185 | self.device_id.serialize_into(bytes); |
| 13186 | self.ptr_btn_actions.serialize_into(bytes); |
| 13187 | u16::from(self.changed).serialize_into(bytes); |
| 13188 | self.min_key_code.serialize_into(bytes); |
| 13189 | self.max_key_code.serialize_into(bytes); |
| 13190 | self.first_type.serialize_into(bytes); |
| 13191 | self.n_types.serialize_into(bytes); |
| 13192 | self.first_key_sym.serialize_into(bytes); |
| 13193 | self.n_key_syms.serialize_into(bytes); |
| 13194 | self.first_key_act.serialize_into(bytes); |
| 13195 | self.n_key_acts.serialize_into(bytes); |
| 13196 | self.first_key_behavior.serialize_into(bytes); |
| 13197 | self.n_key_behavior.serialize_into(bytes); |
| 13198 | self.first_key_explicit.serialize_into(bytes); |
| 13199 | self.n_key_explicit.serialize_into(bytes); |
| 13200 | self.first_mod_map_key.serialize_into(bytes); |
| 13201 | self.n_mod_map_keys.serialize_into(bytes); |
| 13202 | self.first_v_mod_map_key.serialize_into(bytes); |
| 13203 | self.n_v_mod_map_keys.serialize_into(bytes); |
| 13204 | u16::from(self.virtual_mods).serialize_into(bytes); |
| 13205 | bytes.extend_from_slice(&[0; 2]); |
| 13206 | } |
| 13207 | } |
| 13208 | impl From<&MapNotifyEvent> for [u8; 32] { |
| 13209 | fn from(input: &MapNotifyEvent) -> Self { |
| 13210 | let response_type_bytes = input.response_type.serialize(); |
| 13211 | let xkb_type_bytes = input.xkb_type.serialize(); |
| 13212 | let sequence_bytes = input.sequence.serialize(); |
| 13213 | let time_bytes = input.time.serialize(); |
| 13214 | let device_id_bytes = input.device_id.serialize(); |
| 13215 | let ptr_btn_actions_bytes = input.ptr_btn_actions.serialize(); |
| 13216 | let changed_bytes = u16::from(input.changed).serialize(); |
| 13217 | let min_key_code_bytes = input.min_key_code.serialize(); |
| 13218 | let max_key_code_bytes = input.max_key_code.serialize(); |
| 13219 | let first_type_bytes = input.first_type.serialize(); |
| 13220 | let n_types_bytes = input.n_types.serialize(); |
| 13221 | let first_key_sym_bytes = input.first_key_sym.serialize(); |
| 13222 | let n_key_syms_bytes = input.n_key_syms.serialize(); |
| 13223 | let first_key_act_bytes = input.first_key_act.serialize(); |
| 13224 | let n_key_acts_bytes = input.n_key_acts.serialize(); |
| 13225 | let first_key_behavior_bytes = input.first_key_behavior.serialize(); |
| 13226 | let n_key_behavior_bytes = input.n_key_behavior.serialize(); |
| 13227 | let first_key_explicit_bytes = input.first_key_explicit.serialize(); |
| 13228 | let n_key_explicit_bytes = input.n_key_explicit.serialize(); |
| 13229 | let first_mod_map_key_bytes = input.first_mod_map_key.serialize(); |
| 13230 | let n_mod_map_keys_bytes = input.n_mod_map_keys.serialize(); |
| 13231 | let first_v_mod_map_key_bytes = input.first_v_mod_map_key.serialize(); |
| 13232 | let n_v_mod_map_keys_bytes = input.n_v_mod_map_keys.serialize(); |
| 13233 | let virtual_mods_bytes = u16::from(input.virtual_mods).serialize(); |
| 13234 | [ |
| 13235 | response_type_bytes[0], |
| 13236 | xkb_type_bytes[0], |
| 13237 | sequence_bytes[0], |
| 13238 | sequence_bytes[1], |
| 13239 | time_bytes[0], |
| 13240 | time_bytes[1], |
| 13241 | time_bytes[2], |
| 13242 | time_bytes[3], |
| 13243 | device_id_bytes[0], |
| 13244 | ptr_btn_actions_bytes[0], |
| 13245 | changed_bytes[0], |
| 13246 | changed_bytes[1], |
| 13247 | min_key_code_bytes[0], |
| 13248 | max_key_code_bytes[0], |
| 13249 | first_type_bytes[0], |
| 13250 | n_types_bytes[0], |
| 13251 | first_key_sym_bytes[0], |
| 13252 | n_key_syms_bytes[0], |
| 13253 | first_key_act_bytes[0], |
| 13254 | n_key_acts_bytes[0], |
| 13255 | first_key_behavior_bytes[0], |
| 13256 | n_key_behavior_bytes[0], |
| 13257 | first_key_explicit_bytes[0], |
| 13258 | n_key_explicit_bytes[0], |
| 13259 | first_mod_map_key_bytes[0], |
| 13260 | n_mod_map_keys_bytes[0], |
| 13261 | first_v_mod_map_key_bytes[0], |
| 13262 | n_v_mod_map_keys_bytes[0], |
| 13263 | virtual_mods_bytes[0], |
| 13264 | virtual_mods_bytes[1], |
| 13265 | 0, |
| 13266 | 0, |
| 13267 | ] |
| 13268 | } |
| 13269 | } |
| 13270 | impl From<MapNotifyEvent> for [u8; 32] { |
| 13271 | fn from(input: MapNotifyEvent) -> Self { |
| 13272 | Self::from(&input) |
| 13273 | } |
| 13274 | } |
| 13275 | |
| 13276 | /// Opcode for the StateNotify event |
| 13277 | pub const STATE_NOTIFY_EVENT: u8 = 2; |
| 13278 | #[derive (Clone, Copy, Default)] |
| 13279 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 13280 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 13281 | pub struct StateNotifyEvent { |
| 13282 | pub response_type: u8, |
| 13283 | pub xkb_type: u8, |
| 13284 | pub sequence: u16, |
| 13285 | pub time: xproto::Timestamp, |
| 13286 | pub device_id: u8, |
| 13287 | pub mods: xproto::ModMask, |
| 13288 | pub base_mods: xproto::ModMask, |
| 13289 | pub latched_mods: xproto::ModMask, |
| 13290 | pub locked_mods: xproto::ModMask, |
| 13291 | pub group: Group, |
| 13292 | pub base_group: i16, |
| 13293 | pub latched_group: i16, |
| 13294 | pub locked_group: Group, |
| 13295 | pub compat_state: xproto::ModMask, |
| 13296 | pub grab_mods: xproto::ModMask, |
| 13297 | pub compat_grab_mods: xproto::ModMask, |
| 13298 | pub lookup_mods: xproto::ModMask, |
| 13299 | pub compat_loockup_mods: xproto::ModMask, |
| 13300 | pub ptr_btn_state: xproto::KeyButMask, |
| 13301 | pub changed: StatePart, |
| 13302 | pub keycode: xproto::Keycode, |
| 13303 | pub event_type: u8, |
| 13304 | pub request_major: u8, |
| 13305 | pub request_minor: u8, |
| 13306 | } |
| 13307 | impl_debug_if_no_extra_traits!(StateNotifyEvent, "StateNotifyEvent" ); |
| 13308 | impl TryParse for StateNotifyEvent { |
| 13309 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 13310 | let remaining = initial_value; |
| 13311 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 13312 | let (xkb_type, remaining) = u8::try_parse(remaining)?; |
| 13313 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 13314 | let (time, remaining) = xproto::Timestamp::try_parse(remaining)?; |
| 13315 | let (device_id, remaining) = u8::try_parse(remaining)?; |
| 13316 | let (mods, remaining) = u8::try_parse(remaining)?; |
| 13317 | let (base_mods, remaining) = u8::try_parse(remaining)?; |
| 13318 | let (latched_mods, remaining) = u8::try_parse(remaining)?; |
| 13319 | let (locked_mods, remaining) = u8::try_parse(remaining)?; |
| 13320 | let (group, remaining) = u8::try_parse(remaining)?; |
| 13321 | let (base_group, remaining) = i16::try_parse(remaining)?; |
| 13322 | let (latched_group, remaining) = i16::try_parse(remaining)?; |
| 13323 | let (locked_group, remaining) = u8::try_parse(remaining)?; |
| 13324 | let (compat_state, remaining) = u8::try_parse(remaining)?; |
| 13325 | let (grab_mods, remaining) = u8::try_parse(remaining)?; |
| 13326 | let (compat_grab_mods, remaining) = u8::try_parse(remaining)?; |
| 13327 | let (lookup_mods, remaining) = u8::try_parse(remaining)?; |
| 13328 | let (compat_loockup_mods, remaining) = u8::try_parse(remaining)?; |
| 13329 | let (ptr_btn_state, remaining) = u16::try_parse(remaining)?; |
| 13330 | let (changed, remaining) = u16::try_parse(remaining)?; |
| 13331 | let (keycode, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 13332 | let (event_type, remaining) = u8::try_parse(remaining)?; |
| 13333 | let (request_major, remaining) = u8::try_parse(remaining)?; |
| 13334 | let (request_minor, remaining) = u8::try_parse(remaining)?; |
| 13335 | let mods = mods.into(); |
| 13336 | let base_mods = base_mods.into(); |
| 13337 | let latched_mods = latched_mods.into(); |
| 13338 | let locked_mods = locked_mods.into(); |
| 13339 | let group = group.into(); |
| 13340 | let locked_group = locked_group.into(); |
| 13341 | let compat_state = compat_state.into(); |
| 13342 | let grab_mods = grab_mods.into(); |
| 13343 | let compat_grab_mods = compat_grab_mods.into(); |
| 13344 | let lookup_mods = lookup_mods.into(); |
| 13345 | let compat_loockup_mods = compat_loockup_mods.into(); |
| 13346 | let ptr_btn_state = ptr_btn_state.into(); |
| 13347 | let changed = changed.into(); |
| 13348 | 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 }; |
| 13349 | let _ = remaining; |
| 13350 | let remaining = initial_value.get(32..) |
| 13351 | .ok_or(ParseError::InsufficientData)?; |
| 13352 | Ok((result, remaining)) |
| 13353 | } |
| 13354 | } |
| 13355 | impl Serialize for StateNotifyEvent { |
| 13356 | type Bytes = [u8; 32]; |
| 13357 | fn serialize(&self) -> [u8; 32] { |
| 13358 | let response_type_bytes = self.response_type.serialize(); |
| 13359 | let xkb_type_bytes = self.xkb_type.serialize(); |
| 13360 | let sequence_bytes = self.sequence.serialize(); |
| 13361 | let time_bytes = self.time.serialize(); |
| 13362 | let device_id_bytes = self.device_id.serialize(); |
| 13363 | let mods_bytes = (u16::from(self.mods) as u8).serialize(); |
| 13364 | let base_mods_bytes = (u16::from(self.base_mods) as u8).serialize(); |
| 13365 | let latched_mods_bytes = (u16::from(self.latched_mods) as u8).serialize(); |
| 13366 | let locked_mods_bytes = (u16::from(self.locked_mods) as u8).serialize(); |
| 13367 | let group_bytes = u8::from(self.group).serialize(); |
| 13368 | let base_group_bytes = self.base_group.serialize(); |
| 13369 | let latched_group_bytes = self.latched_group.serialize(); |
| 13370 | let locked_group_bytes = u8::from(self.locked_group).serialize(); |
| 13371 | let compat_state_bytes = (u16::from(self.compat_state) as u8).serialize(); |
| 13372 | let grab_mods_bytes = (u16::from(self.grab_mods) as u8).serialize(); |
| 13373 | let compat_grab_mods_bytes = (u16::from(self.compat_grab_mods) as u8).serialize(); |
| 13374 | let lookup_mods_bytes = (u16::from(self.lookup_mods) as u8).serialize(); |
| 13375 | let compat_loockup_mods_bytes = (u16::from(self.compat_loockup_mods) as u8).serialize(); |
| 13376 | let ptr_btn_state_bytes = u16::from(self.ptr_btn_state).serialize(); |
| 13377 | let changed_bytes = u16::from(self.changed).serialize(); |
| 13378 | let keycode_bytes = self.keycode.serialize(); |
| 13379 | let event_type_bytes = self.event_type.serialize(); |
| 13380 | let request_major_bytes = self.request_major.serialize(); |
| 13381 | let request_minor_bytes = self.request_minor.serialize(); |
| 13382 | [ |
| 13383 | response_type_bytes[0], |
| 13384 | xkb_type_bytes[0], |
| 13385 | sequence_bytes[0], |
| 13386 | sequence_bytes[1], |
| 13387 | time_bytes[0], |
| 13388 | time_bytes[1], |
| 13389 | time_bytes[2], |
| 13390 | time_bytes[3], |
| 13391 | device_id_bytes[0], |
| 13392 | mods_bytes[0], |
| 13393 | base_mods_bytes[0], |
| 13394 | latched_mods_bytes[0], |
| 13395 | locked_mods_bytes[0], |
| 13396 | group_bytes[0], |
| 13397 | base_group_bytes[0], |
| 13398 | base_group_bytes[1], |
| 13399 | latched_group_bytes[0], |
| 13400 | latched_group_bytes[1], |
| 13401 | locked_group_bytes[0], |
| 13402 | compat_state_bytes[0], |
| 13403 | grab_mods_bytes[0], |
| 13404 | compat_grab_mods_bytes[0], |
| 13405 | lookup_mods_bytes[0], |
| 13406 | compat_loockup_mods_bytes[0], |
| 13407 | ptr_btn_state_bytes[0], |
| 13408 | ptr_btn_state_bytes[1], |
| 13409 | changed_bytes[0], |
| 13410 | changed_bytes[1], |
| 13411 | keycode_bytes[0], |
| 13412 | event_type_bytes[0], |
| 13413 | request_major_bytes[0], |
| 13414 | request_minor_bytes[0], |
| 13415 | ] |
| 13416 | } |
| 13417 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 13418 | bytes.reserve(32); |
| 13419 | self.response_type.serialize_into(bytes); |
| 13420 | self.xkb_type.serialize_into(bytes); |
| 13421 | self.sequence.serialize_into(bytes); |
| 13422 | self.time.serialize_into(bytes); |
| 13423 | self.device_id.serialize_into(bytes); |
| 13424 | (u16::from(self.mods) as u8).serialize_into(bytes); |
| 13425 | (u16::from(self.base_mods) as u8).serialize_into(bytes); |
| 13426 | (u16::from(self.latched_mods) as u8).serialize_into(bytes); |
| 13427 | (u16::from(self.locked_mods) as u8).serialize_into(bytes); |
| 13428 | u8::from(self.group).serialize_into(bytes); |
| 13429 | self.base_group.serialize_into(bytes); |
| 13430 | self.latched_group.serialize_into(bytes); |
| 13431 | u8::from(self.locked_group).serialize_into(bytes); |
| 13432 | (u16::from(self.compat_state) as u8).serialize_into(bytes); |
| 13433 | (u16::from(self.grab_mods) as u8).serialize_into(bytes); |
| 13434 | (u16::from(self.compat_grab_mods) as u8).serialize_into(bytes); |
| 13435 | (u16::from(self.lookup_mods) as u8).serialize_into(bytes); |
| 13436 | (u16::from(self.compat_loockup_mods) as u8).serialize_into(bytes); |
| 13437 | u16::from(self.ptr_btn_state).serialize_into(bytes); |
| 13438 | u16::from(self.changed).serialize_into(bytes); |
| 13439 | self.keycode.serialize_into(bytes); |
| 13440 | self.event_type.serialize_into(bytes); |
| 13441 | self.request_major.serialize_into(bytes); |
| 13442 | self.request_minor.serialize_into(bytes); |
| 13443 | } |
| 13444 | } |
| 13445 | impl From<&StateNotifyEvent> for [u8; 32] { |
| 13446 | fn from(input: &StateNotifyEvent) -> Self { |
| 13447 | let response_type_bytes = input.response_type.serialize(); |
| 13448 | let xkb_type_bytes = input.xkb_type.serialize(); |
| 13449 | let sequence_bytes = input.sequence.serialize(); |
| 13450 | let time_bytes = input.time.serialize(); |
| 13451 | let device_id_bytes = input.device_id.serialize(); |
| 13452 | let mods_bytes = (u16::from(input.mods) as u8).serialize(); |
| 13453 | let base_mods_bytes = (u16::from(input.base_mods) as u8).serialize(); |
| 13454 | let latched_mods_bytes = (u16::from(input.latched_mods) as u8).serialize(); |
| 13455 | let locked_mods_bytes = (u16::from(input.locked_mods) as u8).serialize(); |
| 13456 | let group_bytes = u8::from(input.group).serialize(); |
| 13457 | let base_group_bytes = input.base_group.serialize(); |
| 13458 | let latched_group_bytes = input.latched_group.serialize(); |
| 13459 | let locked_group_bytes = u8::from(input.locked_group).serialize(); |
| 13460 | let compat_state_bytes = (u16::from(input.compat_state) as u8).serialize(); |
| 13461 | let grab_mods_bytes = (u16::from(input.grab_mods) as u8).serialize(); |
| 13462 | let compat_grab_mods_bytes = (u16::from(input.compat_grab_mods) as u8).serialize(); |
| 13463 | let lookup_mods_bytes = (u16::from(input.lookup_mods) as u8).serialize(); |
| 13464 | let compat_loockup_mods_bytes = (u16::from(input.compat_loockup_mods) as u8).serialize(); |
| 13465 | let ptr_btn_state_bytes = u16::from(input.ptr_btn_state).serialize(); |
| 13466 | let changed_bytes = u16::from(input.changed).serialize(); |
| 13467 | let keycode_bytes = input.keycode.serialize(); |
| 13468 | let event_type_bytes = input.event_type.serialize(); |
| 13469 | let request_major_bytes = input.request_major.serialize(); |
| 13470 | let request_minor_bytes = input.request_minor.serialize(); |
| 13471 | [ |
| 13472 | response_type_bytes[0], |
| 13473 | xkb_type_bytes[0], |
| 13474 | sequence_bytes[0], |
| 13475 | sequence_bytes[1], |
| 13476 | time_bytes[0], |
| 13477 | time_bytes[1], |
| 13478 | time_bytes[2], |
| 13479 | time_bytes[3], |
| 13480 | device_id_bytes[0], |
| 13481 | mods_bytes[0], |
| 13482 | base_mods_bytes[0], |
| 13483 | latched_mods_bytes[0], |
| 13484 | locked_mods_bytes[0], |
| 13485 | group_bytes[0], |
| 13486 | base_group_bytes[0], |
| 13487 | base_group_bytes[1], |
| 13488 | latched_group_bytes[0], |
| 13489 | latched_group_bytes[1], |
| 13490 | locked_group_bytes[0], |
| 13491 | compat_state_bytes[0], |
| 13492 | grab_mods_bytes[0], |
| 13493 | compat_grab_mods_bytes[0], |
| 13494 | lookup_mods_bytes[0], |
| 13495 | compat_loockup_mods_bytes[0], |
| 13496 | ptr_btn_state_bytes[0], |
| 13497 | ptr_btn_state_bytes[1], |
| 13498 | changed_bytes[0], |
| 13499 | changed_bytes[1], |
| 13500 | keycode_bytes[0], |
| 13501 | event_type_bytes[0], |
| 13502 | request_major_bytes[0], |
| 13503 | request_minor_bytes[0], |
| 13504 | ] |
| 13505 | } |
| 13506 | } |
| 13507 | impl From<StateNotifyEvent> for [u8; 32] { |
| 13508 | fn from(input: StateNotifyEvent) -> Self { |
| 13509 | Self::from(&input) |
| 13510 | } |
| 13511 | } |
| 13512 | |
| 13513 | /// Opcode for the ControlsNotify event |
| 13514 | pub const CONTROLS_NOTIFY_EVENT: u8 = 3; |
| 13515 | #[derive (Clone, Copy, Default)] |
| 13516 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 13517 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 13518 | pub struct ControlsNotifyEvent { |
| 13519 | pub response_type: u8, |
| 13520 | pub xkb_type: u8, |
| 13521 | pub sequence: u16, |
| 13522 | pub time: xproto::Timestamp, |
| 13523 | pub device_id: u8, |
| 13524 | pub num_groups: u8, |
| 13525 | pub changed_controls: Control, |
| 13526 | pub enabled_controls: BoolCtrl, |
| 13527 | pub enabled_control_changes: BoolCtrl, |
| 13528 | pub keycode: xproto::Keycode, |
| 13529 | pub event_type: u8, |
| 13530 | pub request_major: u8, |
| 13531 | pub request_minor: u8, |
| 13532 | } |
| 13533 | impl_debug_if_no_extra_traits!(ControlsNotifyEvent, "ControlsNotifyEvent" ); |
| 13534 | impl TryParse for ControlsNotifyEvent { |
| 13535 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 13536 | let remaining = initial_value; |
| 13537 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 13538 | let (xkb_type, remaining) = u8::try_parse(remaining)?; |
| 13539 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 13540 | let (time, remaining) = xproto::Timestamp::try_parse(remaining)?; |
| 13541 | let (device_id, remaining) = u8::try_parse(remaining)?; |
| 13542 | let (num_groups, remaining) = u8::try_parse(remaining)?; |
| 13543 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 13544 | let (changed_controls, remaining) = u32::try_parse(remaining)?; |
| 13545 | let (enabled_controls, remaining) = u32::try_parse(remaining)?; |
| 13546 | let (enabled_control_changes, remaining) = u32::try_parse(remaining)?; |
| 13547 | let (keycode, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 13548 | let (event_type, remaining) = u8::try_parse(remaining)?; |
| 13549 | let (request_major, remaining) = u8::try_parse(remaining)?; |
| 13550 | let (request_minor, remaining) = u8::try_parse(remaining)?; |
| 13551 | let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; |
| 13552 | let changed_controls = changed_controls.into(); |
| 13553 | let enabled_controls = enabled_controls.into(); |
| 13554 | let enabled_control_changes = enabled_control_changes.into(); |
| 13555 | 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 }; |
| 13556 | let _ = remaining; |
| 13557 | let remaining = initial_value.get(32..) |
| 13558 | .ok_or(ParseError::InsufficientData)?; |
| 13559 | Ok((result, remaining)) |
| 13560 | } |
| 13561 | } |
| 13562 | impl Serialize for ControlsNotifyEvent { |
| 13563 | type Bytes = [u8; 32]; |
| 13564 | fn serialize(&self) -> [u8; 32] { |
| 13565 | let response_type_bytes = self.response_type.serialize(); |
| 13566 | let xkb_type_bytes = self.xkb_type.serialize(); |
| 13567 | let sequence_bytes = self.sequence.serialize(); |
| 13568 | let time_bytes = self.time.serialize(); |
| 13569 | let device_id_bytes = self.device_id.serialize(); |
| 13570 | let num_groups_bytes = self.num_groups.serialize(); |
| 13571 | let changed_controls_bytes = u32::from(self.changed_controls).serialize(); |
| 13572 | let enabled_controls_bytes = u32::from(self.enabled_controls).serialize(); |
| 13573 | let enabled_control_changes_bytes = u32::from(self.enabled_control_changes).serialize(); |
| 13574 | let keycode_bytes = self.keycode.serialize(); |
| 13575 | let event_type_bytes = self.event_type.serialize(); |
| 13576 | let request_major_bytes = self.request_major.serialize(); |
| 13577 | let request_minor_bytes = self.request_minor.serialize(); |
| 13578 | [ |
| 13579 | response_type_bytes[0], |
| 13580 | xkb_type_bytes[0], |
| 13581 | sequence_bytes[0], |
| 13582 | sequence_bytes[1], |
| 13583 | time_bytes[0], |
| 13584 | time_bytes[1], |
| 13585 | time_bytes[2], |
| 13586 | time_bytes[3], |
| 13587 | device_id_bytes[0], |
| 13588 | num_groups_bytes[0], |
| 13589 | 0, |
| 13590 | 0, |
| 13591 | changed_controls_bytes[0], |
| 13592 | changed_controls_bytes[1], |
| 13593 | changed_controls_bytes[2], |
| 13594 | changed_controls_bytes[3], |
| 13595 | enabled_controls_bytes[0], |
| 13596 | enabled_controls_bytes[1], |
| 13597 | enabled_controls_bytes[2], |
| 13598 | enabled_controls_bytes[3], |
| 13599 | enabled_control_changes_bytes[0], |
| 13600 | enabled_control_changes_bytes[1], |
| 13601 | enabled_control_changes_bytes[2], |
| 13602 | enabled_control_changes_bytes[3], |
| 13603 | keycode_bytes[0], |
| 13604 | event_type_bytes[0], |
| 13605 | request_major_bytes[0], |
| 13606 | request_minor_bytes[0], |
| 13607 | 0, |
| 13608 | 0, |
| 13609 | 0, |
| 13610 | 0, |
| 13611 | ] |
| 13612 | } |
| 13613 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 13614 | bytes.reserve(32); |
| 13615 | self.response_type.serialize_into(bytes); |
| 13616 | self.xkb_type.serialize_into(bytes); |
| 13617 | self.sequence.serialize_into(bytes); |
| 13618 | self.time.serialize_into(bytes); |
| 13619 | self.device_id.serialize_into(bytes); |
| 13620 | self.num_groups.serialize_into(bytes); |
| 13621 | bytes.extend_from_slice(&[0; 2]); |
| 13622 | u32::from(self.changed_controls).serialize_into(bytes); |
| 13623 | u32::from(self.enabled_controls).serialize_into(bytes); |
| 13624 | u32::from(self.enabled_control_changes).serialize_into(bytes); |
| 13625 | self.keycode.serialize_into(bytes); |
| 13626 | self.event_type.serialize_into(bytes); |
| 13627 | self.request_major.serialize_into(bytes); |
| 13628 | self.request_minor.serialize_into(bytes); |
| 13629 | bytes.extend_from_slice(&[0; 4]); |
| 13630 | } |
| 13631 | } |
| 13632 | impl From<&ControlsNotifyEvent> for [u8; 32] { |
| 13633 | fn from(input: &ControlsNotifyEvent) -> Self { |
| 13634 | let response_type_bytes = input.response_type.serialize(); |
| 13635 | let xkb_type_bytes = input.xkb_type.serialize(); |
| 13636 | let sequence_bytes = input.sequence.serialize(); |
| 13637 | let time_bytes = input.time.serialize(); |
| 13638 | let device_id_bytes = input.device_id.serialize(); |
| 13639 | let num_groups_bytes = input.num_groups.serialize(); |
| 13640 | let changed_controls_bytes = u32::from(input.changed_controls).serialize(); |
| 13641 | let enabled_controls_bytes = u32::from(input.enabled_controls).serialize(); |
| 13642 | let enabled_control_changes_bytes = u32::from(input.enabled_control_changes).serialize(); |
| 13643 | let keycode_bytes = input.keycode.serialize(); |
| 13644 | let event_type_bytes = input.event_type.serialize(); |
| 13645 | let request_major_bytes = input.request_major.serialize(); |
| 13646 | let request_minor_bytes = input.request_minor.serialize(); |
| 13647 | [ |
| 13648 | response_type_bytes[0], |
| 13649 | xkb_type_bytes[0], |
| 13650 | sequence_bytes[0], |
| 13651 | sequence_bytes[1], |
| 13652 | time_bytes[0], |
| 13653 | time_bytes[1], |
| 13654 | time_bytes[2], |
| 13655 | time_bytes[3], |
| 13656 | device_id_bytes[0], |
| 13657 | num_groups_bytes[0], |
| 13658 | 0, |
| 13659 | 0, |
| 13660 | changed_controls_bytes[0], |
| 13661 | changed_controls_bytes[1], |
| 13662 | changed_controls_bytes[2], |
| 13663 | changed_controls_bytes[3], |
| 13664 | enabled_controls_bytes[0], |
| 13665 | enabled_controls_bytes[1], |
| 13666 | enabled_controls_bytes[2], |
| 13667 | enabled_controls_bytes[3], |
| 13668 | enabled_control_changes_bytes[0], |
| 13669 | enabled_control_changes_bytes[1], |
| 13670 | enabled_control_changes_bytes[2], |
| 13671 | enabled_control_changes_bytes[3], |
| 13672 | keycode_bytes[0], |
| 13673 | event_type_bytes[0], |
| 13674 | request_major_bytes[0], |
| 13675 | request_minor_bytes[0], |
| 13676 | 0, |
| 13677 | 0, |
| 13678 | 0, |
| 13679 | 0, |
| 13680 | ] |
| 13681 | } |
| 13682 | } |
| 13683 | impl From<ControlsNotifyEvent> for [u8; 32] { |
| 13684 | fn from(input: ControlsNotifyEvent) -> Self { |
| 13685 | Self::from(&input) |
| 13686 | } |
| 13687 | } |
| 13688 | |
| 13689 | /// Opcode for the IndicatorStateNotify event |
| 13690 | pub const INDICATOR_STATE_NOTIFY_EVENT: u8 = 4; |
| 13691 | #[derive (Clone, Copy, Default)] |
| 13692 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 13693 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 13694 | pub struct IndicatorStateNotifyEvent { |
| 13695 | pub response_type: u8, |
| 13696 | pub xkb_type: u8, |
| 13697 | pub sequence: u16, |
| 13698 | pub time: xproto::Timestamp, |
| 13699 | pub device_id: u8, |
| 13700 | pub state: u32, |
| 13701 | pub state_changed: u32, |
| 13702 | } |
| 13703 | impl_debug_if_no_extra_traits!(IndicatorStateNotifyEvent, "IndicatorStateNotifyEvent" ); |
| 13704 | impl TryParse for IndicatorStateNotifyEvent { |
| 13705 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 13706 | let remaining: &[u8] = initial_value; |
| 13707 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 13708 | let (xkb_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 13709 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 13710 | let (time: u32, remaining: &[u8]) = xproto::Timestamp::try_parse(remaining)?; |
| 13711 | let (device_id: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 13712 | let remaining: &[u8] = remaining.get(3..).ok_or(err:ParseError::InsufficientData)?; |
| 13713 | let (state: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 13714 | let (state_changed: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 13715 | let remaining: &[u8] = remaining.get(12..).ok_or(err:ParseError::InsufficientData)?; |
| 13716 | let result: IndicatorStateNotifyEvent = IndicatorStateNotifyEvent { response_type, xkb_type, sequence, time, device_id, state, state_changed }; |
| 13717 | let _ = remaining; |
| 13718 | let remaining: &[u8] = initial_value.get(32..) |
| 13719 | .ok_or(err:ParseError::InsufficientData)?; |
| 13720 | Ok((result, remaining)) |
| 13721 | } |
| 13722 | } |
| 13723 | impl Serialize for IndicatorStateNotifyEvent { |
| 13724 | type Bytes = [u8; 32]; |
| 13725 | fn serialize(&self) -> [u8; 32] { |
| 13726 | let response_type_bytes = self.response_type.serialize(); |
| 13727 | let xkb_type_bytes = self.xkb_type.serialize(); |
| 13728 | let sequence_bytes = self.sequence.serialize(); |
| 13729 | let time_bytes = self.time.serialize(); |
| 13730 | let device_id_bytes = self.device_id.serialize(); |
| 13731 | let state_bytes = self.state.serialize(); |
| 13732 | let state_changed_bytes = self.state_changed.serialize(); |
| 13733 | [ |
| 13734 | response_type_bytes[0], |
| 13735 | xkb_type_bytes[0], |
| 13736 | sequence_bytes[0], |
| 13737 | sequence_bytes[1], |
| 13738 | time_bytes[0], |
| 13739 | time_bytes[1], |
| 13740 | time_bytes[2], |
| 13741 | time_bytes[3], |
| 13742 | device_id_bytes[0], |
| 13743 | 0, |
| 13744 | 0, |
| 13745 | 0, |
| 13746 | state_bytes[0], |
| 13747 | state_bytes[1], |
| 13748 | state_bytes[2], |
| 13749 | state_bytes[3], |
| 13750 | state_changed_bytes[0], |
| 13751 | state_changed_bytes[1], |
| 13752 | state_changed_bytes[2], |
| 13753 | state_changed_bytes[3], |
| 13754 | 0, |
| 13755 | 0, |
| 13756 | 0, |
| 13757 | 0, |
| 13758 | 0, |
| 13759 | 0, |
| 13760 | 0, |
| 13761 | 0, |
| 13762 | 0, |
| 13763 | 0, |
| 13764 | 0, |
| 13765 | 0, |
| 13766 | ] |
| 13767 | } |
| 13768 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 13769 | bytes.reserve(32); |
| 13770 | self.response_type.serialize_into(bytes); |
| 13771 | self.xkb_type.serialize_into(bytes); |
| 13772 | self.sequence.serialize_into(bytes); |
| 13773 | self.time.serialize_into(bytes); |
| 13774 | self.device_id.serialize_into(bytes); |
| 13775 | bytes.extend_from_slice(&[0; 3]); |
| 13776 | self.state.serialize_into(bytes); |
| 13777 | self.state_changed.serialize_into(bytes); |
| 13778 | bytes.extend_from_slice(&[0; 12]); |
| 13779 | } |
| 13780 | } |
| 13781 | impl From<&IndicatorStateNotifyEvent> for [u8; 32] { |
| 13782 | fn from(input: &IndicatorStateNotifyEvent) -> Self { |
| 13783 | let response_type_bytes = input.response_type.serialize(); |
| 13784 | let xkb_type_bytes = input.xkb_type.serialize(); |
| 13785 | let sequence_bytes = input.sequence.serialize(); |
| 13786 | let time_bytes = input.time.serialize(); |
| 13787 | let device_id_bytes = input.device_id.serialize(); |
| 13788 | let state_bytes = input.state.serialize(); |
| 13789 | let state_changed_bytes = input.state_changed.serialize(); |
| 13790 | [ |
| 13791 | response_type_bytes[0], |
| 13792 | xkb_type_bytes[0], |
| 13793 | sequence_bytes[0], |
| 13794 | sequence_bytes[1], |
| 13795 | time_bytes[0], |
| 13796 | time_bytes[1], |
| 13797 | time_bytes[2], |
| 13798 | time_bytes[3], |
| 13799 | device_id_bytes[0], |
| 13800 | 0, |
| 13801 | 0, |
| 13802 | 0, |
| 13803 | state_bytes[0], |
| 13804 | state_bytes[1], |
| 13805 | state_bytes[2], |
| 13806 | state_bytes[3], |
| 13807 | state_changed_bytes[0], |
| 13808 | state_changed_bytes[1], |
| 13809 | state_changed_bytes[2], |
| 13810 | state_changed_bytes[3], |
| 13811 | 0, |
| 13812 | 0, |
| 13813 | 0, |
| 13814 | 0, |
| 13815 | 0, |
| 13816 | 0, |
| 13817 | 0, |
| 13818 | 0, |
| 13819 | 0, |
| 13820 | 0, |
| 13821 | 0, |
| 13822 | 0, |
| 13823 | ] |
| 13824 | } |
| 13825 | } |
| 13826 | impl From<IndicatorStateNotifyEvent> for [u8; 32] { |
| 13827 | fn from(input: IndicatorStateNotifyEvent) -> Self { |
| 13828 | Self::from(&input) |
| 13829 | } |
| 13830 | } |
| 13831 | |
| 13832 | /// Opcode for the IndicatorMapNotify event |
| 13833 | pub const INDICATOR_MAP_NOTIFY_EVENT: u8 = 5; |
| 13834 | #[derive (Clone, Copy, Default)] |
| 13835 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 13836 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 13837 | pub struct IndicatorMapNotifyEvent { |
| 13838 | pub response_type: u8, |
| 13839 | pub xkb_type: u8, |
| 13840 | pub sequence: u16, |
| 13841 | pub time: xproto::Timestamp, |
| 13842 | pub device_id: u8, |
| 13843 | pub state: u32, |
| 13844 | pub map_changed: u32, |
| 13845 | } |
| 13846 | impl_debug_if_no_extra_traits!(IndicatorMapNotifyEvent, "IndicatorMapNotifyEvent" ); |
| 13847 | impl TryParse for IndicatorMapNotifyEvent { |
| 13848 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 13849 | let remaining: &[u8] = initial_value; |
| 13850 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 13851 | let (xkb_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 13852 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 13853 | let (time: u32, remaining: &[u8]) = xproto::Timestamp::try_parse(remaining)?; |
| 13854 | let (device_id: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 13855 | let remaining: &[u8] = remaining.get(3..).ok_or(err:ParseError::InsufficientData)?; |
| 13856 | let (state: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 13857 | let (map_changed: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
| 13858 | let remaining: &[u8] = remaining.get(12..).ok_or(err:ParseError::InsufficientData)?; |
| 13859 | let result: IndicatorMapNotifyEvent = IndicatorMapNotifyEvent { response_type, xkb_type, sequence, time, device_id, state, map_changed }; |
| 13860 | let _ = remaining; |
| 13861 | let remaining: &[u8] = initial_value.get(32..) |
| 13862 | .ok_or(err:ParseError::InsufficientData)?; |
| 13863 | Ok((result, remaining)) |
| 13864 | } |
| 13865 | } |
| 13866 | impl Serialize for IndicatorMapNotifyEvent { |
| 13867 | type Bytes = [u8; 32]; |
| 13868 | fn serialize(&self) -> [u8; 32] { |
| 13869 | let response_type_bytes = self.response_type.serialize(); |
| 13870 | let xkb_type_bytes = self.xkb_type.serialize(); |
| 13871 | let sequence_bytes = self.sequence.serialize(); |
| 13872 | let time_bytes = self.time.serialize(); |
| 13873 | let device_id_bytes = self.device_id.serialize(); |
| 13874 | let state_bytes = self.state.serialize(); |
| 13875 | let map_changed_bytes = self.map_changed.serialize(); |
| 13876 | [ |
| 13877 | response_type_bytes[0], |
| 13878 | xkb_type_bytes[0], |
| 13879 | sequence_bytes[0], |
| 13880 | sequence_bytes[1], |
| 13881 | time_bytes[0], |
| 13882 | time_bytes[1], |
| 13883 | time_bytes[2], |
| 13884 | time_bytes[3], |
| 13885 | device_id_bytes[0], |
| 13886 | 0, |
| 13887 | 0, |
| 13888 | 0, |
| 13889 | state_bytes[0], |
| 13890 | state_bytes[1], |
| 13891 | state_bytes[2], |
| 13892 | state_bytes[3], |
| 13893 | map_changed_bytes[0], |
| 13894 | map_changed_bytes[1], |
| 13895 | map_changed_bytes[2], |
| 13896 | map_changed_bytes[3], |
| 13897 | 0, |
| 13898 | 0, |
| 13899 | 0, |
| 13900 | 0, |
| 13901 | 0, |
| 13902 | 0, |
| 13903 | 0, |
| 13904 | 0, |
| 13905 | 0, |
| 13906 | 0, |
| 13907 | 0, |
| 13908 | 0, |
| 13909 | ] |
| 13910 | } |
| 13911 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 13912 | bytes.reserve(32); |
| 13913 | self.response_type.serialize_into(bytes); |
| 13914 | self.xkb_type.serialize_into(bytes); |
| 13915 | self.sequence.serialize_into(bytes); |
| 13916 | self.time.serialize_into(bytes); |
| 13917 | self.device_id.serialize_into(bytes); |
| 13918 | bytes.extend_from_slice(&[0; 3]); |
| 13919 | self.state.serialize_into(bytes); |
| 13920 | self.map_changed.serialize_into(bytes); |
| 13921 | bytes.extend_from_slice(&[0; 12]); |
| 13922 | } |
| 13923 | } |
| 13924 | impl From<&IndicatorMapNotifyEvent> for [u8; 32] { |
| 13925 | fn from(input: &IndicatorMapNotifyEvent) -> Self { |
| 13926 | let response_type_bytes = input.response_type.serialize(); |
| 13927 | let xkb_type_bytes = input.xkb_type.serialize(); |
| 13928 | let sequence_bytes = input.sequence.serialize(); |
| 13929 | let time_bytes = input.time.serialize(); |
| 13930 | let device_id_bytes = input.device_id.serialize(); |
| 13931 | let state_bytes = input.state.serialize(); |
| 13932 | let map_changed_bytes = input.map_changed.serialize(); |
| 13933 | [ |
| 13934 | response_type_bytes[0], |
| 13935 | xkb_type_bytes[0], |
| 13936 | sequence_bytes[0], |
| 13937 | sequence_bytes[1], |
| 13938 | time_bytes[0], |
| 13939 | time_bytes[1], |
| 13940 | time_bytes[2], |
| 13941 | time_bytes[3], |
| 13942 | device_id_bytes[0], |
| 13943 | 0, |
| 13944 | 0, |
| 13945 | 0, |
| 13946 | state_bytes[0], |
| 13947 | state_bytes[1], |
| 13948 | state_bytes[2], |
| 13949 | state_bytes[3], |
| 13950 | map_changed_bytes[0], |
| 13951 | map_changed_bytes[1], |
| 13952 | map_changed_bytes[2], |
| 13953 | map_changed_bytes[3], |
| 13954 | 0, |
| 13955 | 0, |
| 13956 | 0, |
| 13957 | 0, |
| 13958 | 0, |
| 13959 | 0, |
| 13960 | 0, |
| 13961 | 0, |
| 13962 | 0, |
| 13963 | 0, |
| 13964 | 0, |
| 13965 | 0, |
| 13966 | ] |
| 13967 | } |
| 13968 | } |
| 13969 | impl From<IndicatorMapNotifyEvent> for [u8; 32] { |
| 13970 | fn from(input: IndicatorMapNotifyEvent) -> Self { |
| 13971 | Self::from(&input) |
| 13972 | } |
| 13973 | } |
| 13974 | |
| 13975 | /// Opcode for the NamesNotify event |
| 13976 | pub const NAMES_NOTIFY_EVENT: u8 = 6; |
| 13977 | #[derive (Clone, Copy, Default)] |
| 13978 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 13979 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 13980 | pub struct NamesNotifyEvent { |
| 13981 | pub response_type: u8, |
| 13982 | pub xkb_type: u8, |
| 13983 | pub sequence: u16, |
| 13984 | pub time: xproto::Timestamp, |
| 13985 | pub device_id: u8, |
| 13986 | pub changed: NameDetail, |
| 13987 | pub first_type: u8, |
| 13988 | pub n_types: u8, |
| 13989 | pub first_level_name: u8, |
| 13990 | pub n_level_names: u8, |
| 13991 | pub n_radio_groups: u8, |
| 13992 | pub n_key_aliases: u8, |
| 13993 | pub changed_group_names: SetOfGroup, |
| 13994 | pub changed_virtual_mods: VMod, |
| 13995 | pub first_key: xproto::Keycode, |
| 13996 | pub n_keys: u8, |
| 13997 | pub changed_indicators: u32, |
| 13998 | } |
| 13999 | impl_debug_if_no_extra_traits!(NamesNotifyEvent, "NamesNotifyEvent" ); |
| 14000 | impl TryParse for NamesNotifyEvent { |
| 14001 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 14002 | let remaining = initial_value; |
| 14003 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 14004 | let (xkb_type, remaining) = u8::try_parse(remaining)?; |
| 14005 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 14006 | let (time, remaining) = xproto::Timestamp::try_parse(remaining)?; |
| 14007 | let (device_id, remaining) = u8::try_parse(remaining)?; |
| 14008 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 14009 | let (changed, remaining) = u16::try_parse(remaining)?; |
| 14010 | let (first_type, remaining) = u8::try_parse(remaining)?; |
| 14011 | let (n_types, remaining) = u8::try_parse(remaining)?; |
| 14012 | let (first_level_name, remaining) = u8::try_parse(remaining)?; |
| 14013 | let (n_level_names, remaining) = u8::try_parse(remaining)?; |
| 14014 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 14015 | let (n_radio_groups, remaining) = u8::try_parse(remaining)?; |
| 14016 | let (n_key_aliases, remaining) = u8::try_parse(remaining)?; |
| 14017 | let (changed_group_names, remaining) = u8::try_parse(remaining)?; |
| 14018 | let (changed_virtual_mods, remaining) = u16::try_parse(remaining)?; |
| 14019 | let (first_key, remaining) = xproto::Keycode::try_parse(remaining)?; |
| 14020 | let (n_keys, remaining) = u8::try_parse(remaining)?; |
| 14021 | let (changed_indicators, remaining) = u32::try_parse(remaining)?; |
| 14022 | let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; |
| 14023 | let changed = changed.into(); |
| 14024 | let changed_group_names = changed_group_names.into(); |
| 14025 | let changed_virtual_mods = changed_virtual_mods.into(); |
| 14026 | 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 }; |
| 14027 | let _ = remaining; |
| 14028 | let remaining = initial_value.get(32..) |
| 14029 | .ok_or(ParseError::InsufficientData)?; |
| 14030 | Ok((result, remaining)) |
| 14031 | } |
| 14032 | } |
| 14033 | impl Serialize for NamesNotifyEvent { |
| 14034 | type Bytes = [u8; 32]; |
| 14035 | fn serialize(&self) -> [u8; 32] { |
| 14036 | let response_type_bytes = self.response_type.serialize(); |
| 14037 | let xkb_type_bytes = self.xkb_type.serialize(); |
| 14038 | let sequence_bytes = self.sequence.serialize(); |
| 14039 | let time_bytes = self.time.serialize(); |
| 14040 | let device_id_bytes = self.device_id.serialize(); |
| 14041 | let changed_bytes = (u32::from(self.changed) as u16).serialize(); |
| 14042 | let first_type_bytes = self.first_type.serialize(); |
| 14043 | let n_types_bytes = self.n_types.serialize(); |
| 14044 | let first_level_name_bytes = self.first_level_name.serialize(); |
| 14045 | let n_level_names_bytes = self.n_level_names.serialize(); |
| 14046 | let n_radio_groups_bytes = self.n_radio_groups.serialize(); |
| 14047 | let n_key_aliases_bytes = self.n_key_aliases.serialize(); |
| 14048 | let changed_group_names_bytes = u8::from(self.changed_group_names).serialize(); |
| 14049 | let changed_virtual_mods_bytes = u16::from(self.changed_virtual_mods).serialize(); |
| 14050 | let first_key_bytes = self.first_key.serialize(); |
| 14051 | let n_keys_bytes = self.n_keys.serialize(); |
| 14052 | let changed_indicators_bytes = self.changed_indicators.serialize(); |
| 14053 | [ |
| 14054 | response_type_bytes[0], |
| 14055 | xkb_type_bytes[0], |
| 14056 | sequence_bytes[0], |
| 14057 | sequence_bytes[1], |
| 14058 | time_bytes[0], |
| 14059 | time_bytes[1], |
| 14060 | time_bytes[2], |
| 14061 | time_bytes[3], |
| 14062 | device_id_bytes[0], |
| 14063 | 0, |
| 14064 | changed_bytes[0], |
| 14065 | changed_bytes[1], |
| 14066 | first_type_bytes[0], |
| 14067 | n_types_bytes[0], |
| 14068 | first_level_name_bytes[0], |
| 14069 | n_level_names_bytes[0], |
| 14070 | 0, |
| 14071 | n_radio_groups_bytes[0], |
| 14072 | n_key_aliases_bytes[0], |
| 14073 | changed_group_names_bytes[0], |
| 14074 | changed_virtual_mods_bytes[0], |
| 14075 | changed_virtual_mods_bytes[1], |
| 14076 | first_key_bytes[0], |
| 14077 | n_keys_bytes[0], |
| 14078 | changed_indicators_bytes[0], |
| 14079 | changed_indicators_bytes[1], |
| 14080 | changed_indicators_bytes[2], |
| 14081 | changed_indicators_bytes[3], |
| 14082 | 0, |
| 14083 | 0, |
| 14084 | 0, |
| 14085 | 0, |
| 14086 | ] |
| 14087 | } |
| 14088 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 14089 | bytes.reserve(32); |
| 14090 | self.response_type.serialize_into(bytes); |
| 14091 | self.xkb_type.serialize_into(bytes); |
| 14092 | self.sequence.serialize_into(bytes); |
| 14093 | self.time.serialize_into(bytes); |
| 14094 | self.device_id.serialize_into(bytes); |
| 14095 | bytes.extend_from_slice(&[0; 1]); |
| 14096 | (u32::from(self.changed) as u16).serialize_into(bytes); |
| 14097 | self.first_type.serialize_into(bytes); |
| 14098 | self.n_types.serialize_into(bytes); |
| 14099 | self.first_level_name.serialize_into(bytes); |
| 14100 | self.n_level_names.serialize_into(bytes); |
| 14101 | bytes.extend_from_slice(&[0; 1]); |
| 14102 | self.n_radio_groups.serialize_into(bytes); |
| 14103 | self.n_key_aliases.serialize_into(bytes); |
| 14104 | u8::from(self.changed_group_names).serialize_into(bytes); |
| 14105 | u16::from(self.changed_virtual_mods).serialize_into(bytes); |
| 14106 | self.first_key.serialize_into(bytes); |
| 14107 | self.n_keys.serialize_into(bytes); |
| 14108 | self.changed_indicators.serialize_into(bytes); |
| 14109 | bytes.extend_from_slice(&[0; 4]); |
| 14110 | } |
| 14111 | } |
| 14112 | impl From<&NamesNotifyEvent> for [u8; 32] { |
| 14113 | fn from(input: &NamesNotifyEvent) -> Self { |
| 14114 | let response_type_bytes = input.response_type.serialize(); |
| 14115 | let xkb_type_bytes = input.xkb_type.serialize(); |
| 14116 | let sequence_bytes = input.sequence.serialize(); |
| 14117 | let time_bytes = input.time.serialize(); |
| 14118 | let device_id_bytes = input.device_id.serialize(); |
| 14119 | let changed_bytes = (u32::from(input.changed) as u16).serialize(); |
| 14120 | let first_type_bytes = input.first_type.serialize(); |
| 14121 | let n_types_bytes = input.n_types.serialize(); |
| 14122 | let first_level_name_bytes = input.first_level_name.serialize(); |
| 14123 | let n_level_names_bytes = input.n_level_names.serialize(); |
| 14124 | let n_radio_groups_bytes = input.n_radio_groups.serialize(); |
| 14125 | let n_key_aliases_bytes = input.n_key_aliases.serialize(); |
| 14126 | let changed_group_names_bytes = u8::from(input.changed_group_names).serialize(); |
| 14127 | let changed_virtual_mods_bytes = u16::from(input.changed_virtual_mods).serialize(); |
| 14128 | let first_key_bytes = input.first_key.serialize(); |
| 14129 | let n_keys_bytes = input.n_keys.serialize(); |
| 14130 | let changed_indicators_bytes = input.changed_indicators.serialize(); |
| 14131 | [ |
| 14132 | response_type_bytes[0], |
| 14133 | xkb_type_bytes[0], |
| 14134 | sequence_bytes[0], |
| 14135 | sequence_bytes[1], |
| 14136 | time_bytes[0], |
| 14137 | time_bytes[1], |
| 14138 | time_bytes[2], |
| 14139 | time_bytes[3], |
| 14140 | device_id_bytes[0], |
| 14141 | 0, |
| 14142 | changed_bytes[0], |
| 14143 | changed_bytes[1], |
| 14144 | first_type_bytes[0], |
| 14145 | n_types_bytes[0], |
| 14146 | first_level_name_bytes[0], |
| 14147 | n_level_names_bytes[0], |
| 14148 | 0, |
| 14149 | n_radio_groups_bytes[0], |
| 14150 | n_key_aliases_bytes[0], |
| 14151 | changed_group_names_bytes[0], |
| 14152 | changed_virtual_mods_bytes[0], |
| 14153 | changed_virtual_mods_bytes[1], |
| 14154 | first_key_bytes[0], |
| 14155 | n_keys_bytes[0], |
| 14156 | changed_indicators_bytes[0], |
| 14157 | changed_indicators_bytes[1], |
| 14158 | changed_indicators_bytes[2], |
| 14159 | changed_indicators_bytes[3], |
| 14160 | 0, |
| 14161 | 0, |
| 14162 | 0, |
| 14163 | 0, |
| 14164 | ] |
| 14165 | } |
| 14166 | } |
| 14167 | impl From<NamesNotifyEvent> for [u8; 32] { |
| 14168 | fn from(input: NamesNotifyEvent) -> Self { |
| 14169 | Self::from(&input) |
| 14170 | } |
| 14171 | } |
| 14172 | |
| 14173 | /// Opcode for the CompatMapNotify event |
| 14174 | pub const COMPAT_MAP_NOTIFY_EVENT: u8 = 7; |
| 14175 | #[derive (Clone, Copy, Default)] |
| 14176 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 14177 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 14178 | pub struct CompatMapNotifyEvent { |
| 14179 | pub response_type: u8, |
| 14180 | pub xkb_type: u8, |
| 14181 | pub sequence: u16, |
| 14182 | pub time: xproto::Timestamp, |
| 14183 | pub device_id: u8, |
| 14184 | pub changed_groups: SetOfGroup, |
| 14185 | pub first_si: u16, |
| 14186 | pub n_si: u16, |
| 14187 | pub n_total_si: u16, |
| 14188 | } |
| 14189 | impl_debug_if_no_extra_traits!(CompatMapNotifyEvent, "CompatMapNotifyEvent" ); |
| 14190 | impl TryParse for CompatMapNotifyEvent { |
| 14191 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 14192 | let remaining: &[u8] = initial_value; |
| 14193 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 14194 | let (xkb_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 14195 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 14196 | let (time: u32, remaining: &[u8]) = xproto::Timestamp::try_parse(remaining)?; |
| 14197 | let (device_id: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 14198 | let (changed_groups: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 14199 | let (first_si: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 14200 | let (n_si: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 14201 | let (n_total_si: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 14202 | let remaining: &[u8] = remaining.get(16..).ok_or(err:ParseError::InsufficientData)?; |
| 14203 | let changed_groups: SetOfGroup = changed_groups.into(); |
| 14204 | let result: CompatMapNotifyEvent = CompatMapNotifyEvent { response_type, xkb_type, sequence, time, device_id, changed_groups, first_si, n_si, n_total_si }; |
| 14205 | let _ = remaining; |
| 14206 | let remaining: &[u8] = initial_value.get(32..) |
| 14207 | .ok_or(err:ParseError::InsufficientData)?; |
| 14208 | Ok((result, remaining)) |
| 14209 | } |
| 14210 | } |
| 14211 | impl Serialize for CompatMapNotifyEvent { |
| 14212 | type Bytes = [u8; 32]; |
| 14213 | fn serialize(&self) -> [u8; 32] { |
| 14214 | let response_type_bytes = self.response_type.serialize(); |
| 14215 | let xkb_type_bytes = self.xkb_type.serialize(); |
| 14216 | let sequence_bytes = self.sequence.serialize(); |
| 14217 | let time_bytes = self.time.serialize(); |
| 14218 | let device_id_bytes = self.device_id.serialize(); |
| 14219 | let changed_groups_bytes = u8::from(self.changed_groups).serialize(); |
| 14220 | let first_si_bytes = self.first_si.serialize(); |
| 14221 | let n_si_bytes = self.n_si.serialize(); |
| 14222 | let n_total_si_bytes = self.n_total_si.serialize(); |
| 14223 | [ |
| 14224 | response_type_bytes[0], |
| 14225 | xkb_type_bytes[0], |
| 14226 | sequence_bytes[0], |
| 14227 | sequence_bytes[1], |
| 14228 | time_bytes[0], |
| 14229 | time_bytes[1], |
| 14230 | time_bytes[2], |
| 14231 | time_bytes[3], |
| 14232 | device_id_bytes[0], |
| 14233 | changed_groups_bytes[0], |
| 14234 | first_si_bytes[0], |
| 14235 | first_si_bytes[1], |
| 14236 | n_si_bytes[0], |
| 14237 | n_si_bytes[1], |
| 14238 | n_total_si_bytes[0], |
| 14239 | n_total_si_bytes[1], |
| 14240 | 0, |
| 14241 | 0, |
| 14242 | 0, |
| 14243 | 0, |
| 14244 | 0, |
| 14245 | 0, |
| 14246 | 0, |
| 14247 | 0, |
| 14248 | 0, |
| 14249 | 0, |
| 14250 | 0, |
| 14251 | 0, |
| 14252 | 0, |
| 14253 | 0, |
| 14254 | 0, |
| 14255 | 0, |
| 14256 | ] |
| 14257 | } |
| 14258 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 14259 | bytes.reserve(32); |
| 14260 | self.response_type.serialize_into(bytes); |
| 14261 | self.xkb_type.serialize_into(bytes); |
| 14262 | self.sequence.serialize_into(bytes); |
| 14263 | self.time.serialize_into(bytes); |
| 14264 | self.device_id.serialize_into(bytes); |
| 14265 | u8::from(self.changed_groups).serialize_into(bytes); |
| 14266 | self.first_si.serialize_into(bytes); |
| 14267 | self.n_si.serialize_into(bytes); |
| 14268 | self.n_total_si.serialize_into(bytes); |
| 14269 | bytes.extend_from_slice(&[0; 16]); |
| 14270 | } |
| 14271 | } |
| 14272 | impl From<&CompatMapNotifyEvent> for [u8; 32] { |
| 14273 | fn from(input: &CompatMapNotifyEvent) -> Self { |
| 14274 | let response_type_bytes = input.response_type.serialize(); |
| 14275 | let xkb_type_bytes = input.xkb_type.serialize(); |
| 14276 | let sequence_bytes = input.sequence.serialize(); |
| 14277 | let time_bytes = input.time.serialize(); |
| 14278 | let device_id_bytes = input.device_id.serialize(); |
| 14279 | let changed_groups_bytes = u8::from(input.changed_groups).serialize(); |
| 14280 | let first_si_bytes = input.first_si.serialize(); |
| 14281 | let n_si_bytes = input.n_si.serialize(); |
| 14282 | let n_total_si_bytes = input.n_total_si.serialize(); |
| 14283 | [ |
| 14284 | response_type_bytes[0], |
| 14285 | xkb_type_bytes[0], |
| 14286 | sequence_bytes[0], |
| 14287 | sequence_bytes[1], |
| 14288 | time_bytes[0], |
| 14289 | time_bytes[1], |
| 14290 | time_bytes[2], |
| 14291 | time_bytes[3], |
| 14292 | device_id_bytes[0], |
| 14293 | changed_groups_bytes[0], |
| 14294 | first_si_bytes[0], |
| 14295 | first_si_bytes[1], |
| 14296 | n_si_bytes[0], |
| 14297 | n_si_bytes[1], |
| 14298 | n_total_si_bytes[0], |
| 14299 | n_total_si_bytes[1], |
| 14300 | 0, |
| 14301 | 0, |
| 14302 | 0, |
| 14303 | 0, |
| 14304 | 0, |
| 14305 | 0, |
| 14306 | 0, |
| 14307 | 0, |
| 14308 | 0, |
| 14309 | 0, |
| 14310 | 0, |
| 14311 | 0, |
| 14312 | 0, |
| 14313 | 0, |
| 14314 | 0, |
| 14315 | 0, |
| 14316 | ] |
| 14317 | } |
| 14318 | } |
| 14319 | impl From<CompatMapNotifyEvent> for [u8; 32] { |
| 14320 | fn from(input: CompatMapNotifyEvent) -> Self { |
| 14321 | Self::from(&input) |
| 14322 | } |
| 14323 | } |
| 14324 | |
| 14325 | /// Opcode for the BellNotify event |
| 14326 | pub const BELL_NOTIFY_EVENT: u8 = 8; |
| 14327 | #[derive (Clone, Copy, Default)] |
| 14328 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 14329 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 14330 | pub struct BellNotifyEvent { |
| 14331 | pub response_type: u8, |
| 14332 | pub xkb_type: u8, |
| 14333 | pub sequence: u16, |
| 14334 | pub time: xproto::Timestamp, |
| 14335 | pub device_id: u8, |
| 14336 | pub bell_class: BellClassResult, |
| 14337 | pub bell_id: u8, |
| 14338 | pub percent: u8, |
| 14339 | pub pitch: u16, |
| 14340 | pub duration: u16, |
| 14341 | pub name: xproto::Atom, |
| 14342 | pub window: xproto::Window, |
| 14343 | pub event_only: bool, |
| 14344 | } |
| 14345 | impl_debug_if_no_extra_traits!(BellNotifyEvent, "BellNotifyEvent" ); |
| 14346 | impl TryParse for BellNotifyEvent { |
| 14347 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 14348 | let remaining = initial_value; |
| 14349 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 14350 | let (xkb_type, remaining) = u8::try_parse(remaining)?; |
| 14351 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 14352 | let (time, remaining) = xproto::Timestamp::try_parse(remaining)?; |
| 14353 | let (device_id, remaining) = u8::try_parse(remaining)?; |
| 14354 | let (bell_class, remaining) = u8::try_parse(remaining)?; |
| 14355 | let (bell_id, remaining) = u8::try_parse(remaining)?; |
| 14356 | let (percent, remaining) = u8::try_parse(remaining)?; |
| 14357 | let (pitch, remaining) = u16::try_parse(remaining)?; |
| 14358 | let (duration, remaining) = u16::try_parse(remaining)?; |
| 14359 | let (name, remaining) = xproto::Atom::try_parse(remaining)?; |
| 14360 | let (window, remaining) = xproto::Window::try_parse(remaining)?; |
| 14361 | let (event_only, remaining) = bool::try_parse(remaining)?; |
| 14362 | let remaining = remaining.get(7..).ok_or(ParseError::InsufficientData)?; |
| 14363 | let bell_class = bell_class.into(); |
| 14364 | let result = BellNotifyEvent { response_type, xkb_type, sequence, time, device_id, bell_class, bell_id, percent, pitch, duration, name, window, event_only }; |
| 14365 | let _ = remaining; |
| 14366 | let remaining = initial_value.get(32..) |
| 14367 | .ok_or(ParseError::InsufficientData)?; |
| 14368 | Ok((result, remaining)) |
| 14369 | } |
| 14370 | } |
| 14371 | impl Serialize for BellNotifyEvent { |
| 14372 | type Bytes = [u8; 32]; |
| 14373 | fn serialize(&self) -> [u8; 32] { |
| 14374 | let response_type_bytes = self.response_type.serialize(); |
| 14375 | let xkb_type_bytes = self.xkb_type.serialize(); |
| 14376 | let sequence_bytes = self.sequence.serialize(); |
| 14377 | let time_bytes = self.time.serialize(); |
| 14378 | let device_id_bytes = self.device_id.serialize(); |
| 14379 | let bell_class_bytes = u8::from(self.bell_class).serialize(); |
| 14380 | let bell_id_bytes = self.bell_id.serialize(); |
| 14381 | let percent_bytes = self.percent.serialize(); |
| 14382 | let pitch_bytes = self.pitch.serialize(); |
| 14383 | let duration_bytes = self.duration.serialize(); |
| 14384 | let name_bytes = self.name.serialize(); |
| 14385 | let window_bytes = self.window.serialize(); |
| 14386 | let event_only_bytes = self.event_only.serialize(); |
| 14387 | [ |
| 14388 | response_type_bytes[0], |
| 14389 | xkb_type_bytes[0], |
| 14390 | sequence_bytes[0], |
| 14391 | sequence_bytes[1], |
| 14392 | time_bytes[0], |
| 14393 | time_bytes[1], |
| 14394 | time_bytes[2], |
| 14395 | time_bytes[3], |
| 14396 | device_id_bytes[0], |
| 14397 | bell_class_bytes[0], |
| 14398 | bell_id_bytes[0], |
| 14399 | percent_bytes[0], |
| 14400 | pitch_bytes[0], |
| 14401 | pitch_bytes[1], |
| 14402 | duration_bytes[0], |
| 14403 | duration_bytes[1], |
| 14404 | name_bytes[0], |
| 14405 | name_bytes[1], |
| 14406 | name_bytes[2], |
| 14407 | name_bytes[3], |
| 14408 | window_bytes[0], |
| 14409 | window_bytes[1], |
| 14410 | window_bytes[2], |
| 14411 | window_bytes[3], |
| 14412 | event_only_bytes[0], |
| 14413 | 0, |
| 14414 | 0, |
| 14415 | 0, |
| 14416 | 0, |
| 14417 | 0, |
| 14418 | 0, |
| 14419 | 0, |
| 14420 | ] |
| 14421 | } |
| 14422 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 14423 | bytes.reserve(32); |
| 14424 | self.response_type.serialize_into(bytes); |
| 14425 | self.xkb_type.serialize_into(bytes); |
| 14426 | self.sequence.serialize_into(bytes); |
| 14427 | self.time.serialize_into(bytes); |
| 14428 | self.device_id.serialize_into(bytes); |
| 14429 | u8::from(self.bell_class).serialize_into(bytes); |
| 14430 | self.bell_id.serialize_into(bytes); |
| 14431 | self.percent.serialize_into(bytes); |
| 14432 | self.pitch.serialize_into(bytes); |
| 14433 | self.duration.serialize_into(bytes); |
| 14434 | self.name.serialize_into(bytes); |
| 14435 | self.window.serialize_into(bytes); |
| 14436 | self.event_only.serialize_into(bytes); |
| 14437 | bytes.extend_from_slice(&[0; 7]); |
| 14438 | } |
| 14439 | } |
| 14440 | impl From<&BellNotifyEvent> for [u8; 32] { |
| 14441 | fn from(input: &BellNotifyEvent) -> Self { |
| 14442 | let response_type_bytes = input.response_type.serialize(); |
| 14443 | let xkb_type_bytes = input.xkb_type.serialize(); |
| 14444 | let sequence_bytes = input.sequence.serialize(); |
| 14445 | let time_bytes = input.time.serialize(); |
| 14446 | let device_id_bytes = input.device_id.serialize(); |
| 14447 | let bell_class_bytes = u8::from(input.bell_class).serialize(); |
| 14448 | let bell_id_bytes = input.bell_id.serialize(); |
| 14449 | let percent_bytes = input.percent.serialize(); |
| 14450 | let pitch_bytes = input.pitch.serialize(); |
| 14451 | let duration_bytes = input.duration.serialize(); |
| 14452 | let name_bytes = input.name.serialize(); |
| 14453 | let window_bytes = input.window.serialize(); |
| 14454 | let event_only_bytes = input.event_only.serialize(); |
| 14455 | [ |
| 14456 | response_type_bytes[0], |
| 14457 | xkb_type_bytes[0], |
| 14458 | sequence_bytes[0], |
| 14459 | sequence_bytes[1], |
| 14460 | time_bytes[0], |
| 14461 | time_bytes[1], |
| 14462 | time_bytes[2], |
| 14463 | time_bytes[3], |
| 14464 | device_id_bytes[0], |
| 14465 | bell_class_bytes[0], |
| 14466 | bell_id_bytes[0], |
| 14467 | percent_bytes[0], |
| 14468 | pitch_bytes[0], |
| 14469 | pitch_bytes[1], |
| 14470 | duration_bytes[0], |
| 14471 | duration_bytes[1], |
| 14472 | name_bytes[0], |
| 14473 | name_bytes[1], |
| 14474 | name_bytes[2], |
| 14475 | name_bytes[3], |
| 14476 | window_bytes[0], |
| 14477 | window_bytes[1], |
| 14478 | window_bytes[2], |
| 14479 | window_bytes[3], |
| 14480 | event_only_bytes[0], |
| 14481 | 0, |
| 14482 | 0, |
| 14483 | 0, |
| 14484 | 0, |
| 14485 | 0, |
| 14486 | 0, |
| 14487 | 0, |
| 14488 | ] |
| 14489 | } |
| 14490 | } |
| 14491 | impl From<BellNotifyEvent> for [u8; 32] { |
| 14492 | fn from(input: BellNotifyEvent) -> Self { |
| 14493 | Self::from(&input) |
| 14494 | } |
| 14495 | } |
| 14496 | |
| 14497 | /// Opcode for the ActionMessage event |
| 14498 | pub const ACTION_MESSAGE_EVENT: u8 = 9; |
| 14499 | #[derive (Clone, Copy, Default)] |
| 14500 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 14501 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 14502 | pub struct ActionMessageEvent { |
| 14503 | pub response_type: u8, |
| 14504 | pub xkb_type: u8, |
| 14505 | pub sequence: u16, |
| 14506 | pub time: xproto::Timestamp, |
| 14507 | pub device_id: u8, |
| 14508 | pub keycode: xproto::Keycode, |
| 14509 | pub press: bool, |
| 14510 | pub key_event_follows: bool, |
| 14511 | pub mods: xproto::ModMask, |
| 14512 | pub group: Group, |
| 14513 | pub message: [String8; 8], |
| 14514 | } |
| 14515 | impl_debug_if_no_extra_traits!(ActionMessageEvent, "ActionMessageEvent" ); |
| 14516 | impl TryParse for ActionMessageEvent { |
| 14517 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 14518 | let remaining: &[u8] = initial_value; |
| 14519 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 14520 | let (xkb_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 14521 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 14522 | let (time: u32, remaining: &[u8]) = xproto::Timestamp::try_parse(remaining)?; |
| 14523 | let (device_id: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 14524 | let (keycode: u8, remaining: &[u8]) = xproto::Keycode::try_parse(remaining)?; |
| 14525 | let (press: bool, remaining: &[u8]) = bool::try_parse(remaining)?; |
| 14526 | let (key_event_follows: bool, remaining: &[u8]) = bool::try_parse(remaining)?; |
| 14527 | let (mods: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 14528 | let (group: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 14529 | let (message: [u8; 8], remaining: &[u8]) = crate::x11_utils::parse_u8_array::<8>(data:remaining)?; |
| 14530 | let remaining: &[u8] = remaining.get(10..).ok_or(err:ParseError::InsufficientData)?; |
| 14531 | let mods: ModMask = mods.into(); |
| 14532 | let group: Group = group.into(); |
| 14533 | let result: ActionMessageEvent = ActionMessageEvent { response_type, xkb_type, sequence, time, device_id, keycode, press, key_event_follows, mods, group, message }; |
| 14534 | let _ = remaining; |
| 14535 | let remaining: &[u8] = initial_value.get(32..) |
| 14536 | .ok_or(err:ParseError::InsufficientData)?; |
| 14537 | Ok((result, remaining)) |
| 14538 | } |
| 14539 | } |
| 14540 | impl Serialize for ActionMessageEvent { |
| 14541 | type Bytes = [u8; 32]; |
| 14542 | fn serialize(&self) -> [u8; 32] { |
| 14543 | let response_type_bytes = self.response_type.serialize(); |
| 14544 | let xkb_type_bytes = self.xkb_type.serialize(); |
| 14545 | let sequence_bytes = self.sequence.serialize(); |
| 14546 | let time_bytes = self.time.serialize(); |
| 14547 | let device_id_bytes = self.device_id.serialize(); |
| 14548 | let keycode_bytes = self.keycode.serialize(); |
| 14549 | let press_bytes = self.press.serialize(); |
| 14550 | let key_event_follows_bytes = self.key_event_follows.serialize(); |
| 14551 | let mods_bytes = (u16::from(self.mods) as u8).serialize(); |
| 14552 | let group_bytes = u8::from(self.group).serialize(); |
| 14553 | [ |
| 14554 | response_type_bytes[0], |
| 14555 | xkb_type_bytes[0], |
| 14556 | sequence_bytes[0], |
| 14557 | sequence_bytes[1], |
| 14558 | time_bytes[0], |
| 14559 | time_bytes[1], |
| 14560 | time_bytes[2], |
| 14561 | time_bytes[3], |
| 14562 | device_id_bytes[0], |
| 14563 | keycode_bytes[0], |
| 14564 | press_bytes[0], |
| 14565 | key_event_follows_bytes[0], |
| 14566 | mods_bytes[0], |
| 14567 | group_bytes[0], |
| 14568 | self.message[0], |
| 14569 | self.message[1], |
| 14570 | self.message[2], |
| 14571 | self.message[3], |
| 14572 | self.message[4], |
| 14573 | self.message[5], |
| 14574 | self.message[6], |
| 14575 | self.message[7], |
| 14576 | 0, |
| 14577 | 0, |
| 14578 | 0, |
| 14579 | 0, |
| 14580 | 0, |
| 14581 | 0, |
| 14582 | 0, |
| 14583 | 0, |
| 14584 | 0, |
| 14585 | 0, |
| 14586 | ] |
| 14587 | } |
| 14588 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 14589 | bytes.reserve(32); |
| 14590 | self.response_type.serialize_into(bytes); |
| 14591 | self.xkb_type.serialize_into(bytes); |
| 14592 | self.sequence.serialize_into(bytes); |
| 14593 | self.time.serialize_into(bytes); |
| 14594 | self.device_id.serialize_into(bytes); |
| 14595 | self.keycode.serialize_into(bytes); |
| 14596 | self.press.serialize_into(bytes); |
| 14597 | self.key_event_follows.serialize_into(bytes); |
| 14598 | (u16::from(self.mods) as u8).serialize_into(bytes); |
| 14599 | u8::from(self.group).serialize_into(bytes); |
| 14600 | bytes.extend_from_slice(&self.message); |
| 14601 | bytes.extend_from_slice(&[0; 10]); |
| 14602 | } |
| 14603 | } |
| 14604 | impl From<&ActionMessageEvent> for [u8; 32] { |
| 14605 | fn from(input: &ActionMessageEvent) -> Self { |
| 14606 | let response_type_bytes = input.response_type.serialize(); |
| 14607 | let xkb_type_bytes = input.xkb_type.serialize(); |
| 14608 | let sequence_bytes = input.sequence.serialize(); |
| 14609 | let time_bytes = input.time.serialize(); |
| 14610 | let device_id_bytes = input.device_id.serialize(); |
| 14611 | let keycode_bytes = input.keycode.serialize(); |
| 14612 | let press_bytes = input.press.serialize(); |
| 14613 | let key_event_follows_bytes = input.key_event_follows.serialize(); |
| 14614 | let mods_bytes = (u16::from(input.mods) as u8).serialize(); |
| 14615 | let group_bytes = u8::from(input.group).serialize(); |
| 14616 | [ |
| 14617 | response_type_bytes[0], |
| 14618 | xkb_type_bytes[0], |
| 14619 | sequence_bytes[0], |
| 14620 | sequence_bytes[1], |
| 14621 | time_bytes[0], |
| 14622 | time_bytes[1], |
| 14623 | time_bytes[2], |
| 14624 | time_bytes[3], |
| 14625 | device_id_bytes[0], |
| 14626 | keycode_bytes[0], |
| 14627 | press_bytes[0], |
| 14628 | key_event_follows_bytes[0], |
| 14629 | mods_bytes[0], |
| 14630 | group_bytes[0], |
| 14631 | input.message[0], |
| 14632 | input.message[1], |
| 14633 | input.message[2], |
| 14634 | input.message[3], |
| 14635 | input.message[4], |
| 14636 | input.message[5], |
| 14637 | input.message[6], |
| 14638 | input.message[7], |
| 14639 | 0, |
| 14640 | 0, |
| 14641 | 0, |
| 14642 | 0, |
| 14643 | 0, |
| 14644 | 0, |
| 14645 | 0, |
| 14646 | 0, |
| 14647 | 0, |
| 14648 | 0, |
| 14649 | ] |
| 14650 | } |
| 14651 | } |
| 14652 | impl From<ActionMessageEvent> for [u8; 32] { |
| 14653 | fn from(input: ActionMessageEvent) -> Self { |
| 14654 | Self::from(&input) |
| 14655 | } |
| 14656 | } |
| 14657 | |
| 14658 | /// Opcode for the AccessXNotify event |
| 14659 | pub const ACCESS_X_NOTIFY_EVENT: u8 = 10; |
| 14660 | #[derive (Clone, Copy, Default)] |
| 14661 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 14662 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 14663 | pub struct AccessXNotifyEvent { |
| 14664 | pub response_type: u8, |
| 14665 | pub xkb_type: u8, |
| 14666 | pub sequence: u16, |
| 14667 | pub time: xproto::Timestamp, |
| 14668 | pub device_id: u8, |
| 14669 | pub keycode: xproto::Keycode, |
| 14670 | pub detailt: AXNDetail, |
| 14671 | pub slow_keys_delay: u16, |
| 14672 | pub debounce_delay: u16, |
| 14673 | } |
| 14674 | impl_debug_if_no_extra_traits!(AccessXNotifyEvent, "AccessXNotifyEvent" ); |
| 14675 | impl TryParse for AccessXNotifyEvent { |
| 14676 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 14677 | let remaining: &[u8] = initial_value; |
| 14678 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 14679 | let (xkb_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 14680 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 14681 | let (time: u32, remaining: &[u8]) = xproto::Timestamp::try_parse(remaining)?; |
| 14682 | let (device_id: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
| 14683 | let (keycode: u8, remaining: &[u8]) = xproto::Keycode::try_parse(remaining)?; |
| 14684 | let (detailt: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 14685 | let (slow_keys_delay: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 14686 | let (debounce_delay: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
| 14687 | let remaining: &[u8] = remaining.get(16..).ok_or(err:ParseError::InsufficientData)?; |
| 14688 | let detailt: AXNDetail = detailt.into(); |
| 14689 | let result: AccessXNotifyEvent = AccessXNotifyEvent { response_type, xkb_type, sequence, time, device_id, keycode, detailt, slow_keys_delay, debounce_delay }; |
| 14690 | let _ = remaining; |
| 14691 | let remaining: &[u8] = initial_value.get(32..) |
| 14692 | .ok_or(err:ParseError::InsufficientData)?; |
| 14693 | Ok((result, remaining)) |
| 14694 | } |
| 14695 | } |
| 14696 | impl Serialize for AccessXNotifyEvent { |
| 14697 | type Bytes = [u8; 32]; |
| 14698 | fn serialize(&self) -> [u8; 32] { |
| 14699 | let response_type_bytes = self.response_type.serialize(); |
| 14700 | let xkb_type_bytes = self.xkb_type.serialize(); |
| 14701 | let sequence_bytes = self.sequence.serialize(); |
| 14702 | let time_bytes = self.time.serialize(); |
| 14703 | let device_id_bytes = self.device_id.serialize(); |
| 14704 | let keycode_bytes = self.keycode.serialize(); |
| 14705 | let detailt_bytes = u16::from(self.detailt).serialize(); |
| 14706 | let slow_keys_delay_bytes = self.slow_keys_delay.serialize(); |
| 14707 | let debounce_delay_bytes = self.debounce_delay.serialize(); |
| 14708 | [ |
| 14709 | response_type_bytes[0], |
| 14710 | xkb_type_bytes[0], |
| 14711 | sequence_bytes[0], |
| 14712 | sequence_bytes[1], |
| 14713 | time_bytes[0], |
| 14714 | time_bytes[1], |
| 14715 | time_bytes[2], |
| 14716 | time_bytes[3], |
| 14717 | device_id_bytes[0], |
| 14718 | keycode_bytes[0], |
| 14719 | detailt_bytes[0], |
| 14720 | detailt_bytes[1], |
| 14721 | slow_keys_delay_bytes[0], |
| 14722 | slow_keys_delay_bytes[1], |
| 14723 | debounce_delay_bytes[0], |
| 14724 | debounce_delay_bytes[1], |
| 14725 | 0, |
| 14726 | 0, |
| 14727 | 0, |
| 14728 | 0, |
| 14729 | 0, |
| 14730 | 0, |
| 14731 | 0, |
| 14732 | 0, |
| 14733 | 0, |
| 14734 | 0, |
| 14735 | 0, |
| 14736 | 0, |
| 14737 | 0, |
| 14738 | 0, |
| 14739 | 0, |
| 14740 | 0, |
| 14741 | ] |
| 14742 | } |
| 14743 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 14744 | bytes.reserve(32); |
| 14745 | self.response_type.serialize_into(bytes); |
| 14746 | self.xkb_type.serialize_into(bytes); |
| 14747 | self.sequence.serialize_into(bytes); |
| 14748 | self.time.serialize_into(bytes); |
| 14749 | self.device_id.serialize_into(bytes); |
| 14750 | self.keycode.serialize_into(bytes); |
| 14751 | u16::from(self.detailt).serialize_into(bytes); |
| 14752 | self.slow_keys_delay.serialize_into(bytes); |
| 14753 | self.debounce_delay.serialize_into(bytes); |
| 14754 | bytes.extend_from_slice(&[0; 16]); |
| 14755 | } |
| 14756 | } |
| 14757 | impl From<&AccessXNotifyEvent> for [u8; 32] { |
| 14758 | fn from(input: &AccessXNotifyEvent) -> Self { |
| 14759 | let response_type_bytes = input.response_type.serialize(); |
| 14760 | let xkb_type_bytes = input.xkb_type.serialize(); |
| 14761 | let sequence_bytes = input.sequence.serialize(); |
| 14762 | let time_bytes = input.time.serialize(); |
| 14763 | let device_id_bytes = input.device_id.serialize(); |
| 14764 | let keycode_bytes = input.keycode.serialize(); |
| 14765 | let detailt_bytes = u16::from(input.detailt).serialize(); |
| 14766 | let slow_keys_delay_bytes = input.slow_keys_delay.serialize(); |
| 14767 | let debounce_delay_bytes = input.debounce_delay.serialize(); |
| 14768 | [ |
| 14769 | response_type_bytes[0], |
| 14770 | xkb_type_bytes[0], |
| 14771 | sequence_bytes[0], |
| 14772 | sequence_bytes[1], |
| 14773 | time_bytes[0], |
| 14774 | time_bytes[1], |
| 14775 | time_bytes[2], |
| 14776 | time_bytes[3], |
| 14777 | device_id_bytes[0], |
| 14778 | keycode_bytes[0], |
| 14779 | detailt_bytes[0], |
| 14780 | detailt_bytes[1], |
| 14781 | slow_keys_delay_bytes[0], |
| 14782 | slow_keys_delay_bytes[1], |
| 14783 | debounce_delay_bytes[0], |
| 14784 | debounce_delay_bytes[1], |
| 14785 | 0, |
| 14786 | 0, |
| 14787 | 0, |
| 14788 | 0, |
| 14789 | 0, |
| 14790 | 0, |
| 14791 | 0, |
| 14792 | 0, |
| 14793 | 0, |
| 14794 | 0, |
| 14795 | 0, |
| 14796 | 0, |
| 14797 | 0, |
| 14798 | 0, |
| 14799 | 0, |
| 14800 | 0, |
| 14801 | ] |
| 14802 | } |
| 14803 | } |
| 14804 | impl From<AccessXNotifyEvent> for [u8; 32] { |
| 14805 | fn from(input: AccessXNotifyEvent) -> Self { |
| 14806 | Self::from(&input) |
| 14807 | } |
| 14808 | } |
| 14809 | |
| 14810 | /// Opcode for the ExtensionDeviceNotify event |
| 14811 | pub const EXTENSION_DEVICE_NOTIFY_EVENT: u8 = 11; |
| 14812 | #[derive (Clone, Copy, Default)] |
| 14813 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
| 14814 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 14815 | pub struct ExtensionDeviceNotifyEvent { |
| 14816 | pub response_type: u8, |
| 14817 | pub xkb_type: u8, |
| 14818 | pub sequence: u16, |
| 14819 | pub time: xproto::Timestamp, |
| 14820 | pub device_id: u8, |
| 14821 | pub reason: XIFeature, |
| 14822 | pub led_class: LedClassResult, |
| 14823 | pub led_id: u16, |
| 14824 | pub leds_defined: u32, |
| 14825 | pub led_state: u32, |
| 14826 | pub first_button: u8, |
| 14827 | pub n_buttons: u8, |
| 14828 | pub supported: XIFeature, |
| 14829 | pub unsupported: XIFeature, |
| 14830 | } |
| 14831 | impl_debug_if_no_extra_traits!(ExtensionDeviceNotifyEvent, "ExtensionDeviceNotifyEvent" ); |
| 14832 | impl TryParse for ExtensionDeviceNotifyEvent { |
| 14833 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
| 14834 | let remaining = initial_value; |
| 14835 | let (response_type, remaining) = u8::try_parse(remaining)?; |
| 14836 | let (xkb_type, remaining) = u8::try_parse(remaining)?; |
| 14837 | let (sequence, remaining) = u16::try_parse(remaining)?; |
| 14838 | let (time, remaining) = xproto::Timestamp::try_parse(remaining)?; |
| 14839 | let (device_id, remaining) = u8::try_parse(remaining)?; |
| 14840 | let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; |
| 14841 | let (reason, remaining) = u16::try_parse(remaining)?; |
| 14842 | let (led_class, remaining) = u16::try_parse(remaining)?; |
| 14843 | let (led_id, remaining) = u16::try_parse(remaining)?; |
| 14844 | let (leds_defined, remaining) = u32::try_parse(remaining)?; |
| 14845 | let (led_state, remaining) = u32::try_parse(remaining)?; |
| 14846 | let (first_button, remaining) = u8::try_parse(remaining)?; |
| 14847 | let (n_buttons, remaining) = u8::try_parse(remaining)?; |
| 14848 | let (supported, remaining) = u16::try_parse(remaining)?; |
| 14849 | let (unsupported, remaining) = u16::try_parse(remaining)?; |
| 14850 | let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; |
| 14851 | let reason = reason.into(); |
| 14852 | let led_class = led_class.into(); |
| 14853 | let supported = supported.into(); |
| 14854 | let unsupported = unsupported.into(); |
| 14855 | 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 }; |
| 14856 | let _ = remaining; |
| 14857 | let remaining = initial_value.get(32..) |
| 14858 | .ok_or(ParseError::InsufficientData)?; |
| 14859 | Ok((result, remaining)) |
| 14860 | } |
| 14861 | } |
| 14862 | impl Serialize for ExtensionDeviceNotifyEvent { |
| 14863 | type Bytes = [u8; 32]; |
| 14864 | fn serialize(&self) -> [u8; 32] { |
| 14865 | let response_type_bytes = self.response_type.serialize(); |
| 14866 | let xkb_type_bytes = self.xkb_type.serialize(); |
| 14867 | let sequence_bytes = self.sequence.serialize(); |
| 14868 | let time_bytes = self.time.serialize(); |
| 14869 | let device_id_bytes = self.device_id.serialize(); |
| 14870 | let reason_bytes = u16::from(self.reason).serialize(); |
| 14871 | let led_class_bytes = u16::from(self.led_class).serialize(); |
| 14872 | let led_id_bytes = self.led_id.serialize(); |
| 14873 | let leds_defined_bytes = self.leds_defined.serialize(); |
| 14874 | let led_state_bytes = self.led_state.serialize(); |
| 14875 | let first_button_bytes = self.first_button.serialize(); |
| 14876 | let n_buttons_bytes = self.n_buttons.serialize(); |
| 14877 | let supported_bytes = u16::from(self.supported).serialize(); |
| 14878 | let unsupported_bytes = u16::from(self.unsupported).serialize(); |
| 14879 | [ |
| 14880 | response_type_bytes[0], |
| 14881 | xkb_type_bytes[0], |
| 14882 | sequence_bytes[0], |
| 14883 | sequence_bytes[1], |
| 14884 | time_bytes[0], |
| 14885 | time_bytes[1], |
| 14886 | time_bytes[2], |
| 14887 | time_bytes[3], |
| 14888 | device_id_bytes[0], |
| 14889 | 0, |
| 14890 | reason_bytes[0], |
| 14891 | reason_bytes[1], |
| 14892 | led_class_bytes[0], |
| 14893 | led_class_bytes[1], |
| 14894 | led_id_bytes[0], |
| 14895 | led_id_bytes[1], |
| 14896 | leds_defined_bytes[0], |
| 14897 | leds_defined_bytes[1], |
| 14898 | leds_defined_bytes[2], |
| 14899 | leds_defined_bytes[3], |
| 14900 | led_state_bytes[0], |
| 14901 | led_state_bytes[1], |
| 14902 | led_state_bytes[2], |
| 14903 | led_state_bytes[3], |
| 14904 | first_button_bytes[0], |
| 14905 | n_buttons_bytes[0], |
| 14906 | supported_bytes[0], |
| 14907 | supported_bytes[1], |
| 14908 | unsupported_bytes[0], |
| 14909 | unsupported_bytes[1], |
| 14910 | 0, |
| 14911 | 0, |
| 14912 | ] |
| 14913 | } |
| 14914 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
| 14915 | bytes.reserve(32); |
| 14916 | self.response_type.serialize_into(bytes); |
| 14917 | self.xkb_type.serialize_into(bytes); |
| 14918 | self.sequence.serialize_into(bytes); |
| 14919 | self.time.serialize_into(bytes); |
| 14920 | self.device_id.serialize_into(bytes); |
| 14921 | bytes.extend_from_slice(&[0; 1]); |
| 14922 | u16::from(self.reason).serialize_into(bytes); |
| 14923 | u16::from(self.led_class).serialize_into(bytes); |
| 14924 | self.led_id.serialize_into(bytes); |
| 14925 | self.leds_defined.serialize_into(bytes); |
| 14926 | self.led_state.serialize_into(bytes); |
| 14927 | self.first_button.serialize_into(bytes); |
| 14928 | self.n_buttons.serialize_into(bytes); |
| 14929 | u16::from(self.supported).serialize_into(bytes); |
| 14930 | u16::from(self.unsupported).serialize_into(bytes); |
| 14931 | bytes.extend_from_slice(&[0; 2]); |
| 14932 | } |
| 14933 | } |
| 14934 | impl From<&ExtensionDeviceNotifyEvent> for [u8; 32] { |
| 14935 | fn from(input: &ExtensionDeviceNotifyEvent) -> Self { |
| 14936 | let response_type_bytes = input.response_type.serialize(); |
| 14937 | let xkb_type_bytes = input.xkb_type.serialize(); |
| 14938 | let sequence_bytes = input.sequence.serialize(); |
| 14939 | let time_bytes = input.time.serialize(); |
| 14940 | let device_id_bytes = input.device_id.serialize(); |
| 14941 | let reason_bytes = u16::from(input.reason).serialize(); |
| 14942 | let led_class_bytes = u16::from(input.led_class).serialize(); |
| 14943 | let led_id_bytes = input.led_id.serialize(); |
| 14944 | let leds_defined_bytes = input.leds_defined.serialize(); |
| 14945 | let led_state_bytes = input.led_state.serialize(); |
| 14946 | let first_button_bytes = input.first_button.serialize(); |
| 14947 | let n_buttons_bytes = input.n_buttons.serialize(); |
| 14948 | let supported_bytes = u16::from(input.supported).serialize(); |
| 14949 | let unsupported_bytes = u16::from(input.unsupported).serialize(); |
| 14950 | [ |
| 14951 | response_type_bytes[0], |
| 14952 | xkb_type_bytes[0], |
| 14953 | sequence_bytes[0], |
| 14954 | sequence_bytes[1], |
| 14955 | time_bytes[0], |
| 14956 | time_bytes[1], |
| 14957 | time_bytes[2], |
| 14958 | time_bytes[3], |
| 14959 | device_id_bytes[0], |
| 14960 | 0, |
| 14961 | reason_bytes[0], |
| 14962 | reason_bytes[1], |
| 14963 | led_class_bytes[0], |
| 14964 | led_class_bytes[1], |
| 14965 | led_id_bytes[0], |
| 14966 | led_id_bytes[1], |
| 14967 | leds_defined_bytes[0], |
| 14968 | leds_defined_bytes[1], |
| 14969 | leds_defined_bytes[2], |
| 14970 | leds_defined_bytes[3], |
| 14971 | led_state_bytes[0], |
| 14972 | led_state_bytes[1], |
| 14973 | led_state_bytes[2], |
| 14974 | led_state_bytes[3], |
| 14975 | first_button_bytes[0], |
| 14976 | n_buttons_bytes[0], |
| 14977 | supported_bytes[0], |
| 14978 | supported_bytes[1], |
| 14979 | unsupported_bytes[0], |
| 14980 | unsupported_bytes[1], |
| 14981 | 0, |
| 14982 | 0, |
| 14983 | ] |
| 14984 | } |
| 14985 | } |
| 14986 | impl From<ExtensionDeviceNotifyEvent> for [u8; 32] { |
| 14987 | fn from(input: ExtensionDeviceNotifyEvent) -> Self { |
| 14988 | Self::from(&input) |
| 14989 | } |
| 14990 | } |
| 14991 | |
| 14992 | |