mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 16:26:39 +01:00
reworked resolution
This commit is contained in:
+2
-4
@@ -17,9 +17,7 @@ execute_process(
|
||||
|
||||
set(PROJECT_VERSION "r${GIT_REV_LIST}.${GIT_REV_PARSE}")
|
||||
|
||||
include (${CMAKE_ROOT}/Modules/FindX11.cmake)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -march=native -O3 -pipe -fno-plt") # for testing
|
||||
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -march=native -O3 -pipe -fno-plt") # for testing
|
||||
|
||||
configure_file(src/fastfetch_config.h.in fastfetch_config.h)
|
||||
include_directories(${PROJECT_BINARY_DIR})
|
||||
@@ -52,6 +50,6 @@ add_executable(${PROJECT_NAME}
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
${X11_LIBRARIES}
|
||||
${CMAKE_DL_LIBS}
|
||||
pci
|
||||
)
|
||||
+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