@@ -34,8 +34,8 @@ use std::sync::{
3434 atomic:: { AtomicBool , Ordering } ,
3535} ;
3636
37- use flume:: Receiver ;
3837use eframe:: egui;
38+ use flume:: Receiver ;
3939
4040use shared:: { log, system:: trigger:: Trigger } ;
4141
@@ -63,10 +63,12 @@ pub(super) struct AppWindow {
6363 pub gui_messages_rx : Receiver < types:: GuiMessage > ,
6464 pub stop : Trigger , // For stopping any ongoing operations
6565 pub screen_size : Option < ( u32 , u32 ) > , // Cached screen size
66+ pub fps_limit : Option < u32 > , // FPS limit for RDP connection, if any
6667 pub catalog : gettext:: Catalog , // For translations
6768}
6869
6970impl AppWindow {
71+ #[ allow( clippy:: too_many_arguments) ]
7072 pub fn new (
7173 processing_events : Arc < AtomicBool > ,
7274 events : Receiver < crate :: RawKey > ,
@@ -75,6 +77,7 @@ impl AppWindow {
7577 catalog : gettext:: Catalog ,
7678 initial_state : Option < types:: AppState > ,
7779 cc : & eframe:: CreationContext < ' _ > ,
80+ fps_limit : Option < u32 > ,
7881 ) -> Self {
7982 processing_events. store ( false , Ordering :: Relaxed ) ; // Initially not processing events
8083 let texture = cc. egui_ctx . load_texture (
@@ -91,6 +94,7 @@ impl AppWindow {
9194 processing_events,
9295 stop,
9396 screen_size : None ,
97+ fps_limit,
9498 catalog,
9599 }
96100 }
@@ -139,11 +143,7 @@ impl AppWindow {
139143 self . app_state = new_state;
140144 }
141145
142- pub fn restore_previous_state (
143- & mut self ,
144- ui : & mut egui:: Ui ,
145- frame : & mut eframe:: Frame ,
146- ) {
146+ pub fn restore_previous_state ( & mut self , ui : & mut egui:: Ui , frame : & mut eframe:: Frame ) {
147147 self . processing_events . store ( false , Ordering :: Relaxed ) ; // Stop processing rdp raw events on event loop
148148 self . app_state = self . prev_app_state . clone ( ) ;
149149 self . prev_app_state = types:: AppState :: default ( ) ;
@@ -160,7 +160,8 @@ impl AppWindow {
160160
161161 pub fn set_visible ( & mut self , ui : & mut egui:: Ui , visible : bool ) {
162162 log:: debug!( "Setting window visibility to {}" , visible) ;
163- ui. ctx ( ) . send_viewport_cmd ( egui:: ViewportCommand :: Minimized ( !visible) ) ;
163+ ui. ctx ( )
164+ . send_viewport_cmd ( egui:: ViewportCommand :: Minimized ( !visible) ) ;
164165 }
165166}
166167
@@ -249,7 +250,9 @@ impl eframe::App for AppWindow {
249250 }
250251 let frame_duration = frame_start. elapsed ( ) ;
251252 // ctx.request_repaint(); // Repaint asap
252- let remaining = std:: time:: Duration :: from_millis ( 16 ) . saturating_sub ( frame_duration) ;
253- ui. ctx ( ) . request_repaint_after ( remaining) ; // Aim for ~60 FPS
253+ let fps_limit = self . fps_limit . unwrap_or ( 60 ) ;
254+ let frame_time = std:: time:: Duration :: from_secs_f32 ( 1.0 / fps_limit as f32 ) ;
255+ let remaining = frame_time. saturating_sub ( frame_duration) ;
256+ ui. ctx ( ) . request_repaint_after ( remaining) ; // Aim for consistent FPS, but allow sleeping if we're ahead of schedule
254257 }
255258}
0 commit comments