feat: add printer cups in bar

This commit is contained in:
2026-04-03 15:34:26 -04:00
parent 1ebcd3ae46
commit ffe45b43c5
5 changed files with 71 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.codex

View File

@@ -18,6 +18,7 @@
], ],
"modules-right": [ "modules-right": [
"tray", "tray",
"custom/print-queue",
"network", "network",
"bluetooth", "bluetooth",
"pulseaudio", "pulseaudio",
@@ -64,6 +65,14 @@
"lock": "hyprlock" "lock": "hyprlock"
} }
}, },
"custom/print-queue": {
"exec": "$HOME/.config/waybar/scripts/print-queue.sh",
"return-type": "json",
"interval": 10,
"format": "{}",
"tooltip": true,
"on-click": "$HOME/.config/waybar/scripts/print-queue-view.sh"
},
"hyprland/workspaces": { "hyprland/workspaces": {
"all-outputs": false, "all-outputs": false,
"sort-by-number": true "sort-by-number": true

View File

@@ -0,0 +1,30 @@
#!/usr/bin/env sh
if command -v system-config-printer >/dev/null 2>&1; then
exec system-config-printer
fi
if command -v alacritty >/dev/null 2>&1; then
exec alacritty -e sh -lc '
while :; do
clear
printf "Print Queue\n"
printf "===========\n\n"
if ! lpstat -r >/dev/null 2>&1; then
printf "CUPS scheduler is not running.\n"
else
if ! lpstat -o 2>/dev/null | sed "/^[[:space:]]*$/d" | grep . >/dev/null 2>&1; then
printf "No print jobs queued.\n"
else
lpstat -o
fi
fi
printf "\nRefreshing every 3 seconds. Press Ctrl+C to close."
sleep 3
done
'
fi
exec xdg-open http://localhost:631/jobs/

View File

@@ -0,0 +1,24 @@
#!/usr/bin/env sh
jobs_output="$(lpstat -o 2>/dev/null)"
status=$?
if [ "$status" -ne 0 ]; then
printf '%s\n' '{"text":"󰐪 n/a","class":"disabled","tooltip":"CUPS is unavailable"}'
exit 0
fi
if [ -z "$jobs_output" ]; then
printf '%s\n' '{"text":"","class":"idle","tooltip":"No print jobs queued"}'
exit 0
fi
job_count="$(printf '%s\n' "$jobs_output" | sed '/^[[:space:]]*$/d' | wc -l | tr -d ' ')"
if [ "$job_count" = "1" ]; then
tooltip="1 print job queued"
else
tooltip="$job_count print jobs queued"
fi
printf '{"text":"󰐪 %s","class":"active","tooltip":"%s"}\n' "$job_count" "$tooltip"

View File

@@ -45,6 +45,7 @@ tooltip {
#workspaces, #workspaces,
#window, #window,
#clock, #clock,
#custom-print-queue,
#network, #network,
#bluetooth, #bluetooth,
#pulseaudio, #pulseaudio,
@@ -63,6 +64,7 @@ tooltip {
#custom-launcher, #custom-launcher,
#workspaces, #workspaces,
#clock, #clock,
#custom-print-queue,
#tray { #tray {
border-left: none; border-left: none;
} }
@@ -72,6 +74,10 @@ tooltip {
border-left: none; border-left: none;
} }
#custom-print-queue {
padding: 0 10px;
}
#network { #network {
padding: 0 6px 0 10px; padding: 0 6px 0 10px;
} }
@@ -153,6 +159,7 @@ tooltip {
#custom-launcher:hover, #custom-launcher:hover,
#workspaces button:hover, #workspaces button:hover,
#network:hover, #network:hover,
#custom-print-queue:hover,
#bluetooth:hover, #bluetooth:hover,
#pulseaudio:hover, #pulseaudio:hover,
#battery:hover, #battery:hover,