.stumpwmrc 0.5

; -*-lisp-*-

;;; 0.5

;; 2008/01/09

;; Moved all the audio commands to un-numlocked keypad. Who uses those keys anyway?
;; Don't need the prefix key this way either, much more efficient.

;; Added Fluxbox-style alt-F# virtual desktop (group in StumpWM speak) switch. Modified from:
;; http://hcl-club.lu/svn/development/lisp/.stumpwmrc

;; Replaced call to (mode-line) with something more intelligent. Found at:
;; http://hcl-club.lu/svn/development/lisp/.stumpwmrc

(in-package :stumpwm)

;;; Internal variable definitions.

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

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

(defparameter MPD-HOST "")
(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".
(defun mpc (host port pass command) "Pass commands to MPD."
  (with-open-stream  (socket (socket:socket-connect port host :timeout 1))
   (format socket "password ~a~%" pass)
   (format socket "~a~%" command)))

;; To be replaced.
(defun current-song-info () "Return current song information from MPD."
  (run-shell-command "mpc | head -n 1 | tr -d '\\n'" t))

;;; 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 ~/.xmodmap, 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.
(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 (current-song-info)) ; 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)
    (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_Down") "mpc-volume-down")
(define-key *top-map* (kbd "KP_Add") "mpc-volume-up") ; Redundant
(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-key *top-map* (kbd "KP_Enter") "mpc-status")
(define-key *top-map* (kbd "KP_Insert") "mpc-status") ; Redundant

(define-stumpwm-command "mpc-status" () "Shows current MPD status and song info. MPC's default output."
 (run-shell-command "mpc" t))

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

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

(define-stumpwm-command "mpc-song-next" () "Switches MPD playback to next song."

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

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

January 9, 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: