Display: add options --display-detect-name and --display-precise-refresh-rate

This commit is contained in:
李通洲
2023-03-22 16:49:53 +08:00
parent 1ac90584cb
commit 642a0c78cc
9 changed files with 58 additions and 26 deletions
+1
View File
@@ -5,6 +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)
Bugfixes:
* Fix date time format
+2
View File
@@ -162,6 +162,8 @@ static void defaultConfig(FFinstance* instance)
instance->config.diskShowSubvolumes = false;
instance->config.displayCompactType = FF_DISPLAY_COMPACT_TYPE_NONE;
instance->config.displayDetectName = false;
instance->config.displayPreciseRefreshRate = false;
instance->config.bluetoothShowDisconnected = false;
+13 -1
View File
@@ -253,12 +253,24 @@
# Default is false.
#--bluetooth-show-disconnected false
# Display compact output
# Display compact output option
# Sets if all displays should be printed in one line
# Must be either original (print pixel resolution) or scaled (print scaled resolution)
# Default is none.
#--display-compact-type none
# Display detect name option
# Sets if display name should be detected and printed (if supported)
# Must be either true of false
# Default is false.
#--display-detect-name none
# Display precise refresh rate option
# Sets if decimal refresh rates should not be rounded into integers when printing
# Must be either true (keep decimals) of false (round into integers)
# Default is false.
#--display-precise-refresh-rate false
# Sound show all option
# Sets if all sound devices should be printed
# Must be either main, active or all. Default is main
+2
View File
@@ -114,6 +114,8 @@ Module specific options:
--disk-show-unknown <?value>: Set if unknown (unable to detect sizes) volumes should be printed. Default is false
--bluetooth-show-disconnected: <?value>: Set if disconnected bluetooth devices should be printed. Default is false
--display-compact-type: <?string>: Set if all displays should be printed in one line. Default is none
--display-detect-name: <?value>: Set if display name should be detected and printed (if supported). Default is false
--display-precise-refresh-rate: <?value>:Set if decimal refresh rates should not be rounded into integers when printing
--sound-type: <value>: Set what type of sound devices should be printed. Should be either main, active or all. Default is main
--battery-dir <folder>: The directory where the battery folders are. Standard: /sys/class/power_supply/
--cpu-temp <?value>: Detect and display CPU temperature if supported. Default is false
@@ -11,7 +11,7 @@
extern CFDictionaryRef CoreDisplay_DisplayCreateInfoDictionary(CGDirectDisplayID display) __attribute__((weak_import));
static void detectDisplays(FFDisplayServerResult* ds)
static void detectDisplays(FFDisplayServerResult* ds, bool detectName)
{
CGDirectDisplayID screens[128];
uint32_t screenCount;
@@ -41,7 +41,7 @@ static void detectDisplays(FFDisplayServerResult* ds)
FF_STRBUF_AUTO_DESTROY name;
ffStrbufInit(&name);
if(CoreDisplay_DisplayCreateInfoDictionary)
if(detectName && CoreDisplay_DisplayCreateInfoDictionary)
{
CFDictionaryRef FF_CFTYPE_AUTO_RELEASE displayInfo = CoreDisplay_DisplayCreateInfoDictionary(screen);
if(displayInfo)
@@ -120,5 +120,5 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds, const FFinstance* ins
ffStrbufAppendS(&ds->dePrettyName, "Aqua");
ffListInitA(&ds->displays, sizeof(FFDisplayResult), 4);
detectDisplays(ds);
detectDisplays(ds, instance->config.displayDetectName);
}
@@ -26,27 +26,8 @@ static CALLBACK WINBOOL enumMonitorProc(HMONITOR hMonitor, FF_MAYBE_UNUSED HDC h
return TRUE;
}
void ffConnectDisplayServerImpl(FFDisplayServerResult* ds, const FFinstance* instance)
static void detectDisplays(FFDisplayServerResult* ds, bool detectName)
{
FF_UNUSED(instance);
BOOL enabled;
if(SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled == TRUE)
{
ffStrbufInitS(&ds->wmProcessName, "dwm.exe");
ffStrbufInitS(&ds->wmPrettyName, "Desktop Window Manager");
}
else
{
ffStrbufInitS(&ds->wmProcessName, "internal");
ffStrbufInitS(&ds->wmPrettyName, "internal");
}
ffStrbufInit(&ds->wmProtocolName);
ffStrbufInit(&ds->deProcessName);
ffStrbufInit(&ds->dePrettyName);
ffStrbufInit(&ds->deVersion);
ffListInit(&ds->displays, sizeof(FFDisplayResult));
DISPLAYCONFIG_PATH_INFO paths[128];
uint32_t pathCount = sizeof(paths) / sizeof(paths[0]);
DISPLAYCONFIG_MODE_INFO modes[256];
@@ -94,7 +75,8 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds, const FFinstance* ins
FF_STRBUF_AUTO_DESTROY name;
ffStrbufInit(&name);
if(SUCCEEDED(DisplayConfigGetDeviceInfo(&targetName.header)) && targetName.flags.friendlyNameFromEdid)
if(detectName && SUCCEEDED(DisplayConfigGetDeviceInfo(&targetName.header)) && targetName.flags.friendlyNameFromEdid)
ffStrbufSetWS(&name, targetName.monitorFriendlyDeviceName);
ffdsAppendDisplay(ds,
@@ -106,6 +88,28 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds, const FFinstance* ins
&name);
}
}
}
void ffConnectDisplayServerImpl(FFDisplayServerResult* ds, const FFinstance* instance)
{
BOOL enabled;
if(SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled == TRUE)
{
ffStrbufInitS(&ds->wmProcessName, "dwm.exe");
ffStrbufInitS(&ds->wmPrettyName, "Desktop Window Manager");
}
else
{
ffStrbufInitS(&ds->wmProcessName, "internal");
ffStrbufInitS(&ds->wmPrettyName, "internal");
}
ffStrbufInit(&ds->wmProtocolName);
ffStrbufInit(&ds->deProcessName);
ffStrbufInit(&ds->dePrettyName);
ffStrbufInit(&ds->deVersion);
ffListInit(&ds->displays, sizeof(FFDisplayResult));
detectDisplays(ds, instance->config.displayDetectName);
//https://github.com/hykilpikonna/hyfetch/blob/master/neofetch#L2067
const FFOSResult* os = ffDetectOS(instance);
+4
View File
@@ -1276,6 +1276,10 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
"scaled", FF_DISPLAY_COMPACT_TYPE_SCALED_BIT,
NULL);
}
else if(strcasecmp(key, "--display-precise-refresh-rate") == 0)
instance->config.displayPreciseRefreshRate = optionParseBoolean(value);
else if(strcasecmp(key, "--display-detect-name") == 0)
instance->config.displayDetectName = optionParseBoolean(value);
else if(strcasecmp(key, "--bluetooth-show-disconnected") == 0)
instance->config.bluetoothShowDisconnected = optionParseBoolean(value);
else if(strcasecmp(key, "--sound-type") == 0)
+2
View File
@@ -209,6 +209,8 @@ typedef struct FFconfig
bool diskShowSubvolumes;
FFDisplayCompactType displayCompactType;
bool displayDetectName;
bool displayPreciseRefreshRate;
bool bluetoothShowDisconnected;
+6 -1
View File
@@ -70,7 +70,12 @@ void ffPrintDisplay(FFinstance* instance)
printf("%ix%i", result->width, result->height);
if(result->refreshRate > 0)
printf(" @ %iHz", (uint32_t) (result->refreshRate + 0.5));
{
if(instance->config.displayPreciseRefreshRate)
printf(" @ %gHz", ((int) (result->refreshRate * 1000 + 0.5)) / 1000.0);
else
printf(" @ %iHz", (uint32_t) (result->refreshRate + 0.5));
}
if(
result->scaledWidth > 0 && result->scaledWidth != result->width &&