(defwidget volume_button [desktop]
  (eventbox
    :onscroll "widgets/volume/setvolume {}"
    :onclick "amixer sset Master ${mute_save} && ${muted ? '${update_mute_save}\'0%\' && ${update_muted}false' : '${update_mute_save}${desktop ? volume_percent_desktop : volume_percent_laptop} && ${update_muted}true' }"
    (box :class "volume_button"
      (circular-progress :class "scale"
      :value {replace(desktop ? volume_percent_desktop : volume_percent_laptop, "%", "")}
      :start-at 75
      :thickness 2.5
      :clockwise true
      :width 24
        (image
          :image-width 16
          :path {replace(desktop ? volume_percent_desktop : volume_percent_laptop, "%", "") == 100 ? vol_high_icon : replace(desktop ? volume_percent_desktop : volume_percent_laptop, "%", "") <= 0 ? vol_mute_icon : replace(desktop ? volume_percent_desktop : volume_percent_laptop, "%", "") <= 25 ? vol_low_icon : replace(desktop ? volume_percent_desktop : volume_percent_laptop, "%", "") <= 75 ? vol_mid_icon : vol_high_icon})))))

(defpoll volume_percent_laptop :interval "0.1s" "awk -F\"[][]\" '/Mono:/ { print $2 }' <(amixer sget Master)") 
(defpoll volume_percent_desktop :interval "0.1s" "awk -F\"[][]\" '/Left:/ { print $2 }' <(amixer sget Master)") 

(defvar mute_save "0%")
(defvar muted false)

(defvar update_mute_save "eww update mute_save=")
(defvar update_muted "eww update muted=")

(defvar vol_high_icon "widgets/volume/high-icon.png")
(defvar vol_mute_icon "widgets/volume/mute-icon.png")
(defvar vol_low_icon "widgets/volume/low-icon.png")
(defvar vol_mid_icon "widgets/volume/mid-icon.png")
