@@ -5,9 +5,10 @@ use core::time::Duration;
55use std:: sync:: Arc ;
66use std:: time:: Instant ;
77
8+ use anyhow:: Context as _;
89use raw_window_handle:: { DisplayHandle , HasDisplayHandle as _} ;
910use tokio:: sync:: mpsc;
10- use tracing:: { debug, error, trace} ;
11+ use tracing:: { debug, error, trace, warn } ;
1112use winit:: application:: ApplicationHandler ;
1213use winit:: dpi:: { LogicalPosition , PhysicalSize } ;
1314use winit:: event:: { self , WindowEvent } ;
@@ -38,7 +39,9 @@ impl App {
3839 // SAFETY: We drop the softbuffer context right before the event loop is stopped, thus making this safe.
3940 // FIXME: This is not a sufficient proof and the API is actually unsound as-is.
4041 let display_handle = unsafe {
41- core:: mem:: transmute :: < DisplayHandle < ' _ > , DisplayHandle < ' static > > ( event_loop. display_handle ( ) . unwrap ( ) )
42+ core:: mem:: transmute :: < DisplayHandle < ' _ > , DisplayHandle < ' static > > (
43+ event_loop. display_handle ( ) . context ( "get display handle" ) ?,
44+ )
4245 } ;
4346 let context = softbuffer:: Context :: new ( display_handle)
4447 . map_err ( |e| anyhow:: anyhow!( "unable to initialize softbuffer context: {e}" ) ) ?;
@@ -65,9 +68,12 @@ impl App {
6568 } ;
6669 let scale_factor = ( window. scale_factor ( ) * 100.0 ) as u32 ;
6770
71+ let width = u16:: try_from ( size. width ) . expect ( "reasonable width" ) ;
72+ let height = u16:: try_from ( size. height ) . expect ( "reasonable height" ) ;
73+
6874 let _ = self . input_event_sender . send ( RdpInputEvent :: Resize {
69- width : u16 :: try_from ( size . width ) . unwrap ( ) ,
70- height : u16 :: try_from ( size . height ) . unwrap ( ) ,
75+ width,
76+ height,
7177 scale_factor,
7278 // TODO: it should be possible to get the physical size here, however winit doesn't make it straightforward.
7379 // FreeRDP does it based on DPI reading grabbed via [`SDL_GetDisplayDPI`](https://wiki.libsdl.org/SDL2/SDL_GetDisplayDPI):
@@ -160,7 +166,14 @@ impl ApplicationHandler<RdpOutputEvent> for App {
160166 // }
161167 WindowEvent :: KeyboardInput { event, .. } => {
162168 if let Some ( scancode) = event. physical_key . to_scancode ( ) {
163- let scancode = ironrdp:: input:: Scancode :: from_u16 ( u16:: try_from ( scancode) . unwrap ( ) ) ;
169+ let scancode = match u16:: try_from ( scancode) {
170+ Ok ( scancode) => scancode,
171+ Err ( _) => {
172+ warn ! ( "Unsupported scancode: `{scancode:#X}`; ignored" ) ;
173+ return ;
174+ }
175+ } ;
176+ let scancode = ironrdp:: input:: Scancode :: from_u16 ( scancode) ;
164177
165178 let operation = match event. state {
166179 event:: ElementState :: Pressed => ironrdp:: input:: Operation :: KeyPressed ( scancode) ,
@@ -325,13 +338,10 @@ impl ApplicationHandler<RdpOutputEvent> for App {
325338 RdpOutputEvent :: Image { buffer, width, height } => {
326339 trace ! ( width = ?width, height = ?height, "Received image with size" ) ;
327340 trace ! ( window_physical_size = ?window. inner_size( ) , "Drawing image to the window with size" ) ;
328- self . buffer_size = ( width, height) ;
341+ self . buffer_size = ( width. get ( ) , height. get ( ) ) ;
329342 self . buffer = buffer;
330343 surface
331- . resize (
332- NonZeroU32 :: new ( u32:: from ( width) ) . unwrap ( ) ,
333- NonZeroU32 :: new ( u32:: from ( height) ) . unwrap ( ) ,
334- )
344+ . resize ( NonZeroU32 :: from ( width) , NonZeroU32 :: from ( height) )
335345 . expect ( "surface resize" ) ;
336346
337347 window. request_redraw ( ) ;
0 commit comments