Merge pull request #6411 from fufesou/fix/displays_order

fix, windows displays' order mismatch the system settings display
This commit is contained in:
RustDesk 2023-11-15 15:39:59 +08:00 committed by GitHub
commit 8d327af0ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -108,15 +108,48 @@ impl Display {
}
pub fn all() -> io::Result<Vec<Display>> {
let tmp = Self::all_().unwrap_or(Default::default());
if tmp.is_empty() {
println!("Display got from gdi");
return Ok(dxgi::Displays::get_from_gdi()
let displays_gdi = dxgi::Displays::get_from_gdi()
.drain(..)
.map(Display)
.collect::<Vec<_>>());
.collect::<Vec<_>>();
let displays_dxgi = Self::all_().unwrap_or(Default::default());
// Return gdi displays if dxgi is not supported
if displays_dxgi.is_empty() {
println!("Display got from gdi");
return Ok(displays_gdi);
}
Ok(tmp)
// Return dxgi displays if length is not equal
if displays_dxgi.len() != displays_gdi.len() {
return Ok(displays_dxgi);
}
// Check if names are equal
let names_gdi = displays_gdi.iter().map(|d| d.name()).collect::<Vec<_>>();
let names_dxgi = displays_dxgi.iter().map(|d| d.name()).collect::<Vec<_>>();
for name in names_gdi.iter() {
if !names_dxgi.contains(name) {
return Ok(displays_dxgi);
}
}
// Reorder displays from dxgi
let mut displays_dxgi = displays_dxgi;
let mut displays_dxgi_ordered = Vec::new();
for name in names_gdi.iter() {
let pos = match displays_dxgi.iter().position(|d| d.name() == *name) {
Some(pos) => pos,
None => {
// unreachable!
0
}
};
displays_dxgi_ordered.push(displays_dxgi.remove(pos));
}
Ok(displays_dxgi_ordered)
}
fn all_() -> io::Result<Vec<Display>> {