.stumpwmrc 0.3

Moved all the audio controls to their own keymap,
*screen-mode-line-format* now calls functions for its display instead of running the commands right there,
the current song portion of which became big and hairy,
now have click-to-focus,
and general cleanups.

— cut ———————————————————————————————

; -*-lisp-*-;;; .stumpwmrc 0.3

(in-package :stumpwm)

;;; Internal variable definitions.

(defparameter FOREGROUND-COLOR "green")

(defparameter BACKGROUND-COLOR "black")


;;; Internal function definitions.

;; Taken from http://en.wikipedia.org/wiki/User:Gwern/.stumpwmrc

(defun cat (&rest strings) "A shortcut for (concatenate 'string foo bar)."

  (apply 'concatenate 'string strings))

;; This function turns:


;; Wumpscut - Cannibal Anthem

;; [playing] #1506/1750   3:53/4:00 (97%)

;; volume: 70%   repeat: off   random: on


;; into:


;; Wumpscut - Cannibal Anthem (playing (97%)) (vol (70%))


;; It is, however, convoluted. I'm considering whether to call an external script

;; or just open a socket to MPD from here.

(defun current-song-info () "Return current song information from MPD."

  (cat (run-shell-command "mpc | tee .tmpmpc | head -n 1 | tr -d '\\n'" t)

       " ("

       (run-shell-command "cat .tmpmpc | head -n 2 | tail -n 1 | tr -s ' ' | cut -d\\  -f 1,4 | tr -d []'\\n'" t)

       ") (vol ("

       (run-shell-command "cat .tmpmpc | tail -n 1 | cut -d : -f 2 | cut -c 1-4 | tr -d ' ''\\n' && rm .tmpmpc" t)


(defun current-date () "Returns the date formatted as: Mon Jan 7 02:27"

  (run-shell-command "date '+%a %b %e %H:%M' | tr -d '\\n'" t)) ; Formatted as: Mon Jan 7 02:27

;;; Theme.

;; Window border colors.

(set-focus-color FOREGROUND-COLOR)

(set-unfocus-color BACKGROUND-COLOR)

;; Input box colors.

(set-bg-color BACKGROUND-COLOR)

(set-fg-color FOREGROUND-COLOR)

(set-border-color BORDER-COLOR)

;; Modeline colors.

(setf *mode-line-background-color* BACKGROUND-COLOR)

(setf *mode-line-border-color* BORDER-COLOR)

(setf *mode-line-foreground-color* FOREGROUND-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

(setf *frame-number-map* "1234567890")

;; Rename the first group to Browse.

(setf (group-name (first (screen-groups (current-screen)))) "Browse")

;; Create the other groups.

(run-commands "gnewbg Edit" "gnewbg Term" "gnewbg Comms")

;; 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 " -bg " BORDER-COLOR)) ; Colors swapped here.

;; Keep the X cursor out of the way.

(run-shell-command "unclutter -idle 5 -jitter 5 -root")

;; 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 (current-date)) ; Defined above

                                      ") (" ; Just a spacer

                                      `(:eval (current-song-info)) ; Defined above


(run-commands "mode-line")

;; Found this tidbit browsing the source. Defaults to :ignore

(setf *mouse-focus-policy* :click) ; I'm fucking lame.

;;; Keyboard shortcuts.

;; 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 its own keymap.

(defvar *audio-map* nil

  "The keymap that audio related key bindings sit on.")

(when (null *audio-map*)

  (setf *audio-map*

        (let ((m (make-sparse-keymap)))

          (define-key m (kbd "Up") "mpc-volume-up")

          (define-key m (kbd "Down") "mpc-volume-down")

          (define-key m (kbd "Left") "mpc-song-prev")

          (define-key m (kbd "Right") "mpc-song-next")

          (define-key m (kbd "P") "mpc-toggle")

          (define-key m (kbd "?") "help-audio")


(define-key *root-map* (kbd "a") *audio-map*)

(define-stumpwm-command "mpc-volume-up" () "Increase MPD playback volume."

 (run-shell-command "mpc volume +10" t))

(define-stumpwm-command "mpc-volume-down" () "Decrease MPD playback volume."

 (run-shell-command "mpc volume -10"t ))

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

 (run-shell-command "mpc next" t))

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

 (run-shell-command "mpc prev" t))

(define-stumpwm-command "mpc-toggle" () "Pause/unpause MPD"

 (run-shell-command "mpc toggle" t))

(define-stumpwm-command "help-audio" () "Show what keybindings are configured for *audio-map*"

 (display-keybinding '*audio-map*))

January 7, 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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: