From 18ba55056ffea94eef87e7805f1a4d1b04f1443e Mon Sep 17 00:00:00 2001 From: fufesou Date: Mon, 30 May 2022 18:16:04 +0800 Subject: [PATCH] privacy_mode_win_magnifier: fix crash when resolution changed Signed-off-by: fufesou --- libs/scrap/src/dxgi/mag.rs | 40 +++++++++++++++++++++++++++++-------- src/main.rs | 2 +- src/server/video_service.rs | 1 + 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/libs/scrap/src/dxgi/mag.rs b/libs/scrap/src/dxgi/mag.rs index b7cfe9088..3e74e960c 100644 --- a/libs/scrap/src/dxgi/mag.rs +++ b/libs/scrap/src/dxgi/mag.rs @@ -364,6 +364,17 @@ impl CapturerMag { )); } + let x = GetSystemMetrics(SM_XVIRTUALSCREEN); + let y = GetSystemMetrics(SM_YVIRTUALSCREEN); + let w = GetSystemMetrics(SM_CXVIRTUALSCREEN); + let h = GetSystemMetrics(SM_CYVIRTUALSCREEN); + s.rect = RECT { + left: x as _, + top: y as _, + right: (x + w) as _, + bottom: (y + h) as _, + }; + // Create the magnifier control. s.magnifier_window = CreateWindowExA( 0, @@ -487,13 +498,26 @@ impl CapturerMag { let y = GetSystemMetrics(SM_YVIRTUALSCREEN); let w = GetSystemMetrics(SM_CXVIRTUALSCREEN); let h = GetSystemMetrics(SM_CYVIRTUALSCREEN); - - self.rect = RECT { - left: x as _, - top: y as _, - right: (x + w) as _, - bottom: (y + h) as _, - }; + if !(self.rect.left == x as _ + && self.rect.top == y as _ + && self.rect.right == (x + w) as _ + && self.rect.bottom == (y + h) as _) + { + return Err(Error::new( + ErrorKind::Other, + format!( + "Failed Check screen rect ({}, {}, {} , {}) to ({}, {}, {}, {})", + self.rect.left, + self.rect.top, + self.rect.right, + self.rect.bottom, + x, + y, + x + w, + y + h + ), + )); + } if FALSE == SetWindowPos( @@ -623,4 +647,4 @@ mod tests { capture_mag.frame(&mut data).unwrap(); println!("capture data len: {}", data.len()); } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index 86e015c9b..f6156ff30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ // Specify the Windows subsystem to eliminate console window. // Requires Rust 1.18. -#![windows_subsystem = "windows"] +//#![windows_subsystem = "windows"] use hbb_common::log; use librustdesk::*; diff --git a/src/server/video_service.rs b/src/server/video_service.rs index c143b680a..97f3e03cc 100644 --- a/src/server/video_service.rs +++ b/src/server/video_service.rs @@ -269,6 +269,7 @@ fn create_capturer(privacy_mode_id: i32, display: Display) -> ResultType {