aboutsummaryrefslogtreecommitdiffstats
path: root/stumpwmrc
blob: 496647fe2c3924f94e0411250a6d2cb1d9eba53d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
;; -*- mode: lisp; -*-

(in-package :stumpwm)

(defmacro elisp (&body body)
  "Run BODY through emacsclient."
  `(sb-ext:run-program
   "/usr/bin/emacsclient"
   '("-e" ,(string-downcase (format nil "~S" (cons 'progn body))))
   :wait nil))

(defvar *conkeror-program* "conkeror"
  "The executable to run to start Conkeror.")
(defvar *emacs-program* "emacsclient -c -a \"\""
  "The executable to run to start Emacs.")
(defvar *firefox-program* "firefox"
  "The executable to run to start Firefox.")
(defvar *i3lock-program* "i3lock -c 000000"
  "The executable to run to start i3lock.")
(defvar *urxvt-program* "urxvt"
  "The executable to run to start URxvt.")
(defvar *lock-screen-hook* nil
  "Hook run right before the screen gets locked.")
(defvar *screen-unlocked-hook* nil
  "Hook run right after the screen is unlocked.")
(defvar *desktop-bindings*
  (let ((m (make-sparse-keymap)))
    (define-key m (kbd "s") "save-desktop-configuration")
    m)
  "Special keymap for desktop management commands.")

(defun get-mail-count (mailbox &optional (inbox "inbox"))
  "Check how many new messages there are in MAILBOX."
  (length
   (append
    (directory
     (format nil "/home/slash/documents/mail/~A/~A/new/*.*"
             mailbox inbox))
    (remove-if (lambda (d)
                 (let ((dir (namestring d)))
                   (string= dir "S" :start1 (1- (length dir)))))
               (directory
                (format nil "/home/slash/documents/mail/~A/~A/cur/*.*"
                        mailbox inbox))))))

(defun dunst-pause ()
  "Pause dunst"
  (sb-ext:run-program "/usr/bin/killall" '("-SIGUSR1" "dunst")))

(defun dunst-start ()
  "Start dunst"
  (sb-ext:run-program "/usr/bin/killall" '("-SIGUSR2" "dunst")))

(defun mpd-playing-p ()
  "Check if MPD is currently in the playing state."
  (and (cl-ppcre:scan
        "\\n\\[playing\\]"
        (with-output-to-string (status)
          (sb-ext:run-program "/usr/bin/mpc" '() :output status)))
       t))

(defun set-jabber-away ()
  "Tell emacs to set jabber to away presence."
  (elisp
    (when (and (fboundp 'jabber-send-away-presence)
               *jabber-connected*)
      (jabber-send-away-presence))))

(defun set-jabber-online ()
  "Tel emacs to set jabber to online presence."
  (elisp
    (when (and (fboundp 'jabber-send-default-presence)
               *jabber-connected*)
      (jabber-send-default-presence))))

(let (mpd-was-playing)
  (defun mpd-pause ()
    "Pause MPD playback."
    (when (setf mpd-was-playing (mpd-playing-p))
      (sb-ext:run-program "/usr/bin/mpc" '("pause") :wait nil)))

  (defun mpd-play ()
    "Resume MPD playback."
    (when mpd-was-playing
      (sb-ext:run-program "/usr/bin/mpc" '("play") :wait nil))))

(defcommand emacs-move-focus (dir) ((:direction "Direction: "))
  "Move focus in direction DIR.

If the current window is an Emacs window, let it handle the event
itself."
  (let ((cw (current-window)))
    (if (and cw (string= (window-class cw) "Emacs"))
        (send-fake-key
         cw (kbd (format nil "S-~a" (string-capitalize dir))))
        (move-focus dir))))

(defcommand run-emacs () ()
  "Open Emacs"
  (run-shell-command *emacs-program*))

(defcommand raise-emacs () ()
  "Open or show Emacs"
  (run-or-raise *emacs-program* '(:class "Emacs")))

(defcommand run-firefox () ()
  "Open Firefox"
  (run-shell-command *firefox-program*))

(defcommand raise-firefox () ()
  "Open or show Firefox"
  (run-or-raise *firefox-program* '(:class "Firefox")))

(defcommand run-conkeror () ()
  "Open Conkeror"
  (run-shell-command *conkeror-program*))

(defcommand raise-conkeror () ()
  "Open or show Conkeror"
  (run-or-raise *conkeror-program* '(:class "Conkeror")))

(defcommand run-urxvt () ()
  "Open URxvt"
  (run-shell-command *urxvt-program*))

(defcommand raise-urxvt () ()
  "Open URxvt"
  (run-or-raise *urxvt-program* '(:class "URxvt")))

(defcommand save-desktop-configuration () ()
  "Save the current desktop configuration."
  (dump-desktop-to-file "~/.stumpwm.d/desktop.lisp"))

(defun run-stumpwm-hook-on-exit (process)
  "Run `*screen-unlocked-hook*' if PROCESS' status is `:exited'."
  (when (eq (sb-ext:process-status process) :exited)
    (run-hook *screen-unlocked-hook*)))

(defcommand lock-screen () ()
  "Lock the screen using i3lock.

Run `*lock-screen-hook*' before locking it and run
`*screen-unlocked-hook*' after it has been unlocked."
  (run-hook *lock-screen-hook*)
  (sb-ext:run-program
   "/usr/bin/i3lock" '("-n" "-c" "000000") :wait nil
   :status-hook #'run-stumpwm-hook-on-exit))

(set-bg-color "#111111")
(set-border-color "#bfbfbf")
(set-fg-color "#c2c2c2")
(set-float-focus-color "#6d97bf")
(set-float-unfocus-color "#222224")
(set-focus-color "#6d97bf")
(set-font "-*-tamsyn-medium-r-normal-*-17-*-*-*-*-0-iso8859-1")
(set-unfocus-color "#222224")
(set-win-bg-color "#111111")

(setf *colors* '("#a5a5a4" "#bf6d6d" "#8abf6d" "#b2bf6d"
                 "#6d97bf" "#b27dbf" "#7dbfbf" "#c2c2c2"))
(setf *input-window-gravity* :center)
(setf *message-window-gravity* :top-right)
(setf *mode-line-background-color* "#152e54")
(setf *mode-line-border-color* "#152e54")
(setf *mode-line-foreground-color* "#c2c2c2")
(setf *shell-program* (getenv "SHELL"))
(setf *transient-border-width* 1)
(setf *window-border-style* :thin)
(setf *screen-mode-line-format*
      (list "[%n]"
            '(:eval
              (format nil " | ryu: ~D | gmail: ~D | aethon: ~D | 9f: ~D | "
               (get-mail-count "ryuslash.org")
               (get-mail-count "gmail")
               (get-mail-count "aethon")
               (get-mail-count "ninthfloor")))))

(add-hook *lock-screen-hook* 'set-jabber-away)
(add-hook *lock-screen-hook* 'mpd-pause)
(add-hook *lock-screen-hook* 'dunst-pause)
(add-hook *screen-unlocked-hook* 'set-jabber-online)
(add-hook *screen-unlocked-hook* 'mpd-play)
(add-hook *screen-unlocked-hook* 'dunst-start)

(set-prefix-key (kbd "C-z"))

(define-key *top-map* (kbd "C-M-l") "lock-screen")
(define-key *top-map* (kbd "XF86AudioLowerVolume") "exec mpc volume -5")
(define-key *top-map* (kbd "XF86AudioMute")
  "exec amixer sset Master toggle")
(define-key *top-map* (kbd "XF86AudioNext") "exec mpc next")
(define-key *top-map* (kbd "XF86AudioPlay") "exec mpc toggle")
(define-key *top-map* (kbd "XF86AudioPrev") "exec mpc prev")
(define-key *top-map* (kbd "XF86AudioRaiseVolume") "exec mpc volume +5")
(define-key *top-map* (kbd "S-Down") "emacs-move-focus down")
(define-key *top-map* (kbd "S-Left") "emacs-move-focus left")
(define-key *top-map* (kbd "S-Right") "emacs-move-focus right")
(define-key *top-map* (kbd "S-Up") "emacs-move-focus up")

(define-key *root-map* (kbd "c") "raise-urxvt")
(define-key *root-map* (kbd "C") "run-urxvt")
(define-key *root-map* (kbd "e") "raise-emacs")
(define-key *root-map* (kbd "E") "run-emacs")
(define-key *root-map* (kbd "w") "raise-conkeror")
(define-key *root-map* (kbd "W") "run-conkeror")

(define-key *root-map* (kbd "C-b") "windowlist")
(define-key *root-map* (kbd "M-b") "move-window left")
(define-key *root-map* (kbd "M-f") "move-window right")
(define-key *root-map* (kbd "M-n") "move-window down")
(define-key *root-map* (kbd "M-p") "move-window up")
(define-key *root-map* (kbd "b") "move-focus left")
(define-key *root-map* (kbd "f") "move-focus right")
(define-key *root-map* (kbd "n") "move-focus down")
(define-key *root-map* (kbd "p") "move-focus up")
(define-key *root-map* (kbd "SPC") "next-in-frame")
(define-key *root-map* (kbd "C-z") "other-in-frame")
(define-key *root-map* (kbd "d") '*desktop-bindings*)

(undefine-key *root-map* (kbd "C-a"))
(undefine-key *root-map* (kbd "C-c"))
(undefine-key *root-map* (kbd "C-e"))
(undefine-key *root-map* (kbd "C-m"))

(define-frame-preference "Default"
    (0 t nil :class "Emacs")
  (2 t nil :class "Firefox")
  (1 t nil :class "URxvt")
  (2 t nil :class "Conkeror"))

(if (not (head-mode-line (current-head)))
    (toggle-mode-line (current-screen) (current-head)))

(restore-from-file
 (concatenate 'string (sb-ext:posix-getenv "HOME")
              "/.stumpwm.d/desktop.lisp"))

(ql:quickload "swank")
(swank-loader:init :load-contribs t)
(swank:create-server :dont-close t)