fix get mac display scale, find screen from display id (#8401)

This commit is contained in:
21pages 2024-06-18 19:37:15 +08:00 committed by GitHub
parent 2c38648e39
commit 8c39979848
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -109,17 +109,17 @@ extern "C" bool MacCheckAdminAuthorization() {
return Elevate(NULL, NULL);
}
// https://gist.github.com/briankc/025415e25900750f402235dbf1b74e42
extern "C" float BackingScaleFactor(uint32_t display) {
NSScreen* s = [NSScreen mainScreen];
if (s) return [s backingScaleFactor];
/* on my mini mac, display==2, but only 1 screen
display -= 1;
NSArray<NSScreen *> *screens = [NSScreen screens];
if (display >= 0 && display < [screens count]) {
NSScreen* s = [screens objectAtIndex:display];
if (s) return [s backingScaleFactor];
for (NSScreen *screen in screens) {
NSDictionary *deviceDescription = [screen deviceDescription];
NSNumber *screenNumber = [deviceDescription objectForKey:@"NSScreenNumber"];
CGDirectDisplayID screenDisplayID = [screenNumber unsignedIntValue];
if (screenDisplayID == display) {
return [screen backingScaleFactor];
}
}
*/
return 1;
}