;;time
(defwindow time_1
           :monitor 1
           :geometry (geometry :x "50px"
                               :y "50px"
                               :width "25%"
                               :height "200px"
                               :anchor "bottom right")
           :stacking "bg"
           :reserve (struts :distance "40px" :side "top")
           :windowtype "dock"
           :wm-ignore false
     (clock))

(defwindow time_0
           :monitor 0
           :geometry (geometry :x "50px"
                               :y "50px"
                               :width "25%"
                               :height "200px"
                               :anchor "top right")
           :stacking "bg"
           :reserve (struts :distance "40px" :side "top")
           :windowtype "dock"
           :wm-ignore false
     (clock))

(defpoll CLOCK :interval "4s" "date +'{\"hour\":\"%I\",\"min\":\"%M\",\"mer\":\"%p\",\"day\":\"%A\"}'")

(defwidget clock [] 
      (box :class "genwin" :orientation "h" :spacing 50 :space-evenly false :vexpand "false" :hexpand "false" 
            (box :orientation "h" :spacing 0
                  (label :class "time_hour" :valign "start" :wrap "true" :limit-width 25 :text "${CLOCK.hour}")
                  (label :class "time_min" :valign "end" :wrap "true" :limit-width 25 :text "${CLOCK.min}"))
            (box :orientation "v" :spacing 0 :space-evenly true
                  (label :class "time_mer" :valign "start" :halign "end" :wrap "true" :limit-width 25 :text "${CLOCK.mer}")
                  (label :class "time_day" :valign "end" :halign "end" :wrap "true" :limit-width 25 :text "${CLOCK.day}"))))

;; music
(defwindow music_0
           :monitor 0
           :geometry (geometry :x "50"
                               :y "50"
                               :width "30%"
                               :height "40px"
                               :anchor "bottom right")
           :stacking "bg"
           :reserve (struts :distance "10px" :side "bottom")
           :windowtype "dock"
           :wm-ignore true
     (music))

(defwindow music_1
           :monitor 1
           :geometry (geometry :x "50"
                               :y "50"
                               :width "30%"
                               :height "40px"
                               :anchor "bottomleft")
           :stacking "bg"
           :reserve (struts :distance "10px" :side "bottom")
           :windowtype "dock"
           :wm-ignore true
     (music))

(defpoll song :interval "2s" "./script songdata")
(defpoll STATUS :interval "0.4s" "./script status")
(defpoll CURRENT :interval "0.4s" "./script time")
(defpoll LYRICS :interval "0.4s" "./script lyrics")

(defwidget music []
      (box :class "genwin" :orientation "h" :spacing 50 :space-evenly "false" :vexpand "false" :hexpand "false" 
            
            (box :orientation "v" :spacing 20 :space-evenly "false" :vexpand "false" :hexpand "false" 
                  (label :tooltip "${song.name}" :halign "center" :class "song" :wrap "false" :limit-width 32 :text "${song.name}")
                  (label :halign "center" :class "artist" :wrap "false" :limit-width 20 :text "${song.artist}")
                  (box :orientation "h" :spacing 80 :halign "center" :space-evenly "true" :vexpand "false" :hexpand "false" 
                        (button :class "btn_controls" :tooltip "History : ${song.prev}" :onclick "./script prev" "󰒮")
                        (button :class "btn_controls" :tooltip "Seek -1%" :onclick "./script seek '-1'" "")
                        (button :class "btn_play" :onclick "./script play_toggle" STATUS)
                        (button :class "btn_controls" :tooltip "Seek +1%" :onclick "./script seek '1'" "")
                        (button :class "btn_controls" :tooltip "Upcoming : ${song.next}" :onclick "./script next" "󰒭"))
                  (label :wrap "true" :class "lyrics" :text LYRICS))
           (box :class "box_art" :vexpand "false" :hexpand "false"
                  (circular-progress :class "music_bar" :value CURRENT :thickness 10 :clockwise true :start-at "${(CURRENT+75)%100}"
                        (image :path "${song.cover}" :image-height 270 :image-width 270)))))
