diff --git a/src/server/connection.rs b/src/server/connection.rs index d1da5c079..200a6dfb5 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -1043,6 +1043,8 @@ impl Connection { }) .into(); #[cfg(not(any(target_os = "android", target_os = "ios")))] + video_service::try_reset_current_display(); + #[cfg(not(any(target_os = "android", target_os = "ios")))] { pi.resolutions = Some(SupportedResolutions { resolutions: video_service::get_current_display_name() diff --git a/src/server/video_service.rs b/src/server/video_service.rs index 5a63a60a6..747fff73e 100644 --- a/src/server/video_service.rs +++ b/src/server/video_service.rs @@ -561,11 +561,6 @@ fn run(sp: GenericService) -> ResultType<()> { log::debug!("Broadcasting display switch"); let mut misc = Misc::new(); let display_name = get_current_display_name().unwrap_or_default(); - println!( - "REMOVE ME ============================ display_name: {:?}, is_virtual: {}", - display_name, - is_virtual_display(&display_name) - ); let original_resolution = get_original_resolution(&display_name, c.width, c.height); misc.set_switch_display(SwitchDisplay { display: c.current as _, @@ -967,6 +962,15 @@ pub fn is_inited_msg() -> Option { None } +// switch to primary display if long time (30 seconds) no users +#[inline] +pub fn try_reset_current_display() { + if LAST_ACTIVE.lock().unwrap().elapsed().as_secs() >= 30 { + *CURRENT_DISPLAY.lock().unwrap() = usize::MAX; + } + *LAST_ACTIVE.lock().unwrap() = time::Instant::now(); +} + pub async fn get_displays() -> ResultType<(usize, Vec)> { #[cfg(target_os = "linux")] { @@ -974,10 +978,6 @@ pub async fn get_displays() -> ResultType<(usize, Vec)> { return super::wayland::get_displays().await; } } - // switch to primary display if long time (30 seconds) no users - if LAST_ACTIVE.lock().unwrap().elapsed().as_secs() >= 30 { - *CURRENT_DISPLAY.lock().unwrap() = usize::MAX; - } Ok(get_displays_2(&try_get_displays()?)) } @@ -1071,6 +1071,8 @@ pub fn get_current_display() -> ResultType<(usize, usize, Display)> { get_current_display_2(try_get_displays()?) } +// `try_reset_current_display` is needed because `get_displays` may change the current display, +// which may cause the mismatch of current display and the current display name. pub fn get_current_display_name() -> ResultType { Ok(get_current_display_2(try_get_displays()?)?.2.name()) }