From 3c2bf2c1547bb3b6f056809a9fc38c9e7ed280c9 Mon Sep 17 00:00:00 2001 From: fufesou Date: Mon, 5 Jun 2023 19:50:24 +0800 Subject: [PATCH] debug restore resolutions Signed-off-by: fufesou --- libs/hbb_common/src/config.rs | 6 +++--- src/client.rs | 3 ++- src/server/connection.rs | 25 ++++++++++++++++--------- src/server/video_service.rs | 2 ++ 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/libs/hbb_common/src/config.rs b/libs/hbb_common/src/config.rs index 6a137f4ca..0bb6dfdaa 100644 --- a/libs/hbb_common/src/config.rs +++ b/libs/hbb_common/src/config.rs @@ -263,9 +263,9 @@ pub struct PeerConfig { #[serde( default, deserialize_with = "deserialize_hashmap_resolutions", - skip_serializing_if = "HashMap::is_empty", + skip_serializing_if = "HashMap::is_empty" )] - pub custom_resolutions: HashMap, + pub custom_resolutions: HashMap, // The other scalar value must before this #[serde(default, deserialize_with = "PeerConfig::deserialize_options")] @@ -1509,7 +1509,7 @@ deserialize_default!(deserialize_option_string, Option); deserialize_default!(deserialize_hashmap_string_string, HashMap); deserialize_default!(deserialize_hashmap_string_bool, HashMap); deserialize_default!(deserialize_hashmap_string_configoidcprovider, HashMap); -deserialize_default!(deserialize_hashmap_resolutions, HashMap); +deserialize_default!(deserialize_hashmap_resolutions, HashMap); #[cfg(test)] mod tests { diff --git a/src/client.rs b/src/client.rs index 9ab01682c..8402752c5 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1591,12 +1591,13 @@ impl LoginConfigHandler { pub fn get_custom_resolution(&self, display: i32) -> Option<(i32, i32)> { self.config .custom_resolutions - .get(&display) + .get(&display.to_string()) .map(|r| (r.w, r.h)) } #[inline] pub fn set_custom_resolution(&mut self, display: i32, wh: Option<(i32, i32)>) { + let display = display.to_string(); let mut config = self.load_config(); match wh { Some((w, h)) => { diff --git a/src/server/connection.rs b/src/server/connection.rs index 3bf485e45..28fcfef75 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -1795,11 +1795,14 @@ impl Connection { video_service::switch_display(s.display).await; #[cfg(not(any(target_os = "android", target_os = "ios")))] if s.width != 0 && s.height != 0 { - self.change_resolution(&Resolution { - width: s.width, - height: s.height, - ..Default::default() - }); + self.change_resolution( + &Resolution { + width: s.width, + height: s.height, + ..Default::default() + }, + false, + ); } } Some(misc::Union::ChatMessage(c)) => { @@ -1902,7 +1905,7 @@ impl Connection { } } #[cfg(not(any(target_os = "android", target_os = "ios")))] - Some(misc::Union::ChangeResolution(r)) => self.change_resolution(&r), + Some(misc::Union::ChangeResolution(r)) => self.change_resolution(&r, false), #[cfg(all(feature = "flutter", feature = "plugin_framework"))] #[cfg(not(any(target_os = "android", target_os = "ios")))] Some(misc::Union::PluginRequest(p)) => { @@ -1945,9 +1948,13 @@ impl Connection { } #[cfg(not(any(target_os = "android", target_os = "ios")))] - fn change_resolution(&mut self, r: &Resolution) { + fn change_resolution(&mut self, r: &Resolution, first_display: bool) { if self.keyboard { - if let Ok(name) = video_service::get_current_display_name() { + if let Ok((_, current, display)) = video_service::get_current_display() { + if first_display && current != 0 { + return; + } + let name = display.name(); #[cfg(all(windows, feature = "virtual_display_driver"))] if let Some(_ok) = crate::virtual_display_manager::change_resolution_if_is_virtual_display( @@ -2173,7 +2180,7 @@ impl Connection { if let Some(custom_resolution) = o.custom_resolution.as_ref() { if Self::alive_conns().len() > 0 { if custom_resolution.width > 0 && custom_resolution.height > 0 { - self.change_resolution(&custom_resolution); + self.change_resolution(&custom_resolution, true); } } } diff --git a/src/server/video_service.rs b/src/server/video_service.rs index 22ad83001..def926da5 100644 --- a/src/server/video_service.rs +++ b/src/server/video_service.rs @@ -1029,12 +1029,14 @@ pub(super) fn get_current_display_2(mut all: Vec) -> ResultType<(usize, return Ok((n, current, all.remove(current))); } +#[inline] 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. +#[inline] pub fn get_current_display_name() -> ResultType { Ok(get_current_display_2(try_get_displays()?)?.2.name()) }