From 741a5dfb187df49449be440403c32c6aa56d9bf2 Mon Sep 17 00:00:00 2001 From: chayleaf Date: Sun, 26 Feb 2023 17:41:58 +0700 Subject: [PATCH] improve media controls, merge colors, etc --- home/common/gui.nix | 36 ------------- home/common/i3-sway.nix | 109 +++++++++++++++++++++++++-------------- home/common/options.nix | 46 ++++++++++++++++- home/common/terminal.nix | 71 ++++++++++++++++++------- home/common/vim.nix | 2 + home/common/waybar.css | 2 +- 6 files changed, 172 insertions(+), 94 deletions(-) diff --git a/home/common/gui.nix b/home/common/gui.nix index 16fe0b8..7872386 100644 --- a/home/common/gui.nix +++ b/home/common/gui.nix @@ -193,42 +193,6 @@ enabled = "fcitx5"; fcitx5.addons = with pkgs; [ fcitx5-lua fcitx5-gtk fcitx5-mozc fcitx5-configtool fcitx5-qt ]; }; - xresources.properties = { - # special colors - "*.foreground" = "#ebdadd"; - "*.background" = "[75]#24101a"; - "*.cursorColor" = "#ebdadd"; - # black - "*.color0" = "#523b3f"; # "#3b4252"; - "*.color8" = "#6b4d52"; # "#4c566a"; - # red - "*.color1" = "#e66e6e"; - "*.color9" = "#e66e6e"; - # green - "*.color2" = "#8cbf73"; - "*.color10" = "#8cbf73"; - # yellow - "*.color3" = "#ebbe5f"; - "*.color11" = "#ebbe5f"; - # blue - "*.color4" = "#5968b3"; - "*.color12" = "#5968b3"; - # magenta - "*.color5" = "#a64999"; - "*.color13" = "#a64999"; - # cyan - "*.color6" = "#77c7c2"; - "*.color14" = "#77c7c2"; - # white - "*.color7" = "#f0e4e6"; - "*.color15" = "#f7f0f1"; - "*antialias" = true; - "*autohint" = true; - # "*fading" = 0; - # "*fadeColor" = "#6b4d52"; - }; - # home.file.".Xdefaults".source = /. + "/${config.home.homeDirectory}/.Xresources"; - home.file.".Xdefaults".source = config.home.file."${config.home.homeDirectory}/.Xresources".source; services.gammastep.enable = true; fonts.fontconfig.enable = true; gtk = { diff --git a/home/common/i3-sway.nix b/home/common/i3-sway.nix index ddab576..623e9a9 100644 --- a/home/common/i3-sway.nix +++ b/home/common/i3-sway.nix @@ -3,6 +3,37 @@ let modifier = "Mod4"; rofiSway = config.programs.rofi.finalPackage; rofiI3 = pkgs.rofi.override { plugins = config.programs.rofi.plugins; }; +audioNext = with pkgs; writeShellScript "playerctl-next" '' + ${playerctl}/bin/playerctl next + PLAYER=$(${playerctl}/bin/playerctl -l | head -n 1) + # mpdris2 bug: audio wont play after a seek/skip, you have to pause-unpause + if [[ "$PLAYER" == "mpd" ]]; then + ${playerctl}/bin/playerctl pause + ${playerctl}/bin/playerctl position 0 + ${playerctl}/bin/playerctl play + fi +''; +audioPrev = with pkgs; writeShellScript "playerctl-prev" '' + # just seek if over 5 seconds into the track + POS=$(${playerctl}/bin/playerctl position) + PLAYER=$(${playerctl}/bin/playerctl -l | head -n 1) + if [ -n "$POS" ]; then + if (( $(echo "$POS > 5.01" | ${bc}/bin/bc -l) )); then + SEEK=1 + fi + fi + if [ -z "$SEEK" ]; then + ${playerctl}/bin/playerctl previous + else + ${playerctl}/bin/playerctl position 0 + fi + # mpdris2 bug: audio wont play after a seek/skip, you have to pause-unpause + if [[ "$PLAYER" == "mpd" ]]; then + ${playerctl}/bin/playerctl pause + ${playerctl}/bin/playerctl position 0 + ${playerctl}/bin/playerctl play + fi +''; barConfig = { mode = "dock"; hiddenState = "hide"; @@ -15,18 +46,18 @@ barConfig = { }; trayOutput = "*"; colors = { - background = "#24101a"; - statusline = "#ebdadd"; - separator = "#6b4d52"; + background = "#${config.colors.background}"; + statusline = "#${config.colors.foreground}"; + separator = "#${config.colors.brBlack}"; focusedWorkspace = { border = "#782a2a"; background = "#782a2a"; - text = "#ebdadd"; + text = "#${config.colors.foreground}"; }; activeWorkspace = { border = "#913131"; background = "#913131"; - text = "#ebdadd"; + text = "#${config.colors.foreground}"; }; inactiveWorkspace = { border = "#472222"; @@ -36,12 +67,12 @@ barConfig = { urgentWorkspace = { border = "#734545"; background = "#993d3d"; - text = "#ebdadd"; + text = "#${config.colors.foreground}"; }; bindingMode = { border = "#734545"; background = "#993d3d"; - text = "#ebdadd"; + text = "#${config.colors.foreground}"; }; }; }; @@ -59,37 +90,37 @@ commonConfig = { ]; colors = { focused = { - childBorder = "#b0a3a5c0"; - # background = "#24101ac0"; + childBorder = "#b0a3a5${config.colors.hexAlpha}"; + # background = "#${config.colors.background}${config.colors.hexAlpha}"; background = "#4c4042e0"; - # border = "#24101ac0"; + # border = "#${config.colors.background}${config.colors.hexAlpha}"; border = "#4c4042e0"; indicator = "#b35656"; - text = "#ebdadd"; + text = "#${config.colors.foreground}"; }; focusedInactive = { - # background = "#24101ac0"; + # background = "#${config.colors.background}${config.colors.hexAlpha}"; background = "#4c4042e0"; - # border = "#24101ac0"; + # border = "#${config.colors.background}${config.colors.hexAlpha}"; border = "#4c4042e0"; - childBorder = "#24101ac0"; + childBorder = "#${config.colors.background}${config.colors.hexAlpha}"; indicator = "#b32d2d"; - text = "#ebdadd"; + text = "#${config.colors.foreground}"; }; unfocused = { - background = "#24101ac0"; - # border = "#24101ac0"; + background = "#${config.colors.background}${config.colors.hexAlpha}"; + # border = "#${config.colors.background}${config.colors.hexAlpha}"; border = "#4c4042e0"; - childBorder = "#24101ac0"; + childBorder = "#${config.colors.background}${config.colors.hexAlpha}"; indicator = "#661a1a"; - text = "#ebdadd"; + text = "#${config.colors.foreground}"; }; urgent = { background = "#993d3d"; border = "#734545"; childBorder = "#734545"; indicator = "#993d3d"; - text = "#ebdadd"; + text = "#${config.colors.foreground}"; }; }; floating.criteria = [ @@ -178,8 +209,8 @@ in XF86AudioLowerVolume = "exec ${pkgs.pamixer}/bin/pamixer --decrease 5"; XF86AudioMute = "exec ${pkgs.pamixer}/bin/pamixer --toggle-mute"; XF86AudioPlay = "exec ${pkgs.playerctl}/bin/playerctl play-pause"; - XF86AudioNext = "exec ${pkgs.playerctl}/bin/playerctl next"; - XF86AudioPrev = "exec ${pkgs.playerctl}/bin/playerctl previous"; + XF86AudioNext = "exec ${audioNext}"; + XF86AudioPrev = "exec ${audioPrev}"; }; terminal = config.terminalBinX; }; in commonConfig // i3Config; @@ -275,8 +306,8 @@ in "--locked XF86AudioLowerVolume" = "exec ${pkgs.pamixer}/bin/pamixer --decrease 5"; "--locked XF86AudioMute" = "exec ${pkgs.pamixer}/bin/pamixer --toggle-mute"; "--locked --inhibited XF86AudioPlay" = "exec ${pkgs.playerctl}/bin/playerctl play-pause"; - "--locked --inhibited XF86AudioNext" = "exec ${pkgs.playerctl}/bin/playerctl next"; - "--locked --inhibited XF86AudioPrev" = "exec ${pkgs.playerctl}/bin/playerctl previous"; + "--locked --inhibited XF86AudioNext" = "exec ${audioNext}"; + "--locked --inhibited XF86AudioPrev" = "exec ${audioPrev}"; }); startup = commonConfig.startup ++ [ { @@ -355,25 +386,25 @@ in line-uses-inside = true; - inside-color = "#24101ac0"; - text-color = "#ebdadd"; - ring-color = "#8cbf73"; # green + inside-color = "#${config.colors.background}${config.colors.hexAlpha}"; + text-color = "#${config.colors.foreground}"; + ring-color = "#${config.colors.green}"; key-hl-color = "#6398bf"; # blue - bs-hl-color = "#e66e6e"; # red + bs-hl-color = "#${config.colors.red}"; inside-caps-lock-color = inside-color; text-caps-lock-color = text-color; - ring-caps-lock-color = "#ebbe5f"; # yellow + ring-caps-lock-color = "#${config.colors.yellow}"; caps-lock-key-hl-color = key-hl-color; caps-lock-bs-hl-color = bs-hl-color; inside-clear-color = inside-color; text-clear-color = text-color; - ring-clear-color = ring-color; # green + ring-clear-color = ring-color; inside-ver-color = inside-color; text-ver-color = text-color; - ring-ver-color = "#a64999"; # purple + ring-ver-color = "#${config.colors.magenta}"; inside-wrong-color = inside-color; text-wrong-color = text-color; @@ -398,8 +429,10 @@ in scrollbar = true; background = transparent; - background-color = mkLiteral "#24101a80"; - foreground = mkLiteral "#ebdadd"; + background-color = + # this somehow uses different opacity + mkLiteral "#${config.colors.background}c0"; + foreground = mkLiteral "#${config.colors.foreground}"; border-color = foreground; separatorcolor = border-color; scrollbar-handle = border-color; @@ -409,21 +442,21 @@ in alternate-normal-background = transparent; alternate-normal-foreground = normal-foreground; selected-normal-background = mkLiteral "#394893"; - selected-normal-foreground = mkLiteral "#e66e6e"; + selected-normal-foreground = mkLiteral "#${config.colors.red}"; active-background = foreground; - active-foreground = mkLiteral "#24101a"; + active-foreground = mkLiteral "#${config.colors.background}"; alternate-active-background = active-background; alternate-active-foreground = active-foreground; - selected-active-background = mkLiteral "#e66e6e"; + selected-active-background = mkLiteral "#${config.colors.red}"; selected-active-foreground = mkLiteral "#394893"; - urgent-background = mkLiteral "#e66e6e"; + urgent-background = mkLiteral "#${config.colors.red}"; urgent-foreground = foreground; alternate-urgent-background = urgent-background; alternate-urgent-foreground = urgent-foreground; selected-urgent-background = mkLiteral "#394893"; - selected-urgent-foreground = mkLiteral "#ebbe5f"; + selected-urgent-foreground = mkLiteral "#${config.colors.yellow}"; }; "@import" = "gruvbox-common.rasi"; }; diff --git a/home/common/options.nix b/home/common/options.nix index f44d4f9..cd6525b 100644 --- a/home/common/options.nix +++ b/home/common/options.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib, config, ... }: with lib; { options.terminals = mkOption { type = with types; listOf str; @@ -31,9 +31,53 @@ with lib; { type = types.float; description = "opacity (0.0-1.0)"; }; + hexAlpha = mkOption { + type = types.str; + description = "hex opacity (read-only)"; + }; + percentAlpha = mkOption { + type = types.int; + description = "opacity percentage (read-only)"; + }; + black = mkOption { type = types.str; description = "read-only"; }; + red = mkOption { type = types.str; description = "read-only"; }; + green = mkOption { type = types.str; description = "read-only"; }; + yellow = mkOption { type = types.str; description = "read-only"; }; + blue = mkOption { type = types.str; description = "read-only"; }; + magenta = mkOption { type = types.str; description = "read-only"; }; + cyan = mkOption { type = types.str; description = "read-only"; }; + white = mkOption { type = types.str; description = "read-only"; }; + brBlack = mkOption { type = types.str; description = "read-only"; }; + brRed = mkOption { type = types.str; description = "read-only"; }; + brGreen = mkOption { type = types.str; description = "read-only"; }; + brYellow = mkOption { type = types.str; description = "read-only"; }; + brBlue = mkOption { type = types.str; description = "read-only"; }; + brMagenta = mkOption { type = types.str; description = "read-only"; }; + brCyan = mkOption { type = types.str; description = "read-only"; }; + brWhite = mkOption { type = types.str; description = "read-only"; }; }; }; }; + config.colors.hexAlpha = + let hex = lib.trivial.toHexString (lib.trivial.min 255 (builtins.floor (config.colors.alpha * 256.0))); + in if (builtins.stringLength hex) == 2 then hex else "0${hex}"; + config.colors.percentAlpha = builtins.floor (config.colors.alpha * 100.0); + config.colors.black = builtins.elemAt config.colors.base 0; + config.colors.red = builtins.elemAt config.colors.base 1; + config.colors.green = builtins.elemAt config.colors.base 2; + config.colors.yellow = builtins.elemAt config.colors.base 3; + config.colors.blue = builtins.elemAt config.colors.base 4; + config.colors.magenta = builtins.elemAt config.colors.base 5; + config.colors.cyan = builtins.elemAt config.colors.base 6; + config.colors.white = builtins.elemAt config.colors.base 7; + config.colors.brBlack = builtins.elemAt config.colors.base 8; + config.colors.brRed = builtins.elemAt config.colors.base 9; + config.colors.brGreen = builtins.elemAt config.colors.base 10; + config.colors.brYellow = builtins.elemAt config.colors.base 11; + config.colors.brBlue = builtins.elemAt config.colors.base 12; + config.colors.brMagenta = builtins.elemAt config.colors.base 13; + config.colors.brCyan = builtins.elemAt config.colors.base 14; + config.colors.brWhite = builtins.elemAt config.colors.base 15; options.termShell = mkOption { type = types.submodule { options = { diff --git a/home/common/terminal.nix b/home/common/terminal.nix index 8d71151..b02bed3 100644 --- a/home/common/terminal.nix +++ b/home/common/terminal.nix @@ -9,7 +9,7 @@ let }).${term}); color = builtins.elemAt config.colors.base; hex = (x: if builtins.isFunction x then (y: "#" + (x y)) else ("#" + x)); - shell = lib.mkIf config.termShell.enable config.termShell.path; + shell = lib.mkIf config.termShell.enable (lib.mkDefault config.termShell.path); in { imports = [ ./options.nix ]; terminalBin = getTerminalBin (builtins.head config.terminals); @@ -35,8 +35,10 @@ in { ]; foreground = "ebdadd"; background = "24101a"; - alpha = 0.75; + # 0.75 with opengl sway + alpha = 0.95; }; + programs.tmux.shell = shell; programs.alacritty = { enable = supportTerminal "alacritty"; # https://github.com/alacritty/alacritty/blob/master/alacritty.yml @@ -48,24 +50,24 @@ in { colors.primary.background = hex config.colors.background; colors.primary.foreground = hex config.colors.foreground; colors.normal = { - black = hex color 0; - red = hex color 1; - green = hex color 2; - yellow = hex color 3; - blue = hex color 4; - magenta = hex color 5; - cyan = hex color 6; - white = hex color 7; + black = hex config.colors.black; + red = hex config.colors.red; + green = hex config.colors.green; + yellow = hex config.colors.yellow; + blue = hex config.colors.blue; + magenta = hex config.colors.magenta; + cyan = hex config.colors.cyan; + white = hex config.colors.white; }; colors.bright = { - black = hex color 8; - red = hex color 9; - green = hex color 10; - yellow = hex color 11; - blue = hex color 12; - magenta = hex color 13; - cyan = hex color 14; - white = hex color 15; + black = hex config.colors.brBlack; + red = hex config.colors.brRed; + green = hex config.colors.brGreen; + yellow = hex config.colors.brYellow; + blue = hex config.colors.brBlue; + magenta = hex config.colors.brMagenta; + cyan = hex config.colors.brCyan; + white = hex config.colors.brWhite; }; }; }; @@ -89,6 +91,39 @@ in { "xft:Symbols Nerd Font Mono:size=16" ]; }; + xresources.properties = lib.mkIf config.programs.urxvt.enable { + # special colors + "*.foreground" = hex config.colors.foreground; + "*.background" = "[${builtins.toString config.colors.percentAlpha}]#${config.colors.background}"; + "*.cursorColor" = hex config.colors.foreground; + # black + "*.color0" = hex color 0; + "*.color8" = hex color 8; + # red + "*.color1" = hex color 1; + "*.color9" = hex color 9; + # green + "*.color2" = hex color 2; + "*.color10" = hex color 10; + # yellow + "*.color3" = hex color 3; + "*.color11" = hex color 11; + # blue + "*.color4" = hex color 4; + "*.color12" = hex color 12; + # magenta + "*.color5" = hex color 5; + "*.color13" = hex color 13; + # cyan + "*.color6" = hex color 6; + "*.color14" = hex color 14; + # white + "*.color7" = hex color 7; + "*.color15" = hex color 15; + "*antialias" = true; + "*autohint" = true; + }; + home.file.".Xdefaults".source = lib.mkIf config.programs.urxvt.enable config.home.file."${config.home.homeDirectory}/.Xresources".source; programs.foot = { enable = supportTerminal "foot"; server.enable = true; diff --git a/home/common/vim.nix b/home/common/vim.nix index 4795f29..29cfbc8 100644 --- a/home/common/vim.nix +++ b/home/common/vim.nix @@ -24,6 +24,8 @@ au FileType markdown set colorcolumn=73 textwidth=72 au FileType gitcommit set colorcolumn=73 highlight NormalFloat guibg=NONE + au BufReadPre * set foldmethod=syntax + au BufReadPost * folddoc foldopen! ''; viAlias = true; vimAlias = true; diff --git a/home/common/waybar.css b/home/common/waybar.css index f9efb66..06e5c4c 100644 --- a/home/common/waybar.css +++ b/home/common/waybar.css @@ -1,4 +1,4 @@ -@define-color bg rgba(36, 16, 26, .75); /*#24101ac0;*/ +@define-color bg rgba(36, 16, 26, /*.75*/ .95); /*#24101ac0;*/ @define-color blue #87e5cf; @define-color green #8cbf73; @define-color yellow #ebbe5f;