From 18240524dc2f6112ef8d053ac912323891b9c49d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 23 Apr 2024 05:17:15 +0000 Subject: [PATCH 01/30] DisplayServer (Linux): basic support for ukui --- src/detection/displayserver/displayserver.h | 1 + src/detection/displayserver/linux/wmde.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/detection/displayserver/displayserver.h b/src/detection/displayserver/displayserver.h index 9c6c2d96e..1497e786f 100644 --- a/src/detection/displayserver/displayserver.h +++ b/src/detection/displayserver/displayserver.h @@ -13,6 +13,7 @@ #define FF_DE_PRETTY_BUDGIE "Budgie" #define FF_DE_PRETTY_CDE "CDE" #define FF_DE_PRETTY_UNITY "Unity" +#define FF_DE_PRETTY_UKUI "UKUI" #define FF_WM_PRETTY_KWIN "KWin" #define FF_WM_PRETTY_MUTTER "Mutter" diff --git a/src/detection/displayserver/linux/wmde.c b/src/detection/displayserver/linux/wmde.c index 5d21f1d6c..64f16db03 100644 --- a/src/detection/displayserver/linux/wmde.c +++ b/src/detection/displayserver/linux/wmde.c @@ -75,7 +75,9 @@ static void applyPrettyNameIfWM(FFDisplayServerResult* result, const char* name) ffStrEqualsIgnCase(name, "kwin_wayland_wrapper") || ffStrEqualsIgnCase(name, "kwin_x11") || ffStrEqualsIgnCase(name, "kwin_x11_wrapper") || - ffStrEqualsIgnCase(name, "kwin") + ffStrEqualsIgnCase(name, "kwin") || + ffStrEndsWithIgnCase(name, "-kwin_wayland") || + ffStrEndsWithIgnCase(name, "-kwin_x11") ) ffStrbufSetS(&result->wmPrettyName, FF_WM_PRETTY_KWIN); else if( ffStrEqualsIgnCase(name, "gnome-shell") || @@ -231,6 +233,13 @@ static void applyPrettyNameIfDE(FFDisplayServerResult* result, const char* name) ffStrbufSetS(&result->deProcessName, "dtsession"); ffStrbufSetS(&result->dePrettyName, FF_DE_PRETTY_CDE); } + + else if( + ffStrEqualsIgnCase(name, "ukui-session") + ) { + ffStrbufSetS(&result->deProcessName, "ukui-session"); + ffStrbufSetS(&result->dePrettyName, FF_DE_PRETTY_UKUI); + } } static void getWMProtocolNameFromEnv(FFDisplayServerResult* result) From 04456d9807815f5bebd5f4a53699326bb4ccead6 Mon Sep 17 00:00:00 2001 From: Guiorgy Date: Tue, 23 Apr 2024 15:05:55 +0400 Subject: [PATCH 02/30] allow generation of either deb or rpm package only (#807) --- CMakeLists.txt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c2ac9fcdd..c17e7456b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1147,16 +1147,20 @@ endif() if(LINUX) find_program(HAVE_DPKG "dpkg") - find_program(HAVE_RPMBUILD "rpmbuild") - if(HAVE_DPKG AND HAVE_RPMBUILD) - set(CPACK_GENERATOR "${CPACK_GENERATOR};DEB;RPM") + if(HAVE_DPKG) + set(CPACK_GENERATOR "${CPACK_GENERATOR};DEB") + + set(CPACK_DEBIAN_PACKAGE_SECTION, "utils") + set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") + set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6") endif() - set(CPACK_DEBIAN_PACKAGE_SECTION, "utils") - set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") - set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6") + find_program(HAVE_RPMBUILD "rpmbuild") + if(HAVE_RPMBUILD) + set(CPACK_GENERATOR "${CPACK_GENERATOR};RPM") - set(CPACK_RPM_PACKAGE_LICENSE "MIT") + set(CPACK_RPM_PACKAGE_LICENSE "MIT") + endif() endif() set(CPACK_SET_DESTDIR ON) From ea1ef0f34731ad50e277f6a0b1a37fce739c9c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 23 Apr 2024 22:45:12 +0800 Subject: [PATCH 03/30] JsonSchema: add missing modules --- doc/json_schema.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/json_schema.json b/doc/json_schema.json index 49c0596c7..5804b2292 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -679,6 +679,7 @@ "board", "break", "brightness", + "camera", "chassis", "cpu", "cpuusage", @@ -772,6 +773,10 @@ "const": "board", "description": "Print mather board name and other info" }, + { + "const": "camera", + "description": "Print available cameras" + }, { "const": "cursor", "description": "Print cursor style name" From c2fd057126f7b4e0858a98379dff0f642cc0f076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 23 Apr 2024 22:47:50 +0800 Subject: [PATCH 04/30] CI (macOS): revert back to macos 12 before we know what was happening --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f70de31aa..557425515 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -258,7 +258,7 @@ jobs: macos-universal: name: macOS-universal - runs-on: macos-latest + runs-on: macos-12 permissions: security-events: write contents: read From 40320e5efaa775ec096abafabeb79cc37c858213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 23 Apr 2024 23:29:26 +0800 Subject: [PATCH 05/30] Swap (Windows): fix detection in i686 build --- src/detection/swap/swap_windows.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/detection/swap/swap_windows.c b/src/detection/swap/swap_windows.c index a5788a358..52d713c2b 100644 --- a/src/detection/swap/swap_windows.c +++ b/src/detection/swap/swap_windows.c @@ -7,7 +7,7 @@ const char* ffDetectSwap(FFSwapResult* swap) { - ULONG size = sizeof(SYSTEM_PAGEFILE_INFORMATION); + ULONG size = sizeof(SYSTEM_PAGEFILE_INFORMATION) * 2; SYSTEM_PAGEFILE_INFORMATION* FF_AUTO_FREE pstart = (SYSTEM_PAGEFILE_INFORMATION*)malloc(size); while(true) { @@ -16,6 +16,7 @@ const char* ffDetectSwap(FFSwapResult* swap) { if(!(pstart = (SYSTEM_PAGEFILE_INFORMATION*)realloc(pstart, size))) return "realloc(pstart, size) failed"; + continue; } else if(!NT_SUCCESS(status)) return "NtQuerySystemInformation(SystemPagefileInformation, size) failed"; From e3cdecdb14ce21a32fbfb3a3f7eb28e5c4590155 Mon Sep 17 00:00:00 2001 From: halperyon <130178512+halperyon@users.noreply.github.com> Date: Tue, 23 Apr 2024 23:45:45 +0000 Subject: [PATCH 06/30] bedrock version (#809) --- src/detection/os/os_linux.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/detection/os/os_linux.c b/src/detection/os/os_linux.c index 5058033a2..74e9f1475 100644 --- a/src/detection/os/os_linux.c +++ b/src/detection/os/os_linux.c @@ -150,8 +150,11 @@ static void detectOS(FFOSResult* os) if(os->prettyName.length == 0) ffStrbufAppendS(&os->prettyName, "Bedrock Linux"); + + parseFile("/bedrock"FASTFETCH_TARGET_DIR_ETC"/os-release", os); - return; + if(allRelevantValuesSet(os)) + return; } parseFile(FASTFETCH_TARGET_DIR_ETC"/os-release", os); From e660e61027593e30ce3fd5ab7ce8e55de8532f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 24 Apr 2024 11:04:03 +0800 Subject: [PATCH 07/30] Swap (Windows): fix x86-32 (v2) --- src/detection/swap/swap_windows.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/detection/swap/swap_windows.c b/src/detection/swap/swap_windows.c index 52d713c2b..5b3a15457 100644 --- a/src/detection/swap/swap_windows.c +++ b/src/detection/swap/swap_windows.c @@ -7,21 +7,11 @@ const char* ffDetectSwap(FFSwapResult* swap) { - ULONG size = sizeof(SYSTEM_PAGEFILE_INFORMATION) * 2; - SYSTEM_PAGEFILE_INFORMATION* FF_AUTO_FREE pstart = (SYSTEM_PAGEFILE_INFORMATION*)malloc(size); - while(true) - { - NTSTATUS status = NtQuerySystemInformation(SystemPagefileInformation, pstart, size, &size); - if(status == STATUS_INFO_LENGTH_MISMATCH) - { - if(!(pstart = (SYSTEM_PAGEFILE_INFORMATION*)realloc(pstart, size))) - return "realloc(pstart, size) failed"; - continue; - } - else if(!NT_SUCCESS(status)) - return "NtQuerySystemInformation(SystemPagefileInformation, size) failed"; - break; - } + uint8_t buffer[1024]; + ULONG size = sizeof(buffer); + SYSTEM_PAGEFILE_INFORMATION* pstart = (SYSTEM_PAGEFILE_INFORMATION*) buffer; + if(!NT_SUCCESS(NtQuerySystemInformation(SystemPagefileInformation, pstart, size, &size))) + return "NtQuerySystemInformation(SystemPagefileInformation, size) failed"; uint32_t pageSize = instance.state.platform.pageSize; swap->bytesUsed = (uint64_t)pstart->TotalUsed * pageSize; From beb5f479d92f914b305a931a6d916dfd7582e7ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 24 Apr 2024 19:01:46 +0800 Subject: [PATCH 08/30] CI: build Linux binaries with Ubuntu 20.04 again... Ref: #808 --- .github/workflows/ci.yml | 74 ++-------------------------------------- README.md | 4 +-- 2 files changed, 4 insertions(+), 74 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 557425515..2b4a25576 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,8 +19,8 @@ jobs: - name: Run Spellchecker run: codespell - Linux-old-amd64: - name: Linux-old-amd64 + Linux-amd64: + name: Linux-amd64 runs-on: ubuntu-20.04 permissions: security-events: write @@ -72,71 +72,6 @@ jobs: - name: run tests run: ctest - - name: upload artifacts - uses: actions/upload-artifact@v4 - with: - name: fastfetch-linux-old-amd64 - path: ./fastfetch-*.* - - linux-amd64: - name: Linux-amd64 - runs-on: ubuntu-22.04 # Ubuntu 22.04 uses Glibc 2.35. Should be fine with Debian 12, which uses Glibc 2.36 (https://packages.debian.org/source/bookworm/glibc) - permissions: - security-events: write - contents: read - outputs: - ffversion: ${{ steps.ffversion.outputs.ffversion }} - steps: - - name: checkout repository - uses: actions/checkout@v4 - - - name: uname -a - run: uname -a - - - name: install required packages - run: sudo apt-get update && sudo apt-get install -y libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libxfconf-0-dev libsqlite3-dev librpm-dev libegl-dev libglx-dev libosmesa6-dev ocl-icd-opencl-dev libnm-dev libpulse-dev libdrm-dev libddcutil-dev libchafa-dev directx-headers-dev - - - name: install linuxbrew packages - run: | - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - /home/linuxbrew/.linuxbrew/bin/brew install imagemagick --ignore-dependencies - - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: c - - - name: configure project - run: PKG_CONFIG_PATH=/home/linuxbrew/.linuxbrew/lib/pkgconfig:$PKG_CONFIG_PATH cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DCMAKE_INSTALL_PREFIX=/usr . - - - name: build project - run: cmake --build . --target package --verbose -j4 - - - name: perform CodeQL analysis - uses: github/codeql-action/analyze@v3 - - - name: list features - run: ./fastfetch --list-features - - - name: run fastfetch - run: time ./fastfetch -c presets/ci.jsonc - - - name: run fastfetch --format json - run: time ./fastfetch -c presets/ci.jsonc --format json - - - name: run flashfetch - run: time ./flashfetch - - - name: print dependencies - run: ldd fastfetch - - - name: run tests - run: ctest - - - name: get fastfetch version - id: ffversion - run: echo "ffversion=$(./fastfetch --version-raw)" >> $GITHUB_OUTPUT - - name: upload artifacts uses: actions/upload-artifact@v4 with: @@ -541,11 +476,6 @@ jobs: if: needs.linux-amd64.outputs.ffversion != steps.get_version_release.outputs.release uses: actions/download-artifact@v4 - - name: rm old artifacts - if: needs.linux-amd64.outputs.ffversion != steps.get_version_release.outputs.release - run: | - rm -rf fastfetch-*-old-* - - name: create release if: needs.linux-amd64.outputs.ffversion != steps.get_version_release.outputs.release uses: ncipollo/release-action@v1 diff --git a/README.md b/README.md index cc40b2ee6..9dc5c7a00 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,8 @@ There are [screenshots on different platforms](https://github.com/fastfetch-cli/ Some distros packaged an outdated fastfetch version. Older version is not supported, please always ensure that the latest version is used. -* Ubuntu: [`ppa:zhangsongcui3371/fastfetch`](https://launchpad.net/~zhangsongcui3371/+archive/ubuntu/fastfetch) (for Ubuntu 22.04 or above) -* Debian / Ubuntu: Download `fastfetch--Linux.deb` from [Github release page](https://github.com/fastfetch-cli/fastfetch/releases/latest) and `dpkg -i fastfetch--Linux.deb` (for Ubuntu 22.04 or above and Debian 12 or above). +* Ubuntu: [`ppa:zhangsongcui3371/fastfetch`](https://launchpad.net/~zhangsongcui3371/+archive/ubuntu/fastfetch) (for Ubuntu 22.04 or newer) +* Debian / Ubuntu: Download `fastfetch--Linux.deb` from [Github release page](https://github.com/fastfetch-cli/fastfetch/releases/latest) and `dpkg -i fastfetch--Linux.deb` (for Ubuntu 20.04 or newer and Debian 11 or newer). * Arch Linux: `sudo pacman -S fastfetch` * Fedora: `sudo dnf install fastfetch` * Gentoo: `sudo emerge --ask app-misc/fastfetch` From de4afb650737884040c42093948e9cad4928bd3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 24 Apr 2024 19:24:24 +0800 Subject: [PATCH 09/30] CI: test with no dependencies installed --- .github/workflows/ci.yml | 43 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2b4a25576..6b4934da6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,12 +14,51 @@ jobs: - name: Install codespell shell: bash - run: sudo apt update && sudo apt install -y codespell + run: | + sudo apt-get update || true + sudo apt-get install -y codespell - name: Run Spellchecker run: codespell - Linux-amd64: + no-features-test: + name: No-features-test + runs-on: ubuntu-latest + permissions: + security-events: write + contents: read + steps: + - name: checkout repository + uses: actions/checkout@v4 + + - name: uname -a + run: uname -a + + - name: configure project + run: cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DCMAKE_INSTALL_PREFIX=/usr . -DENABLE_VULKAN=OFF -DENABLE_WAYLAND=OFF -DENABLE_XCB_RANDR=OFF -DENABLE_XCB=OFF -DENABLE_XRANDR=OFF -DENABLE_X11=OFF -DENABLE_DRM=OFF -DENABLE_GIO=OFF -DENABLE_DCONF=OFF -DENABLE_DBUS=OFF -DENABLE_XFCONF=OFF -DENABLE_SQLITE3=OFF -DENABLE_RPM=OFF -DENABLE_IMAGEMAGICK7=OFF -DENABLE_IMAGEMAGICK6=OFF -DENABLE_CHAFA=OFF -DENABLE_ZLIB=OFF -DENABLE_EGL=OFF -DENABLE_GLX=OFF -DENABLE_OSMESA=OFF -DENABLE_OPENCL=OFF -DENABLE_LIBNM=OFF -DENABLE_FREETYPE=OFF -DENABLE_PULSE=OFF -DENABLE_DDCUTIL=OFF -DENABLE_DIRECTX_HEADERS=OFF -DENABLE_THREADS=OFF + + - name: build project + run: cmake --build . --target package --verbose -j4 + + - name: list features + run: ./fastfetch --list-features + + - name: run fastfetch + run: time ./fastfetch -c presets/ci.jsonc + + - name: run fastfetch --format json + run: time ./fastfetch -c presets/ci.jsonc --format json + + - name: run flashfetch + run: time ./flashfetch + + - name: print dependencies + run: ldd fastfetch + + - name: run tests + run: ctest + + linux-amd64: name: Linux-amd64 runs-on: ubuntu-20.04 permissions: From e596d76430f955efde05b9c2f017182da106fa99 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 25 Apr 2024 09:08:21 +0800 Subject: [PATCH 10/30] Display (Linux): don't use `*-unknown` as name --- src/detection/displayserver/linux/wayland/global-output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/detection/displayserver/linux/wayland/global-output.c b/src/detection/displayserver/linux/wayland/global-output.c index c38ceee03..956afc376 100644 --- a/src/detection/displayserver/linux/wayland/global-output.c +++ b/src/detection/displayserver/linux/wayland/global-output.c @@ -118,7 +118,7 @@ void ffWaylandHandleGlobalOutput(WaylandData* wldata, struct wl_registry* regist rotation, display.edidName.length ? &display.edidName - : display.description.length + : display.description.length && !ffStrbufEndsWithS(&display.description, "-unknown") ? &display.description : &display.name, display.type, From 6805cb16fbb1a633fc920b36667c9861990c2c47 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 25 Apr 2024 09:16:12 +0800 Subject: [PATCH 11/30] Packages: support printing total number of nix / flatpak / brew packages Ref: https://github.com/fastfetch-cli/fastfetch/issues/436#issuecomment-2075469683 --- src/modules/packages/packages.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/modules/packages/packages.c b/src/modules/packages/packages.c index 843f620c6..de81f49e7 100644 --- a/src/modules/packages/packages.c +++ b/src/modules/packages/packages.c @@ -4,7 +4,7 @@ #include "modules/packages/packages.h" #include "util/stringUtils.h" -#define FF_PACKAGES_NUM_FORMAT_ARGS 26 +#define FF_PACKAGES_NUM_FORMAT_ARGS 29 void ffPrintPackages(FFPackagesOptions* options) { @@ -70,6 +70,9 @@ void ffPrintPackages(FFPackagesOptions* options) } else { + uint32_t nixAll = counts.nixDefault + counts.nixSystem + counts.nixUser; + uint32_t flatpakAll = counts.flatpakSystem + counts.flatpakUser; + uint32_t brewAll = counts.brew + counts.brewCask; FF_PRINT_FORMAT_CHECKED(FF_PACKAGES_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_PACKAGES_NUM_FORMAT_ARGS, ((FFformatarg[]){ {FF_FORMAT_ARG_TYPE_UINT, &counts.all}, {FF_FORMAT_ARG_TYPE_UINT, &counts.pacman}, @@ -97,6 +100,9 @@ void ffPrintPackages(FFPackagesOptions* options) {FF_FORMAT_ARG_TYPE_UINT, &counts.winget}, {FF_FORMAT_ARG_TYPE_UINT, &counts.opkg}, {FF_FORMAT_ARG_TYPE_UINT, &counts.am}, + {FF_FORMAT_ARG_TYPE_UINT, &nixAll}, + {FF_FORMAT_ARG_TYPE_UINT, &flatpakAll}, + {FF_FORMAT_ARG_TYPE_UINT, &brewAll}, })); } @@ -394,6 +400,9 @@ void ffPrintPackagesHelpFormat(void) "Number of winget packages", "Number of opkg packages", "Number of am packages", + "Total number of all nix packages", + "Total number of all flatpak packages", + "Total number of all brew packages", })); } From ab8ad7ffc08a926052cd9be72eeb6fb9ffb1e851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 25 Apr 2024 14:18:25 +0800 Subject: [PATCH 12/30] Fastfetch: default `hideCursor` to false It doesn't make much difference but make user's terminal unusable if fastfetch is not exited correctly --- src/options/display.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/options/display.c b/src/options/display.c index 423177286..f5683fc21 100644 --- a/src/options/display.c +++ b/src/options/display.c @@ -354,12 +354,11 @@ void ffOptionsInitDisplay(FFOptionsDisplay* options) #ifdef NDEBUG options->disableLinewrap = !options->pipe; - options->hideCursor = !options->pipe; #else options->disableLinewrap = false; - options->hideCursor = false; #endif + options->hideCursor = false; options->binaryPrefixType = FF_BINARY_PREFIX_TYPE_IEC; options->sizeNdigits = 2; options->sizeMaxPrefix = UINT8_MAX; From 229c6674a45eedfd5a5e39cbd7a1288fcca38fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 25 Apr 2024 15:48:39 +0800 Subject: [PATCH 13/30] CMake: fix #810 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c17e7456b..43dfc36e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -255,7 +255,7 @@ file(GLOB LOGO_FILES "src/logo/ascii/*.txt") set(LOGO_BUILTIN_H "#pragma once\n#pragma GCC diagnostic ignored \"-Wtrigraphs\"\n\n") foreach(file ${LOGO_FILES}) fastfetch_load_text("${file}" content) - get_filename_component(file "${file}" NAME_WLE) + get_filename_component(file "${file}" NAME_WE) string(TOUPPER "${file}" file) string(REGEX REPLACE "\\$\\{c([0-9]+)\\}" "$\\1" content "${content}") set(LOGO_BUILTIN_H "${LOGO_BUILTIN_H}#define FASTFETCH_DATATEXT_LOGO_${file} ${content}\n") From 74c89cc03f38597e191631b298e989f44e2591c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 26 Apr 2024 19:26:58 +0800 Subject: [PATCH 14/30] Wifi (Linux): try fixing #811 --- src/detection/wifi/wifi_linux.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/detection/wifi/wifi_linux.c b/src/detection/wifi/wifi_linux.c index d9788c994..fffadc9a2 100644 --- a/src/detection/wifi/wifi_linux.c +++ b/src/detection/wifi/wifi_linux.c @@ -337,7 +337,8 @@ static const char* detectWifiWithIoctls(FFlist* result) const char* ffDetectWifi(FFlist* result) { #ifdef FF_HAVE_LIBNM - if(!detectWifiWithLibnm(result)) + detectWifiWithLibnm(result); + if(result->length) // NetworkManager not enabled? #811 return NULL; #endif From e157b9a51fc14f951fd34525c8081e9006f6775e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 27 Apr 2024 16:29:35 +0800 Subject: [PATCH 15/30] TerminalShell (Linux): fix nixos wrapped process name Fix #814 --- src/detection/terminalshell/terminalshell_linux.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index e6e28794c..7e7477933 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -482,14 +482,12 @@ static void setShellInfoDetails(FFShellResult* result) static void setTerminalInfoDetails(FFTerminalResult* result) { - if(result->exeName[0] == '.' && ffStrEndsWith(result->exeName, "-wrapped")) + if(ffStrbufStartsWithC(&result->processName, '.') && ffStrbufEndsWithS(&result->processName, "-wrapped")) { // For NixOS. Ref: #510 and https://github.com/NixOS/nixpkgs/pull/249428 // We use processName when detecting version and font, overriding it for simplification - ffStrbufSetNS( - &result->processName, - (uint32_t) (strlen(result->exeName) - strlen(".-wrapped")), - result->exeName + 1); + ffStrbufSubstrBefore(&result->processName, result->processName.length - (uint32_t) strlen("-wrapped")); + ffStrbufSubstrAfter(&result->processName, 1); } if(ffStrbufEqualS(&result->processName, "wezterm-gui")) From 866e65749e6cd232d7f2ee77a56b55e5312bf2e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 27 Apr 2024 16:36:33 +0800 Subject: [PATCH 16/30] Init: tweaks --- CMakeLists.txt | 4 ---- src/common/init.c | 10 +++++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 43dfc36e2..bc9fa4ddf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -933,10 +933,6 @@ if(ENABLE_THREADS) endif() endif() -if(ENABLE_PCI_MEMORY) - target_compile_definitions(libfastfetch PRIVATE FF_USE_PCI_MEMORY) -endif() - if(LINUX) target_link_libraries(libfastfetch PRIVATE "m" diff --git a/src/common/init.c b/src/common/init.c index c8ab6593e..853042fc8 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -238,9 +238,6 @@ void ffListFeatures(void) #ifdef FF_HAVE_DDCUTIL "libddcutil\n" #endif - #if __has_include() - "videodev2\n" - #endif #ifdef FF_HAVE_DIRECTX_HEADERS "Directx Headers\n" #endif @@ -250,8 +247,11 @@ void ffListFeatures(void) #ifdef FF_USE_SYSTEM_YYJSON "System yyjson\n" #endif - #ifdef FF_USE_PCI_MEMORY - "PCI memory\n" + #if __has_include() + "linux/videodev2\n" + #endif + #if __has_include() + "linux/wireless\n" #endif "" , stdout); From 35b54fd064a353426229201d3c73f6b49c8a0445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 27 Apr 2024 17:30:42 +0800 Subject: [PATCH 17/30] Separator: add fast path for ascii strings --- src/modules/separator/separator.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/modules/separator/separator.c b/src/modules/separator/separator.c index 538b651f4..7f8ac41d3 100644 --- a/src/modules/separator/separator.c +++ b/src/modules/separator/separator.c @@ -12,9 +12,20 @@ static inline uint32_t max(uint32_t a, uint32_t b) static inline uint32_t getWcsWidth(const FFstrbuf* mbstr, wchar_t* wstr, mbstate_t* state) { + int result = 1; + for (uint32_t i = 0; i < mbstr->length; i++) + { + if (!isascii(mbstr->chars[i])) + { + result = 0; + break; + } + } + if (__builtin_expect(result, 1)) return mbstr->length; + const char* str = mbstr->chars; uint32_t wstrLength = (uint32_t) mbsrtowcs(wstr, &str, mbstr->length, state); - int result = mk_wcswidth(wstr, wstrLength); + result = mk_wcswidth(wstr, wstrLength); return result > 0 ? (uint32_t) result : mbstr->length; } @@ -32,9 +43,9 @@ void ffPrintSeparator(FFSeparatorOptions* options) + (fqdn ? platform->hostName.length : ffStrbufFirstIndexC(&platform->hostName, '.')); // host name ffLogoPrintLine(); - if(options->string.length == 0) + if(__builtin_expect(options->string.length == 1, 1)) { - ffPrintCharTimes('-', titleLength); + ffPrintCharTimes(options->string.chars[0], titleLength); } else { @@ -131,7 +142,7 @@ void ffInitSeparatorOptions(FFSeparatorOptions* options) NULL, ffGenerateSeparatorJsonConfig ); - ffStrbufInit(&options->string); + ffStrbufInitStatic(&options->string, "-"); } void ffDestroySeparatorOptions(FFSeparatorOptions* options) From 81fb1468699491d301013294113fd90a0105a840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 27 Apr 2024 23:05:36 +0800 Subject: [PATCH 18/30] CPU (Windows): detect max CPU freq with `CPUID` instruction Note this only works when Hyper-V is not enabled Ultimately fixes #800 #812 #815 --- src/detection/cpu/cpu_windows.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/detection/cpu/cpu_windows.c b/src/detection/cpu/cpu_windows.c index 2a8b69bfb..534ec74b4 100644 --- a/src/detection/cpu/cpu_windows.c +++ b/src/detection/cpu/cpu_windows.c @@ -50,6 +50,31 @@ typedef struct FFSmbiosProcessorInfo uint16_t ThreadEnabled; // varies } FFSmbiosProcessorInfo; +#if defined(__x86_64__) || defined(__i386__) + +#include + +inline static const char* detectSpeedByCpuid(FFCPUResult* cpu) +{ + uint32_t base = 0, max = 0, bus = 0, unused = 0; + if (!__get_cpuid(0x16, &base, &max, &bus, &unused)) + return "Unsupported instruction"; + + // cpuid returns 0 MHz when hyper-v is enabled + if (base) cpu->frequencyBase = base / 1000.0; + if (max) cpu->frequencyMax = max / 1000.0; + return NULL; +} + +#else + +inline static const char* detectSpeedByCpuid(FFCPUResult* cpu) +{ + return "Unsupported platform"; +} + +#endif + static const char* detectMaxSpeedBySmbios(FFCPUResult* cpu) { const FFSmbiosProcessorInfo* data = (const FFSmbiosProcessorInfo*) (*ffGetSmbiosHeaderTable())[FF_SMBIOS_TYPE_PROCESSOR_INFO]; @@ -114,6 +139,7 @@ static const char* detectByRegistry(FFCPUResult* cpu) if(!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", &hKey, NULL)) return "ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L\"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0\", &hKey, NULL) failed"; + if (detectSpeedByCpuid(cpu) == NULL && cpu->frequencyBase == 0) { uint32_t mhz; if(ffRegReadUint(hKey, L"~MHz", &mhz, NULL)) @@ -141,7 +167,8 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) if (error) return error; - detectMaxSpeedBySmbios(cpu); + if (cpu->frequencyMax == 0) + detectMaxSpeedBySmbios(cpu); if(options->temp) ffDetectSmbiosTemp(&cpu->temperature, NULL); From 6831c095eca6524e2e15315c648623cb32f66dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 27 Apr 2024 23:12:45 +0800 Subject: [PATCH 19/30] TerminalShell (Linux): actually fix #814 --- src/detection/terminalshell/terminalshell_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index 7e7477933..a12bb0930 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -487,7 +487,7 @@ static void setTerminalInfoDetails(FFTerminalResult* result) // For NixOS. Ref: #510 and https://github.com/NixOS/nixpkgs/pull/249428 // We use processName when detecting version and font, overriding it for simplification ffStrbufSubstrBefore(&result->processName, result->processName.length - (uint32_t) strlen("-wrapped")); - ffStrbufSubstrAfter(&result->processName, 1); + ffStrbufSubstrAfter(&result->processName, 0); } if(ffStrbufEqualS(&result->processName, "wezterm-gui")) From 115b293ff55c0f8b228c259dcf6f71fd169e382b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 27 Apr 2024 23:27:16 +0800 Subject: [PATCH 20/30] CPU (Windows): fix silly bug... --- src/detection/cpu/cpu_windows.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/detection/cpu/cpu_windows.c b/src/detection/cpu/cpu_windows.c index 534ec74b4..6a4d8195e 100644 --- a/src/detection/cpu/cpu_windows.c +++ b/src/detection/cpu/cpu_windows.c @@ -139,7 +139,7 @@ static const char* detectByRegistry(FFCPUResult* cpu) if(!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", &hKey, NULL)) return "ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L\"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0\", &hKey, NULL) failed"; - if (detectSpeedByCpuid(cpu) == NULL && cpu->frequencyBase == 0) + if (detectSpeedByCpuid(cpu) != NULL || cpu->frequencyBase != cpu->frequencyBase) { uint32_t mhz; if(ffRegReadUint(hKey, L"~MHz", &mhz, NULL)) @@ -167,7 +167,7 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) if (error) return error; - if (cpu->frequencyMax == 0) + if (cpu->frequencyMax != cpu->frequencyMax) detectMaxSpeedBySmbios(cpu); if(options->temp) From d4a402f4ddb0972d57a3f881fd251b3921be9320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 26 Apr 2024 08:48:58 +0800 Subject: [PATCH 21/30] Common: slience compiler warnings --- src/common/library.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/library.c b/src/common/library.c index 7f858e966..e776516b5 100644 --- a/src/common/library.c +++ b/src/common/library.c @@ -4,7 +4,7 @@ #include //Clang doesn't define __SANITIZE_ADDRESS__ but defines __has_feature(address_sanitizer) -#if defined(__has_feature) +#if !defined(__SANITIZE_ADDRESS__) && defined(__has_feature) #if __has_feature(address_sanitizer) #define __SANITIZE_ADDRESS__ #endif From bdd2908e6ae152bf011797230ec40881c89f9623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 28 Apr 2024 10:46:08 +0800 Subject: [PATCH 22/30] Doc: update changelog --- CHANGELOG.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13ee141ef..00bb9c8f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,22 @@ +# 2.10.3 + +Changes: +* Default `hideCursor` to false. It doesn't make much difference but makes user's terminal unusable if fastfetch is not exited correctly. +* Linux amd64 binaries are built with Ubuntu 20.04 again (#808) + * Note aarch64 binaries are unchanged (built with Ubuntu 22.04) + +Bugfixes: +* Fix swap usage detection in x86-32 build (Windows, Swap) +* Fix minimum cmake version support (#810) +* Fix wifi detection on platforms that don't use NetworkManager (#811, Wifi, Linux) +* Fix nixos wrapped process name (#814) + +Features: +* Add basic support DE detection support for UKUI (DE, Linux) +* Support printing total number of nix / flatpak / brew packages (Packages) +* Better max CPU frequency detection support with `CPUID / 16H` instruction (CPU, Windows) + * This requires Core I Gen 6 or newer, and with `Virtual Machine Platform` Windows feature disabled. X86 only. + # 2.10.2 Bugfixes: From 882b17834cbcc3b424f69b6df3ba28efdaf905cd Mon Sep 17 00:00:00 2001 From: Juan Llamas <38849891+xoltia@users.noreply.github.com> Date: Sun, 28 Apr 2024 20:59:05 -0500 Subject: [PATCH 23/30] Packages (nix): use hash to cache count and process count manually (#817) --- src/detection/packages/packages_linux.c | 146 ++++++++++++++++++++++-- 1 file changed, 135 insertions(+), 11 deletions(-) diff --git a/src/detection/packages/packages_linux.c b/src/detection/packages/packages_linux.c index 9f5b3c307..e451a2a6d 100644 --- a/src/detection/packages/packages_linux.c +++ b/src/detection/packages/packages_linux.c @@ -118,28 +118,152 @@ static uint32_t countFilesRecursive(FFstrbuf* baseDir, const char* dirname, cons return sum; } +static bool isValidNixPkg(FFstrbuf* pkg) +{ + if (!ffPathExists(pkg->chars, FF_PATHTYPE_DIRECTORY)) + return false; + + ffStrbufSubstrAfterLastC(pkg, '/'); + if ( + ffStrbufStartsWithS(pkg, "nixos-system-nixos-") || + ffStrbufEndsWithS(pkg, "-doc") || + ffStrbufEndsWithS(pkg, "-man") || + ffStrbufEndsWithS(pkg, "-info") || + ffStrbufEndsWithS(pkg, "-dev") || + ffStrbufEndsWithS(pkg, "-bin") + ) return false; + + enum { START, DIGIT, DOT, MATCH } state = START; + + for (uint32_t i = 0; i < pkg->length; i++) + { + char c = pkg->chars[i]; + switch (state) + { + case START: + if (c >= '0' && c <= '9') + state = DIGIT; + break; + case DIGIT: + if (c >= '0' && c <= '9') + continue; + if (c == '.') + state = DOT; + else + state = START; + break; + case DOT: + if (c >= '0' && c <= '9') + state = MATCH; + else + state = START; + break; + case MATCH: + break; + } + } + + return state == MATCH; +} + +static bool checkNixCache(FFstrbuf* cacheDir, FFstrbuf* hash, uint32_t* count) +{ + if (!ffPathExists(cacheDir->chars, FF_PATHTYPE_FILE)) + return false; + + FF_STRBUF_AUTO_DESTROY cacheContent; + ffStrbufInit(&cacheContent); + if (!ffReadFileBuffer(cacheDir->chars, &cacheContent)) + return false; + + // Format: \n + uint32_t split = ffStrbufFirstIndexC(&cacheContent, '\n'); + if (split == cacheContent.length) + return false; + + ffStrbufSetNS(hash, split, cacheContent.chars); + *count = (uint32_t)atoi(cacheContent.chars + split + 1); + + return true; +} + +static bool writeNixCache(FFstrbuf* cacheDir, FFstrbuf* hash, uint32_t count) +{ + FF_STRBUF_AUTO_DESTROY cacheContent; + ffStrbufInit(&cacheContent); + ffStrbufAppend(&cacheContent, hash); + ffStrbufAppendC(&cacheContent, '\n'); + ffStrbufAppendF(&cacheContent, "%u", count); + return ffWriteFileBuffer(cacheDir->chars, &cacheContent); +} + static uint32_t getNixPackagesImpl(char* path) { //Nix detection is kinda slow, so we only do it if the dir exists if(!ffPathExists(path, FF_PATHTYPE_DIRECTORY)) return 0; - FF_STRBUF_AUTO_DESTROY output = ffStrbufCreateA(128); + FF_STRBUF_AUTO_DESTROY cacheDir; + ffStrbufInit(&cacheDir); + ffStrbufAppend(&cacheDir, &instance.state.platform.cacheDir); + ffStrbufEnsureEndsWithC(&cacheDir, '/'); + ffStrbufAppendS(&cacheDir, "fastfetch/packages/nix"); + ffStrbufAppendS(&cacheDir, path); - //https://github.com/fastfetch-cli/fastfetch/issues/195#issuecomment-1191748222 - FF_STRBUF_AUTO_DESTROY command = ffStrbufCreateA(255); - ffStrbufAppendS(&command, "for x in $(nix-store --query --requisites "); - ffStrbufAppendS(&command, path); - ffStrbufAppendS(&command, "); do if [ -d $x ]; then echo $x ; fi ; done | cut -d- -f2- | egrep '([0-9]{1,}\\.)+[0-9]{1,}' | egrep -v '\\-doc$|\\-man$|\\-info$|\\-dev$|\\-bin$|^nixos-system-nixos-' | uniq | wc -l"); + //Check the hash first to determine if we need to recompute the count + FF_STRBUF_AUTO_DESTROY hash = ffStrbufCreateA(64); + FF_STRBUF_AUTO_DESTROY cacheHash = ffStrbufCreateA(64); + uint32_t count = 0; - ffProcessAppendStdOut(&output, (char* const[]) { - "sh", - "-c", - command.chars, + ffProcessAppendStdOut(&hash, (char* const[]) { + "nix-store", + "--query", + "--hash", + path, NULL }); - return (uint32_t) strtol(output.chars, NULL, 10); + if (checkNixCache(&cacheDir, &cacheHash, &count) && ffStrbufEqual(&hash, &cacheHash)) + return count; + + //Cache is invalid, recompute the count + count = 0; + + //Implementation based on bash script from here: + //https://github.com/fastfetch-cli/fastfetch/issues/195#issuecomment-1191748222 + + FF_STRBUF_AUTO_DESTROY output = ffStrbufCreateA(1024); + + ffProcessAppendStdOut(&output, (char* const[]) { + "nix-store", + "--query", + "--requisites", + path, + NULL + }); + + uint32_t lineLength = 0; + for (uint32_t i = 0; i < output.length; i++) + { + if (output.chars[i] != '\n') + { + lineLength++; + continue; + } + + output.chars[i] = '\0'; + FFstrbuf line = { + .allocated = 0, + .length = lineLength, + .chars = output.chars + i - lineLength + }; + if (isValidNixPkg(&line)) + count++; + lineLength = 0; + } + + writeNixCache(&cacheDir, &hash, count); + return count; } static uint32_t getNixPackages(FFstrbuf* baseDir, const char* dirname) From 39dfcb6f1027ec0012a81fb54c20260100e18fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 29 Apr 2024 10:04:20 +0800 Subject: [PATCH 24/30] Packages (Linux): optimise nix detection code --- src/detection/packages/packages_linux.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/detection/packages/packages_linux.c b/src/detection/packages/packages_linux.c index e451a2a6d..aada79a74 100644 --- a/src/detection/packages/packages_linux.c +++ b/src/detection/packages/packages_linux.c @@ -171,8 +171,7 @@ static bool checkNixCache(FFstrbuf* cacheDir, FFstrbuf* hash, uint32_t* count) if (!ffPathExists(cacheDir->chars, FF_PATHTYPE_FILE)) return false; - FF_STRBUF_AUTO_DESTROY cacheContent; - ffStrbufInit(&cacheContent); + FF_STRBUF_AUTO_DESTROY cacheContent = ffStrbufCreate(); if (!ffReadFileBuffer(cacheDir->chars, &cacheContent)) return false; @@ -189,11 +188,8 @@ static bool checkNixCache(FFstrbuf* cacheDir, FFstrbuf* hash, uint32_t* count) static bool writeNixCache(FFstrbuf* cacheDir, FFstrbuf* hash, uint32_t count) { - FF_STRBUF_AUTO_DESTROY cacheContent; - ffStrbufInit(&cacheContent); - ffStrbufAppend(&cacheContent, hash); - ffStrbufAppendC(&cacheContent, '\n'); - ffStrbufAppendF(&cacheContent, "%u", count); + FF_STRBUF_AUTO_DESTROY cacheContent = ffStrbufCreateCopy(hash); + ffStrbufAppendF(&cacheContent, "\n%u", count); return ffWriteFileBuffer(cacheDir->chars, &cacheContent); } @@ -203,9 +199,7 @@ static uint32_t getNixPackagesImpl(char* path) if(!ffPathExists(path, FF_PATHTYPE_DIRECTORY)) return 0; - FF_STRBUF_AUTO_DESTROY cacheDir; - ffStrbufInit(&cacheDir); - ffStrbufAppend(&cacheDir, &instance.state.platform.cacheDir); + FF_STRBUF_AUTO_DESTROY cacheDir = ffStrbufCreateCopy(&instance.state.platform.cacheDir); ffStrbufEnsureEndsWithC(&cacheDir, '/'); ffStrbufAppendS(&cacheDir, "fastfetch/packages/nix"); ffStrbufAppendS(&cacheDir, path); @@ -231,7 +225,7 @@ static uint32_t getNixPackagesImpl(char* path) //Implementation based on bash script from here: //https://github.com/fastfetch-cli/fastfetch/issues/195#issuecomment-1191748222 - + FF_STRBUF_AUTO_DESTROY output = ffStrbufCreateA(1024); ffProcessAppendStdOut(&output, (char* const[]) { @@ -261,7 +255,7 @@ static uint32_t getNixPackagesImpl(char* path) count++; lineLength = 0; } - + writeNixCache(&cacheDir, &hash, count); return count; } From 29644ef9046d156dbf5a573f692a0ec028d4f1bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 29 Apr 2024 13:27:57 +0800 Subject: [PATCH 25/30] GPU (Linux): disable vmem detection Ref #816 --- src/detection/gpu/gpu_linux.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index b497a8a5a..47f5cdee1 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -186,8 +186,12 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf ffGPUParsePciIds(&pciids, subclassId, (uint16_t) vendorId, (uint16_t) deviceId, gpu); } - pciDetectVmem(gpu, drmDir, buffer); - ffStrbufSubstrBefore(drmDir, drmDirPathLength); + // Temporarily disabled for now #816 + if (false) + { + pciDetectVmem(gpu, drmDir, buffer); + ffStrbufSubstrBefore(drmDir, drmDirPathLength); + } pciDetectVfreq(gpu, drmDir, buffer); ffStrbufSubstrBefore(drmDir, drmDirPathLength); From 6bd3d2c4345d9e562f336a39a57d633770cd120c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 29 Apr 2024 20:05:40 +0800 Subject: [PATCH 26/30] GPU (Linux): greatly improve detection for AMD cards Completely untested --- src/detection/gpu/gpu_linux.c | 158 +++++++++++++++++++--------------- 1 file changed, 87 insertions(+), 71 deletions(-) diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 47f5cdee1..69ffdd9d5 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -15,23 +15,6 @@ #include -FF_MAYBE_UNUSED static void pciDetectTemp(FFGPUResult* gpu, uint32_t deviceClass) -{ - const FFlist* tempsResult = ffDetectTemps(); - - FF_LIST_FOR_EACH(FFTempValue, tempValue, *tempsResult) - { - // https://www.kernel.org/doc/html/v5.10/gpu/amdgpu.html#hwmon-interfaces - // FIXME: this code doesn't take multiGPUs into count - // The kernel exposes the device class multiplied by 256 for some reason - if(tempValue->deviceClass == deviceClass * 256) - { - gpu->temperature = tempValue->value; - return; - } - } -} - static void pciDetectDriver(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer) { ffStrbufAppendS(pciDir, "/driver"); @@ -56,33 +39,59 @@ static void pciDetectDriver(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer } } -static void pciDetectVmem(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer) +static void pciDetectAmdSpecific(const FFGPUOptions* options, FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer) { - // Works for AMD GPUs // https://www.kernel.org/doc/html/v5.10/gpu/amdgpu.html#mem-info-vis-vram-total - ffStrbufAppendS(pciDir, "/mem_info_vis_vram_total"); - uint64_t size = 0; - if (ffReadFileBuffer(pciDir->chars, buffer) && (size = ffStrbufToUInt(buffer, 0))) - { - gpu->type = size > 1024UL * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED; - if (gpu->type == FF_GPU_TYPE_DISCRETE) - gpu->dedicated.total = size; - else - gpu->shared.total = size; + const uint32_t pciDirLen = pciDir->length; - ffStrbufSubstrBefore(pciDir, pciDir->length - (uint32_t) strlen("/mem_info_vis_vram_total")); - ffStrbufAppendS(pciDir, "/mem_info_vram_used"); - if (ffReadFileBuffer(pciDir->chars, buffer) && (size = ffStrbufToUInt(buffer, 0))) + ffStrbufAppendS(pciDir, "/hwmon/"); + FF_AUTO_CLOSE_DIR DIR* dirp = opendir(pciDir->chars); + struct dirent* entry = readdir(dirp); + if (!entry) return; + ffStrbufAppendS(pciDir, entry->d_name); + ffStrbufAppendC(pciDir, '/'); + + const uint32_t hwmonLen = pciDir->length; + ffStrbufAppendS(pciDir, "in1_input"); // Northbridge voltage in millivolts (APUs only) + if (ffPathExists(pciDir->chars, FF_PATHTYPE_FILE)) + gpu->type = FF_GPU_TYPE_INTEGRATED; + else + gpu->type = FF_GPU_TYPE_DISCRETE; + + uint64_t value = 0; + if (options->temp) + { + ffStrbufSubstrBefore(pciDir, hwmonLen); + ffStrbufAppendS(pciDir, "temp1_input"); // The on die GPU temperature in millidegrees Celsius + if (ffReadFileBuffer(pciDir->chars, buffer) && (value = ffStrbufToUInt(buffer, 0))) + gpu->frequency = (double) value / 1000; + } + + ffStrbufSubstrBefore(pciDir, hwmonLen); + ffStrbufAppendS(pciDir, "freq1_input"); // The gfx/compute clock in hertz + if (ffReadFileBuffer(pciDir->chars, buffer) && (value = ffStrbufToUInt(buffer, 0))) + gpu->frequency = (double) value / (1000 * 1000 * 1000); + + if (options->driverSpecific) + { + ffStrbufSubstrBefore(pciDir, pciDirLen); + ffStrbufAppendS(pciDir, "/mem_info_vis_vram_total"); + if (ffReadFileBuffer(pciDir->chars, buffer) && (value = ffStrbufToUInt(buffer, 0))) { - if (gpu->type == FF_GPU_TYPE_DISCRETE) - gpu->dedicated.used = size; - else - gpu->shared.used = size; + ffStrbufSubstrBefore(pciDir, pciDir->length - (uint32_t) strlen("/mem_info_vis_vram_total")); + ffStrbufAppendS(pciDir, "/mem_info_vram_used"); + if (ffReadFileBuffer(pciDir->chars, buffer) && (value = ffStrbufToUInt(buffer, 0))) + { + if (gpu->type == FF_GPU_TYPE_DISCRETE) + gpu->dedicated.used = value; + else + gpu->shared.used = value; + } } } } -static void pciDetectVfreq(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer) +static void pciDetectIntelSpecific(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer) { if (!ffStrbufEndsWithS(pciDir, "/device")) // Must be in `/sys/class/drm/cardN/device` return; @@ -98,6 +107,10 @@ static void pciDetectVfreq(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer) str[len] = '\0'; gpu->frequency = (double) strtoul(str, NULL, 10) / 1000.0; } + + if (ffStrbufStartsWithS(&gpu->name, "Intel ")) + ffStrbufSubstrAfter(&gpu->name, (uint32_t) strlen("Intel ")); + gpu->type = ffStrbufStartsWithIgnCaseS(&gpu->name, "Arc ") ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED; } static bool loadPciIds(FFstrbuf* pciids) @@ -186,47 +199,50 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf ffGPUParsePciIds(&pciids, subclassId, (uint16_t) vendorId, (uint16_t) deviceId, gpu); } - // Temporarily disabled for now #816 - if (false) - { - pciDetectVmem(gpu, drmDir, buffer); - ffStrbufSubstrBefore(drmDir, drmDirPathLength); - } - - pciDetectVfreq(gpu, drmDir, buffer); - ffStrbufSubstrBefore(drmDir, drmDirPathLength); - pciDetectDriver(gpu, drmDir, buffer); ffStrbufSubstrBefore(drmDir, drmDirPathLength); - #ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API - if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || options->driverSpecific)) + if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD) { - ffDetectNvidiaGpuInfo(&(FFGpuDriverCondition) { - .type = FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID, - .pciBusId = { - .domain = pciDomain, - .bus = pciBus, - .device = pciDevice, - .func = pciFunc, - }, - }, (FFGpuDriverResult) { - .temp = options->temp ? &gpu->temperature : NULL, - .memory = options->driverSpecific ? &gpu->dedicated : NULL, - .coreCount = options->driverSpecific ? (uint32_t*) &gpu->coreCount : NULL, - .type = &gpu->type, - .frequency = &gpu->frequency, - }, "libnvidia-ml.so"); - - if (gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET) - gpu->type = gpu->dedicated.total > (uint64_t)1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED; + pciDetectAmdSpecific(options, gpu, drmDir, buffer); + ffStrbufSubstrBefore(drmDir, drmDirPathLength); } - #endif // FF_USE_PROPRIETARY_GPU_DRIVER_API + else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_INTEL) + { + pciDetectIntelSpecific(gpu, drmDir, buffer); + ffStrbufSubstrBefore(drmDir, drmDirPathLength); + } + else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA) + { + #ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API + if (options->temp || options->driverSpecific) + { + ffDetectNvidiaGpuInfo(&(FFGpuDriverCondition) { + .type = FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID, + .pciBusId = { + .domain = pciDomain, + .bus = pciBus, + .device = pciDevice, + .func = pciFunc, + }, + }, (FFGpuDriverResult) { + .temp = options->temp ? &gpu->temperature : NULL, + .memory = options->driverSpecific ? &gpu->dedicated : NULL, + .coreCount = options->driverSpecific ? (uint32_t*) &gpu->coreCount : NULL, + .type = &gpu->type, + .frequency = &gpu->frequency, + }, "libnvidia-ml.so"); + } + #endif // FF_USE_PROPRIETARY_GPU_DRIVER_API - #ifdef __linux__ - if(options->temp && gpu->temperature != gpu->temperature) - pciDetectTemp(gpu, ((uint32_t) classId << 8) + subclassId); - #endif + if (gpu->type == FF_GPU_TYPE_UNKNOWN) + { + if (ffStrbufStartsWithIgnCaseS(&gpu->name, "GeForce") || + ffStrbufStartsWithIgnCaseS(&gpu->name, "Quadro") || + ffStrbufStartsWithIgnCaseS(&gpu->name, "Tesla")) + gpu->type = FF_GPU_TYPE_DISCRETE; + } + } return NULL; } From 6e15a4416838620c92e2d79cc37a2f8f75dfd36a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 29 Apr 2024 20:28:50 +0800 Subject: [PATCH 27/30] GPU (Linux): ignore `.` when enumerating directories --- src/detection/gpu/gpu_linux.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 69ffdd9d5..5ea018bec 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -46,7 +46,12 @@ static void pciDetectAmdSpecific(const FFGPUOptions* options, FFGPUResult* gpu, ffStrbufAppendS(pciDir, "/hwmon/"); FF_AUTO_CLOSE_DIR DIR* dirp = opendir(pciDir->chars); - struct dirent* entry = readdir(dirp); + struct dirent* entry; + while ((entry = readdir(dirp)) != NULL) + { + if (entry->d_name[0] == '.') continue; + break; + } if (!entry) return; ffStrbufAppendS(pciDir, entry->d_name); ffStrbufAppendC(pciDir, '/'); From b65a0e2543acbee20ab617c67d115ec58c7b47a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 29 Apr 2024 20:43:19 +0800 Subject: [PATCH 28/30] GPU (Linux): fix copy & paste error --- src/detection/gpu/gpu_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 5ea018bec..7afe12ada 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -69,7 +69,7 @@ static void pciDetectAmdSpecific(const FFGPUOptions* options, FFGPUResult* gpu, ffStrbufSubstrBefore(pciDir, hwmonLen); ffStrbufAppendS(pciDir, "temp1_input"); // The on die GPU temperature in millidegrees Celsius if (ffReadFileBuffer(pciDir->chars, buffer) && (value = ffStrbufToUInt(buffer, 0))) - gpu->frequency = (double) value / 1000; + gpu->temperature = (double) value / 1000; } ffStrbufSubstrBefore(pciDir, hwmonLen); From 8b4586b9140367a39ecc0b230444ab69bff4282c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 29 Apr 2024 21:47:29 +0800 Subject: [PATCH 29/30] Packages: update help messages --- src/modules/packages/packages.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/packages/packages.c b/src/modules/packages/packages.c index de81f49e7..7f411d023 100644 --- a/src/modules/packages/packages.c +++ b/src/modules/packages/packages.c @@ -373,7 +373,7 @@ void ffGeneratePackagesJsonResult(FF_MAYBE_UNUSED FFPackagesOptions* options, yy void ffPrintPackagesHelpFormat(void) { - FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_PACKAGES_MODULE_NAME, "{2} (pacman){?3}[{3}]{?}, {4} (dpkg), {5} (rpm), {6} (emerge), {7} (eopkg), {8} (xbps), {9} (nix-system), {10} (nix-user), {11} (nix-default), {12} (apk), {13} (pkg), {14} (flatpak-system), {15} (flatpack-user), {16} (snap), {17} (brew), {18} (brew-cask), {19} (MacPorts), {20} (scoop), {21} (choco), {22} (pkgtool), {23} (paludis), {24} (winget), {25} (opkg)", FF_PACKAGES_NUM_FORMAT_ARGS, ((const char* []) { + FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_PACKAGES_MODULE_NAME, "{2} (pacman){?3}[{3}]{?}, {4} (dpkg), {5} (rpm), {6} (emerge), {7} (eopkg), {8} (xbps), {9} (nix-system), {10} (nix-user), {11} (nix-default), {12} (apk), {13} (pkg), {14} (flatpak-system), {15} (flatpack-user), {16} (snap), {17} (brew), {18} (brew-cask), {19} (MacPorts), {20} (scoop), {21} (choco), {22} (pkgtool), {23} (paludis), {24} (winget), {25} (opkg), {26} (am)", FF_PACKAGES_NUM_FORMAT_ARGS, ((const char* []) { "Number of all packages", "Number of pacman packages", "Pacman branch on manjaro", From c597b7ec3a016c76e1fe785d0d0531bd53591091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 29 Apr 2024 21:45:46 +0800 Subject: [PATCH 30/30] Release: v2.10.3 --- CHANGELOG.md | 6 ++++-- CMakeLists.txt | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00bb9c8f9..17f58128a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,19 +3,21 @@ Changes: * Default `hideCursor` to false. It doesn't make much difference but makes user's terminal unusable if fastfetch is not exited correctly. * Linux amd64 binaries are built with Ubuntu 20.04 again (#808) - * Note aarch64 binaries are unchanged (built with Ubuntu 22.04) Bugfixes: * Fix swap usage detection in x86-32 build (Windows, Swap) * Fix minimum cmake version support (#810) * Fix wifi detection on platforms that don't use NetworkManager (#811, Wifi, Linux) -* Fix nixos wrapped process name (#814) +* Fix NixOS wrapped process name (#814, Terminal, Linux) +* Fix GPU type detection for AMD cards (#816, GPU, Linux) Features: * Add basic support DE detection support for UKUI (DE, Linux) * Support printing total number of nix / flatpak / brew packages (Packages) + * See `fastfetch -h packages-format` for detail * Better max CPU frequency detection support with `CPUID / 16H` instruction (CPU, Windows) * This requires Core I Gen 6 or newer, and with `Virtual Machine Platform` Windows feature disabled. X86 only. +* Improve performance of nix packages detection (Packages, Linux) # 2.10.2 diff --git a/CMakeLists.txt b/CMakeLists.txt index bc9fa4ddf..3f2fff8dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url project(fastfetch - VERSION 2.10.2 + VERSION 2.10.3 LANGUAGES C DESCRIPTION "Fast neofetch-like system information tool" HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch"