From 7bcaa341b8685ba411d206c1a89dc3ca77aa71bb Mon Sep 17 00:00:00 2001 From: Max Verevkin Date: Fri, 1 Apr 2022 21:50:19 +0300 Subject: initial commit --- src/pointer_btn.rs | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/pointer_btn.rs (limited to 'src/pointer_btn.rs') diff --git a/src/pointer_btn.rs b/src/pointer_btn.rs new file mode 100644 index 0000000..829fc9c --- /dev/null +++ b/src/pointer_btn.rs @@ -0,0 +1,62 @@ +use serde::{Serialize, Serializer}; + +// From linux/input-event-codes.h +const BTN_LEFT: u32 = 0x110; +const BTN_RIGHT: u32 = 0x111; +const BTN_MIDDLE: u32 = 0x112; +// const BTN_SIDE: u32 = 0x113; +// const BTN_EXTRA: u32 = 0x114; +const BTN_FORWARD: u32 = 0x115; +const BTN_BACK: u32 = 0x116; +// const BTN_TASK: u32 = 0x117; + +#[derive(Debug, Clone, Copy)] +pub enum PointerBtn { + Left, + Middle, + Right, + Forward, + WheelUp, + WheelDown, + Back, + Unknown, +} + +impl Default for PointerBtn { + fn default() -> Self { + Self::Unknown + } +} + +impl From for PointerBtn { + fn from(code: u32) -> Self { + use PointerBtn::*; + match code { + BTN_LEFT => Left, + BTN_MIDDLE => Middle, + BTN_RIGHT => Right, + BTN_FORWARD => Forward, + BTN_BACK => Back, + _ => Unknown, + } + } +} + +impl Serialize for PointerBtn { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let num = match *self { + PointerBtn::Left => 1, + PointerBtn::Middle => 2, + PointerBtn::Right => 3, + PointerBtn::WheelUp => 4, + PointerBtn::WheelDown => 5, + PointerBtn::Forward => 9, + PointerBtn::Back => 8, + PointerBtn::Unknown => 0, + }; + serializer.serialize_u8(num) + } +} -- cgit v1.3.1