.stumpwmrc 0.4

Current .stumpwmrc with entire changelog will now be kept available here.

— cut ——————————————————————————————-

; -*-lisp-*-

;;; 0.4

;; 2008/01/09

;; Axed my custom (current-date). Set *format-time-string-default* and call (format-time-string) for the
;; modeline instead. Besides saving the overhead that an external application implies, it keeps it
;; from disappearing now. (current-song-info) will simply call (mpc-status) once it's rewritten.

;; All (mpc-*) functions other than (mpc-status) now use a direct socket connection to MPD instead of
;; using an external client. It could easily enough be made portable but right now it's CLISP specific.
;; Will write a custom (mpc-status) later. Yes, my StumpWM config is now its own MPD client. ;)

;; 2008/01/08

;; Note that CLISP seems to have a problem with my modeline. The exec portions stop getting run
;; seemingly at random, and sometimes comes back. Appears to be related to the fact that they
;; both use (run-shell-command). Attempting to use an MPD-affecting command makes it throw an
;; error regarding no child process and fails to have an effect on MPD, but restores the modeline
;; after which subsequent MPD keybindings work as expected. No, disabling current-song-info
;; doesn't fix it. Yes, it was happening before the previous two changes. No, it doesn't happen
;; with SBCL. May attempt to debug in a couple days.

;; Replace the monstrocity that (current-song-info) had become with its previous version.
;; Add keybinding to display mpc's default output instead.

;; Replace call to external 'unclutter' application with (run-with-timer 5 5 'banish-pointer).
;; Although, it goes off every 5 seconds regardless of mouse activity now. But I'm OK with that.
;; Fixing it would likely require a hook to mouse activity to reset the timer. I may look into it later.

(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.

;; 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))

;; 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-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-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
(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 "a") "mpc-status")
          (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-pause")
          (define-key m (kbd "?") "help-audio")

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

(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"))

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

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 )

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: