Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

volume level widget crash #26

Open
retroj opened this issue Feb 16, 2018 · 0 comments
Open

volume level widget crash #26

retroj opened this issue Feb 16, 2018 · 0 comments
Labels

Comments

@retroj
Copy link
Owner

retroj commented Feb 16, 2018

This is an error with a widget in my own config, but I'm filing it here so I will remember to come back to it.

Here is the widget:

;; volume
;;

(define (alsa-volume-get-volume)
  (let loop ((lines (with-input-from-pipe
                     "amixer sget Master,0"
                     read-lines)))
    (if (null? lines)
        #f
        (let ((m (string-match
                  '(: (* any) "[" ($ (+ num)) "%] ["
                      ($ (+ alpha)) "]")
                  (first lines))))
          (if m
              (list (string->number (second m))
                    (if (equal? "off" (third m)) #f #t))
              (loop (rest lines)))))))

(define alsa-volume-format
  (match-lambda
    (#f "")
    ((? string? text) text)
    ((level #f) '(color (1 0 0 1) "MUTE"))
    ((level #t)
     (let* ((indicator "▁▂▄▆█")
            (indicator-length (string-length indicator))
            (n (inexact->exact (floor (* (min 100 level) 0.01 indicator-length)))))
       `(color (0.5 0.5 1 1)
               (font "DejaVu Sans Mono-8:bold"
                     ,(string-pad-right (substring indicator 0 n) indicator-length))
               ,(->string level))))))

(define (widget:alsa-volume)
  (widget:text
   format: alsa-volume-format
   init: (lambda (widget)
           (thread-start!
            (lambda ()
              (call-with-input-pipe
               "stdbuf -oL alsactl monitor"
               (lambda (port)
                 (let ((fileno (port->fileno port)))
                   (let loop ()
                     (thread-wait-for-i/o! fileno input:)
                     (read-line port)
                     (update widget (alsa-volume-get-volume))
                     (loop)))))))
           (update widget (alsa-volume-get-volume)))))

Here is the error. Not sure about steps to reproduce:

Warning (#<thread: thread1753>): in thread: (>) bad argument type: (color (0.5 0.5 1 1) (font "DejaVu Sans Mono-8:bold" "▁▂▄▆ ") "89")

        Call history:

        mowedline.scm:338: max          <--
@retroj retroj added the bug label Feb 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant