From bdb5bcad01ff7332fdcf4b128211e81905113f84 Mon Sep 17 00:00:00 2001 From: polykernel <81340136+polykernel@users.noreply.github.com> Date: Fri, 28 Jul 2023 22:01:41 -0400 Subject: [PATCH] home-cursor: improve icon compatibility The current cursor configuration poorly accomodate applications not following the XDG icon theme spec. As a result, some applications fail to locate user defined icons and themes. To address this, symlinks from icon directories in the provided cursor package was to $HOME/.icons were added added for greater compatibility with applications using hardcoded icons directories. This approach was chosen to allow for coexistence of declarative and non-declarative icon files in the icons directory. In addition, symlinks of icon directories were mirrored in $XDG_DATA_HOME/.icons for backwards compatibility. As per the XDG icon theme spec, applications are to search in $HOME/.icons first for icons and themes so the existing behavior should not break for XDG compliant applications[1]. [1] https://specifications.freedesktop.org/icon-theme-spec/latest/ar01s03.html --- modules/config/home-cursor.nix | 48 ++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/modules/config/home-cursor.nix b/modules/config/home-cursor.nix index a64ccc50e..c0268db6e 100644 --- a/modules/config/home-cursor.nix +++ b/modules/config/home-cursor.nix @@ -52,6 +52,27 @@ let escapeShellArg cfg.x11.defaultCursor }"; + defaultIndexThemePackage = pkgs.writeTextFile { + name = "index.theme"; + destination = "/share/icons/default/index.theme"; + # Set name in icons theme, for compatibility with AwesomeWM etc. See: + # https://github.com/nix-community/home-manager/issues/2081 + # https://wiki.archlinux.org/title/Cursor_themes#XDG_specification + text = '' + [Icon Theme] + Name=Default + Comment=Default Cursor Theme + Inherits=${cfg.name} + ''; + }; + + iconMappings = let + knownFiles = filterAttrs (_: type: type != "unknown") + (builtins.readDir "${cfg.package}/share/icons"); + in mapAttrs' + (n: _: nameValuePair ".icons/${n}" "${cfg.package}/share/icons/${n}") + knownFiles; + in { meta.maintainers = [ maintainers.polykernel maintainers.league ]; @@ -120,17 +141,7 @@ in { (hm.assertions.assertPlatform "home.pointerCursor" pkgs platforms.linux) ]; - home.packages = [ cfg.package ]; - - # Set name in icons theme, for compatibility with AwesomeWM etc. See: - # https://github.com/nix-community/home-manager/issues/2081 - # https://wiki.archlinux.org/title/Cursor_themes#XDG_specification - xdg.dataFile."icons/default/index.theme".text = '' - [icon theme] - Name=Default - Comment=Default Cursor Theme - Inherits=${cfg.name} - ''; + home.packages = [ cfg.package defaultIndexThemePackage ]; # Set directory to look for cursors in, needed for some applications # that are unable to find cursors otherwise. See: @@ -142,6 +153,21 @@ in { XCURSOR_SIZE = mkDefault cfg.size; XCURSOR_THEME = mkDefault cfg.name; }; + + # Add symlinks of cursor icons to subdirectories in $HOME/.icons, needed for + # backwards compatibility with some applications. See: + # https://specifications.freedesktop.org/icon-theme-spec/latest/ar01s03.html + home.file = (mapAttrs (_: source: { inherit source; }) iconMappings) // { + ".icons/default/index.theme".source = + "${defaultIndexThemePackage}/share/icons/default/index.theme"; + }; + + # Add cursor icon links to $XDG_DATA_HOME as well for redundancy. + xdg.dataFile = (mapAttrs (_: source: { inherit source; }) iconMappings) + // { + ".icons/default/index.theme".source = + "${defaultIndexThemePackage}/share/icons/default/index.theme"; + }; } (mkIf cfg.x11.enable {