From e38480e32026c43c74e8f669d1fd000ab434ab98 Mon Sep 17 00:00:00 2001 From: Thomas Syms Date: Mon, 6 Oct 2025 12:08:32 -0300 Subject: [PATCH] feat: enhance Waybar configuration for Sway/Hyprland with improved module settings and autostart functionality --- .../common/optional/desktops/niri/waybar.nix | 196 +++++++++++++++--- 1 file changed, 167 insertions(+), 29 deletions(-) diff --git a/home/panotaka/common/optional/desktops/niri/waybar.nix b/home/panotaka/common/optional/desktops/niri/waybar.nix index 98ab2a6..5b3a1ac 100644 --- a/home/panotaka/common/optional/desktops/niri/waybar.nix +++ b/home/panotaka/common/optional/desktops/niri/waybar.nix @@ -1,5 +1,21 @@ -{pkgs, ...}: let - waybarStyle = ''* { color: #ffffff; }''; +{ + pkgs, + config, + ... +}: let + # Safely access system-level stylix targets (may not always be present during some checks) + stylixTargets = + if config.stylix != null && config.stylix ? targets + then config.stylix.targets + else {}; + waybarOut = + if stylixTargets ? waybar && stylixTargets.waybar ? stylixTargets.waybar.outPath + then stylixTargets.waybar.outPath + else null; + colors = + if config.lib != null && config.lib.stylix != null && config.lib.stylix.colors != null + then config.lib.stylix.colors + else {base05 = "ffffff";}; in { # Use the programs.waybar home-manager module programs.waybar = { @@ -7,48 +23,170 @@ in { package = pkgs.waybar; systemd.enable = true; - # Minimal config as a Nix attribute set; users can override ~/.config/waybar/config if desired + # Waybar settings tailored for sway/hyprland-style setups settings = { mainBar = { layer = "top"; position = "top"; - modules-left = ["niri/workspaces"]; - modules-center = []; - modules-right = ["tray" "clock"]; + height = 35; + spacing = 4; - "niri/workspaces" = { - format = "{name}"; + # Add a placeholder for your window manager's workspace module + # For Sway/Hyprland: "sway/workspaces" or "hyprland/workspaces" + modules-left = ["sway/workspaces" "sway/mode"]; + modules-center = ["sway/window"]; + modules-right = [ + "bluetooth" + "network" + "pipewire" + "tray" + "battery" + "clock" + ]; + + # --- Module Definitions --- + "sway/workspaces" = { + disable-scroll = true; + all-outputs = true; + format = "{name}: {icon}"; + format-icons = { + "1" = ""; + "2" = ""; + "3" = ""; + "focused" = ""; + "default" = ""; + }; }; clock = { - format = "{:%H:%M}"; - tooltip-format = "{:%Y %B}\n{calendar}"; + format = " {:%I:%M %p}"; + tooltip-format = "{:%A, %B %d, %Y}\n{calendar}"; + }; + + tray = { + "icon-size" = 18; + spacing = 10; + }; + + pipewire = { + format = "{icon} {volume}%"; + format-muted = "󰖁 Muted"; + format-icons = { + "default" = ["󰕿" "󰖀" "󰕾"]; + }; + # Native PipeWire control using wpctl + on-click = "${pkgs.pavucontrol}/bin/pavucontrol"; + on-click-right = "wpctl set-mute @DEFAULT_SINK@ toggle"; + on-scroll-up = "wpctl set-volume @DEFAULT_SINK@ +5%"; + on-scroll-down = "wpctl set-volume @DEFAULT_SINK@ -5%"; + scroll-step = 5; + }; + + network = { + format-wifi = "󰖩 {essid}"; + format-ethernet = "󰈀 Wired"; + format-disconnected = "󰖪 Off"; + on-click = "nm-connection-editor"; + }; + + # Battery module (uses sysfs/upower depending on system) + battery = { + format = "{capacity}% {icon}"; + tooltip = true; + format-icons = { + "discharging" = ""; # low battery icon + "charging" = ""; # charging icon + "full" = ""; + }; + }; + + bluetooth = { + format = "󰂯 {status}"; + format-disabled = "󰂲 Off"; + format-connected = "󰂱 {device_alias}"; + on-click = "blueman-manager"; }; }; }; - # Minimal CSS; consider generating this from config.lib.stylix.colors for richer theming - style = waybarStyle; + # Use Stylix-generated CSS as a base and override icon/text color to a monochrome value + style = let + importLine = + if waybarOut != null + then ''@import "${toString waybarOut}";'' + else ''/* stylix waybar target not available */''; + in + with colors; '' + /* Import the CSS generated by Stylix for Waybar (if available) */ + ${importLine} + + /* Override the color for common modules to a single monochrome color */ + #workspaces button label, + #taskbar button label, + #clock, + #tray, + #network, + #pulseaudio, + #battery { + color: #${base05}; + } + + /* Fallback: target all labels */ + label { + color: #${base05}; + } + + /* Prefer a single icon font for consistent monochrome icons */ + * { + font-family: "JetBrainsMono Nerd Font", sans-serif; + } + ''; }; # The config file is generated automatically by programs.waybar, so we don't need manual file writes # Users can override by setting programs.waybar.settings directly in their config - # Make sure nm-applet is available and autostarts so its tray icon shows up in the tray module - home.packages = with pkgs; [networkmanagerapplet]; + # Keep GUI helper packages but don't autostart applets here. + # We prefer Waybar modules (network/pipewire/bluetooth/battery) as the primary + # UI so users don't get duplicate tray icons. GUI tools are still available + # via `home.packages` and the Waybar on-click actions (pavucontrol, nm-connection-editor, + # blueman-manager) will launch them when needed. + home.packages = with pkgs; [networkmanagerapplet blueman pavucontrol pasystray]; - # Start nm-applet as a systemd user service for UWSM integration - systemd.user.services.nm-applet = { - Unit = { - Description = "Network Manager Applet"; - PartOf = ["graphical-session.target"]; - After = ["graphical-session.target"]; - }; - Service = { - ExecStart = "${pkgs.networkmanagerapplet}/bin/nm-applet"; - Restart = "on-failure"; - }; - Install = { - WantedBy = ["graphical-session.target"]; - }; - }; + # Hide the nm-applet and blueman tray icons by overriding their icon entries + # in the user's icon theme with a transparent SVG. This lets the applets run + # (providing background/autoconnect and secret-service integration) while Waybar + # provides the visible UI with nicer icons. + home.file."${config.home.homeDirectory}/.local/share/icons/hicolor/scalable/status/nm-applet.svg".text = '' + + ''; + + home.file."${config.home.homeDirectory}/.local/share/icons/hicolor/scalable/status/network-wireless.svg".text = '' + + ''; + + home.file."${config.home.homeDirectory}/.local/share/icons/hicolor/scalable/status/blueman.svg".text = '' + + ''; + + # Autostart the applets so they provide background/network/keyring integration + # while their icons remain hidden (Waybar shows the label/text UI). + home.file."${config.home.homeDirectory}/.config/autostart/nm-applet.desktop".text = '' + [Desktop Entry] + Type=Application + Exec=${pkgs.networkmanagerapplet}/bin/nm-applet + Hidden=false + X-GNOME-Autostart-enabled=true + Name=Network Manager Applet + Comment=Autostart nm-applet for network management + ''; + + home.file."${config.home.homeDirectory}/.config/autostart/blueman-manager.desktop".text = '' + [Desktop Entry] + Type=Application + Exec=${pkgs.blueman}/bin/blueman-applet + Hidden=false + X-GNOME-Autostart-enabled=true + Name=Blueman Applet + Comment=Autostart blueman for bluetooth management + ''; }