From 65883766a0d875fa77380f82520a97601fd3c36f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 1 Aug 2024 16:02:41 +0800 Subject: [PATCH] Display (macOS): don't parse string --- .../displayserver/displayserver_apple.c | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/detection/displayserver/displayserver_apple.c b/src/detection/displayserver/displayserver_apple.c index 15bba56b5..53baf7092 100644 --- a/src/detection/displayserver/displayserver_apple.c +++ b/src/detection/displayserver/displayserver_apple.c @@ -86,21 +86,15 @@ static void detectDisplays(FFDisplayServerResult* ds) ); if (display) { - // Shitty code - uint8_t bitDepth = 0; - FF_CFTYPE_AUTO_RELEASE CFStringRef desc = CFCopyDescription(mode); - CFRange start = CFStringFind(desc, CFSTR("BitsPerSample = "), 0); - if (start.location != kCFNotFound) + // https://stackoverflow.com/a/33519316/9976392 + // Also shitty, but better than parsing `CFCopyDescription(mode)` + CFDictionaryRef dict = (CFDictionaryRef) *((int64_t *)mode + 2); + if (CFGetTypeID(dict) == CFDictionaryGetTypeID()) { - for (CFIndex idx = start.location + start.length; idx < CFStringGetLength(desc); ++idx) - { - UniChar ch = CFStringGetCharacterAtIndex(desc, idx); - if (!ffCharIsDigit((char) ch)) - break; - bitDepth = (uint8_t) (bitDepth * 10 + (ch - '0')); - } + int32_t bitDepth; + ffCfDictGetInt(dict, kCGDisplayBitsPerSample, &bitDepth); + display->bitDepth = (uint8_t) bitDepth; } - display->bitDepth = bitDepth; } CGDisplayModeRelease(mode); }