From 5a95d8512b3eda15a92e8cb932aa4049ec73dd55 Mon Sep 17 00:00:00 2001 From: Libadoxon <90480641+Libadoxon@users.noreply.github.com> Date: Tue, 30 Jul 2024 20:04:10 +0000 Subject: [PATCH] lib: Use XDG_DATA_DIRS to query themes (#58) * lib: use XDG_DATA_DIRS to search themes * lib: fix some stylistic errors * lib: more stylistic errors fixed --- libhyprcursor/hyprcursor.cpp | 21 ++++++++++++++++++--- nix/default.nix | 5 ----- nix/dirs.patch | 13 ------------- 3 files changed, 18 insertions(+), 21 deletions(-) delete mode 100644 nix/dirs.patch diff --git a/libhyprcursor/hyprcursor.cpp b/libhyprcursor/hyprcursor.cpp index 91d3a89..86ab9f8 100644 --- a/libhyprcursor/hyprcursor.cpp +++ b/libhyprcursor/hyprcursor.cpp @@ -2,6 +2,7 @@ #include "internalSharedTypes.hpp" #include "internalDefines.hpp" #include +#include #include #include #include @@ -15,11 +16,25 @@ using namespace Hyprcursor; -// directories for lookup -constexpr const std::array systemThemeDirs = {"/usr/share/icons"}; +static std::vector getSystemThemeDirs() { + const auto envXdgData = std::getenv("XDG_DATA_DIRS"); + std::vector result; + if (envXdgData) { + std::stringstream envXdgStream(envXdgData); + std::string tmpStr; + while (getline(envXdgStream, tmpStr, ':')) + result.push_back((tmpStr + "/icons")); + } else + result = {"/usr/share/icons"}; + + return result; +} + +const std::vector systemThemeDirs = getSystemThemeDirs(); constexpr const std::array userThemeDirs = {"/.local/share/icons", "/.icons"}; // + static std::string themeNameFromEnv(PHYPRCURSORLOGFUNC logfn) { const auto ENV = getenv("HYPRCURSOR_THEME"); if (!ENV) { @@ -728,7 +743,7 @@ std::optional CHyprcursorImplementation::loadTheme() { IMAGE->cairoSurface = cairo_image_surface_create_from_png_stream(::readPNG, IMAGE); if (const auto STATUS = cairo_surface_status(IMAGE->cairoSurface); STATUS != CAIRO_STATUS_SUCCESS) { - delete[](char*) IMAGE->data; + delete[] (char*)IMAGE->data; IMAGE->data = nullptr; return "Failed reading cairoSurface, status " + std::to_string((int)STATUS); } diff --git a/nix/default.nix b/nix/default.nix index 281af4b..94de02c 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -15,11 +15,6 @@ stdenv.mkDerivation { inherit version; src = ../.; - patches = [ - # adds /run/current-system/sw/share/icons to the icon lookup directories - ./dirs.patch - ]; - nativeBuildInputs = [ cmake pkg-config diff --git a/nix/dirs.patch b/nix/dirs.patch deleted file mode 100644 index adc690a..0000000 --- a/nix/dirs.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/libhyprcursor/hyprcursor.cpp b/libhyprcursor/hyprcursor.cpp -index 304ab9f..1f7e95d 100644 ---- a/libhyprcursor/hyprcursor.cpp -+++ b/libhyprcursor/hyprcursor.cpp -@@ -14,7 +14,7 @@ - using namespace Hyprcursor; - - // directories for lookup --constexpr const std::array systemThemeDirs = {"/usr/share/icons"}; -+constexpr const std::array systemThemeDirs = {"/usr/share/icons", "/run/current-system/sw/share/icons"}; - constexpr const std::array userThemeDirs = {"/.local/share/icons", "/.icons"}; - - //