eww: Added bar widget

This commit is contained in:
GaspardCulis 2024-01-25 14:39:08 +01:00
parent fca97c277e
commit 799fdb14fa
13 changed files with 387 additions and 1 deletions

63
bar/eww/bar.scss Normal file
View file

@ -0,0 +1,63 @@
.bar {
* {
color: #a4acc5;
font-family: "JetBrainsMono Nerd Font", "Font Awesome 6 Free";
font-weight: bold;
font-size: 16px;
}
.container {
margin: 0px 14px 0px 10px;
padding: 0px 10px 0px 10px;
border-radius: 10px;
background-color: #181926;
& > * + * {
margin-left: 20px;
}
}
.time {
color: #c8906e;
}
.connectivity {
color: #c7b68e;
}
.bluetooth {
color: #6e91ca;
}
.volume {
color: #6e91ca;
}
.mic {
color: #a286c8;
}
& * {
.normal {
color: #86b985;
}
.warning {
color: #be8d3e;
}
.critical {
color: #cb535e;
}
}
.workspaces {
.workspace-entry {
margin: 0px 3px 0px 3px;
padding: 0px 8px 0px 8px;
&.current {
background: #326bb9;
border-radius: 10px;
}
}
}
}

210
bar/eww/bar.yuck Normal file
View file

@ -0,0 +1,210 @@
; Static vars
(defvar GIGA 1073741824)
(defpoll time :interval "10s"
`date +" %H:%M  %a, %b %d"`)
(defpoll power_profile :interval "10s" :initial "" "~/.config/eww/scripts/power_profile")
(defpoll gpu_status :initial "active" :interval "2s" "cat /sys/bus/pci/devices/0000:01:00.0/power/runtime_status")
(defpoll refresh_rate :interval "10s" :initial "165" "~/.config/eww/scripts/refresh_rate")
(deflisten connectivity :initial '{"status": "down"}' "~/.config/eww/scripts/get-connectivity wlan0")
(deflisten bluetoothinfo :initial '{"count": 0}' "~/.config/eww/scripts/get-bluetooth-info")
(deflisten workspaces :initial "[]" "~/.config/eww/scripts/hypr/get-workspaces")
(deflisten current_workspace :initial "{\"id\": 1, \"title\": \"...\"}" "~/.config/eww/scripts/hypr/get-active-workspace")
(deflisten window_title :initial "{\"id\": 1, \"title\": \"...\"}" "~/.config/eww/scripts/hypr/get-window-title")
(deflisten volume :initial "{}" "~/.config/eww/scripts/get-volume")
(defwidget container [?nopadding]
(box
:class "container"
:style "padding: ${nopadding == true ? "0px" : "0px 10px 0px 10px"}"
:orientation "horizontal"
:halign "end"
:space-evenly false
(children))
)
(defwidget time []
(label
:class "time"
:text time)
)
(defwidget connectivity []
(label
:class "connectivity"
:text " ${connectivity.status == "down" ? "down" : connectivity.ssid}")
)
(defwidget bluetooth []
(eventbox
:onclick "bash -c 'blueman-manager &> /dev/null &'"
(label
:class "bluetooth"
:text " ${bluetoothinfo.count > 0 ? bluetoothinfo.count : bluetoothinfo.power}")
)
)
(defwidget workspaces [monitor]
(eventbox :onscroll "bash ~/.config/eww/scripts/hypr/change-active-workspace {} ${current_workspace}" :class "workspaces"
(box :space-evenly true
(label :text "${workspaces}${current_workspace}" :visible false)
(for workspace in workspaces
(eventbox :onclick "hyprctl dispatch workspace ${workspace.id}" :visible "${workspace.monitor == monitor}"
(box :class "workspace-entry ${workspace.id == current_workspace ? "current" : ""}"
(label :text "${workspace.id}")
)
)
)
)
)
)
(defwidget activewindow []
(label :text "${window_title ?: "..."}")
)
(defwidget ram []
(label
:text "󰍛 ${round(EWW_RAM.used_mem/GIGA, 1)}G/${round(EWW_RAM.total_mem/GIGA, 1)}G"
:class "${EWW_RAM.used_mem >= EWW_RAM.total_mem * 0.9 ? "critical" : EWW_RAM.used_mem >= EWW_RAM.total_mem * 0.6 ? "warning" : ""}")
)
(defwidget cpu []
(label
:text "󰻠 ${round(EWW_CPU.avg, 0)}%"
:class "${EWW_CPU.avg >= 90 ? "critical" : EWW_CPU.avg >= 60 ? "warning" :""}")
)
(defwidget temp []
(label
:text " ${EWW_TEMPS.ACPITZ_TEMP1}°C"
:class "${EWW_TEMPS.ACPITZ_TEMP1 >= 90 ? "critical" : EWW_TEMPS.ACPITZ_TEMP1 >= 70 ? "warning" : ""}")
)
(defvar PP_STATE '{"Quiet": "normal", "Balanced": "warning", "Performance": "critical"}')
(defwidget powerprofile []
(button :onclick "~/.config/eww/scripts/power_profile next"
(label
:text "󰈐 ${power_profile}"
:class "${PP_STATE[power_profile]}")
)
)
(defvar GPU_ICON '{"active": "󰍹", "suspended": "󰶐", "resuming": "󱄄"}')
(defvar GPU_STATE '{"active": "warning", "suspended": "normal", "resuming": "warning"}')
(defwidget gpustatus []
(label
:text "${GPU_ICON[gpu_status]} "
:class "${GPU_STATE[gpu_status]}")
)
(defwidget refreshrate []
(button :onclick "~/.config/eww/scripts/refresh_rate toggle"
(label
:text "${refresh_rate}Hz"
:class "${refresh_rate == "60" ? "normal" : "warning"}")
)
)
(defwidget battery []
(label
:text "${EWW_BATTERY.BAT0.status == "Discharging" ? "" : ""} ${EWW_BATTERY.BAT0.capacity}%"
:class "${EWW_BATTERY.BAT0.capacity <= 15 ? "critical" : EWW_BATTERY.BAT0.capacity <= 40 ? "warning" : "normal"}")
)
(defwidget volume []
(eventbox
:onclick "pamixer -t"
:onscroll "echo {} | sed 's/up/-i/g; s/down/-d/g' | xargs -I{} pamixer {} 1"
(label
:text "${volume.speaker == "Muted" ? "󰝟" : ""} ${volume.speaker}"
:class "volume"
)
)
)
(defwidget mic []
(eventbox
:onclick "pamixer --default-source -t"
:onscroll "echo {} | sed 's/up/-i/g; s/down/-d/g' | xargs -I{} pamixer --default-source {} 1"
(label
:text "${volume.mic == "Muted" ? "" : ""} ${volume.mic}"
:class "mic"
)
)
)
(defwidget leftstuff [monitor]
(box
:space-evenly false
(container
(time)
(connectivity)
(label :text "") ; Else container spacing rule doesn't apply
(bluetooth)
)
(container
:nopadding true
(workspaces :monitor monitor)
)
)
)
(defwidget centerstuff []
(container
(activewindow)
)
)
(defwidget rightstuff []
(box
:space-evenly false
:halign "end"
(container
(ram)
(cpu)
(temp)
(powerprofile)
(box :space-evenly false
(gpustatus)
(refreshrate)
)
(battery)
)
(container
(volume)
(label :text "") ; Else container spacing rule doesn't apply
(mic)
)
)
)
(defwidget barwidget [monitor]
(centerbox
:class "bar"
:orientation "horizontal"
(leftstuff :monitor monitor)
(centerstuff)
(rightstuff)
)
)
(defwindow bar [?monitor]
:namespace "eww.bar"
:monitor "${monitor ?: 0}"
:geometry (geometry
:x "0%"
:y "8px"
:width "100%"
:height "38px"
:anchor "top center")
:stacking "fg"
:focusable false
:exclusive true
(barwidget :monitor "${monitor ?: 0}")
)

View file

@ -1,4 +1,4 @@
* {
@import "./bar.scss" * {
all: unset;
font-family: "FiraCode Nerd Font";
}

View file

@ -1,3 +1,5 @@
(include "./bar.yuck")
(defpoll bots
:initial `[]`
:interval "3s"

View file

@ -0,0 +1,12 @@
#!/bin/bash
info (){
power=$(bluetoothctl show | grep Powered | awk '{print $2}' | sed 's/yes/on/g; s/no/off/g')
count=$(bluetoothctl devices Connected | wc -l)
echo "{\"power\": \"${power}\", \"count\": \"${count}\"}"
}
info
dbus-monitor "interface=org.blueman.Applet" | while read -r line; do
info
done

View file

@ -0,0 +1,18 @@
#!/bin/dash
if=$1
status (){
status=$(cat /sys/class/net/wlan0/operstate)
if [ "$status" != "down" ]; then
ssid=$(iw dev wlan0 link | grep SSID | awk '{print $2}')
fi
echo "{\"status\": \"$status\", \"ssid\": \"$ssid\"}"
}
status
iwevent 2> /dev/null | while read -r line; do
status
done

12
bar/eww/scripts/get-volume Executable file
View file

@ -0,0 +1,12 @@
#!/bin/bash
volume (){
vol=$(pamixer --get-volume-human)
mic_vol=$(pamixer --default-source --get-volume-human)
echo "{\"speaker\": \"${vol^}\", \"mic\": \"${mic_vol^}\"}"
}
volume
pactl subscribe | grep --line-buffered "'change'" | while read -r line; do
volume
done

View file

@ -0,0 +1,22 @@
#!/bin/dash
function clamp {
min=$1
max=$2
val=$3
python -c "print(max($min, min($val, $max)))"
}
direction=$1
current=$2
if test "$direction" = "down"
then
target=$(clamp 1 10 $(($current+1)))
echo "jumping to $target"
hyprctl dispatch workspace $target
elif test "$direction" = "up"
then
target=$(clamp 1 10 $(($current-1)))
echo "jumping to $target"
hyprctl dispatch workspace $target
fi

View file

@ -0,0 +1,6 @@
#!/bin/dash
hyprctl monitors -j | jq '.[] | select(.focused) | .activeWorkspace.id'
socat -u UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock - |
stdbuf -o0 awk -F '>>|,' -e '/^workspace>>/ {print $2}' -e '/^focusedmon>>/ {print $3}'

View file

@ -0,0 +1,4 @@
#!/bin/dash
hyprctl activewindow -j | jq --raw-output .title
socat -u UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock - | stdbuf -o0 awk -F '>>|,' '/^activewindow>>/{print $3}'

View file

@ -0,0 +1,11 @@
#!/bin/dash
spaces (){
hyprctl workspaces -j | jq -c 'map({id: .id, windows: .windows, monitor: .monitorID})'
}
spaces
socat -u UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock - | while read -r line; do
spaces
done

10
bar/eww/scripts/power_profile Executable file
View file

@ -0,0 +1,10 @@
#!/bin/dash
if [ "$1" = "next" ]; then
asusctl profile -n
profile=$(asusctl profile -p | sed s:'Active profile is '::)
eww update power_profile="$profile"
else
asusctl profile -p | sed s:'Active profile is '::
fi

16
bar/eww/scripts/refresh_rate Executable file
View file

@ -0,0 +1,16 @@
#!/bin/dash
refresh_rate=$(hyprctl -j monitors | jq '.[0].refreshRate | round')
if [ "$1" = "toggle" ]; then
if [ "$refresh_rate" = "60" ]; then
hyprctl keyword monitor eDP-1,2560x1440@165,auto,1
refresh_rate=165
else
hyprctl keyword monitor eDP-1,2560x1440@60,auto,1
refresh_rate=60
fi
eww update refresh_rate="$refresh_rate"
else
echo "$refresh_rate"
fi