Add do-not-disturb widget to waybar

This commit is contained in:
Jakob Lechner 2025-03-13 17:30:31 +01:00
parent 7f489b0e5a
commit 770e354480
2 changed files with 195 additions and 169 deletions

View file

@ -6,6 +6,8 @@ let
${builtins.readFile ./android-set-dnd.py}
'';
do-not-disturb = pkgs.writeShellScriptBin "dnd" ''
export PATH=${pkgs.lib.makeBinPath [pkgs.mako]}
if [[ "$1" != off && "$1" != on ]]; then
echo "USAGE: $0 [on|off]" >&2
exit 1

View file

@ -22,69 +22,74 @@ let
in
{
# home-managers waybar module performs additional checks that are overly strict
xdg.configFile."waybar/config".text = lib.generators.toJSON { } {
layer = "top";
output = [
"!HEADLESS-1"
"*"
];
position = "top";
height = 24;
xdg.configFile."waybar/config".text =
let
makoctl = "${pkgs.mako}/bin/makoctl";
in
lib.generators.toJSON { } {
layer = "top";
output = [
"!HEADLESS-1"
"*"
];
position = "top";
height = 24;
modules-center = [ ];
modules-left = [
"sway/workspaces"
"sway/mode"
];
modules-right = [
"tray"
"custom/screencast"
"custom/redshift"
"idle_inhibitor"
"custom/pomodoro"
"backlight"
"pulseaudio"
"network"
"memory"
"cpu"
"temperature"
"battery"
"clock"
];
modules-center = [ ];
modules-left = [
"sway/workspaces"
"sway/mode"
];
modules-right = [
"tray"
"custom/screencast"
"custom/redshift"
"idle_inhibitor"
"custom/pomodoro"
"backlight"
"pulseaudio"
"network"
"memory"
"cpu"
"temperature"
"battery"
"clock"
"custom/dnd"
];
"sway/workspaces" = {
disable-scroll = true;
};
"sway/mode" = {
format = "{}";
};
"sway/workspaces" = {
disable-scroll = true;
};
"sway/mode" = {
format = "{}";
};
tray = {
spacing = 5;
};
"custom/redshift" = {
exec = watchUserUnitState
"gammastep"
{ class = "active"; }
{ class = "inactive"; };
on-click = toggleUserUnitState "gammastep";
return-type = "json";
format = "󰌵";
tooltip = false;
};
"custom/pomodoro" = let uairctl = "${pkgs.uair}/bin/uairctl"; in {
# We need to remove nul-characters
# See https://github.com/metent/uair/issues/15
exec = pkgs.writeShellScript "uairctl-without-null-characters" ''
${uairctl} listen -o waybar | ${pkgs.gnused}/bin/sed --unbuffered 's/\x0//g'
'';
tray = {
spacing = 5;
};
"custom/redshift" = {
exec = watchUserUnitState
"gammastep"
{ class = "active"; }
{ class = "inactive"; };
on-click = toggleUserUnitState "gammastep";
return-type = "json";
format = "󰌵";
tooltip = false;
};
"custom/pomodoro" = let uairctl = "${pkgs.uair}/bin/uairctl"; in {
# We need to remove nul-characters
# See https://github.com/metent/uair/issues/15
exec = pkgs.writeShellScript "uairctl-without-null-characters" ''
${uairctl} listen -o waybar | ${pkgs.gnused}/bin/sed --unbuffered 's/\x0//g'
'';
on-click = "${uairctl} toggle";
on-scroll-up = "${uairctl} next";
on-scroll-down = "${uairctl} prev";
on-click-middle = "${uairctl} finish";
menu = "on-click-right";
/*
on-click = "${uairctl} toggle";
on-scroll-up = "${uairctl} next";
on-scroll-down = "${uairctl} prev";
on-click-middle = "${uairctl} finish";
menu = "on-click-right";
/*
menu-actions = {
"work 1" = "${uairctl} jump 0";
"break 1" = "${uairctl} jump 1";
@ -95,118 +100,132 @@ in
"work 4" = "${uairctl} jump 6";
"long break" = "${uairctl} jump 7";
};
*/
return-type = "json";
};
idle_inhibitor = {
format = "{icon}";
format-icons = {
activated = "󰈈 ";
deactivated = "󰈉 ";
*/
return-type = "json";
};
idle_inhibitor = {
format = "{icon}";
format-icons = {
activated = "󰈈 ";
deactivated = "󰈉 ";
};
};
"custom/screencast" = {
exec = pkgs.writeScript "screencast-monitor" /* python */ ''
#!${pkgs.python3}/bin/python3
import subprocess
import sys
active_outputs = 0
with subprocess.Popen(
["${pkgs.coreutils}/bin/stdbuf", "-o0", "${nixosConfig.services.pipewire.package}/bin/pw-link", "-m", "-o", "xdg-desktop-portal-wlr"],
stdout=subprocess.PIPE,
text=True,
) as proc:
for line in proc.stdout:
action = line.split(" ")[0]
if action == "=" or action == "+":
active_outputs += 1
elif action == "-":
active_outputs -= 1
else:
print(f"Invalid action {action} (in line {line})", file=sys.stderr)
if active_outputs > 0:
print("󱒃")
subprocess.run(["${makoctl}", "mode", "-a" "screencast"], stdout=subprocess.DEVNULL)
else:
print()
subprocess.run(["${makoctl}", "mode", "-r" "screencast"], stdout=subprocess.DEVNULL)
sys.stdout.flush()
'';
format = "{}";
tooltip = false;
};
backlight = {
format = "{percent}% {icon}";
format-icons = [ "󰛩" "󱩎" "󱩏" "󱩐" "󱩑" "󱩒" "󱩓" "󱩔" "󱩕" "󱩖" "󰛨" ];
on-scroll-up = "${pkgs.brightnessctl}/bin/brightnessctl -q set +5%";
on-scroll-down = "${pkgs.brightnessctl}/bin/brightnessctl -q set 5%-";
};
pulseaudio = {
format = "{volume}% {icon} {format_source}";
format-bluetooth = "{volume}% {icon}󰗾{format_source}";
format-bluetooth-muted = "{icon}󰗿{format_source}";
format-muted = "󰝟 {format_source}";
format-source = "{volume}% ${thinsp}";
format-source-muted = "${thinsp}";
format-icons = {
car = "󰄋 ";
default = [ "󰕿" "󰖀" "󰕾" ];
hands-free = "󰋎";
headphone = "󰋋";
headset = "󰋎";
phone = "󰏲";
portable = "󰏲";
};
on-click-right = "${pkgs.pavucontrol}/bin/pavucontrol";
};
network = {
format-wifi = "{essid} ({signalStrength}%) 󰖩 ";
format-ethernet = "{ipaddr}/{cidr} 󰈀 ";
format-linked = "{ifname} (No IP) 󰈀 ";
format-disconnected = "Disconnected ";
format-alt = "{ifname}: {ipaddr}/{cidr}";
tooltip = false;
on-click-right = "${config.programs.alacritty.package}/bin/alacritty -e ${pkgs.networkmanager}/bin/nmtui";
};
memory = {
interval = 2;
format = "{:2}% 󰍛 ";
};
cpu = {
interval = 2;
format = "{usage:2}% ";
tooltip = false;
};
temperature = {
critical-threshold = 80;
format = "{temperatureC}°C {icon}";
format-icons = [ "" "" "" "" "" ];
} // (lib.optionalAttrs (nixosConfig.networking.hostName == "mayushii") {
hwmon-path = "/sys/class/hwmon/hwmon3/temp1_input";
});
battery = {
interval = 5;
format = "{capacity}% {icon}";
format-charging = "{capacity}% ";
format-plugged = "{capacity}% x";
format-alt = "{time} {icon}";
format-icons = [ "󰂎" "󰁺" "󰁻" "󰁼" "󰁽" "󰁾" "󰁿" "󰂀" "󰂁" "󰂂" "󰁹" ];
states = {
critical = 15;
good = 95;
warning = 30;
};
};
clock = {
format = "{:%H:%M %Z}";
format-alt = "{:%Y-%m-%d (%a)}";
tooltip-format = "<big>{:%Y %B}</big>\n<tt><small>{calendar}</small></tt>";
};
"custom/dnd" = {
exec = pkgs.writeShellScript "waybar-dnd-widget" ''
export PATH=${pkgs.lib.makeBinPath [pkgs.gnugrep]}
if ${makoctl} mode | grep -Fxq 'dnd'; then
echo '{"text": "󰂛", "class": "active"}'
else
echo '{"text": "󰂚", "class": "inactive"}'
fi
'';
on-click = "/etc/profiles/per-user/jalr/bin/dnd on";
on-click-right = "/etc/profiles/per-user/jalr/bin/dnd off";
interval = 10;
return-type = "json";
};
};
"custom/screencast" = let makoctl = "${pkgs.mako}/bin/makoctl"; in {
exec = pkgs.writeScript "screencast-monitor" /* python */ ''
#!${pkgs.python3}/bin/python3
import subprocess
import sys
active_outputs = 0
with subprocess.Popen(
["${pkgs.coreutils}/bin/stdbuf", "-o0", "${nixosConfig.services.pipewire.package}/bin/pw-link", "-m", "-o", "xdg-desktop-portal-wlr"],
stdout=subprocess.PIPE,
text=True,
) as proc:
for line in proc.stdout:
action = line.split(" ")[0]
if action == "=" or action == "+":
active_outputs += 1
elif action == "-":
active_outputs -= 1
else:
print(f"Invalid action {action} (in line {line})", file=sys.stderr)
if active_outputs > 0:
print("󱒃")
subprocess.run(["${makoctl}", "mode", "-a" "screencast"], stdout=subprocess.DEVNULL)
else:
print()
subprocess.run(["${makoctl}", "mode", "-r" "screencast"], stdout=subprocess.DEVNULL)
sys.stdout.flush()
'';
format = "{}";
tooltip = false;
};
backlight = {
format = "{percent}% {icon}";
format-icons = [ "󰛩" "󱩎" "󱩏" "󱩐" "󱩑" "󱩒" "󱩓" "󱩔" "󱩕" "󱩖" "󰛨" ];
on-scroll-up = "${pkgs.brightnessctl}/bin/brightnessctl -q set +5%";
on-scroll-down = "${pkgs.brightnessctl}/bin/brightnessctl -q set 5%-";
};
pulseaudio = {
format = "{volume}% {icon} {format_source}";
format-bluetooth = "{volume}% {icon}󰗾{format_source}";
format-bluetooth-muted = "{icon}󰗿{format_source}";
format-muted = "󰝟 {format_source}";
format-source = "{volume}% ${thinsp}";
format-source-muted = "${thinsp}";
format-icons = {
car = "󰄋 ";
default = [ "󰕿" "󰖀" "󰕾" ];
hands-free = "󰋎";
headphone = "󰋋";
headset = "󰋎";
phone = "󰏲";
portable = "󰏲";
};
on-click-right = "${pkgs.pavucontrol}/bin/pavucontrol";
};
network = {
format-wifi = "{essid} ({signalStrength}%) 󰖩 ";
format-ethernet = "{ipaddr}/{cidr} 󰈀 ";
format-linked = "{ifname} (No IP) 󰈀 ";
format-disconnected = "Disconnected ";
format-alt = "{ifname}: {ipaddr}/{cidr}";
tooltip = false;
on-click-right = "${config.programs.alacritty.package}/bin/alacritty -e ${pkgs.networkmanager}/bin/nmtui";
};
memory = {
interval = 2;
format = "{:2}% 󰍛 ";
};
cpu = {
interval = 2;
format = "{usage:2}% ";
tooltip = false;
};
temperature = {
critical-threshold = 80;
format = "{temperatureC}°C {icon}";
format-icons = [ "" "" "" "" "" ];
} // (lib.optionalAttrs (nixosConfig.networking.hostName == "mayushii") {
hwmon-path = "/sys/class/hwmon/hwmon3/temp1_input";
});
battery = {
interval = 5;
format = "{capacity}% {icon}";
format-charging = "{capacity}% ";
format-plugged = "{capacity}% x";
format-alt = "{time} {icon}";
format-icons = [ "󰂎" "󰁺" "󰁻" "󰁼" "󰁽" "󰁾" "󰁿" "󰂀" "󰂁" "󰂂" "󰁹" ];
states = {
critical = 15;
good = 95;
warning = 30;
};
};
clock = {
format = "{:%H:%M %Z}";
format-alt = "{:%Y-%m-%d (%a)}";
tooltip-format = "<big>{:%Y %B}</big>\n<tt><small>{calendar}</small></tt>";
};
};
xdg.configFile."waybar/theme-light.css".text = solarizedColors {
base00 = "base3";
@ -394,6 +413,11 @@ in
color: @base01;
background-color: @base0B;
}
#custom-dnd.active {
color: @base01;
background-color: @base0B;
}
'';
systemd.user.services.waybar = {