fix: win, virtual display, privacy mode (#8537)

Restore display settings.

Only restore by the display registry settings.

Do not change display settings twice when turning off privacy mode.

Only restore the registry values.

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-06-30 00:44:10 +08:00 committed by GitHub
parent 750368af7b
commit bd334769fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -34,7 +34,7 @@ const CONFIG_KEY_REG_RECOVERY: &str = "reg_recovery";
struct Display { struct Display {
dm: DEVMODEW, dm: DEVMODEW,
name: [WCHAR; 32], name: [WCHAR; 32],
primary: bool, _primary: bool,
} }
pub struct PrivacyModeImpl { pub struct PrivacyModeImpl {
@ -135,7 +135,7 @@ impl PrivacyModeImpl {
let display = Display { let display = Display {
dm, dm,
name: dd.DeviceName, name: dd.DeviceName,
primary, _primary: primary,
}; };
let ds = virtual_display_manager::get_cur_device_string(); let ds = virtual_display_manager::get_cur_device_string();
@ -149,40 +149,11 @@ impl PrivacyModeImpl {
} }
} }
fn restore(&mut self) {
Self::restore_displays(&self.displays);
Self::restore_displays(&self.virtual_displays);
allow_err!(Self::commit_change_display(0));
self.restore_plug_out_monitor();
self.displays.clear();
self.virtual_displays.clear();
}
fn restore_plug_out_monitor(&mut self) { fn restore_plug_out_monitor(&mut self) {
let _ = virtual_display_manager::plug_out_monitor_indices(&self.virtual_displays_added); let _ = virtual_display_manager::plug_out_monitor_indices(&self.virtual_displays_added);
self.virtual_displays_added.clear(); self.virtual_displays_added.clear();
} }
fn restore_displays(displays: &[Display]) {
for display in displays {
unsafe {
let mut dm = display.dm.clone();
let flags = if display.primary {
CDS_NORESET | CDS_UPDATEREGISTRY | CDS_SET_PRIMARY
} else {
CDS_NORESET | CDS_UPDATEREGISTRY
};
ChangeDisplaySettingsExW(
display.name.as_ptr(),
&mut dm,
std::ptr::null_mut(),
flags,
std::ptr::null_mut(),
);
}
}
}
fn set_primary_display(&mut self) -> ResultType<()> { fn set_primary_display(&mut self) -> ResultType<()> {
let display = &self.virtual_displays[0]; let display = &self.virtual_displays[0];
@ -433,7 +404,7 @@ impl PrivacyMode for PrivacyModeImpl {
) -> ResultType<()> { ) -> ResultType<()> {
self.check_off_conn_id(conn_id)?; self.check_off_conn_id(conn_id)?;
super::win_input::unhook()?; super::win_input::unhook()?;
self.restore(); self.restore_plug_out_monitor();
restore_reg_connectivity(false); restore_reg_connectivity(false);
if self.conn_id != INVALID_PRIVACY_MODE_CONN_ID { if self.conn_id != INVALID_PRIVACY_MODE_CONN_ID {