My StumpWM Config

StumpWM vs Gnome

StumpWM is a tiling, keyboard-driven (100% mouse-less) Linux Window Manager, written entirely in Common Lisp. It is the successor of ratpoison.

Each window is the same size: the real entirety of the screen. There are no window borders, no title bars, no minimize buttons, none of the clutter that's needed by a mouse (remember, that's the device used for pointing at the xterm you want to type in) — just some easy to remember key bindings (that you can customize to your own taste!) prefixed by a default key.

And using the keyboard (almost) exclusively is, without a doubt, considerably faster than having to frequently reach the mouse: your mouse is useful for graphical stuff (like gimp and xfig) but, for most stuff, it is useless and counterproductive.

The combination of StumpWM, Emacs and mouseless browsing with Firefox is great. I learned to love it after having tested it! And once you've used it, you can't go back anymore… Maybe it's time for you to use it as well…

How to download and install StumpWM Ubuntu

The easiest route would be:

sudo aptitude install clisp
sudo aptitude install stumpwm

The following description applies only if you want to install a more recent version of it.

Prerequisites

sudo aptitude install git-core
sudo aptitude install autoconf
sudo aptitude install build-essential
sudo aptitude install texinfo

Installing Common Lisp

You should first decide which Common Lisp (from now on, CL) implementation you want to use:

and then install the version packaged with Ubuntu or their latest release. I would recommend using the latest versions because earlier issues have been resolved.

My advice is to use SBCL (with cl-clx-sbcl, as you definitely need to install CLX support before building StumpWM).

SBCL with CLX

Normally, you could just do:

sudo aptitude install sbcl sbcl-doc
sudo aptitude install cl-clx-sbcl
sudo aptitude install cl-ppcre

To install CLX, start sudo sbcl and use asdf-install to download and install Lisp packages:

(require 'asdf)
(require 'asdf-install)
(asdf-install:install 'clx)
(asdf-install:install 'cl-ppcre)

When prompted "GPG warns that the key id […] is not fully trusted", choose "[SKIP-GPG-CHECK] Don't check GPG signature for this package".

(quit)

CLisp

Get CLisp from CVS:

cvs -d:pserver:anonymous@clisp.cvs.sourceforge.net:/cvsroot/clisp login
cvs -z3 -d:pserver:anonymous@clisp.cvs.sourceforge.net:/cvsroot/clisp co -d clisp-cvs -P clisp

or download the latest stable release of CLisp (2.48, as of 2009-07-28).

Switch to the directory you want your CLisp directory to be downloaded into (/usr/local/src, meant for source files that you downloaded yourself) and type:

wget ftp://ftp.gnu.org/pub/gnu/clisp/latest/clisp-2.48.tar.gz
tar -xvzf clisp-2.48.tar.gz
cd clisp-2.48

Install a few libraries on which CLISP relies:

GNU libsigsegv
Library for handling page faults in a portable way
GNU libffcall
Foreign Function Call Libraries
  • Install libffcall
    mkdir tools; cd tools
    wget http://www.haible.de/bruno/gnu/ffcall-1.10.tar.gz
    tar xfz ffcall-1.10.tar.gz
    cd ffcall-1.10
    ./configure
    make
    make check
    sudo make install
    cd ../..
    
  • Install libsigsegv
    cd tools; prefix=`pwd`/i686-pc-linux-gnu
    wget http://ftp.gnu.org/pub/gnu/libsigsegv/libsigsegv-2.6.tar.gz
    tar xfz libsigsegv-2.6.tar.gz
    cd libsigsegv-2.6
    ./configure --prefix=${prefix} && make && make check && make install
    cd ../..
    
    rm -f src/config.cache
    

Install the XLIB development libraries

They're just packages you have to install. On Ubuntu, you can install xorg-dev and get what you need.

sudo aptitude install xorg-dev

Also, you have to make sure CLisp is compiled with new-clx support (mit-clx is not supported).

Otherwise, you'll get the error "there is no package with name `XLIB'" when building StumpWM.

# cd tools; prefix=`pwd`/i686-pc-linux-gnu
# cd ..
./configure --with-libsigsegv-prefix=${prefix} --with-module="clx/new-clx"
cd src
vi config.lisp
ulimit -s 16384  # increase default stack size
make
make check
sudo make install
cd ../..

Once the software has been installed, you can find further information about using clisp with these commands:

man clisp
apropos clisp
which clisp
locate clisp

And, finally, install CL-PPCRE from your package manager:

sudo aptitude install cl-ppcre

Other approach

The other approach is to install version 2.44.1, by typing:

sudo aptitude install clisp

Installing StumpWM

Fetch StumpWM

Get StumpWM from Git. Type:

git clone git://git.savannah.nongnu.org/stumpwm.git

Configure StumpWM

Now cd to your stumpwm dir and type autoconf to get an executable configure script:

cd stumpwm
autoconf

Build StumpWM

Then type (as normal user):

  • If you're building with CLisp:
    ./configure --with-lisp=clisp --with-ppcre=/usr/share/common-lisp/source/cl-ppcre
    sudo make
    make      #! this one succeeds (after a first failure)
    
  • If you're building with SBCL:
    ./configure
    make
    

Install StumpWM

Copy the compiled binary in your PATH somewhere (e.g. /usr/local/bin) by typing:

sudo install <full-path-to-stumpwm>/stumpwm /usr/local/bin/
sudo cp <full-path-to-stumpwm>/contrib/stumpish /usr/local/bin/

Debugging

clisp -K full -x "(load \"asdf.lisp\") (load \"stumpwm.asd\") (load \"/usr/share/common-lisp/systems/cl-ppcre.asd\") (asdf:operate 'asdf:load-op :stumpwm) (stumpwm::stumpwm)"

You can run these expressions in the repl. Maybe then you'll get the debugger. The goal is to get a backtrace for the error.

Installing StumpWM as the default window manager

Add a new entry to GDM Sessions menu, so that we can easily switch between StumpWM and Gnome.

To do so, copy any of the *.desktop files in /usr/share/xsessions to /usr/share/xsessions/stumpwm.desktop and edit it to look like this:

[Desktop Entry]
Encoding=UTF-8
Name=StumpWM
Comment=This session logs you into StumpWM (a minimalistic window manager)
Exec=/usr/local/bin/stumpwm
Icon=
Type=Application

Making StumpWM the default session will update your .dmrc file:

[Desktop]
Session=stumpwm

Logging out of StumpWM can take you to Gnome, and conversely, by choosing the appropriate session.

StumpWM manual

How to get Network Manager working with StumpWM

StumpWM does not have a system tray. And Network Manager needs one to be controlled. So, you need to install one. No further discussion.

I use stalonetray (instead of gnome-panel) which works great.

Currently, the system tray is put in the middle of the screen. It is not docked to the bottom of the screen, and it is overlapped by other windows, but that's not a real problem — to the contrary, in fact, as I save some space for the other windows.

How to change keyboard language in StumpWM

To switch to another keyboard layout without restarting the X server, the easy answer is to use setxkbmap (for example, setxkbmap fr or setxkbmap us).

You can bind the two layout switching commands in your .stumpwmrc. That's what I've done with the Caps Lock key.

And to get a visual feedback of the current layout, I use a program called numlockx that turn on the Num Lock led — what has no negative side effect. The led is off in the default keyboard layout, on for the other one.

How to get new mail notification with StumpWM

For the email notification, a powerful customization is to set the email alert as being a blinking led of the keyboard.

I use mail-notification and the command xset led 3 to turn on the Scroll Lock led when new mail arrives. When all mail has been read, the led is turned off with xset -led 3.

For a blinking led, use blink -s -r 1 and blink to turn the led on and off… but I've found this to interact badly with my Caps Lock: the status of the Caps Lock led is changed whenever the Scroll Lock led blinks…

How to get Impressive working fine

  • Try it with fullscreen mode disabled (option -f)
  • Try -g 1280x1024 (or whatever your resolution is) for black margins

Fonts

You could add to your X defaults a setting like this:

Xft.dpi: 96

or a value closer to your display's resolution. It might also help to run your X server with your display's resolution. Some X servers evaluate the contents of a ~/.xserverrc file.

Print Screen

Monitor

A handy little application is the xosview client, which provides load, CPU, memory and swap usage, disk I/O usage and activity, page swapping information, network activity, I/O activity, I/O rates, serial port status, and if APM is enabled, the battery level (such as for a laptop).

Automount

Un environnement de bureau comme Gnome ou KDE fait aussi tourner ds tas de démons pour genre auto-monter les CD ou clés USB, et faire des tas de trucs.

StumpWM RC file

Here is my .stumpwmrc:

;; Hey, Emacs! This is a -*- lisp -*- file!
;;; .stumpwmrc --- my StumpWM Init File

;; Copyright (C) 2008-2010 Fabrice Niessen
;; Time-stamp: <2010-06-21 Mon 14:30 sva on mundaneum>

;; Author: Fabrice Niessen <(concat "fni" at-symbol "mygooglest.com")>
;; Keywords: stumpwm, dotfile, config

;; $Revision: 1933 $
;; $Date: 2010-06-21 14:06:22 +0200 (Mon, 21 Jun 2010) $

;;* Comment:

;; This config is known to work with stumpwm 0.9.6, and should work with
;; later versions as well.

;; You should specify full path to contrib modules. (load "~/...") works on
;; CLisp but doesn't work on SBCL...


;;* TODO

;; - Add googlers or wikiers functions?


;;* Code:

;; This file is only provided as an example. Customize it to your own taste!

;; See http://www.nongnu.org/stumpwm/manual/stumpwm.html

(in-package :stumpwm)

(message "Loading rc!")

(run-shell-command "rm .xsession-errors")

;; (run-shell-command "~/bin/x-second-monitor")


;; ;; load Swank so we can connect with SLIME
;; (load "/usr/share/emacs/site-lisp/slime/swank-loader.lisp")
;; (swank-loader:init)
;; (defvar *swank-p* nil)
;;
;; ;; define swank command to start swank server on port 4005
;; (defcommand swank () ()
;;   "Starts a swank server on port 4005 and notifies the user."
;;   (setf stumpwm:*top-level-error-action* :break)
;;   (if *swank-p*
;;       (message "Swank server already running.")
;;     (progn
;;       (swank:create-server :port 4005
;;                            :style swank:*communication-style*
;;                            :dont-close t)
;;       (setf *swank-p* t)
;;       (message "Starting swank on port 4005."))))


;;** 2 (info "(stumpwm)Key Bindings")

;; `*top-map*' is the top level key map. This is where you'll find the
;; binding for the prefix map.
;;
;; `*root-map*' is the keymap by default bound to `C-t'. It is known as the
;; prefix map.


;;*** --2.2 (info "(stumpwm)Binding Keys")

;; TODO Check this out!
;; unison synchronization
(defcommand unison-synchronization (host) ((:rest "Synchro host: "))
  (run-shell-command (concat "/home/sva/bin/unisync " host)))

;; screenshot-to-website
(defcommand screenshot-to-website (filename) ((:rest "Filename: "))
  (run-shell-command
   (format nil
           "import -window root /home/m0rg/code/html/patzy/screenshots/~a"
           filename)))

;; screenshot-to-file
(defcommand screenshot-to-file (filename) ((:rest "Filename: "))
  (run-shell-command
   (format nil "import -window root ~a" filename)))



;; Keyboard Shortcuts

;;**** Sound

;; mixer
;; XXX `m' conflicts with `lastmsg'
(define-key *root-map* (kbd "m") "exec xterm -rv -e alsamixer")


;;**** Desktop

;; launch Emacs
(defcommand emacs () ()  ;! redefining emacs command
  "Start Emacs or switch to it, if it is already running."
  (run-or-raise "emacs" '(:class "Emacs")))

;; mail notification
;; use `blink -c -r 1' (TODO Install `blinkd') for new mail (to be configured
;; via `gconf-editor' -> apps -> mail-notification -> commands)

;; launch Web browser
(defcommand firefox () ()
  "Start Firefox or switch to it, if it is already running."
  (run-or-raise "firefox" '(:class "Firefox")))
(define-key *root-map* (kbd "f") "firefox")

;; run an `urxvt' terminal (instead of `xterm')
;; TODO Install `rxvt-unicode'
;; FIXME If urxvt is not installed, let default keybinding
(defcommand urxvt () ()
  "Start an urxvt instance or switch to it, if it is already running."
  (run-or-raise "urxvt" '(:instance "urxvt")))
(define-key *root-map* (kbd "c") "urxvt")
    ; How do I scroll in a `urxvt' or in a `Ctrl-Alt-F6' command prompt?
    ; Shift + Pg Up/Dn
    ;
    ; How do I paste text to an `urxvt' terminal?
    ; Shift + Insert

;; too dangerous (easily typed!)
;; ;; log out
;; (define-key *root-map* (kbd "q") "quit")

;; ;; shutdown
;; (define-key *root-map* (kbd "Delete") "exec gksudo halt")

;; lock screen (x or L or l?)
(define-key *root-map* (kbd "L") "exec xtrlock")

(define-key *root-map* (kbd "M-l") "exec xset dpms force off")

;; take a screenshot of the screen (using PrtSc)
;; TODO Install `imagemagick' (for getting the `import' command)
(define-key *root-map* (kbd "Print")
  "exec import -window root png:$HOME/Desktop/screenshot_$(date +%F_%H-%M-%S).png")

;; take a screenshot of a window (using Alt-PrtSc)
;; TODO Install `scrot'
(defcommand part-screenshot () ()
  "Take a screenshot of only the active window."
  (run-shell-command "scrot -s"))
(define-key *top-map* (kbd "M-Print") "part-screenshot")


;;**** Window Management

;; push the window in the adjacent frame
(define-key *root-map* (kbd "C-Up") "move-window up")
(define-key *root-map* (kbd "C-Left") "move-window left")
(define-key *root-map* (kbd "C-Down") "move-window down")
(define-key *root-map* (kbd "C-Right") "move-window right")

(define-key *root-map* (kbd "Delete") "repack-window-numbers")

(define-key *root-map* (kbd "I") "show-window-properties")


;;**** Custom Shortcuts

;; keyboard layout (toggling between "qwerty-gb" and "azwerty-fr" via
;; `Caps_Lock')
(run-shell-command "setxkbmap -model \"pc105\" -layout \"gb,fr\" -option \"grp:caps_toggle,grp_led:scroll\"")
;; FIXME grp_led:caps??

;; aptitude
(define-key *root-map* (kbd "&") "exec xterm -rv -e aptitude")

;; openvpn
;; (define-key *root-map* (kbd "o") "exec xterm -name vpnup -rv -e \"sudo openvpn mcbe.vpn\"")
;; ;; (define-key *root-map* (kbd "o") "exec xterm -name vpnup -rv -e \"sudo openvpn --config mcbe.vpn\"")

;; FIXME This does not work.
(defcommand openvpn  () ()
  (run-or-raise
   "urxvt -title openvpn -cd /home/sva/.hide/ -e sudo ./openvpn mcbe.vpn"
   '(:title "openvpn" :instance "urxvt" :class "URxvt"))
  :all-screens t
  :all-groups t)
(define-key *root-map* (kbd "o") "openvpn")


;;** Commands

(defparameter *start-menu*
  '(
    ("Graphics"
     ("Color Picker"   "gcolor2")
     ("GIMP"           "gimp")
     ("Inkscape"       "inkscape")
     ("Picasa"         "picasa")
     ("Scanner"        "xsane")
     ("OCR"            "gocr"))

    ("Internet"
     ("Filezilla" "filezilla")
     ("Firefox"   "firefox")
     ("Skype"     "skype"))

    ("Office"
     ("OpenOffice.org"  "openoffice"))

    ("Sound and Video"
     ("Europe 1"      "mplayer http://vipicecast.yacast.net/europe1")
     ("RTL"           "mplayer http://streaming.radio.rtl.fr/rtl-1-44-96")
     ("Mixer"         "xterm -rv -e alsamixer")
     ("K3b Burner"    "k3b")
     ("Eject CD-ROM"  "eject cdrom"))

    ("System Tools"
     ("Calculator"        "speedcrunch")
     ("Disk space"        "filelight")
     ("File Manager"      "nautilus")  ; thunar
     ("Nvidia X Server"   "nvidia-settings")
     ("Power Preferences" "gnome-power-preferences")
     ("Printers"          "system-config-printer")
     ("Terminal Server"   "tsclient")
         ; Turn on "Enable window manager's key bindings" for prefix key to
         ; be passed seamlessly (when *not* in full screen).
         ; Toggle between full screen and not full screen using
         ; `Ctrl-Alt-Enter'.

     ;; > In the case of Rdesktop you have to launch the app with the option
     ;; > '-K' so Stump can retain control over the key combinations that you
     ;; > input inside the remote session.

     ("VirtualBox"       "VirtualBox"))

    ("X Windows Tools"
     ("Clipboard"  "xclipboard")
     ("Fonts"      "xfontsel")
     ("Ruler"      "kruler")
     ("Events"     "xev"))
    ))

(defcommand menu () ()
  "docstring"
  (labels ((pick (options)
                 (let ((selection (stumpwm::select-from-menu
                                   (current-screen) options "")))
                   (cond
                    ((null selection)
                     (throw 'stumpwm::error "Abort."))
                    ((stringp (second selection))
                     (second selection))
                    (t
                     (pick (cdr selection)))))))
    (let ((choice (pick *start-menu*)))
      (run-shell-command choice))))

(define-key *root-map* (kbd ".") "menu")


(defcommand reinit () ()
  "docstring"
  (run-commands "reload" "loadrc"))


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

;; Web browsing commands
;; Get the X selection and order the GUI browser to open it. Presumably it
;; is a HTTP address.
(defcommand open-selection-browser () ()
  "docstring"
  (run-shell-command (cat "exec firefox " (get-x-selection))))


;; Ask user for a search string and search Wikipedia for it.
;; (defcommand wikipedia ((search-string :string "wikipedia " :string)) ()
;;   (check-type search-string string)
;; (run-shell-command (cat "exec firefox wikipedia " search-string)))


;; Web jump (works for Google)
(defmacro make-web-jump (name prefix)
  `(defcommand ,name (search) ((search :rest ,(concatenate 'string name " search: ")))
     (substitute #\+ #\Space search)
     (run-shell-command (concatenate 'string ,prefix search))))

;; (make-web-jump "ggoogle" "firefox http://www.google.com/search?q=")

(define-key *root-map* (kbd "z") "google")

;; ask the user for a search string and search for it in Wikipedia
(defcommand wikipedia (search)
  ((:string "Search in Wikipedia for: "))
  "docstring"
  (check-type search string)
  (substitute #\+ #\Space search)
  (run-shell-command (cat "firefox http://www.wikipedia.org/wiki/" search)))

;; ask the user for a search string and search for it in Google
(defcommand google (search)
  ((:string "Search in Google for: "))
  "docstring"
  (check-type search string)
  (substitute #\+ #\Space search)
  (run-shell-command (cat "firefox http://www.google.com/search?q=" search)))

;; courtesy of Peter Seibel
(defmacro with-gensyms ((&rest names) &body body)
  `(let ,(loop for n in names collect `(,n (gensym)))
     ,@body))

(defmacro program-with-layout (name &key (command (string-downcase (string name)))
                                    (props `'(:class ,(string-capitalize command))))
  (with-gensyms (s w h files-path layout rules)
                `(defcommand ,name () ()
                   (let* ((,s (current-screen))
                          (,w (prin1-to-string (screen-width ,s)))
                          (,h (prin1-to-string (screen-height ,s)))
                          (,files-path "/home/sva/etc/stumpwm_files/")
                          (,layout (concat ,files-path ,command "-layout-" ,w "x" ,h))
                          (,rules (concat ,files-path ,command "-rules")))
                     (gnew ,command)
                     (restore-from-file ,layout)
                     (restore-window-placement-rules ,rules)
                     (run-or-raise ,command ,props)
                     (place-existing-windows))))) ; needed if command was already run

(program-with-layout gimp)


;;** 3 (info "(stumpwm)Message and Input Bar")

;;*** 3.1 (info "(stumpwm)Customizing The Bar")

;; Find a font of your choice in `xfontsel' and put it here.

;; set the font for the message bar and input bar
;; (set-font "-*-FreeMono-medium-r-*-*-6*")
(set-font "-adobe-helvetica-medium-r-normal--10*")

;;** 4 (info "(stumpwm)Windows")

;; how to format the window list
(setf *window-format* "^B%m%n^b %40t  ")


;;*** 4.2 (info "(stumpwm)Customizing Window Appearance")

;; width in pixels given to the borders of windows with maxsize or ratio
;; hints
(setf *maxsize-border-width* 1)

;; width in pixels given to the borders of transient or pop-up windows
(setf *transient-border-width* 1)

;; width in pixels given to the borders of regular windows
(setf *normal-border-width* 1)

;; TODO Install `xloadimage' (for getting the `xsetbg' command)
(run-shell-command "which xsetbg && xsetbg -fullscreen /usr/share/backgrounds/GrassinA.jpg")

;; set the border color for focused windows
(set-focus-color "orange")  ; `white' by default

(set-unfocus-color "palegreen3")


;; input focus is transferred to the window you click on
(setf *mouse-focus-policy* :click)

;; (defun banish-mouse (from-frame to-frame)
;;   (run-commands "banish"))
;; (add-hook *focus-window-hook* 'banish-mouse)


;;** 5 (info "(stumpwm)Frames")

;; make frames 1-indexed
;; See http://lists.gnu.org/archive/html/stumpwm-devel/2006-08/msg00002.html
(setf *frame-number-map* "1234567890")
;; FIXME Does not work


;; from simias
(defun shift-windows-forward (frames win)
  (when frames
          (let ((frame (car frames)))
                 (shift-windows-forward (cdr frames)
                                        (frame-window frame))
                 (when win
                         (pull-window win frame)))))

(defcommand rotate-windows () ()
  (let* ((frames (group-frames (current-group)))
           (win (frame-window (car (last frames)))))
          (shift-windows-forward frames win)))

;; swap 2 windows
(define-key *root-map* (kbd "~") "rotate-windows")


;; from simias
(defcommand toggle-split () ()
  (let* ((group (current-group))
         (cur-frame (tile-group-current-frame group))
         (frames (group-frames group)))
    (if (eq (length frames) 2)
        (progn (if (or (neighbour :left cur-frame frames)
                       (neighbour :right cur-frame frames))
                   (progn
                     (only)
                     (vsplit))
                 (progn
                   (only)
                   (hsplit))))
      (message "Works only with 2 frames"))))

;; toggle between vertical split and horizontal split
(define-key *root-map* (kbd "|") "toggle-split")


;;** 6 The (info "(stumpwm)Mode-line")

;; modeline foreground color
(setf *mode-line-foreground-color* "palegreen3")

;; modeline border color
(setf *mode-line-border-color* "palegreen3")

;; set contrib directory
(set-contrib-dir "/home/sva/src/stumpwm/contrib")

;; load a few modules
(mapcar #'load-module '("cpu"
                        "mem"
                        "battery-portable"
                        "net"
                        "wifi"
                        "disk"))

(defconstant *day-names*
  '("Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun"))

(defun current-date ()
  "Returns the date formatted as `2009-11-16 Mon 11:34:03'."
  (multiple-value-bind
      (second minute hour date month year day-of-week dst-p tz)
      (get-decoded-time)
    (format nil "~d-~2,'0d-~2,'0d ~a ^B~2,'0d:~2,'0d:~2,'0d^b"
            year month date (nth day-of-week *day-names*)
            hour minute second)))

;; FIXME ppp0 comes after lo0; hence, the IP is wrong
(defun current-ip ()
  "Returns the IP address in CIDR notation."
  (run-shell-command
   "IP_ADDRESS=`ifconfig | grep 'inet addr:' | head -n 1 | sed 's/.*addr:\\([0-9.]*\\).*/\\1/'`; NETMASK=`ifconfig | grep 'inet addr:' | head -n 1 | sed 's/.*Mask:\\([0-9.]*\\).*/\\1/'`; NETWORK=`ipcalc -n -b $IP_ADDRESS $NETMASK | grep Network | awk '{print $2}'`; echo -n IP:$IP_ADDRESS`echo $NETWORK | sed 's/.*\\(\\/.*\\)/\\1/g' | tr -d '[:cntrl:]'`"
   t))

(defun current-gw ()
  "Returns the default gateway."
  (run-shell-command
   "echo -n Gw:`ip route show | grep default | awk '{print $3}' | tr -d '[:cntrl:]'`"
   t))

;; TODO Get this in a lighter manner, by parsing /proc/net/route. See, for
;; example, contribs/net.lisp.


;; %h :: List the number of the head the mode-line belongs to
;; %w :: List all windows in the current group windows using `*window-format*'
;; %W :: List all windows on the current head of the current group using `*window-format*'
;; %g :: List the groups using `*group-format*'

;; colors
;; 0 = black, 1 = red, 2 = green, 3 = yellow,
;; 4 = blue, 5 = magenta, 6 = cyan, 7 = white

;; %N :: notifications
;; what's `^n'?
;; what's `%48'?

;; what will be displayed on the modeline (sort of taskbar) for each screen
;; FIXME `run-shell-command' in mode-line could be the source of StumpWM crashes?
(setf *screen-mode-line-format*
      (list
       ;; date
       "^6*" '(:eval (current-date)) ; defined above
       ;; cpu | mem | battery
       " | %D | %c %C (%f) %t | %M | %B"

       ;; ip and gw
       " | " '(:eval (current-ip)) " " '(:eval (current-gw)) ; defined above
       ;; net | wifi
       " | %l | %I"
       '(:eval (run-shell-command "echo" t))
       "^2*" "[^B%n^b] %W%48"))

;; how many seconds elapse between each update of the modeline
(setf *mode-line-timeout* 1) ; must be set *before* turning on the modeline

;; turn on the modeline
(if (not (head-mode-line (current-head)))
    (toggle-mode-line (current-screen) (current-head)))
    ; A head is a physical monitor. A screen is a section of video memory
    ; that heads are mapped on to. When using xinerama you generally have
    ; 1 screen and many heads. When not using xinerama each screen is a
    ; physical monitor so you have many screens with only one head on them.

;; number of padding pixels between the modeline text and the top/bottom of
;; the modeline
(setf *mode-line-pad-y* 0)

;; modeline background color
(setf *mode-line-background-color* "black")

;; TODO add hook so I get notified when people say my name on IRC or IM me
(defun echo-urgent-window (target)
  (message-no-timeout "~a has an message for you." (window-title target)))
(add-hook *urgent-window-hook* 'echo-urgent-window)


;;** 7 (info "(stumpwm)Groups")

;; Super_L-F1..F9 to change workspace

;; Is there a way to share windows between several groups?
;; Try using tags. A window can have arbitrary set of tags, and there is a
;; command to pull all windows which have any of the specified tags to current
;; group. Bind some tags to F1-F10 instead of groups, and you are done.

;; create the other groups
(run-commands "gnewbg Other")


;;** 9 (info "(stumpwm)Interacting With Unix")

;; shell program used by `run-shell-command' (`sh' by default, which is *not*
;; `bash' nor `zsh')
(setq *shell-program* (stumpwm::getenv "SHELL"))  ; `getenv' is not exported

;; system tray

;; ;; TODO Check if it exists
;; (run-shell-command "which stalonetray && stalonetray")

;; From http://archive.ubuntu.com/ubuntu/pool/universe/t/trayer/
(run-shell-command "/usr/bin/trayer --SetDockType false --transparent true --expand false")
;; (run-shell-command "/usr/bin/trayer")


;; dzen2 -fn fixed -w 600 -ta l -fg '#ffffff' -bg '#006699' -e ''

;; dzen provides customisable status bars

;; 9menu

;; dmenu provides a simple popup menu for launching programs
(define-key *root-map* (kbd "P")
  "exec dmenu_run -i -b -p \"run command:\"") ; simple $PATH to run commands



;; (run-shell-command "/usr/bin/gnome-settings-daemon")
;; ;;(run-shell-command "/usr/bin/gnome-panel &")
;; (run-shell-command "/usr/bin/nm-applet &")
;; (run-shell-command "/usr/bin/bluetooth-applet &")
;; (run-shell-command "/usr/bin/pactl load-module module-x11-xsmp &")

;; other programs in the system tray
(run-shell-command "gnome-power-manager")
(run-shell-command "nm-applet --sm-disable")  ; network manager
;; (run-shell-command "which mail-notification && mail-notification --sm-disable")
(run-shell-command "which log-event-notify && log-event-notify")
                                        ; TODO Install `inotify-tools' and
                                        ; `libnotify-bin' for this to work as
                                        ; expected

(run-shell-command "emacs")
;; (run-shell-command "urxvt")
(run-shell-command "update-manager")

;; fix volume levels
(run-shell-command "~/bin/volume-control")


;; so i modified my keymap settings so that compaq keys2-4 are mapped to
;; function keys F13-F15 (i only have F1 to F12…)
;;
;; -- .Xmodmap --
;; keycode 160 = F13
;; keycode 174 = F14
;; keycode 176 = F15
;;
;; and my corresponding .fluxbox/keys file
;;
;; -- snip --
;;
;; # laptop keymap
;; F13 :ExecCommand /bin/bash ~/.mykbd
;; F14 :ExecCommand /usr/bin/amixer sset PCM 5%-
;; F15 :ExecCommand /usr/bin/amixer sset PCM 5%+


;;** 11 (info "(stumpwm)Miscellaneous Commands")

;; This forces the user to set the focus into the screen before being able to
;; use the prefix key for the first time!
;; ;; get rid of cursor initially
;; (banish-pointer)


;;*** 11.2 (info "(stumpwm)Debugging StumpWM")

;; turn on debugging (look at `.xsession-errors')
(setf stumpwm::*debug-level* 10)  ; get rid of debug by setting level to 0


;;*** 11.4 (info "(stumpwm)Getting Help")

(setf *help-map*
      (let ((m (make-sparse-keymap)))
        (define-key m (kbd "m") "man")
        (define-key m (kbd "i") "info")
        (define-key m (kbd "v") "describe-variable")
        (define-key m (kbd "f") "describe-function")
        (define-key m (kbd "k") "describe-key")
        (define-key m (kbd "w") "where-is")
        m))


;;** 12 (info "(stumpwm)Hooks")

;; display the key sequence in progress
(defun key-press-hook (key key-seq cmd)
  (declare (ignore key))
  (unless (eq *top-map* *resize-map*)
    (let ((*message-window-gravity* :bottom-right))
      (message "Key sequence: ~a" (print-key-seq (reverse key-seq))))
    (when (stringp cmd)
      ;; give 'em time to read it
      (sleep 0.5))))

(defmacro replace-hook (hook fn)
  `(remove-hook ,hook ,fn)
  `(add-hook ,hook ,fn))

(replace-hook *key-press-hook* 'key-press-hook)


;;** Prefix Key

;; I tend to place "system-wide" window manager shortcut keys consistently
;; on Super-<something> rather than the horrible defaults that can get in
;; the way of Emacs' use (various Control and Alt bindings).

;; same as `keycode 133 = F20' in `~/.Xmodmap', `133' (TO BE CHECKED WITH
;; `xev') being the left "Windows" key, aka `Super_L'
;; (run-shell-command "xmodmap -e 'keycode 133 = F20'" t)

;; change the prefix key
(set-prefix-key (kbd "ISO_Level3_Shift"))  ;; `Alt Gr'


;; This is for the sake of Emacs.
;; Local Variables:
;; coding: utf-8
;; mode: emacs-lisp
;; mode: outline-minor
;; ispell-local-dictionary: "en_US"
;; End:

;;; .stumpwmrc ends here