Monitor: remove module

This commit is contained in:
李通洲
2024-09-30 23:35:34 +08:00
parent d5c395fb85
commit 316849e5df
18 changed files with 3 additions and 794 deletions
-7
View File
@@ -382,7 +382,6 @@ set(LIBFASTFETCH_SRC
src/modules/locale/locale.c
src/modules/localip/localip.c
src/modules/memory/memory.c
src/modules/monitor/monitor.c
src/modules/netio/netio.c
src/modules/opencl/opencl.c
src/modules/opengl/opengl.c
@@ -484,7 +483,6 @@ if(LINUX)
src/detection/gamepad/gamepad_linux.c
src/detection/media/media_linux.c
src/detection/memory/memory_linux.c
src/detection/monitor/monitor_linux.c
src/detection/netio/netio_linux.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_linux.c
@@ -549,7 +547,6 @@ elseif(ANDROID)
src/detection/gamepad/gamepad_nosupport.c
src/detection/media/media_nosupport.c
src/detection/memory/memory_linux.c
src/detection/monitor/monitor_nosupport.c
src/detection/netio/netio_linux.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_android.c
@@ -629,7 +626,6 @@ elseif(FreeBSD)
src/detection/gamepad/gamepad_bsd.c
src/detection/media/media_linux.c
src/detection/memory/memory_bsd.c
src/detection/monitor/monitor_linux.c
src/detection/netio/netio_bsd.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_linux.c
@@ -696,7 +692,6 @@ elseif(APPLE)
src/detection/gamepad/gamepad_apple.c
src/detection/media/media_apple.m
src/detection/memory/memory_apple.c
src/detection/monitor/monitor_apple.m
src/detection/netio/netio_bsd.c
src/detection/opengl/opengl_apple.c
src/detection/os/os_apple.m
@@ -764,7 +759,6 @@ elseif(WIN32)
src/detection/media/media_windows.c
src/detection/memory/memory_windows.c
src/detection/physicalmemory/physicalmemory_linux.c
src/detection/monitor/monitor_windows.c
src/detection/netio/netio_windows.c
src/detection/opengl/opengl_windows.c
src/detection/os/os_windows.cpp
@@ -848,7 +842,6 @@ elseif(SunOS)
src/detection/gamepad/gamepad_nosupport.c
src/detection/media/media_linux.c
src/detection/memory/memory_sunos.c
src/detection/monitor/monitor_linux.c
src/detection/netio/netio_sunos.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_sunos.c
-5
View File
@@ -684,7 +684,6 @@
"localip",
"media",
"memory",
"monitor",
"netio",
"opencl",
"opengl",
@@ -814,10 +813,6 @@
"const": "media",
"description": "Print playing song name"
},
{
"const": "monitor",
"description": "Print connected physical monitor information"
},
{
"const": "opencl",
"description": "Print highest OpenCL version supported by the GPU"
-1
View File
@@ -24,7 +24,6 @@
"editor",
"display",
"brightness",
"monitor",
"lm",
"de",
"wm",
-1
View File
@@ -26,7 +26,6 @@
"editor",
"display",
"brightness",
"monitor",
"lm",
"de",
"wm",
+3 -2
View File
@@ -119,9 +119,10 @@
"keyColor": "blue"
},
{
"type": "monitor",
"type": "display",
"key": "MONITOR ({name})",
"keyColor": "blue"
"keyColor": "blue",
"format": "{width}x{height} @ {refresh-rate} Hz - {physical-width}x{physical-height} mm ({inch} inches, {ppi} ppi)"
},
{
"type": "custom", // DesignInfo
-1
View File
@@ -87,7 +87,6 @@ static FFModuleBaseInfo* L[] = {
static FFModuleBaseInfo* M[] = {
(void*) &instance.config.modules.media,
(void*) &instance.config.modules.memory,
(void*) &instance.config.modules.monitor,
NULL,
};
-17
View File
@@ -1,17 +0,0 @@
#include "fastfetch.h"
typedef struct FFMonitorResult
{
FFstrbuf name;
uint32_t width; // native / maximum resolution, in pixels
uint32_t height; // native / maximum resolution, in pixels
double refreshRate;// maximum refresh rate in native resolution, in Hz
uint32_t physicalWidth; // in mm
uint32_t physicalHeight; // in mm
bool hdrCompatible;
uint16_t manufactureYear;
uint16_t manufactureWeek;
uint32_t serial;
} FFMonitorResult;
const char* ffDetectMonitor(FFlist* results);
-137
View File
@@ -1,137 +0,0 @@
#include "monitor.h"
#include "detection/displayserver/displayserver.h"
#include "util/apple/cf_helpers.h"
#include "util/edidHelper.h"
#import <AppKit/NSScreen.h>
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#ifdef MAC_OS_X_VERSION_10_15
extern CFDictionaryRef CoreDisplay_DisplayCreateInfoDictionary(CGDirectDisplayID display) __attribute__((weak_import));
extern Boolean CoreDisplay_Display_SupportsHDRMode(CGDirectDisplayID display) __attribute__((weak_import));
#else
#include <IOKit/graphics/IOGraphicsLib.h>
#endif
static bool detectHdrSupportWithNSScreen(FFDisplayResult* display)
{
NSScreen* mainScreen = NSScreen.mainScreen;
if (display->primary)
{
#ifdef MAC_OS_X_VERSION_10_15
return mainScreen.maximumPotentialExtendedDynamicRangeColorComponentValue > 1;
#else
return mainScreen.maximumExtendedDynamicRangeColorComponentValue > 1;
#endif
}
else
{
for (NSScreen* screen in NSScreen.screens)
{
if (screen == mainScreen) continue;
NSNumber* screenNumber = screen.deviceDescription[@"NSScreenNumber"];
if (screenNumber && screenNumber.longValue == (long) display->id)
{
#ifdef MAC_OS_X_VERSION_10_15
return screen.maximumPotentialExtendedDynamicRangeColorComponentValue > 1;
#else
return screen.maximumExtendedDynamicRangeColorComponentValue > 1;
#endif
}
}
}
return false;
}
static bool detectHdrSupport(CFDictionaryRef displayInfo, FFDisplayResult* display)
{
#ifdef MAC_OS_X_VERSION_10_15
if (CoreDisplay_Display_SupportsHDRMode)
{
if (CoreDisplay_Display_SupportsHDRMode(display->id))
return true;
}
#endif
return CFDictionaryContainsKey(displayInfo, CFSTR("ReferencePeakHDRLuminance")) ||
detectHdrSupportWithNSScreen(display);
}
const char* ffDetectMonitor(FFlist* results)
{
#ifdef MAC_OS_X_VERSION_10_15
if(!CoreDisplay_DisplayCreateInfoDictionary) return "CoreDisplay_DisplayCreateInfoDictionary is not available";
#endif
const FFDisplayServerResult* displayServer = ffConnectDisplayServer();
FF_LIST_FOR_EACH(FFDisplayResult, display, displayServer->displays)
{
#ifdef MAC_OS_X_VERSION_10_15
CFDictionaryRef FF_CFTYPE_AUTO_RELEASE displayInfo = CoreDisplay_DisplayCreateInfoDictionary((CGDirectDisplayID) display->id);
#else
io_service_t servicePort = CGDisplayIOServicePort((CGDirectDisplayID) display->id);
CFDictionaryRef FF_CFTYPE_AUTO_RELEASE displayInfo = IODisplayCreateInfoDictionary(servicePort, kIODisplayOnlyPreferredName);
#endif
if(!displayInfo) continue;
bool isVirtual = false;
if (ffCfDictGetBool(displayInfo, CFSTR("kCGDisplayIsVirtualDevice"), &isVirtual) == NULL && isVirtual)
continue;
uint8_t edidData[128] = {};
uint32_t edidLength = 0;
if (ffCfDictGetData(displayInfo, CFSTR(kIODisplayEDIDKey), 0, sizeof(edidData), edidData, &edidLength) == NULL)
{
uint32_t width, height;
ffEdidGetPhysicalResolution(edidData, &width, &height);
if (width > 0 && height > 0)
{
FFMonitorResult* monitor = (FFMonitorResult*) ffListAdd(results);
ffStrbufInitCopy(&monitor->name, &display->name);
monitor->width = width;
monitor->height = height;
ffEdidGetPhysicalSize(edidData, &monitor->physicalWidth, &monitor->physicalHeight);
monitor->hdrCompatible = detectHdrSupport(displayInfo, display);
continue;
}
}
int width, height;
if (ffCfDictGetInt(displayInfo, CFSTR("kCGDisplayPixelWidth"), &width) || // Default resolution (limited by connectors, GPUs, etc.)
ffCfDictGetInt(displayInfo, CFSTR("kCGDisplayPixelHeight"), &height) ||
width <= 0 || height <= 0)
continue;
FFMonitorResult* monitor = (FFMonitorResult*) ffListAdd(results);
monitor->width = (uint32_t) width;
monitor->height = (uint32_t) height;
ffStrbufInitCopy(&monitor->name, &display->name);
CGSize size = CGDisplayScreenSize((CGDirectDisplayID) display->id);
monitor->physicalWidth = (uint32_t) (size.width + 0.5);
monitor->physicalHeight = (uint32_t) (size.height + 0.5);
monitor->hdrCompatible = detectHdrSupport(displayInfo, display);
monitor->serial = CGDisplaySerialNumber((CGDirectDisplayID) display->id);
FF_CFTYPE_AUTO_RELEASE CFArrayRef modes = CGDisplayCopyAllDisplayModes((CGDirectDisplayID) display->id, NULL);
double maxRefreshRate = 0;
for (uint32_t j = 0; j < CFArrayGetCount(modes); ++j)
{
CGDisplayModeRef mode = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, j);
if (CGDisplayModeGetWidth(mode) == (uint32_t) width && CGDisplayModeGetHeight(mode) == (uint32_t) height)
{
double refreshRate = CGDisplayModeGetRefreshRate(mode);
if (refreshRate > maxRefreshRate) maxRefreshRate = refreshRate;
}
}
monitor->refreshRate = maxRefreshRate;
int64_t year, week;
if (ffCfDictGetInt64(displayInfo, CFSTR("DisplayYearManufacture"), &year) == NULL)
monitor->manufactureYear = (uint16_t) year;
if (ffCfDictGetInt64(displayInfo, CFSTR("DisplayWeekManufacture"), &week) == NULL)
monitor->manufactureWeek = (uint16_t) week;
}
return NULL;
}
-254
View File
@@ -1,254 +0,0 @@
#include "monitor.h"
#include "common/io/io.h"
#include "common/library.h"
#include "util/edidHelper.h"
#include "util/stringUtils.h"
#ifdef FF_HAVE_XRANDR
#include <X11/extensions/Xrandr.h>
#include <X11/Xlib.h>
typedef struct XrandrData
{
FF_LIBRARY_SYMBOL(XInternAtom)
FF_LIBRARY_SYMBOL(XGetAtomName);
FF_LIBRARY_SYMBOL(XFree);
FF_LIBRARY_SYMBOL(XRRGetMonitors)
FF_LIBRARY_SYMBOL(XRRGetOutputInfo)
FF_LIBRARY_SYMBOL(XRRGetOutputProperty)
FF_LIBRARY_SYMBOL(XRRFreeOutputInfo)
FF_LIBRARY_SYMBOL(XRRFreeMonitors)
//Init once
Display* display;
//Init per screen
XRRScreenResources* screenResources;
} XrandrData;
static const char* xrandrHandleMonitors(XrandrData* data, Screen* screen, FFlist* results)
{
int numberOfMonitors;
XRRMonitorInfo* monitorInfos = data->ffXRRGetMonitors(data->display, RootWindowOfScreen(screen), True, &numberOfMonitors);
if(monitorInfos == NULL)
return "XRRGetMonitors() failed";
for(int i = 0; i < numberOfMonitors; i++)
{
XRRMonitorInfo* monitorInfo = &monitorInfos[i];
for(int i = 0; i < monitorInfo->noutput; i++)
{
RROutput output = monitorInfo->outputs[i];
XRROutputInfo* outputInfo = data->ffXRRGetOutputInfo(data->display, data->screenResources, output);
if(outputInfo == NULL)
continue;
FFMonitorResult* display = (FFMonitorResult*) ffListAdd(results);
ffStrbufInit(&display->name);
display->width = 0;
display->height = 0;
display->manufactureYear = 0;
display->manufactureWeek = 0;
display->serial = 0;
display->hdrCompatible = false;
display->refreshRate = 0;
bool edidOk = false;
Atom atomEdid = data->ffXInternAtom(data->display, "EDID", true);
if (atomEdid != None)
{
int actual_format = 0;
unsigned long nitems = 0, bytes_after = 0;
Atom actual_type = None;
uint8_t* edidData = NULL;
if (data->ffXRRGetOutputProperty(data->display, output, atomEdid, 0, 100, false, false, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, &edidData) == Success)
{
if (nitems > 0 && nitems % 128 == 0)
{
ffEdidGetName(edidData, &display->name);
ffEdidGetPhysicalResolution(edidData, &display->width, &display->height);
ffEdidGetPhysicalSize(edidData, &display->physicalWidth, &display->physicalHeight);
ffEdidGetSerialAndManufactureDate(edidData, &display->serial, &display->manufactureYear, &display->manufactureWeek);
display->hdrCompatible = ffEdidGetHdrCompatible(edidData, (uint32_t) nitems);
edidOk = true;
}
}
if (edidData)
data->ffXFree(edidData);
}
if (!edidOk)
{
ffStrbufSetS(&display->name, data->ffXGetAtomName(data->display, monitorInfo->name));
display->physicalWidth = (uint32_t) monitorInfo->mwidth;
display->physicalHeight = (uint32_t) monitorInfo->mheight;
display->width = (uint32_t) monitorInfo->width;
display->height = (uint32_t) monitorInfo->height;
}
for(int i = 0; i < data->screenResources->nmode; i++)
{
bool found = false;
for (int j = 0; j < outputInfo->nmode; ++j)
{
if (data->screenResources->modes[i].id == outputInfo->modes[j])
{
found = true;
break;
}
}
if(found)
{
XRRModeInfo* modeInfo = &data->screenResources->modes[i];
double refreshRate = (double) modeInfo->dotClock / (double) (modeInfo->hTotal * modeInfo->vTotal);
if (edidOk)
{
if (display->width != modeInfo->width || display->height != modeInfo->height)
continue;
}
else
{
if (display->width < modeInfo->width || display->height < modeInfo->height)
{
display->width = (uint32_t) modeInfo->width;
display->height = (uint32_t) modeInfo->height;
display->refreshRate = refreshRate;
continue;
}
else if (display->width != modeInfo->width || display->height != modeInfo->height)
continue;
}
if (display->refreshRate < refreshRate)
display->refreshRate = refreshRate;
}
}
data->ffXRRFreeOutputInfo(outputInfo);
}
}
data->ffXRRFreeMonitors(monitorInfos);
return NULL;
}
static const char* detectByXrandr(FFlist* results)
{
FF_LIBRARY_LOAD(xrandr, "dlopen libXrandr" FF_LIBRARY_EXTENSION " failed", "libXrandr" FF_LIBRARY_EXTENSION, 3)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(xrandr, XOpenDisplay)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(xrandr, XCloseDisplay)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(xrandr, XRRGetScreenResourcesCurrent);
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(xrandr, XRRFreeScreenResources);
XrandrData data;
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(xrandr, data, XInternAtom);
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(xrandr, data, XGetAtomName);
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(xrandr, data, XFree);
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(xrandr, data, XRRGetMonitors);
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(xrandr, data, XRRGetOutputInfo);
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(xrandr, data, XRRGetOutputProperty);
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(xrandr, data, XRRFreeOutputInfo);
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(xrandr, data, XRRFreeMonitors);
data.display = ffXOpenDisplay(NULL);
if(data.display == NULL)
return "XOpenDisplay() failed";
for(int i = 0; i < ScreenCount(data.display); i++)
{
Screen* screen = ScreenOfDisplay(data.display, i);
data.screenResources = ffXRRGetScreenResourcesCurrent(data.display, RootWindowOfScreen(screen));
xrandrHandleMonitors(&data, screen, results);
ffXRRFreeScreenResources(data.screenResources);
}
ffXCloseDisplay(data.display);
return NULL;
}
#endif // FF_HAVE_XRANDR
#ifdef __linux__
FF_MAYBE_UNUSED static const char* detectByDrm(FFlist* results)
{
const char* drmDirPath = "/sys/class/drm/";
FF_AUTO_CLOSE_DIR DIR* dirp = opendir(drmDirPath);
if(dirp == NULL)
return "opendir(drmDirPath) == NULL";
FF_STRBUF_AUTO_DESTROY drmDir = ffStrbufCreateA(64);
ffStrbufAppendS(&drmDir, drmDirPath);
uint32_t drmDirLength = drmDir.length;
struct dirent* entry;
while((entry = readdir(dirp)) != NULL)
{
if(ffStrEquals(entry->d_name, ".") || ffStrEquals(entry->d_name, ".."))
continue;
ffStrbufAppendS(&drmDir, entry->d_name);
uint32_t drmDirWithDnameLength = drmDir.length;
ffStrbufAppendS(&drmDir, "/status");
char status = 'd'; // disconnected
ffReadFileData(drmDir.chars, sizeof(status), &status);
if (status != 'c') // connected
{
ffStrbufSubstrBefore(&drmDir, drmDirLength);
continue;
}
ffStrbufSubstrBefore(&drmDir, drmDirWithDnameLength);
ffStrbufAppendS(&drmDir, "/edid");
uint8_t edidData[512];
ssize_t edidLength = ffReadFileData(drmDir.chars, sizeof(edidData), edidData);
if(edidLength <= 0 || edidLength % 128 != 0)
{
ffStrbufSubstrBefore(&drmDir, drmDirLength);
continue;
}
uint32_t width, height;
ffEdidGetPhysicalResolution(edidData, &width, &height);
if (width != 0 && height != 0)
{
FFMonitorResult* display = (FFMonitorResult*) ffListAdd(results);
display->width = width;
display->height = height;
ffStrbufInit(&display->name);
ffEdidGetName(edidData, &display->name);
ffEdidGetPhysicalSize(edidData, &display->physicalWidth, &display->physicalHeight);
ffEdidGetSerialAndManufactureDate(edidData, &display->serial, &display->manufactureYear, &display->manufactureWeek);
display->hdrCompatible = ffEdidGetHdrCompatible(edidData, (uint32_t) edidLength);
display->refreshRate = 0;
}
ffStrbufSubstrBefore(&drmDir, drmDirLength);
}
return NULL;
}
#endif // __linux__
const char* ffDetectMonitor(FFlist* results)
{
const char* error = NULL;
#if defined(__linux__)
error = detectByDrm(results);
if (!error && results->length > 0) return NULL;
#endif
#ifdef FF_HAVE_XRANDR
error = detectByXrandr(results);
if (!error) return NULL;
#endif
return "Fastfetch was compiled without xrandr support";
}
@@ -1,6 +0,0 @@
#include "monitor.h"
const char* ffDetectMonitor(FF_MAYBE_UNUSED FFlist* results)
{
return "Not supported on this platform";
}
-116
View File
@@ -1,116 +0,0 @@
#include "monitor.h"
#include "util/edidHelper.h"
#include "util/windows/registry.h"
#include <windows.h>
const char* ffDetectMonitor(FFlist* results)
{
DISPLAYCONFIG_PATH_INFO paths[128];
uint32_t pathCount = sizeof(paths) / sizeof(paths[0]);
DISPLAYCONFIG_MODE_INFO modes[256];
uint32_t modeCount = sizeof(modes) / sizeof(modes[0]);
if (QueryDisplayConfig(
QDC_ONLY_ACTIVE_PATHS,
&pathCount,
paths,
&modeCount,
modes,
NULL) != ERROR_SUCCESS)
return "QueryDisplayConfig() failed";
if (pathCount == 0)
return "QueryDisplayConfig() returns 0 paths";
for (uint32_t i = 0; i < pathCount; ++i)
{
DISPLAYCONFIG_PATH_INFO* path = &paths[i];
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)
continue;
wchar_t regPath[256] = L"SYSTEM\\CurrentControlSet\\Enum";
wchar_t* pRegPath = regPath + strlen("SYSTEM\\CurrentControlSet\\Enum");
wchar_t* pDevPath = targetName.monitorDevicePath + strlen("\\\\?");
while (*pDevPath && *pDevPath != L'{')
{
if (*pDevPath == L'#')
*pRegPath = L'\\';
else
*pRegPath = *pDevPath;
++pRegPath;
++pDevPath;
assert(pRegPath < regPath + sizeof(regPath) / sizeof(wchar_t) + strlen("Device Parameters"));
}
wcscpy(pRegPath, L"Device Parameters");
uint8_t edidData[1024];
DWORD edidLength = sizeof(edidData);
if (RegGetValueW(HKEY_LOCAL_MACHINE, regPath, L"EDID", RRF_RT_REG_BINARY, NULL, edidData, &edidLength) == ERROR_SUCCESS &&
edidLength > 0 && edidLength % 128 == 0)
{
uint32_t width, height;
ffEdidGetPhysicalResolution(edidData, &width, &height);
if (width == 0 || height == 0) continue;
FFMonitorResult* display = (FFMonitorResult*) ffListAdd(results);
display->width = width;
display->height = height;
ffEdidGetSerialAndManufactureDate(edidData, &display->serial, &display->manufactureYear, &display->manufactureWeek);
ffStrbufInit(&display->name);
ffEdidGetName(edidData, &display->name);
ffEdidGetPhysicalSize(edidData, &display->physicalWidth, &display->physicalHeight);
display->refreshRate = 0;
display->hdrCompatible = false;
DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO advColorInfo = {
.header = {
.type = DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO,
.size = sizeof(advColorInfo),
.adapterId = path->targetInfo.adapterId,
.id = path->targetInfo.id,
}
};
if (DisplayConfigGetDeviceInfo(&advColorInfo.header) == ERROR_SUCCESS)
display->hdrCompatible = !!advColorInfo.advancedColorSupported;
else
display->hdrCompatible = ffEdidGetHdrCompatible(edidData, (uint32_t) edidLength);
DISPLAYCONFIG_TARGET_PREFERRED_MODE preferredMode = {
.header = {
.type = DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_PREFERRED_MODE,
.size = sizeof(preferredMode),
.adapterId = path->targetInfo.adapterId,
.id = path->targetInfo.id,
}
};
if (DisplayConfigGetDeviceInfo(&preferredMode.header) == ERROR_SUCCESS)
{
if (preferredMode.width == width && preferredMode.height == height)
{
DISPLAYCONFIG_RATIONAL freq = preferredMode.targetMode.targetVideoSignalInfo.vSyncFreq;
display->refreshRate = freq.Numerator / (double) freq.Denominator;
}
}
DISPLAYCONFIG_VIDEO_SIGNAL_INFO current = modes[path->targetInfo.modeInfoIdx].targetMode.targetVideoSignalInfo;
if (current.activeSize.cx == width && current.activeSize.cy == height)
{
double refreshRate = current.vSyncFreq.Numerator / (double) current.vSyncFreq.Denominator;
if (refreshRate > display->refreshRate) display->refreshRate = refreshRate;
}
}
}
return NULL;
}
-1
View File
@@ -40,7 +40,6 @@
#include "modules/localip/localip.h"
#include "modules/media/media.h"
#include "modules/memory/memory.h"
#include "modules/monitor/monitor.h"
#include "modules/netio/netio.h"
#include "modules/opengl/opengl.h"
#include "modules/opencl/opencl.h"
-222
View File
@@ -1,222 +0,0 @@
#include "common/printing.h"
#include "common/jsonconfig.h"
#include "detection/monitor/monitor.h"
#include "modules/monitor/monitor.h"
#include "util/stringUtils.h"
#include <math.h>
#define FF_MONITOR_NUM_FORMAT_ARGS 11
void ffPrintMonitor(FFMonitorOptions* options)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFMonitorResult));
const char* error = ffDetectMonitor(&result);
if(error)
{
ffPrintError(FF_MONITOR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
}
if(!result.length)
{
ffPrintError(FF_MONITOR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No physical display detected");
return;
}
FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate();
uint32_t index = 0;
FF_LIST_FOR_EACH(FFMonitorResult, display, result)
{
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;
ffStrbufClear(&key);
if(options->moduleArgs.key.length == 0)
{
ffStrbufAppendF(&key, "%s (%s)", FF_MONITOR_MODULE_NAME, display->name.chars);
}
else
{
uint32_t moduleIndex = result.length == 1 ? 0 : index + 1;
FF_PARSE_FORMAT_STRING_CHECKED(&key, &options->moduleArgs.key, 3, ((FFformatarg[]){
FF_FORMAT_ARG(moduleIndex, "index"),
FF_FORMAT_ARG(display->name, "name"),
FF_FORMAT_ARG(options->moduleArgs.keyIcon, "icon"),
}));
}
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY);
printf("%ux%u px", display->width, display->height);
if (display->refreshRate > 0)
printf(" @ %g Hz", ((int) (display->refreshRate * 1000 + 0.5)) / 1000.0);
if (inch > 0)
printf(" - %ux%u mm (%.2f inches, %.2f ppi)\n", display->physicalWidth, display->physicalHeight, inch, ppi);
else
putchar('\n');
}
else
{
char buf[32];
if (display->serial)
{
const uint8_t* nums = (uint8_t*) &display->serial;
snprintf(buf, sizeof(buf), "%2X-%2X-%2X-%2X", nums[0], nums[1], nums[2], nums[3]);
}
else
buf[0] = '\0';
FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_MONITOR_NUM_FORMAT_ARGS, ((FFformatarg[]) {
FF_FORMAT_ARG(display->name, "name"),
FF_FORMAT_ARG(display->width, "width"),
FF_FORMAT_ARG(display->height, "height"),
FF_FORMAT_ARG(display->physicalWidth, "physical-width"),
FF_FORMAT_ARG(display->physicalHeight, "physical-height"),
FF_FORMAT_ARG(inch, "inch"),
FF_FORMAT_ARG(ppi, "ppi"),
FF_FORMAT_ARG(display->manufactureYear, "manufacture-year"),
FF_FORMAT_ARG(display->manufactureWeek, "manufacture-week"),
FF_FORMAT_ARG(buf, "serial"),
FF_FORMAT_ARG(display->refreshRate, "refresh-rate"),
}));
}
ffStrbufDestroy(&display->name);
++index;
}
}
bool ffParseMonitorCommandOptions(FFMonitorOptions* options, const char* key, const char* value)
{
const char* subKey = ffOptionTestPrefix(key, FF_MONITOR_MODULE_NAME);
if (!subKey) return false;
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
return true;
return false;
}
void ffParseMonitorJsonObject(FFMonitorOptions* options, yyjson_val* module)
{
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue;
ffPrintError(FF_MONITOR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", key);
}
}
void ffGenerateMonitorJsonConfig(FFMonitorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
__attribute__((__cleanup__(ffDestroyMonitorOptions))) FFMonitorOptions defaultOptions;
ffInitMonitorOptions(&defaultOptions);
ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs);
}
void ffGenerateMonitorJsonResult(FF_MAYBE_UNUSED FFMonitorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFMonitorResult));
const char* error = ffDetectMonitor(&results);
if (error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
}
else if(results.length == 0)
{
yyjson_mut_obj_add_str(doc, module, "error", "No monitors found");
}
else
{
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
FF_LIST_FOR_EACH(FFMonitorResult, item, results)
{
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
yyjson_mut_obj_add_bool(doc, obj, "hdrCompatible", item->hdrCompatible);
yyjson_mut_obj_add_strbuf(doc, obj, "name", &item->name);
yyjson_mut_val* resolution = yyjson_mut_obj_add_obj(doc, obj, "resolution");
yyjson_mut_obj_add_uint(doc, resolution, "width", item->width);
yyjson_mut_obj_add_uint(doc, resolution, "height", item->height);
yyjson_mut_val* physical = yyjson_mut_obj_add_obj(doc, obj, "physical");
yyjson_mut_obj_add_uint(doc, physical, "height", item->physicalHeight);
yyjson_mut_obj_add_uint(doc, physical, "width", item->physicalWidth);
yyjson_mut_obj_add_real(doc, obj, "refreshRate", item->refreshRate);
if (item->manufactureYear)
{
yyjson_mut_val* manufactureDate = yyjson_mut_obj_add_obj(doc, obj, "manufactureDate");
yyjson_mut_obj_add_uint(doc, manufactureDate, "year", item->manufactureYear);
yyjson_mut_obj_add_uint(doc, manufactureDate, "week", item->manufactureWeek);
}
else
{
yyjson_mut_obj_add_null(doc, obj, "manufactureDate");
}
if (item->serial)
yyjson_mut_obj_add_uint(doc, obj, "serial", item->serial);
else
yyjson_mut_obj_add_null(doc, obj, "serial");
}
}
FF_LIST_FOR_EACH(FFMonitorResult, item, results)
{
ffStrbufDestroy(&item->name);
}
}
void ffPrintMonitorHelpFormat(void)
{
FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_MONITOR_MODULE_NAME, "{2}x{3} px - {4}x{5} mm ({6} inches, {7} ppi)", FF_MONITOR_NUM_FORMAT_ARGS, ((const char* []) {
"Display name - name",
"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",
}));
}
void ffInitMonitorOptions(FFMonitorOptions* options)
{
ffOptionInitModuleBaseInfo(
&options->moduleInfo,
FF_MONITOR_MODULE_NAME,
"Print connected physical monitor information",
ffParseMonitorCommandOptions,
ffParseMonitorJsonObject,
ffPrintMonitor,
ffGenerateMonitorJsonResult,
ffPrintMonitorHelpFormat,
ffGenerateMonitorJsonConfig
);
ffOptionInitModuleArg(&options->moduleArgs, "󰹑");
}
void ffDestroyMonitorOptions(FFMonitorOptions* options)
{
ffOptionDestroyModuleArg(&options->moduleArgs);
}
-9
View File
@@ -1,9 +0,0 @@
#pragma once
#include "fastfetch.h"
#define FF_MONITOR_MODULE_NAME "Monitor"
void ffPrintMonitor(FFMonitorOptions* options);
void ffInitMonitorOptions(FFMonitorOptions* options);
void ffDestroyMonitorOptions(FFMonitorOptions* options);
-11
View File
@@ -1,11 +0,0 @@
#pragma once
// This file will be included in "fastfetch.h", do NOT put unnecessary things here
#include "common/option.h"
typedef struct FFMonitorOptions
{
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
} FFMonitorOptions;
-1
View File
@@ -40,7 +40,6 @@
#include "modules/localip/option.h"
#include "modules/media/option.h"
#include "modules/memory/option.h"
#include "modules/monitor/option.h"
#include "modules/netio/option.h"
#include "modules/opengl/option.h"
#include "modules/opencl/option.h"
-2
View File
@@ -41,7 +41,6 @@ void ffOptionsInitModules(FFOptionsModules* options)
ffInitLocaleOptions(&options->locale);
ffInitMediaOptions(&options->media);
ffInitMemoryOptions(&options->memory);
ffInitMonitorOptions(&options->monitor);
ffInitNetIOOptions(&options->netIo);
ffInitOSOptions(&options->os);
ffInitOpenCLOptions(&options->openCL);
@@ -116,7 +115,6 @@ void ffOptionsDestroyModules(FFOptionsModules* options)
ffDestroyLocaleOptions(&options->locale);
ffDestroyMediaOptions(&options->media);
ffDestroyMemoryOptions(&options->memory);
ffDestroyMonitorOptions(&options->monitor);
ffDestroyNetIOOptions(&options->netIo);
ffDestroyOSOptions(&options->os);
ffDestroyOpenCLOptions(&options->openCL);
-1
View File
@@ -42,7 +42,6 @@ typedef struct FFOptionsModules
FFLocaleOptions locale;
FFMediaOptions media;
FFMemoryOptions memory;
FFMonitorOptions monitor;
FFNetIOOptions netIo;
FFOSOptions os;
FFOpenCLOptions openCL;