diff --git a/examples/server.rs b/examples/server.rs index 843eb34..6898f29 100644 --- a/examples/server.rs +++ b/examples/server.rs @@ -13,7 +13,8 @@ use image::GenericImageView; use log::info; use rfb::encodings::RawEncoding; use rfb::rfb::{ - FramebufferUpdate, KeyEvent, PixelFormat, ProtoVersion, Rectangle, SecurityType, SecurityTypes, + FramebufferUpdate, KeyEvent, PixelFormat, PointerEvent, ProtoVersion, Rectangle, SecurityType, + SecurityTypes, }; use rfb::{ pixel_formats::rgb_888, @@ -108,8 +109,8 @@ async fn main() -> Result<()> { name: "rfb-example-server".to_string(), }; let data = VncServerData { - width: WIDTH as u16, - height: HEIGHT as u16, + width: WIDTH as _, + height: HEIGHT as _, input_pixel_format: pf.clone(), }; let server = ExampleServer { @@ -220,8 +221,8 @@ fn generate_pixels(img: Image, big_endian: bool, rgb_order: (u8, u8, u8)) -> Vec #[async_trait] impl Server for ExampleServer { async fn get_framebuffer_update(&self) -> FramebufferUpdate { - let pixels_width = 1024; - let pixels_height = 768; + let pixels_width = WIDTH as _; + let pixels_height = HEIGHT as _; let pixels = generate_pixels(self.display, self.big_endian, self.rgb_order); let r = Rectangle::new( 0, @@ -233,5 +234,23 @@ impl Server for ExampleServer { FramebufferUpdate::new(vec![r]) } - async fn key_event(&self, _ke: KeyEvent) {} + async fn key_event(&self, ke: KeyEvent) { + log::info!( + "Key {:?} {}", + ke.keysym(), + if ke.is_pressed() { + "pressed" + } else { + "reselased" + } + ); + } + + async fn pointer_event(&self, pe: PointerEvent) { + log::info!("Pointer {:?} {:?}", pe.position, pe.pressed); + } + + async fn cut_text(&self, t: String) { + log::info!("Cut {:?}", t); + } } diff --git a/src/rfb.rs b/src/rfb.rs index 4679c93..7a95bf3 100644 --- a/src/rfb.rs +++ b/src/rfb.rs @@ -224,9 +224,9 @@ impl FramebufferUpdate { } #[derive(Debug, Copy, Clone)] -pub(crate) struct Position { - x: u16, - y: u16, +pub struct Position { + pub x: u16, + pub y: u16, } impl ReadMessage for Position { @@ -242,9 +242,9 @@ impl ReadMessage for Position { } #[derive(Debug, Copy, Clone)] -pub(crate) struct Resolution { - width: u16, - height: u16, +pub struct Resolution { + pub width: u16, + pub height: u16, } impl ReadMessage for Resolution { @@ -271,9 +271,9 @@ impl WriteMessage for Resolution { } pub struct Rectangle { - position: Position, - dimensions: Resolution, - data: Box, + pub position: Position, + pub dimensions: Resolution, + pub data: Box, } impl Rectangle { @@ -650,9 +650,9 @@ impl ReadMessage for ClientMessage { #[derive(Debug)] #[allow(dead_code)] pub struct FramebufferUpdateRequest { - incremental: bool, - position: Position, - resolution: Resolution, + pub incremental: bool, + pub position: Position, + pub resolution: Resolution, } #[derive(Debug, Copy, Clone)] @@ -677,7 +677,7 @@ impl KeyEvent { } bitflags! { - struct MouseButtons: u8 { + pub struct MouseButtons: u8 { const LEFT = 1 << 0; const MIDDLE = 1 << 1; const RIGHT = 1 << 2; @@ -691,8 +691,8 @@ bitflags! { #[derive(Debug)] #[allow(dead_code)] pub struct PointerEvent { - position: Position, - pressed: MouseButtons, + pub position: Position, + pub pressed: MouseButtons, } impl ReadMessage for PointerEvent { diff --git a/src/server.rs b/src/server.rs index fcfe631..34d75a4 100644 --- a/src/server.rs +++ b/src/server.rs @@ -14,8 +14,9 @@ use tokio::net::{TcpListener, TcpStream}; use tokio::sync::Mutex; use crate::rfb::{ - ClientInit, ClientMessage, FramebufferUpdate, KeyEvent, PixelFormat, ProtoVersion, ReadMessage, - SecurityResult, SecurityType, SecurityTypes, ServerInit, WriteMessage, + ClientInit, ClientMessage, FramebufferUpdate, KeyEvent, PixelFormat, PointerEvent, + ProtoVersion, ReadMessage, SecurityResult, SecurityType, SecurityTypes, ServerInit, + WriteMessage, }; /// Immutable state @@ -47,6 +48,8 @@ pub struct VncServer { pub trait Server: Sync + Send + Clone + 'static { async fn get_framebuffer_update(&self) -> FramebufferUpdate; async fn key_event(&self, _ke: KeyEvent) {} + async fn pointer_event(&self, _pe: PointerEvent) {} + async fn cut_text(&self, _t: String) {} } impl VncServer { @@ -209,9 +212,11 @@ impl VncServer { } ClientMessage::PointerEvent(pe) => { trace!("Rx [{:?}: PointerEvent={:?}", addr, pe); + self.server.pointer_event(pe).await; } ClientMessage::ClientCutText(t) => { trace!("Rx [{:?}: ClientCutText={:?}", addr, t); + self.server.cut_text(t).await; } }, Err(e) => {