Merge pull request #6394 from rustdesk/revert-6379-fix/the_displays_order

Revert "Fix, windows display orders"
This commit is contained in:
RustDesk 2023-11-13 17:32:10 +08:00 committed by GitHub
commit 5a6a773583
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 26 additions and 55 deletions

View File

@ -111,23 +111,16 @@ impl Display {
let tmp = Self::all_().unwrap_or(Default::default());
if tmp.is_empty() {
println!("Display got from gdi");
return Ok(Self::displays_from_dxgi_displays(
dxgi::Displays::get_from_gdi().drain(..),
));
return Ok(dxgi::Displays::get_from_gdi()
.drain(..)
.map(Display)
.collect::<Vec<_>>());
}
Ok(tmp)
}
#[inline]
pub fn displays_from_dxgi_displays<I>(displays: I) -> Vec<Display>
where
I: Iterator<Item = dxgi::Display>,
{
displays.map(Display).collect::<Vec<_>>()
}
fn all_() -> io::Result<Vec<Display>> {
Ok(Self::displays_from_dxgi_displays(dxgi::Displays::new()?))
Ok(dxgi::Displays::new()?.map(Display).collect::<Vec<_>>())
}
pub fn width(&self) -> usize {

View File

@ -1098,7 +1098,7 @@ pub fn main_get_main_display() -> SyncReturn<String> {
#[cfg(not(target_os = "ios"))]
let mut display_info = "".to_owned();
#[cfg(not(target_os = "ios"))]
if let Ok(displays) = crate::display_service::try_get_displays(false) {
if let Ok(displays) = crate::display_service::try_get_displays() {
// to-do: Need to detect current display index.
if let Some(display) = displays.iter().next() {
display_info = serde_json::to_string(&HashMap::from([
@ -1117,7 +1117,7 @@ pub fn main_get_displays() -> SyncReturn<String> {
#[cfg(not(target_os = "ios"))]
let mut display_info = "".to_owned();
#[cfg(not(target_os = "ios"))]
if let Ok(displays) = crate::display_service::try_get_displays(false) {
if let Ok(displays) = crate::display_service::try_get_displays() {
let displays = displays
.iter()
.map(|d| {

View File

@ -1165,7 +1165,7 @@ impl Connection {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
{
pi.resolutions = Some(SupportedResolutions {
resolutions: display_service::try_get_displays(true)
resolutions: display_service::try_get_displays()
.map(|displays| {
displays
.get(self.display_idx)
@ -2369,7 +2369,7 @@ impl Connection {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
fn change_resolution(&mut self, r: &Resolution) {
if self.keyboard {
if let Ok(displays) = display_service::try_get_displays(true) {
if let Ok(displays) = display_service::try_get_displays() {
if let Some(display) = displays.get(self.display_idx) {
let name = display.name();
#[cfg(all(windows, feature = "virtual_display_driver"))]

View File

@ -180,7 +180,7 @@ fn displays_to_msg(displays: Vec<DisplayInfo>) -> Message {
}
fn check_get_displays_changed_msg() -> Option<Message> {
check_update_displays(&try_get_displays(true).ok()?);
check_update_displays(&try_get_displays().ok()?);
let displays = SYNC_DISPLAYS.lock().unwrap().get_update_sync_displays()?;
Some(displays_to_msg(displays))
}
@ -292,7 +292,7 @@ pub async fn update_get_sync_displays() -> ResultType<Vec<DisplayInfo>> {
return super::wayland::get_displays().await;
}
}
check_update_displays(&try_get_displays(true)?);
check_update_displays(&try_get_displays()?);
Ok(SYNC_DISPLAYS.lock().unwrap().displays.clone())
}
@ -308,9 +308,7 @@ pub fn get_primary() -> usize {
}
}
try_get_displays(false)
.map(|d| get_primary_2(&d))
.unwrap_or(0)
try_get_displays().map(|d| get_primary_2(&d)).unwrap_or(0)
}
#[inline]
@ -345,41 +343,20 @@ fn no_displays(displays: &Vec<Display>) -> bool {
#[inline]
#[cfg(not(all(windows, feature = "virtual_display_driver")))]
pub fn try_get_displays(_order: bool) -> ResultType<Vec<Display>> {
Ok(get_displays(_order)?)
pub fn try_get_displays() -> ResultType<Vec<Display>> {
Ok(Display::all()?)
}
#[cfg(all(windows, feature = "virtual_display_driver"))]
pub fn try_get_displays(order: bool) -> ResultType<Vec<Display>> {
let mut displays = get_displays(order)?;
pub fn try_get_displays() -> ResultType<Vec<Display>> {
let mut displays = Display::all()?;
if crate::platform::is_installed() && no_displays(&displays) {
log::debug!("no displays, create virtual display");
if let Err(e) = virtual_display_manager::plug_in_headless() {
log::error!("plug in headless failed {}", e);
} else {
displays = get_displays(order)?;
displays = Display::all()?;
}
}
Ok(displays)
}
// Note: Do not use `Display::all()` to get displays.
// Use `get_displays()` instead.
#[cfg(not(windows))]
pub fn get_displays(_order: bool) -> ResultType<Vec<Display>> {
Ok(Display::all()?)
}
// get_from_gdi() returns the displays in the same order of the windows display settings.
// dxgi does not guarantee the order of displays.
#[cfg(windows)]
pub fn get_displays(order: bool) -> ResultType<Vec<Display>> {
if !order {
Ok(Display::all()?)
} else {
Ok(Display::displays_from_dxgi_displays(
scrap::dxgi::Displays::get_from_gdi().drain(..),
))
}
}

View File

@ -317,7 +317,7 @@ pub mod server {
let current_display = (*para).current_display;
let timeout_ms = (*para).timeout_ms;
if c.is_none() {
let Ok(mut displays) = display_service::try_get_displays(true) else {
let Ok(mut displays) = display_service::try_get_displays() else {
log::error!("Failed to get displays");
*EXIT.lock().unwrap() = true;
return;
@ -534,7 +534,7 @@ pub mod client {
bail!("already running");
}
if SHMEM.lock().unwrap().is_none() {
let displays = crate::display_service::get_displays(false)?;
let displays = scrap::Display::all()?;
if displays.is_empty() {
bail!("no display available!");
}
@ -655,7 +655,7 @@ pub mod client {
shmem.write(ADDR_CAPTURE_WOULDBLOCK, &utils::i32_to_vec(TRUE));
}
let (mut width, mut height) = (0, 0);
if let Ok(displays) = display_service::try_get_displays(true) {
if let Ok(displays) = display_service::try_get_displays() {
if let Some(display) = displays.get(current_display) {
width = display.width();
height = display.height();

View File

@ -249,7 +249,7 @@ pub fn test_create_capturer(
) -> String {
let test_begin = Instant::now();
loop {
let err = match super::display_service::get_displays(true) {
let err = match Display::all() {
Ok(mut displays) => {
if displays.len() <= display_idx {
anyhow!(
@ -322,7 +322,7 @@ fn get_capturer(current: usize, portable_service_running: bool) -> ResultType<Ca
}
}
let mut displays = super::display_service::get_displays(true)?;
let mut displays = Display::all()?;
let ndisplay = displays.len();
if ndisplay <= current {
bail!(

View File

@ -1,6 +1,6 @@
use super::*;
use hbb_common::{allow_err, platform::linux::DISTRO};
use scrap::{is_cursor_embedded, set_map_err, Capturer, Frame, TraitCapturer};
use scrap::{is_cursor_embedded, set_map_err, Capturer, Display, Frame, TraitCapturer};
use std::io;
use std::process::{Command, Output};
@ -139,7 +139,7 @@ pub(super) async fn check_init() -> ResultType<()> {
if *CAP_DISPLAY_INFO.read().unwrap() == 0 {
let mut lock = CAP_DISPLAY_INFO.write().unwrap();
if *lock == 0 {
let mut all = super::display_service::get_displays(true)?;
let mut all = Display::all()?;
let num = all.len();
let primary = super::display_service::get_primary_2(&all);
let current = primary;
@ -186,7 +186,8 @@ pub(super) async fn check_init() -> ResultType<()> {
maxy = max_height;
let capturer = Box::into_raw(Box::new(
Capturer::new(display).with_context(|| "Failed to create capturer")?,
Capturer::new(display)
.with_context(|| "Failed to create capturer")?,
));
let capturer = CapturerPtr(capturer);
let cap_display_info = Box::into_raw(Box::new(CapDisplayInfo {