Merge pull request #4560 from fufesou/refact/virtual_display_dummy_display
Refact/virtual display dummy display
This commit is contained in:
commit
94536c6dea
@ -639,6 +639,10 @@ impl Connection {
|
||||
if active_conns_lock.is_empty() {
|
||||
video_service::reset_resolutions();
|
||||
}
|
||||
#[cfg(all(windows, feature = "virtual_display_driver"))]
|
||||
if active_conns_lock.is_empty() {
|
||||
video_service::try_plug_out_virtual_display();
|
||||
}
|
||||
log::info!("#{} connection loop exited", id);
|
||||
}
|
||||
|
||||
|
@ -340,16 +340,6 @@ fn create_capturer(
|
||||
};
|
||||
}
|
||||
|
||||
// to-do: do not close if in privacy mode.
|
||||
#[cfg(all(windows, feature = "virtual_display_driver"))]
|
||||
fn ensure_close_virtual_device() -> ResultType<()> {
|
||||
let num_displays = Display::all()?.len();
|
||||
if num_displays > 1 {
|
||||
let _res = virtual_display_manager::plug_out_headless();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// This function works on privacy mode. Windows only for now.
|
||||
pub fn test_create_capturer(privacy_mode_id: i32, timeout_millis: u64) -> bool {
|
||||
let test_begin = Instant::now();
|
||||
@ -505,11 +495,14 @@ fn check_get_displays_changed_msg() -> Option<Message> {
|
||||
Some(msg_out)
|
||||
}
|
||||
|
||||
#[cfg(all(windows, feature = "virtual_display_driver"))]
|
||||
pub fn try_plug_out_virtual_display() {
|
||||
let _res = virtual_display_manager::plug_out_headless();
|
||||
}
|
||||
|
||||
fn run(sp: GenericService) -> ResultType<()> {
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
let _wake_lock = get_wake_lock();
|
||||
#[cfg(all(windows, feature = "virtual_display_driver"))]
|
||||
ensure_close_virtual_device()?;
|
||||
|
||||
// ensure_inited() is needed because release_resource() may be called.
|
||||
#[cfg(target_os = "linux")]
|
||||
@ -993,21 +986,38 @@ fn try_get_displays() -> ResultType<Vec<Display>> {
|
||||
Ok(Display::all()?)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(windows)]
|
||||
fn no_displays(displays: &Vec<Display>) -> bool {
|
||||
let display_len = displays.len();
|
||||
if display_len == 0 {
|
||||
true
|
||||
} else if display_len == 1 {
|
||||
let display = &displays[0];
|
||||
let dummy_display_side_max_size = 800;
|
||||
display.width() <= dummy_display_side_max_size
|
||||
&& display.height() <= dummy_display_side_max_size
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(not(windows))]
|
||||
fn no_displays(displays: &Vec<Display>) -> bool {
|
||||
displays.is_empty()
|
||||
}
|
||||
|
||||
#[cfg(all(windows, feature = "virtual_display_driver"))]
|
||||
fn try_get_displays() -> ResultType<Vec<Display>> {
|
||||
let mut displays = Display::all()?;
|
||||
if displays.len() == 0 {
|
||||
if 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 = Display::all()?;
|
||||
}
|
||||
} else if displays.len() > 1 {
|
||||
// If more than one displays exists, close RustDeskVirtualDisplay
|
||||
if virtual_display_manager::plug_out_headless() {
|
||||
displays = Display::all()?;
|
||||
}
|
||||
}
|
||||
Ok(displays)
|
||||
}
|
||||
|
@ -110,12 +110,6 @@ pub fn get_license() -> String {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn get_option_opt(key: &str) -> Option<String> {
|
||||
OPTIONS.lock().unwrap().get(key).map(|x| x.clone())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_option(key: String) -> String {
|
||||
get_option_(&key)
|
||||
|
@ -911,16 +911,16 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
pub fn change_resolution(&self, display: i32, width: i32, height: i32) {
|
||||
*self.last_change_display.lock().unwrap() =
|
||||
ChangeDisplayRecord::new(display, width, height);
|
||||
self.do_change_resolution(display, width, height);
|
||||
self.do_change_resolution(width, height);
|
||||
}
|
||||
|
||||
fn try_change_init_resolution(&self, display: i32) {
|
||||
if let Some((w, h)) = self.lc.read().unwrap().get_custom_resolution(display) {
|
||||
self.do_change_resolution(display, w, h);
|
||||
self.do_change_resolution(w, h);
|
||||
}
|
||||
}
|
||||
|
||||
fn do_change_resolution(&self, display: i32, width: i32, height: i32) {
|
||||
fn do_change_resolution(&self, width: i32, height: i32) {
|
||||
let mut misc = Misc::new();
|
||||
misc.set_change_resolution(Resolution {
|
||||
width,
|
||||
|
Loading…
x
Reference in New Issue
Block a user