From a28dc8a9bfc646ecfbb249794ac7f0eac1799ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 11 Dec 2023 13:25:58 +0800 Subject: [PATCH] DisplayServer (Linux): support `--ds-force-drm sysfs-only` --- CHANGELOG.md | 1 + doc/json_schema.json | 21 +++++++-- src/data/help.json | 9 +++- .../displayserver/linux/displayserver_linux.c | 2 +- src/detection/displayserver/linux/drm.c | 7 ++- src/options/general.c | 45 +++++++++++++++++-- src/options/general.h | 9 +++- 7 files changed, 81 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f3160625..b4a84c112 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Features: * Improve performance of detecting rpm and pkg package count (Packages, Linux / FreeBSD) * Support Apple M3X temperature detection (CPU / GPU, macOS) +* `--ds-force-drm` support a new option `sysfs-only` # 2.3.4 diff --git a/doc/json_schema.json b/doc/json_schema.json index 091770f46..99b908c63 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -251,9 +251,24 @@ "description": "Set the path to the file containing OS information. Linux only" }, "dsForceDrm": { - "type": "boolean", - "description": "Force display detection to use `/sys/class/drm`. Linux only", - "default": false + "description": "Force display detection to use DRM. Linux only", + "oneOf": [ + { + "type": "bool", + "const": false, + "description": "Try `libdrm` first, then `sysfs` if libdrm failed" + }, + { + "type": "string", + "description": "Use `/sys/class/drm` only.", + "const": "sysfs-only" + }, + { + "type": "bool", + "const": true, + "description": "Don't force using DRM" + } + ] }, "wmiTimeout": { "type": "integer", diff --git a/src/data/help.json b/src/data/help.json index f72a94a2d..8dcd3c03a 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -124,9 +124,14 @@ "desc": "Set if only DRM should be used to detect displays", "remark": "Use this option if you encountered problems with other detection method. Linux only", "arg": { - "type": "bool", + "type": "enum", "optional": true, - "default": false + "default": "false", + "enum": { + "true": "Try `libdrm` first, then `sysfs` if libdrm failed", + "sysfs-only": "Use `/sys/class/drm` only", + "false": "Don't force using DRM" + } } } ], diff --git a/src/detection/displayserver/linux/displayserver_linux.c b/src/detection/displayserver/linux/displayserver_linux.c index d6eb3da99..e75e311b0 100644 --- a/src/detection/displayserver/linux/displayserver_linux.c +++ b/src/detection/displayserver/linux/displayserver_linux.c @@ -10,7 +10,7 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds) ffStrbufInit(&ds->dePrettyName); ffListInitA(&ds->displays, sizeof(FFDisplayResult), 4); - if (!instance.config.general.dsForceDrm) + if (instance.config.general.dsForceDrm == FF_DS_FORCE_DRM_TYPE_FALSE) { //We try wayland as our preferred display server, as it supports the most features. //This method can't detect the name of our WM / DE diff --git a/src/detection/displayserver/linux/drm.c b/src/detection/displayserver/linux/drm.c index baf4e4bdf..4adffe6be 100644 --- a/src/detection/displayserver/linux/drm.c +++ b/src/detection/displayserver/linux/drm.c @@ -285,8 +285,11 @@ static const char* drmConnectLibdrm(FFDisplayServerResult* result) void ffdsConnectDrm(FFDisplayServerResult* result) { #ifdef FF_HAVE_DRM - if (drmConnectLibdrm(result) == NULL) - return; + if (instance.config.general.dsForceDrm != FF_DS_FORCE_DRM_TYPE_SYSFS_ONLY) + { + if (drmConnectLibdrm(result) == NULL) + return; + } #endif drmParseSysfs(result); diff --git a/src/options/general.c b/src/options/general.c index 6357e04b8..7cec888f7 100644 --- a/src/options/general.c +++ b/src/options/general.c @@ -30,7 +30,24 @@ const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_va else if (ffStrEqualsIgnCase(key, "osFile")) ffStrbufSetS(&options->osFile, yyjson_get_str(val)); else if (ffStrEqualsIgnCase(key, "dsForceDrm")) - options->dsForceDrm = yyjson_get_bool(val); + { + if (yyjson_is_str(val)) + { + int value; + const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) { + { "sysfs-only", FF_DS_FORCE_DRM_TYPE_SYSFS_ONLY }, + { "false", FF_DS_FORCE_DRM_TYPE_FALSE }, + { "true", FF_DS_FORCE_DRM_TYPE_TRUE }, + {}, + }); + if (error) + return "Invalid enum value of `dsForceDrm`"; + else + options->dsForceDrm = (FFDsForceDrmType) value; + } + else + options->dsForceDrm = yyjson_get_bool(val) ? FF_DS_FORCE_DRM_TYPE_TRUE : FF_DS_FORCE_DRM_TYPE_FALSE; + } #elif defined(_WIN32) else if (ffStrEqualsIgnCase(key, "wmiTimeout")) options->wmiTimeout = (int32_t) yyjson_get_int(val); @@ -65,7 +82,14 @@ bool ffOptionsParseGeneralCommandLine(FFOptionsGeneral* options, const char* key else if (ffStrEqualsIgnCase(key, "--os-file")) ffOptionParseString(key, value, &options->osFile); else if(ffStrEqualsIgnCase(key, "--ds-force-drm")) - options->dsForceDrm = ffOptionParseBoolean(value); + { + if (ffOptionParseBoolean(value)) + options->dsForceDrm = FF_DS_FORCE_DRM_TYPE_TRUE; + else if (ffStrEqualsIgnCase(value, "sysfs-only")) + options->dsForceDrm = FF_DS_FORCE_DRM_TYPE_SYSFS_ONLY; + else + options->dsForceDrm = FF_DS_FORCE_DRM_TYPE_FALSE; + } #elif defined(_WIN32) else if (ffStrEqualsIgnCase(key, "--wmi-timeout")) options->wmiTimeout = ffOptionParseInt32(key, value); @@ -86,7 +110,7 @@ void ffOptionsInitGeneral(FFOptionsGeneral* options) options->escapeBedrock = true; ffStrbufInit(&options->playerName); ffStrbufInit(&options->osFile); - options->dsForceDrm = false; + options->dsForceDrm = FF_DS_FORCE_DRM_TYPE_FALSE; #elif defined(_WIN32) options->wmiTimeout = 5000; #endif @@ -125,7 +149,20 @@ void ffOptionsGenerateGeneralJsonConfig(FFOptionsGeneral* options, yyjson_mut_do yyjson_mut_obj_add_strbuf(doc, obj, "osFile", &options->osFile); if (options->dsForceDrm != defaultOptions.dsForceDrm) - yyjson_mut_obj_add_bool(doc, obj, "dsForceDrm", options->dsForceDrm); + { + switch (options->dsForceDrm) + { + case FF_DS_FORCE_DRM_TYPE_FALSE: + yyjson_mut_obj_add_bool(doc, obj, "dsForceDrm", false); + break; + case FF_DS_FORCE_DRM_TYPE_SYSFS_ONLY: + yyjson_mut_obj_add_str(doc, obj, "dsForceDrm", "sysfs-only"); + break; + case FF_DS_FORCE_DRM_TYPE_TRUE: + yyjson_mut_obj_add_bool(doc, obj, "dsForceDrm", true); + break; + } + } #elif defined(_WIN32) diff --git a/src/options/general.h b/src/options/general.h index 156991028..98667c2f8 100644 --- a/src/options/general.h +++ b/src/options/general.h @@ -2,6 +2,13 @@ #include "util/FFstrbuf.h" +typedef enum FFDsForceDrmType +{ + FF_DS_FORCE_DRM_TYPE_FALSE = 0, // Disable + FF_DS_FORCE_DRM_TYPE_TRUE = 1, // Try `libdrm`, then `sysfs` if libdrm failed + FF_DS_FORCE_DRM_TYPE_SYSFS_ONLY, // Use `/sys/class/drm` only +} FFDsForceDrmType; + typedef struct FFOptionsGeneral { bool multithreading; @@ -12,7 +19,7 @@ typedef struct FFOptionsGeneral FFstrbuf playerName; FFstrbuf osFile; bool escapeBedrock; - bool dsForceDrm; + FFDsForceDrmType dsForceDrm; #elif defined(_WIN32) int32_t wmiTimeout; #endif