treewide: add support for fallback fonts

This modifies the modules to add support for fallback fonts. Some of
them just use the default fonts (the first font in the list), some also
respect the fallback.
This commit is contained in:
Jalil David Salamé Messina 2024-01-17 22:31:45 +01:00
parent c9c6134bbe
commit 9503b1e5d3
No known key found for this signature in database
GPG key ID: F016B9E770737A0B
26 changed files with 141 additions and 72 deletions

View file

@ -5,6 +5,18 @@
let let
colors = config.lib.stylix.colors.withHashtag; colors = config.lib.stylix.colors.withHashtag;
useYaml = (builtins.compareVersions config.programs.alacritty.package.version "0.13.0") < 0;
templateRepo = config.lib.stylix.templates.
"base16-alacritty${if useYaml then "-yaml" else ""}";
inherit (config.stylix) fonts;
inherit (fonts) sizes;
monospace = builtins.head fonts.monospace;
themeFile = config.lib.stylix.colors {
inherit templateRepo;
};
in in
{ {
options.stylix.targets.alacritty.enable = config.lib.stylix.mkEnableTarget "Alacritty" true; options.stylix.targets.alacritty.enable = config.lib.stylix.mkEnableTarget "Alacritty" true;

View file

@ -1,7 +1,6 @@
{ config, lib, options, ... }: { config, lib, options, ... }:
with config.lib.stylix.colors; with config.lib.stylix.colors;
with config.stylix.fonts;
let let
aviOpacity = toString config.stylix.opacity.popups; aviOpacity = toString config.stylix.opacity.popups;
in in

View file

@ -1,8 +1,10 @@
{pkgs, config, lib, ... }: { pkgs, config, lib, ... }:
with config.lib.stylix.colors.withHashtag; with config.lib.stylix.colors.withHashtag;
with config.stylix.fonts;
let let
inherit (config.stylix) fonts;
inherit (fonts) sizes;
sansSerif = builtins.head fonts.sansSerif;
bemenuOpacity = lib.toHexString ((((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100)); bemenuOpacity = lib.toHexString ((((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100));
in { in {
options.stylix.targets.bemenu = { options.stylix.targets.bemenu = {
@ -26,26 +28,23 @@ in {
}; };
config = lib.mkIf config.stylix.targets.bemenu.enable { config = lib.mkIf config.stylix.targets.bemenu.enable {
programs.bemenu.settings = with config.stylix.targets.bemenu; { home.sessionVariables.BEMENU_OPTS = with config.stylix.targets.bemenu; builtins.concatStringsSep " " [
tb = "${base01}${bemenuOpacity}"; # Title bg # Inspired from https://git.sr.ht/~h4n1/base16-bemenu_opts
nb = "${base01}${bemenuOpacity}"; # Normal bg "--tb '${base01}${bemenuOpacity}'"
fb = "${base01}${bemenuOpacity}"; # Filter bg "--nb '${base01}${bemenuOpacity}'"
hb = "${base03}${bemenuOpacity}"; # Highlighted bg "--fb '${base01}${bemenuOpacity}'"
sb = "${base03}${bemenuOpacity}"; # Selected bg "--hb '${base03}${bemenuOpacity}'"
scb = "${base01}"; # Scrollbar bg "--sb '${base03}${bemenuOpacity}'"
"--hf '${base0A}'"
hf = "${base0A}"; # Highlighted fg "--sf '${base0B}'"
sf = "${base0B}"; # Selected fg "--tf '${base05}'"
tf = "${base05}"; # Title fg "--ff '${base05}'"
ff = "${base05}"; # Filter fg "--nf '${base05}'"
nf = "${base05}"; # Normal fg "--scb '${base01}'"
scf = "${base03}"; # Scrollbar fg "--scf '${base03}'"
"--ab '${if alternate then base00 else base01}'"
ab = "${if alternate then base00 else base01}"; # Alternate bg "--af '${if alternate then base04 else base05}'"
af = "${if alternate then base04 else base05}"; # Alternate fg "--fn '${sansSerif.name} ${lib.optionalString (fontSize != null) (builtins.toString fontSize)}'"
];
# Font name
fn = "${sansSerif.name} ${lib.optionalString (fontSize != null) (builtins.toString fontSize)}";
};
}; };
} }

View file

@ -1,9 +1,11 @@
{ config, lib, ... }: { config, lib, ... }:
with config.lib.stylix.colors.withHashtag; with config.lib.stylix.colors.withHashtag;
with config.stylix.fonts;
let let
dunstOpacity = lib.toHexString ((((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100)); dunstOpacity = lib.toHexString ((((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100));
inherit (config.stylix) fonts;
inherit (fonts) sizes;
sansSerif = builtins.head sansSerif;
in { in {
options.stylix.targets.dunst.enable = options.stylix.targets.dunst.enable =
config.lib.stylix.mkEnableTarget "Dunst" true; config.lib.stylix.mkEnableTarget "Dunst" true;

View file

@ -1,9 +1,10 @@
{ pkgs, config, lib, ... }: { pkgs, config, lib, ... }:
with config.lib.stylix.colors.withHashtag; with config.lib.stylix.colors.withHashtag;
with config.stylix.fonts;
let let
inherit (config.stylix) fonts;
monospace = builtins.head fonts.monospace;
emacsOpacity = builtins.toString (builtins.ceil (config.stylix.opacity.applications * 100)); emacsOpacity = builtins.toString (builtins.ceil (config.stylix.opacity.applications * 100));
in in
{ {

View file

@ -2,10 +2,12 @@
let let
profileSettings = { profileSettings = {
settings = { settings = let
"font.name.monospace.x-western" = config.stylix.fonts.monospace.name; inherit (config.stylix) fonts;
"font.name.sans-serif.x-western" = config.stylix.fonts.sansSerif.name; in {
"font.name.serif.x-western" = config.stylix.fonts.serif.name; "font.name.monospace.x-western" = (builtins.head fonts.monospace).name;
"font.name.sans-serif.x-western" = (builtins.head fonts.sansSerif).name;
"font.name.serif.x-western" = (builtins.head fonts.serif).name;
}; };
}; };
makeProfileSettingsPair = profileName: makeProfileSettingsPair = profileName:

View file

@ -14,8 +14,11 @@ in {
config.programs.foot.settings = lib.mkIf cfg.enable { config.programs.foot.settings = lib.mkIf cfg.enable {
main = { main = {
include = theme; include = theme;
font = font = let
with config.stylix.fonts; inherit (config.stylix) fonts;
inherit (fonts) sizes;
monospace = builtins.head fonts.monospace;
in
"${monospace.name}:size=${toString sizes.terminal}"; "${monospace.name}:size=${toString sizes.terminal}";
dpi-aware = "no"; dpi-aware = "no";
}; };

View file

@ -21,8 +21,11 @@ in {
border = "${base0D-hex}ff"; border = "${base0D-hex}ff";
}; };
main = { main = let
font = "${config.stylix.fonts.sansSerif.name}:size=${toString config.stylix.fonts.sizes.popups}"; inherit (config.stylix) fonts;
sansSerif = builtins.head fonts.sansSerif;
in {
font = "${sansSerif.name}:size=${toString fonts.sizes.popups}";
dpi-aware = "no"; dpi-aware = "no";
}; };
}; };

View file

@ -14,8 +14,13 @@ with lib;
picture-uri = "file://${config.stylix.image}"; picture-uri = "file://${config.stylix.image}";
picture-uri-dark = "file://${config.stylix.image}"; picture-uri-dark = "file://${config.stylix.image}";
}; };
"org/gnome/desktop/interface" = let
"org/gnome/desktop/interface" = with config.stylix.fonts ; { inherit (config.stylix) fonts;
inherit (fonts) sizes;
serif = builtins.head fonts.serif;
sansSerif = builtins.head fonts.sansSerif;
monospace = builtins.head fonts.monospace;
in {
# We show the same colours regardless of this setting, and the quick # We show the same colours regardless of this setting, and the quick
# settings tile is removed. The value is still used by Epiphany to # settings tile is removed. The value is still used by Epiphany to
# request dark mode for websites which support it. # request dark mode for websites which support it.

View file

@ -1,10 +1,14 @@
{ pkgs, config, lib, ... }: { pkgs, config, lib, ... }:
with config.lib.stylix; with config.lib.stylix;
with config.stylix.fonts;
with config.lib.stylix.colors.withHashtag; with config.lib.stylix.colors.withHashtag;
let let
inherit (config.stylix) fonts;
inherit (fonts) sizes;
monospace = builtins.head fonts.monospace;
sansSerif = builtins.head fonts.sansSerif;
# Grub requires fonts to be converted to "PFF2 format" # Grub requires fonts to be converted to "PFF2 format"
# This function takes a font { name, package } and produces a .pf2 file # This function takes a font { name, package } and produces a .pf2 file
mkGrubFont = font: mkGrubFont = font:

View file

@ -37,10 +37,13 @@ in {
# programs.dconf.enable = true; required in system config # programs.dconf.enable = true; required in system config
gtk = { gtk = {
enable = true; enable = true;
font = { font = let
inherit (config.stylix.fonts.sansSerif) package name; inherit (config.stylix) fonts;
size = config.stylix.fonts.sizes.applications; sansSerif = builtins.head fonts.sansSerif;
}; in {
inherit (sansSerif) package name;
size = fonts.sizes.applications;
};
theme = { theme = {
package = pkgs.adw-gtk3; package = pkgs.adw-gtk3;
name = "adw-gtk3"; name = "adw-gtk3";

View file

@ -9,9 +9,9 @@ let
unfocused = base03; unfocused = base03;
fonts = let fonts = let
fonts = config.stylix.fonts; inherit (config.stylix) fonts;
in { in {
names = [ fonts.sansSerif.name ]; names = lib.catAttrs "name" fonts.sansSerif;
size = fonts.sizes.desktop * 1.0; size = fonts.sizes.desktop * 1.0;
}; };

View file

@ -1,9 +1,12 @@
{ pkgs, config, lib, ... }: { pkgs, config, lib, ... }:
with config.stylix.fonts;
with config.lib.stylix.colors; with config.lib.stylix.colors;
let let
inherit (config.stylix) fonts;
inherit (fonts) sizes;
sansSerif = builtins.head fonts.sansSerif;
monospace = builtins.head fonts.monospace;
formatValue = value: formatValue = value:
if builtins.isBool value if builtins.isBool value
then if value then "true" else "false" then if value then "true" else "false"

View file

@ -22,9 +22,12 @@ in {
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
programs.kitty = { programs.kitty = {
font = { font = let
inherit (config.stylix.fonts.monospace) package name; inherit (config.stylix) fonts;
size = config.stylix.fonts.sizes.terminal; monospace = builtins.head fonts.monospace;
in {
inherit (monospace) package name;
size = fonts.sizes.terminal;
}; };
settings.background_opacity = with config.stylix.opacity; "${builtins.toString terminal}"; settings.background_opacity = with config.stylix.opacity; "${builtins.toString terminal}";
extraConfig = '' extraConfig = ''

View file

@ -4,7 +4,7 @@
config.lib.stylix.mkEnableTarget "the kmscon virtual console" true; config.lib.stylix.mkEnableTarget "the kmscon virtual console" true;
config.services.kmscon = lib.mkIf config.stylix.targets.kmscon.enable { config.services.kmscon = lib.mkIf config.stylix.targets.kmscon.enable {
fonts = [config.stylix.fonts.monospace]; fonts = config.stylix.fonts.monospace;
extraConfig = extraConfig =
let let
formatBase = name: formatBase = name:

View file

@ -1,8 +1,10 @@
{pkgs, config, lib, options, ... }: {pkgs, config, lib, options, ... }:
with config.lib.stylix.colors.withHashtag; with config.lib.stylix.colors.withHashtag;
with config.stylix.fonts;
let let
inherit (config.stylix) fonts;
inherit(fonts) sizes;
sansSerif = builtins.head fonts.sansSerif;
makoOpacity = lib.toHexString ((((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100)); makoOpacity = lib.toHexString ((((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100));
in { in {
options.stylix.targets.mako.enable = options.stylix.targets.mako.enable =

View file

@ -12,11 +12,15 @@ let
inverted-foreground = base00; inverted-foreground = base00;
error = base08; error = base08;
info = base0B; info = base0B;
secondary-info = base0C; secondary-info = base0C;
warning = base0E; warning = base0E;
inherit (config.stylix) fonts;
inherit (fonts) sizes;
serif = builtins.head fonts.serif;
sansSerif = builtins.head fonts.sansSerif;
monospace = builtins.head fonts.monospace;
in { in {
options.stylix.targets.qutebrowser.enable = options.stylix.targets.qutebrowser.enable =
config.lib.stylix.mkEnableTarget "Qutebrowser" true; config.lib.stylix.mkEnableTarget "Qutebrowser" true;

View file

@ -1,7 +1,5 @@
{ config, lib, ... }: { config, lib, ... }:
with config.stylix.fonts;
let let
inherit (config.lib.formats.rasi) mkLiteral; inherit (config.lib.formats.rasi) mkLiteral;
mkRgba = opacity: color: mkRgba = opacity: color:
@ -14,6 +12,10 @@ let
mkLiteral mkLiteral
"rgba ( ${r}, ${g}, ${b}, ${opacity} % )"; "rgba ( ${r}, ${g}, ${b}, ${opacity} % )";
mkRgb = mkRgba "100"; mkRgb = mkRgba "100";
inherit (config.stylix) fonts;
inherit (fonts) sizes;
monospace = builtins.head fonts.monospace;
rofiOpacity = builtins.toString (builtins.ceil (config.stylix.opacity.popups * 100)); rofiOpacity = builtins.toString (builtins.ceil (config.stylix.opacity.popups * 100));
in in
{ {

View file

@ -8,9 +8,12 @@ let
focused = base0A; focused = base0A;
unfocused = base03; unfocused = base03;
fonts = { fonts = let
names = [ config.stylix.fonts.sansSerif.name ]; inherit (config.stylix) fonts;
size = config.stylix.fonts.sizes.desktop + 0.0; inherit (fonts) sizes;
in {
names = lib.catAttrs "name" fonts.sansSerif;
size = sizes.desktop + 0.0;
}; };
in { in {

View file

@ -1,8 +1,9 @@
{ config, lib, ... }: { config, lib, ... }:
let let
colors = config.lib.stylix.colors; inherit (config.lib.stylix) colors;
fonts = config.stylix.fonts; inherit (config.stylix) fonts;
sansSerif = builtins.head fonts.sansSerif;
in { in {
options.stylix.targets.sxiv.enable = options.stylix.targets.sxiv.enable =
config.lib.stylix.mkEnableTarget "Sxiv" true; config.lib.stylix.mkEnableTarget "Sxiv" true;
@ -12,7 +13,7 @@ in {
properties = { properties = {
"Sxiv.foreground" = "#${colors.base01}"; "Sxiv.foreground" = "#${colors.base01}";
"Sxiv.background" = "#${colors.base04}"; "Sxiv.background" = "#${colors.base04}";
"Sxiv.font" = "${fonts.sansSerif.name}-${toString fonts.sizes.applications}"; "Sxiv.font" = "${sansSerif.name}-${toString fonts.sizes.applications}";
}; };
}; };
}; };

View file

@ -20,14 +20,16 @@ let
}; };
vimOptions = let vimOptions = let
fonts = config.stylix.fonts; inherit (config.stylix) fonts;
inherit (fonts) sizes;
monospace = builtins.head fonts.monospace;
in { in {
plugins = [ themePlugin ]; plugins = [ themePlugin ];
extraConfig = '' extraConfig = ''
set termguicolors set termguicolors
colorscheme base16-stylix colorscheme base16-stylix
unlet g:colors_name unlet g:colors_name
set guifont=${escape [" "] fonts.monospace.name}:h${toString fonts.sizes.terminal} set guifont=${escape [" "] monospace.name}:h${toString sizes.terminal}
''; '';
}; };

View file

@ -1,8 +1,9 @@
{pkgs, config, lib, ... }: {pkgs, config, lib, ... }:
with config.stylix.fonts;
let let
inherit (config.stylix) fonts;
monospace = builtins.head fonts.monospace;
themeFile = config.lib.stylix.colors { themeFile = config.lib.stylix.colors {
template = ./template.mustache; template = ./template.mustache;
extension = ".json"; extension = ".json";

View file

@ -1,7 +1,11 @@
{ config, lib, ... }: { config, lib, ... }:
with config.lib.stylix.colors.withHashtag; with config.lib.stylix.colors.withHashtag;
with config.stylix.fonts;
let let
inherit (config.stylix) fonts;
inherit (fonts) sizes;
sansSerif = builtins.head fonts.sansSerif;
colorlessModules = place: '' colorlessModules = place: ''
.modules-${place} #workspaces button { .modules-${place} #workspaces button {
border-bottom: 3px solid transparent; border-bottom: 3px solid transparent;

View file

@ -1,6 +1,12 @@
{ config, lib, ... }: { config, lib, ... }:
let colors = config.lib.stylix.colors.withHashtag; let
colors = config.lib.stylix.colors.withHashtag;
inherit (config.stylix) fonts;
inherit (fonts) sizes;
fontList = lib.strings.concatMapStringsSep ", " ({name,...}: "\"${name}\"") (fonts.monospace ++ fonts.emoji);
in { in {
options.stylix.targets.wezterm.enable = options.stylix.targets.wezterm.enable =
config.lib.stylix.mkEnableTarget "wezterm" config.programs.wezterm.enable; config.lib.stylix.mkEnableTarget "wezterm" config.programs.wezterm.enable;
@ -47,7 +53,6 @@ in {
}; };
xdg.configFile."wezterm/wezterm.lua".text = with colors; xdg.configFile."wezterm/wezterm.lua".text = with colors;
with config.stylix.fonts;
lib.mkForce '' lib.mkForce ''
-- Generated by Stylix -- Generated by Stylix
local wezterm = require("wezterm") local wezterm = require("wezterm")
@ -62,10 +67,7 @@ in {
-- See https://github.com/wez/wezterm/issues/2615 -- See https://github.com/wez/wezterm/issues/2615
use_fancy_tab_bar = false, use_fancy_tab_bar = false,
color_scheme = "stylix", color_scheme = "stylix",
font = wezterm.font_with_fallback { font = wezterm.font_with_fallback { ${fontList} },
"${monospace.name}",
"${emoji.name}",
},
font_size = ${builtins.toString sizes.terminal}, font_size = ${builtins.toString sizes.terminal},
window_background_opacity = ${ window_background_opacity = ${
builtins.toString config.stylix.opacity.terminal builtins.toString config.stylix.opacity.terminal

View file

@ -6,7 +6,12 @@
config.lib.stylix.mkEnableTarget "Xfce" false; config.lib.stylix.mkEnableTarget "Xfce" false;
config = lib.mkIf config.stylix.targets.xfce.enable { config = lib.mkIf config.stylix.targets.xfce.enable {
xfconf.settings = with config.stylix.fonts; { xfconf.settings = let
inherit (config.stylix) fonts;
inherit (fonts) sizes;
sansSerif = builtins.head fonts.sansSerif;
monospace = builtins.head fonts.monospace;
in {
xfwm4 = { xfwm4 = {
"general/title_font" = "${sansSerif.name} ${toString sizes.desktop}"; "general/title_font" = "${sansSerif.name} ${toString sizes.desktop}";
}; };

View file

@ -1,11 +1,15 @@
{ config, lib, ... }: { config, lib, ... }:
{ let
inherit (config.stylix) fonts;
inherit (fonts) sizes;
monospace = builtins.head fonts.monospace;
in {
options.stylix.targets.xresources.enable = options.stylix.targets.xresources.enable =
config.lib.stylix.mkEnableTarget "Xresources" true; config.lib.stylix.mkEnableTarget "Xresources" true;
config = lib.mkIf config.stylix.targets.xresources.enable { config = lib.mkIf config.stylix.targets.xresources.enable {
xresources.properties = with config.lib.stylix.colors.withHashtag; with config.stylix.fonts; { xresources.properties = with config.lib.stylix.colors.withHashtag; {
"*.faceName" = monospace.name; "*.faceName" = monospace.name;
"*.faceSize" = sizes.terminal; "*.faceSize" = sizes.terminal;
"*.renderFont" = true; "*.renderFont" = true;