Files
fastfetch/src/modules/display.c
T

50 lines
1.9 KiB
C
Raw Normal View History

2021-06-27 21:09:18 +02:00
#include "fastfetch.h"
#include "common/printing.h"
2022-09-06 15:42:37 +02:00
#include "detection/displayserver/displayserver.h"
2021-02-18 22:25:36 +01:00
2023-01-18 01:37:47 +08:00
#define FF_RESOLUTION_MODULE_NAME "Display"
2021-06-27 21:09:18 +02:00
#define FF_RESOLUTION_NUM_FORMAT_ARGS 3
2023-01-18 01:37:47 +08:00
void ffPrintDisplay(FFinstance* instance)
2021-06-27 21:09:18 +02:00
{
2022-01-10 14:41:34 +01:00
#ifdef __ANDROID__
2023-01-18 01:37:47 +08:00
ffPrintError(instance, FF_RESOLUTION_MODULE_NAME, 0, &instance->config.display, "Display detection is not supported on Android");
2022-01-10 14:41:34 +01:00
return;
#endif
2022-01-02 16:55:26 +01:00
const FFDisplayServerResult* dsResult = ffConnectDisplayServer(instance);
2021-07-02 22:43:58 +02:00
2023-01-18 01:37:47 +08:00
for(uint32_t i = 0; i < dsResult->displays.length; i++)
2021-07-02 22:43:58 +02:00
{
2023-01-18 01:37:47 +08:00
FFDisplayResult* result = ffListGet(&dsResult->displays, i);
uint8_t moduleIndex = dsResult->displays.length == 1 ? 0 : (uint8_t) (i + 1);
2021-07-06 21:15:08 +02:00
2023-01-18 01:37:47 +08:00
if(instance->config.display.outputFormat.length == 0)
2021-07-06 21:15:08 +02:00
{
2023-01-18 01:37:47 +08:00
ffPrintLogoAndKey(instance, FF_RESOLUTION_MODULE_NAME, moduleIndex, &instance->config.display.key);
2021-07-06 21:15:08 +02:00
printf("%ix%i", result->width, result->height);
if(result->refreshRate > 0)
printf(" @ %iHz", result->refreshRate);
if(
result->scaledWidth > 0 && result->scaledWidth != result->width &&
result->scaledHeight > 0 && result->scaledHeight != result->height)
printf(" (as %ix%i)", result->scaledWidth, result->scaledHeight);
2021-07-06 21:15:08 +02:00
putchar('\n');
}
else
{
2023-01-18 01:37:47 +08:00
ffPrintFormat(instance, FF_RESOLUTION_MODULE_NAME, moduleIndex, &instance->config.display, FF_RESOLUTION_NUM_FORMAT_ARGS, (FFformatarg[]) {
2021-07-06 21:15:08 +02:00
{FF_FORMAT_ARG_TYPE_INT, &result->width},
{FF_FORMAT_ARG_TYPE_INT, &result->height},
{FF_FORMAT_ARG_TYPE_INT, &result->refreshRate}
2021-07-06 21:15:08 +02:00
});
}
2021-07-02 22:43:58 +02:00
}
2023-01-18 01:37:47 +08:00
if(dsResult->displays.length == 0)
ffPrintError(instance, FF_RESOLUTION_MODULE_NAME, 0, &instance->config.display, "Couldn't detect display");
2021-06-27 21:09:18 +02:00
}