(defwidget bar [] (centerbox :orientation "h" (workspaces :names active-workspaces :current-idx current-workspace) (music) (info))) (deflisten active-workspaces :initial "[]" "bash ./scripts/get-workspaces") (deflisten current-workspace :initial "1" "bash ./scripts/get-active-workspace") (defwidget workspaces [names current-idx] (box :halign "start" :hexpand false :space-evenly true :spacing "12" :css "* {margin-left: 20px; margin-right: 20px;}" (box :class {replace(captures(names, "\"[0-9]\"")[captures(current-idx, "[0-9]")[0][0]][0], "\"", "") == "1" ? "active-workspace" : "regular"} (label :text {names =~ `"1"` ? "" : ""})) (box :class {replace(captures(names, "\"[0-9]\"")[captures(current-idx, "[0-9]")[0][0]][0], "\"", "") == "2" ? "active-workspace" : "regular"} (label :text {names =~ `"2"` ? "" : ""})) (box :class {replace(captures(names, "\"[0-9]\"")[captures(current-idx, "[0-9]")[0][0]][0], "\"", "") == "3" ? "active-workspace" : "regular"} (label :text {names =~ `"3"` ? "" : ""})) (box :class {replace(captures(names, "\"[0-9]\"")[captures(current-idx, "[0-9]")[0][0]][0], "\"", "") == "4" ? "active-workspace" : "regular"} (label :text {names =~ `"4"` ? "" : ""})) (box :class {replace(captures(names, "\"[0-9]\"")[captures(current-idx, "[0-9]")[0][0]][0], "\"", "") == "5" ? "active-workspace" : "regular"} (label :text {names =~ `"5"` ? "" : ""})) (box :class {replace(captures(names, "\"[0-9]\"")[captures(current-idx, "[0-9]")[0][0]][0], "\"", "") == "6" ? "active-workspace" : "regular"} (label :text {names =~ `"6"` ? "" : ""})) (box :class {replace(captures(names, "\"[0-9]\"")[captures(current-idx, "[0-9]")[0][0]][0], "\"", "") == "7" ? "active-workspace" : "regular"} (label :text {names =~ `"7"` ? "" : ""})) (box :class {replace(captures(names, "\"[0-9]\"")[captures(current-idx, "[0-9]")[0][0]][0], "\"", "") == "8" ? "active-workspace" : "regular"} (label :text {names =~ `"8"` ? "" : ""})) (box :class {replace(captures(names, "\"[0-9]\"")[captures(current-idx, "[0-9]")[0][0]][0], "\"", "") == "9" ? "active-workspace" : "regular"} (label :text {names =~ `"9"` ? "" : ""})))) (defwidget info [] (box :class "side-stuff" :halign "end" :space-evenly false :spacing "25" (box :space-evenly false :spacing "10" (_volume :volume volume) (_battery :status {EWW_BATTERY.BAT0.status} :battery {EWW_BATTERY.BAT0.capacity})) (_network :strength net-strength :name net-name) (sep) (buttons))) (defvar eww "eww -c $HOME/.config/eww") (defwidget revealer-on-hover [toggle togglename ?transition ?duration] (eventbox :onhover "${eww} update ${togglename}=true" :onhoverlost "${eww} update ${togglename}=false" (box :space-evenly false (children :nth 0) (revealer :reveal toggle :transition {transition ?: "slideright"} :duration {duration ?: "300ms"} (children :nth 1))))) (defvar volume-visible false) (defwidget _volume [volume] (box :hexpand false :class {volume > 100 ? "alert" : "regular"} (revealer-on-hover :toggle volume-visible :togglename "volume-visible" (label :text {volume <= 0 ? "󰝟 " : volume < 33 ? "󰕿 " : volume < 66 ? "󰖀 " : volume < 99 ? "󰕾 " : "󱄡 "}) (label :text "${volume}%")))) (defvar battery-visible false) (defwidget _battery [status battery] (box :hexpand false :class {battery < 20 ? "alert" : "regular"} (revealer-on-hover :toggle battery-visible :togglename "battery-visible" (label :text {status == 'Charging' ? "󰂄" : battery < 20 ? "󰁻" : battery < 40 ? "󰁽" : battery < 60 ? "󰁿" : battery < 80 ? "󰂁" : "󰁹"}) (label :text "${battery}%")))) (defvar network-visible false) (defwidget _network [strength name] (box :hexpand false :vexpand true :class "regular" (revealer-on-hover :toggle network-visible :togglename "network-visible" :ransition "slidedown" (label :text {strength == "" ? "󰤮 " : strength < 26 ? "󰤟 " : strength < 51 ? "󰤢 " : strength < 76 ? "󰤥 " : "󰤨 "}) (label :text "${name} (${strength})")))) (defwidget buttons [] (box :halign "end" :hexpand false :space-evenly true :spacing "15" (box (button :onclick `hyprctl dispatch exit` "󰍃 ")) (box (button :onclick `reboot` " ")) (box (button :onclick `shutdown now` " ")))) (defwidget sep [] (box :hexpand false (label :class "sep" :text "|"))) (defpoll net-strength :interval "5s" :initial `N/A` `nmcli -t -f SIGNAL,ACTIVE device wifi | awk -F':' '{if($2=="yes")print$1}'`) (defpoll net-name :interval "60s" :initial "N/A" "nmcli -t -f NAME c show --active | head -n 1") (deflisten music :initial "" "playerctl --follow metadata --format '{{ artist }} - {{ title }}' || true") (defwidget music [] (box :class "music" :orientation "h" :space-evenly false :halign "center" {music != "" ? "🎵${music}" : ""})) (defpoll volume :interval "1s" "scripts/getvol") (defpoll time :interval "10s" "date '+%H:%M %b %d, %Y'") (defwindow bar :monitor 1 :exclusive true :windowtype "dock" :geometry (geometry :x "0%" :y "0%" :width "90%" :height "10px" :anchor "top center") :reserve (struts :side "top" :distance "4%") (bar))