danth / stylix

System-wide colorscheming and typography for NixOS
https://stylix.danth.me/
MIT License
1.23k stars 157 forks source link

zathura: missing transparency #392

Closed jghauser closed 5 months ago

jghauser commented 6 months ago

Zathura recently-ish deprecated their highlight-transparency option, which by default was set to something like 0.3 so that text would still be visible when highlighting it (for instance in search results). Now, the colours completely conceal the text. The solution is to define transparency via an alpha channel value (as man 5 zathurarc describes):

       For colors, zathura supports HTML color codes and  CSS3-style  rgb(r,g,b)  and
       rgba(r,g,b,a)  values.  If  you want to use color codes for some options, make
       sure to quote them accordingly or to escape the hash symbol.

          set default-fg "#CCBBCC"
          set default-fg \#CCBBCC

       For rgba, note that it parses the color components as integers between  0  and
       255 and the alpha component as float between 0 and 1.

Stylix should change the module to automatically add transparency to the relevant entries.

I would be willing to write a PR though I'm not very fluent in nix and unsure how to create the rgb(r,g,b,a) values. Maybe someone could give me a pointer?

trueNAHO commented 6 months ago

Zathura recently-ish deprecated their highlight-transparency option, which by default was set to something like 0.3 so that text would still be visible when highlighting it (for instance in search results). Now, the colours completely conceal the text.

Thanks for pointing that out. Actually, I have been wondering for a while why it is no longer transparent.

The solution is to define transparency via an alpha channel value (as man 5 zathurarc describes):

       For colors, zathura supports HTML color codes and  CSS3-style  rgb(r,g,b)  and
       rgba(r,g,b,a)  values.  If  you want to use color codes for some options, make
       sure to quote them accordingly or to escape the hash symbol.

          set default-fg "#CCBBCC"
          set default-fg \#CCBBCC

       For rgba, note that it parses the color components as integers between  0  and
       255 and the alpha component as float between 0 and 1.

Stylix should change the module to automatically add transparency to the relevant entries.

Agreed.

I would be willing to write a PR though I'm not very fluent in nix

Thanks for helping out! Supporting Stylix applications usually only involves declaring options and only rarely requires advanced logic.

unsure how to create the rgb(r,g,b,a) values. Maybe someone could give me a pointer?

Considering the wide range of application support, there is a high chance that what you need has already been done somewhere, which you can use as reference.

For example, check out how rgb( is used in the following files:

palette-generator/Stylix/Palette.hs:import Data.Colour ( LAB(lightness), RGB(RGB), deltaE, rgb2lab )
palette-generator/Stylix/Output.hs:import Data.Colour ( RGB(RGB) )
palette-generator/Data/Colour.hs:module Data.Colour ( LAB(..), RGB(..), deltaE, lab2rgb, rgb2lab ) where
modules/hyprland/hm.nix:  rgb = color: "rgb(${color})";
modules/gitui/hm.nix:    "Rgb(${r}, ${g}, ${b})";

And check out how rgba( is used in the following files:

modules/gtk/gtk.mustache:@define-color headerbar_border_color rgba({{base01-dec-r}}, {{base01-dec-g}}, {{base01-dec-b}}, 0.7);
modules/gtk/gtk.mustache:@define-color headerbar_shade_color rgba(0, 0, 0, 0.07);
modules/gtk/gtk.mustache:@define-color headerbar_darker_shade_color rgba(0, 0, 0, 0.07);
modules/gtk/gtk.mustache:@define-color sidebar_shade_color rgba(0, 0, 0, 0.07);
modules/gtk/gtk.mustache:@define-color card_shade_color rgba(0, 0, 0, 0.07);
modules/gtk/gtk.mustache:@define-color popover_shade_color rgba(0, 0, 0, 0.07);
modules/gtk/gtk.mustache:@define-color shade_color rgba(0, 0, 0, 0.07);
modules/avizo/hm.nix:              background = "rgba(${base01-rgb-r}, ${base01-rgb-g}, ${base01-rgb-b}, ${aviOpacity})";
modules/avizo/hm.nix:              border-color = "rgba(${base0D-rgb-r}, ${base0D-rgb-g}, ${base0D-rgb-b}, ${aviOpacity})";
modules/avizo/hm.nix:              bar-fg-color = "rgba(${base05-rgb-r}, ${base05-rgb-g}, ${base05-rgb-b}, ${aviOpacity})";
modules/avizo/hm.nix:              bar-bg-color = "rgba(${base01-rgb-r}, ${base01-rgb-g}, ${base01-rgb-b}, ${aviOpacity})";
modules/hyprland/hm.nix:  rgba = color: alpha: "rgba(${color}${alpha})";

For reference, you would need to add your patch to the zathura module: https://github.com/danth/stylix/blob/290c8aef476ce98fff9cefc059284429d561a085/modules/zathura/hm.nix

jghauser commented 6 months ago

Thanks for the thorough response and the pointers towards existing similar implementations! I'll try to get back to you with a PR soon! :)

danth commented 6 months ago

Note that the Haskell (.hs) files mentioned are unlikely to be relevant.