Display (macOS): detect primary display

This commit is contained in:
李通洲
2023-06-16 13:51:00 +08:00
committed by CarterLi
parent 59ec3ca697
commit eea02ffb80
3 changed files with 10 additions and 3 deletions
+3 -1
View File
@@ -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;
}
+3 -1
View File
@@ -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
@@ -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);
}