(hello

‘world)

.stumpwmrc 0.6


; -*-lisp-*-

;;; 0.6

;; 2008/01/11

;; Renamed (mpc) to (mpd-command).
;; Wrote that custom (current-song-info), and changed its name to (mpd-info).
;; It uses CL-PPCRE but we don't need to :use it, StumpWM already does.
;; And neither of them are likely portable, though it would be trivial to make them so if anyone cared.
;; Would have done it sooner but I was too busy passing my NREMT-B license exam.

(in-package :stumpwm)

;;; Internal variable definitions.

(defparameter FOREGROUND-COLOR "green")
(defparameter BACKGROUND-COLOR "black")
(defparameter BORDER-COLOR FOREGROUND-COLOR)

(setf *format-time-string-default* "%a %b %e %k:%M")

(defparameter MPD-HOST "127.0.0.1")
(defparameter MPD-PORT 2100)
(defparameter MPD-PASS "")

;;; Internal function definitions.

;; Found at:
;; http://en.wikipedia.org/wiki/User:Gwern/.stumpwmrc
(defun cat (&rest strings) "A shortcut for (concatenate 'string foo bar)."
  (apply 'concatenate 'string strings))

;;; My MPD "client". It's pretty clunky, but it works.

;; These are used by mpd-info.
(defvar artist-scanner (cl-ppcre:create-scanner "^Artist:\\s(.*)"))
(defvar title-scanner (cl-ppcre:create-scanner "^Title:\\s(.*)"))

;; Returns "(Artist - Title)"
(defun mpd-info (host port pass) "Return current song information from MPD."
  (with-open-stream  (socket (socket:socket-connect port host)) ; Likely unportable from CLISP.
    (format socket "password ~a~%" pass)
    (format socket "currentsong~%")
    (cat (loop :for line = (read-line socket nil nil) :while line
           :do (if (cl-ppcre:scan artist-scanner line)
                  (return (subseq (cl-ppcre:scan-to-strings artist-scanner line) 8))))
         " - "
         (loop :for line = (read-line socket nil nil) :while line
           :do (if (cl-ppcre:scan title-scanner line)
                  (return (subseq (cl-ppcre:scan-to-strings title-scanner line) 7)))))))

;; This sends our vol up/down and prev/next song and pause/unpause commands.
(defun mpd-command (host port pass command) "Pass commands to MPD."
  (with-open-stream  (socket (socket:socket-connect port host :timeout 1)) ; Likely unportable from CLISP.
   (format socket "password ~a~%" pass)
   (format socket "~a~%" command)))

;;; Theme.

;; Window border colors.
(set-focus-color FOREGROUND-COLOR)
(set-unfocus-color BACKGROUND-COLOR)

;; Input box colors.
(set-fg-color FOREGROUND-COLOR)
(set-bg-color BACKGROUND-COLOR)
(set-border-color BORDER-COLOR)

;; Modeline colors.
(setf *mode-line-foreground-color* FOREGROUND-COLOR)
(setf *mode-line-background-color* BACKGROUND-COLOR)
(setf *mode-line-border-color* BORDER-COLOR)

;; Background.
(run-shell-command (cat "xsetroot -solid " BACKGROUND-COLOR))

;;; Init stuff.

;; Make frames 1-indexed.
;; See: http://lists.gnu.org/archive/html/stumpwm-devel/2006-08/msg00002.html
;; Found at: http://en.wikipedia.org/wiki/User:Gwern/.stumpwmrc
(setf *frame-number-map* "1234567890") ; Still doesn't seem to work.

;; Rename the first group to Browse and create the other groups.
;; Found at: http://en.wikipedia.org/wiki/User:Gwern/.stumpwmrc
(setf (group-name (first (screen-groups (current-screen)))) "Browse")
(run-commands "gnewbg Edit" "gnewbg Term" "gnewbg Comms" "gnewbg Misc")

;; Change the prefix key
;; keycode 115 = F20 in ~/.xmodmaprc, 115 being the left "windows" key.
(set-prefix-key (kbd "F20"))

;; Set up X cursor and colors.
(run-shell-command (cat "xsetroot -cursor_name left_ptr -fg " BACKGROUND-COLOR ; Cursor body
                                                      " -bg " BORDER-COLOR)) ; Cursor outline

;; Keep the X cursor out of the way. Even when I want it.
(run-with-timer 5 5 'banish-pointer)

;; Configure and start the modeline. Colors are handled above.
(setf *mode-line-border-width* 1)
(setf *mode-line-pad-x* 1)
(setf *mode-line-pad-y* 1)
(setf *mode-line-position* :bottom)
(setf *mode-line-timeout* 10) ; Update every 10 seconds if nothing else has triggered it already.
(setf *screen-mode-line-format* (list "(%n %w) (" ; Current group and frames
                                      `(:eval (format-time-string))
                                      ") (" ; Just a spacer
                                      `(:eval (mpd-info MPD-HOST MPD-PORT MPD-PASS)) ; Defined above
                                      ")"))

;; Switch mode-line on only if needed. Found at:
;; http://hcl-club.lu/svn/development/lisp/.stumpwmrc
(if (not (head-mode-line (current-head)))
     (toggle-mode-line (current-screen) (current-head)))

;; Found this tidbit browsing the source. Defaults to :ignore
(setf *mouse-focus-policy* :click) ; I'm fucking lame.

;;; Keyboard shortcuts.

;; Fluxbox-style Alt-F# virtual desktop (group in StumpWM-speak) switching. Modified from:
;; http://hcl-club.lu/svn/development/lisp/.stumpwmrc
(dotimes (i 13)
  (unless (eq i 0) ; F0 is non-existant and will error.
    (define-key *top-map* (kbd (format nil "M-F~a" i)) (format nil "gselect ~a" i))))

;; Applications.
(define-key *root-map* (kbd "b") "exec firefox ")
(define-key *root-map* (kbd "e") "exec xemacs ")
(define-key *root-map* (kbd "c") (cat "exec urxvt -fg " FOREGROUND-COLOR
                                                " -bg " BACKGROUND-COLOR
                                                " -pr " FOREGROUND-COLOR
                                                " +sb "))

;; Audio controls, uses un-numlocked keypad.
;; Some keys duplicated, not sure which I prefer yet.
(define-key *top-map* (kbd "KP_Up")       "mpc-volume-up")
(define-key *top-map* (kbd "KP_Add")      "mpc-volume-up") ; Redundant
(define-key *top-map* (kbd "KP_Down")     "mpc-volume-down")
(define-key *top-map* (kbd "KP_Subtract") "mpc-volume-down") ; Redundant
(define-key *top-map* (kbd "KP_Left")     "mpc-song-prev")
(define-key *top-map* (kbd "KP_Right")    "mpc-song-next")
(define-key *top-map* (kbd "Num_Lock")    "mpc-pause") ; The light indicates play/pause ;)

(define-stumpwm-command "mpc-volume-up" () "Increase MPD playback volume."
 (mpd-command MPD-HOST MPD-PORT MPD-PASS "volume +5"))

(define-stumpwm-command "mpc-volume-down" () "Decrease MPD playback volume."
 (mpd-command MPD-HOST MPD-PORT MPD-PASS "volume -5"))

(define-stumpwm-command "mpc-song-next" () "Switches MPD playback to next song."
 (mpd-command MPD-HOST MPD-PORT MPD-PASS "next"))

(define-stumpwm-command "mpc-song-prev" () "Switches MPD playback to previous song."
 (mpd-command MPD-HOST MPD-PORT MPD-PASS "previous"))

(define-stumpwm-command "mpc-pause" () "Pause/unpause MPD"
 (mpd-command MPD-HOST MPD-PORT MPD-PASS "pause"))

January 13, 2008 - Posted by | Common Lisp, StumpWM

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: