[eww] Add brightness, network & notifications widgets

This commit is contained in:
Viyurz 2024-11-04 11:40:49 +01:00
parent e4301645d1
commit 962fdf8c30
Signed by: Viyurz
SSH key fingerprint: SHA256:IskOHTmhHSJIvAt04N6aaxd5SZCVWW1Guf9tEcxIMj8
5 changed files with 56 additions and 5 deletions

View file

@ -1,5 +1,5 @@
; Brightness ; 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-icons '["", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]')
(defvar brightness-slide false) (defvar brightness-slide false)
@ -12,8 +12,11 @@
(defpoll day :interval "1m" :initial "1" "date +'%d'") (defpoll day :interval "1m" :initial "1" "date +'%d'")
(defpoll year :interval "1m" :initial "0" "date +'%Y'") (defpoll year :interval "1m" :initial "0" "date +'%Y'")
; Network
(defpoll network :initial '{"if": "lo"}' :interval "2s" "~/.config/eww/scripts/get-network.sh")
; Notifications status ; 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 ; Packages updates
(deflisten packages-updates :initial '{"count": "-", "class": " "}' "~/.config/eww/scripts/pkg-updates.sh") (deflisten packages-updates :initial '{"count": "-", "class": " "}' "~/.config/eww/scripts/pkg-updates.sh")
@ -38,6 +41,7 @@
) )
(nf-state) (nf-state)
(packages-updates) (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 [] (defwidget bar-middle []
(label :limit-width 2 (label :limit-width 2
@ -109,7 +120,7 @@
(scale :value {brightness} (scale :value {brightness}
:min 0 :min 0
:max 255 :max 255
:onchange "echo {} > /sys/class/backlight/amdgpu_bl1/brightness" :onchange "~/.config/eww/scripts/set-brightness.sh {}"
) )
) )
) )

View file

@ -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

View file

@ -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)

View file

@ -3,10 +3,13 @@
makoctl mode -t dnd makoctl mode -t dnd
if ! makoctl mode | grep -q dnd; then if ! makoctl mode | grep -q dnd; then
eww update nf-enabled=true
if [[ "$LANG" =~ ^fr ]]; then if [[ "$LANG" =~ ^fr ]]; then
text="Notifications activées." text="Notifications activées."
else else
text="Notifications enabled." text="Notifications enabled."
fi fi
notify-send "$text" notify-send "$text"
else
eww update nf-enabled=false
fi fi

View file

@ -71,8 +71,8 @@ binde = , XF86AudioRaiseVolume, exec, swayosd-client --output-volume=raise
binde = , XF86AudioLowerVolume, exec, swayosd-client --output-volume=lower binde = , XF86AudioLowerVolume, exec, swayosd-client --output-volume=lower
binde = , XF86AudioMute, exec, swayosd-client --output-volume=mute-toggle binde = , XF86AudioMute, exec, swayosd-client --output-volume=mute-toggle
binde = , XF86AudioMicMute, exec, swayosd-client --input-volume=mute-toggle binde = , XF86AudioMicMute, exec, swayosd-client --input-volume=mute-toggle
bindel = , XF86MonBrightnessUp, exec, swayosd-client --brightness raise bindel = , XF86MonBrightnessUp, exec, $HOME/.config/eww/scripts/set-brightness.sh raise
bindel = , XF86MonBrightnessDown, exec, swayosd-client --brightness lower bindel = , XF86MonBrightnessDown, exec, $HOME/.config/eww/scripts/set-brightness.sh lower
# Media keys # Media keys
bindl = , XF86AudioPlay, exec, playerctl play-pause bindl = , XF86AudioPlay, exec, playerctl play-pause