From ff3198ee65f1c217d51be133816a76c0648afcd7 Mon Sep 17 00:00:00 2001 From: brustybee Date: Sat, 7 Mar 2026 05:04:20 +0530 Subject: Add waybar and scripts --- common/modules/mango/default.nix | 2 + common/modules/mango/scripts.nix | 77 ++++++ common/modules/mango/waybar.nix | 514 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 593 insertions(+) create mode 100644 common/modules/mango/scripts.nix create mode 100644 common/modules/mango/waybar.nix (limited to 'common') diff --git a/common/modules/mango/default.nix b/common/modules/mango/default.nix index b5332a4..c7634e9 100644 --- a/common/modules/mango/default.nix +++ b/common/modules/mango/default.nix @@ -42,6 +42,8 @@ in if homeManager then [ inputs.mango.hmModules.mango + ./waybar.nix + ./scripts.nix ] else [ diff --git a/common/modules/mango/scripts.nix b/common/modules/mango/scripts.nix new file mode 100644 index 0000000..b3de75d --- /dev/null +++ b/common/modules/mango/scripts.nix @@ -0,0 +1,77 @@ +{ pkgs, ... }: +let + # CHANGED: writeShellScript -> writeShellScriptBin + volume-control = pkgs.writeShellScriptBin "volume-control" '' + TAG="audio-volume" + + function get_vol { + ${pkgs.wireplumber}/bin/wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{print int($2 * 100)}' + } + + case $1 in + up) ${pkgs.wireplumber}/bin/wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 5%+ ;; + down) ${pkgs.wireplumber}/bin/wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- ;; + mute) ${pkgs.wireplumber}/bin/wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle ;; + esac + + vol=$(get_vol) + is_muted=$(${pkgs.wireplumber}/bin/wpctl get-volume @DEFAULT_AUDIO_SINK@ | grep "MUTED") + + if [ -n "$is_muted" ]; then + ${pkgs.dunst}/bin/dunstify -a "Volume" -u low \ + -h string:x-canonical-private-synchronous:$TAG \ + "Volume: Muted" + else + ${pkgs.dunst}/bin/dunstify -a "Volume" -u low \ + -h string:x-canonical-private-synchronous:$TAG \ + -h int:value:"$vol" \ + "Volume: $vol%" + fi + ''; + + # CHANGED: writeShellScript -> writeShellScriptBin + brightness-control = pkgs.writeShellScriptBin "brightness-control" '' + TAG="screen-brightness" + + case $1 in + up) ${pkgs.brightnessctl}/bin/brightnessctl set +5% ;; + down) ${pkgs.brightnessctl}/bin/brightnessctl set 5%- ;; + esac + + # Get current percentage + current=$(${pkgs.brightnessctl}/bin/brightnessctl info | grep -oP '\(\K[0-9]+(?=%\))') + + ${pkgs.dunst}/bin/dunstify -a "Brightness" -u low \ + -h string:x-canonical-private-synchronous:$TAG \ + -h int:value:"$current" \ + "Brightness: $current%" + ''; + + # CHANGED: writeShellScript -> writeShellScriptBin + mic-control = pkgs.writeShellScriptBin "mic-control" '' + TAG="audio-mic" + + case $1 in + toggle) ${pkgs.wireplumber}/bin/wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle ;; + esac + + is_muted=$(${pkgs.wireplumber}/bin/wpctl get-volume @DEFAULT_AUDIO_SOURCE@ | grep "MUTED") + + if [ -n "$is_muted" ]; then + ${pkgs.dunst}/bin/dunstify -a "Microphone" -u low \ + -h string:x-canonical-private-synchronous:$TAG \ + "Microphone: Muted" + else + ${pkgs.dunst}/bin/dunstify -a "Microphone" -u low \ + -h string:x-canonical-private-synchronous:$TAG \ + "Microphone: On" + fi + ''; +in +{ + home.packages = [ + volume-control + brightness-control + mic-control + ]; +} diff --git a/common/modules/mango/waybar.nix b/common/modules/mango/waybar.nix new file mode 100644 index 0000000..f1e6712 --- /dev/null +++ b/common/modules/mango/waybar.nix @@ -0,0 +1,514 @@ +{ pkgs, config, ... }: +let + screenshot = pkgs.writeShellScript "screenshot" '' + GEOM=$(${pkgs.slurp}/bin/slurp -b '#2E2A1E55' -c '#fb751bff') || exit + ${pkgs.grim}/bin/grim -g "$GEOM" -t ppm - | ${pkgs.satty}/bin/satty --filename - + ''; +in +{ + programs.waybar = { + enable = config.beeMods.mango.waybar; + + settings = { + mainBar = { + layer = "top"; + position = "top"; + exclusive = true; + passthrough = false; + gtk-layer-shell = true; + ipc = false; + reload_style_on_change = true; + height = 35; + + modules-left = [ + "dwl/tags" + "wlr/taskbar" + "dwl/window" + ]; + + modules-center = [ + "mpris" + ]; + + modules-right = [ + "tray" + "power-profiles-daemon" + "network" + "group/hardware" + "upower" + "clock" + "custom/power" + ]; + + "group/hardware" = { + orientation = "horizontal"; + modules = [ + "pulseaudio" + "pulseaudio#microphone" + "cpu" + "backlight" + ]; + }; + + "dwl/tags" = { + num-tags = 9; + hide-vacant = true; + # tag-labels = ["一" "二" "三" "四" "五" "六" "七" "八" "九"]; + }; + + "dwl/window" = { + format = "[{layout}]{title}"; + on-click = "${screenshot}"; + }; + + cpu = { + interval = 2; + format = " {load}%"; + }; + + "wlr/taskbar" = { + format = "{icon}"; + icon-size = 22; + all-outputs = false; + tooltip-format = "{title}"; + markup = true; + on-click = "activate"; + on-click-right = "close"; + ignore-list = [ + "Rofi" + "wofi" + ]; + }; + + backlight = { + interval = 2; + format = "{icon} {percent}%"; + format-icons = [ + "󰖔" + "󰖨" + ]; + on-scroll-up = "brightnessctl set +1%"; + on-scroll-down = "brightnessctl set 1%-"; + smooth-scrolling-threshold = 1; + }; + + idle_inhibitor = { + tooltip = false; + format = "{icon}"; + start-activated = false; + format-icons = { + activated = " "; + deactivated = " "; + }; + }; + + tray = { + interval = 1; + icon-size = 21; + spacing = 10; + }; + + network = { + interval = 2; + format-wifi = "{essid} ({signalStrength}%) \uf1eb "; + format-ethernet = "󰈀 {ifname}"; + format-linked = "\uf059 No IP ({ifname})"; + format-disconnected = "\uf071 Disconnected"; + tooltip-format = "{ifname} {ipaddr}/{cidr} via {gwaddr}"; + format-alt = "↓{bandwidthDownBytes} ↑{bandwidthUpBytes}"; + }; + + clock = { + format = "{:%H:%M} "; + format-alt = "{:%A, %b %d} "; + tooltip-format = "{:%Y}"; + calendar = { + mode = "year"; + mode-mon-col = 3; + weeks-pos = "right"; + on-scroll = 1; + format = { + months = "{}"; + days = "{}"; + weeks = "W{}"; + weekdays = "{}"; + today = "{}"; + }; + }; + }; + + pulseaudio = { + format = "{icon} {volume}%"; + tooltip = false; + format-muted = " Muted"; + format-bluetooth = " {volume}%"; + format-bluetooth-muted = " Muted"; + on-click = "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle"; + on-scroll-up = "wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 2%+"; + on-scroll-down = "wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 2%-"; + scroll-step = 5; + format-icons = { + headphone = ""; + hands-free = ""; + headset = ""; + phone = ""; + portable = ""; + car = ""; + default = [ + "" + "" + "" + ]; + }; + ignored-sinks = [ "Easy Effects Sink" ]; + }; + + "pulseaudio#microphone" = { + format = "{format_source}"; + format-source = " {volume}%"; + tooltip = false; + format-source-muted = " Muted"; + on-click = "wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle"; + on-scroll-up = "wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SOURCE@ 2%+"; + on-scroll-down = "wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SOURCE@ 2%-"; + scroll-step = 5; + }; + + "custom/power" = { + format = ""; + tooltip = false; + on-click = "wlogout -C ~/.config/wlogout/style.css -l ~/.config/wlogout/layout -b 6 --protocol layer-shell"; + }; + + power-profiles-daemon = { + format = "{icon}"; + tooltip-format = "Power profile: {profile}\nDriver: {driver}"; + tooltip = true; + format-icons = { + default = " "; + performance = " "; + balanced = " "; + power-saver = " "; + }; + }; + + mpris = { + format = "{player_icon} {title} - {artist}"; + format-paused = "{status_icon} {title} - {artist}"; + format-stopped = ""; + max-length = 45; + ellipsis = true; + tooltip = false; + playerctld = false; + player-icons = { + default = ""; + spotify = ""; + firefox = ""; + mpv = ""; + }; + status-icons = { + paused = ""; + playing = ""; + }; + on-click = "playerctl play-pause"; + on-click-right = "playerctl next"; + on-click-middle = "playerctl previous"; + on-scroll-up = "wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 2%+"; + on-scroll-down = "wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 2%-"; + }; + + cava = { + framerate = 60; + autosens = 0; + bars = 8; + lower_cutoff_freq = 50; + higher_cutoff_freq = 12000; + method = "pipewire"; + hide_on_silence = true; + sleep_timer = 5; + source = "auto"; + stereo = false; + reverse = false; + bar_delimiter = 0; + monstercat = false; + waves = false; + noise_reduction = 0.77; + input_delay = 0; + format-icons = [ + "▁" + "▂" + "▃" + "▄" + "▅" + "▆" + "▇" + "█" + ]; + actions = { + on-click-right = "mode"; + }; + }; + + upower = { + icon-size = 18; + hide-if-empty = true; + tooltip = true; + tooltip-spacing = 20; + format = "{percentage}"; + }; + }; + }; + + # The style attribute manages style.css natively + style = '' + * { + border: none; + font-family: "JetBrainsMono Nerd Font", monospace; + font-weight: 700; + font-size: 14px; + min-height: 0; + } + + window#waybar { + background: none; + margin: 0px; + padding: 0px; + } + + ${ + if config.beeMods.matugen.enable then + ''@import url("colors.css");'' + else + ''@import url("colors-default.css");'' + } + + tooltip { + background: @bg_panel; + border-radius: 0px; + border-width: 2px; + border-style: solid; + border-color: @border_color; + color: @text_main; + } + + #window, + #taskbar, + #tags, + #workspaces, + #mpris, + #clock, + #upower, + #network, + #tray, + #cava, + #custom-power, + #power-profiles-daemon, + #hardware { + background: @bg_panel; + color: @text_main; + padding: 0px 8px; + margin: 0px; + margin-top: 1px; + margin-bottom: 0px; + border-width: 2px; + border-style: solid; + border-color: @border_color; + border-radius: 0px; + } + + #workspaces button, + #tags button { + border: none; + background: none; + box-shadow: inherit; + text-shadow: inherit; + padding: 1px 3px; + } + + #workspaces button:hover, + #tags button:hover { + color: @text_accent; + } + + + #workspaces button.active, + #tags button.focused, + #taskbar button.active { + background-color: @text_main; + } + + #workspaces button.urgent, + #tags button.urgent { + background-color: @alert_urgent; + } + + #taskbar button.urgent { + background-color: @alert_critical; + } + + #taskbar button.minimized { + background-color: @alert_minimized; + } + + #taskbar button.active, + #taskbar button.urgent, + #taskbar button.minimized { + padding-left: 3px; + padding-right: 3px; + } + + #hardware { + padding: 0px; + margin-right: 4px; + } + + #hardware > widget > * { + padding: 0px 8px; + } + + #workspaces { + margin-left: 4px; + padding-left: 10px; + padding-right: 6px; + } + + #workspaces button { + color: @text_main; + margin-right: 2px; + margin-left: 2px; + } + + #workspaces button.hidden { + color: @text_muted; + background-color: transparent; + } + + #workspaces button.visible { + color: @text_main; + } + + #tags { + margin-left: 5px; + padding-left: 6px; + padding-right: 6px; + } + + #taskbar button { + color: @text_dim; + margin: 2px; + padding: 0px 3px; + border-radius: 0px; + background: transparent; + } + + #tags button:not(.occupied):not(.focused):not(.overview):not(.urgent) { + font-size: 0; + min-width: 0; + min-height: 0; + margin: -17px; + padding: 0; + color: transparent; + background-color: transparent; + } + + #tags button.occupied, + #tags button.overview { + color: @text_main; + } + + #tray { + margin-right: 4px; + margin-left: 4px; + padding: 0px 9px 0px 9px; + } + + #power-profiles-daemon, + #network { + margin-right: 4px; + padding: 0px 8px 0px 9px; + } + + #window { + margin-right: 10px; + } + + #taskbar { + margin-left: 10px; + margin-right: 10px; + } + + #taskbar.empty { + margin: 0px; + padding-left: 10px; + padding-right: 0px; + border-color: transparent; + border: none; + background-color: transparent; + } + + #taskbar button { + margin-right: 3px; + } + + #mpris { + margin-left: 4px; + } + + #cava { + margin-left: 4px; + } + + #clock { + border-right: 2px; + } + + #upower { + margin-right: 4px; + } + + #custom-power { + border-left: 0px; + margin-left: 0px; + margin-right: 5px; + padding-right: 14px; + } + + #workspaces button.active, + #workspaces button.urgent, + #tags button.focused, + #tags button.urgent, + #taskbar button.active, + #taskbar button.urgent, + #taskbar button.minimized { + color: @text_dark; + margin-top: 2px; + margin-bottom: 2px; + padding-top: 0px; + padding-bottom: 0px; + border-radius: 0px; + } + ''; + }; + + xdg.configFile = { + "waybar/colors-default.css" = { + enable = !config.beeMods.matugen.enable; + text = + # css + '' + @define-color bg_panel alpha(#131313, 0.9); + @define-color bg_base transparent; + @define-color border_color #ffffff; + @define-color text_main #ffffff; + @define-color text_muted #ffffff; + @define-color text_dim #ffffff; + @define-color text_accent #ffffff; + @define-color text_dark #353535; + @define-color alert_urgent #ffb4ab; + @define-color alert_minimized #93000a; + @define-color alert_critical #ffdad6; + + ''; + }; + }; +} -- cgit v1.3.1