
(defwindow bar [monitor]
  :monitor monitor
  :class "ewwbar"
  :windowtype "dock"
  :geometry (geometry :x "0%"
                      :y "1%"
                      :width "99%"
                      :height "20px"
                      :anchor "top center")
                      :exclusive true
  (bar :monitor_ monitor))

(defpoll battery :interval "2s"
  "scripts/batteryperc")



(defwidget bar [monitor_]
  (centerbox :orientation "h"
	(winsworks :monitor monitor_)
    (music)
    (sidestuff)))

(defwidget winsworks [monitor]
	(box :orientation "h" :space-evenly false :halign "start"
		(box :class "music" {"${battery}"})
		(workspaceWidget :monitor monitor)
		(box :onclick "scripts/windowswitcher" :class "music" {" ${activewindow}"})
        	)
)

(defwidget sidestuff []
  (box :class "sidestuff" :orientation "h" :space-evenly false :halign "end"
    (box :class "music" {"󰛳 ${IP}"}) 
    (metric :label "󰓃"
            :value volume
            :onchange "pactl set-sink-volume @DEFAULT_SINK@ {}%")
    (metric :label ""
            :value {round((1 - (EWW_DISK["/"].free / EWW_DISK["/"].total)) * 100, 0)}
            :onchange "")
	(clock)
    ))

(defwidget music []
  (box :class "music"
       :orientation "h"
       :space-evenly false
       :halign "center"
    {music != "" ? " ${music}" : " None"}))


(defwidget metric [label value onchange]
  (box :orientation "h"
       :class "metric"
       :space-evenly false
    (box :class "label" label)
    (scale :min 0
           :max 101
           :active {onchange != ""}
           :value value
           :onchange onchange)))

(deflisten workspaces "hyprland-workspaces _")

(defwidget workspaceWidget [monitor]
  (eventbox :onscroll "hyprctl dispatch workspace `echo {} | sed 's/up/+/\' | sed 's/down/-/'`1"
    (box :class "workspaces"
         :space-evenly false
         :width 20
      (for i in {workspaces[monitor].workspaces}
        (button
          :width 20
          :onclick "hyprctl dispatch workspace ${i.id}"
          :class "${i.class}"
          {i.name == "special:magic" ? "󱂬" : "󱂬${i.name}"})))))


(deflisten workspace-old "scripts/workspace")
(defwidget workspaces-old []
(literal :content workspace-old))

(defpoll music :interval "0.5s"
  "scripts/playerget")


(defpoll activewindow :interval "0.5s"
  "scripts/activewindow")


(defpoll IP :interval "5s"
  "scripts/ip")

(defpoll volume :interval "0.5s"
  "scripts/getvol")

(defpoll time :interval "1s"
  "date '+%H:%M:%S|%d.%m.%Y'")

(defwidget clock []
	(box	:class "clock"
		(label	:text {"${time}"})
	)
)
