Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use XDG_DATA_DIRS to query themes #58

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 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,12 +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() {
char* envXdgData = std::getenv("XDG_DATA_DIRS");
Libadoxon marked this conversation as resolved.
Show resolved Hide resolved
std::vector<std::string> result;
if (envXdgData) {
std::stringstream envXdgStream(envXdgData);
std::string tmpStr;
while (getline(envXdgStream, tmpStr, ':')) {
result.push_back((tmpStr + "/icons"));
}
} else {
Libadoxon marked this conversation as resolved.
Show resolved Hide resolved
std::vector<std::string> result = {"/usr/share/icons"};
Libadoxon marked this conversation as resolved.
Show resolved Hide resolved
}
return result;
}

const std::vector<std::string> systemThemeDirs = getSystemThemeDirs();
constexpr const std::array<const char*, 2> userThemeDirs = {"/.local/share/icons", "/.icons"};

//
Libadoxon marked this conversation as resolved.
Show resolved Hide resolved
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");
Expand Down Expand Up @@ -728,7 +742,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.