Files
fastfetch/src/detection/displayserver/linux/displayserver_linux.c
T

109 lines
3.0 KiB
C
Raw Normal View History

2022-09-06 15:42:37 +02:00
#include "displayserver_linux.h"
#include "util/stringUtils.h"
2022-06-18 14:25:31 +02:00
2022-01-02 16:55:26 +01:00
#include <dirent.h>
static void parseDRM(FFDisplayServerResult* result)
{
const char* drmDirPath = "/sys/class/drm/";
DIR* dirp = opendir(drmDirPath);
if(dirp == NULL)
return;
FF_STRBUF_AUTO_DESTROY drmDir = ffStrbufCreateA(64);
2022-01-02 16:55:26 +01:00
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;
2022-01-02 16:55:26 +01:00
ffStrbufAppendS(&drmDir, entry->d_name);
ffStrbufAppendS(&drmDir, "/modes");
FILE* modeFile = fopen(drmDir.chars, "r");
if(modeFile == NULL)
{
ffStrbufSubstrBefore(&drmDir, drmDirLength);
continue;
}
2023-06-20 18:12:12 +08:00
uint32_t width = 0, height = 0;
int scanned = fscanf(modeFile, "%ux%u", &width, &height);
if(scanned == 2 && 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;
}
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreateS(plainName);
ffdsAppendDisplay(
result,
width, height,
0,
0, 0,
0,
&name,
FF_DISPLAY_TYPE_UNKNOWN,
2023-07-08 10:06:04 +08:00
false,
0
2023-06-20 18:12:12 +08:00
);
}
2022-01-02 16:55:26 +01:00
fclose(modeFile);
ffStrbufSubstrBefore(&drmDir, drmDirLength);
}
closedir(dirp);
}
void ffConnectDisplayServerImpl(FFDisplayServerResult* ds)
2022-01-02 16:55:26 +01:00
{
2022-09-06 15:42:37 +02:00
ffStrbufInit(&ds->wmProcessName);
ffStrbufInit(&ds->wmPrettyName);
ffStrbufInit(&ds->wmProtocolName);
ffStrbufInit(&ds->deProcessName);
ffStrbufInit(&ds->dePrettyName);
ffStrbufInit(&ds->deVersion);
2023-01-18 01:37:47 +08:00
ffListInitA(&ds->displays, sizeof(FFDisplayResult), 4);
2022-01-02 16:55:26 +01:00
2023-07-31 23:11:39 +08:00
if (!instance.config.dsForceDrm)
{
//We try wayland as our prefered display server, as it supports the most features.
//This method can't detect the name of our WM / DE
ffdsConnectWayland(ds);
2022-01-02 16:55:26 +01:00
//Try the x11 libs, from most feature rich to least.
//We use the display list to detect if a connection is needed.
//They respect wmProtocolName, and only detect display if it is set.
2023-08-01 15:15:03 +08:00
if(ds->displays.length == 0)
2023-07-31 23:11:39 +08:00
ffdsConnectXcbRandr(ds);
2022-01-05 14:40:57 +01:00
if(ds->displays.length == 0)
ffdsConnectXrandr(ds);
2022-01-02 16:55:26 +01:00
if(ds->displays.length == 0)
ffdsConnectXcb(ds);
2022-01-05 14:40:57 +01:00
if(ds->displays.length == 0)
ffdsConnectXlib(ds);
2023-07-31 23:11:39 +08:00
}
2022-01-02 16:55:26 +01:00
2023-01-18 01:37:47 +08:00
//This display detection method is display server independent.
2022-01-02 16:55:26 +01:00
//Use it if all connections failed
2023-01-18 01:37:47 +08:00
if(ds->displays.length == 0)
2022-09-06 15:42:37 +02:00
parseDRM(ds);
2022-01-02 16:55:26 +01:00
//This fills in missing information about WM / DE by using env vars and iterating processes
ffdsDetectWMDE(ds);
2022-01-02 16:55:26 +01:00
}