DisplayServer: detect display type ( builtin or external )

This commit is contained in:
李通洲
2023-03-22 21:33:46 +08:00
parent 95e0a5ee95
commit babb836f91
9 changed files with 66 additions and 20 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ Features:
* Support foot terminal (#431, Linux)
* Support cursor size detection on Windows (Cursor, Windows)
* Support cursor detection on macOS (Cursor, macOS)
* Support display name and decimal refresh rate detection (Display, macOS / Windows)
* Support display name, display type and decimal refresh rate detection (Display, macOS / Windows)
Bugfixes:
* Fix date time format
+10 -1
View File
@@ -1,7 +1,15 @@
#include "displayserver.h"
#include "detection/internal.h"
bool ffdsAppendDisplay(FFDisplayServerResult* result, uint32_t width, uint32_t height, double refreshRate, uint32_t scaledWidth, uint32_t scaledHeight, FFstrbuf* name)
bool ffdsAppendDisplay(
FFDisplayServerResult* result,
uint32_t width,
uint32_t height,
double refreshRate,
uint32_t scaledWidth,
uint32_t scaledHeight,
FFstrbuf* name,
FFDisplayType type)
{
if(width == 0 || height == 0)
return false;
@@ -13,6 +21,7 @@ bool ffdsAppendDisplay(FFDisplayServerResult* result, uint32_t width, uint32_t h
display->scaledWidth = scaledWidth;
display->scaledHeight = scaledHeight;
ffStrbufInitMove(&display->name, name);
display->type = type;
return true;
}
+17 -1
View File
@@ -34,6 +34,12 @@
#define FF_WM_PROTOCOL_X11 "X11"
#define FF_WM_PROTOCOL_WAYLAND "Wayland"
typedef enum FFDisplayType {
FF_DISPLAY_TYPE_UNKNOWN,
FF_DISPLAY_TYPE_BUILTIN,
FF_DISPLAY_TYPE_EXTERNAL,
} FFDisplayType;
typedef struct FFDisplayResult
{
uint32_t width;
@@ -42,6 +48,7 @@ typedef struct FFDisplayResult
uint32_t scaledWidth;
uint32_t scaledHeight;
FFstrbuf name;
FFDisplayType type;
} FFDisplayResult;
typedef struct FFDisplayServerResult
@@ -56,6 +63,15 @@ typedef struct FFDisplayServerResult
} FFDisplayServerResult;
const FFDisplayServerResult* ffConnectDisplayServer(const FFinstance* instance);
bool ffdsAppendDisplay(FFDisplayServerResult* result, uint32_t width, uint32_t height, double refreshRate, uint32_t scaledWidth, uint32_t scaledHeight, FFstrbuf* name);
bool ffdsAppendDisplay(
FFDisplayServerResult* result,
uint32_t width,
uint32_t height,
double refreshRate,
uint32_t scaledWidth,
uint32_t scaledHeight,
FFstrbuf* name,
FFDisplayType type);
#endif
@@ -58,7 +58,8 @@ static void detectDisplays(FFDisplayServerResult* ds, bool detectName)
refreshRate,
(uint32_t)CGDisplayModeGetWidth(mode),
(uint32_t)CGDisplayModeGetHeight(mode),
&name
&name,
CGDisplayIsBuiltin(screen) ? FF_DISPLAY_TYPE_BUILTIN : FF_DISPLAY_TYPE_EXTERNAL
);
CGDisplayModeRelease(mode);
}
@@ -93,7 +93,12 @@ static void detectDisplays(FFDisplayServerResult* ds, bool detectName)
path->targetInfo.refreshRate.Numerator / (double) path->targetInfo.refreshRate.Denominator,
data.width,
data.height,
&name);
&name,
path->targetInfo.outputTechnology == DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL ||
path->targetInfo.outputTechnology == DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED ||
path->targetInfo.outputTechnology == DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EMBEDDED
? FF_DISPLAY_TYPE_BUILTIN : FF_DISPLAY_TYPE_EXTERNAL
);
}
}
}
+2 -1
View File
@@ -126,7 +126,8 @@ static void waylandOutputHandler(WaylandData* wldata, struct wl_registry* regist
display.refreshRate / 1000.0,
(uint32_t) (display.width / display.scale),
(uint32_t) (display.height / display.scale),
NULL
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
ffThreadMutexUnlock(&mutex);
+10 -5
View File
@@ -118,7 +118,8 @@ void ffdsConnectXcb(const FFinstance* instance, FFDisplayServerResult* result)
0,
(uint32_t) iterator.data->width_in_pixels,
(uint32_t) iterator.data->height_in_pixels,
NULL
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
ffxcb_screen_next(&iterator);
}
@@ -183,7 +184,8 @@ static bool xcbRandrHandleModeInfo(XcbRandrData* data, xcb_randr_mode_info_t* mo
refreshRate == 0 ? data->defaultRefreshRate : refreshRate,
(uint32_t) modeInfo->width,
(uint32_t) modeInfo->height,
NULL
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
}
@@ -221,7 +223,8 @@ static bool xcbRandrHandleCrtc(XcbRandrData* data, xcb_randr_crtc_t crtc)
data->defaultRefreshRate,
(uint32_t) crtcInfoReply->width,
(uint32_t) crtcInfoReply->height,
NULL
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
free(crtcInfoReply);
@@ -267,7 +270,8 @@ static bool xcbRandrHandleMonitor(XcbRandrData* data, xcb_randr_monitor_info_t*
data->defaultRefreshRate,
(uint32_t) monitor->width,
(uint32_t) monitor->height,
NULL
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
}
@@ -328,7 +332,8 @@ static void xcbRandrHandleScreen(XcbRandrData* data, xcb_screen_t* screen)
data->defaultRefreshRate,
(uint32_t) screen->width_in_pixels,
(uint32_t) screen->height_in_pixels,
NULL
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
}
+10 -5
View File
@@ -83,7 +83,8 @@ void ffdsConnectXlib(const FFinstance* instance, FFDisplayServerResult* result)
0,
(uint32_t) WidthOfScreen(screen),
(uint32_t) HeightOfScreen(screen),
NULL
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
}
@@ -142,7 +143,8 @@ static bool xrandrHandleModeInfo(XrandrData* data, XRRModeInfo* modeInfo)
refreshRate == 0 ? data->defaultRefreshRate : refreshRate,
(uint32_t) modeInfo->width,
(uint32_t) modeInfo->height,
NULL
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
}
@@ -174,7 +176,8 @@ static bool xrandrHandleCrtc(XrandrData* data, RRCrtc crtc)
data->defaultRefreshRate,
(uint32_t) crtcInfo->width,
(uint32_t) crtcInfo->height,
NULL
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
data->ffXRRFreeCrtcInfo(crtcInfo);
@@ -211,7 +214,8 @@ static bool xrandrHandleMonitor(XrandrData* data, XRRMonitorInfo* monitorInfo)
data->defaultRefreshRate,
(uint32_t) monitorInfo->width,
(uint32_t) monitorInfo->height,
NULL
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
}
@@ -266,7 +270,8 @@ static void xrandrHandleScreen(XrandrData* data, Screen* screen)
data->defaultRefreshRate,
(uint32_t) WidthOfScreen(screen),
(uint32_t) HeightOfScreen(screen),
NULL
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
}
+8 -4
View File
@@ -3,7 +3,7 @@
#include "detection/displayserver/displayserver.h"
#define FF_DISPLAY_MODULE_NAME "Display"
#define FF_DISPLAY_NUM_FORMAT_ARGS 6
#define FF_DISPLAY_NUM_FORMAT_ARGS 7
void ffPrintDisplay(FFinstance* instance)
{
@@ -44,20 +44,23 @@ void ffPrintDisplay(FFinstance* instance)
{
FFDisplayResult* result = ffListGet(&dsResult->displays, i);
uint8_t moduleIndex = dsResult->displays.length == 1 ? 0 : (uint8_t) (i + 1);
const char* displayType = result->type == FF_DISPLAY_TYPE_UNKNOWN ? NULL : result->type == FF_DISPLAY_TYPE_BUILTIN ? "built-in" : "external";
if(instance->config.display.outputFormat.length == 0)
{
if(result->name.length)
if(result->name.length || (moduleIndex > 0 && displayType))
{
ffStrbufClear(&key);
if(instance->config.display.key.length == 0)
{
ffStrbufAppendF(&key, "%s (%s)", FF_DISPLAY_MODULE_NAME, result->name.chars);
ffStrbufAppendF(&key, "%s (%s)", FF_DISPLAY_MODULE_NAME, result->name.length ? result->name.chars : displayType);
}
else
{
ffParseFormatString(&key, &instance->config.display.key, 1, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &result->name}
{FF_FORMAT_ARG_TYPE_UINT, &i},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->name},
{FF_FORMAT_ARG_TYPE_STRING, displayType},
});
}
ffPrintLogoAndKey(instance, key.chars, 0, NULL);
@@ -93,6 +96,7 @@ void ffPrintDisplay(FFinstance* instance)
{FF_FORMAT_ARG_TYPE_UINT, &result->scaledWidth},
{FF_FORMAT_ARG_TYPE_UINT, &result->scaledHeight},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->name},
{FF_FORMAT_ARG_TYPE_STRING, displayType},
});
}