Power menu

This commit is contained in:
soraefir
2026-06-15 01:01:23 +02:00
parent db6662420c
commit b586df0816
11 changed files with 63 additions and 215 deletions

View File

@@ -1,30 +1,18 @@
#!/usr/bin/env bash
PANEL="$1"
# Drop concurrent invocations, but recover from stale locks (dead processes)
LOCK="/tmp/eww_panel_toggle.lock"
if [ -f "$LOCK" ] && kill -0 "$(cat "$LOCK" 2>/dev/null)" 2>/dev/null; then
exit 0
fi
echo $$ > "$LOCK"
trap 'rm -f "$LOCK"' EXIT
# Atomic lock: flock acquires exclusively or exits immediately.
# Released automatically when the process exits (no trap needed).
exec 9>"/tmp/eww_panel_toggle.lock"
flock -n 9 || exit 0
CURRENT=$(eww get active-panel 2>/dev/null | tr -d '"')
open_popup() {
local screen
screen=$(hyprctl monitors -j 2>/dev/null | jq -r '.[] | select(.focused == true) | .name' | head -n1)
if [ -n "$screen" ]; then
eww open popup --screen "$screen"
else
eww open popup
fi
}
if [ "$CURRENT" = "$PANEL" ]; then
eww update active-panel=""
eww close popup 2>/dev/null
else
eww update active-panel="$PANEL"
open_popup
eww close popup 2>/dev/null
eww-open-on-current-screen popup
fi

View File

@@ -0,0 +1,4 @@
#!/usr/bin/env bash
eww close popup 2>/dev/null
eww update active-panel=""
eww-open-on-current-screen powermenu --toggle

View File

@@ -1,30 +0,0 @@
#!/usr/bin/env bash
function get_time_ms {
date -u +%s%3N
}
icons=("󰛩" "󱩒" "󰛨")
gen_output() {
icon="${icons[$(awk -v n="$(brillo)" 'BEGIN{print int(n/34)}')]}"
prcnt=$(brillo | xargs printf "%.*f\n" "0")
echo '{"percent": '$prcnt', "icon": "'$icon'"}'
}
if [[ $(brillo 2>/dev/stdout 1>/dev/null | head -n1 | awk '{print $1}') == "No" ]]; then
echo '{"percent": 100, "icon": "󰛨"}'
elif [ "$1" = "" ]; then
# initial
last_time=$(get_time_ms)
gen_output
udevadm monitor | rg --line-buffered "backlight" | while read -r _; do
current_time=$(get_time_ms)
delta=$((current_time - last_time))
if [[ $delta -gt 50 ]]; then
gen_output
last_time=$(get_time_ms)
fi
done
fi

View File

@@ -1,23 +0,0 @@
#!/bin/sh
icon() {
[ "$STATUS" = "no" ] && echo "󰀞" || echo "󰀝"
}
toggle() {
if [ "$STATUS" = "no" ]; then
rfkill block all
else
rfkill unblock all
fi
}
if [ "$1" = "toggle" ]; then
toggle
else
icon
rfkill event | while read -r _; do
STATUS="$(rfkill list | sed -n 2p | awk '{print $3}')"
icon
done
fi

View File

@@ -1,20 +0,0 @@
#!/bin/sh
icon() {
[ "$STATUS" = "no" ] && echo "󰌪" || echo "󱐋"
}
toggle() {
if [ "$STATUS" = "no" ]; then
echo ""
else
echo ""
fi
}
if [ "$1" = "toggle" ]; then
toggle
icon
else
icon
fi

View File

@@ -1,64 +0,0 @@
#!/usr/bin/env bash
function get_time_ms {
date -u +%s%3N
}
volicons=("󰕿" "󰖀" "󰕾")
vol() {
wpctl get-volume @DEFAULT_AUDIO_"$1"@ | awk '{print int($2*100)}'
}
ismuted() {
wpctl get-volume @DEFAULT_AUDIO_"$1"@ | rg -qi muted
echo -n $?
}
setvol() {
wpctl set-volume @DEFAULT_AUDIO_"$1"@ "$(awk -v n="$2" 'BEGIN{print (n / 100)}')"
}
setmute() {
wpctl set-mute @DEFAULT_AUDIO_"$1"@ toggle
}
gen_output() {
percent="$(vol "SINK")"
lvl=$(awk -v n="$percent" 'BEGIN{print int(n/34)}')
ismuted=$(ismuted "SINK")
if [ "$ismuted" = 1 ]; then
icon="${volicons[$lvl]}"
else
icon="󰝟"
fi
echo '{"icon": "'$icon'", "percent": '$(vol "SINK")', "microphone": '$(vol "SOURCE")'}'
}
if [ "$1" = "mute" ]; then
if [ "$2" != "SOURCE" ] && [ "$2" != "SINK" ]; then
echo "Can only mute SINK or SOURCE"
exit 1
fi
setmute "$2"
elif [ "$1" = "setvol" ]; then
if [ "$2" != "SOURCE" ] && [ "$2" != "SINK" ]; then
echo "Can only set volume for SINK or SOURCE"
exit 1
elif [ "$3" -lt 0 ] || [ "$3" -gt 100 ]; then
echo "Volume must be between 0 and 100"
exit 1
fi
setvol "$2" "$3"
else
last_time=$(get_time_ms)
gen_output
pw-cli -m 2>/dev/null | rg --line-buffered "PipeWire:Interface:Client" | while read -r event; do
current_time=$(get_time_ms)
delta=$((current_time - last_time))
if [[ $delta -gt 50 ]]; then
gen_output
last_time=$(get_time_ms)
fi
done
fi