mirror of
https://github.com/nix-community/home-manager.git
synced 2025-03-24 09:06:17 +00:00
home-cursor: use .enable pattern
This commit is contained in:
parent
32531e4572
commit
00712ac0fb
1 changed files with 99 additions and 76 deletions
|
@ -7,8 +7,19 @@ let
|
|||
|
||||
cfg = config.home.pointerCursor;
|
||||
|
||||
enable = if (lib.versionOlder config.home.stateVersion "25.05") then
|
||||
# respect .enable if it is declared
|
||||
if (any (x: x ? enable) options.home.pointerCursor.definitions) then
|
||||
cfg.enable
|
||||
else
|
||||
cfg != null
|
||||
else
|
||||
(cfg ? enable) && cfg.enable;
|
||||
|
||||
pointerCursorModule = types.submodule {
|
||||
options = {
|
||||
enable = mkEnableOption "cursor config generation";
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
example = literalExpression "pkgs.vanilla-dmz";
|
||||
|
@ -65,8 +76,7 @@ let
|
|||
};
|
||||
};
|
||||
|
||||
cursorPath =
|
||||
"${cfg.package}/share/icons/${escapeShellArg cfg.name}/cursors/${
|
||||
cursorPath = "${cfg.package}/share/icons/${escapeShellArg cfg.name}/cursors/${
|
||||
escapeShellArg cfg.x11.defaultCursor
|
||||
}";
|
||||
|
||||
|
@ -109,25 +119,17 @@ in {
|
|||
"x11"
|
||||
"defaultCursor"
|
||||
])
|
||||
|
||||
({ ... }: {
|
||||
warnings = lib.optional (lib.any (x:
|
||||
lib.getAttrFromPath
|
||||
([ "xsession" "pointerCursor" ] ++ [ x ] ++ [ "isDefined" ])
|
||||
options) [ "package" "name" "size" "defaultCursor" ]) ''
|
||||
The option `xsession.pointerCursor` has been merged into `home.pointerCursor` and will be removed
|
||||
in the future. Please change to set `home.pointerCursor` directly and enable `home.pointerCursor.x11.enable`
|
||||
to generate x11 specific cursor configurations. You can refer to the documentation for more details.
|
||||
'';
|
||||
})
|
||||
];
|
||||
|
||||
options = {
|
||||
home.pointerCursor = mkOption {
|
||||
type = types.nullOr pointerCursorModule;
|
||||
default = null;
|
||||
default = if (lib.versionOlder config.home.stateVersion "25.05") then
|
||||
null
|
||||
else
|
||||
{ };
|
||||
description = ''
|
||||
Cursor configuration. Set to `null` to disable.
|
||||
Cursor configuration.
|
||||
|
||||
Top-level options declared under this submodule are backend independent
|
||||
options. Options declared under namespaces such as `x11`
|
||||
|
@ -146,78 +148,99 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf (cfg != null) (lib.mkMerge [
|
||||
{
|
||||
assertions = [
|
||||
(lib.hm.assertions.assertPlatform "home.pointerCursor" pkgs
|
||||
lib.platforms.linux)
|
||||
];
|
||||
config = mkMerge [
|
||||
(mkIf enable (mkMerge [
|
||||
{
|
||||
assertions = [
|
||||
(hm.assertions.assertPlatform "home.pointerCursor" pkgs
|
||||
lib.platforms.linux)
|
||||
];
|
||||
|
||||
home.packages = [ cfg.package defaultIndexThemePackage ];
|
||||
home.packages = [ cfg.package defaultIndexThemePackage ];
|
||||
|
||||
home.sessionVariables = {
|
||||
XCURSOR_SIZE = mkDefault cfg.size;
|
||||
XCURSOR_THEME = mkDefault cfg.name;
|
||||
};
|
||||
home.sessionVariables = {
|
||||
XCURSOR_SIZE = mkDefault cfg.size;
|
||||
XCURSOR_THEME = mkDefault cfg.name;
|
||||
};
|
||||
|
||||
# Set directory to look for cursors in, needed for some applications
|
||||
# that are unable to find cursors otherwise. See:
|
||||
# https://github.com/nix-community/home-manager/issues/2812
|
||||
# https://wiki.archlinux.org/title/Cursor_themes#Environment_variable
|
||||
home.sessionSearchVariables.XCURSOR_PATH =
|
||||
[ "${config.home.profileDirectory}/share/icons" ];
|
||||
# Set directory to look for cursors in, needed for some applications
|
||||
# that are unable to find cursors otherwise. See:
|
||||
# https://github.com/nix-community/home-manager/issues/2812
|
||||
# https://wiki.archlinux.org/title/Cursor_themes#Environment_variable
|
||||
home.sessionSearchVariables.XCURSOR_PATH =
|
||||
[ "${config.home.profileDirectory}/share/icons" ];
|
||||
|
||||
# Add symlink of cursor icon directory to $HOME/.icons, needed for
|
||||
# backwards compatibility with some applications. See:
|
||||
# https://specifications.freedesktop.org/icon-theme-spec/latest/ar01s03.html
|
||||
home.file.".icons/default/index.theme".source =
|
||||
"${defaultIndexThemePackage}/share/icons/default/index.theme";
|
||||
home.file.".icons/${cfg.name}".source =
|
||||
"${cfg.package}/share/icons/${cfg.name}";
|
||||
# Add cursor icon link to $XDG_DATA_HOME/icons as well for redundancy.
|
||||
xdg.dataFile."icons/default/index.theme".source =
|
||||
"${defaultIndexThemePackage}/share/icons/default/index.theme";
|
||||
xdg.dataFile."icons/${cfg.name}".source =
|
||||
"${cfg.package}/share/icons/${cfg.name}";
|
||||
|
||||
# Add cursor icon link to $XDG_DATA_HOME/icons as well for redundancy.
|
||||
xdg.dataFile."icons/default/index.theme".source =
|
||||
"${defaultIndexThemePackage}/share/icons/default/index.theme";
|
||||
xdg.dataFile."icons/${cfg.name}".source =
|
||||
"${cfg.package}/share/icons/${cfg.name}";
|
||||
}
|
||||
# Add symlink of cursor icon directory to $HOME/.icons, needed for
|
||||
# backwards compatibility with some applications. See:
|
||||
# https://specifications.freedesktop.org/icon-theme-spec/latest/ar01s03.html
|
||||
home.file.".icons/default/index.theme".source =
|
||||
"${defaultIndexThemePackage}/share/icons/default/index.theme";
|
||||
home.file.".icons/${cfg.name}".source =
|
||||
"${cfg.package}/share/icons/${cfg.name}";
|
||||
}
|
||||
|
||||
(lib.mkIf cfg.x11.enable {
|
||||
xsession.profileExtra = ''
|
||||
${pkgs.xorg.xsetroot}/bin/xsetroot -xcf ${cursorPath} ${
|
||||
toString cfg.size
|
||||
}
|
||||
'';
|
||||
(mkIf cfg.x11.enable {
|
||||
xsession.profileExtra = ''
|
||||
${pkgs.xorg.xsetroot}/bin/xsetroot -xcf ${cursorPath} ${
|
||||
toString cfg.size
|
||||
}
|
||||
'';
|
||||
|
||||
xresources.properties = {
|
||||
"Xcursor.theme" = cfg.name;
|
||||
"Xcursor.size" = cfg.size;
|
||||
};
|
||||
})
|
||||
xresources.properties = {
|
||||
"Xcursor.theme" = cfg.name;
|
||||
"Xcursor.size" = cfg.size;
|
||||
};
|
||||
})
|
||||
|
||||
(lib.mkIf cfg.gtk.enable {
|
||||
gtk.cursorTheme = mkDefault { inherit (cfg) package name size; };
|
||||
})
|
||||
(mkIf cfg.gtk.enable {
|
||||
gtk.cursorTheme = mkDefault { inherit (cfg) package name size; };
|
||||
})
|
||||
|
||||
(lib.mkIf cfg.hyprcursor.enable {
|
||||
home.sessionVariables = {
|
||||
HYPRCURSOR_THEME = cfg.name;
|
||||
HYPRCURSOR_SIZE =
|
||||
if cfg.hyprcursor.size != null then cfg.hyprcursor.size else cfg.size;
|
||||
};
|
||||
})
|
||||
(mkIf cfg.hyprcursor.enable {
|
||||
home.sessionVariables = {
|
||||
HYPRCURSOR_THEME = cfg.name;
|
||||
HYPRCURSOR_SIZE = if cfg.hyprcursor.size != null then
|
||||
cfg.hyprcursor.size
|
||||
else
|
||||
cfg.size;
|
||||
};
|
||||
})
|
||||
|
||||
(lib.mkIf cfg.sway.enable {
|
||||
wayland.windowManager.sway = {
|
||||
config = {
|
||||
seat = {
|
||||
"*" = {
|
||||
xcursor_theme =
|
||||
"${cfg.name} ${toString config.gtk.cursorTheme.size}";
|
||||
(mkIf cfg.sway.enable {
|
||||
wayland.windowManager.sway = {
|
||||
config = {
|
||||
seat = {
|
||||
"*" = {
|
||||
xcursor_theme =
|
||||
"${cfg.name} ${toString config.gtk.cursorTheme.size}";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
})
|
||||
]);
|
||||
})
|
||||
]))
|
||||
|
||||
{
|
||||
warnings = (optional (any (x:
|
||||
getAttrFromPath
|
||||
([ "xsession" "pointerCursor" ] ++ [ x ] ++ [ "isDefined" ])
|
||||
options) [ "package" "name" "size" "defaultCursor" ]) ''
|
||||
The option `xsession.pointerCursor` has been merged into `home.pointerCursor` and will be removed
|
||||
in the future. Please change to set `home.pointerCursor` directly and enable `home.pointerCursor.x10.enable`
|
||||
to generate x10 specific cursor configurations. You can refer to the documentation for more details.
|
||||
'') ++ (optional ((lib.versionAtLeast config.home.stateVersion "25.05")
|
||||
&& (cfg == null)) ''
|
||||
Setting home.pointerCursor to null is deprecated.
|
||||
Please update your configuration so that
|
||||
|
||||
home.pointerCursor.enable = false;
|
||||
'');
|
||||
}
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue