ironrdp_pdu/input/
mouse_rel.rs1use bitflags::bitflags;
2use ironrdp_core::{ensure_fixed_part_size, Decode, DecodeResult, Encode, EncodeResult, ReadCursor, WriteCursor};
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct MouseRelPdu {
6 pub flags: PointerRelFlags,
7 pub x_delta: i16,
8 pub y_delta: i16,
9}
10
11impl MouseRelPdu {
12 const NAME: &'static str = "MouseRelPdu";
13
14 const FIXED_PART_SIZE: usize = 2 + 2 + 2 ;
15}
16
17impl Encode for MouseRelPdu {
18 fn encode(&self, dst: &mut WriteCursor<'_>) -> EncodeResult<()> {
19 ensure_fixed_part_size!(in: dst);
20
21 dst.write_u16(self.flags.bits());
22 dst.write_i16(self.x_delta);
23 dst.write_i16(self.y_delta);
24
25 Ok(())
26 }
27
28 fn name(&self) -> &'static str {
29 Self::NAME
30 }
31
32 fn size(&self) -> usize {
33 Self::FIXED_PART_SIZE
34 }
35}
36
37impl<'de> Decode<'de> for MouseRelPdu {
38 fn decode(src: &mut ReadCursor<'de>) -> DecodeResult<Self> {
39 ensure_fixed_part_size!(in: src);
40
41 let flags = PointerRelFlags::from_bits_truncate(src.read_u16());
42 let x_delta = src.read_i16();
43 let y_delta = src.read_i16();
44
45 Ok(Self {
46 flags,
47 x_delta,
48 y_delta,
49 })
50 }
51}
52
53bitflags! {
54 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
55 pub struct PointerRelFlags: u16 {
56 const MOVE = 0x0800;
57 const DOWN = 0x8000;
58 const BUTTON1 = 0x1000;
59 const BUTTON2 = 0x2000;
60 const BUTTON3 = 0x4000;
61 const XBUTTON1 = 0x0001;
62 const XBUTTON2 = 0x0002;
63 }
64}