From eea02ffb800782c5fc689295515d669406a1d196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 16 Jun 2023 13:51:00 +0800 Subject: [PATCH] Display (macOS): detect primary display --- src/detection/displayserver/displayserver.c | 4 +++- src/detection/displayserver/displayserver.h | 4 +++- src/detection/displayserver/displayserver_apple.c | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/detection/displayserver/displayserver.c b/src/detection/displayserver/displayserver.c index 062f3be12..b535012d2 100644 --- a/src/detection/displayserver/displayserver.c +++ b/src/detection/displayserver/displayserver.c @@ -10,7 +10,8 @@ bool ffdsAppendDisplay( uint32_t scaledHeight, uint32_t rotation, FFstrbuf* name, - FFDisplayType type) + FFDisplayType type, + bool primary) { if(width == 0 || height == 0) return false; @@ -24,6 +25,7 @@ bool ffdsAppendDisplay( display->rotation = rotation; ffStrbufInitMove(&display->name, name); display->type = type; + display->primary = primary; return true; } diff --git a/src/detection/displayserver/displayserver.h b/src/detection/displayserver/displayserver.h index 52d0f34c9..5ffd5a30d 100644 --- a/src/detection/displayserver/displayserver.h +++ b/src/detection/displayserver/displayserver.h @@ -51,6 +51,7 @@ typedef struct FFDisplayResult FFstrbuf name; FFDisplayType type; uint32_t rotation; + bool primary; } FFDisplayResult; typedef struct FFDisplayServerResult @@ -75,6 +76,7 @@ bool ffdsAppendDisplay( uint32_t scaledHeight, uint32_t rotation, FFstrbuf* name, - FFDisplayType type); + FFDisplayType type, + bool primary); #endif diff --git a/src/detection/displayserver/displayserver_apple.c b/src/detection/displayserver/displayserver_apple.c index 2ab624a39..15e423330 100644 --- a/src/detection/displayserver/displayserver_apple.c +++ b/src/detection/displayserver/displayserver_apple.c @@ -19,6 +19,8 @@ static void detectDisplays(FFDisplayServerResult* ds) if(CGGetOnlineDisplayList(sizeof(screens) / sizeof(screens[0]), screens, &screenCount) != kCGErrorSuccess) return; + CGDirectDisplayID primary = CGMainDisplayID(); + for(uint32_t i = 0; i < screenCount; i++) { CGDirectDisplayID screen = screens[i]; @@ -60,7 +62,8 @@ static void detectDisplays(FFDisplayServerResult* ds) (uint32_t)CGDisplayModeGetHeight(mode), (uint32_t)CGDisplayRotation(screen), &name, - CGDisplayIsBuiltin(screen) ? FF_DISPLAY_TYPE_BUILTIN : FF_DISPLAY_TYPE_EXTERNAL + CGDisplayIsBuiltin(screen) ? FF_DISPLAY_TYPE_BUILTIN : FF_DISPLAY_TYPE_EXTERNAL, + screen == primary ); CGDisplayModeRelease(mode); }