NixOS-Config/modules/home/wms/programs/waybar/default.nix

450 lines
12 KiB
Nix
Raw Normal View History

2024-10-15 02:40:43 -04:00
{ pkgs, config, ... }:
2024-10-09 03:36:08 -04:00
{
2024-08-24 22:16:51 -04:00
programs.waybar = let
swayWorkspaceModule = {
2024-08-24 22:16:51 -04:00
format = "{name}";
enable-bar-scroll = true;
warp-on-scroll = false;
disable-scroll-wraparound = true;
};
swayWindowsModule = {
icon = true;
icon-size = 15;
all-outputs = true;
2024-08-24 22:16:51 -04:00
tooltip = false;
rewrite = {
"(.*) LibreWolf" = " $1";
"LibreWolf" = " Firefox";
"(.*) - LibreWolf Firefox" = "󰗃 $1";
};
};
pulseModule = {
format = "{icon} {volume}%";
format-bluetooth = "{icon} {volume}%";
format-muted = " muted";
format-icons = {
headphone = "󰋋 ";
headset = "󰋋 ";
default = [ " " " " ];
2024-08-24 22:16:51 -04:00
};
on-click = "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle";
on-click-middle = "wpctl set-volume @DEFAULT_AUDIO_SINK@ 100%";
on-click-right = "wpctl set-volume @DEFAULT_AUDIO_SINK@ 60%";
ignored-sinks = [
"Easy Effects Sink"
"USB FS AUDIO Analog Stereo"
];
2024-08-24 22:16:51 -04:00
};
# CPU, Ram and Vram
cpuModule = {
format = " {usage}%";
interval = 3;
};
ramModule = {
format = " {used}G";
tooltip = false;
interval = 3;
2024-08-24 22:16:51 -04:00
};
vramModule = {
exec = pkgs.writeScript "vramScript" ''
# Don't run the script if running on integrated graphics
gpu_driver=$(${pkgs.pciutils}/bin/lspci -k | grep -Eo "in use: (nvidia|amdgpu)" | awk '{print $3}')
2024-08-24 22:16:51 -04:00
if [ -n "$gpu_driver" ]; then
if [ "$gpu_driver" == "nvidia" ]; then
2024-08-24 22:16:51 -04:00
vram_usage_mb=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits)
temperature=$(nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits)
elif [ "$gpu_driver" == "amdgpu" ]; then
2024-08-24 22:16:51 -04:00
vram_usage_mb=$(echo "$(cat /sys/class/drm/card0/device/mem_info_vram_used || cat /sys/class/drm/card1/device/mem_info_vram_used) / 1024 / 1024" | bc)
temperature=$(${pkgs.lm_sensors}/bin/sensors | grep 'edge' | awk '{print $2}' | sed 's/[^0-9.-]//g')
2024-08-24 22:16:51 -04:00
fi
# Check if VRAM usage is under 1GB
if [ $vram_usage_mb -lt 1024 ]; then
vram_usage_display="$(echo $vram_usage_mb)M"
else
# Convert MB to GiB
vram_usage_gib=$(bc <<< "scale=2; $vram_usage_mb / 1024")
vram_usage_display="$(echo $vram_usage_gib)G"
fi
# Print the VRAM usage and temperature
echo "{\"text\":\"󰢮 $(echo $vram_usage_display)\",\"tooltip\":\"$(echo $temperature)°C\"}"
2024-08-24 22:16:51 -04:00
fi
'';
format = "{}";
return-type = "json";
interval = 3;
};
# Clocks
longClockModule = {
exec = pkgs.writeScript "longClock" ''
time=$(date +'%a %b %d %l:%M:%S%p' | tr -s ' ')
date=$(date "+%Y-%m-%d")
echo "{\"text\":\" $time\",\"tooltip\":\"$date\"}"
'';
on-click = ''wl-copy $(date "+%Y-%m-%d-%H%M%S"); notify-send "Date copied."'';
format = "{}";
return-type = "json";
interval = 1;
tooltip = true;
};
shortClockModule = {
exec = "echo ' '$(date +'%l:%M%p' | sed 's/^ //')";
on-click = ''wl-copy $(date "+%Y-%m-%d-%H%M%S"); notify-send "Date copied."'';
interval = 60;
tooltip = false;
};
# Tray, gamemode, bluetooth, and network tray modules
trayModule.spacing = 5;
2024-08-24 22:16:51 -04:00
networkModule = {
format-ethernet = "󰈀";
format-wifi = "";
format-disconnected = "󰖪";
format-linked = "";
tooltip-format-ethernet = "{ipaddr}\n{ifname} ";
tooltip-format-wifi = "{ipaddr}\n{essid} ({signalStrength}%)";
tooltip-format-disconnected = "Disconnected";
};
bluetoothModule = {
format = "";
format-disabled = "";
format-no-controller = "";
tooltip-format-on = "No devices connected.";
tooltip-format-connected = "{num_connections} connected\n{device_enumerate}";
tooltip-format-enumerate-connected = "{device_alias}";
tooltip-format-enumerate-connected-battery = "{device_alias} {device_battery_percentage}%";
on-click = "rofi-bluetooth";
};
scratchpadModule = {
format = " {count}";
show-empty = false;
tooltip = true;
tooltip-format = "{title}";
};
gamemodeModule = {
format = "{glyph}";
glyph = "󰖺";
hide-not-running = true;
use-icon = true;
icon-spacing = 3;
icon-size = 19;
tooltip = true;
tooltip-format = "Gamemode On";
};
# Special per-bar modules
mediaModule = {
format = " {title}";
format-paused = " {artist}";
format-stopped = "";
format-disconnected = "";
tooltip-format = "{artist} - {title}";
2024-08-24 22:16:51 -04:00
interval = 2;
max-length = 30;
on-click = "mpc toggle";
};
notificationModule = {
exec = pkgs.writeScript "notificationScript" ''
# Run makoctl mode and store the output in a variable
mode_output=$(makoctl mode)
# Extract the second line after "default"
mode_line=$(echo "$mode_output" | sed -n '/default/{n;p}')
# Print the notification status with the tooltip
if [[ "$mode_line" == "do-not-disturb" ]]; then
printf '{"text":"󱆥 Off","class":"disabled","tooltip":"Notifications Disabled."}'
else
printf '{"text":" On","tooltip":"Notifications Enabled."}';
fi
'';
format = "{}";
return-type = "json";
interval = 2;
on-click = "makotoggle";
};
weatherModule = {
exec = "${pkgs.wttrbar}/bin/wttrbar --ampm";
format = "{}°";
tooltip = true;
2024-08-24 22:16:51 -04:00
return-type = "json";
interval = 3600;
2024-08-24 22:16:51 -04:00
};
# Laptop modules
backlightModule = {
format = "{icon} {percent}%";
format-icons = [ "" "󰖨" ];
2024-08-24 22:16:51 -04:00
tooltip = false;
};
batteryModule = {
interval = 60;
states = {
warning = 30;
critical = 15;
};
format = "{icon} {capacity}%";
format-icons = [ "" "" "" "" "" ];
2024-08-24 22:16:51 -04:00
};
in {
enable = config.home.desktop.enable;
2024-08-24 22:16:51 -04:00
settings = {
display1 = {
name = "bar1";
position = "top";
layer = "bottom";
output = [
config.displays.d1
"VGA-1"
];
modules-left = [
"sway/workspaces"
"sway/window"
"niri/workspaces"
"niri/window"
];
2024-08-24 22:16:51 -04:00
modules-right = [
"pulseaudio"
"cpu"
"memory"
"custom/vram"
"custom/clock-long"
"gamemode"
"sway/scratchpad"
"tray"
"bluetooth"
"network"
];
"sway/workspaces" = swayWorkspaceModule;
2024-08-24 22:16:51 -04:00
"sway/window" = swayWindowsModule;
"niri/window" = swayWindowsModule;
2024-08-24 22:16:51 -04:00
"pulseaudio" = pulseModule;
"cpu" = cpuModule;
"memory" = ramModule;
"custom/vram" = vramModule;
"custom/clock-long" = longClockModule;
"gamemode" = gamemodeModule;
"sway/scratchpad" = scratchpadModule;
"tray" = trayModule;
"bluetooth" = bluetoothModule;
"network" = networkModule // { interface = "enp*"; };
2024-08-24 22:16:51 -04:00
};
display2 = {
name = "bar2";
position = "top";
layer = "bottom";
output = [ config.displays.d2 ];
modules-left = [
"sway/workspaces"
"sway/window"
"niri/workspaces"
"niri/window"
];
2024-08-24 22:16:51 -04:00
modules-right = [
"pulseaudio"
"mpd"
2024-08-24 22:16:51 -04:00
"custom/notifs"
"cpu"
"memory"
"custom/vram"
"custom/clock-long"
];
"sway/workspaces" = swayWorkspaceModule;
2024-08-24 22:16:51 -04:00
"sway/window" = swayWindowsModule;
"niri/window" = swayWindowsModule;
2024-08-24 22:16:51 -04:00
"pulseaudio" = pulseModule;
"mpd" = mediaModule;
2024-08-24 22:16:51 -04:00
"custom/notifs" = notificationModule;
"cpu" = cpuModule;
"memory" = ramModule;
"custom/vram" = vramModule;
"custom/clock-long" = longClockModule;
};
display3 = {
name = "bar3";
position = "top";
layer = "bottom";
output = [ config.displays.d3 ];
modules-left = [
"sway/workspaces"
"sway/window"
"niri/workspaces"
"niri/window"
];
2024-08-24 22:16:51 -04:00
modules-right = [
"pulseaudio"
"custom/weather"
"cpu"
"memory"
"custom/vram"
"custom/clock-short"
];
"sway/workspaces" = swayWorkspaceModule;
2024-08-24 22:16:51 -04:00
"sway/window" = swayWindowsModule;
"niri/window" = swayWindowsModule;
2024-08-24 22:16:51 -04:00
"pulseaudio" = pulseModule;
"custom/weather" = weatherModule;
"cpu" = cpuModule;
"memory" = ramModule;
"custom/vram" = vramModule;
"custom/clock-short" = shortClockModule;
};
displayLap = {
name = "laptop";
position = "top";
layer = "bottom";
output = [
"eDP-1"
"LVDS-1"
"DSI-1"
"HDMI-A-1"
];
modules-left = [
"sway/workspaces"
"sway/window"
"niri/workspaces"
"niri/window"
];
2024-08-24 22:16:51 -04:00
modules-right = [
"pulseaudio"
"mpd"
2024-08-24 22:16:51 -04:00
"custom/notifs"
"custom/weather2"
"cpu"
"memory"
"custom/vram"
"backlight"
"battery"
"custom/clock-long"
"gamemode"
"sway/scratchpad"
"tray"
"bluetooth"
"network"
];
"sway/workspaces" = swayWorkspaceModule;
2024-08-24 22:16:51 -04:00
"sway/window" = swayWindowsModule;
"niri/window" = swayWindowsModule;
2024-08-24 22:16:51 -04:00
"pulseaudio" = pulseModule;
"mpd" = mediaModule;
2024-08-24 22:16:51 -04:00
"custom/notifs" = notificationModule;
"custom/weather2" = weatherModule;
"cpu" = cpuModule;
"memory" = ramModule;
"custom/vram" = vramModule;
"backlight" = backlightModule;
"battery" = batteryModule;
"custom/clock-long" = longClockModule;
"sway/scratchpad" = scratchpadModule;
"tray" = trayModule;
"bluetooth" = bluetoothModule;
"network" = networkModule;
};
};
style = ''
* {
border: 0;
border-radius: 0;
min-height: 0;
2024-10-15 02:40:43 -04:00
font-family: ${config.look.fonts.main}, ${config.look.fonts.nerd};
2024-08-24 22:16:51 -04:00
font-size: 15.5px;
2024-10-15 02:40:43 -04:00
color: #${config.look.colors.text};
2024-08-24 22:16:51 -04:00
}
#waybar {
2024-10-15 02:40:43 -04:00
background: #${config.look.colors.dark};
2024-08-24 22:16:51 -04:00
}
#workspaces {
padding: 0 6px 0 0;
}
#tray {
padding: 0 2px 0 5px;
}
#network {
padding: 0 10px 0 4px;
}
#network.disconnected,#bluetooth.off {
color: #424242;
}
#bluetooth {
margin: 0 6px 0 4px;
font-size: 13.4px;
}
#workspaces button {
padding: 0 3px;
color: white;
border-bottom: 3px solid transparent;
min-width: 20px;
}
#workspaces button.visible, #workspaces button.active {
2024-10-15 02:40:43 -04:00
border-bottom: 3px solid #${config.look.colors.prime};
background: #${config.look.colors.mid};
2024-08-24 22:16:51 -04:00
}
#workspaces button.urgent {
2024-10-15 02:40:43 -04:00
border-bottom: 3px solid #${config.look.colors.urgent};
2024-08-24 22:16:51 -04:00
}
#workspaces button:hover {
box-shadow: none;
2024-10-15 02:40:43 -04:00
background: #${config.look.colors.light};
2024-08-24 22:16:51 -04:00
}
#scratchpad {
margin-left: 2px;
}
#cpu, #memory, #custom-vram, #mpd, #custom-clock-long, #custom-clock-short, #backlight, #battery, #custom-weather, #custom-weather2, #custom-notifs {
2024-09-04 22:07:29 -04:00
margin: 0 5px 0 2px;
}
2024-08-24 22:16:51 -04:00
#cpu {
border-bottom: 3px solid #f90000;
}
#memory {
border-bottom: 3px solid #4bffdc;
}
#custom-vram {
border-bottom: 3px solid #33FF00;
}
#mpd {
2024-08-24 22:16:51 -04:00
border-bottom: 3px solid #ffb066;
}
#mpd.paused {
color: #888;
}
2024-08-24 22:16:51 -04:00
#custom-clock-long {
border-bottom: 3px solid #0a6cf5;
}
#custom-clock-short {
border-bottom: 3px solid #0a6cf5;
}
#backlight {
border-bottom: 3px solid #5ffca3;
}
#battery {
border-bottom: 3px solid #fcfc16;
}
#custom-weather {
border-bottom: 3px solid #3823C4;
2024-08-24 22:16:51 -04:00
}
#custom-weather2 {
border-bottom: 3px solid #c75bd3;
}
#custom-notifs {
border-bottom: 3px solid #3823C4;
2024-08-24 22:16:51 -04:00
}
#custom-notifs.disabled {
color: #888;
}
#pulseaudio {
margin-right: 5px;
}
#pulseaudio.muted {
color: #424242;
}
'';
};
}