better support for win7

This commit is contained in:
rustdesk
2021-05-17 20:46:02 +08:00
parent 7630713534
commit f760e56f79
5 changed files with 101 additions and 28 deletions

View File

@@ -62,13 +62,23 @@ pub struct Display(dxgi::Display);
impl Display {
pub fn primary() -> io::Result<Display> {
match dxgi::Displays::new()?.next() {
Some(inner) => Ok(Display(inner)),
None => Err(NotFound.into()),
}
// not implemented yet
Err(NotFound.into())
}
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()
.drain(..)
.map(Display)
.collect::<Vec<_>>());
}
Ok(tmp)
}
fn all_() -> io::Result<Vec<Display>> {
Ok(dxgi::Displays::new()?.map(Display).collect::<Vec<_>>())
}
@@ -92,13 +102,12 @@ impl Display {
self.0.is_online()
}
pub fn origin(&self) -> (usize, usize) {
let o = self.0.origin();
(o.0 as usize, o.1 as usize)
pub fn origin(&self) -> (i32, i32) {
self.0.origin()
}
// to-do: not found primary display api for dxgi
pub fn is_primary(&self) -> bool {
self.name() == Self::primary().unwrap().name()
// https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-devmodea
self.origin() == (0, 0)
}
}

View File

@@ -114,9 +114,9 @@ impl Display {
self.0.is_online()
}
pub fn origin(&self) -> (usize, usize) {
pub fn origin(&self) -> (i32, i32) {
let o = self.0.bounds().origin;
(o.x as usize, o.y as usize)
(o.x as _, o.y as _)
}
pub fn is_primary(&self) -> bool {

View File

@@ -68,7 +68,7 @@ impl Display {
self.0.rect().h as usize
}
pub fn origin(&self) -> (usize, usize) {
pub fn origin(&self) -> (i32, i32) {
let r = self.0.rect();
(r.x as _, r.y as _)
}