fix: macos, hidpi, resolutions (#11825)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2025-05-21 16:53:02 +08:00
committed by GitHub
parent b4a30cac73
commit 06ab987e32
5 changed files with 90 additions and 24 deletions

View File

@@ -3093,10 +3093,18 @@ impl Connection {
if virtual_display_manager::amyuni_idd::is_my_display(&name) {
record_changed = false;
}
#[cfg(not(target_os = "macos"))]
let scale = 1.0;
#[cfg(target_os = "macos")]
let scale = display.scale();
let original = (
((display.width() as f64) / scale).round() as _,
(display.height() as f64 / scale).round() as _,
);
if record_changed {
display_service::set_last_changed_resolution(
&name,
(display.width() as _, display.height() as _),
original,
(r.width, r.height),
);
}
@@ -4424,7 +4432,7 @@ mod raii {
*WALLPAPER_REMOVER.lock().unwrap() = None;
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
display_service::reset_resolutions();
display_service::restore_resolutions();
#[cfg(windows)]
let _ = virtual_display_manager::reset_all();
#[cfg(target_os = "linux")]

View File

@@ -133,12 +133,13 @@ pub fn set_last_changed_resolution(display_name: &str, original: (i32, i32), cha
#[inline]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn reset_resolutions() {
pub fn restore_resolutions() {
for (name, res) in CHANGED_RESOLUTIONS.read().unwrap().iter() {
let (w, h) = res.original;
log::info!("Restore resolution of display '{}' to ({}, {})", name, w, h);
if let Err(e) = crate::platform::change_resolution(name, w as _, h as _) {
log::error!(
"Failed to reset resolution of display '{}' to ({},{}): {}",
"Failed to restore resolution of display '{}' to ({},{}): {}",
name,
w,
h,
@@ -146,7 +147,7 @@ pub fn reset_resolutions() {
);
}
}
// Can be cleared because reset resolutions is called when there is no client connected.
// Can be cleared because restore resolutions is called when there is no client connected.
CHANGED_RESOLUTIONS.write().unwrap().clear();
}
@@ -404,7 +405,6 @@ fn no_displays(displays: &Vec<Display>) -> bool {
}
}
#[inline]
#[cfg(not(windows))]
pub fn try_get_displays() -> ResultType<Vec<Display>> {