Fix, do not restore resolution if it is not changed through the session

Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
dignow
2023-08-13 22:38:37 +08:00
parent 3d49909fc9
commit 0d6356c855
3 changed files with 84 additions and 81 deletions

View File

@@ -1051,13 +1051,15 @@ impl Connection {
..Default::default()
})
.into();
// `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.
#[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()
.map(|name| crate::platform::resolutions(&name))
resolutions: video_service::get_current_display()
.map(|(_, _, d)| crate::platform::resolutions(&d.name()))
.unwrap_or(vec![]),
..Default::default()
})
@@ -1948,7 +1950,8 @@ impl Connection {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
fn change_resolution(&mut self, r: &Resolution) {
if self.keyboard {
if let Ok(name) = video_service::get_current_display_name() {
if let Ok((_, _, display)) = video_service::get_current_display() {
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(
@@ -1959,6 +1962,11 @@ impl Connection {
{
return;
}
video_service::set_last_changed_resolution(
&name,
(display.width() as _, display.height() as _),
(r.width, r.height),
);
if let Err(e) =
crate::platform::change_resolution(&name, r.width as _, r.height as _)
{