From: Christophe Rhodes Date: Wed, 26 Mar 2014 11:07:02 +0000 (+0000) Subject: mouse events for mixer sliders X-Git-Url: http://christophe.rhodes.io/gitweb/?a=commitdiff_plain;h=81056f7e38b56257fd1cabbb205250e251ca647b;p=squeeze-el.git mouse events for mixer sliders Sure, why not? --- diff --git a/squeeze.el b/squeeze.el index d71a503..5ca2f7c 100644 --- a/squeeze.el +++ b/squeeze.el @@ -222,16 +222,26 @@ (defvar squeeze-control-mixer-map (let ((map (make-sparse-keymap))) - (define-key map (kbd "RET") 'squeeze-control-mixer-foo) + (define-key map (kbd "RET") 'squeeze-control-mixer-set-volume) + (define-key map [mouse-1] 'squeeze-control-mixer-mouse-1) map)) -(defun squeeze-control-mixer-foo () +(defun squeeze-control-compute-volume (pos) + (let* ((end (next-single-property-change pos 'keymap)) + (start (previous-single-property-change end 'keymap))) + (/ (* 100 (- (point) start)) (- end start 1)))) + +(defun squeeze-control-mixer-mouse-1 (event) + (interactive "e") + (let* ((pos (cadadr event)) + (val (squeeze-control-compute-volume pos)) + (id (get-text-property pos 'squeeze-playerid))) + (squeeze-control-volume-set id val))) + +(defun squeeze-control-mixer-set-volume () (interactive) - (let* ((end (next-single-property-change (point) 'keymap)) - (start (previous-single-property-change end 'keymap)) - (val (/ (* 100 (- (point) start)) (- end start 1))) + (let* ((val (squeeze-control-compute-volume (point))) (id (get-text-property (point) 'squeeze-playerid))) - (message "start %d, end %d, val %d" start end val) (squeeze-control-volume-set id val))) (defun squeeze-control-display-players () @@ -249,6 +259,7 @@ (insert (propertize (squeeze-mixer-make-bar (squeeze-player-volume player) 28) 'squeeze-playerid (squeeze-player-playerid player) 'keymap squeeze-control-mixer-map + 'pointer 'hdrag 'rear-nonsticky '(keymap)))) (insert (propertize "\n" 'intangible t))) (read-only-mode 1))))