2026-01-06 09:48:38 +08:00
|
|
|
#include "common/printing.h"
|
|
|
|
|
#include "common/jsonconfig.h"
|
2026-05-28 15:58:08 +08:00
|
|
|
#include "common/strutil.h"
|
2024-10-01 12:10:15 +08:00
|
|
|
#include "detection/displayserver/displayserver.h"
|
|
|
|
|
#include "modules/monitor/monitor.h"
|
|
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
bool ffPrintMonitor(FFMonitorOptions* options) {
|
2024-10-01 12:10:15 +08:00
|
|
|
const FFDisplayServerResult* result = ffConnectDisplayServer();
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
if (!result->displays.length) {
|
2026-08-14 23:33:54 +08:00
|
|
|
ffPrintError(FF_MODULE_GET_DISPLAY_NAME(Monitor), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No display detected");
|
2025-08-18 13:38:30 +08:00
|
|
|
return false;
|
2024-10-01 12:10:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate();
|
|
|
|
|
uint32_t index = 0;
|
2026-03-29 09:28:49 +08:00
|
|
|
FF_LIST_FOR_EACH (FFDisplayResult, display, result->displays) {
|
2024-10-01 12:10:15 +08:00
|
|
|
double inch = sqrt(display->physicalWidth * display->physicalWidth + display->physicalHeight * display->physicalHeight) / 25.4;
|
|
|
|
|
double ppi = sqrt(display->width * display->width + display->height * display->height) / inch;
|
|
|
|
|
bool hdrCompatible = display->hdrStatus == FF_DISPLAY_HDR_STATUS_SUPPORTED || display->hdrStatus == FF_DISPLAY_HDR_STATUS_ENABLED;
|
|
|
|
|
|
|
|
|
|
ffStrbufClear(&key);
|
2026-03-29 09:28:49 +08:00
|
|
|
if (options->moduleArgs.key.length == 0) {
|
2026-08-14 23:33:54 +08:00
|
|
|
ffStrbufAppendS(&key, FF_MODULE_GET_DISPLAY_NAME(Monitor));
|
2026-03-29 09:28:49 +08:00
|
|
|
if (display->name.length > 0) {
|
2024-11-05 10:01:43 +08:00
|
|
|
ffStrbufAppendF(&key, " (%s)", display->name.chars);
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
|
|
|
|
} else {
|
2024-10-01 12:10:15 +08:00
|
|
|
uint32_t moduleIndex = result->displays.length == 1 ? 0 : index + 1;
|
2024-12-11 10:47:02 +08:00
|
|
|
FF_PARSE_FORMAT_STRING_CHECKED(&key, &options->moduleArgs.key, ((FFformatarg[]) {
|
2026-03-29 09:28:49 +08:00
|
|
|
FF_ARG(moduleIndex, "index"),
|
|
|
|
|
FF_ARG(display->name, "name"),
|
|
|
|
|
FF_ARG(options->moduleArgs.keyIcon, "icon"),
|
2026-09-01 19:18:02 +08:00
|
|
|
FF_ARG(FF_MODULE_GET_DISPLAY_NAME(Monitor), "module-name"),
|
2026-03-29 09:28:49 +08:00
|
|
|
}));
|
2024-10-01 12:10:15 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
if (options->moduleArgs.outputFormat.length == 0) {
|
2024-10-01 12:10:15 +08:00
|
|
|
ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY);
|
|
|
|
|
|
|
|
|
|
printf("%ux%u px", display->width, display->height);
|
2026-03-29 09:28:49 +08:00
|
|
|
if (display->refreshRate > 0) {
|
2024-10-01 12:10:15 +08:00
|
|
|
printf(" @ %g Hz", ((int) (display->refreshRate * 1000 + 0.5)) / 1000.0);
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
|
|
|
|
if (inch > 0) {
|
2024-10-01 12:10:15 +08:00
|
|
|
printf(" - %ux%u mm (%.2f inches, %.2f ppi)", display->physicalWidth, display->physicalHeight, inch, ppi);
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
|
|
|
|
if (hdrCompatible) {
|
2024-10-01 12:10:15 +08:00
|
|
|
fputs(" [HDR Compatible]", stdout);
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2024-10-01 12:10:15 +08:00
|
|
|
putchar('\n');
|
2026-03-29 09:28:49 +08:00
|
|
|
} else {
|
2024-12-11 10:47:02 +08:00
|
|
|
FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, ((FFformatarg[]) {
|
2026-03-29 09:28:49 +08:00
|
|
|
FF_ARG(display->name, "name"),
|
|
|
|
|
FF_ARG(display->width, "width"),
|
|
|
|
|
FF_ARG(display->height, "height"),
|
|
|
|
|
FF_ARG(display->physicalWidth, "physical-width"),
|
|
|
|
|
FF_ARG(display->physicalHeight, "physical-height"),
|
|
|
|
|
FF_ARG(inch, "inch"),
|
|
|
|
|
FF_ARG(ppi, "ppi"),
|
|
|
|
|
FF_ARG(display->manufactureYear, "manufacture-year"),
|
|
|
|
|
FF_ARG(display->manufactureWeek, "manufacture-week"),
|
2026-06-19 18:53:10 +08:00
|
|
|
FF_ARG(display->serial, "serial"),
|
2026-03-29 09:28:49 +08:00
|
|
|
FF_ARG(display->refreshRate, "refresh-rate"),
|
|
|
|
|
FF_ARG(hdrCompatible, "hdr-compatible"),
|
|
|
|
|
}));
|
2024-10-01 12:10:15 +08:00
|
|
|
}
|
|
|
|
|
|
2026-06-23 10:58:51 +08:00
|
|
|
// result is a singleton, so we don't destroy the members
|
2024-10-01 12:10:15 +08:00
|
|
|
++index;
|
|
|
|
|
}
|
2025-08-18 13:38:30 +08:00
|
|
|
|
|
|
|
|
return true;
|
2024-10-01 12:10:15 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
void ffParseMonitorJsonObject(FFMonitorOptions* options, yyjson_val* module) {
|
2025-08-02 18:51:03 +08:00
|
|
|
yyjson_val *key, *val;
|
2024-10-01 12:10:15 +08:00
|
|
|
size_t idx, max;
|
2026-03-29 09:28:49 +08:00
|
|
|
yyjson_obj_foreach (module, idx, max, key, val) {
|
|
|
|
|
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) {
|
2024-10-01 12:10:15 +08:00
|
|
|
continue;
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2024-10-01 12:10:15 +08:00
|
|
|
|
2026-08-14 23:33:54 +08:00
|
|
|
ffPrintError(FF_MODULE_GET_DISPLAY_NAME(Monitor), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", unsafe_yyjson_get_str(key));
|
2024-10-01 12:10:15 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-03 01:32:02 +08:00
|
|
|
[[gnu::cold]]
|
2026-03-29 09:28:49 +08:00
|
|
|
void ffGenerateMonitorJsonConfig(FFMonitorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
2025-08-04 16:46:28 +08:00
|
|
|
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
|
2024-10-01 12:10:15 +08:00
|
|
|
}
|
|
|
|
|
|
2026-07-10 21:13:03 +08:00
|
|
|
bool ffGenerateMonitorJsonResult([[maybe_unused]] FFMonitorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
2024-10-01 12:10:15 +08:00
|
|
|
yyjson_mut_obj_add_str(doc, module, "error", "Monitor module is an alias of Display module");
|
2025-08-18 13:38:30 +08:00
|
|
|
return false;
|
2024-10-01 12:10:15 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
void ffInitMonitorOptions(FFMonitorOptions* options) {
|
2025-08-04 14:25:14 +08:00
|
|
|
ffOptionInitModuleArg(&options->moduleArgs, "");
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
void ffDestroyMonitorOptions(FFMonitorOptions* options) {
|
2025-08-04 14:25:14 +08:00
|
|
|
ffOptionDestroyModuleArg(&options->moduleArgs);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-03 22:50:56 +08:00
|
|
|
FFModuleBaseInfo ffMonitorModuleInfo = {
|
2026-08-14 23:33:54 +08:00
|
|
|
.name = "Monitor",
|
2026-03-24 17:40:46 +08:00
|
|
|
.description = "Same as Display module, but with a different default output format",
|
2026-08-14 20:38:58 +08:00
|
|
|
.displayName = {
|
|
|
|
|
.en = "Monitor",
|
2026-08-16 10:51:42 +08:00
|
|
|
.ar = "الشاشة",
|
2026-08-21 10:19:06 +08:00
|
|
|
.cs = "Monitor",
|
2026-08-14 20:38:58 +08:00
|
|
|
.de = "Monitor",
|
|
|
|
|
.es = "Monitor",
|
2026-10-03 13:35:56 +03:00
|
|
|
.fi = "Monitori",
|
2026-08-14 20:38:58 +08:00
|
|
|
.fr = "Moniteur",
|
2026-08-20 16:25:32 +00:00
|
|
|
.gl = "Monitor",
|
2026-08-16 10:51:42 +08:00
|
|
|
.he = "צג",
|
2026-08-21 10:19:06 +08:00
|
|
|
.id = "Monitor",
|
2026-08-14 20:38:58 +08:00
|
|
|
.it = "Monitor",
|
|
|
|
|
.ja = "モニター",
|
|
|
|
|
.ko = "모니터",
|
|
|
|
|
.pl = "Monitor",
|
2026-08-16 10:37:06 +08:00
|
|
|
.pt = "Monitor",
|
2026-08-14 20:38:58 +08:00
|
|
|
.ru = "Монитор",
|
2026-08-21 10:19:06 +08:00
|
|
|
.tr = "Monitör",
|
|
|
|
|
.uk = "Монітор",
|
|
|
|
|
.vi = "Màn hình",
|
2026-08-17 14:20:46 +08:00
|
|
|
.zh_CN = "监视器",
|
|
|
|
|
.zh_TW = "監視器",
|
2026-08-14 20:38:58 +08:00
|
|
|
},
|
2025-08-03 18:39:41 +08:00
|
|
|
.initOptions = (void*) ffInitMonitorOptions,
|
|
|
|
|
.destroyOptions = (void*) ffDestroyMonitorOptions,
|
2024-12-11 10:47:02 +08:00
|
|
|
.parseJsonObject = (void*) ffParseMonitorJsonObject,
|
|
|
|
|
.printModule = (void*) ffPrintMonitor,
|
|
|
|
|
.generateJsonResult = (void*) ffGenerateMonitorJsonResult,
|
|
|
|
|
.generateJsonConfig = (void*) ffGenerateMonitorJsonConfig,
|
|
|
|
|
.formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
|
2026-09-15 22:20:17 +08:00
|
|
|
{ "Display name *", "name" },
|
2026-03-30 10:27:23 +08:00
|
|
|
{ "Native resolution width in pixels", "width" },
|
|
|
|
|
{ "Native resolution height in pixels", "height" },
|
|
|
|
|
{ "Physical width in millimeters", "physical-width" },
|
|
|
|
|
{ "Physical height in millimeters", "physical-height" },
|
|
|
|
|
{ "Physical diagonal length in inches", "inch" },
|
|
|
|
|
{ "Pixels per inch (PPI)", "ppi" },
|
|
|
|
|
{ "Year of manufacturing", "manufacture-year" },
|
|
|
|
|
{ "Nth week of manufacturing in the year", "manufacture-week" },
|
|
|
|
|
{ "Serial number", "serial" },
|
|
|
|
|
{ "Maximum refresh rate in Hz", "refresh-rate" },
|
|
|
|
|
{ "True if the display is HDR compatible", "hdr-compatible" },
|
2026-07-31 10:56:13 +08:00
|
|
|
})),
|
|
|
|
|
.defaultOrder = 19,
|
2026-03-30 10:17:45 +08:00
|
|
|
};
|