vnc/event.rs
1use crate::PixelFormat;
2
3type ImageData = Vec<u8>;
4
5/// A rect where the image should be updated
6#[derive(Debug, Clone, Copy)]
7pub struct Rect {
8 pub x: u16,
9 pub y: u16,
10 pub width: u16,
11 pub height: u16,
12}
13
14/// Resolution format to resize window
15#[derive(Debug, Clone)]
16pub struct Screen {
17 pub width: u16,
18 pub height: u16,
19}
20
21impl From<(u16, u16)> for Screen {
22 fn from(tuple: (u16, u16)) -> Self {
23 Self {
24 width: tuple.0,
25 height: tuple.1,
26 }
27 }
28}
29
30type SrcRect = Rect;
31type DstRect = Rect;
32
33/// Events generated by the [crate::VncClient]
34///
35#[non_exhaustive]
36#[derive(Debug, Clone)]
37pub enum VncEvent {
38 /// Tell the client how to display the images
39 ///
40 /// ```no_compile
41 /// if let VncEvent::SetResolution(resolution) = event {
42 /// window.resize(screen.width, screen.height);
43 /// }
44 /// ```
45 ///
46 /// Note that this event may be recived multiple times
47 ///
48 /// If the [crate::VncEncoding::DesktopSizePseudo] is set
49 ///
50 SetResolution(Screen),
51 /// If the connector doesn't call `set_pixel_format` method
52 ///
53 /// The engine will generate a [VncEvent::SetPixelFormat] to let the window know how to render image
54 ///
55 SetPixelFormat(PixelFormat),
56 /// Raw image data in the order followed by informed PixelFormat
57 ///
58 RawImage(Rect, ImageData),
59 /// Copy image data from the second rect to the first
60 ///
61 Copy(DstRect, SrcRect),
62 /// A jpeg image if using Tight encoding,
63 ///
64 /// Encoding the bytes with base64 and render it with "<img src=data:image/jpeg;base64,.../>",
65 ///
66 JpegImage(Rect, ImageData),
67
68 // PngImage(Rect, ImageData),
69 /// Will be generated if [crate::VncEncoding::CursorPseudo] is set
70 ///
71 /// According to [RFC6143, section-7.8.1](https://www.rfc-editor.org/rfc/rfc6143.html#section-7.8.1)
72 ///
73 SetCursor(Rect, ImageData),
74 /// Just ring a bell
75 ///
76 Bell,
77 /// Will be generated everytime the vncserver's clipboarded get updated
78 ///
79 /// Note that only Latin-1 character set is allowed
80 ///
81 /// According to [RFC6143](https://www.rfc-editor.org/rfc/rfc6143.html#section-7.6.4)
82 ///
83 Text(String),
84 /// If any unexpected error happens in the async process routines
85 /// This event will propagate the error to the current context
86 Error(String),
87}
88
89/// X11 keyboard event to notify the server
90///
91/// Referring to [RFC6143, section-7.5.4](https://www.rfc-editor.org/rfc/rfc6143.html#section-7.5.4)
92///
93#[derive(Debug, Clone)]
94pub struct ClientKeyEvent {
95 pub keycode: u32,
96 pub down: bool,
97}
98
99impl From<(u32, bool)> for ClientKeyEvent {
100 fn from(tuple: (u32, bool)) -> Self {
101 Self {
102 keycode: tuple.0,
103 down: tuple.1,
104 }
105 }
106}
107
108/// X11 mouse event to notify the server
109///
110/// Referring to [RFC6143, seciont-7.5.5](https://www.rfc-editor.org/rfc/rfc6143.html#section-7.5.5)
111///
112#[derive(Debug, Clone)]
113pub struct ClientMouseEvent {
114 pub position_x: u16,
115 pub position_y: u16,
116 pub bottons: u8,
117}
118
119impl From<(u16, u16, u8)> for ClientMouseEvent {
120 fn from(tuple: (u16, u16, u8)) -> Self {
121 Self {
122 position_x: tuple.0,
123 position_y: tuple.1,
124 bottons: tuple.2,
125 }
126 }
127}
128
129/// Client-side event which used to ask the engine send some command to the vnc server
130///
131#[non_exhaustive]
132#[derive(Debug, Clone)]
133pub enum X11Event {
134 /// Require a frame update
135 ///
136 Refresh,
137 /// Key down/up
138 ///
139 KeyEvent(ClientKeyEvent),
140 /// Mouse move/up/down/scroll
141 ///
142 PointerEvent(ClientMouseEvent),
143 /// Send data to the server's clipboard
144 ///
145 /// Only Latin-1 character set is allowed
146 ///
147 CopyText(String),
148}