feat(eww): Add simple bluetooth widget

This commit is contained in:
Viyurz 2024-11-19 09:37:19 +01:00
parent b80c011052
commit 2be407b7c9
Signed by: Viyurz
SSH key fingerprint: SHA256:IskOHTmhHSJIvAt04N6aaxd5SZCVWW1Guf9tEcxIMj8
3 changed files with 62 additions and 0 deletions

View file

@ -6,6 +6,9 @@
; Battery ; Battery
(defvar battery-icons '{"Full": {"10": "󰂄"}, "Charging": ["󰢟", "󰢜", "󰂆", "󰂇", "󰂈", "󰢝", "󰂉", "󰢞", "󰂊", "󰂋", "󰂅"], "Discharging": ["󰂎", "󰁺", "󰁻", "󰁼", "󰁽", "󰁾", "󰁿", "󰂀", "󰂁", "󰂂", "󰁹"]}') (defvar battery-icons '{"Full": {"10": "󰂄"}, "Charging": ["󰢟", "󰢜", "󰂆", "󰂇", "󰂈", "󰢝", "󰂉", "󰢞", "󰂊", "󰂋", "󰂅"], "Discharging": ["󰂎", "󰁺", "󰁻", "󰁼", "󰁽", "󰁾", "󰁿", "󰂀", "󰂁", "󰂂", "󰁹"]}')
; Bluetooth
(deflisten bluetooth :initial "{}" "~/.config/eww/scripts/get-bluetooth.sh")
; DateTime ; DateTime
(defpoll datetime :interval "1s" "date +'%a %-e %b %X'") (defpoll datetime :interval "1s" "date +'%a %-e %b %X'")
(defpoll month :interval "1m" :initial "1" "date +'%m'") (defpoll month :interval "1m" :initial "1" "date +'%m'")
@ -46,6 +49,7 @@
(packages-updates) (packages-updates)
(volume) (volume)
(network) (network)
(bluetooth)
) )
) )
@ -118,8 +122,24 @@
) )
) )
(defwidget bluetooth []
(eventbox :onclick "~/.config/eww/scripts/toggle-bluetooth-state.sh"
(label :text "${bluetooth.icon} ${bluetooth.device}"
:class "${bluetooth.state}"
)
)
)
(defwidget bar-middle [] (defwidget bar-middle []
(box :halign "center"
:spacing 12
:space-evenly false
(title)
)
)
(defwidget title []
(label :limit-width 42 (label :limit-width 42
:show-truncated false :show-truncated false
:text "${window-title}" :text "${window-title}"

View file

@ -0,0 +1,30 @@
#!/bin/bash
interval=2
function get {
unset icon state device
if bluetoothctl show | grep -q 'Powered: no'; then
icon="󰂲"
state="disabled"
device="Disabled"
else
icon="󰂯"
state="powered"
device="Not connected"
fi
cat << EOF
{"icon": "$icon", "state": "$state", "device": "$device"}
EOF
}
if [[ "$1" == "once" ]]; then
get
else
while :; do
get
sleep $interval
done
fi

View file

@ -0,0 +1,12 @@
#!/bin/bash
if [[ $(bluetoothctl show | grep Powered: | cut -f 2 -d ' ') == "no" ]]; then
if [[ ! $(bluetoothctl power on) ]]; then
rfkill block bluetooth
rfkill unblock bluetooth
fi
else
bluetoothctl power off
fi
eww update bluetooth="$(~/.config/eww/scripts/get-bluetooth.sh once)"