From fb40ac08f8eafeab1cb98d24a58fdf18ce05bf3c Mon Sep 17 00:00:00 2001 From: Ben Mayer Date: Tue, 30 Jul 2024 12:30:50 +0000 Subject: [PATCH 1/3] lib: use XDG_DATA_DIRS to search themes --- libhyprcursor/hyprcursor.cpp | 24 +++++++++++++++++++----- nix/default.nix | 5 ----- nix/dirs.patch | 13 ------------- 3 files changed, 19 insertions(+), 23 deletions(-) delete mode 100644 nix/dirs.patch diff --git a/libhyprcursor/hyprcursor.cpp b/libhyprcursor/hyprcursor.cpp index 91d3a89..d724139 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,12 +16,25 @@ using namespace Hyprcursor; -// directories for lookup -constexpr const std::array systemThemeDirs = {"/usr/share/icons"}; +static std::vector getSystemThemeDirs() { + char* 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 { + std::vector 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) { +static std::string themeNameFromEnv(PHYPRCURSORLOGFUNC logfn) { const auto ENV = getenv("HYPRCURSOR_THEME"); if (!ENV) { Debug::log(HC_LOG_INFO, logfn, "themeNameFromEnv: env unset"); @@ -728,7 +742,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"}; - - // From 4e738329bcc25b5fc733de8a859fa951a56ddc5b Mon Sep 17 00:00:00 2001 From: Ben Mayer Date: Tue, 30 Jul 2024 13:20:11 +0000 Subject: [PATCH 2/3] lib: fix some stylistic errors --- libhyprcursor/hyprcursor.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/libhyprcursor/hyprcursor.cpp b/libhyprcursor/hyprcursor.cpp index d724139..2cffe4c 100644 --- a/libhyprcursor/hyprcursor.cpp +++ b/libhyprcursor/hyprcursor.cpp @@ -17,17 +17,16 @@ using namespace Hyprcursor; static std::vector getSystemThemeDirs() { - char* envXdgData = std::getenv("XDG_DATA_DIRS"); + const auto envXdgData = std::getenv("XDG_DATA_DIRS"); std::vector result; if (envXdgData) { std::stringstream envXdgStream(envXdgData); std::string tmpStr; - while (getline(envXdgStream, tmpStr, ':')) { + while (getline(envXdgStream, tmpStr, ':')) result.push_back((tmpStr + "/icons")); - } - } else { - std::vector result = {"/usr/share/icons"}; - } + } else + result = {"/usr/share/icons"}; + return result; } From 3f2de8090b8bacec04acb5e8c9d31b7e4d3d08b7 Mon Sep 17 00:00:00 2001 From: Ben Mayer Date: Tue, 30 Jul 2024 17:02:13 +0000 Subject: [PATCH 3/3] lib: more stylistic errors fixed --- libhyprcursor/hyprcursor.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libhyprcursor/hyprcursor.cpp b/libhyprcursor/hyprcursor.cpp index 2cffe4c..86ab9f8 100644 --- a/libhyprcursor/hyprcursor.cpp +++ b/libhyprcursor/hyprcursor.cpp @@ -33,7 +33,9 @@ static std::vector getSystemThemeDirs() { const std::vector systemThemeDirs = getSystemThemeDirs(); constexpr const std::array userThemeDirs = {"/.local/share/icons", "/.icons"}; -static std::string themeNameFromEnv(PHYPRCURSORLOGFUNC logfn) { +// + +static std::string themeNameFromEnv(PHYPRCURSORLOGFUNC logfn) { const auto ENV = getenv("HYPRCURSOR_THEME"); if (!ENV) { Debug::log(HC_LOG_INFO, logfn, "themeNameFromEnv: env unset");