2021-02-18 22:25:36 +01:00
|
|
|
#include "fastfetch.h"
|
|
|
|
|
|
2021-02-27 14:40:03 +01:00
|
|
|
#include "X11/extensions/Xrandr.h"
|
|
|
|
|
#include "dlfcn.h"
|
|
|
|
|
|
2021-03-19 20:57:07 +01:00
|
|
|
static int getCurrentRate(FFinstance* instance, Display* display)
|
2021-02-27 14:40:03 +01:00
|
|
|
{
|
2021-03-11 22:15:48 +01:00
|
|
|
void* xrandr;
|
2021-03-23 19:48:52 +01:00
|
|
|
if(instance->config.libXrandr.length == 0)
|
2021-03-11 22:15:48 +01:00
|
|
|
xrandr = dlopen("libXrandr.so", RTLD_LAZY);
|
2021-03-23 19:48:52 +01:00
|
|
|
else
|
|
|
|
|
xrandr = dlopen(instance->config.libXrandr.chars, RTLD_LAZY);
|
2021-04-05 23:42:07 +02:00
|
|
|
|
2021-02-27 14:40:03 +01:00
|
|
|
if(xrandr == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
XRRScreenConfiguration*(*ffXRRGetScreenInfo)(Display*, Window) = dlsym(xrandr, "XRRGetScreenInfo");
|
|
|
|
|
if(ffXRRGetScreenInfo == NULL)
|
2021-04-05 23:42:07 +02:00
|
|
|
{
|
|
|
|
|
dlclose(xrandr);
|
2021-02-27 14:40:03 +01:00
|
|
|
return 0;
|
2021-04-05 23:42:07 +02:00
|
|
|
}
|
2021-02-27 14:40:03 +01:00
|
|
|
|
|
|
|
|
short(*ffXRRConfigCurrentRate)(XRRScreenConfiguration*) = dlsym(xrandr, "XRRConfigCurrentRate");
|
|
|
|
|
if(ffXRRConfigCurrentRate == NULL)
|
2021-04-05 23:42:07 +02:00
|
|
|
{
|
|
|
|
|
dlclose(xrandr);
|
2021-02-27 14:40:03 +01:00
|
|
|
return 0;
|
2021-04-05 23:42:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Window root = RootWindow(display, 0);
|
2021-02-27 14:40:03 +01:00
|
|
|
|
|
|
|
|
XRRScreenConfiguration* xrrscreenconf = ffXRRGetScreenInfo(display, root);
|
|
|
|
|
if(xrrscreenconf == NULL)
|
2021-04-05 23:42:07 +02:00
|
|
|
{
|
|
|
|
|
dlclose(xrandr);
|
2021-02-27 14:40:03 +01:00
|
|
|
return 0;
|
2021-04-05 23:42:07 +02:00
|
|
|
}
|
2021-02-27 14:40:03 +01:00
|
|
|
|
|
|
|
|
short currentRate = ffXRRConfigCurrentRate(xrrscreenconf);
|
|
|
|
|
|
|
|
|
|
void(*ffXRRFreeScreenConfigInfo)(XRRScreenConfiguration*) = dlsym(xrandr, "XRRFreeScreenConfigInfo");
|
|
|
|
|
if(ffXRRFreeScreenConfigInfo != NULL)
|
|
|
|
|
ffXRRFreeScreenConfigInfo(xrrscreenconf);
|
|
|
|
|
|
|
|
|
|
dlclose(xrandr);
|
|
|
|
|
|
2021-03-19 20:57:07 +01:00
|
|
|
return (int) currentRate;
|
2021-02-27 14:40:03 +01:00
|
|
|
}
|
2021-02-18 22:25:36 +01:00
|
|
|
|
2021-02-27 18:30:05 +01:00
|
|
|
void ffPrintResolution(FFinstance* instance)
|
2021-02-18 22:25:36 +01:00
|
|
|
{
|
2021-04-03 11:39:59 +02:00
|
|
|
if(ffPrintCachedValue(instance, &instance->config.resolutionFormat, "Resolution"))
|
2021-02-22 16:52:51 +01:00
|
|
|
return;
|
2021-02-18 22:25:36 +01:00
|
|
|
|
2021-03-11 22:15:48 +01:00
|
|
|
void* x11;
|
2021-03-23 19:48:52 +01:00
|
|
|
if(instance->config.libX11.length == 0)
|
2021-03-11 22:15:48 +01:00
|
|
|
x11 = dlopen("libX11.so", RTLD_LAZY);
|
2021-03-23 19:48:52 +01:00
|
|
|
else
|
|
|
|
|
x11 = dlopen(instance->config.libX11.chars, RTLD_LAZY);
|
2021-04-05 23:42:07 +02:00
|
|
|
|
2021-02-27 14:40:03 +01:00
|
|
|
if(x11 == NULL)
|
2021-02-27 14:46:31 +01:00
|
|
|
{
|
2021-04-03 11:39:59 +02:00
|
|
|
ffPrintError(instance, &instance->config.resolutionFormat, "Resolution", "dlopen(\"libX11.so\", RTLD_LAZY) == NULL");
|
2021-02-27 14:40:03 +01:00
|
|
|
return;
|
2021-02-27 14:46:31 +01:00
|
|
|
}
|
2021-02-27 14:40:03 +01:00
|
|
|
|
|
|
|
|
Display*(*ffXOpenDisplay)(const char*) = dlsym(x11, "XOpenDisplay");
|
|
|
|
|
if(ffXOpenDisplay == NULL)
|
2021-02-27 14:46:31 +01:00
|
|
|
{
|
2021-04-05 23:42:07 +02:00
|
|
|
dlclose(x11);
|
2021-04-03 11:39:59 +02:00
|
|
|
ffPrintError(instance, &instance->config.resolutionFormat, "Resolution", "dlsym(x11, \"XOpenDisplay\") == NULL");
|
2021-02-27 14:40:03 +01:00
|
|
|
return;
|
2021-02-27 14:46:31 +01:00
|
|
|
}
|
2021-02-27 14:40:03 +01:00
|
|
|
|
|
|
|
|
Display* display = ffXOpenDisplay(NULL);
|
|
|
|
|
if(display == NULL)
|
2021-02-27 14:46:31 +01:00
|
|
|
{
|
2021-04-05 23:42:07 +02:00
|
|
|
dlclose(x11);
|
2021-04-03 11:39:59 +02:00
|
|
|
ffPrintError(instance, &instance->config.resolutionFormat, "Resolution", "ffXOpenDisplay(NULL) == NULL");
|
2021-02-27 14:40:03 +01:00
|
|
|
return;
|
2021-02-27 14:46:31 +01:00
|
|
|
}
|
2021-02-27 14:40:03 +01:00
|
|
|
|
|
|
|
|
Screen* screen = DefaultScreenOfDisplay(display);
|
|
|
|
|
|
2021-03-19 20:57:07 +01:00
|
|
|
int currentRate = getCurrentRate(instance, display);
|
2021-02-27 14:40:03 +01:00
|
|
|
|
|
|
|
|
dlclose(x11);
|
2021-02-18 22:25:36 +01:00
|
|
|
|
2021-03-21 16:52:17 +01:00
|
|
|
FF_STRBUF_CREATE(resolution);
|
2021-03-19 20:57:07 +01:00
|
|
|
|
2021-03-23 19:48:52 +01:00
|
|
|
if(instance->config.resolutionFormat.length == 0)
|
2021-03-19 20:57:07 +01:00
|
|
|
{
|
2021-03-23 19:48:52 +01:00
|
|
|
ffStrbufAppendF(&resolution, "%ix%i", screen->width, screen->height);
|
2021-03-19 20:57:07 +01:00
|
|
|
|
2021-03-23 19:48:52 +01:00
|
|
|
if(currentRate > 0)
|
|
|
|
|
ffStrbufAppendF(&resolution, " @ %iHz", currentRate);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-03-19 20:57:07 +01:00
|
|
|
ffParseFormatString(&resolution, &instance->config.resolutionFormat, 3,
|
|
|
|
|
(FFformatarg){FF_FORMAT_ARG_TYPE_INT, &screen->width},
|
|
|
|
|
(FFformatarg){FF_FORMAT_ARG_TYPE_INT, &screen->height},
|
|
|
|
|
(FFformatarg){FF_FORMAT_ARG_TYPE_INT, ¤tRate}
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-02-22 16:52:51 +01:00
|
|
|
|
2021-04-03 11:39:59 +02:00
|
|
|
ffPrintAndSaveCachedValue(instance, &instance->config.resolutionKey, "Resolution", &resolution);
|
2021-03-19 20:57:07 +01:00
|
|
|
ffStrbufDestroy(&resolution);
|
2021-03-27 18:14:19 +01:00
|
|
|
}
|