nixos/pkgs/eww-hyprland/scripts/utils

53 lines
1 KiB
Bash

#!/usr/bin/env bash
if [ ! "$XDG_CACHE_HOME" ]; then
XDG_CACHE_HOME="/home/mihai/.local/cache"
fi
function get_time_ms {
date -u +%s%3N
}
function osd {
date="$1"
if [ ! -f "$date" ]; then
mkdir -p "$XDG_CACHE_HOME/eww"
fi
date +%s >"$date"
}
function osd_handler {
lock=0
rundate=0
OBJ="$1"
if [ ! -f "$date" ]; then
mkdir -p "$XDG_CACHE_HOME/eww"
echo 0 >"$date"
fi
while true; do
# get dates
rundate=$(cat "$date")
currentdate=$(date +%s)
# handle showing
if [ "$rundate" = "$currentdate" ] && [ "$lock" -eq 0 ]; then
eww open osd >/dev/null 2>&1
eww update "$OBJ"=true >/dev/null 2>&1
lock=1
elif [ "$((currentdate - rundate))" = "2" ] && [ "$lock" -eq 1 ]; then
eww update "$OBJ"=false >/dev/null 2>&1
lock=0
if [ "$(eww get osd-volume)" = "false" ] && [ "$(eww get osd-brightness)" = "false" ]; then
sleep 1
eww close osd >/dev/null 2>&1
fi
fi
sleep 0.1
done
eww close osd >/dev/null 2>&1
}