mac scale factor of each screen (#8368)

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages 2024-06-16 12:01:41 +08:00 committed by GitHub
parent 12ff1319f1
commit 60ea8d2c2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 5 deletions

View File

@ -71,7 +71,7 @@ impl Display {
}
pub fn scale(self) -> f64 {
let s = unsafe { BackingScaleFactor() as _ };
let s = unsafe { BackingScaleFactor(self.0) as _ };
if s > 1. {
let enable_retina = super::ENABLE_RETINA.lock().unwrap().clone();
if enable_retina {

View File

@ -193,7 +193,7 @@ extern "C" {
pub fn CGDisplayIsOnline(display: u32) -> i32;
pub fn CGDisplayBounds(display: u32) -> CGRect;
pub fn BackingScaleFactor() -> f32;
pub fn BackingScaleFactor(display: u32) -> f32;
// IOSurface

View File

@ -109,9 +109,13 @@ extern "C" bool MacCheckAdminAuthorization() {
return Elevate(NULL, NULL);
}
extern "C" float BackingScaleFactor() {
NSScreen* s = [NSScreen mainScreen];
if (s) return [s backingScaleFactor];
extern "C" float BackingScaleFactor(uint32_t display) {
display -= 1;
NSArray<NSScreen *> *screens = [NSScreen screens];
if (display >= 0 && display < [screens count]) {
NSScreen* s = [screens objectAtIndex:display];
if (s) return [s backingScaleFactor];
}
return 1;
}