fix: win, virtual display (#9023)

1. Default resolution 1920x1080.
2. Restore on conn & disconn.

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2024-08-11 19:26:41 +08:00
committed by GitHub
parent ce56be6507
commit 6625aca994
8 changed files with 229 additions and 144 deletions

View File

@@ -1780,6 +1780,54 @@ pub fn try_sync_peer_option(
}
}
pub(super) fn session_update_virtual_display(session: &FlutterSession, index: i32, on: bool) {
let virtual_display_key = "virtual-display";
let displays = session.get_option(virtual_display_key.to_owned());
if !on {
if index == -1 {
if !displays.is_empty() {
session.set_option(virtual_display_key.to_owned(), "".to_owned());
}
} else {
let mut vdisplays = displays.split(',').collect::<Vec<_>>();
let len = vdisplays.len();
if index == 0 {
// 0 means we cann't toggle the virtual display by index.
vdisplays.remove(vdisplays.len() - 1);
} else {
if let Some(i) = vdisplays.iter().position(|&x| x == index.to_string()) {
vdisplays.remove(i);
}
}
if vdisplays.len() != len {
session.set_option(
virtual_display_key.to_owned(),
vdisplays.join(",").to_owned(),
);
}
}
} else {
let mut vdisplays = displays
.split(',')
.map(|x| x.to_string())
.collect::<Vec<_>>();
let len = vdisplays.len();
if index == 0 {
vdisplays.push(index.to_string());
} else {
if !vdisplays.iter().any(|x| *x == index.to_string()) {
vdisplays.push(index.to_string());
}
}
if vdisplays.len() != len {
session.set_option(
virtual_display_key.to_owned(),
vdisplays.join(",").to_owned(),
);
}
}
}
// sessions mod is used to avoid the big lock of sessions' map.
pub mod sessions {
use std::collections::HashSet;