Power menu
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user