mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
NativeResolution (Linux): add support
This commit is contained in:
parent
a58db92ab8
commit
c28ced9dcb
@ -356,6 +356,7 @@ set(LIBFASTFETCH_SRC
|
||||
src/modules/wifi/wifi.c
|
||||
src/modules/wm/wm.c
|
||||
src/modules/wmtheme/wmtheme.c
|
||||
src/util/edidHelper.c
|
||||
src/util/FFlist.c
|
||||
src/util/FFstrbuf.c
|
||||
src/util/platform/FFPlatform.c
|
||||
@ -394,7 +395,7 @@ if(LINUX)
|
||||
src/detection/gamepad/gamepad_linux.c
|
||||
src/detection/media/media_linux.c
|
||||
src/detection/memory/memory_linux.c
|
||||
src/detection/nativeresolution/nativeresolution_nosupport.c
|
||||
src/detection/nativeresolution/nativeresolution_linux.c
|
||||
src/detection/opengl/opengl_linux.c
|
||||
src/detection/os/os_linux.c
|
||||
src/detection/packages/packages_linux.c
|
||||
|
60
src/detection/nativeresolution/nativeresolution_linux.c
Normal file
60
src/detection/nativeresolution/nativeresolution_linux.c
Normal file
@ -0,0 +1,60 @@
|
||||
#include "nativeresolution.h"
|
||||
|
||||
#include "common/io/io.h"
|
||||
#include "util/edidHelper.h"
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
const char* ffDetectNativeResolution(FFlist* results)
|
||||
{
|
||||
const char* drmDirPath = "/sys/class/drm/";
|
||||
|
||||
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);
|
||||
ffStrbufAppendS(&drmDir, "/edid");
|
||||
|
||||
uint8_t edidData[128];
|
||||
if(ffReadFileData(drmDir.chars, sizeof(edidData), edidData) != sizeof(edidData))
|
||||
{
|
||||
ffStrbufSubstrBefore(&drmDir, drmDirLength);
|
||||
continue;
|
||||
}
|
||||
|
||||
uint32_t width, height;
|
||||
ffEdidGetNativeResolution(edidData, &width, &height);
|
||||
if (width != 0 && height != 0)
|
||||
{
|
||||
const char* plainName = entry->d_name;
|
||||
if (ffStrStartsWith(plainName, "card"))
|
||||
{
|
||||
const char* tmp = strchr(plainName + strlen("card"), '-');
|
||||
if (tmp) plainName = tmp + 1;
|
||||
}
|
||||
|
||||
FFNativeResolutionResult* display = (FFNativeResolutionResult*) ffListAdd(results);
|
||||
display->width = width;
|
||||
display->height = height;
|
||||
ffStrbufInitS(&display->name, plainName);
|
||||
}
|
||||
|
||||
ffStrbufSubstrBefore(&drmDir, drmDirLength);
|
||||
}
|
||||
|
||||
closedir(dirp);
|
||||
return NULL;
|
||||
}
|
8
src/util/edidHelper.c
Normal file
8
src/util/edidHelper.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include "edidHelper.h"
|
||||
|
||||
void ffEdidGetNativeResolution(uint8_t edid[128], uint32_t* width, uint32_t* height)
|
||||
{
|
||||
const int dtd = 54;
|
||||
*width = ((edid[dtd + 4] >> 4) << 8) | edid[dtd + 2];
|
||||
*height = ((edid[dtd + 7] >> 4) << 8) | edid[dtd + 5];
|
||||
}
|
10
src/util/edidHelper.h
Normal file
10
src/util/edidHelper.h
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef FF_INCLUDED_EDID_HELPER_H
|
||||
#define FF_INCLUDED_EDID_HELPER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void ffEdidGetNativeResolution(uint8_t edid[128], uint32_t* width, uint32_t* height);
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user