From d36e827ec9d0060a2100e57b51a04e0cffb69b51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 30 Jan 2023 12:01:16 +0800 Subject: [PATCH 1/9] Fastfetch: remove `--nocache` which has been deprecated for a while --- src/fastfetch.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/fastfetch.c b/src/fastfetch.c index 012f5da68..78b86708c 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -928,8 +928,6 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con else if(strcasecmp(key, "-r") == 0 || strcasecmp(key, "--recache") == 0) instance->config.recache = optionParseBoolean(value); - else if(strcasecmp(key, "--nocache") == 0) - fputs("`--nocache` are obsoleted. Caching functions other than image caching are removed.\n\n", stderr); else if(strcasecmp(key, "--load-config") == 0) optionParseConfigFile(instance, data, key, value); else if(strcasecmp(key, "--gen-config") == 0) From 2476b44300abc02f0c843d097b53e62cd3f4a849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Jan 2023 19:42:02 +0800 Subject: [PATCH 2/9] Global: add support for colored percentage numbers output --- src/common/bar.c | 50 ++++++++++++++++++++++++++++++++++++++++ src/common/bar.h | 8 ++++--- src/data/config_user.txt | 2 +- src/data/help.txt | 2 +- src/modules/battery.c | 3 ++- src/modules/cpuUsage.c | 2 +- src/modules/disk.c | 3 ++- src/modules/memory.c | 2 +- 8 files changed, 63 insertions(+), 9 deletions(-) diff --git a/src/common/bar.c b/src/common/bar.c index 34b14aa7a..d4a8cf0f1 100644 --- a/src/common/bar.c +++ b/src/common/bar.c @@ -47,3 +47,53 @@ void ffAppendPercentBar(FFinstance* instance, FFstrbuf* buffer, uint8_t percent, else ffStrbufAppendS(buffer, " ]"); } + +// if (green < yellow) +// [0, green]: print green +// (green, yellow]: print yellow +// (yellow, 100]: print red +// +// if (green > yellow) +// [green, 100]: print green +// [yellow, green): print yellow +// [0, yellow): PRINT RED +void ffAppendPercentNum(FFinstance* instance, FFstrbuf* buffer, uint8_t percent, uint8_t green, uint8_t yellow, bool parentheses) +{ + assert(green <= 100 && yellow <= 100); + + bool colored = !!(instance->config.percentType & FF_PERCENTAGE_TYPE_NUM_COLOR_BIT); + + if (parentheses) + ffStrbufAppendC(buffer, '('); + + if (colored && !instance->config.pipe) + { + if(green < yellow) + { + if (percent <= green) + ffStrbufAppendS(buffer, "\033[32m"); + else if (percent <= yellow) + ffStrbufAppendS(buffer, "\033[93m"); + else + ffStrbufAppendS(buffer, "\033[91m"); + } + else + { + if (percent >= green) + ffStrbufAppendS(buffer, "\033[32m"); + else if (percent >= yellow) + ffStrbufAppendS(buffer, "\033[93m"); + else + ffStrbufAppendS(buffer, "\033[91m"); + } + } + ffStrbufAppendF(buffer, "%u%%", (unsigned) percent); + + if (colored && !instance->config.pipe) + { + ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET); + } + + if (parentheses) + ffStrbufAppendC(buffer, ')'); +} diff --git a/src/common/bar.h b/src/common/bar.h index 575adc01d..f28cbe777 100644 --- a/src/common/bar.h +++ b/src/common/bar.h @@ -7,11 +7,13 @@ enum { - FF_PERCENTAGE_TYPE_NUM_BIT = 1, - FF_PERCENTAGE_TYPE_BAR_BIT = 2, - FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT = 4, + FF_PERCENTAGE_TYPE_NUM_BIT = 1 << 0, + FF_PERCENTAGE_TYPE_BAR_BIT = 1 << 1, + FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT = 1 << 2, + FF_PERCENTAGE_TYPE_NUM_COLOR_BIT = 1 << 3, }; void ffAppendPercentBar(FFinstance* instance, FFstrbuf* buffer, uint8_t percent, uint8_t green, uint8_t yellow, uint8_t red); +void ffAppendPercentNum(FFinstance* instance, FFstrbuf* buffer, uint8_t percent, uint8_t green, uint8_t yellow, bool parentheses); #endif diff --git a/src/data/config_user.txt b/src/data/config_user.txt index 1b9ac9635..e4fcef289 100644 --- a/src/data/config_user.txt +++ b/src/data/config_user.txt @@ -262,7 +262,7 @@ # Percentage output type option # Applies to all modules that prints percentage values. Currently memory, swap, disk, battery and CPU usage are supported. # Only works with default format ( without --module-format option ). -# 0: prints none; 1: prints percent number only; 2: prints bar only; 3: prints both percent number and bar; 6: prints bar and hide other texts +# 0: prints none; 1: prints percent number only; 2: prints bar only; 3: prints both percent number and bar; 6: prints bar and hide other texts; 9: prints colored number #--percent-type 1 # Key options: diff --git a/src/data/help.txt b/src/data/help.txt index c4fd1acd3..37adf2eed 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -130,7 +130,7 @@ Module specific options: --weather-output-format: The output weather format to be used. It must be URI encoded. --player-name: The name of the player to use --gl : Set the OpenGL context creation library to use. Must be auto, egl, glx or osmesa. Default is auto - --percent-type : Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only. Default is 1 + --percent-type : Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number. Default is 1 --command-shell : Set the shell program to execute the command text. Default is cmd for Windows, csh for FreeBSD, bash for others --command-key : Set the module key to display, can be specified mulitple times --command-text : Set the command text to be executed, can be specified mulitple times diff --git a/src/modules/battery.c b/src/modules/battery.c index 79cdf4c79..6bafb0ee7 100644 --- a/src/modules/battery.c +++ b/src/modules/battery.c @@ -36,7 +36,8 @@ static void printBattery(FFinstance* instance, BatteryResult* result, uint8_t in { if(str.length > 0) ffStrbufAppendC(&str, ' '); - ffStrbufAppendF(&str, str.length > 0 ? "(%u%%)" : "%u%%", (unsigned) result->capacity); + + ffAppendPercentNum(instance, &str, (uint8_t) result->capacity, 51, 21, str.length > 0); } } diff --git a/src/modules/cpuUsage.c b/src/modules/cpuUsage.c index 3e4165b90..f46de6259 100644 --- a/src/modules/cpuUsage.c +++ b/src/modules/cpuUsage.c @@ -29,7 +29,7 @@ void ffPrintCPUUsage(FFinstance* instance) { if(str.length > 0) ffStrbufAppendC(&str, ' '); - ffStrbufAppendF(&str, "%.2lf%%", percentage); + ffAppendPercentNum(instance, &str, (uint8_t) percentage, 50, 80, str.length > 0); } ffStrbufPutTo(&str, stdout); ffStrbufDestroy(&str); diff --git a/src/modules/disk.c b/src/modules/disk.c index c1e074812..d2311f11f 100644 --- a/src/modules/disk.c +++ b/src/modules/disk.c @@ -53,7 +53,8 @@ static void printDisk(FFinstance* instance, const FFDisk* disk) if(instance->config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) { - ffStrbufAppendF(&str, str.length > 0 ? "(%u%%) " : "%u%% ", bytesPercentage); + ffAppendPercentNum(instance, &str, (uint8_t) bytesPercentage, 50, 80, str.length > 0); + ffStrbufAppendC(&str, ' '); } } else diff --git a/src/modules/memory.c b/src/modules/memory.c index fbb893f02..05d7c33cf 100644 --- a/src/modules/memory.c +++ b/src/modules/memory.c @@ -56,7 +56,7 @@ static void printMemory(FFinstance* instance, const char* name, const FFModuleAr ffStrbufAppendF(&str, "%s / %s ", usedPretty.chars, totalPretty.chars); if(instance->config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) - ffStrbufAppendF(&str, str.length > 0 ? "(%u%%)" : "%u%%", percentage); + ffAppendPercentNum(instance, &str, (uint8_t) percentage, 50, 80, str.length > 0); ffStrbufTrimRight(&str, ' '); ffStrbufPutTo(&str, stdout); From 7132762c9cdb6b247462d014e5edebf1f31e0afb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Jan 2023 20:55:01 +0800 Subject: [PATCH 3/9] Sound (Linux): small fixes 1. treat PA_PORT_AVAILABLE_UNKNOWN as active so that the default speaker is active now 2. load `libpulse.so` as suggested in `config_user.txt` --- src/detection/sound/sound_linux.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/detection/sound/sound_linux.c b/src/detection/sound/sound_linux.c index 0aa10b753..658fc82c7 100644 --- a/src/detection/sound/sound_linux.c +++ b/src/detection/sound/sound_linux.c @@ -16,7 +16,7 @@ static void paSinkInfoCallback(pa_context *c, const pa_sink_info *i, int eol, vo ffStrbufInitS(&device->name, i->description); ffStrbufInitS(&device->manufacturer, i->driver); device->volume = i->mute ? 0 : (uint8_t) (i->volume.values[0] * 100 / PA_VOLUME_NORM); - device->active = i->active_port && i->active_port->available == PA_PORT_AVAILABLE_YES; + device->active = i->active_port && i->active_port->available != PA_PORT_AVAILABLE_NO; device->main = false; } @@ -32,7 +32,6 @@ static void paServerInfoCallback(pa_context *c, const pa_server_info *i, void *u if(ffStrbufEqualS(&device->identifier, i->default_sink_name)) { device->main = true; - device->active = true; // Treat the default sink as always active break; } } @@ -40,7 +39,7 @@ static void paServerInfoCallback(pa_context *c, const pa_server_info *i, void *u static const char* detectSound(const FFinstance* instance, FFlist* devices) { - FF_LIBRARY_LOAD(pulse, &instance->config.libPulse, "Failed to load libpulse.so.0", "libpulse.so.0", 0) + FF_LIBRARY_LOAD(pulse, &instance->config.libPulse, "Failed to load libpulse" FF_LIBRARY_EXTENSION, "libpulse" FF_LIBRARY_EXTENSION, 0) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(pulse, pa_mainloop_new) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(pulse, pa_mainloop_get_api) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(pulse, pa_mainloop_iterate) From 00e044c431e20f62c89e2659645658ab35897e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Jan 2023 21:12:47 +0800 Subject: [PATCH 4/9] Sound: change option `--sound-show-all` to `--sound-type` --- src/common/init.c | 2 +- src/data/help.txt | 2 +- src/fastfetch.c | 11 +++++++++-- src/fastfetch.h | 9 ++++++++- src/modules/sound.c | 8 ++++++-- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/common/init.c b/src/common/init.c index 7eabe0948..0125c4b75 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -164,7 +164,7 @@ static void defaultConfig(FFinstance* instance) instance->config.bluetoothShowDisconnected = false; - instance->config.soundShowAll = false; + instance->config.soundType = FF_SOUND_TYPE_MAIN; ffStrbufInitA(&instance->config.batteryDir, 0); diff --git a/src/data/help.txt b/src/data/help.txt index 37adf2eed..3eeaf662b 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -113,7 +113,7 @@ Module specific options: --disk-show-subvolumes : Set if subvolumes should be printed. Default is false --disk-show-unknown : Set if unknown (unable to detect sizes) volumes should be printed. Default is false --bluetooth-show-disconnected: : Set if disconnected bluetooth devices should be printed. Default is false - --sound-show-all: : Set if all sound devices should be printed. Default is false + --sound-type: : Set what type of sound devices should be printed. Should be either main, active or all. Default is main --battery-dir : The directory where the battery folders are. Standard: /sys/class/power_supply/ --cpu-temp : Detect and display CPU temperature if supported. Default is false --gpu-temp : Detect and display GPU temperature if supported. Default is false diff --git a/src/fastfetch.c b/src/fastfetch.c index 78b86708c..75431699f 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -1261,8 +1261,15 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con instance->config.diskShowUnknown = optionParseBoolean(value); else if(strcasecmp(key, "--bluetooth-show-disconnected") == 0) instance->config.bluetoothShowDisconnected = optionParseBoolean(value); - else if(strcasecmp(key, "--sound-show-all") == 0) - instance->config.soundShowAll = optionParseBoolean(value); + else if(strcasecmp(key, "--sound-type") == 0) + { + optionParseEnum(key, value, &instance->config.soundType, + "main", FF_SOUND_TYPE_MAIN, + "active", FF_SOUND_TYPE_ACTIVE, + "all", FF_SOUND_TYPE_ALL, + NULL + ); + } else if(strcasecmp(key, "--battery-dir") == 0) optionParseString(key, value, &instance->config.batteryDir); else if(strcasecmp(key, "--separator-string") == 0) diff --git a/src/fastfetch.h b/src/fastfetch.h index e1d5be954..0d57902c6 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -34,6 +34,13 @@ typedef enum FFLogoType FF_LOGO_TYPE_NONE, //--logo none } FFLogoType; +typedef enum FFSoundType +{ + FF_SOUND_TYPE_MAIN, + FF_SOUND_TYPE_ACTIVE, + FF_SOUND_TYPE_ALL, +} FFSoundType; + typedef enum FFBinaryPrefixType { FF_BINARY_PREFIX_TYPE_IEC, // 1024 Bytes = 1 KiB, 1024 KiB = 1 MiB, ... (standard) @@ -203,7 +210,7 @@ typedef struct FFconfig FFstrbuf weatherOutputFormat; uint32_t weatherTimeout; - bool soundShowAll; + FFSoundType soundType; FFstrbuf osFile; diff --git a/src/modules/sound.c b/src/modules/sound.c index d9ee35d37..1bf02b824 100644 --- a/src/modules/sound.c +++ b/src/modules/sound.c @@ -40,8 +40,12 @@ static void printSound(FFinstance* instance, FFlist* devices) FF_LIST_FOR_EACH(FFSoundDevice, device, *devices) { - if(!device->active && !instance->config.soundShowAll) - continue; + switch (instance->config.soundType) + { + case FF_SOUND_TYPE_MAIN: if (!device->main) continue; break; + case FF_SOUND_TYPE_ACTIVE: if (!device->active) continue; break; + case FF_SOUND_TYPE_ALL: break; + } *(FFSoundDevice**)ffListAdd(&filtered) = device; } From a92e6b6d91b0e504374689f4e9ec120c0a66b09e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Jan 2023 22:17:46 +0800 Subject: [PATCH 5/9] Sound (macOS): fix active device detection; fix memleaks; don't use deprecated properties --- src/detection/sound/sound_apple.c | 39 +++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/detection/sound/sound_apple.c b/src/detection/sound/sound_apple.c index 305e991bf..b1260db2f 100644 --- a/src/detection/sound/sound_apple.c +++ b/src/detection/sound/sound_apple.c @@ -9,16 +9,16 @@ const char* ffDetectSound(FF_MAYBE_UNUSED const FFinstance* instance, FFlist* de UInt32 dataSize = sizeof(mainDeviceId); if(AudioObjectGetPropertyData(kAudioObjectSystemObject, &(AudioObjectPropertyAddress){ kAudioHardwarePropertyDefaultOutputDevice, - kAudioDevicePropertyScopeOutput, + kAudioObjectPropertyScopeOutput, kAudioObjectPropertyElementMain }, 0, NULL, &dataSize, &mainDeviceId) != kAudioHardwareNoError) return "AudioObjectGetPropertyData(kAudioHardwarePropertyDefaultOutputDevice) failed"; - AudioDeviceID deviceIds[32]; + AudioObjectID deviceIds[32] = {}; dataSize = sizeof(deviceIds); if(AudioObjectGetPropertyData(kAudioObjectSystemObject, &(AudioObjectPropertyAddress){ kAudioHardwarePropertyDevices, - kAudioDevicePropertyScopeOutput, + kAudioObjectPropertyScopeOutput, kAudioObjectPropertyElementMain }, 0, NULL, &dataSize, &deviceIds) != kAudioHardwareNoError) return "AudioObjectGetPropertyData(kAudioHardwarePropertyDevices) failed"; @@ -31,27 +31,36 @@ const char* ffDetectSound(FF_MAYBE_UNUSED const FFinstance* instance, FFlist* de dataSize = sizeof(muted); if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){ kAudioDevicePropertyMute, - kAudioDevicePropertyScopeOutput, - 0 + kAudioObjectPropertyScopeOutput, + kAudioObjectPropertyElementMain }, 0, NULL, &dataSize, &muted) != kAudioHardwareNoError) continue; FFSoundDevice* device = (FFSoundDevice*) ffListAdd(devices); device->main = deviceId == mainDeviceId; - device->active = device->main; + device->active = false; device->volume = 0; ffStrbufInitF(&device->identifier, "%u", (unsigned) deviceId); ffStrbufInit(&device->name); ffStrbufInit(&device->manufacturer); + uint32_t active; + dataSize = sizeof(active); + if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){ + kAudioDevicePropertyDeviceIsAlive, + kAudioObjectPropertyScopeOutput, + kAudioObjectPropertyElementMain + }, 0, NULL, &dataSize, &active) == kAudioHardwareNoError) + device->active = !!active; + if (!muted) { float volume; dataSize = sizeof(volume); if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){ kAudioDevicePropertyVolumeScalar, - kAudioDevicePropertyScopeOutput, - 0 + kAudioObjectPropertyScopeOutput, + kAudioObjectPropertyElementMain }, 0, NULL, &dataSize, &volume) == kAudioHardwareNoError) device->volume = (uint8_t) (volume * 100 + 0.5); } @@ -60,19 +69,25 @@ const char* ffDetectSound(FF_MAYBE_UNUSED const FFinstance* instance, FFlist* de dataSize = sizeof(name); if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){ kAudioObjectPropertyName, - kAudioDevicePropertyScopeOutput, - 0 + kAudioObjectPropertyScopeOutput, + kAudioObjectPropertyElementMain }, 0, NULL, &dataSize, &name) == kAudioHardwareNoError) + { ffCfStrGetString(name, &device->name); + CFRelease(name); + } CFStringRef manufacturer; dataSize = sizeof(manufacturer); if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){ kAudioObjectPropertyManufacturer, - kAudioDevicePropertyScopeOutput, - 0 + kAudioObjectPropertyScopeOutput, + kAudioObjectPropertyElementMain }, 0, NULL, &dataSize, &manufacturer) == kAudioHardwareNoError) + { ffCfStrGetString(manufacturer, &device->manufacturer); + CFRelease(manufacturer); + } } return NULL; From 39f47d65a997b4f087257b75c673eb8d4ed0c77d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Jan 2023 22:39:27 +0800 Subject: [PATCH 6/9] Sound: remove manufacturer detection as it's only implemented on macOS --- src/detection/sound/sound.h | 1 - src/detection/sound/sound_apple.c | 13 ------------- src/detection/sound/sound_linux.c | 1 - src/detection/sound/sound_windows.cpp | 3 --- src/fastfetch.c | 1 - src/modules/sound.c | 4 +--- 6 files changed, 1 insertion(+), 22 deletions(-) diff --git a/src/detection/sound/sound.h b/src/detection/sound/sound.h index 76c17627c..9a89ab694 100644 --- a/src/detection/sound/sound.h +++ b/src/detection/sound/sound.h @@ -9,7 +9,6 @@ typedef struct FFSoundDevice { FFstrbuf identifier; FFstrbuf name; - FFstrbuf manufacturer; uint8_t volume; // 0-100% bool main; bool active; diff --git a/src/detection/sound/sound_apple.c b/src/detection/sound/sound_apple.c index b1260db2f..a9ec04703 100644 --- a/src/detection/sound/sound_apple.c +++ b/src/detection/sound/sound_apple.c @@ -42,7 +42,6 @@ const char* ffDetectSound(FF_MAYBE_UNUSED const FFinstance* instance, FFlist* de device->volume = 0; ffStrbufInitF(&device->identifier, "%u", (unsigned) deviceId); ffStrbufInit(&device->name); - ffStrbufInit(&device->manufacturer); uint32_t active; dataSize = sizeof(active); @@ -76,18 +75,6 @@ const char* ffDetectSound(FF_MAYBE_UNUSED const FFinstance* instance, FFlist* de ffCfStrGetString(name, &device->name); CFRelease(name); } - - CFStringRef manufacturer; - dataSize = sizeof(manufacturer); - if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){ - kAudioObjectPropertyManufacturer, - kAudioObjectPropertyScopeOutput, - kAudioObjectPropertyElementMain - }, 0, NULL, &dataSize, &manufacturer) == kAudioHardwareNoError) - { - ffCfStrGetString(manufacturer, &device->manufacturer); - CFRelease(manufacturer); - } } return NULL; diff --git a/src/detection/sound/sound_linux.c b/src/detection/sound/sound_linux.c index 658fc82c7..a752a6b5f 100644 --- a/src/detection/sound/sound_linux.c +++ b/src/detection/sound/sound_linux.c @@ -14,7 +14,6 @@ static void paSinkInfoCallback(pa_context *c, const pa_sink_info *i, int eol, vo FFSoundDevice* device = ffListAdd(userdata); ffStrbufInitS(&device->identifier, i->name); ffStrbufInitS(&device->name, i->description); - ffStrbufInitS(&device->manufacturer, i->driver); device->volume = i->mute ? 0 : (uint8_t) (i->volume.values[0] * 100 / PA_VOLUME_NORM); device->active = i->active_port && i->active_port->available != PA_PORT_AVAILABLE_NO; device->main = false; diff --git a/src/detection/sound/sound_windows.cpp b/src/detection/sound/sound_windows.cpp index 2b9e95be1..5221c8368 100644 --- a/src/detection/sound/sound_windows.cpp +++ b/src/detection/sound/sound_windows.cpp @@ -65,7 +65,6 @@ const char* ffDetectSound(FF_MAYBE_UNUSED const FFinstance* instance, FF_MAYBE_U device->volume = 0; ffStrbufInit(&device->identifier); ffStrbufInit(&device->name); - ffStrbufInit(&device->manufacturer); ffStrbufSetWS(&device->identifier, immDeviceId); @@ -74,8 +73,6 @@ const char* ffDetectSound(FF_MAYBE_UNUSED const FFinstance* instance, FF_MAYBE_U PropVariantInit(&friendlyName); if (SUCCEEDED(immPropStore->GetValue(PKEY_Device_FriendlyName, &friendlyName))) ffStrbufSetWS(&device->name, friendlyName.pwszVal); - if (SUCCEEDED(immPropStore->GetValue(PKEY_DeviceInterface_FriendlyName, &friendlyName))) - ffStrbufSetWS(&device->manufacturer, friendlyName.pwszVal); } IAudioEndpointVolume* FF_AUTO_RELEASE_COM_OBJECT immEndpointVolume; diff --git a/src/fastfetch.c b/src/fastfetch.c index 75431699f..ded937466 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -460,7 +460,6 @@ static inline void printCommandHelp(const char* command) "Main", "Name", "Volume", - "Manufacturer", "Identifier" ); } diff --git a/src/modules/sound.c b/src/modules/sound.c index 1bf02b824..4ef58cdc2 100644 --- a/src/modules/sound.c +++ b/src/modules/sound.c @@ -2,7 +2,7 @@ #include "detection/sound/sound.h" #define FF_SOUND_MODULE_NAME "Sound" -#define FF_SOUND_NUM_FORMAT_ARGS 5 +#define FF_SOUND_NUM_FORMAT_ARGS 4 static void printDevice(FFinstance* instance, const FFSoundDevice* device, uint8_t index) { @@ -27,7 +27,6 @@ static void printDevice(FFinstance* instance, const FFSoundDevice* device, uint8 {FF_FORMAT_ARG_TYPE_BOOL, &device->main}, {FF_FORMAT_ARG_TYPE_STRBUF, &device->name}, {FF_FORMAT_ARG_TYPE_UINT8, &device->volume}, - {FF_FORMAT_ARG_TYPE_STRBUF, &device->manufacturer}, {FF_FORMAT_ARG_TYPE_STRBUF, &device->identifier} }); } @@ -79,6 +78,5 @@ void ffPrintSound(FFinstance* instance) { ffStrbufDestroy(&device->identifier); ffStrbufDestroy(&device->name); - ffStrbufDestroy(&device->manufacturer); } } From 4f3b9776ae8a64715927fe7f59d02f6201395a58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Jan 2023 23:26:50 +0800 Subject: [PATCH 7/9] WmTheme (Windows): align output format to winfetch Ref: https://github.com/lptstr/winfetch/commit/0358deea5e3ca03086be4984b905a0a534f8d1a5 --- src/detection/wmtheme/wmtheme_windows.c | 69 ++++++++++++------------- 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/src/detection/wmtheme/wmtheme_windows.c b/src/detection/wmtheme/wmtheme_windows.c index cf070be69..0522b933b 100644 --- a/src/detection/wmtheme/wmtheme_windows.c +++ b/src/detection/wmtheme/wmtheme_windows.c @@ -60,64 +60,59 @@ const char* colorHexToString(DWORD hex) } } -bool ffDetectWmTheme(FFinstance* instance, FFstrbuf* themeOrError) +bool ffDetectWmTheme(FF_MAYBE_UNUSED FFinstance* instance, FFstrbuf* themeOrError) { - FF_UNUSED(instance); + { + FF_HKEY_AUTO_DESTROY hKey = NULL; + if(ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes", &hKey, NULL)) + { + FF_STRBUF_AUTO_DESTROY theme; + ffStrbufInit(&theme); + if(ffRegReadStrbuf(hKey, L"CurrentTheme", &theme, NULL)) + { + ffStrbufSubstrBeforeLastC(&theme, '.'); + ffStrbufSubstrAfterLastC(&theme, '\\'); + if(isalpha(theme.chars[0])) + theme.chars[0] = (char)toupper(theme.chars[0]); + + ffStrbufAppendF(themeOrError, "%s", theme.chars); + } + } + } do { uint32_t rgbColor; uint32_t bgrColor; DWORD bufSize = sizeof(bgrColor); if(RegGetValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\DWM", L"AccentColor", RRF_RT_REG_DWORD, NULL, &bgrColor, &bufSize) == ERROR_SUCCESS) - { - ffStrbufAppendS(themeOrError, "Accent Color - "); rgbColor = ((bgrColor & 0xFF) << 16) | (bgrColor & 0xFF00) | ((bgrColor >> 16) & 0xFF); - - } else if(RegGetValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\DWM", L"ColorizationColor", RRF_RT_REG_DWORD, NULL, &rgbColor, &bufSize) == ERROR_SUCCESS) - { - ffStrbufAppendS(themeOrError, "Colorization Color - "); rgbColor &= 0xFFFFFF; - } else break; + if(themeOrError->length > 0) ffStrbufAppendS(themeOrError, " - "); const char* text = colorHexToString(rgbColor); if(text) ffStrbufAppendS(themeOrError, text); else ffStrbufAppendF(themeOrError, "#%06lX", (long)rgbColor); - } while(false); + } while (false); - FF_HKEY_AUTO_DESTROY hKey = NULL; - if(ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", &hKey, NULL)) { - uint32_t value = 1; - if(ffRegReadUint(hKey, L"SystemUsesLightTheme", &value, NULL)) + FF_HKEY_AUTO_DESTROY hKey = NULL; + if(ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", &hKey, NULL)) { - if(themeOrError->length > 0) ffStrbufAppendS(themeOrError, ", "); - ffStrbufAppendF(themeOrError, "System - %s", value ? "Light" : "Dark"); - } - - if(ffRegReadUint(hKey, L"AppsUseLightTheme", &value, NULL)) - { - if(themeOrError->length > 0) ffStrbufAppendS(themeOrError, ", "); - ffStrbufAppendF(themeOrError, "Apps - %s", value ? "Light" : "Dark"); - } - } - else if(ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes", &hKey, NULL)) - { - FF_STRBUF_AUTO_DESTROY theme; - ffStrbufInit(&theme); - if(ffRegReadStrbuf(hKey, L"CurrentTheme", &theme, NULL)) - { - ffStrbufSubstrBeforeLastC(&theme, '.'); - ffStrbufSubstrAfterLastC(&theme, '\\'); - if(isalpha(theme.chars[0])) - theme.chars[0] = (char)toupper(theme.chars[0]); - - if(themeOrError->length > 0) ffStrbufAppendS(themeOrError, ", "); - ffStrbufAppendF(themeOrError, "Theme - %s", theme.chars); + uint32_t system = 1, apps = 1; + if (ffRegReadUint(hKey, L"SystemUsesLightTheme", &system, NULL) && ffRegReadUint(hKey, L"AppsUseLightTheme", &apps, NULL)) + { + bool paren = themeOrError->length > 0; + if (paren) + ffStrbufAppendS(themeOrError, " ("); + ffStrbufAppendF(themeOrError, "System: %s, Apps: %s", system ? "Light" : "Dark", apps ? "Light" : "Dark"); + if (paren) + ffStrbufAppendC(themeOrError, ')'); + } } } From f53a1f785db88932a1e2bd567922fe79060346dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Jan 2023 23:32:49 +0800 Subject: [PATCH 8/9] Doc: update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d79318a8..0c7af9af4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,11 +3,16 @@ Features: * Bluetooth module * Sound module +* Support colored percentage numbers output Bugfixes: * Fix a rare case that fails to detect terminal +Other: + +* Simplified wmtheme output format (Windows) + # 1.9.1 Bugfixes: From 7a2826358ba350d090c5f64f7510d9c408fd33c5 Mon Sep 17 00:00:00 2001 From: CSoellinger Date: Wed, 1 Feb 2023 10:08:08 +0100 Subject: [PATCH 9/9] fix: spell correction --- src/detection/terminalfont/terminalfont.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/detection/terminalfont/terminalfont.c b/src/detection/terminalfont/terminalfont.c index 1d3503da2..d4c1359ad 100644 --- a/src/detection/terminalfont/terminalfont.c +++ b/src/detection/terminalfont/terminalfont.c @@ -385,7 +385,7 @@ const FFTerminalFontResult* ffDetectTerminalFont(const FFinstance* instance) const FFTerminalShellResult* terminalShell = ffDetectTerminalShell(instance); if(terminalShell->terminalProcessName.length == 0) - ffStrbufAppendS(&result.error, "Terminal font needs successfull terminal detection"); + ffStrbufAppendS(&result.error, "Terminal font needs successful terminal detection"); else if(!detectTerminalFontCommon(instance, terminalShell, &result)) ffDetectTerminalFontPlatform(instance, terminalShell, &result);