debug restore resolutions

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-06-05 19:50:24 +08:00
parent e670989e0f
commit 3c2bf2c154
4 changed files with 23 additions and 13 deletions

View File

@ -263,9 +263,9 @@ pub struct PeerConfig {
#[serde( #[serde(
default, default,
deserialize_with = "deserialize_hashmap_resolutions", deserialize_with = "deserialize_hashmap_resolutions",
skip_serializing_if = "HashMap::is_empty", skip_serializing_if = "HashMap::is_empty"
)] )]
pub custom_resolutions: HashMap<i32, Resolution>, pub custom_resolutions: HashMap<String, Resolution>,
// The other scalar value must before this // The other scalar value must before this
#[serde(default, deserialize_with = "PeerConfig::deserialize_options")] #[serde(default, deserialize_with = "PeerConfig::deserialize_options")]
@ -1509,7 +1509,7 @@ deserialize_default!(deserialize_option_string, Option<String>);
deserialize_default!(deserialize_hashmap_string_string, HashMap<String, String>); deserialize_default!(deserialize_hashmap_string_string, HashMap<String, String>);
deserialize_default!(deserialize_hashmap_string_bool, HashMap<String, bool>); deserialize_default!(deserialize_hashmap_string_bool, HashMap<String, bool>);
deserialize_default!(deserialize_hashmap_string_configoidcprovider, HashMap<String, ConfigOidcProvider>); deserialize_default!(deserialize_hashmap_string_configoidcprovider, HashMap<String, ConfigOidcProvider>);
deserialize_default!(deserialize_hashmap_resolutions, HashMap<i32, Resolution>); deserialize_default!(deserialize_hashmap_resolutions, HashMap<String, Resolution>);
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

View File

@ -1591,12 +1591,13 @@ impl LoginConfigHandler {
pub fn get_custom_resolution(&self, display: i32) -> Option<(i32, i32)> { pub fn get_custom_resolution(&self, display: i32) -> Option<(i32, i32)> {
self.config self.config
.custom_resolutions .custom_resolutions
.get(&display) .get(&display.to_string())
.map(|r| (r.w, r.h)) .map(|r| (r.w, r.h))
} }
#[inline] #[inline]
pub fn set_custom_resolution(&mut self, display: i32, wh: Option<(i32, i32)>) { pub fn set_custom_resolution(&mut self, display: i32, wh: Option<(i32, i32)>) {
let display = display.to_string();
let mut config = self.load_config(); let mut config = self.load_config();
match wh { match wh {
Some((w, h)) => { Some((w, h)) => {

View File

@ -1795,11 +1795,14 @@ impl Connection {
video_service::switch_display(s.display).await; video_service::switch_display(s.display).await;
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[cfg(not(any(target_os = "android", target_os = "ios")))]
if s.width != 0 && s.height != 0 { if s.width != 0 && s.height != 0 {
self.change_resolution(&Resolution { self.change_resolution(
width: s.width, &Resolution {
height: s.height, width: s.width,
..Default::default() height: s.height,
}); ..Default::default()
},
false,
);
} }
} }
Some(misc::Union::ChatMessage(c)) => { Some(misc::Union::ChatMessage(c)) => {
@ -1902,7 +1905,7 @@ impl Connection {
} }
} }
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[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(all(feature = "flutter", feature = "plugin_framework"))]
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[cfg(not(any(target_os = "android", target_os = "ios")))]
Some(misc::Union::PluginRequest(p)) => { Some(misc::Union::PluginRequest(p)) => {
@ -1945,9 +1948,13 @@ impl Connection {
} }
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[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 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"))] #[cfg(all(windows, feature = "virtual_display_driver"))]
if let Some(_ok) = if let Some(_ok) =
crate::virtual_display_manager::change_resolution_if_is_virtual_display( 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 let Some(custom_resolution) = o.custom_resolution.as_ref() {
if Self::alive_conns().len() > 0 { if Self::alive_conns().len() > 0 {
if custom_resolution.width > 0 && custom_resolution.height > 0 { if custom_resolution.width > 0 && custom_resolution.height > 0 {
self.change_resolution(&custom_resolution); self.change_resolution(&custom_resolution, true);
} }
} }
} }

View File

@ -1029,12 +1029,14 @@ pub(super) fn get_current_display_2(mut all: Vec<Display>) -> ResultType<(usize,
return Ok((n, current, all.remove(current))); return Ok((n, current, all.remove(current)));
} }
#[inline]
pub fn get_current_display() -> ResultType<(usize, usize, Display)> { pub fn get_current_display() -> ResultType<(usize, usize, Display)> {
get_current_display_2(try_get_displays()?) get_current_display_2(try_get_displays()?)
} }
// `try_reset_current_display` is needed because `get_displays` may change the current display, // `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. // which may cause the mismatch of current display and the current display name.
#[inline]
pub fn get_current_display_name() -> ResultType<String> { pub fn get_current_display_name() -> ResultType<String> {
Ok(get_current_display_2(try_get_displays()?)?.2.name()) Ok(get_current_display_2(try_get_displays()?)?.2.name())
} }