Display: detect screen rotation

This commit is contained in:
李通洲
2023-06-12 10:35:28 +08:00
parent 56effcb189
commit 6f9167c725
9 changed files with 89 additions and 41 deletions
@@ -8,6 +8,7 @@ bool ffdsAppendDisplay(
double refreshRate,
uint32_t scaledWidth,
uint32_t scaledHeight,
uint32_t rotation,
FFstrbuf* name,
FFDisplayType type)
{
@@ -20,6 +21,7 @@ bool ffdsAppendDisplay(
display->refreshRate = refreshRate;
display->scaledWidth = scaledWidth;
display->scaledHeight = scaledHeight;
display->rotation = rotation;
ffStrbufInitMove(&display->name, name);
display->type = type;
@@ -50,6 +50,7 @@ typedef struct FFDisplayResult
uint32_t scaledHeight;
FFstrbuf name;
FFDisplayType type;
uint32_t rotation;
} FFDisplayResult;
typedef struct FFDisplayServerResult
@@ -72,6 +73,7 @@ bool ffdsAppendDisplay(
double refreshRate,
uint32_t scaledWidth,
uint32_t scaledHeight,
uint32_t rotation,
FFstrbuf* name,
FFDisplayType type);
@@ -12,7 +12,7 @@
extern CFDictionaryRef CoreDisplay_DisplayCreateInfoDictionary(CGDirectDisplayID display) __attribute__((weak_import));
static void detectDisplays(FFDisplayServerResult* ds, bool detectName)
static void detectDisplays(FFDisplayServerResult* ds)
{
CGDirectDisplayID screens[128];
uint32_t screenCount;
@@ -41,7 +41,7 @@ static void detectDisplays(FFDisplayServerResult* ds, bool detectName)
}
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate();
if(detectName && CoreDisplay_DisplayCreateInfoDictionary)
if(CoreDisplay_DisplayCreateInfoDictionary)
{
CFDictionaryRef FF_CFTYPE_AUTO_RELEASE displayInfo = CoreDisplay_DisplayCreateInfoDictionary(screen);
if(displayInfo)
@@ -58,6 +58,7 @@ static void detectDisplays(FFDisplayServerResult* ds, bool detectName)
refreshRate,
(uint32_t)CGDisplayModeGetWidth(mode),
(uint32_t)CGDisplayModeGetHeight(mode),
(uint32_t)CGDisplayRotation(screen),
&name,
CGDisplayIsBuiltin(screen) ? FF_DISPLAY_TYPE_BUILTIN : FF_DISPLAY_TYPE_EXTERNAL
);
@@ -120,5 +121,5 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds, const FFinstance* ins
ffStrbufAppendS(&ds->dePrettyName, "Aqua");
ffListInitA(&ds->displays, sizeof(FFDisplayResult), 4);
detectDisplays(ds, instance->config.display.detectName);
detectDisplays(ds);
}
@@ -5,7 +5,7 @@
#include <dwmapi.h>
#include <WinUser.h>
static void detectDisplays(FFDisplayServerResult* ds, bool detectName)
static void detectDisplays(FFDisplayServerResult* ds)
{
DISPLAYCONFIG_PATH_INFO paths[128];
uint32_t pathCount = sizeof(paths) / sizeof(paths[0]);
@@ -44,26 +44,23 @@ static void detectDisplays(FFDisplayServerResult* ds, bool detectName)
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate();
if (detectName)
DISPLAYCONFIG_TARGET_DEVICE_NAME targetName = {
.header = {
.type = DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME,
.size = sizeof(targetName),
.adapterId = path->targetInfo.adapterId,
.id = path->targetInfo.id,
},
};
if(DisplayConfigGetDeviceInfo(&targetName.header) == ERROR_SUCCESS)
{
DISPLAYCONFIG_TARGET_DEVICE_NAME targetName = {
.header = {
.type = DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME,
.size = sizeof(targetName),
.adapterId = path->targetInfo.adapterId,
.id = path->targetInfo.id,
},
};
if(DisplayConfigGetDeviceInfo(&targetName.header) == ERROR_SUCCESS)
if (targetName.flags.friendlyNameFromEdid)
ffStrbufSetWS(&name, targetName.monitorFriendlyDeviceName);
else
{
if (targetName.flags.friendlyNameFromEdid)
ffStrbufSetWS(&name, targetName.monitorFriendlyDeviceName);
else
{
ffStrbufSetWS(&name, targetName.monitorDevicePath);
ffStrbufSubstrAfterFirstC(&name, '#');
ffStrbufSubstrBeforeFirstC(&name, '#');
}
ffStrbufSetWS(&name, targetName.monitorDevicePath);
ffStrbufSubstrAfterFirstC(&name, '#');
ffStrbufSubstrBeforeFirstC(&name, '#');
}
}
@@ -77,12 +74,30 @@ static void detectDisplays(FFDisplayServerResult* ds, bool detectName)
height = temp;
}
uint32_t rotation;
switch (path->targetInfo.rotation)
{
case DISPLAYCONFIG_ROTATION_ROTATE90:
rotation = 90;
break;
case DISPLAYCONFIG_ROTATION_ROTATE180:
rotation = 180;
break;
case DISPLAYCONFIG_ROTATION_ROTATE270:
rotation = 270;
break;
default:
rotation = 0;
break;
}
ffdsAppendDisplay(ds,
width,
height,
path->targetInfo.refreshRate.Numerator / (double) path->targetInfo.refreshRate.Denominator,
scaledWidth,
scaledHeight,
rotation,
&name,
path->targetInfo.outputTechnology == DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL ||
path->targetInfo.outputTechnology == DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED ||
@@ -112,7 +127,7 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds, const FFinstance* ins
ffStrbufInit(&ds->deVersion);
ffListInit(&ds->displays, sizeof(FFDisplayResult));
detectDisplays(ds, instance->config.display.detectName);
detectDisplays(ds);
//https://github.com/hykilpikonna/hyfetch/blob/master/neofetch#L2067
const FFOSResult* os = ffDetectOS(instance);
+28 -14
View File
@@ -19,7 +19,6 @@ typedef struct WaylandData
FF_LIBRARY_SYMBOL(wl_display_roundtrip)
struct wl_display* display;
const struct wl_interface* ffwl_output_interface;
bool detectName;
} WaylandData;
typedef struct WaylandDisplay
@@ -31,7 +30,6 @@ typedef struct WaylandDisplay
enum wl_output_transform transform;
FFDisplayType type;
FFstrbuf name;
bool detectName;
} WaylandDisplay;
#ifndef __FreeBSD__
@@ -92,16 +90,14 @@ static void waylandOutputGeometryListener(void *data,
{
WaylandDisplay* display = data;
display->transform = (enum wl_output_transform) transform;
if(display->detectName)
if(make && strcmp(make, "unknown") != 0)
ffStrbufAppendS(&display->name, make);
if(model && strcmp(model, "unknown") != 0)
{
if(make && strcmp(make, "unknown") != 0)
ffStrbufAppendS(&display->name, make);
if(model && strcmp(model, "unknown") != 0)
{
if(display->name.length > 0)
ffStrbufAppendC(&display->name, '-');
ffStrbufAppendS(&display->name, model);
}
if(display->name.length > 0)
ffStrbufAppendC(&display->name, '-');
ffStrbufAppendS(&display->name, model);
}
}
@@ -123,7 +119,6 @@ static void waylandOutputHandler(WaylandData* wldata, struct wl_registry* regist
return;
WaylandDisplay display = {
.detectName = wldata->detectName,
.width = 0,
.height = 0,
.refreshRate = 0,
@@ -179,12 +174,33 @@ static void waylandOutputHandler(WaylandData* wldata, struct wl_registry* regist
break;
}
uint32_t rotation;
switch(display.transform)
{
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
case WL_OUTPUT_TRANSFORM_90:
rotation = 90;
break;
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
case WL_OUTPUT_TRANSFORM_180:
rotation = 180;
break;
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
case WL_OUTPUT_TRANSFORM_270:
rotation = 270;
break;
default:
rotation = 0;
break;
}
ffdsAppendDisplay(wldata->result,
(uint32_t) display.width,
(uint32_t) display.height,
display.refreshRate / 1000.0,
(uint32_t) (display.width / display.scale),
(uint32_t) (display.height / display.scale),
rotation,
&display.name,
display.type
);
@@ -223,8 +239,6 @@ bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result)
if(data.display == NULL)
return false;
data.detectName = instance->config.display.detectName;
waylandDetectWM(ffwl_display_get_fd(data.display), result);
struct wl_proxy* registry = ffwl_proxy_marshal_constructor((struct wl_proxy*) data.display, WL_DISPLAY_GET_REGISTRY, ffwl_registry_interface, NULL);
+5
View File
@@ -118,6 +118,7 @@ void ffdsConnectXcb(const FFinstance* instance, FFDisplayServerResult* result)
0,
(uint32_t) iterator.data->width_in_pixels,
(uint32_t) iterator.data->height_in_pixels,
0,
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
@@ -184,6 +185,7 @@ static bool xcbRandrHandleModeInfo(XcbRandrData* data, xcb_randr_mode_info_t* mo
refreshRate == 0 ? data->defaultRefreshRate : refreshRate,
(uint32_t) modeInfo->width,
(uint32_t) modeInfo->height,
0,
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
@@ -223,6 +225,7 @@ static bool xcbRandrHandleCrtc(XcbRandrData* data, xcb_randr_crtc_t crtc)
data->defaultRefreshRate,
(uint32_t) crtcInfoReply->width,
(uint32_t) crtcInfoReply->height,
0,
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
@@ -270,6 +273,7 @@ static bool xcbRandrHandleMonitor(XcbRandrData* data, xcb_randr_monitor_info_t*
data->defaultRefreshRate,
(uint32_t) monitor->width,
(uint32_t) monitor->height,
0,
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
@@ -332,6 +336,7 @@ static void xcbRandrHandleScreen(XcbRandrData* data, xcb_screen_t* screen)
data->defaultRefreshRate,
(uint32_t) screen->width_in_pixels,
(uint32_t) screen->height_in_pixels,
0,
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
+5
View File
@@ -83,6 +83,7 @@ void ffdsConnectXlib(const FFinstance* instance, FFDisplayServerResult* result)
0,
(uint32_t) WidthOfScreen(screen),
(uint32_t) HeightOfScreen(screen),
0,
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
@@ -143,6 +144,7 @@ static bool xrandrHandleModeInfo(XrandrData* data, XRRModeInfo* modeInfo)
refreshRate == 0 ? data->defaultRefreshRate : refreshRate,
(uint32_t) modeInfo->width,
(uint32_t) modeInfo->height,
0,
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
@@ -176,6 +178,7 @@ static bool xrandrHandleCrtc(XrandrData* data, RRCrtc crtc)
data->defaultRefreshRate,
(uint32_t) crtcInfo->width,
(uint32_t) crtcInfo->height,
0,
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
@@ -214,6 +217,7 @@ static bool xrandrHandleMonitor(XrandrData* data, XRRMonitorInfo* monitorInfo)
data->defaultRefreshRate,
(uint32_t) monitorInfo->width,
(uint32_t) monitorInfo->height,
0,
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
@@ -270,6 +274,7 @@ static void xrandrHandleScreen(XrandrData* data, Screen* screen)
data->defaultRefreshRate,
(uint32_t) WidthOfScreen(screen),
(uint32_t) HeightOfScreen(screen),
0,
NULL,
FF_DISPLAY_TYPE_UNKNOWN
);
+5 -2
View File
@@ -177,12 +177,15 @@ static inline void printCommandHelp(const char* command)
}
else if(strcasecmp(command, "display-format") == 0)
{
constructAndPrintCommandHelpFormat("display", "{}x{} @ {}Hz", 5,
constructAndPrintCommandHelpFormat("display", "{}x{} @ {}Hz", 7,
"Screen width",
"Screen height",
"Screen refresh rate",
"Screen scaled width",
"Screen scaled height"
"Screen scaled height",
"Screen name",
"Screen type",
"Screen rotation"
);
}
else if(strcasecmp(command, "de-format") == 0)
+3 -2
View File
@@ -3,7 +3,7 @@
#include "detection/displayserver/displayserver.h"
#include "modules/display/display.h"
#define FF_DISPLAY_NUM_FORMAT_ARGS 7
#define FF_DISPLAY_NUM_FORMAT_ARGS 8
void ffPrintDisplay(FFinstance* instance, FFDisplayOptions* options)
{
@@ -53,7 +53,7 @@ void ffPrintDisplay(FFinstance* instance, FFDisplayOptions* options)
if(options->moduleArgs.outputFormat.length == 0)
{
if(result->name.length || (moduleIndex > 0 && displayType))
if((options->detectName && result->name.length) || (moduleIndex > 0 && displayType))
{
ffStrbufClear(&key);
if(options->moduleArgs.key.length == 0)
@@ -102,6 +102,7 @@ void ffPrintDisplay(FFinstance* instance, FFDisplayOptions* options)
{FF_FORMAT_ARG_TYPE_UINT, &result->scaledHeight},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->name},
{FF_FORMAT_ARG_TYPE_STRING, displayType},
{FF_FORMAT_ARG_TYPE_UINT, &result->rotation},
});
}