Redesign Eww bars

This commit is contained in:
soraefir
2023-11-21 16:52:35 +01:00
parent 285d5caa8e
commit 8a833d1eb6
47 changed files with 785 additions and 37 deletions

View File

@ -0,0 +1,72 @@
#!/usr/bin/env bash
function get_time_ms {
date -u +%s%3N
}
icons=("󰤯" "󰤟" "󰤢" "󰤥" "󰤨")
function toggle() {
status=$(rfkill | grep wlan | awk '{print $4}')
if [ "$status" = "unblocked" ]; then
rfkill block wlan
else
rfkill unblock wlan
fi
}
function gen_wifi() {
signal=$(cat /proc/net/wireless | head -n3 | tail -n1 | awk '{print $3}')
level=$(awk -v n="$signal" 'BEGIN{print int((n-1)/20)}')
if [ "$level" -gt 4 ]; then
level=4
fi
icon=${icons[$level]}
ip="-"
class="net-connected"
name=$(wpa_cli status | grep \^ssid= | sed 's/ssid=//g')
}
function gen_ethernet() {
icon="󰈀"
class="net-connected"
ip=""
name=Wired
}
function make_content() {
local ethernet wifi
ethernet=$(ip link | rg "^[0-9]+: en[po]+" | head -n1 | sed 's/[a-zA-Z0-9_,><:\ -]*state //g' | sed 's/ mode [a-zA-Z0-9 ]*//g')
wifi=$(wpa_cli status | rg "^wpa_state=" | sed 's/wpa_state=//g')
# test ethernet first
if [[ $ethernet == "UP" ]]; then
gen_ethernet
elif [[ $wifi == "COMPLETED" ]]; then
gen_wifi
else
icon="󰤮"
ip="-"
class="net-disconnected"
name="Disconnected"
fi
echo '{"icon": "'$icon'", "name": "'$name'", "ip": "'$ip'", "class": "'$class'"}'
}
if [ "$1" = "toggle" ]; then
toggle
else
last_time=$(get_time_ms)
make_content
ip monitor | while read -r _; do
current_time=$(get_time_ms)
delta=$((current_time - last_time))
if [[ $delta -gt 50 ]]; then
make_content
last_time=$(get_time_ms)
fi
done
fi

View File

@ -0,0 +1,61 @@
#!/usr/bin/env bash
icons=("󰂎" "󰁺" "󰁻" "󰁼" "󰁽" "󰁾" "󰁿" "󰂀" "󰂁" "󰂂" "󰁹")
num_icons=$(awk -v n="${#icons[@]}" 'BEGIN{print 100 / n}')
BATTERY="/sys/class/power_supply/BAT0"
geticon() {
level=$(awk -v n="$CAPACITY" -v c="$num_icons" 'BEGIN{print int(n/c-1)}')
echo "${icons[$level]}"
}
status() {
if [ "$STATE" = "Charging" ]; then
echo -n "charging"
if [ "$RATE" -gt 0 ]; then
echo ", $(gettime) left"
else
echo ""
fi
elif [ "$STATE" = "Discharging" ]; then
echo "$(gettime)h left"
else
echo "fully charged"
fi
}
color() {
[ "$CAPACITY" -le 20 ] && echo '#f38ba8' || echo '#a6e3a1'
}
wattage() {
awk -v rate="$RATE" -v uw="1000000" 'BEGIN{print sprintf("%.1f W", rate/uw)}'
}
gettime() {
FULL=$(cat $BATTERY/energy_full)
NOW=$(cat $BATTERY/energy_now)
if [ "$RATE" -gt 0 ]; then
if [ "$STATE" = "Discharging" ]; then
EX="$NOW / $RATE"
else
EX="($FULL - $NOW) / $RATE"
fi
date -u -d@"$(awk -v ex="$EX" 'BEGIN{print ex * 3600}')" +%H:%M
fi
}
if [ -d "$BATTERY" ]; then
while true; do
RATE=$(cat $BATTERY/power_now)
CAPACITY=$(cat $BATTERY/capacity)
STATE=$(cat $BATTERY/status)
echo '{ "visible": true, "icon": "'$(geticon)'", "percentage": '$CAPACITY', "wattage": "'$(wattage)'", "status": "'$(status)'", "color": "'$(color)'" }'
sleep 15
done
else
echo '{ "visible": false, "icon": "", "percentage": 0, "wattage": "", "status": "", "color": "#a6e3a1" }'
fi

View File

@ -0,0 +1 @@
#!/usr/bin/env bash

View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
amdgpu_top -J -s 5000 | sed 's/ //g'

View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
total="$(free --si | rg Mem | awk '{print $2}')"
human() {
awk -v mem="$1" 'BEGIN{print sprintf("%.1f%s", mem/1000/(mem > 1000000 ? 1000 : 1), mem > 1000000 ? "G" : "M")}'
}
free --si -s 3 | rg --line-buffered Mem | while read -r line; do
used=$(echo "$line" | awk '{print $3}')
perc=$(awk -v used="$used" -v total="$total" 'BEGIN{print sprintf("%.f", used/total*100)}')
echo '{"total": "'$(human "$total")'", "used": "'$(human "$used")'", "percent": '$perc'}'
done

View File

@ -0,0 +1,30 @@
#!/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

@ -0,0 +1,23 @@
#!/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

@ -0,0 +1,20 @@
#!/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

@ -0,0 +1,64 @@
#!/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

View File

@ -0,0 +1,86 @@
#!/usr/bin/env bash
colors=("blue" "blue" "green" "red")
empty="grey"
# get initial focused workspace
focusedws=$(hyprctl -j monitors | jaq -r '.[] | select(.focused == true) | .activeWorkspace.id')
declare -A o=([1]=0 [2]=0 [3]=0 [4]=0 [5]=0 [6]=0 [7]=0 [8]=0 [9]=0 [10]=0)
declare -A monitormap
declare -A workspaces
# set color for each workspace
status() {
if [ "${o[$1]}" -eq 1 ]; then
mon=${monitormap[${workspaces[$1]}]}
echo -n "${colors[$mon]}"
else
echo -n "$empty"
fi
}
# handle workspace create/destroy
workspace_event() {
while read -r k v; do workspaces[$k]="$v"; done < <(hyprctl -j workspaces | jaq -jr '.[] | .id, " ", .monitor, "\n"')
}
# handle monitor (dis)connects
monitor_event() {
while read -r k v; do monitormap["$k"]=$v; done < <(hyprctl -j monitors | jaq -jr '.[] | .name, " ", .id, "\n"')
}
# get all apps titles in a workspace
applist() {
ws="$1"
apps=$(hyprctl -j clients | jaq -jr '.[] | select(.workspace.id == '"$ws"') | .title + "\\n"')
echo -En "${apps%"\n"}"
}
# generate the json for eww
generate() {
echo -n '['
for i in {1..10}; do
echo -n ''"$([ "$i" -eq 1 ] || echo ,)" '{"number": "'"$i"'", "color": "'"$(status "$i")"'", "focused": '"$([ "$focusedws" = "$i" ] && echo "true" || echo "false")"'}' #, "tooltip": "'$(applist "$i")'" }'
done
echo ']'
}
# setup
# add monitors
monitor_event
# add workspaces
workspace_event
# check occupied workspaces
for num in "${!workspaces[@]}"; do
o[$num]=1
done
# generate initial widget
generate
# main loop
socat -u UNIX-CONNECT:/tmp/hypr/"$HYPRLAND_INSTANCE_SIGNATURE"/.socket2.sock - | rg --line-buffered "workspace|mon(itor)?" | while read -r line; do
case ${line%>>*} in
"workspace")
focusedws=${line#*>>}
;;
"focusedmon")
focusedws=${line#*,}
;;
"createworkspace")
o[${line#*>>}]=1
;;
"destroyworkspace")
o[${line#*>>}]=0
;;
"monitor"*)
monitor_event
;;
esac
generate
done