Files
dotfiles/home-modules/waybar.nix
Lennart J. Kurzweg (Nx2) 428c531415 homeACE
2024-05-05 12:32:57 +02:00

252 lines
7.0 KiB
Nix
Executable File

{ config, lib, pkgs, user, rice, ... }:
let
sep = " ";
in
lib.mkIf (user != "tv")
{
home.packages = with pkgs; [
waybar
(pkgs.writeShellScriptBin "waybar_mode" ''
#!/usr/bin/env bash
print_help() {
echo "Usage: waybar_mode {set <string>|unset}"
}
if [ $# -lt 1 ]; then
print_help; exit 1;
fi
case "$1" in
set)
# Check if there is a second argument for the 'set' operation
if [ $# -eq 2 ]; then
echo "$2" > /tmp/waybar-mode
pkill -RTMIN+8 waybar
else
echo "Error: 'set' operation requires exactly one string argument."
print_help
exit 1
fi
;;
unset)
echo "" > /tmp/waybar-mode
pkill -RTMIN+8 waybar
;;
*)
echo "Error: Unknown command '$1'"
print_help
exit 1
;;
esac
exit 0
'')
(pkgs.writeShellScriptBin "cclock" ''
#!/bin/bash
#ord=$(date +"%e" | awk '{printf("%d%s\n", $1, substr("thstndrd", ($1%100-20)%10*2+1, 2))}')
ord=$(date +"%e" | awk '{printf("%d%s\n", $1, ($1==11||$1==12||$1==13)?"th":((($1%10)==1)?"st":((($1%10)==2)?"nd":((($1%10)==3)?"rd":"th"))))}')
if [ $# -eq 0 ]; then
echo "󰃮${sep}$(date +'%A the')" "$ord" "of" "$(date +'%B')" " ${sep}$(date +'%R')"
elif [ "$1" = "--no-icons" ]; then
echo "$(date +'%A the')" "$ord" "of" "$(date +'%B')" "$(date +'%R')"
fi
'')
];
programs.waybar = {
enable = true;
settings = {
bar = {
height = 20;
layer = "top";
# position = "top";
position = "bottom";
margin-top = 0;
margin-left = rice.gap-size;
margin-bottom = rice.gap-size;
margin-right = rice.gap-size;
spacing = 10;
modules-left = [
# "cpu"
# "memory"
"wireplumber"
"backlight"
"battery"
"network"
"hyprland/window"
];
modules-center = [
"hyprland/workspaces"
];
modules-right = [
"custom/mode"
"custom/ctimeremaining"
"custom/cclock"
"tray"
];
"hyprland/workspaces" = {
on-click = "activate";
format = "{name}";
all-outputs = false;
active-only = false;
};
"hyprland/window" = {
# format = "${sep}{}";
format = "{}";
separate-outputs = true;
};
"custom/cclock" = {
exec = "cclock";
restart-interval = 60;
};
"custom/ctimeremaining" = {
exec = "nx_gcal_event lookup";
restart-interval = 60;
};
"custom/mode" = {
exec = "cat /tmp/waybar-mode";
interval = "once";
signal = 8;
};
cpu = {
interval = 1;
format = "󰍛${sep}{}%";
max-length = 10;
};
memory = {
interval = 5;
format = "${sep}{avail:.0f}G free";
};
battery = {
interval = 60;
tooltip = false;
format = "{icon}${sep}{capacity}%";
states = {
warning = 15;
critical = 5;
};
format-icons = [
" "
" "
" "
" "
" "
];
format-charging = "{icon}${sep}+{capacity}%";
format-plugged = "{icon}${sep}P{capacity}%";
format-full = "{icon}${sep}F{capacity}%";
};
backlight = {
device = "eDP-1";
format = "{icon}${sep}{percent}%";
format-icons = [
""
""
""
""
""
""
""
""
""
];
};
network = {
format-wifi = "${sep}{essid}";
format-ethernet = "󰈀${sep}Wired";
format-disconnected = "󰌙${sep}Disconnected";
};
wireplumber = {
format = "󰕾${sep}{volume}%";
format-muted = "󰝟${sep}--%";
};
};
};
style = ''
* {
font-family: ${rice.font.code.name2};
font-size: 1em;
min-height: 0px;
margin: 0px;
padding: 0px;
}
window#waybar {
background-color: rgba(${rice.lib.hex-to-rgb-comma-string rice.color.background},${builtins.toString rice.transparency});
transition-duration: 2s;
padding: 7px 10px;
padding-top: 0.1em;
/* border: ${builtins.toString rice.border-width}px solid rgb(${rice.lib.hex-to-rgb-comma-string rice.color.blue}); */
/* margin: ${builtins.toString rice.gap-size}px; */
border-radius: ${builtins.toString rice.rounding}px;
}
#clock,
#custom-cclock,
#custom-ctimeremaining,
#custom-mode,
#battery,
#cpu,
#tray,
#disk,
#backlight,
#network,
#wireplumber,
#memory,
#window,
#workspaces {
padding: 0px 3px;
margin-top: 0.3em;
border-radius: ${builtins.toString rice.rounding}px;
color: rgb(${rice.lib.hex-to-rgb-comma-string rice.color.bright-cyan});
}
#workspaces button {
color: rgb(${rice.lib.hex-to-rgb-comma-string rice.color.bright-black});
margin-left: 10px;
margin-right: 10px;
border-radius: ${builtins.toString rice.rounding}px;
}
#workspaces button.active {
color: rgb(${rice.lib.hex-to-rgb-comma-string rice.color.bright-cyan});
}
#workspaces button:hover {
color: rgb(${rice.lib.hex-to-rgb-comma-string rice.color.background});
background-color: rgba(${rice.lib.hex-to-rgb-comma-string rice.color.bright-cyan},${builtins.toString rice.transparency});
}
#workspaces button.urgent {
background-color: rgba(${rice.lib.hex-to-rgb-comma-string rice.color.magenta},${builtins.toString rice.transparency});
}
#custom-mode {
color: rgb(${rice.lib.hex-to-rgb-comma-string rice.color.red});
}
#window, #custom-ctimeremaining {
font-family: ${rice.font.base.name}, ${rice.font.code.name2};
color: rgb(${rice.lib.hex-to-rgb-comma-string rice.color.blue});
}
#wireplumber.muted {
color: rgb(${rice.lib.hex-to-rgb-comma-string rice.color.blue});
}
#battery.warning:not(.charging) {
color: rgb(${rice.lib.hex-to-rgb-comma-string rice.color.green});;
}
#battery.critical {
color: rgb(${rice.lib.hex-to-rgb-comma-string rice.color.red});;
background: rgb(${rice.lib.hex-to-rgb-comma-string rice.color.bright-red});
}
#battery.charging { color: rgb(${rice.lib.hex-to-rgb-comma-string rice.color.green}); }
'';
#battery.critical:not(.charging) {
};
}