@@ -84,10 +84,12 @@ pub fn insert_in_monitor_cache(serial_or_device_id: &str, monitor: Monitor) {
8484 monitor_cache. insert ( preferred_id, monitor) ;
8585}
8686
87- pub fn attached_display_devices ( ) -> color_eyre:: Result < Vec < Monitor > > {
88- let all_displays = win32_display_data:: connected_displays_all ( )
89- . flatten ( )
90- . collect :: < Vec < _ > > ( ) ;
87+ pub fn attached_display_devices < F , I > ( display_provider : F ) -> color_eyre:: Result < Vec < Monitor > >
88+ where
89+ F : Fn ( ) -> I + Copy ,
90+ I : Iterator < Item = Result < win32_display_data:: Device , win32_display_data:: Error > > ,
91+ {
92+ let all_displays = display_provider ( ) . flatten ( ) . collect :: < Vec < _ > > ( ) ;
9193
9294 let mut serial_id_map = HashMap :: new ( ) ;
9395
@@ -154,7 +156,7 @@ pub fn listen_for_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Re
154156 tracing:: info!( "created hidden window to listen for monitor-related events" ) ;
155157
156158 std:: thread:: spawn ( move || loop {
157- match handle_notifications ( wm. clone ( ) ) {
159+ match handle_notifications ( wm. clone ( ) , win32_display_data :: connected_displays_all ) {
158160 Ok ( ( ) ) => {
159161 tracing:: warn!( "restarting finished thread" ) ;
160162 }
@@ -171,7 +173,14 @@ pub fn listen_for_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Re
171173 Ok ( ( ) )
172174}
173175
174- pub fn handle_notifications ( wm : Arc < Mutex < WindowManager > > ) -> color_eyre:: Result < ( ) > {
176+ pub fn handle_notifications < F , I > (
177+ wm : Arc < Mutex < WindowManager > > ,
178+ display_provider : F ,
179+ ) -> color_eyre:: Result < ( ) >
180+ where
181+ F : Fn ( ) -> I + Copy ,
182+ I : Iterator < Item = Result < win32_display_data:: Device , win32_display_data:: Error > > ,
183+ {
175184 tracing:: info!( "listening" ) ;
176185
177186 let receiver = event_rx ( ) ;
@@ -296,7 +305,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
296305 let initial_monitor_count = wm. monitors ( ) . len ( ) ;
297306
298307 // Get the currently attached display devices
299- let attached_devices = attached_display_devices ( ) ?;
308+ let attached_devices = attached_display_devices ( display_provider ) ?;
300309
301310 // Make sure that in our state any attached displays have the latest Win32 data
302311 for monitor in wm. monitors_mut ( ) {
0 commit comments