mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
resolution options
This commit is contained in:
+16
-1
@@ -22,6 +22,11 @@ __fastfetch_complete_string()
|
||||
fi
|
||||
}
|
||||
|
||||
__fastfetch_complete_path()
|
||||
{
|
||||
COMPREPLY=($(compgen -A file -- "$CURRENT_WORD"))
|
||||
}
|
||||
|
||||
__fastfetch_complete_logo()
|
||||
{
|
||||
COMPREPLY=($(compgen -W "$(fastfetch --list-logos)" -- "$CURRENT_WORD"))
|
||||
@@ -32,6 +37,7 @@ __fastfetch_complete_option()
|
||||
local FF_OPTIONS_ALL=(
|
||||
"${FF_OPTIONS_BOOL[@]}"
|
||||
"${FF_OPTIONS_STRING[@]}"
|
||||
"${FF_OPTIONS_PATH[@]}"
|
||||
"${FF_OPTIONS_LOGO[@]}"
|
||||
)
|
||||
|
||||
@@ -91,11 +97,12 @@ __fastfetch_completion()
|
||||
"--host-version"
|
||||
"--kernel-release"
|
||||
"--kernel-version"
|
||||
"--shell-path"
|
||||
"--packages-combined"
|
||||
"--packages-combined-names"
|
||||
"--packages-pacman"
|
||||
"--packages-flatpak"
|
||||
"--shell-path"
|
||||
"--resolution-refreshrate"
|
||||
"--battery-manufacturer"
|
||||
"--battery-model"
|
||||
"--battery-technology"
|
||||
@@ -112,11 +119,17 @@ __fastfetch_completion()
|
||||
"-x"
|
||||
"--offsetx"
|
||||
"--packages-format"
|
||||
"--resolution-format"
|
||||
"--battery-format"
|
||||
"--structure"
|
||||
"--set"
|
||||
)
|
||||
|
||||
local FF_OPTIONS_PATH=(
|
||||
"--resolution-libX11"
|
||||
"--resolution-libXrandr"
|
||||
)
|
||||
|
||||
local FF_OPTIONS_LOGO=(
|
||||
"-l"
|
||||
"--logo"
|
||||
@@ -134,6 +147,8 @@ __fastfetch_completion()
|
||||
__fastfetch_complete_bool
|
||||
elif __fastfetch_previous_matches "${FF_OPTIONS_STRING[@]}"; then
|
||||
__fastfetch_complete_string
|
||||
elif __fastfetch_previous_matches "${FF_OPTIONS_PATH[@]}"; then
|
||||
__fastfetch_complete_path
|
||||
elif __fastfetch_previous_matches "${FF_OPTIONS_LOGO[@]}"; then
|
||||
__fastfetch_complete_logo
|
||||
else
|
||||
|
||||
+9
-4
@@ -35,14 +35,19 @@ void ffDefaultConfig(FFconfig* config)
|
||||
config->kernelShowRelease = true;
|
||||
config->kernelShowVersion = false;
|
||||
|
||||
config->shellShowPath = false;
|
||||
|
||||
config->packagesCombined = false;
|
||||
config->packagesCombinedNames = true;
|
||||
config->packagesPacman = true;
|
||||
config->packagesFlatpak = true;
|
||||
config->packagesShowPacman = true;
|
||||
config->packagesShowFlatpak = true;
|
||||
config->packagesFormat[0] = '\0';
|
||||
|
||||
config->shellShowPath = false;
|
||||
|
||||
config->resolutionShowRefreshRate = true;
|
||||
config->resolutionLibX11[0] = '\0';
|
||||
config->resolutionLibXrandr[0] = '\0';
|
||||
config->resolutionFormat[0] = '\0';
|
||||
|
||||
config->batteryShowManufacturer = true;
|
||||
config->batteryShowModel = true;
|
||||
config->batteryShowTechnology = true;
|
||||
|
||||
+44
-10
@@ -41,15 +41,20 @@
|
||||
"# --kernel-release true\n" \
|
||||
"# --kernel-version false\n" \
|
||||
"\n" \
|
||||
"## Shell options:\n" \
|
||||
"# --shell-path false\n" \
|
||||
"\n" \
|
||||
"## Packages options:\n" \
|
||||
"# --packages-combined false\n" \
|
||||
"# --packages-combined-names true\n" \
|
||||
"# --packages-pacman true\n" \
|
||||
"# --packages-flatpak true\n" \
|
||||
"\n" \
|
||||
"## Shell options:\n" \
|
||||
"# --shell-path false\n" \
|
||||
"\n" \
|
||||
"## Resolution options:\n" \
|
||||
"# --resolution-refreshrate true\n" \
|
||||
"# --resolution-libX11 libX11.so\n"\
|
||||
"# --resolution-libXrandr libXrandr.so\n" \
|
||||
"\n" \
|
||||
"## Battery options:\n" \
|
||||
"# --battery-manufacturer true\n" \
|
||||
"# --battery-model true\n" \
|
||||
@@ -102,9 +107,6 @@ static inline void printHelp()
|
||||
" --kernel-release <?value>: Shows the release of the kernel\n"
|
||||
" --kernel-version <?value>: Shows the build version of the kernel\n"
|
||||
"\n"
|
||||
"Shell options:\n"
|
||||
" --shell-path <?value>: Show the full path of the shell\n"
|
||||
"\n"
|
||||
"Packages options:\n"
|
||||
" --packages-combined <?value>: Show the sum of all packages\n"
|
||||
" --packages-combined-names <?value>: Show the names of the package managers after the sum if in packages-combined mode\n"
|
||||
@@ -112,6 +114,15 @@ static inline void printHelp()
|
||||
" --packages-flatpak <?value>: Count flatpak packages\n"
|
||||
" --packages-format <format>: Provide the printf format string for packages output (+)\n"
|
||||
"\n"
|
||||
"Shell options:\n"
|
||||
" --shell-path <?value>: Show the full path of the shell\n"
|
||||
"\n"
|
||||
"Resolution optins:\n"
|
||||
" --resolution-refreshrate <?value>: Show the refresh rate of the monitor\n"
|
||||
" --resolution-libX11 <path>: Set the path to the x11 library to load\n"
|
||||
" --resolution-libXrandr <path>: Set the path to the xrandr library to load\n"
|
||||
" --resolution-format <format>: Provide the printf format string for resolution output (+)\n"
|
||||
"\n"
|
||||
"Battery options:\n"
|
||||
" --battery-manufacturer <?value>: Show the manufacturer of the battery, if possible\n"
|
||||
" --battery-model <?value>: Show the model of the battery, if possible\n"
|
||||
@@ -167,6 +178,19 @@ static inline void printCommandHelpPackagesFormat()
|
||||
);
|
||||
}
|
||||
|
||||
static inline void printCommandHelpResolutionFormat()
|
||||
{
|
||||
puts(
|
||||
"usage: fastfetch --resolution-format <format>\n"
|
||||
"\n"
|
||||
"<format> is a string of maximum length 32, which is passed to printf as the format string.\n"
|
||||
"the values passed to printf are in following order:\n"
|
||||
"width (int), height (int), refreshRate (short)\n"
|
||||
"if refresh rate is disabled, or could not be determined, zero is passed\n"
|
||||
"The default value is something like \"%ix%i @ %dHz\""
|
||||
);
|
||||
}
|
||||
|
||||
static inline void printCommandHelp(const char* command)
|
||||
{
|
||||
if(strcasecmp(command, "c") == 0 || strcasecmp(command, "color") == 0)
|
||||
@@ -175,6 +199,8 @@ static inline void printCommandHelp(const char* command)
|
||||
printCommandHelpBatteryFormat();
|
||||
else if(strcasecmp(command, "packages-format") == 0)
|
||||
printCommandHelpPackagesFormat();
|
||||
else if(strcasecmp(command, "resolution-format") == 0)
|
||||
printCommandHelpResolutionFormat();
|
||||
else
|
||||
printf("No specific help for command %s provided\n", command);
|
||||
}
|
||||
@@ -384,8 +410,6 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
instance->config.kernelShowRelease = optionParseBoolean(value);
|
||||
else if(strcasecmp(key, "--kernel-version") == 0)
|
||||
instance->config.kernelShowVersion = optionParseBoolean(value);
|
||||
else if(strcasecmp(key, "--shell-path") == 0)
|
||||
instance->config.shellShowPath = optionParseBoolean(value);
|
||||
else if(strcasecmp(key, "--packages-combined") == 0)
|
||||
instance->config.packagesCombined = optionParseBoolean(value);
|
||||
else if(strcasecmp(key, "--packages-combined-names") == 0)
|
||||
@@ -394,11 +418,21 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
instance->config.packagesCombinedNames = optionParseBoolean(value);
|
||||
}
|
||||
else if(strcasecmp(key, "--packages-pacman") == 0)
|
||||
instance->config.packagesPacman = optionParseBoolean(value);
|
||||
instance->config.packagesShowPacman = optionParseBoolean(value);
|
||||
else if(strcasecmp(key, "--packages-flatpak") == 0)
|
||||
instance->config.packagesFlatpak = optionParseBoolean(value);
|
||||
instance->config.packagesShowFlatpak = optionParseBoolean(value);
|
||||
else if(strcasecmp(key, "--packages-format") == 0)
|
||||
optionParseString(key, value, instance->config.packagesFormat, sizeof(instance->config.packagesFormat));
|
||||
else if(strcasecmp(key, "--shell-path") == 0)
|
||||
instance->config.shellShowPath = optionParseBoolean(value);
|
||||
else if(strcasecmp(key, "--resolution-refreshrate") == 0)
|
||||
instance->config.resolutionShowRefreshRate = optionParseBoolean(value);
|
||||
else if(strcasecmp(key, "--resolution-libX11") == 0)
|
||||
optionParseString(key, value, instance->config.resolutionLibX11, sizeof(instance->config.resolutionLibX11));
|
||||
else if(strcasecmp(key, "--resolution-libXrandr") == 0)
|
||||
optionParseString(key, value, instance->config.resolutionLibXrandr, sizeof(instance->config.resolutionLibXrandr));
|
||||
else if(strcasecmp(key, "--resolution-format") == 0)
|
||||
optionParseString(key, value, instance->config.resolutionFormat, sizeof(instance->config.resolutionFormat));
|
||||
else if(strcasecmp(key, "--battery-manufacturer") == 0)
|
||||
instance->config.batteryShowManufacturer = optionParseBoolean(value);
|
||||
else if(strcasecmp(key, "--battery-model") == 0)
|
||||
|
||||
+11
-5
@@ -53,16 +53,22 @@ typedef struct FFconfig
|
||||
bool kernelShowRelease;
|
||||
bool kernelShowVersion;
|
||||
|
||||
//Shell
|
||||
bool shellShowPath;
|
||||
|
||||
//Packages
|
||||
bool packagesCombined;
|
||||
bool packagesCombinedNames;
|
||||
bool packagesPacman;
|
||||
bool packagesFlatpak;
|
||||
bool packagesShowPacman;
|
||||
bool packagesShowFlatpak;
|
||||
char packagesFormat[32];
|
||||
|
||||
//Shell
|
||||
bool shellShowPath;
|
||||
|
||||
//Resolution
|
||||
bool resolutionShowRefreshRate;
|
||||
char resolutionLibX11[64];
|
||||
char resolutionLibXrandr[64];
|
||||
char resolutionFormat[32];
|
||||
|
||||
//Battery
|
||||
bool batteryShowManufacturer;
|
||||
bool batteryShowModel;
|
||||
|
||||
@@ -25,8 +25,8 @@ static uint32_t get_num_dirs(const char* dirname) {
|
||||
|
||||
void ffPrintPackages(FFinstance* instance)
|
||||
{
|
||||
uint32_t pacman = instance->config.packagesPacman ? get_num_dirs("/var/lib/pacman/local") : 0;
|
||||
uint32_t flatpak = instance->config.packagesFlatpak ? get_num_dirs("/var/lib/flatpak/app") : 0;
|
||||
uint32_t pacman = instance->config.packagesShowPacman ? get_num_dirs("/var/lib/pacman/local") : 0;
|
||||
uint32_t flatpak = instance->config.packagesShowFlatpak ? get_num_dirs("/var/lib/flatpak/app") : 0;
|
||||
|
||||
uint32_t all = pacman + flatpak;
|
||||
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
#include "X11/extensions/Xrandr.h"
|
||||
#include "dlfcn.h"
|
||||
|
||||
static short getCurrentRate(Display* display)
|
||||
static short getCurrentRate(FFinstance* instance, Display* display)
|
||||
{
|
||||
void* xrandr = dlopen("libXrandr.so", RTLD_LAZY);
|
||||
void* xrandr;
|
||||
if(instance->config.resolutionLibXrandr[0] != '\0')
|
||||
xrandr = dlopen(instance->config.resolutionLibXrandr, RTLD_LAZY);
|
||||
else
|
||||
xrandr = dlopen("libXrandr.so", RTLD_LAZY);
|
||||
if(xrandr == NULL)
|
||||
return 0;
|
||||
|
||||
@@ -39,7 +43,11 @@ void ffPrintResolution(FFinstance* instance)
|
||||
if(ffPrintCachedValue(instance, "Resolution"))
|
||||
return;
|
||||
|
||||
void* x11 = dlopen("libX11.so", RTLD_LAZY);
|
||||
void* x11;
|
||||
if(instance->config.resolutionLibX11[0] != '\0')
|
||||
x11 = dlopen(instance->config.resolutionLibX11, RTLD_LAZY);
|
||||
else
|
||||
x11 = dlopen("libX11.so", RTLD_LAZY);
|
||||
if(x11 == NULL)
|
||||
{
|
||||
ffPrintError(instance, "Resolution", "dlopen(\"libX11.so\", RTLD_LAZY) == NULL");
|
||||
@@ -62,13 +70,15 @@ void ffPrintResolution(FFinstance* instance)
|
||||
|
||||
Screen* screen = DefaultScreenOfDisplay(display);
|
||||
|
||||
short currentRate = getCurrentRate(display);
|
||||
short currentRate = instance->config.resolutionShowRefreshRate ? getCurrentRate(instance, display) : 0;
|
||||
|
||||
dlclose(x11);
|
||||
|
||||
char resolution[1024];
|
||||
|
||||
if(currentRate == 0)
|
||||
if(instance->config.resolutionFormat[0] != '\0')
|
||||
sprintf(resolution, instance->config.resolutionFormat, screen->width, screen->height, currentRate);
|
||||
else if(currentRate == 0)
|
||||
sprintf(resolution, "%ix%i", screen->width, screen->height);
|
||||
else
|
||||
sprintf(resolution, "%ix%i @ %dHz", screen->width, screen->height, currentRate);
|
||||
|
||||
Reference in New Issue
Block a user