From f06229cc33d47262799748b9a8244d8ba975dbfe Mon Sep 17 00:00:00 2001 From: Anthony Rodriguez Date: Thu, 21 Nov 2024 17:44:42 +0100 Subject: [PATCH] treewide: conditionally add theming --- home/programs/niri/default.nix | 144 ++++++++++++++------------- home/programs/swaylock.nix | 86 +++++++++-------- home/programs/waybar/style.nix | 161 +++++++++++++++---------------- home/terminal/emulators/foot.nix | 8 +- hosts/solaire/modules/theme.nix | 1 + 5 files changed, 207 insertions(+), 193 deletions(-) diff --git a/home/programs/niri/default.nix b/home/programs/niri/default.nix index 6061c02..5f9c89a 100644 --- a/home/programs/niri/default.nix +++ b/home/programs/niri/default.nix @@ -5,7 +5,7 @@ osConfig, ... }: let - inherit (osConfig.theme.scheme) palette; + inherit (lib) mkMerge mkIf; in { imports = [./binds.nix]; @@ -22,79 +22,85 @@ in { }; }; - programs.niri = { - settings = { - input = { - power-key-handling.enable = false; - keyboard.xkb = { - layout = "us"; - options = "compose:ralt"; - }; - }; - - prefer-no-csd = true; - hotkey-overlay.skip-at-startup = true; - - layout = { - focus-ring = { - enable = true; - active.color = palette.base0E; - }; - always-center-single-column = true; - }; - - # https://github.com/sodiboo/system/blob/2978f4d79c51a5bd7e38a9cd75e3ec9046aa7e75/niri.mod.nix#L418-L434 - outputs = let - cfg = config.programs.niri.settings.outputs; - in { - "HDMI-A-1" = { - mode = { - width = 1920; - height = 1080; - refresh = 60.0; + programs.niri = mkMerge [ + { + settings = { + input = { + power-key-handling.enable = false; + keyboard.xkb = { + layout = "us"; + options = "compose:ralt"; }; - position.x = -cfg."HDMI-A-1".mode.width; - position.y = 0; }; - "DP-1" = { - mode = { - width = 2560; - height = 1440; - refresh = 144.0; + + prefer-no-csd = true; + hotkey-overlay.skip-at-startup = true; + + layout = { + focus-ring = { + enable = true; }; - position.x = 0; - position.y = 0; + always-center-single-column = true; + }; + + # https://github.com/sodiboo/system/blob/2978f4d79c51a5bd7e38a9cd75e3ec9046aa7e75/niri.mod.nix#L418-L434 + outputs = let + cfg = config.programs.niri.settings.outputs; + in { + "HDMI-A-1" = { + mode = { + width = 1920; + height = 1080; + refresh = 60.0; + }; + position.x = -cfg."HDMI-A-1".mode.width; + position.y = 0; + }; + "DP-1" = { + mode = { + width = 2560; + height = 1440; + refresh = 144.0; + }; + position.x = 0; + position.y = 0; + }; + }; + + window-rules = [ + { + draw-border-with-background = false; + geometry-corner-radius = let + r = 8.0; + in { + top-left = r; + top-right = r; + bottom-left = r; + bottom-right = r; + }; + clip-to-geometry = true; + } + { + matches = [ + {app-id = "foot";} + ]; + default-column-width = {proportion = 0.5;}; + } + ]; + + environment = { + "NIXOS_OZONE_WL" = "1"; + "DISPLAY" = ":0"; + "_JAVA_AWT_WM_NONREPARENTING" = "1"; # https://wiki.archlinux.org/title/Sway#Java_applications }; }; - - window-rules = [ - { - draw-border-with-background = false; - geometry-corner-radius = let - r = 8.0; - in { - top-left = r; - top-right = r; - bottom-left = r; - bottom-right = r; - }; - clip-to-geometry = true; - } - { - matches = [ - {app-id = "foot";} - ]; - default-column-width = {proportion = 0.5;}; - } - ]; - - environment = { - "NIXOS_OZONE_WL" = "1"; - "DISPLAY" = ":0"; - "_JAVA_AWT_WM_NONREPARENTING" = "1"; # https://wiki.archlinux.org/title/Sway#Java_applications - }; - }; - }; + } + (mkIf osConfig.theme.enable (let + inherit (osConfig.theme.scheme) palette; + in { + layout.focus-ring.active.color = palette.base0E; + })) + ]; # copied from https://github.com/linyinfeng/dotfiles/blob/c00fe3b1562ad947672863a43e455bc2f01a56b6/home-manager/profiles/niri/default.nix#L594-L611 systemd.user.services.xwayland-satellite = { diff --git a/home/programs/swaylock.nix b/home/programs/swaylock.nix index f5fe17f..e03aa34 100644 --- a/home/programs/swaylock.nix +++ b/home/programs/swaylock.nix @@ -1,9 +1,10 @@ { pkgs, osConfig, + lib, ... }: let - inherit (osConfig.theme.scheme) palette; + inherit (lib) mkMerge mkIf; in { # requires `security.pam.services.swaylock = { };` at the system level or else # unlock will not work. @@ -11,46 +12,53 @@ in { enable = true; package = pkgs.swaylock-effects; - settings = { - clock = true; - timestr = "%H:%M"; + settings = mkMerge [ + { + clock = true; + timestr = "%H:%M"; - indicator = true; - indicator-radius = 111; - indicator-thickness = 9; + indicator = true; + indicator-radius = 111; + indicator-thickness = 9; - screenshots = true; - effect-blur = "7x5"; - effect-vignette = "0.75:0.75"; - effect-pixelate = 5; + screenshots = true; + effect-blur = "7x5"; + effect-vignette = "0.75:0.75"; + effect-pixelate = 5; - ignore-empty-password = false; # needed for PAM to work with fprintd / password - - inside-color = palette.base01; - inside-clear-color = palette.base0C; - inside-caps-lock-color = palette.base09; - inside-ver-color = palette.base0D; - inside-wrong-color = palette.base08; - key-hl-color = palette.base0B; - layout-bg-color = palette.base00; - layout-border-color = palette.base05; - layout-text-color = palette.base07; - line-color = palette.base00; - line-clear-color = palette.base0C; - line-caps-lock-color = palette.base09; - line-ver-color = palette.base0D; - line-wrong-color = palette.base08; - ring-color = palette.base02; - ring-clear-color = palette.base0C; - ring-caps-lock-color = palette.base09; - ring-ver-color = palette.base0D; - ring-wrong-color = palette.base08; - separator-color = palette.base02; - text-color = palette.base07; - text-clear-color = palette.base04; - text-caps-lock-color = palette.base04; - text-ver-color = palette.base04; - text-wrong-color = palette.base04; - }; + ignore-empty-password = false; # needed for PAM to work with fprintd / password + } + (mkIf + osConfig.theme.enable + (let + inherit (osConfig.theme.scheme) palette; + in { + inside-color = palette.base01; + inside-clear-color = palette.base0C; + inside-caps-lock-color = palette.base09; + inside-ver-color = palette.base0D; + inside-wrong-color = palette.base08; + key-hl-color = palette.base0B; + layout-bg-color = palette.base00; + layout-border-color = palette.base05; + layout-text-color = palette.base07; + line-color = palette.base00; + line-clear-color = palette.base0C; + line-caps-lock-color = palette.base09; + line-ver-color = palette.base0D; + line-wrong-color = palette.base08; + ring-color = palette.base02; + ring-clear-color = palette.base0C; + ring-caps-lock-color = palette.base09; + ring-ver-color = palette.base0D; + ring-wrong-color = palette.base08; + separator-color = palette.base02; + text-color = palette.base07; + text-clear-color = palette.base04; + text-caps-lock-color = palette.base04; + text-ver-color = palette.base04; + text-wrong-color = palette.base04; + })) + ]; }; } diff --git a/home/programs/waybar/style.nix b/home/programs/waybar/style.nix index 0eb7964..66bb7ea 100644 --- a/home/programs/waybar/style.nix +++ b/home/programs/waybar/style.nix @@ -5,106 +5,103 @@ }: let inherit (osConfig.theme.scheme) palette; inherit (builtins) concatStringsSep; - inherit (lib) mapAttrsToList; + inherit (lib) mapAttrsToList mkIf mkMerge; generateGtkColors = palette: (concatStringsSep "\n" (mapAttrsToList (name: color: "@define-color ${name} ${color};") palette)); in { - programs.waybar.style = '' - ${ - if osConfig.theme.enable - then generateGtkColors palette - else "" - } + programs.waybar.style = mkMerge [ + (mkIf osConfig.theme.enable generateGtkColors palette) + '' + * { + /* `otf-font-awesome` is required to be installed for icons */ + border: none; + border-radius: 0px; + min-height: 0; + } - * { - /* `otf-font-awesome` is required to be installed for icons */ - border: none; - border-radius: 0px; - min-height: 0; - } + window#waybar { + border-radius: 2em; + font-family: "Symbols Nerd Font", Inter, sans-serif; + font-size: 16px; + font-style: normal; + background: alpha( + @base00, + 0.9999999 + ); /* niri issue workaround, thanks https://github.com/oatmealine/nix-config/blob/bfdddd2cb36ef659bcddc28e0dbb542b6db8b3bc/modules/desktop/themes/catppuccin/waybar.css#L14 */ + color: @base05; + } - window#waybar { - border-radius: 2em; - font-family: "Symbols Nerd Font", Inter, sans-serif; - font-size: 16px; - font-style: normal; - background: alpha( - @base00, - 0.9999999 - ); /* niri issue workaround, thanks https://github.com/oatmealine/nix-config/blob/bfdddd2cb36ef659bcddc28e0dbb542b6db8b3bc/modules/desktop/themes/catppuccin/waybar.css#L14 */ - color: @base05; - } + #workspaces, + .modules-right box { + background: @base02; + padding: 0.15em 0.25em; + border-radius: 1em; + margin: 0 0.25em; + } - #workspaces, - .modules-right box { - background: @base02; - padding: 0.15em 0.25em; - border-radius: 1em; - margin: 0 0.25em; - } + #workspaces { + padding: 0; + background: @base02; + } - #workspaces { - padding: 0; - background: @base02; - } + #workspaces button:nth-child(1) { + border-top-left-radius: 1em; + border-bottom-left-radius: 1em; + } + #workspaces button:nth-last-child(1) { + border-top-right-radius: 1em; + border-bottom-right-radius: 1em; + } - #workspaces button:nth-child(1) { - border-top-left-radius: 1em; - border-bottom-left-radius: 1em; - } - #workspaces button:nth-last-child(1) { - border-top-right-radius: 1em; - border-bottom-right-radius: 1em; - } + #workspaces button { + padding: 0 0.5em; + background-color: transparent; + } - #workspaces button { - padding: 0 0.5em; - background-color: transparent; - } + #workspaces button:hover { + background: rgba(255, 255, 255, 0.1); + box-shadow: none; + } - #workspaces button:hover { - background: rgba(255, 255, 255, 0.1); - box-shadow: none; - } + #workspaces button.active { + background: @base0E; + color: @base02; + } - #workspaces button.active { - background: @base0E; - color: @base02; - } + #workspaces button.urgent { + background: @base08; + } - #workspaces button.urgent { - background: @base08; - } + #window { + margin-left: 1em; + } - #window { - margin-left: 1em; - } + .modules-left, + .modules-right { + margin: 0.4em 0.5em; + } - .modules-left, - .modules-right { - margin: 0.4em 0.5em; - } + #battery, + #clock, + #pulseaudio, + #tray, + #power-profiles-daemon { + padding: 0 0.8em; + } - #battery, - #clock, - #pulseaudio, - #tray, - #power-profiles-daemon { - padding: 0 0.8em; - } - - .modules-left, - .modules-right { - margin: 0.4em 0.5em; - } + .modules-left, + .modules-right { + margin: 0.4em 0.5em; + } - #custom-power { - padding: 0 1.2em; - color: @base08; - } - ''; + #custom-power { + padding: 0 1.2em; + color: @base08; + } + '' + ]; } diff --git a/home/terminal/emulators/foot.nix b/home/terminal/emulators/foot.nix index 49c4bee..fcc6712 100644 --- a/home/terminal/emulators/foot.nix +++ b/home/terminal/emulators/foot.nix @@ -3,7 +3,9 @@ config, lib, ... -}: { +}: let + inherit (lib) mkIf; +in { programs.foot = { enable = true; settings = { @@ -12,7 +14,7 @@ font = "monospace:size=14"; shell = "${lib.getExe config.programs.fish.package}"; }; - colors = let + colors = mkIf osConfig.theme.enable (let inherit (lib) mapAttrs; inherit (lib.strings) removePrefix; # because someone thought this was a great idea: https://github.com/tinted-theming/schemes/commit/61058a8d2e2bd4482b53d57a68feb56cdb991f0b @@ -38,7 +40,7 @@ bright5 = palette.base0E; bright6 = palette.base0C; bright7 = palette.base07; - }; + }); }; }; } diff --git a/hosts/solaire/modules/theme.nix b/hosts/solaire/modules/theme.nix index 394686a..14d5a56 100644 --- a/hosts/solaire/modules/theme.nix +++ b/hosts/solaire/modules/theme.nix @@ -1,6 +1,7 @@ { theme = { wallpaper = ../../../wallpapers/lucy-edgerunners-wallpaper.jpg; + schemeName = "catppuccin-macchiato"; enable = true; gtk.enable = false; };