From f11b07ba8a39b5ccddf3498242695ef96ec1d5d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 18 Jul 2024 16:41:31 +0800 Subject: [PATCH] DisplayServer (macOS): detect bit depth --- .../displayserver/displayserver_apple.c | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/detection/displayserver/displayserver_apple.c b/src/detection/displayserver/displayserver_apple.c index a668ce961..15bba56b5 100644 --- a/src/detection/displayserver/displayserver_apple.c +++ b/src/detection/displayserver/displayserver_apple.c @@ -1,5 +1,6 @@ #include "displayserver.h" #include "util/apple/cf_helpers.h" +#include "util/stringUtils.h" #include #include @@ -69,7 +70,7 @@ static void detectDisplays(FFDisplayServerResult* ds) CGSize size = CGDisplayScreenSize(screen); - ffdsAppendDisplay(ds, + FFDisplayResult* display = ffdsAppendDisplay(ds, (uint32_t)CGDisplayModeGetPixelWidth(mode), (uint32_t)CGDisplayModeGetPixelHeight(mode), refreshRate, @@ -83,6 +84,24 @@ static void detectDisplays(FFDisplayServerResult* ds) (uint32_t) (size.width + 0.5), (uint32_t) (size.height + 0.5) ); + 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) + { + 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')); + } + } + display->bitDepth = bitDepth; + } CGDisplayModeRelease(mode); } CGDisplayRelease(screen);