mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 17:41:41 +01:00
reworked resolution
This commit is contained in:
+55
-4
@@ -1,17 +1,68 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include "X11/extensions/Xrandr.h"
|
||||
#include "dlfcn.h"
|
||||
|
||||
short getCurrentRate(Display* display)
|
||||
{
|
||||
void* xrandr = dlopen("libXrandr.so", RTLD_LAZY);
|
||||
if(xrandr == NULL)
|
||||
return 0;
|
||||
|
||||
Window root = RootWindow(display, 0);
|
||||
|
||||
XRRScreenConfiguration*(*ffXRRGetScreenInfo)(Display*, Window) = dlsym(xrandr, "XRRGetScreenInfo");
|
||||
if(ffXRRGetScreenInfo == NULL)
|
||||
return 0;
|
||||
|
||||
short(*ffXRRConfigCurrentRate)(XRRScreenConfiguration*) = dlsym(xrandr, "XRRConfigCurrentRate");
|
||||
if(ffXRRConfigCurrentRate == NULL)
|
||||
return 0;
|
||||
|
||||
XRRScreenConfiguration* xrrscreenconf = ffXRRGetScreenInfo(display, root);
|
||||
if(xrrscreenconf == NULL)
|
||||
return 0;
|
||||
|
||||
short currentRate = ffXRRConfigCurrentRate(xrrscreenconf);
|
||||
|
||||
void(*ffXRRFreeScreenConfigInfo)(XRRScreenConfiguration*) = dlsym(xrandr, "XRRFreeScreenConfigInfo");
|
||||
if(ffXRRFreeScreenConfigInfo != NULL)
|
||||
ffXRRFreeScreenConfigInfo(xrrscreenconf);
|
||||
|
||||
dlclose(xrandr);
|
||||
|
||||
return currentRate;
|
||||
}
|
||||
|
||||
void ffPrintResolution(FFstate* state)
|
||||
{
|
||||
if(ffPrintCachedValue(state, "Resolution"))
|
||||
return;
|
||||
|
||||
Display* display = XOpenDisplay(NULL);
|
||||
Screen* screen = DefaultScreenOfDisplay(display);
|
||||
void* x11 = dlopen("libX11.so", RTLD_LAZY);
|
||||
if(x11 == NULL)
|
||||
return;
|
||||
|
||||
Display*(*ffXOpenDisplay)(const char*) = dlsym(x11, "XOpenDisplay");
|
||||
if(ffXOpenDisplay == NULL)
|
||||
return;
|
||||
|
||||
Display* display = ffXOpenDisplay(NULL);
|
||||
if(display == NULL)
|
||||
return;
|
||||
|
||||
Screen* screen = DefaultScreenOfDisplay(display);
|
||||
|
||||
short currentRate = getCurrentRate(display);
|
||||
|
||||
dlclose(x11);
|
||||
|
||||
char resolution[1024];
|
||||
sprintf(resolution, "%ix%i", screen->width, screen->height);
|
||||
|
||||
if(currentRate == 0)
|
||||
sprintf(resolution, "%ix%i", screen->width, screen->height);
|
||||
else
|
||||
sprintf(resolution, "%ix%i @ %dHz", screen->width, screen->height, currentRate);
|
||||
|
||||
ffPrintAndSaveCachedValue(state, "Resolution", resolution);
|
||||
}
|
||||
+9
-8
@@ -27,14 +27,15 @@ void printTerminalName(FFstate* state, const char* pid)
|
||||
fclose(stat);
|
||||
|
||||
if (
|
||||
strcmp(name, "bash") == 0 ||
|
||||
strcmp(name, "sh") == 0 ||
|
||||
strcmp(name, "zsh") == 0 ||
|
||||
strcmp(name, "ksh") == 0 ||
|
||||
strcmp(name, "fish") == 0 ||
|
||||
strcmp(name, "sudo") == 0 ||
|
||||
strcmp(name, "su") == 0 ||
|
||||
strcmp(name, "doas") == 0 )
|
||||
strcmp(name, "bash") == 0 ||
|
||||
strcmp(name, "sh") == 0 ||
|
||||
strcmp(name, "zsh") == 0 ||
|
||||
strcmp(name, "ksh") == 0 ||
|
||||
strcmp(name, "fish") == 0 ||
|
||||
strcmp(name, "sudo") == 0 ||
|
||||
strcmp(name, "su") == 0 ||
|
||||
strcmp(name, "doas") == 0 ||
|
||||
strcmp(name, "strace") == 0 )
|
||||
{
|
||||
printTerminalName(state, ppid);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user