From 56a89c495930fe5dea4870a10329f2b5d16b842b Mon Sep 17 00:00:00 2001 From: Frantisek Bohacek Date: Sun, 7 Apr 2024 19:25:41 +0200 Subject: [PATCH] feat(home): use themes as option of the module system --- home/modules/default.nix | 1 + .../profiles/desktop/qtile/autorandr.nix | 13 +---- .../profiles/desktop/qtile/config/bars.py | 50 ++++++++-------- .../profiles/desktop/qtile/config/config.py | 9 ++- .../profiles/desktop/qtile/config/styling.py | 12 ---- .../profiles/desktop/qtile/default.nix | 2 +- .../profiles/desktop/qtile/launcher.nix | 19 ++++--- .../profiles/desktop/qtile/services.nix | 22 +++---- home/modules/themes.nix | 57 +++++++++++++++++++ scratch | 2 + themes/colors.nix | 48 ---------------- 11 files changed, 112 insertions(+), 123 deletions(-) delete mode 100644 home/modules/profiles/desktop/qtile/config/styling.py create mode 100644 home/modules/themes.nix create mode 100644 scratch delete mode 100644 themes/colors.nix diff --git a/home/modules/default.nix b/home/modules/default.nix index 5358d82..6116e7f 100644 --- a/home/modules/default.nix +++ b/home/modules/default.nix @@ -3,5 +3,6 @@ ./home-config.nix ./profiles/default.nix ./programs/default.nix + ./themes.nix ]; } diff --git a/home/modules/profiles/desktop/qtile/autorandr.nix b/home/modules/profiles/desktop/qtile/autorandr.nix index 7dad484..4748cb3 100644 --- a/home/modules/profiles/desktop/qtile/autorandr.nix +++ b/home/modules/profiles/desktop/qtile/autorandr.nix @@ -1,16 +1,5 @@ -{ inputs, config, lib, pkgs, ... }: +{ config, lib, pkgs, ... }: -let - inherit (config.lib.formats.rasi) mkLiteral; # Theme.rasi alternative. Add Theme here - colors = import "${inputs.self}/themes/colors.nix"; - - themes-collection = pkgs.fetchFromGitHub { - owner = "newmanls"; - repo = "rofi-themes-collection"; - rev = "f87e08300cb1c984994efcaf7d8ae26f705226fd"; - hash = "sha256-A6zIAQvjfe/XB5GZefs4TWgD+eGICQP2Abz/sQynJPo="; - }; -in { config = lib.mkIf config.profiles.desktop.qtile.enable { programs.autorandr = { diff --git a/home/modules/profiles/desktop/qtile/config/bars.py b/home/modules/profiles/desktop/qtile/config/bars.py index 262ce08..f405713 100644 --- a/home/modules/profiles/desktop/qtile/config/bars.py +++ b/home/modules/profiles/desktop/qtile/config/bars.py @@ -3,7 +3,7 @@ import re from libqtile import layout, bar, qtile from qtile_extras.widget.decorations import BorderDecoration, PowerLineDecoration, RectDecoration import qtile_extras.widget as widget -from styling import colors +from nixenvironment import nixConfig from libqtile.widget import Mpris2, Bluetooth from tasklist import TaskList @@ -15,13 +15,13 @@ def create_top_bar(systray = False): } widgets = [ - widget.Sep(padding = 5, size_percent = 0, background = colors['background_secondary']), + widget.Sep(padding = 5, size_percent = 0, background = nixConfig.theme.background.secondary, widget.CurrentScreen( active_text = 'I', - active_color = colors['active'], + active_color = nixConfig.theme.foreground.active, padding = 3, fontsize = 16, - background = colors['background_secondary'], + background = nixConfig.theme.background.secondary, ), widget.GroupBox( markup = False, @@ -30,22 +30,22 @@ def create_top_bar(systray = False): margin_x = 2, disable_drag = True, use_mouse_wheel = True, - active = colors['white'], - inactive = colors['grey'], + active = nixConfig.theme.foreground.activeAlt, + inactive = nixConfig.theme.foreground.inactive, urgent_alert_method = 'line', - urgent_border = colors['urgent'], - this_current_screen_border = colors['active'], - this_screen_border = colors['secondary'], - other_screen_border = colors['inactive'], + urgent_border = nixConfig.theme.urgent, + this_current_screen_border = nixConfig.theme.foreground.active, + this_screen_border = nixConfig.theme.foreground.secondary, + other_screen_border = nixConfig.theme.background.inactive, other_current_screen_border = '6989c0', - background = colors['background_secondary'], + background = nixConfig.theme.background.secondary, ), widget.CurrentScreen( active_text = 'I', - active_color = colors['active'], + active_color = nixConfig.theme.foreground.active, padding = 3, fontsize = 16, - background = colors['background_secondary'], + background = nixConfig.theme.background.secondary, decorations = [ PowerLineDecoration(path = 'forward_slash'), ], @@ -57,14 +57,14 @@ def create_top_bar(systray = False): ), widget.Prompt(), widget.WindowName( - foreground = colors['primary'], + foreground = nixConfig.theme.foreground.primary, width = bar.CALCULATED, padding = 10, empty_group_string = 'Desktop', max_chars = 160, decorations = [ RectDecoration( - colour = colors['black'], + colour = nixConfig.theme.background.box, radius = 0, padding_y = 4, padding_x = 0, @@ -78,7 +78,7 @@ def create_top_bar(systray = False): padding = 15, decorations = [ RectDecoration( - colour = colors['black'], + colour = nixConfig.theme.background.box, radius = 0, padding_y = 4, padding_x = 6, @@ -91,7 +91,7 @@ def create_top_bar(systray = False): # interface = 'enp24s0', # prefix='M', # format = '{down:6.2f} {down_suffix:<2}↓↑{up:6.2f} {up_suffix:<2}', - # background = colors['background_secondary'], + # background = nixConfig.theme.background.secondary, # **powerline, # ), widget.Memory( @@ -102,7 +102,7 @@ def create_top_bar(systray = False): widget.CPU( format = '{load_percent} %', fmt = ' {}', - background = colors['background_secondary'], + background = nixConfig.theme.background.secondary, **powerline, ), widget.DF( @@ -122,16 +122,16 @@ def create_top_bar(systray = False): ), widget.Clock( timezone='Europe/Prague', - foreground = colors['primary'], + foreground = nixConfig.theme.foreground.primary, format='%A, %B %d - %H:%M:%S', - background = colors['background_secondary'], + background = nixConfig.theme.background.secondary, **powerline ), widget.Volume( fmt = '🕫 {}', ), widget.Sep( - foreground = colors['background_secondary'], + foreground = nixConfig.theme.background.secondary, size_percent = 70, linewidth = 3, ), @@ -149,7 +149,7 @@ def create_top_bar(systray = False): if systray: widgets.append(widget.Sep( - foreground = colors['background_secondary'], + foreground = nixConfig.theme.background.secondary, size_percent = 70, linewidth = 2, )) @@ -184,7 +184,7 @@ def create_bottom_bar(): padding = 10, decorations = [ RectDecoration( - colour = colors['black'], + colour = nixConfig.theme.background.box, radius = 0, padding_y = 4, padding_x = 5, @@ -202,7 +202,7 @@ def create_bottom_bar(): padding = 10, decorations = [ RectDecoration( - colour = colors['black'], + colour = nixConfig.theme.background.box, radius = 0, padding_y = 4, padding_x = 5, @@ -219,7 +219,7 @@ def create_bottom_bar(): widget.Wttr( location = {'Odolena_Voda': ''}, format = '%t %c', - background = colors['background_secondary'], + background = nixConfig.theme.background.secondary, **powerline, ), ], 30) diff --git a/home/modules/profiles/desktop/qtile/config/config.py b/home/modules/profiles/desktop/qtile/config/config.py index 43b2f0b..176b080 100644 --- a/home/modules/profiles/desktop/qtile/config/config.py +++ b/home/modules/profiles/desktop/qtile/config/config.py @@ -16,7 +16,6 @@ from nixenvironment import nixConfig import functions import utils from screens import init_screens, observe_monitors, init_navigation_keys -from styling import colors import time # ##################################### @@ -25,8 +24,8 @@ mod = 'mod4' terminal = nixConfig.defaults.terminal layout_theme = { - 'border_focus': colors['active'], - 'border_normal': colors['inactive'], + 'border_focus': nixConfig.theme.foreground.active, + 'border_normal': nixConfig.theme.background.inactive, 'border_width': 1, 'margin': 3, } @@ -41,8 +40,8 @@ widget_defaults = dict( font = 'Roboto Bold', fontsize = 13, padding = 3, - background = colors['background_primary'], - foreground = colors['white'], + background = nixConfig.theme.background.primary, + foreground = nixConfig.theme.foreground.activeAlt, ) extension_defaults = widget_defaults.copy() diff --git a/home/modules/profiles/desktop/qtile/config/styling.py b/home/modules/profiles/desktop/qtile/config/styling.py deleted file mode 100644 index 80e1d71..0000000 --- a/home/modules/profiles/desktop/qtile/config/styling.py +++ /dev/null @@ -1,12 +0,0 @@ -colors = { - 'primary': '51afef', - 'active': '8babf0', - 'inactive': '555e60', - 'secondary': '55eddc', - 'background_primary': '222223', - 'background_secondary': '444444', - 'urgent': 'c45500', - 'white': 'd5d5d5', - 'grey': '737373', - 'black': '121212', -} diff --git a/home/modules/profiles/desktop/qtile/default.nix b/home/modules/profiles/desktop/qtile/default.nix index 17f2f24..7b33417 100644 --- a/home/modules/profiles/desktop/qtile/default.nix +++ b/home/modules/profiles/desktop/qtile/default.nix @@ -3,6 +3,7 @@ let configFormat = pkgs.formats.json {}; configJson = configFormat.generate "qtile-config.json" { + theme = config.themes.default; scripts = { brightness = ./config/brightness.sh; notifications = { @@ -68,7 +69,6 @@ in { xdg.configFile."qtile/functions.py".source = ./config/functions.py; xdg.configFile."qtile/bars.py".source = ./config/bars.py; xdg.configFile."qtile/screens.py".source = ./config/screens.py; - xdg.configFile."qtile/styling.py".source = ./config/styling.py; xdg.configFile."qtile/tasklist.py".source = ./config/tasklist.py; xdg.configFile."qtile/xmonadcustom.py".source = ./config/xmonadcustom.py; diff --git a/home/modules/profiles/desktop/qtile/launcher.nix b/home/modules/profiles/desktop/qtile/launcher.nix index 30825f7..9ffca82 100644 --- a/home/modules/profiles/desktop/qtile/launcher.nix +++ b/home/modules/profiles/desktop/qtile/launcher.nix @@ -1,8 +1,7 @@ -{ inputs, config, lib, pkgs, ... }: +{ config, lib, pkgs, ... }: let inherit (config.lib.formats.rasi) mkLiteral; # Theme.rasi alternative. Add Theme here - colors = import "${inputs.self}/themes/colors.nix"; themes-collection = pkgs.fetchFromGitHub { owner = "newmanls"; @@ -26,17 +25,17 @@ in terminal = "${config.home-config.defaultTerminalExe}"; location = "center"; font = "${config.home-config.defaultFont} 11"; - theme = with colors.scheme.doom; { + theme = with config.themes.default; { # Based on spotlight theme "*" = { font = "Montserrat 12"; - bg0 = mkLiteral "#222223e6"; - bg1 = mkLiteral "#44444480"; - bg2 = mkLiteral "#51afefe6"; - fg0 = mkLiteral "#${text}"; - fg1 = mkLiteral "#d5d5d5"; - fg2 = mkLiteral "#${fg}"; + bg0 = mkLiteral "#${background.primary}e6"; + bg1 = mkLiteral "#${background.secondary}80"; + bg2 = mkLiteral "#${background.active}e6"; + fg0 = mkLiteral "#${foreground.text}"; + fg1 = mkLiteral "#${foreground.activeAlt}"; + fg2 = mkLiteral "#${foreground.inactive}"; background-color = mkLiteral "transparent"; text-color = mkLiteral "@fg0"; @@ -48,6 +47,8 @@ in "window" = { background-color = mkLiteral "@bg0"; + border = mkLiteral "2px 0 0"; + border-color = mkLiteral "@bg2"; location = mkLiteral "center"; width = mkLiteral "640"; diff --git a/home/modules/profiles/desktop/qtile/services.nix b/home/modules/profiles/desktop/qtile/services.nix index b1170ae..cd60be1 100644 --- a/home/modules/profiles/desktop/qtile/services.nix +++ b/home/modules/profiles/desktop/qtile/services.nix @@ -1,7 +1,6 @@ { inputs, config, lib, pkgs, ... }: let - colors = import "${inputs.self}/themes/colors.nix"; mpris-ctl = inputs.self.packages.${pkgs.system}.mpris-ctl; sequence-detector = inputs.self.packages.${pkgs.system}.sequence-detector; in { @@ -26,7 +25,7 @@ in { package = pkgs.papirus-icon-theme; size = "16x16"; }; - settings = with colors.scheme.doom; { # Settings + settings = with config.themes.default; { # Settings global = { monitor = 0; follow = "keyboard"; @@ -39,9 +38,10 @@ in { shrink = "yes"; transparency = 10; padding = 16; + gap_size = 5; horizontal_padding = 16; - frame_width = 3; - frame_color = "#${bg}"; + frame_width = 2; + frame_color = "#${background.active}"; separator_color = "frame"; font = "FiraCode Nerd Font 10"; line_height = 4; @@ -60,19 +60,19 @@ in { hide_duplicate_count = true; }; urgency_low = { # Colors - background = "#${bg}"; - foreground = "#${text}"; + background = "#${background.primary}"; + foreground = "#${foreground.text}"; timeout = 4; }; urgency_normal = { - background = "#${bg}"; - foreground = "#${text}"; + background = "#${background.primary}"; + foreground = "#${foreground.text}"; timeout = 4; }; urgency_critical = { - background = "#${bg}"; - foreground = "#${text}"; - frame_color = "#${red}"; + background = "#${background.primary}"; + foreground = "#${foreground.text}"; + frame_color = "#${urgent}"; timeout = 10; }; }; diff --git a/home/modules/themes.nix b/home/modules/themes.nix new file mode 100644 index 0000000..f5125ca --- /dev/null +++ b/home/modules/themes.nix @@ -0,0 +1,57 @@ +{ lib, ... }: + +let + mkColorOption = description: lib.mkOption { + inherit description; + type = lib.types.str; + }; +in { + options = { + themes = lib.mkOption { + type = lib.types.attrsOf (lib.types.submodule ({config, ...}: { + options = { + foreground = { + primary = mkColorOption "Primary color for foreground (text)"; + secondary = mkColorOption "Secondary color for foreground (text)"; + text = mkColorOption "Basic text color for stuff that's not primary, secondary etc."; + + active = mkColorOption "Color for foreground (text) when element is active"; + activeAlt = mkColorOption "Color for foreground when element is active, and `active` color is used as background instead"; + + inactive = mkColorOption "Color for foreground (text) when element is inactive"; + }; + background = { + primary = mkColorOption "Primary color for background"; + secondary = mkColorOption "Primary color for background"; + box = mkColorOption "Color for box elements"; + inactive = mkColorOption "Color for foreground (text) when element is inactive"; + active = mkColorOption "Color for background when element is active. When this is in use, use `foreground.activeAlt` for text."; + }; + + urgent = mkColorOption "Urgent windows"; + }; + })); + }; + }; + + config = { + themes.default = { + foreground = { + primary = "51afef"; + secondary = "55eddc"; + activeAlt = "d5d5d5"; + text = "cccccc"; + active = "8babf0"; + inactive = "737373"; + }; + background = { + primary = "222223"; + secondary = "444444"; + active = "8babf0"; + inactive = "555e60"; + box = "121212"; + }; + urgent = "c45500"; + }; + }; +} diff --git a/scratch b/scratch new file mode 100644 index 0000000..2e5787e --- /dev/null +++ b/scratch @@ -0,0 +1,2 @@ +themes to proper options +defaultTerminal and editor to session variables diff --git a/themes/colors.nix b/themes/colors.nix deleted file mode 100644 index 252691d..0000000 --- a/themes/colors.nix +++ /dev/null @@ -1,48 +0,0 @@ -# -# System themes -# - -{ - scheme = { - doom = { - scheme = "Doom One Dark"; - black = "000000"; - red = "ff6c6b"; - orange = "da8548"; - yellow = "ecbe7b"; - green = "95be65"; - teal = "4db5bd"; - blue = "6eaafb"; - dark-blue = "2257a0"; - magenta = "c678dd"; - violet = "a9a1e1"; - cyan = "6cdcf7"; - dark-cyan = "5699af"; - emphasis = "50536b"; - text = "dfdfdf"; - text-alt = "b2b2b2"; - fg = "abb2bf"; - bg = "282c34"; - }; - - dracula = { - scheme = "Dracula"; - base00 = "282936"; #background - base01 = "3a3c4e"; - base02 = "4d4f68"; - base03 = "626483"; - base04 = "62d6e8"; - base05 = "e9e9f4"; #foreground - base06 = "f1f2f8"; - base07 = "f7f7fb"; - base08 = "ea51b2"; - base09 = "b45bcf"; - base0A = "00f769"; - base0B = "ebff87"; - base0C = "a1efe4"; - base0D = "62d6e8"; - base0E = "b45bcf"; - base0F = "00f769"; - }; - }; -} -- 2.48.1