From 962fdf8c308730f3df36e8d25e8adc0928e65a1c Mon Sep 17 00:00:00 2001 From: Viyurz Date: Mon, 4 Nov 2024 11:40:49 +0100 Subject: [PATCH] [eww] Add brightness, network & notifications widgets --- .config/eww/eww.yuck | 17 ++++++++++++++--- .config/eww/scripts/get-network.sh | 26 ++++++++++++++++++++++++++ .config/eww/scripts/set-brightness.sh | 11 +++++++++++ .config/eww/scripts/toggle-nf-state.sh | 3 +++ .config/hypr/hyprland.d/bindings.conf | 4 ++-- 5 files changed, 56 insertions(+), 5 deletions(-) create mode 100755 .config/eww/scripts/get-network.sh create mode 100755 .config/eww/scripts/set-brightness.sh diff --git a/.config/eww/eww.yuck b/.config/eww/eww.yuck index 706959f..a021a90 100644 --- a/.config/eww/eww.yuck +++ b/.config/eww/eww.yuck @@ -1,5 +1,5 @@ ; Brightness -(deflisten brightness :initial "128" "while :; do cat /sys/class/backlight/amdgpu_bl1/brightness; sleep 0.1; done") +(defpoll brightness :initial "128" :interval "1m" "cat /sys/class/backlight/amdgpu_bl1/brightness") (defvar brightness-icons '["", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]') (defvar brightness-slide false) @@ -12,8 +12,11 @@ (defpoll day :interval "1m" :initial "1" "date +'%d'") (defpoll year :interval "1m" :initial "0" "date +'%Y'") +; Network +(defpoll network :initial '{"if": "lo"}' :interval "2s" "~/.config/eww/scripts/get-network.sh") + ; Notifications status -(deflisten nf-enabled :initial "true" "while :; do makoctl mode | grep -q dnd && echo false || echo true; sleep 0.1; done") +(defpoll nf-enabled :initial "true" :interval "1m" "makoctl mode | grep -q dnd && echo false || echo true") ; Packages updates (deflisten packages-updates :initial '{"count": "-", "class": " "}' "~/.config/eww/scripts/pkg-updates.sh") @@ -38,6 +41,7 @@ ) (nf-state) (packages-updates) + (network) ) ) @@ -69,6 +73,13 @@ ) ) +(defwidget network [] + (tooltip + (label :text "IPv4: ${network.ip4}\\nIPv6: ${network.ip6}${network.type == "wifi" ? "\\nRate: ${network.rate}\\nSignal strength: ${network.signal}" : ""}") + (label :text "${network.icon} ${network.name} ${network.if == "null" ? "" : "󰜮 ${EWW_NET[network.if].NET_DOWN} 󰜷 ${EWW_NET[network.if].NET_UP}"}") + ) +) + (defwidget bar-middle [] (label :limit-width 2 @@ -109,7 +120,7 @@ (scale :value {brightness} :min 0 :max 255 - :onchange "echo {} > /sys/class/backlight/amdgpu_bl1/brightness" + :onchange "~/.config/eww/scripts/set-brightness.sh {}" ) ) ) diff --git a/.config/eww/scripts/get-network.sh b/.config/eww/scripts/get-network.sh new file mode 100755 index 0000000..fb19b43 --- /dev/null +++ b/.config/eww/scripts/get-network.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +if=$(ip -j r list default | jq -r '.[0].dev') + +if [[ "$if" != "null" ]]; then + type="$(nmcli -t -g general.type device show $if)" + ip4="$(nmcli -t -g ip4.address device show $if)" + ip6="$(nmcli -t -g ip6.address device show $if | sed 's/\\//g')" + + if [[ "$type" == "wifi" ]]; then + icon="󰖩" + name="$(nmcli -t -g general.connection device show $if)" + rate="$(nmcli -t -g 'AP' device show wlo1 | awk -F ':' '{if ($2 == "*") { print $12 } }')" + signal="$(nmcli -t -g 'AP' device show wlo1 | awk -F ':' '{if ($2 == "*") { print $13 } }')%" + else + icon="󰛳" + name="Ethernet" + fi +else + icon="󰲛" + name="Not connected" +fi + +cat << EOF +{"if": "$if", "icon": "$icon", "type": "$type", "name": "$name", "ip4": "$ip4", "ip6": "$ip6", "rate": "$rate", "signal": "$signal"} +EOF diff --git a/.config/eww/scripts/set-brightness.sh b/.config/eww/scripts/set-brightness.sh new file mode 100755 index 0000000..0ce4eb7 --- /dev/null +++ b/.config/eww/scripts/set-brightness.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +if [[ "$1" =~ ^[0-9]+$ ]]; then + echo "$1" > /sys/class/backlight/amdgpu_bl1/brightness +elif [[ "$1" == "raise" ]]; then + swayosd-client --brightness raise +elif [[ "$1" == "lower" ]]; then + swayosd-client --brightness lower +fi + +eww update brightness=$(cat /sys/class/backlight/amdgpu_bl1/brightness) diff --git a/.config/eww/scripts/toggle-nf-state.sh b/.config/eww/scripts/toggle-nf-state.sh index bca3228..34d2f45 100755 --- a/.config/eww/scripts/toggle-nf-state.sh +++ b/.config/eww/scripts/toggle-nf-state.sh @@ -3,10 +3,13 @@ makoctl mode -t dnd if ! makoctl mode | grep -q dnd; then + eww update nf-enabled=true if [[ "$LANG" =~ ^fr ]]; then text="Notifications activées." else text="Notifications enabled." fi notify-send "$text" +else + eww update nf-enabled=false fi diff --git a/.config/hypr/hyprland.d/bindings.conf b/.config/hypr/hyprland.d/bindings.conf index d0c6b3e..97ca749 100644 --- a/.config/hypr/hyprland.d/bindings.conf +++ b/.config/hypr/hyprland.d/bindings.conf @@ -71,8 +71,8 @@ binde = , XF86AudioRaiseVolume, exec, swayosd-client --output-volume=raise binde = , XF86AudioLowerVolume, exec, swayosd-client --output-volume=lower binde = , XF86AudioMute, exec, swayosd-client --output-volume=mute-toggle binde = , XF86AudioMicMute, exec, swayosd-client --input-volume=mute-toggle -bindel = , XF86MonBrightnessUp, exec, swayosd-client --brightness raise -bindel = , XF86MonBrightnessDown, exec, swayosd-client --brightness lower +bindel = , XF86MonBrightnessUp, exec, $HOME/.config/eww/scripts/set-brightness.sh raise +bindel = , XF86MonBrightnessDown, exec, $HOME/.config/eww/scripts/set-brightness.sh lower # Media keys bindl = , XF86AudioPlay, exec, playerctl play-pause