diff --git a/src/server/connection.rs b/src/server/connection.rs index db594fbcd..1b005ea5e 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -2142,6 +2142,12 @@ impl Connection { }); } } + + // Send display changed message. + // For compatibility with old versions ( < 1.2.4 ). + if let Some(msg_out) = video_service::make_display_changed_msg(self.display_idx, None) { + self.send(msg_out).await; + } } } diff --git a/src/server/display_service.rs b/src/server/display_service.rs index eb9b4272b..d1d14f0f9 100644 --- a/src/server/display_service.rs +++ b/src/server/display_service.rs @@ -242,6 +242,10 @@ pub(super) fn get_sync_displays() -> Vec { SYNC_DISPLAYS.lock().unwrap().displays.clone() } +pub(super) fn get_display_info(idx: usize) -> Option { + SYNC_DISPLAYS.lock().unwrap().displays.get(idx).cloned() +} + // Display to DisplayInfo // The DisplayInfo is be sent to the peer. pub(super) fn check_update_displays(all: &Vec) { diff --git a/src/server/video_service.rs b/src/server/video_service.rs index 664ca6628..0e1c3cb23 100644 --- a/src/server/video_service.rs +++ b/src/server/video_service.rs @@ -20,7 +20,12 @@ #[cfg(target_os = "linux")] use super::display_service::IS_X11; -use super::{display_service::check_display_changed, service::ServiceTmpl, video_qos::VideoQoS, *}; +use super::{ + display_service::{check_display_changed, get_display_info}, + service::ServiceTmpl, + video_qos::VideoQoS, + *, +}; #[cfg(target_os = "linux")] use crate::common::SimpleCallOnReturn; #[cfg(windows)] @@ -511,7 +516,7 @@ fn run(vs: VideoService) -> ResultType<()> { (c.origin.0, c.origin.1, c.width, c.height), ) { log::info!("Display {} changed", display); - broadcast_display_changed(display_idx, &sp, &c.name, display); + broadcast_display_changed(display_idx, &sp, display); bail!("SWITCH"); } } @@ -596,7 +601,7 @@ fn run(vs: VideoService) -> ResultType<()> { (c.origin.0, c.origin.1, c.width, c.height), ) { log::info!("Display {} changed", display); - broadcast_display_changed(display_idx, &sp, &c.name, display); + broadcast_display_changed(display_idx, &sp, display); bail!("SWITCH"); } @@ -853,22 +858,20 @@ fn get_wake_lock() -> crate::platform::WakeLock { } #[inline] -fn broadcast_display_changed( - display_idx: usize, - sp: &GenericService, - name: &str, - display: DisplayInfo, -) { - if let Some(msg_out) = make_display_changed_msg(display_idx, name, display) { +fn broadcast_display_changed(display_idx: usize, sp: &GenericService, display: DisplayInfo) { + if let Some(msg_out) = make_display_changed_msg(display_idx, Some(display)) { sp.send(msg_out); } } -fn make_display_changed_msg( +pub fn make_display_changed_msg( display_idx: usize, - name: &str, - display: DisplayInfo, + opt_display: Option, ) -> Option { + let display = match opt_display { + Some(d) => d, + None => get_display_info(display_idx)?, + }; let mut misc = Misc::new(); misc.set_switch_display(SwitchDisplay { display: display_idx as _, @@ -879,10 +882,10 @@ fn make_display_changed_msg( cursor_embedded: display_service::capture_cursor_embedded(), #[cfg(not(any(target_os = "android", target_os = "ios")))] resolutions: Some(SupportedResolutions { - resolutions: if name.is_empty() { + resolutions: if display.name.is_empty() { vec![] } else { - crate::platform::resolutions(name) + crate::platform::resolutions(&display.name) }, ..SupportedResolutions::default() })