Skip to content

Commit

Permalink
lib: Use XDG_DATA_DIRS to query themes (#58)
Browse files Browse the repository at this point in the history
* lib: use XDG_DATA_DIRS to search themes

* lib: fix some stylistic errors

* lib: more stylistic errors fixed
  • Loading branch information
Libadoxon authored Jul 30, 2024
1 parent 4493a97 commit 5a95d85
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
21 changes: 18 additions & 3 deletions libhyprcursor/hyprcursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "internalSharedTypes.hpp"
#include "internalDefines.hpp"
#include <array>
#include <cstdio>
#include <filesystem>
#include <zip.h>
#include <cstring>
Expand All @@ -15,11 +16,25 @@

using namespace Hyprcursor;

// directories for lookup
constexpr const std::array<const char*, 1> systemThemeDirs = {"/usr/share/icons"};
static std::vector<std::string> getSystemThemeDirs() {
const auto envXdgData = std::getenv("XDG_DATA_DIRS");
std::vector<std::string> 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<std::string> systemThemeDirs = getSystemThemeDirs();
constexpr const std::array<const char*, 2> userThemeDirs = {"/.local/share/icons", "/.icons"};

//

static std::string themeNameFromEnv(PHYPRCURSORLOGFUNC logfn) {
const auto ENV = getenv("HYPRCURSOR_THEME");
if (!ENV) {
Expand Down Expand Up @@ -728,7 +743,7 @@ std::optional<std::string> 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);
}
Expand Down
5 changes: 0 additions & 5 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions nix/dirs.patch

This file was deleted.

0 comments on commit 5a95d85

Please sign in to comment.