From 5d4536fbb38223cb49452ca699df7382cf6e5841 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Fri, 14 Mar 2025 08:46:05 +0100 Subject: graphical/waybar: gatekeep behind an enable option --- usecases/desktop/graphical.nix | 2 +- usecases/desktop/graphical/sway.nix | 1 + usecases/desktop/graphical/waybar.nix | 641 ++++++++++++++++++---------------- 3 files changed, 338 insertions(+), 306 deletions(-) diff --git a/usecases/desktop/graphical.nix b/usecases/desktop/graphical.nix index 787c455..f038b06 100644 --- a/usecases/desktop/graphical.nix +++ b/usecases/desktop/graphical.nix @@ -15,7 +15,7 @@ inputs: { (import ./graphical/sway.nix inputs) ./graphical/swaylock.nix ./graphical/swaync.nix - (import ./graphical/waybar.nix inputs) + ./graphical/waybar.nix ./graphical/wlsunset.nix (import ./graphical/zathura.nix inputs) ]; diff --git a/usecases/desktop/graphical/sway.nix b/usecases/desktop/graphical/sway.nix index 34dc978..e5aec69 100644 --- a/usecases/desktop/graphical/sway.nix +++ b/usecases/desktop/graphical/sway.nix @@ -10,6 +10,7 @@ _inputs: greetd.enable = true; swaylock.enable = true; swaync.enable = true; + waybar.enable = true; wlsunset.enable = true; }; diff --git a/usecases/desktop/graphical/waybar.nix b/usecases/desktop/graphical/waybar.nix index 6e6620c..4fdb68a 100644 --- a/usecases/desktop/graphical/waybar.nix +++ b/usecases/desktop/graphical/waybar.nix @@ -1,311 +1,342 @@ -inputs: - -{ config, lib, pkgs, ... }: - { - home-manager.users.minijackson = { - programs.waybar = { - enable = true; - - settings = [{ - layer = "top"; - position = "bottom"; - height = 25; - - gtk-layer-shell = true; - - modules-left = [ "sway/workspaces" "sway/mode" ]; - modules-center = lib.mkIf config.services.mpd.enable [ "mpd" ]; - modules-right = [ - "custom/notification" - "pulseaudio" - "network#eth" - "network#wlan" - "cpu" - "memory" - "temperature" - "backlight" - "battery" - "clock" - "tray" - ]; + config, + lib, + pkgs, + ... +}: + +let + cfg = config.reborn.waybar; +in +{ + options.reborn.waybar = { + enable = lib.mkEnableOption "Reborn waybar config"; + }; - mpd = lib.mkIf config.services.mpd.enable { - format = "{stateIcon} {consumeIcon}{randomIcon}{repeatIcon}{singleIcon}{artist} - {album} - {title} ({elapsedTime:%M:%S}/{totalTime:%M:%S}) "; - format-stopped = "{consumeIcon}{randomIcon}{repeatIcon}{singleIcon}Stopped "; - format-disconnected = "Disconnected "; - - on-click-middle = "${pkgs.alacritty}/bin/alacritty --command ncmpcpp"; - - consume-icons = { - on = " "; - }; - - random-icons = { - on = " "; - }; - - repeat-icons = { - on = " "; - }; - - single-icons = { - on = "1 "; - }; - - state-icons = { - playing = ""; - paused = ""; - }; - }; - - "custom/notification" = let - swaync-client = "${lib.getBin config.home-manager.users.minijackson.services.swaync.package}/bin/swaync-client"; - in { - format = "{icon}"; - format-icons = { - notification = "󰂜"; - none = "󰂜"; - dnd-notification = "󰪑"; - dnd-none = "󰪑"; - inhibited-notification = "󰂜"; - inhibited-none = "󰂜"; - dnd-inhibited-notification = "󰪑"; - dnd-inhibited-none = "󰪑"; - }; - tooltip = false; - return-type = "json"; - exec = "${swaync-client} -swb"; - on-click = "${swaync-client} -t -sw"; - on-click-right = "${swaync-client} -d -sw"; - escape = true; - }; - - clock = { - tooltip-format = "{:%Y-%m-%d | %H:%M}"; - format-alt = "{:%Y-%m-%d}"; - }; - - cpu = { format = "{usage}% "; }; - - memory = { format = "{}% "; }; - - battery = { - states = { good = 90; }; - format = "{capacity}% {icon}"; - format-icons = [ - "" - "" - "" - "" - "" - ]; - }; - - "network#eth" = { - interface = "enp*"; - format-ethernet = "{ipaddr}/{cidr} "; - format-disconnected = "Disconnected "; - }; - - "network#wlan" = { - interface = "wlp*"; - format-wifi = "{essid} ({signalStrength}%) "; - format-disconnected = "Disconnected "; - tooltip = true; - tooltip-format-wifi = "{ipaddr}/{cidr}"; - }; - - temperature = { - hwmon-path = "/sys/class/hwmon/hwmon0/temp1_input"; - format = "{temperatureC} °C "; - }; - - backlight = { - format = "{percent}% {icon}"; - format-icons = [ "" "" ]; - }; - - pulseaudio = { - format = "{volume}% {icon}"; - format-bluetooth = "{volume}% {icon}"; - format-muted = ""; - format-icons = { - headphones = ""; - handsfree = ""; - headset = ""; - phone = ""; - portable = ""; - car = ""; - default = [ "" "" ]; - }; - on-click = "pavucontrol"; - }; - }]; - - style = with config.theme.colors; '' - * { - border: none; - border-radius: 0; - font-family: mono; - font-size: 11px; - min-height: 0; - } - - window#waybar { - background: ${background}; - border-bottom: 3px solid ${lightBackground}; - color: ${foreground}; - } - - /* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect */ - #workspaces button { - padding: 0 5px; - background: transparent; - color: ${foreground}; - border-bottom: 3px solid transparent; - } - - #workspaces button.focused { - background: ${dominant}; - border-bottom: 3px solid ${foreground}; - } - - #mode { - background: ${lightBackground}; - border-bottom: 3px solid ${foreground}; - } - - #clock, #battery, #cpu, #memory, #temperature, #backlight, #network, #pulseaudio, #custom-mpd, #mpd, #tray, #mode, #custom-notification { - padding: 0 10px; - margin: 0 5px; - } - - #clock { - background-color: ${neutralMagenta}; - color: ${background}; - } - - #battery { - background-color: ${neutralYellow}; - color: ${background}; - } - - /* - #battery.charging { - color: ${foreground}; - background-color: #26A65B; - } - */ - - @keyframes blink { - to { - background-color: ${foreground}; - color: ${background}; - } - } - - #battery.critical:not(.charging) { - background: ${fadedRed}; - color: ${foreground}; - animation-name: blink; - animation-duration: 0.5s; - animation-timing-function: linear; - animation-iteration-count: infinite; - animation-direction: alternate; - } - - #cpu { - background: ${neutralOrange}; - color: ${background}; - } - - #memory { - background: ${brightBlue}; - color: ${background}; - } - - #backlight { - background: ${background6}; - color: ${background}; - } - - #network { - background: ${neutralGreen}; - color: ${background}; - } - - #network.disconnected { - background: ${lightBackground}; - color: ${foreground}; - } - - #pulseaudio { - background: ${neutralCyan}; - color: ${background}; - } - - #pulseaudio.muted { - background: ${foreground}; - } - - #temperature { - background: ${brightCyan}; - color: ${background}; - } - - #temperature.critical { - background: ${fadedRed}; - color: ${foreground}; - } - - #tray { - background-color: #2980b9; - } - - #custom-notification { - color: ${background}; - background-color: ${foreground}; - } - - #custom-notification.inhibited-notification, - #custom-notification.inhibited-none, - #custom-notification.dnd-inhibited-notification, - #custom-notification.dnd-inhibited-none { - color: ${foreground}; - background-color: ${lightBackground}; - } - - #custom-mpd { - background-color: ${dominant}; - } - - #mpd { - background: ${dominant}; - } - - #mpd.disconnected { - background: ${lightBackground}; - color: ${foreground}; - } - - #mpd.stopped { - background: ${foreground}; - color: ${background}; - } - - #mpd.paused { - background: ${dimDominant}; - } - ''; - - systemd.enable = true; - }; + config = lib.mkIf cfg.enable { + home-manager.users.minijackson = { + programs.waybar = { + enable = true; + + settings = [ + { + layer = "top"; + position = "bottom"; + height = 25; + + gtk-layer-shell = true; + + modules-left = [ + "sway/workspaces" + "sway/mode" + ]; + modules-center = lib.mkIf config.services.mpd.enable [ "mpd" ]; + modules-right = [ + "custom/notification" + "pulseaudio" + "network#eth" + "network#wlan" + "cpu" + "memory" + "temperature" + "backlight" + "battery" + "clock" + "tray" + ]; + + mpd = lib.mkIf config.services.mpd.enable { + format = "{stateIcon} {consumeIcon}{randomIcon}{repeatIcon}{singleIcon}{artist} - {album} - {title} ({elapsedTime:%M:%S}/{totalTime:%M:%S}) "; + format-stopped = "{consumeIcon}{randomIcon}{repeatIcon}{singleIcon}Stopped "; + format-disconnected = "Disconnected "; + + on-click-middle = "${pkgs.alacritty}/bin/alacritty --command ncmpcpp"; + + consume-icons = { + on = " "; + }; + + random-icons = { + on = " "; + }; + + repeat-icons = { + on = " "; + }; + + single-icons = { + on = "1 "; + }; + + state-icons = { + playing = ""; + paused = ""; + }; + }; + + "custom/notification" = + let + swaync-client = "${lib.getBin config.home-manager.users.minijackson.services.swaync.package}/bin/swaync-client"; + in + { + format = "{icon}"; + format-icons = { + notification = "󰂜"; + none = "󰂜"; + dnd-notification = "󰪑"; + dnd-none = "󰪑"; + inhibited-notification = "󰂜"; + inhibited-none = "󰂜"; + dnd-inhibited-notification = "󰪑"; + dnd-inhibited-none = "󰪑"; + }; + tooltip = false; + return-type = "json"; + exec = "${swaync-client} -swb"; + on-click = "${swaync-client} -t -sw"; + on-click-right = "${swaync-client} -d -sw"; + escape = true; + }; + + clock = { + tooltip-format = "{:%Y-%m-%d | %H:%M}"; + format-alt = "{:%Y-%m-%d}"; + }; + + cpu = { + format = "{usage}% "; + }; + + memory = { + format = "{}% "; + }; + + battery = { + states = { + good = 90; + }; + format = "{capacity}% {icon}"; + format-icons = [ + "" + "" + "" + "" + "" + ]; + }; + + "network#eth" = { + interface = "enp*"; + format-ethernet = "{ipaddr}/{cidr} "; + format-disconnected = "Disconnected "; + }; + + "network#wlan" = { + interface = "wlp*"; + format-wifi = "{essid} ({signalStrength}%) "; + format-disconnected = "Disconnected "; + tooltip = true; + tooltip-format-wifi = "{ipaddr}/{cidr}"; + }; + + temperature = { + hwmon-path = "/sys/class/hwmon/hwmon0/temp1_input"; + format = "{temperatureC} °C "; + }; + + backlight = { + format = "{percent}% {icon}"; + format-icons = [ + "" + "" + ]; + }; + + pulseaudio = { + format = "{volume}% {icon}"; + format-bluetooth = "{volume}% {icon}"; + format-muted = ""; + format-icons = { + headphones = ""; + handsfree = ""; + headset = ""; + phone = ""; + portable = ""; + car = ""; + default = [ + "" + "" + ]; + }; + on-click = "pavucontrol"; + }; + } + ]; - # Fix https://github.com/nix-community/home-manager/pull/1628 - systemd.user.services.waybar.Unit = { - Requisite = lib.mkForce []; - After = lib.mkForce []; + style = with config.theme.colors; '' + * { + border: none; + border-radius: 0; + font-family: mono; + font-size: 11px; + min-height: 0; + } + + window#waybar { + background: ${background}; + border-bottom: 3px solid ${lightBackground}; + color: ${foreground}; + } + + /* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect */ + #workspaces button { + padding: 0 5px; + background: transparent; + color: ${foreground}; + border-bottom: 3px solid transparent; + } + + #workspaces button.focused { + background: ${dominant}; + border-bottom: 3px solid ${foreground}; + } + + #mode { + background: ${lightBackground}; + border-bottom: 3px solid ${foreground}; + } + + #clock, #battery, #cpu, #memory, #temperature, #backlight, #network, #pulseaudio, #custom-mpd, #mpd, #tray, #mode, #custom-notification { + padding: 0 10px; + margin: 0 5px; + } + + #clock { + background-color: ${neutralMagenta}; + color: ${background}; + } + + #battery { + background-color: ${neutralYellow}; + color: ${background}; + } + + /* + #battery.charging { + color: ${foreground}; + background-color: #26A65B; + } + */ + + @keyframes blink { + to { + background-color: ${foreground}; + color: ${background}; + } + } + + #battery.critical:not(.charging) { + background: ${fadedRed}; + color: ${foreground}; + animation-name: blink; + animation-duration: 0.5s; + animation-timing-function: linear; + animation-iteration-count: infinite; + animation-direction: alternate; + } + + #cpu { + background: ${neutralOrange}; + color: ${background}; + } + + #memory { + background: ${brightBlue}; + color: ${background}; + } + + #backlight { + background: ${background6}; + color: ${background}; + } + + #network { + background: ${neutralGreen}; + color: ${background}; + } + + #network.disconnected { + background: ${lightBackground}; + color: ${foreground}; + } + + #pulseaudio { + background: ${neutralCyan}; + color: ${background}; + } + + #pulseaudio.muted { + background: ${foreground}; + } + + #temperature { + background: ${brightCyan}; + color: ${background}; + } + + #temperature.critical { + background: ${fadedRed}; + color: ${foreground}; + } + + #tray { + background-color: #2980b9; + } + + #custom-notification { + color: ${background}; + background-color: ${foreground}; + } + + #custom-notification.inhibited-notification, + #custom-notification.inhibited-none, + #custom-notification.dnd-inhibited-notification, + #custom-notification.dnd-inhibited-none { + color: ${foreground}; + background-color: ${lightBackground}; + } + + #custom-mpd { + background-color: ${dominant}; + } + + #mpd { + background: ${dominant}; + } + + #mpd.disconnected { + background: ${lightBackground}; + color: ${foreground}; + } + + #mpd.stopped { + background: ${foreground}; + color: ${background}; + } + + #mpd.paused { + background: ${dimDominant}; + } + ''; + + systemd.enable = true; + }; + + # Fix https://github.com/nix-community/home-manager/pull/1628 + systemd.user.services.waybar.Unit = { + Requisite = lib.mkForce [ ]; + After = lib.mkForce [ ]; + }; }; }; } -- cgit v1.2.3