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

treewide: adapt icon theme colors #157

Draft
wants to merge 27 commits into
base: master
Choose a base branch
from

Conversation

Kasper24
Copy link
Contributor

@Kasper24 Kasper24 commented Oct 1, 2023

I've been using this in my personal configuration for a bit, but not sure if you guys will be interested in this. The script is a modified and stripped down version of color-manager.

One issue that I'm having is with parent themes. They should always be accessible in propagatedbuildinputs, but I'm unsure how to dynamically adjust them. Additionally, this script could potentially be expanded to recolor wallpapers, but that would require some adjustments as well.

Examples:
Gruvbox:
image

Nord:
image

Custom cyberpunk color scheme
mode = "palette"
6

Custom cyberpunk color scheme
mode = "palette"
7

Custom cyberpunk color scheme
mode = "monochrome"
9

Same settings, but icon theme is numix circle:
12

@SomeGuyNamedMay
Copy link
Contributor

if were going to add a new package to stylix we might want to reorganise were it and the palate generator are place, ie putting them both into ./pkgs or something

};

config = cfg.enable {
home-manager.users.${config.modules.user.name} = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be here, Stylix will import the module directly into Home Manager.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was meant to be mkIf cfg.enable. Should I remove it completely?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant the home-manager.users.${config.modules.user.name} part. The way the modules are loaded means that anything in hm.nix is already inside Home Manager, so you can remove that line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, I based this off a module that lives in my own nix flake, so I must have forgotten to change it

modules/icon-theme/hm.nix Outdated Show resolved Hide resolved
modules/icon-theme/hm.nix Outdated Show resolved Hide resolved
modules/icon-theme/hm.nix Outdated Show resolved Hide resolved
modules/icon-theme/hm.nix Outdated Show resolved Hide resolved
Comment on lines 82 to 90
iconTheme = lib.mkMerge [
{
name = cfg.name;
}

(lib.mkIf (!cfg.adjustColorScheme.enable) {
package = cfg.package;
})
(lib.mkIf (cfg.adjustColorScheme.enable) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to use a normal if statement here rather than mkMerge.

Copy link
Contributor Author

@Kasper24 Kasper24 Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just me gives me an error. I'm stilla little new to nix, so not sure how to do it

iconTheme = {
	name = cfg.name;
	(lib.mkIf (!cfg.recolor.enable) {
	 	....
	})
	(lib.mkIf (cfg.recolor.enable) {
		...
	});

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like

iconTheme = {
  name = cfg.name;
  package =
    if cfg.recolor.enable
    then ...
    else ...;
};

Comment on lines 34 to 69
colors = lib.mkOption {
description = "The color to use when mode is set to color";
type = lib.types.listOf (lib.types.str);
default =
if cfg.adjustColorScheme.mode == "color" then
config.lib.stylix.colors.withHashtag.base09
else if cfg.adjustColorScheme.mode == "color-from-palette" then
with config.lib.stylix.colors.withHashtag; [
base08
base09
base0A
base0B
base0C
base0D
base0E
base0F
]
else
with config.lib.stylix.colors.withHashtag; [
base00
base01
base02
base03
base04
base05
base06
base07
base08
base09
base0A
base0B
base0C
base0D
base0E
base0F
];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be an option? It looks more like an implementation detail.

Copy link
Contributor Author

@Kasper24 Kasper24 Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it in 32da08c. Before that commit, it was only possible to customize the color when the mode was set to "color" which just sets all the icons to a single color. I thought it the other modes should be customizable as well, as someone might want to use different colors. Maybe for some color-schemes only some colors work well.

modules/icon-theme/hm.nix Outdated Show resolved Hide resolved
@Kasper24
Copy link
Contributor Author

Kasper24 commented Oct 5, 2023

I'm wondering how we should add support for recoloring the wallpaper as well? @danth

@danth
Copy link
Owner

danth commented Oct 5, 2023

After #102 is finished we should be able to add that as a function which takes in an image and a color scheme, and outputs the recoloured wallpaper.

@Kasper24
Copy link
Contributor Author

Kasper24 commented Oct 6, 2023

@danth What about recoloring the parent icon themes? For example in the "Numix Circle" theme the folder icons come from the parent "Numix" theme and those don't get recolored and look out of place. Surely there's a way?

@danth
Copy link
Owner

danth commented Oct 8, 2023

I'm not too familiar with how icon themes are packaged in NixOS. If the parent theme is a separate package then we would need to override it from there. Does the Numix Circle theme depend on Numix or do you install them separately?

@Kasper24
Copy link
Contributor Author

Kasper24 commented Oct 12, 2023

@danth https://github.com/NixOS/nixpkgs/blob/nixos-23.05/pkgs/data/icons/numix-icon-theme-circle/default.nix#L40
Every parent theme that the child theme inherits from should be part of propagatedBuildInputs. Is there some magic we can do to override those as well?

@danth
Copy link
Owner

danth commented Oct 12, 2023

If they're the only thing in propagatedBuildInputs you could map the override function over that as part of the override

@Kasper24
Copy link
Contributor Author

If they're the only thing in propagatedBuildInputs you could map the override function over that as part of the override

Could you help me with that? I'm not quite sure how

@donovanglover
Copy link
Contributor

Any example configs on how to use this branch? The icon theme colors look great.

@danth danth linked an issue Jan 3, 2024 that may be closed by this pull request
@trueNAHO trueNAHO mentioned this pull request Jan 12, 2024
4 tasks
@trueNAHO trueNAHO changed the title Add module to adjust the icon theme colors treewide: adapt icon theme colors Feb 9, 2024
@trueNAHO trueNAHO marked this pull request as draft February 9, 2024 21:36
@Kasper24
Copy link
Contributor Author

Kasper24 commented Feb 10, 2024

@donovanglover
The modes property works as follows:
-- monochrome: A monochromatic variant, colored by appropriate shades of the provided base color.
-- palette: A multichromatic variant, where all colors are replaced by their nearest perceived equivalent that adheres to the provided color palette.

stylix.targets.iconTheme = {
    enable = true;
    name = "Zafiro-icons-Dark";
    package = pkgs.zafiro-icons;
    recolor = {
      enable = true;
      mode = "palette";
      colors = with config.lib.stylix.colors.withHashtag; [
        base08
        base09
        base0A
        base0B
        base0C
        base0D
        base0E
        base0F
      ];
      smooth = false;
    };
  };
};

@Kasper24 Kasper24 force-pushed the adjust-icontheme-colors branch from d1a69f2 to d4a5ca7 Compare February 19, 2024 08:25
* Use str_float type rather than checking each arguement is not null and conveting to float
* Update the way color modifications work. Now, saturation/light can be changed for both accent and foreground colors
* Currently color modifications only work for SVGs as it's too slow for images
* It was checking for the new color, rather than the old color for detecting if it's an accent/foreground color
* There's no need to check for the distance between the color and white, checking the light value is enough
* Update the foregroundThreshold value and default for the new method
* Now using custom saturation/light values for images will also work, checking for the distance for each color in each image is too slow so couldn't be enabled before
@Kasper24
Copy link
Contributor Author

Kasper24 commented Feb 20, 2024

@danth I added lots of options to better allow for adjusting the output, which helps icons that previously had very poor contrast when they got recolored. You can look at the new pics for examples.
I'm wondering what needs to be done to get this merged?

@Kasper24 Kasper24 force-pushed the adjust-icontheme-colors branch from c88358b to 2c3993d Compare February 27, 2024 05:31
@Kasper24 Kasper24 force-pushed the adjust-icontheme-colors branch from 2c3993d to 9b1fbed Compare February 27, 2024 05:31
@danth
Copy link
Owner

danth commented Feb 27, 2024

When rebased on master, this branch causes an infinite recursion with my config:

error:
       … while calling the 'head' builtin

         at /nix/store/gzv0nsm8d5js3wzq2mr1sv9lfp1iyail-source/lib/attrsets.nix:960:11:

          959|         || pred here (elemAt values 1) (head values) then
          960|           head values
             |           ^
          961|         else

       … while evaluating the attribute 'value'

         at /nix/store/gzv0nsm8d5js3wzq2mr1sv9lfp1iyail-source/lib/modules.nix:809:9:

          808|     in warnDeprecation opt //
          809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          810|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: infinite recursion encountered

       at /nix/store/gzv0nsm8d5js3wzq2mr1sv9lfp1iyail-source/lib/modules.nix:233:21:

          232|           (regularModules ++ [ internalModule ])
          233|           ({ inherit lib options config specialArgs; } // specialArgs);
             |                     ^
          234|         in mergeModules prefix (reverseList collected);

@Kasper24
Copy link
Contributor Author

Kasper24 commented Feb 29, 2024

@danth It's probably 53d1bb4. Any better way to do it?

modules/icon-theme/hm.nix Outdated Show resolved Hide resolved
@donovanglover
Copy link
Contributor

Got around to trying this out and it's pretty cool. Lots of options to play around with but would be great if it produced better results by default.

Not all themes will have propagatedBuildInputs so it shouldn't fail for those themes. I also had a few cases where certain icons would end up as circles with a single color, like the NixOS Manual for example.

@danth
Copy link
Owner

danth commented Aug 31, 2024

Anyone interested in this may also want to check #370, where I implemented this manually for parts of the Adwaita icon theme (the default in GNOME)

@Kasper24 Kasper24 closed this Oct 20, 2024
@Kasper24 Kasper24 deleted the adjust-icontheme-colors branch October 20, 2024 01:31
@Kasper24 Kasper24 restored the adjust-icontheme-colors branch October 20, 2024 01:31
@Kasper24 Kasper24 reopened this Oct 20, 2024
* Switched colormath to basic_colormath as the upstream project is using
it now, should be faster too
* Using the previous color lightness to prevent icons from ending up as
a big circle of indistinguishable colors
* Removed unused code
@Kasper24
Copy link
Contributor Author

Kasper24 commented Nov 22, 2024

@donovanglover I made some changes, it should not produce circles of indistinguishable colors anymore (or so I hope)

@trueNAHO
Copy link
Collaborator

For reference:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Recolored Icon Packs
5 participants