>>>>> Regarding 'Re: (message) function, minibuffer and Xwem'; Steve Youngs
>>>>> adds:
> Share the code, I'd love to see it.
Sure, the code is in my xwemrc
(http://ignotus.linuxforum.hu/rk-xwemrc.el), but I copy/paste it here
for the your convenience.
The display routine is at the very end, search for "(defun
xwem-mpd-osd-update"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; ////////////////////////////////////////////////////////////
;; music infrastructure:) it needs mpd (music playing daemon), see
;; http://musicpd.sourceforge.net/ or apt-get install mpd
(defvar mpd-process nil)
;; (mpd-start-connection)
(defun mpd-start-connection ()
(when (or (not mpd-process)
(not (eq mpd-process 'open)))
(setq mpd-process (open-network-stream "mpd"
" *mpd connection*"
"localhost" 6600))
(set-process-coding-system mpd-process 'utf-8 'utf-8)
(set-process-filter mpd-process 'mpd-process-filter)))
(defun mpd-reset-variables ()
(setq mpd-zero-vars-p t)
(setq **mpd-var-* nil **mpd-var-Album* nil **mpd-var-Artist* nil
**mpd-var-Date* nil **mpd-var-Genre* nil **mpd-var-Id* nil **mpd-var-Pos* nil
**mpd-var-Time* nil **mpd-var-Title* nil **mpd-var-Track* nil **mpd-var-ate*
nil **mpd-var-audio* nil **mpd-var-aylistlength* nil **mpd-var-bitrate* nil
**mpd-var-ck* nil **mpd-var-de* nil **mpd-var-dom* nil **mpd-var-e* nil
**mpd-var-file* nil **mpd-var-g* nil **mpd-var-h* nil **mpd-var-itle* nil
**mpd-var-length* nil **mpd-var-ndom* nil **mpd-var-olume* nil **mpd-var-om*
nil **mpd-var-peat* nil **mpd-var-playlist* nil **mpd-var-playlistlength* nil
**mpd-var-random* nil **mpd-var-repeat* nil **mpd-var-s* nil **mpd-var-song*
nil **mpd-var-songid* nil **mpd-var-state* nil **mpd-var-stlength* nil
**mpd-var-te* nil **mpd-var-time* nil **mpd-var-volume* nil **mpd-var-xfade*
nil))
;;(process-status mpd-process)
(defun mpd-send-string (string)
(case (process-status mpd-process)
('open (process-send-string mpd-process string))
('closed (mpd-start-connection)
(process-send-string mpd-process string))))
(defvar mpd-after-command-hook nil)
(defun mpd-stopped-p ()
(equal **mpd-var-state* "stop"))
(defun mpd-paused-p ()
(equal **mpd-var-state* "pause"))
;; (mpd-songpos)
(defun mpd-songpos ()
(if **mpd-var-time*
(destructuring-bind (a b)
(split-string **mpd-var-time* ":")
(cons (parse-integer a) (parse-integer b)))
(cons 0 1))) ;todo?
(defun mpd-volume-up ()
(interactive)
(mpd-send-string "volume +2\n")
; (run-hooks 'mpd-after-command-hook)
)
(defun mpd-volume-down ()
(interactive)
(mpd-send-string "volume -2\n")
; (run-hooks 'mpd-after-command-hook)
)
(defun mpd-seek (time)
(mpd-send-string (concat "seekid " **mpd-var-Id*
" " (number-to-string (+ (car (mpd-songpos)) time))
"\n"))
(run-hooks 'mpd-after-command-hook))
(defun mpd-seek-forward ()
(interactive)
(mpd-seek 10))
(defun mpd-seek-backward ()
(interactive)
(mpd-seek -10))
;; (mpd-next-track)
(defun mpd-next-track ()
(interactive)
(mpd-send-string "next\n")
(run-hooks 'mpd-after-command-hook)
)
(defun mpd-previous-track ()
(interactive)
(mpd-send-string "previous\n")
(run-hooks 'mpd-after-command-hook)
)
(defun mpd-stop ()
(interactive)
(mpd-send-string "stop\n")
(run-hooks 'mpd-after-command-hook)
)
(defun mpd-playpause ()
(interactive)
(if (mpd-stopped-p)
(mpd-send-string "play\n")
(mpd-send-string "pause\n"))
(run-hooks 'mpd-after-command-hook)
)
(defun mpd-process-filter (process output)
(with-temp-buffer
(insert output)
(goto-char (point-min))
(while (not (eobp))
(when (looking-at "\\(.*?\\): \\(.*\\)")
(set (intern (concat "**mpd-var-" (match-string 1) "*"))
(match-string 2)))
(forward-line 1)))
(when mpd-status-update-p
(xwem-mpd-osd-deferred-update) ;; MPD
(setq mpd-status-update-p nil)
(setq mpd-zero-vars-p nil)
))
(defvar mpd-zero-vars-p nil)
(defvar mpd-status-update-p nil)
(defun mpd-update-variables ()
(mpd-reset-variables)
(mpd-send-string "currentsong\n")
(setq mpd-status-update-p t)
(mpd-send-string "status\n")
)
;; ---- configuration // usage ----
(mpd-start-connection)
(add-hook 'mpd-after-command-hook 'mpd-update-variables)
;(add-hook 'mpd-after-command-hook 'xwem-mpd-osd-deferred-update t)
(run-with-timer 5 5 'mpd-update-variables)
(defun xwem-mpd-osd-deferred-update ()
(xwem-deffered-funcall 'xwem-mpd-osd-update))
(xwem-global-set-key [(XF86AudioRaiseVolume)] 'mpd-volume-up)
(xwem-global-set-key [(XF86AudioLowerVolume)] 'mpd-volume-down)
(xwem-global-set-key [(XF86AudioPlay)] 'mpd-playpause)
(xwem-global-set-key [(XF86AudioStop)] 'mpd-stop)
(xwem-global-set-key [(XF86AudioPrev)] 'mpd-previous-track)
(xwem-global-set-key [(XF86AudioNext)] 'mpd-next-track)
(xwem-global-set-key [(shift control XF86Forward)] 'mpd-seek-forward)
(xwem-global-set-key [(shift control XF86Back)] 'mpd-seek-backward)
;; (telnet "localhost" "6600")
(defvar xwem-mpd-osd nil)
(defvar xwem-mpd-osd-size-x 265)
(defvar xwem-mpd-osd-size-y 30)
;(progn (setq xwem-mpd-osd (xwem-osd-create-dock (xwem-dpy) xwem-mpd-osd-size-x
xwem-mpd-osd-size-y)) t)
;(xwem-osd-destroy xwem-mpd-osd)
;; (xwem-mpd-osd-update)
(defun xwem-mpd-osd-update ()
(unless mpd-zero-vars-p
(xwem-osd-offscreen xwem-mpd-osd)
(let* ((1stline (concat **mpd-var-Track*
". "
**mpd-var-Title*))
(2ndline (concat ;**mpd-var-Artist* ": "
**mpd-var-Album*
(if **mpd-var-Date*
(concat ", " **mpd-var-Date*))))
(vol-pos-y (if (< (length 2ndline)
(length 1stline))
14 0)))
(xwem-osd-text xwem-mpd-osd "")
(xwem-osd-text-add xwem-mpd-osd 0 0 1stline 2 "yellow")
(xwem-osd-text-add xwem-mpd-osd 0 14 2ndline 2 "yellow3")
; (xwem-osd-set-line-width xwem-mpd-osd 2)
(xwem-osd-line-add xwem-mpd-osd
0
(1- xwem-mpd-osd-size-y)
(destructuring-bind (a . b)
(mpd-songpos)
(truncate
(* xwem-mpd-osd-size-x
(/ (float a)
b))))
(1- xwem-mpd-osd-size-y)
0
"red")
(xwem-osd-text-add xwem-mpd-osd
(- xwem-mpd-osd-size-x 25)
vol-pos-y
(concat **mpd-var-volume* "%")
1
"white")
(when (or (mpd-stopped-p)
(mpd-paused-p))
(xwem-osd-text-add xwem-mpd-osd
(* 3 (/ xwem-mpd-osd-size-x 4))
3;(/ xwem-mpd-osd-size-y 4)
(or (and (mpd-stopped-p)
"SSS")
(and (mpd-paused-p)
"PPP"))
2
"red")
;; causes too much flicker
; (xwem-osd-rect-add xwem-mpd-osd
; (* 3 (/ xwem-mpd-osd-size-x 4))
; 3
; 20 20 4 "gray75" t)
)
t)
(xwem-osd-commit xwem-mpd-osd)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
--
Richard Klinda \/
/\ Show me your init.el and I'll you tell who you are.
|