Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

fix: mstsc switch, plug in virtual displays (#7913)

fufesou846522037f3f
diff --git a/src/server/connection.rs b/src/server/connection.rs
index f5330b323..6bf9602e0 100644
--- a/src/server/connection.rs
+++ b/src/server/connection.rs
@@ -1231,8 +1231,12 @@ impl Connection {
} else {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
{
+ #[cfg(not(all(windows, feature = "virtual_display_driver")))]
+ let displays = display_service::try_get_displays();
+ #[cfg(all(windows, feature = "virtual_display_driver"))]
+ let displays = display_service::try_get_displays_add_amyuni_headless();
pi.resolutions = Some(SupportedResolutions {
- resolutions: display_service::try_get_displays()
+ resolutions: displays
.map(|displays| {
displays
.get(self.display_idx)
diff --git a/src/server/display_service.rs b/src/server/display_service.rs
index d3caa1362..386371c12 100644
--- a/src/server/display_service.rs
+++ b/src/server/display_service.rs
@@ -372,15 +372,47 @@ pub fn try_get_displays() -> ResultType<Vec<Display>> {
Ok(Display::all()?)
}
+#[inline]
#[cfg(all(windows, feature = "virtual_display_driver"))]
pub fn try_get_displays() -> ResultType<Vec<Display>> {
+ try_get_displays_(false)
+}
+
+// We can't get full control of the virtual display if we use amyuni idd.
+// If we add a virtual display, we cannot remove it automatically.
+// So when using amyuni idd, we only add a virtual display for headless if it is required.
+// eg. when the client is connecting.
+#[inline]
+#[cfg(all(windows, feature = "virtual_display_driver"))]
+pub fn try_get_displays_add_amyuni_headless() -> ResultType<Vec<Display>> {
+ try_get_displays_(true)
+}
+
+#[inline]
+#[cfg(all(windows, feature = "virtual_display_driver"))]
+pub fn try_get_displays_(add_amyuni_headless: bool) -> ResultType<Vec<Display>> {
let mut displays = Display::all()?;
+
+ // Do not add virtual display if the platform is not installed or the virtual display is not supported.
+ if !crate::platform::is_installed() || !virtual_display_manager::is_virtual_display_supported() {
+ return Ok(displays);
+ }
+
+ // Enable headless virtual display when
+ // 1. `amyuni` idd is not used.
+ // 2. `amyuni` idd is used and `add_amyuni_headless` is true.
+ if virtual_display_manager::is_amyuni_idd() && !add_amyuni_headless {
+ return Ok(displays);
+ }
+
+ // If is switching session, no displays may be detected. But it is not a real case.
+ if displays.is_empty() && crate::platform::desktop_changed() {
+ return Ok(displays);
+ }
+
let no_displays_v = no_displays(&displays);
virtual_display_manager::set_can_plug_out_all(!no_displays_v);
- if crate::platform::is_installed()
- && no_displays_v
- && virtual_display_manager::is_virtual_display_supported()
- {
+ if no_displays_v {
log::debug!("no displays, create virtual display");
if let Err(e) = virtual_display_manager::plug_in_headless() {
log::error!("plug in headless failed {}", e);