Advertisement
Guest User

.stumpwmrc (bulk version)

a guest
Jul 2nd, 2011
947
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 55.55 KB | None | 0 0
  1. ;;--------------------------------------------------------------------------;;
  2. ;; ${XDG_CONFIG_DIR:-/howl/conf}/.stumpwmrc                                 ;;
  3. ;;--------------------------------------------------------------------------;;
  4. ;; author: milomouse <vincent[at]fea.st>                                    ;;
  5. ;; update: 2011-06-21 23:01:09                                              ;;
  6. ;;--------------------------------------------------------------------------;;
  7. ;; versions used atoc:                                                      ;;
  8. ;; |  sbcl              -> 1.0.49-1                                         ;;
  9. ;; |  clx               -> 0.7.4-1                                          ;;
  10. ;; |  cl-ppcre          -> 2.0.3-1                                          ;;
  11. ;; |  stumpwm-git       -> 20110617-1                                       ;;
  12. ;;-TODO/CHANGELOG:----------------------------------------------------------;;
  13. ;; >>>-: create a 'dedicate' and 'catchall' window-rule (remember * *)      ;;
  14. ;; >>--: create a 'dedicate' and 'catchall' hook for changing focus color   ;;
  15. ;; >>--: have mifo(mplayer-daemon) prompts use filename completion          ;;
  16. ;; >---: better resize; if neighbour {above} then -ARG else +ARG, etc.      ;;
  17. ;; >>>-: show frame-indicator for 'resize' only if no window in frame       ;;
  18. ;; >>>>? command for dedicating current win/frame as the Master win/frame   ;;
  19. ;; >---: better command for Master; remember Master thru re{loadrc,start}   ;;
  20. ;; >>>>! command for swapping current window with the Master win/frame      ;;
  21. ;; >>>>! exchange two windows but keep focus in current frame               ;;
  22. ;; >>>>! dynamically dump group|screen|desktop|rules to *data-dir* by type  ;;
  23. ;; >>>>! dynamically load group|screen|desktop|rules from *data-dir* by type;;
  24. ;; >>>>! have my 'undo' use group and check current group for undos first   ;;
  25. ;; >>>>! create a togglable, on-the-fly scratchpad group                    ;;
  26. ;;--------------------------------------------------------------------------;;
  27. ;; files: *data-dir*/../{commands,functions,hooks,key-maps,macros}.lisp     ;;
  28. ;;--------------------------------------------------------------------------;;
  29.  
  30. ;; bulk version (config usually broken up in multiple. see loop below.)
  31.  
  32. (in-package :stumpwm)
  33.  
  34. ;; set a home-dir. not relative *default-pathname-defaults*.
  35. ;; set a data-dir for storing debug-file, group and placement dumps, etc.
  36. ;; set undo directory to store each group (and desktop) undo states.
  37. ;; set scratchpad group name for when it's created on the fly (.NAME to hide)
  38. (setf *home-dir* (make-pathname :directory "/howl")
  39.       *data-dir* (merge-pathnames (make-pathname :directory
  40.                  '(:relative "conf" "stumpwm" "storage")) *home-dir*)
  41.       *undo-data-dir* (make-pathname :directory "/dev/shm/.1009")
  42.       *scratchpad-group-name* ".scratchpad"
  43.       *debug-level* 1)
  44.  
  45. ;; setup a quick function for redirecting debug information directly to file.
  46. ;; (didn't want to use (redirect-all-output) as that's not what i want..)
  47. ;; (prefer internal handling as opposed to redirecting via exec $ >>! file)
  48. (defvar *debug-restream* nil)
  49. (defun redirect-debug (file) "Redirect *debug-stream* directly to a file."
  50.   (when (typep *debug-restream* 'file-stream)
  51.     (close *debug-restream*))
  52.   (setf *debug-restream* (open file :direction :output :if-exists :append
  53.                          :if-does-not-exist :create)
  54.         *debug-stream* *debug-restream*))
  55.  
  56. ;; setup debug-file variable for referencing (e.g. quitting) purposes.
  57. (defvar *debug-file* (data-dir-file "log" "lisp"))
  58. (redirect-debug *debug-file*)
  59.  
  60. ;; before we go further, rewrite colon command to old behavior.
  61. ;; (this should already be fixed in newest version)
  62. (defcommand colon (&optional initial-input) (:rest)
  63.   (let ((cmd (completing-read (current-screen) ": "
  64.           (all-commands) :initial-input (or initial-input ""))))
  65.     (unless cmd
  66.       (throw 'error :abort))
  67.     (when (plusp (length cmd))
  68.       (eval-command cmd t))))
  69.  
  70. ;; redefine run-shell-command for 'zsh', change :shell "", and fix a typo.
  71. (defcommand run-shell-command (cmd &optional collect-output-p)
  72.   ((:shell "execute: "))
  73.   "Run the specified shell command. If @var{collect-output-p} is @code{T}
  74. then run the command synchronously and collect the output."
  75.   (if collect-output-p
  76.     (run-prog-collect-output *shell-program* "-c" cmd)
  77.     (run-prog *shell-program* :args (list "-c" cmd) :wait nil)))
  78. (setf *shell-program* "/bin/zsh")
  79. ;(setf *shell-program* (stumpwm::getenv "SHELL"))
  80. (defcommand-alias exec run-shell-command)
  81.  
  82. ;; define a background-image-path for random image setting function.
  83. ;; (will soon change this to accept optional sub-dir for situations where
  84. ;; user wants to use 'work' or 'family' wallpapers instead)
  85. (defvar *background-image-path*
  86.   (merge-pathnames
  87.     (make-pathname :directory '(:relative "foto" "wall")) *home-dir*))
  88.  
  89. ;; gravities.
  90. (setf *mouse-focus-policy* :click
  91.       *window-border-style* :thin
  92.       *message-window-gravity* :top-right
  93.       *input-window-gravity* :top-right)
  94. (set-normal-gravity :top) ; top for terminals
  95. (set-maxsize-gravity :center) ; center for floating X apps
  96. (set-transient-gravity :center) ; center for save-as/open popups
  97.  
  98. ;; borders.
  99. (setf *resize-hides-windows* T
  100.       *normal-border-width* 2
  101.       *maxsize-border-width* 2
  102.       *transient-border-width* 2
  103.       *float-window-border* 1
  104.       *float-window-title-height* 1)
  105. (set-msg-border-width 1)
  106.  
  107. ;; fonts/colors.
  108. (set-font "-misc-fixed-medium-r-semicondensed-*-12-110-75-75-c-60-koi8-r")
  109. (set-fg-color        "grey64")
  110. (set-bg-color        "grey14")
  111. (set-focus-color     "grey60")
  112. ;(set-focus-color     "mediumpurple2")
  113. (set-unfocus-color   "grey16")
  114. (set-border-color    "grey44")
  115. (set-win-bg-color    "grey6")
  116. (setf *colors* (list "grey9"          ; 0 black
  117.                      "palevioletred1" ; 1 red
  118.                      "lightblue3"     ; 2 green
  119.                      "bisque3"        ; 3 yellow
  120.                      "steelblue3"     ; 4 blue
  121.                      "slateblue1"     ; 5 magenta
  122.                      "aquamarine4"    ; 6 cyan
  123.                      "honeydew4"      ; 7 white
  124.                      "thistle4"       ; 8 user
  125.                      "lightskyblue4")); 9 user
  126. (update-color-map (current-screen))
  127.  
  128. ;; text formatting (no mode-line). shorten time-day-names, etc.
  129. (setf *startup-message*
  130.        "^B^1*together we ate the king^n:^B^5*and laughed ourselves to death^n"
  131.       *time-day-names* #("Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun")
  132.       *time-format-string-default* "^B^2*%T^9* %Y-%m-%d^**/^8*%A^n"
  133.       *group-format*    "^B^0*%t^7*%s^07|^n"
  134.       *window-format*   "^B^87%s^9*%m^0*%16t^n"
  135.       *screen-mode-line-format* nil
  136.       *timeout-wait* 6)
  137.  
  138. ;; windows/frames. use more intuitive frame-numbers (with 'fselect').
  139. (setf *default-window-name* "null"
  140.       *new-frame-action* :empty
  141.       *min-frame-width* 45
  142.       *min-frame-height* 45
  143.       *resize-increment* 2
  144.       *frame-number-map* "yhjukilop")
  145.  
  146. ;; mode-line and input.
  147. (setf *mode-line-background-color* "grey5"
  148.       *mode-line-border-color* "grey10"
  149.       *mode-line-foreground-color* "azure4"
  150.       *mode-line-border-width* 1
  151.       *mode-line-pad-x* 1
  152.       *mode-line-pad-y* 0
  153.       *mode-line-timeout* 300
  154.       *mode-line-position* :top
  155.       *input-history-ignore-duplicates* 0)
  156.  
  157. ;; bulk version (skip loading external files; already appended below.)
  158. ;; load external settings files. these are the bulk of setup/optimizations.
  159. ;(loop for file in '("functions" "macros" "commands" "hooks" "key-maps")
  160. ;  do (load (merge-pathnames (make-pathname :name file :type "lisp"
  161. ;           :directory '(:relative "conf" "stumpwm")) *home-dir*)))
  162.  
  163. ;; create given groups while keeping focus on current.
  164. (defmacro make-groups-bg (&rest names)
  165.   (let ((ns (mapcar #'(lambda (n) (concatenate 'string "gnewbg " n)) names)))
  166.   `(run-commands ,@ns)))
  167.  
  168. ;; restore data from previous exit (state StumpWM was last using),
  169. (clear-window-placement-rules)
  170. (setf (group-name (first (screen-groups (current-screen)))) "1")
  171. (make-groups-bg "2" "3" "4" "5" "6")
  172. (if (probe-file (data-dir-file "desktop.lisp"))
  173.     (restore-from-file (data-dir-file "desktop.lisp")))
  174. (restore-window-placement-rules (data-dir-file "tile-rules.lisp"))
  175. (cond ((string-equal (group-name (current-group)) *scratchpad-group-name*) (gother)))
  176.  
  177. ;; display a random background image on root window.
  178. ;(display-random-bg)
  179.  
  180. ;; EOF
  181. ;;-----------------------------------------
  182. ;; author: milomouse <vincent[at]fea.st> ;;
  183. ;; *data-dir*/../functions.lisp          ;;
  184. ;;-----------------------------------------
  185.  
  186. (defun fmt-group-status (group)
  187.   (let ((screen (group-screen group)))
  188.     (cond ((eq group (screen-current-group screen))
  189.            #\*)
  190.           ((and (typep (second (screen-groups screen)) 'group)
  191.                 (eq group (second (screen-groups screen))))
  192.            #\+)
  193.           (t #\-))))
  194.  
  195. (defun move-window-to-next-group (current list)
  196. "Move current window to next group but keep focus on current frame."
  197.   (let ((next (next-group current (non-hidden-groups list)))
  198.         (win (group-current-window current)))
  199.     (when (and next win) (move-window-to-group win next))))
  200.  
  201. (defun exchange-windows-remain (win1 win2)
  202. "Exchange windows but keep focus on current frame, unlike exchange-windows."
  203.   (let ((f1 (window-frame win1))
  204.         (f2 (window-frame win2)))
  205.     (unless (eq f1 f2)
  206.       (pull-window win1 f2)
  207.       (pull-window win2 f1))))
  208.  
  209. (defun shift-windows-forward (frames win)
  210. "Exchange windows through cycling frames."
  211.   (when frames
  212.           (let ((frame (car frames)))
  213.                   (shift-windows-forward (cdr frames)
  214.                                          (frame-window frame))
  215.                   (when win
  216.                            (pull-window win frame)))))
  217.  
  218. (defun remember-group (&optional (group (current-group))) ()
  219. "Remember current group information before calling another command or
  220. function. Combined with 'undo' command this allows for toggling between
  221. the two undo states."
  222.   (if (ensure-directories-exist *undo-data-dir*)
  223.     (when group
  224.       (dump-group-to-file
  225.         (make-pathname :name (format nil "screen_~{~A~}_group_~{~A~}"
  226.         (list (char (getenv "DISPLAY") 1)) (list (group-name (current-group))))
  227.         :type "lisp" :defaults *undo-data-dir*)))))
  228.  
  229. (defun remember-all () ()
  230. "Similiar to remember-group except all information is dumped, useful
  231. for next startup or recalling all undo actions."
  232.   (dump-to-datadir "rules") (dump-to-datadir "desktop"))
  233.  
  234. (defun select-random-bg-image ()
  235. "Select a random image from *background-image-path* and display it
  236. on the root window. This is a rewrite of another function to check
  237. for errors and allow more than one picture type, as display command
  238. will only display valid files anyway."
  239.   (if (ensure-directories-exist *background-image-path*)
  240.     (let ((file-list (directory (make-pathname :defaults *background-image-path*
  241.             :name :wild :type :wild :case :common)))
  242.           (*random-state* (make-random-state t)))
  243.       (namestring (nth (random (length file-list)) file-list)))))
  244.  
  245. (defun print-key-seq (seq) (format nil "^B^9*~{~a~^ ~}^n^1*" (mapcar 'print-key seq)))
  246. (defun display-bindings-for-keymaps (key-seq &rest keymaps)
  247. "Display key-bindings for a given keymap, using a simple and clean format."
  248.   (let* ((screen (current-screen))
  249.          (data (mapcan (lambda (map)
  250.                          (mapcar (lambda (b) (format nil "^B^5*~5a^n ~a" (print-key (binding-key b)) (binding-command b))) (kmap-bindings map)))
  251.                        keymaps))
  252.          (cols (ceiling (1+ (length data))
  253.                         (truncate (- (head-height (current-head)) (* 2 (screen-msg-border-width screen)))
  254.                                   (font-height (screen-font screen))))))
  255.     (message-no-timeout "Prefix: ~a~%~{~a~^~%~}"
  256.                         (print-key-seq key-seq)
  257.                         (columnize data cols))))
  258.  
  259. (defun focus-frame (group f)
  260. "Focus frame but do not show-frame-indicator in certain cases."
  261.   (let ((w (frame-window f))
  262.         (last (tile-group-current-frame group))
  263.         (show-indicator nil))
  264.     (setf (tile-group-current-frame group) f)
  265.     (unless (eq f last)
  266.       (setf (tile-group-last-frame group) last)
  267.       (run-hook-with-args *focus-frame-hook* f last)
  268.       (setf show-indicator t))
  269.     (if w (focus-window w) (no-focus group (frame-window last)))
  270.     (if show-indicator (show-frame-outline group))))
  271.  
  272. (defun split-frame-in-dir (group dir)
  273.   (let ((f (tile-group-current-frame group)))
  274.     (if (split-frame group dir)
  275.         (progn
  276.           (update-decoration (frame-window f)))
  277.         (message "Canot split smaller than minimum size."))))
  278.  
  279. (defun run-shell-command-output (command)
  280. "Run a shell command and display results (may hang if used wrong)."
  281.   (check-type command string)
  282.   (echo-string (current-screen) (run-shell-command command t)))
  283.  
  284. ;(defun expand-file-name (path &optional default-directory)
  285. ;;"Expand filenames with special focus on home dir."
  286. ;  (let ((first-char (subseq path 0 1))
  287. ;    (home-dir *home-dir*)
  288. ;    (dir (if default-directory
  289. ;      (if (string= (subseq (reverse default-directory) 0 1) "/")
  290. ;        default-directory
  291. ;        (concatenate 'string default-directory "/")))))
  292. ;  (cond ((string= first-char "~") (concatenate 'string home-dir (subseq path 2)))
  293. ;        ((string= first-char "/") path)
  294. ;        (dir (if (strings= (subseq 0 1) "/")
  295. ;          (concatenate 'string dir path)
  296. ;          (expand-file-name (concatenate 'string dir path))))
  297. ;        (t (concatenate 'string home-dir path)))))
  298.  
  299. (defun eval-command (cmd &optional interactivep)
  300. "Execute a lisp command and display the result, skipping mode-line updates."
  301.   (labels ((parse-and-run-command (input)
  302.              (let* ((arg-line (make-argument-line :string input :start 0))
  303.                     (cmd (argument-pop arg-line)))
  304.                (let ((*interactivep* interactivep))
  305.      (call-interactively cmd arg-line)))))
  306.     (multiple-value-bind (result error-p)
  307.       ;; <original quote=
  308.       ;; this fancy footwork lets us grab the backtrace from where the error actually happened.>
  309.       (restart-case (handler-bind
  310.           ((error (lambda (c)
  311.                     (invoke-restart 'eval-command-error
  312.                           (format nil "^B^0*{{ ^9*~a ^0*}} ^n~A~a"
  313.                                 cmd c (if *show-command-backtrace*
  314.                                           (backtrace-string) ""))))))
  315.             (parse-and-run-command cmd))
  316.         (eval-command-error (err-text)
  317.           (values err-text t)))
  318.       (cond ((stringp result)
  319.              (if error-p  (message-no-timeout "~a" result)
  320.                           (message "~a" result)))
  321.             ((eq result :abort)
  322.              (unless *suppress-abort-messages* (message "Abort.")))))))
  323.  
  324. (defun update-resize-map ()
  325. "Update the (i)resize map, using cleaner key-bindings."
  326.   (let ((m (setf *resize-map* (make-sparse-keymap))))
  327.     (let ((i *resize-increment*))
  328.     (labels ((dk (m k c) (define-key m k (format nil c i))))
  329.       (dk m (kbd "k") "resize 0 -~D")
  330.       (dk m (kbd "(") "resize 0 -~D")
  331.       (dk m (kbd "j") "resize 0 ~D")
  332.       (dk m (kbd ")") "resize 0 ~D")
  333.       (dk m (kbd "h") "resize -~D 0")
  334.       (dk m (kbd "9") "resize -~D 0")
  335.       (dk m (kbd "l") "resize ~D 0")
  336.       (dk m (kbd "0") "resize ~D 0")
  337.       (dk m (kbd "RET") "exit-iresize")
  338.       (dk m (kbd "ESC") "abort-iresize")
  339.     M)))) (update-resize-map)
  340.  
  341. ;; incomplete, was just testing alsa out..
  342. ;(defcommand amixer-control (channel arg)
  343. ;  (let ((variance (run-shell-command (concatenate 'string
  344. ;      "print ${$(amixer sget " channel ")[-2,-1]//(\[|\]|.*dB|-)}"))))
  345. ;    (cond ((and (eq channel "PCM") (not (eq arg "toggle")))
  346. ;          (message (first (concatenate 'string variance))))
  347. ;          (t (message (second (concatenate 'string variance))))
  348. ;          )))
  349.  
  350. ;; EOF
  351. ;;-----------------------------------------
  352. ;; author: milomouse <vincent[at]fea.st> ;;
  353. ;; *data-dir*/../macros.lisp             ;;
  354. ;;-----------------------------------------
  355.  
  356. ;; faster hook management.
  357. (defmacro replace-hook (hook fn)
  358.   `(remove-hook, hook, fn)
  359.   `(add-hook, hook, fn))
  360.  
  361. ;; Last rule to match takes precedence!
  362. ;; TIP: if the argument to :title or :role begins with an ellipsis, a substring
  363. ;; match is performed.
  364. ;; TIP: if the :create flag is set then a missing group will be created and
  365. ;; restored from *data-dir*/create file.
  366. ;; TIP: if the :restore flag is set then group dump is restored even for an
  367. ;; existing group using *data-dir*/restore file.
  368. ;; frame raise lock (lock AND raise == jumpto)
  369.  
  370. ;; internet related workspace:
  371. (define-frame-preference "3"
  372.   (0    nil   t     :instance "luakit")
  373.   (0    nil   t     :instance "Navigator"))
  374.  
  375. ;; largely undefined, temporal workspace:
  376. (define-frame-preference "6"
  377.   (0    t     t     :class "Ossxmix")
  378.   (0    t     t     :class "Gliv"))
  379.  
  380. ;; EOF
  381. ;;-----------------------------------------
  382. ;; author: milomouse <vincent[at]fea.st> ;;
  383. ;; *data-dir*/../commands.lisp           ;;
  384. ;;-----------------------------------------
  385.  
  386. ;; create a scratchpad group if none exist and toggle between viewing current group and scratchpad group.
  387. ;; (idea from Ion3+ window-manager except scratchpad is a group and not a floating frame)
  388. ;; (also inspired by another users 'scratchpad' command set, although i found all the functions
  389. ;;  and parameters to be wasteful, especially since it's created per screen anyway(?:[untested aspect]))
  390. (defcommand scratchpad () ()
  391. "Create a scratchpad group for current screen, if not found, and toggle between the scatchpad group
  392. and the current group upon reissue of the same command."
  393.   (let* ((sg (find-group (current-screen) *scratchpad-group-name*)) (cg (current-group)))
  394.     (if sg
  395.         (cond ((eq cg sg) (gother)) (t (switch-to-group sg) (message "scratchpad")))
  396.       (progn (gnew *scratchpad-group-name*) (message "scratchpad")))))
  397.  
  398. ;; undo to last state in current-group (set by calling 'remember-group' in various commands/functions),
  399. ;; unless no state found. (once i learn more about lisp i'll try removing the use of a second temp file)
  400. (defcommand undo (&optional (group (current-group))) ()
  401. "If an undo state exists for group, revert to last state. Multiple calls toggle between the two states."
  402.   (when group
  403.     (let* ((i (make-pathname :name (format nil "screen_~{~A~}_group_~{~A~}"
  404.               (list (char (getenv "DISPLAY") 1)) (list (group-name (current-group))))
  405.               :type "lisp" :defaults *undo-data-dir*)))
  406.       (if (probe-file i)
  407.         (progn
  408.           (let* ((o (make-pathname :name (format nil "screen_~{~A~}_group_~{~A~}"
  409.                     (list (char (getenv "DISPLAY") 1)) (list (group-name (current-group))))
  410.                     :type "bak" :defaults *undo-data-dir*)))
  411.             (dump-group-to-file o)
  412.           (restore-from-file i)
  413.           (rename-file o i)))
  414.         (message "Cannot undo previous state. Nothing found for group ~A" (list (group-name group)))))))
  415.  
  416. ;; dump [current]-group (for current-screen), [current]-screen, desktop or window-placement-rules
  417. ;; to a dynamically named file in user defined *data-dir*.
  418. (defcommand dump-to-datadir (expr) (:rest)
  419. "Dump group (from current-screen), screen (current-screen), desktop or rules to file in data-dir.
  420. Just specify what you want to dump and this will dynamically create and name file accordingly."
  421.   (cond ((string-equal expr 'group)
  422.           (let* ((o (make-pathname :name (format nil "screen_~{~A~}_group_~{~A~}"
  423.                     (list (char (getenv "DISPLAY") 1)) (list (group-name (current-group))))
  424.                     :type "lisp" :defaults *data-dir*)))
  425.             (dump-group-to-file o) (message "~A dumped" expr)))
  426.         ((string-equal expr 'screen)
  427.           (let* ((o (make-pathname :name (format nil "screen_~{~A~}" (list (char (getenv "DISPLAY") 1)))
  428.                     :type "lisp" :defaults *data-dir*)))
  429.             (dump-screen-to-file o) (message "~A dumped" expr)))
  430.         ((string-equal expr 'rules)
  431.           (let* ((o (make-pathname :name "tile-rules" :type "lisp" :defaults *data-dir*)))
  432.             (dump-window-placement-rules o) (message "~A dumped" expr)))
  433.         ((string-equal expr 'desktop)
  434.           (let* ((o (make-pathname :name "desktop" :type "lisp" :defaults *data-dir*)))
  435.             (dump-desktop-to-file o) (message "~A dumped" expr)))
  436.         (t (message "dont know how to dump ~a" expr))))
  437.  
  438. ;; restore [current]-group (for current-screen), [current]-screen, desktop or window-placement-rules
  439. ;; from a previously created file (more correctly from DUMP-TO-DATADIR) in user defined *data-dir*.
  440. (defcommand restore-from-datadir (expr) (:rest)
  441. "Restore file from data-dir, previously created by 'dump-to-datadir', according to what you specify.
  442. You may restore group (for current-screen), screen (for current-screen), desktop or rules. This will
  443. restore file dynamically by pattern patching, according to what you're restoring, to file name by
  444. looking at what you're currently using.
  445.  
  446. E.g. if you're in group 2 on screen 0 and you enter 'restore-from-datadir group' it will look for a
  447. file named 'screen_0_group_2.lisp' (created by accompanying 'dump-to-datadir') in your data-dir and
  448. restore it. If no matching file is found it will skip loading of any files and print an error message.
  449.  
  450. Note: if restoring a group file was successful then an undo state is created so you can technically
  451. undo the loading of that file. There are no undo states when loading 'screen', 'desktop' or 'rules'."
  452.   (cond ((string-equal expr 'group)
  453.           (let* ((i (make-pathname :name (format nil "screen_~{~A~}_group_~{~A~}"
  454.                     (list (char (getenv "DISPLAY") 1)) (list (group-name (current-group))))
  455.                     :type "lisp" :defaults *data-dir*)))
  456.             (if (probe-file i)
  457.                 (progn (restore-from-file i) (remember-group) (message "~A restored" expr))
  458.               (message "unable to find valid ~A file in data dir" expr))))
  459.         ((string-equal expr 'screen)
  460.           (let* ((i (make-pathname :name (format nil "screen_~{~A~}" (list (char (getenv "DISPLAY") 1)))
  461.                     :type "lisp" :defaults *data-dir*)))
  462.             (if (probe-file i)
  463.                 (progn (restore-from-file i) (message "~A restored" expr))
  464.               (message "unable to find valid ~A file in data dir" expr))))
  465.         ((string-equal expr 'rules)
  466.           (if (probe-file (data-dir-file "tile-rules.lisp"))
  467.               (progn (restore-window-placement-rules (data-dir-file "tile-rules.lisp"))
  468.                      (message "~A restored" expr))
  469.             (message "unable to find valid ~A file in data dir" expr)))
  470.         ((string-equal expr 'desktop)
  471.           (if (probe-file (data-dir-file "desktop.lisp"))
  472.               (progn (restore-from-file (data-dir-file "tile-rules.lisp")) (message "~A restored" expr))
  473.             (message "unable to find valid ~A file in data dir" expr)))
  474.         (t (message "dont know how to restore ~a" expr))))
  475.  
  476. ;; swap neighbors but do not change focus to specified neighbor direction.
  477. (defcommand (exchange-direction-remain tile-group) (dir &optional (win (current-window)))
  478.     ((:direction "Direction: "))
  479.     "If neighbor window exists, swap current window with neighbor in specified direction while
  480. keeping focus on current frame, unlike 'exchange-direction' where focus moves to neighbor."
  481.   (if win
  482.       (let* ((frame-set (group-frames (window-group win)))
  483.              (neighbour (neighbour dir (window-frame win) frame-set)))
  484.         (if (and neighbour (frame-window neighbour))
  485.             (exchange-windows-remain win (frame-window neighbour))
  486.             (message "No window in direction ~A!" dir)))
  487.       (message "No window in current frame!")))
  488.  
  489. ;; move focused window to next/prev group without following it. focus remains on current frame.
  490. (defcommand gmove-next () ()
  491. "Move focused window to next group without switching to it. Unlike behavior in gnext-with-window."
  492.   (move-window-to-next-group (current-group) (sort-groups (current-screen))))
  493. (defcommand gmove-prev () ()
  494. "Move focused window to previous group without switching to it. Unlike behavior in gprev-with-window."
  495.   (move-window-to-next-group (current-group) (reverse (sort-groups (current-screen)))))
  496.  
  497. ;; from simias: rotate windows.
  498. (defcommand rotate-windows () ()
  499.   (let* ((frames (group-frames (current-group)))
  500.             (win (frame-window (car (last frames)))))
  501.           (shift-windows-forward frames win)))
  502.  
  503. ;; rework of original random-bg command, display random wallpaper on root window.
  504. (defcommand display-random-bg () () "Display a random background image on root window."
  505.   (run-shell-command
  506.     (concatenate 'string "display -window root -resize 1600x900! " (select-random-bg-image))))
  507.  
  508. ;; designate master window/frame (should probably use current frame number, but less dynamic?)
  509. (defcommand (master-make tile-group) () () "Designate current window as Master."
  510.   (renumber 0) (repack-window-numbers) (remember-group))
  511. (defcommand (master-focus tile-group) () () "Focus on designated Master window." (select-window-by-number 0))
  512.  
  513. ;; swap current window with master (should be 0 (from master-make)) and desginate it as the new master.
  514. (defcommand (master-swap tile-group) (num &optional (group (current-group))) ((:window-number t))
  515.   "If current window is not Master and Master exists, swap current
  516. window with Master and designate this as the new Master."
  517.   (labels ((match (win)
  518.               (= (window-number win) num)))
  519.   (let ((win (find-if #'match (group-windows group))))
  520.     (when (and win group) (exchange-windows (current-window) win) (master-make)))))
  521.  
  522. ;; [with *shell-program* "/bin/zsh"] look for detached 'tmux [socket] xorg' session and attach, else create new.
  523. ;; (useful for StumpWM crashes, as tmux windows survive crashes and this command brings them back)
  524. (defcommand tmux-attach-else-new () () "Find detached tmux session and attach, else create new session."
  525.   (run-shell-command
  526.   "if [[ -n ${$(tmux -S /tmp/.${UID}/tmux/xorg list-session|grep -v attached)[1]//:} ]]; then
  527.    urxvt -e tmux -S /tmp/.${UID}/tmux/xorg attach-session -t ${$(tmux -S /tmp/.${UID}/tmux/xorg list-session|grep -v attached)[1]//:}
  528.  else
  529.    urxvt -e tmux -S /tmp/.${UID}/tmux/xorg new-session
  530.  fi"))
  531.  
  532. ;; [with *shell-program* "/bin/zsh"] look for detached 'tmux [socket] rtorrent' session and attach, else nothing.
  533. (defcommand tmux-attach-rtorrent () () "Find detached rtorrent session and attach, else not running so do nothing."
  534.   (run-shell-command
  535.   "if [[ -n ${$(tmux -S /tmp/.${UID}/tmux/rtorrent list-session|grep -v attached)[1]//:} ]]; then
  536.    urxvt -e tmux -S /tmp/.${UID}/tmux/rtorrent attach-session -t ${$(tmux -S /tmp/.${UID}/tmux/rtorrent list-session|grep -v attached)[1]//:}
  537.  fi"))
  538.  
  539. ;; reassign original commands to *-forget
  540. (defcommand quit-forget () () "Quit StumpWM without remembering current state."
  541.   (with-open-file (stream *debug-file* :direction :io :if-exists :supersede))
  542.   (cond ((find-group (current-screen) *scratchpad-group-name*)
  543.     (if (eq (current-group) (find-group (current-screen) *scratchpad-group-name*))
  544.         (gkill)
  545.       (progn
  546.         (gnext) (kill-group
  547.         (find-group (current-screen) *scratchpad-group-name*)
  548.         (current-group))))))
  549.   (throw :top-level :quit))
  550.  
  551. (defcommand restart-soft-forget () () "Soft Restart StumpWM without remembering current state.
  552. The lisp process isn't restarted. Instead, control jumps
  553. to the very beginning of the stumpwm program. This
  554. differs from RESTART, which restarts the unix process.
  555.  
  556. Since the process isn't restarted, existing customizations remain
  557. after the restart." (throw :top-level :restart))
  558.  
  559. (defcommand loadrc-forget () () "Reload the @file{~/.stumpwmrc} file without remember current state."
  560.   (handler-case
  561.       (progn
  562.         (with-restarts-menu (load-rc-file nil)))
  563.       (error (c)
  564.         (message "^B^1*Error loading rc file:^n ~A" c))
  565.       (:no-error (&rest args)
  566.         (declare (ignore args))
  567.         (message "rc file loaded successfully."))))
  568.  
  569. (defcommand loadrc () () "Reload the @file{~/.stumpwmrc} file while remembering current state."
  570.   (remember-all) (loadrc-forget))
  571.  
  572. (defcommand restart-soft () ()
  573. "Soft Restart StumpWM while remembering current state.
  574. The lisp process isn't restarted. Instead, control jumps
  575. to the very beginning of the stumpwm program. This
  576. differs from RESTART, which restarts the unix process.
  577.  
  578. Since the process isn't restarted, existing customizations remain
  579. after the restart." (remember-all) (restart-soft-forget))
  580. (defcommand-alias restart restart-soft)
  581.  
  582. (defcommand quit () ()
  583. "Quit StumpWM while remembering current state."
  584.   (cond ((find-group (current-screen) *scratchpad-group-name*)
  585.     (if (eq (current-group) (find-group (current-screen) *scratchpad-group-name*))
  586.         (gkill)
  587.       (progn
  588.         (gnext) (kill-group
  589.         (find-group (current-screen) *scratchpad-group-name*)
  590.         (current-group))))))
  591.   (remember-all) (quit-forget))
  592.  
  593. ;; redefine resize commands
  594. (defcommand (resize tile-group) (width height) ((:number "+ Width: ")
  595.                                                 (:number "+ Height: "))
  596.   "Resize the current frame by @var{width} and @var{height} pixels."
  597.   (let* ((group (current-group))
  598.          (f (tile-group-current-frame group)))
  599.     (if (atom (tile-group-frame-tree group))
  600.         (message "No more frames!")
  601.         (progn
  602.           (clear-frame-outlines group)
  603.           (resize-frame group f width :width)
  604.           (resize-frame group f height :height)
  605.           (draw-frame-outlines group (current-head))
  606.           (curframe))))) (defcommand (iresize tile-group) () ()
  607.   "Remember current state before starting the interactive resize mode. A new keymap
  608. specific to resizing the current frame is loaded. Hit @key{C-g}, @key{RET},
  609. or @key{ESC} to exit." (let ((frame (tile-group-current-frame (current-group))))
  610.     (if (atom (tile-group-frame-head (current-group) (frame-head (current-group) frame)))
  611.         (message "There's only 1 frame!")
  612.         (progn
  613.           (remember-group)
  614.           (when *resize-hides-windows*
  615.             (dolist (f (head-frames (current-group) (current-head)))
  616.               (clear-frame f (current-group))))
  617.           (push-top-map *resize-map*)
  618.           (draw-frame-outlines (current-group) (current-head)))
  619.         ))) (defcommand (exit-iresize tile-group) () ()
  620.   "Exit from the interactive resize mode, quietly." (resize-unhide) (pop-top-map) (redisplay))
  621. (defcommand (quiet-resize tile-group) (width height) ((:number "+ Width: ")
  622.                                                       (:number "+ Height: "))
  623.   "Resize the current frame by @var{width} and @var{height} pixels without highlighting frames."
  624.   (let* ((group (current-group))
  625.          (f (tile-group-current-frame group)))
  626.     (if (atom (tile-group-frame-tree group))
  627.         (message "No more frames!")
  628.         (progn
  629.           (resize-frame group f width :width)
  630.           (resize-frame group f height :height)))))
  631. (defcommand (abort-iresize tile-group) () () "Undo resize changes if aborted."
  632.   (resize-unhide) (undo) (message "Abort resize") (pop-top-map))
  633.  
  634. ;; remove frame and reallocate space while remembering removed frame position, also hiding frame-indicator.
  635. (defcommand (remove-split tile-group)
  636. (&optional (group (current-group)) (frame (tile-group-current-frame group))) ()
  637. "Remove the specified frame in the specified group (defaults to current group, current
  638. frame). Windows in the frame are migrated to the frame taking up its space but not before
  639. remembering their previous positions, also hiding frame highlights."
  640.   (let* ((head (frame-head group frame))
  641.          (current (tile-group-current-frame group))
  642.          (tree (tile-group-frame-head group head))
  643.          (s (closest-sibling (list tree) frame))
  644.          (l (tree-accum-fn s
  645.                            (lambda (&rest siblings)
  646.                              (car siblings))
  647.                            #'identity)))
  648.     ;; <only remove the current frame if it has a sibling>
  649.     (if (atom tree)
  650.         (message "No more frames!")
  651.         (when s
  652.           (remember-group)
  653.           (when (frame-is-head group frame)
  654.             (setf (frame-number l) (frame-number frame)))
  655.           ;; <move the windows from the removed frame to its sibling>
  656.           (migrate-frame-windows group frame l)
  657.           ;; <if the frame has no window, give it the current window of the current frame.>
  658.           (unless (frame-window l)
  659.             (setf (frame-window l)
  660.                   (frame-window frame)))
  661.           ;; <unsplit>
  662.           (setf (tile-group-frame-head group head) (remove-frame tree frame))
  663.           ;; <update the current frame and sync all windows>
  664.           (when (eq frame current)
  665.             (setf (tile-group-current-frame group) l))
  666.           (tree-iterate tree
  667.                         (lambda (leaf)
  668.                           (sync-frame-windows group leaf)))
  669.           (frame-raise-window group l (frame-window l) nil)
  670.           (when (frame-window l)
  671.             (update-decoration (frame-window l)))))))
  672.        
  673. ;; remember states if not already in 'only' mode (e.g., one frame).
  674. (defcommand only () () "Delete all the frames but the current one and grow it
  675. to take up the entire head and remember previous states if entire head
  676. is not already taken up (e.g. already in 'only' mode)."
  677.   (let* ((screen (current-screen))
  678.          (group (screen-current-group screen))
  679.          (win (group-current-window group))
  680.          (head (current-head group))
  681.          (frame (copy-frame head)))
  682.     (if (atom (tile-group-frame-head group head))
  683.       (message "Will not remember state, already using one frame.")
  684.       (progn
  685.         (remember-group)
  686.         (mapc (lambda (w)
  687.                 (unless (eq (window-frame w) (tile-group-current-frame group))
  688.                   (hide-window w))
  689.                 (setf (window-frame w) frame))
  690.               (head-windows group head))
  691.         (setf (frame-window frame) win
  692.               (tile-group-frame-head group head) frame
  693.               (tile-group-current-frame group) frame)
  694.         (focus-frame group frame)
  695.         (if (frame-window frame)
  696.             (update-decoration (frame-window frame))
  697.             (show-frame-indicator group))
  698.         (sync-frame-windows group (tile-group-current-frame group))))))
  699.  
  700. ;; remember frame positions before splitting (do not edit split-frames function for this)
  701. (defcommand (hsplit tile-group) () () "Remember current state before splitting the
  702. current frame into 2 side-by-side frames." (remember-group) (split-frame-in-dir (current-group) :column))
  703. (defcommand (vsplit tile-group) () ()  "Remember current state before splitting the
  704. current frame into 2 frames, one on top of the other." (remember-group) (split-frame-in-dir (current-group) :row))
  705.  
  706. ;; dump to file, which is silent, but with more informative prompts.
  707. (defcommand dump-group-to-file (file) ((:rest "group to file: "))
  708.   "Dumps the frames of the current group of the current screen to the named file."
  709.   (dump-to-file (dump-group (current-group)) file))
  710. (defcommand dump-screen-to-file (file) ((:rest "screen to file: "))
  711.   "Dumps the frames of all groups of the current screen to the named file."
  712.   (dump-to-file (dump-screen (current-screen)) file))
  713. (defcommand dump-desktop-to-file (file) ((:rest "desktop to file: "))
  714.   "Dumps the frames of all groups of all screens to the named file."
  715.   (dump-to-file (dump-desktop) file))
  716.  
  717. ;; predefined echoes for speed, else use 'shell-command-output'.
  718. (defcommand echo-highcpu-user () () "" (message-no-timeout (run-shell-command "ps -U root,privoxy,15,daemon,nobody,unbound --deselect -C tmux,urxvt k -%cpu opid,nice,args:70,etime:10,%cpu,pmem | head -75" t)))
  719. (defcommand echo-highcpu-root () () "" (message-no-timeout (run-shell-command "ps -U h,privoxy,15,daemon,nobody,unbound --deselect -C tmux,urxvt k -%cpu opid,nice,args:70,etime:10,%cpu,pmem | head -75" t)))
  720. (defcommand echo-highcpu-rest () () "" (message-no-timeout (run-shell-command "ps -U root,h --deselect -C tmux,urxvt k -%cpu opid,nice,args:70,etime:10,%cpu,pmem | head -75" t)))
  721. (defcommand echo-mifo-stumpwm () () "" (echo-string (current-screen) (run-shell-command "mifo --stumpwm" t)))
  722. (defcommand echo-mifo-raw () () "" (echo-string (current-screen) (run-shell-command "mifo --raw" t)))
  723. (defcommand echo-mifo-current-list () () "" (echo-string (current-screen) (run-shell-command "mifo --show current|grep -A 7 -B 7 $(mifo --raw)|sed 's|'$(mifo --raw)'|^B^1*&^n|'" t)))
  724. (defcommand echo-mifo-playlists () () "" (echo-string (current-screen) (run-shell-command "mifo --show" t)))
  725. (defcommand echo-mifo-fav-add () () "" (echo-string (current-screen) (run-shell-command "mifo --fav-add" t)))
  726. (defcommand echo-mifo-fav-del () () "" (echo-string (current-screen) (run-shell-command "mifo --fav-delete" t)))
  727. (defcommand echo-mifo-next () () "" (echo-string (current-screen) (run-shell-command "mifo --next ; sleep 1 ; mifo --stumpwm" t)))
  728. (defcommand echo-mifo-prev () () "" (echo-string (current-screen) (run-shell-command "mifo --prev ; sleep 1 ; mifo --stumpwm" t)))
  729. (defcommand echo-mifo-random () () "" (echo-string (current-screen) (run-shell-command "mifo -r ; sleep 1 ; mifo --stumpwm" t)))
  730. (defcommand echo-oss-vol () () "" (echo-string (current-screen) (run-shell-command "ossvol -a" t)))
  731. (defcommand echo-oss-volup () () "" (run-shell-command "ossvol -i 1") (echo-oss-vol))
  732. (defcommand echo-oss-voldown () () "" (run-shell-command "ossvol -d 1") (echo-oss-vol))
  733. (defcommand echo-oss-volmute () () "" (run-shell-command "ossvol -m"))
  734. (defcommand echo-oss-speakers () () "" (echo-string (current-screen) (run-shell-command "ossvol --speakers --quiet" t)) (echo-oss-vol))
  735. (defcommand echo-oss-headphones () () "" (run-shell-command "ossvol --headphones --quiet") (echo-oss-vol))
  736. (defcommand echo-mail () () "" (echo-string (current-screen) (run-shell-command "print - @fea.st: ${#$(find /howl/mail/FastMail/*/new -type f)}" t)))
  737. (defcommand echo-wlan () () "" (echo-string (current-screen) (run-shell-command "iwconfig wlan0" t)))
  738. (defcommand echo-free-hdd () () "" (echo-string (current-screen) (run-shell-command "di -x debugfs,tmpfs -d h -Af SMTufI" t)))
  739. (defcommand echo-free-mem () () "" (echo-string (current-screen) (run-shell-command "print '^B^6/free^1* used^5* base^n';free -m|awk 'NR==2 {print $4,$3,$2}'" t)))
  740. (defcommand echo-battery () () "" (echo-string (current-screen) (run-shell-command "acpi -tf;repeat 36; do printf '='; done;print;ibam --percentbattery" t)))
  741. (defcommand echo-loadavg () () "" (echo-string (current-screen) (run-shell-command "print ${$(</proc/loadavg)[1,3]}" t)))
  742. (defcommand echo-colors-brief () () "Output a brief list of currently defined colors." (echo-string (current-screen) (eval "
  743. BOLD ^B^0*black ^1*red ^2*green ^3*yellow ^4*blue ^5*magenta ^6*cyan ^7*white ^8*user ^9*user^n
  744. NONE ^0*black ^1*red ^2*green ^3*yellow ^4*blue ^5*magenta ^6*cyan ^7*white ^8*user ^9*user^n")))
  745.  
  746. ;; sent output of command to echo-string (may hang if used wrong).
  747. (defcommand shell-command-output (command) ((:string "execute/output: "))
  748.   "Take output of command and display it. This may hang if used wrong."
  749.   (check-type command string) (run-shell-command-output command))
  750. (defcommand pout (&optional (initial "")) (:rest)
  751.   "Prompt with the given argument as command, await any additional arguments
  752. and then run as shell command, displaying a message with any of the
  753. command's output. This may hang if used wrong."
  754.   (let ((cmd (read-one-line (current-screen) ": " :initial-input initial)))
  755.     (when cmd (shell-command-output cmd))))
  756.  
  757. ;; manpage reader. needs filename completion, etc.. very simple right now
  758. (defcommand manpage (command) ((:rest "manpage: ")) ""
  759.   (run-shell-command (format nil "urxvt -e man ~a" command)))
  760.  
  761. ;; prompt for X selection to transfer, or prompt for X selection to echo
  762. (defcommand prompt-xclip (filename) ((:rest "xclip -selection ")) ""
  763.   (run-shell-command (format nil "xclip -selection ~a" filename)))
  764. ;; prompt for X selection to display contents of.
  765. (defcommand echo-xclip (filename) ((:rest "echo.selection: ")) ""
  766.   (echo-string (current-screen) (run-shell-command (format nil "xclip -selection ~a -o" filename) t)))
  767.  
  768. ;; i don't like 'Colon' showing editable command in prompt
  769. ;; perhaps i'll figure out a global macro/function for this..
  770. (defcommand prompt-mifo-command (filename) ((:rest "mifo.command: ")) ""
  771.   (run-shell-command (format nil "mifo --command ~a" filename)))
  772. (defcommand prompt-mifo-next (filename) ((:rest "mifo.next: ")) ""
  773.   (echo-string (current-screen) (run-shell-command (format nil "mifo --next ~a && sleep 2" filename) t))
  774.   (echo-mifo-stumpwm))
  775. (defcommand prompt-mifo-prev (filename) ((:rest "mifo.previous: ")) ""
  776.   (echo-string (current-screen) (run-shell-command (format nil "mifo --prev ~a && sleep 2" filename) t))
  777.   (echo-mifo-stumpwm))
  778. (defcommand prompt-mifo-save (filename) ((:rest "mifo.save-as: ")) ""
  779.   (echo-string (current-screen) (run-shell-command (format nil "mifo --save ~a" filename) t)))
  780. (defcommand prompt-mifo-load (filename) ((:rest "mifo.load: "))
  781.   (run-shell-command (format nil "mifo --load ~a" filename))) ""
  782. (defcommand prompt-mifo-append (filename) ((:rest "mifo.append: "))
  783.   (run-shell-command (format nil "mifo --append ~a" filename))) ""
  784. (defcommand prompt-mifo-playlist (filename) ((:rest "mifo.playlist: "))
  785.   (run-shell-command (format nil "mifo --playlist ~a" filename))) ""
  786. (defcommand prompt-mifo-reload (filename) ((:rest "mifo.reload: ")) ""
  787.   (run-shell-command (format nil "mifo --reload ~a" filename)))
  788.  
  789. ;; evaluate string, with prettier color.
  790. (defcommand eval-line (cmd) ((:rest "eval: "))
  791.   "Evaluate the s-expression and display the result(s)."
  792.   (handler-case
  793.     (message "^B^10~{~a~^~%~}"
  794.       (mapcar 'prin1-to-string
  795.         (multiple-value-list (eval (read-from-string cmd)))))
  796.     (error (c)
  797.       (err "^B^5*~A" c))))
  798.  
  799. ;; run or raise.
  800. ;;(defcommand ror_firefox () () "" (setf *run-or-raise-all-groups* t) (run-or-raise "firefox" '(:instance "Navigator")))
  801. ;;(defcommand ror_jumanji () () "" (setf *run-or-raise-all-groups* t) (run-or-raise "jumanji" '(:class "Jumanji")))
  802. (defcommand ror_luakit () () "" (setf *run-or-raise-all-groups* t) (run-or-raise "luakit" '(:class "luakit")))
  803. (defcommand ror_mutt () () "" (setf *run-or-raise-all-groups* t)
  804.   (run-or-raise "urxvt -title '[urxvt] mutt' -e mutt -F ${XDG_CONFIG_DIR:-${HOME}}/mutt/muttrc" '(:title "\\[urxvt\\] mutt")))
  805.  
  806. ;; EOF
  807. ;;-----------------------------------------
  808. ;; author: milomouse <vincent[at]fea.st> ;;
  809. ;; *data-dir*/../hooks.lisp              ;;
  810. ;;-----------------------------------------
  811.  
  812. ;; show local windows in frame when focusing on it. unfortunately the echo
  813. ;; command is cropped when focused frame overlaps part of it's output.
  814. ;(defun local-list (from-frame to-frame)
  815. ;  (run-commands "echo-frame-windows"))
  816. ;add-hook *focus-frame-hook* 'local-list)
  817.  
  818. ;; display the keysequence in progress (found this).
  819. ;(defun key-press-hook (key key-seq cmd)
  820. ;  (declare (ignore key))
  821. ;  (unless (eq *top-map* *resize-map*)
  822. ;    (let ((*message-window-gravity* :top-right))
  823. ;      (message "Key sequence: ~A" (print-key-seq (reverse key-seq))))
  824. ;    (when (stringp cmd)
  825. ;      (sleep 0.1))))
  826. ;(replace-hook *key-press-hook* 'key-press-hook)
  827.  
  828. ;; EOF
  829. ;;-----------------------------------------
  830. ;; author: milomouse <vincent[at]fea.st> ;;
  831. ;; *data-dir*/../key-maps.lisp           ;;
  832. ;;-----------------------------------------
  833.  
  834. ;; export custom maps.
  835. (export '(*echo-map* *xsel-map* *xclip-clipboard-map* *xclip-primary-map*
  836.           *frequent-map* *win-frame-map* *mplayer-map1* *mplayer-map2*))
  837.  
  838. ;; set a few undefined keysyms, unavailable in */stumpwm/keysyms.lisp
  839. (define-keysym #x1008ff02 "XF86MonBrightnessUp")
  840. (define-keysym #x1008ff03 "XF86MonBrightnessDown")
  841.  
  842. ;; set "Super+Shift+\" as prefix for root-map bindings (this will not be used)
  843. (set-prefix-key (kbd "s-|"))
  844.  
  845. ;; some useful window/frame commands.
  846. (defvar *win-frame-map*
  847.   (let ((m (make-sparse-keymap)))
  848.     (labels ((dk (m k c) (define-key m k c)))
  849.     (dk m (kbd "r")   "remember")
  850.     (dk m (kbd "f")   "forget")
  851.     (dk m (kbd "p")   "place-existing-windows")
  852.     (dk m (kbd "n")   "repack-window-numbers")
  853.     (dk m (kbd "ESC") "abort")
  854.    M)))
  855.  
  856. ;; transfer contents of clipboard into other buffers, or manually type cmd.
  857. (defvar *xclip-clipboard-map*
  858.   (let ((m (make-sparse-keymap)))
  859.     (labels ((dk (m k c) (define-key m k c)))
  860.     (dk m (kbd "b") "exec xclip -selection clipboard -o | xclip -selection buffer-cut -i")
  861.     (dk m (kbd "p") "exec xclip -selection clipboard -o | xclip -selection primary -i")
  862.     (dk m (kbd "s") "exec xclip -selection clipboard -o | xclip -selection secondary -i")
  863.     (dk m (kbd ";") "prompt-xclip")
  864.     (dk m (kbd ":") "echo-xclip")
  865.     (dk m (kbd "ESC") "abort")
  866.    M)))
  867.  
  868. (defvar *xclip-primary-map*
  869.   (let ((m (make-sparse-keymap)))
  870.     (labels ((dk (m k c) (define-key m k c)))
  871.     (dk m (kbd "b") "exec xclip -selection primary -o | xclip -selection buffer-cut -i")
  872.     (dk m (kbd "c") "exec xclip -selection primary -o | xclip -selection clipboard -i")
  873.     (dk m (kbd "s") "exec xclip -selection primary -o | xclip -selection secondary -i")
  874.     (dk m (kbd ";") "prompt-xclip")
  875.     (dk m (kbd ":") "echo-xclip")
  876.     (dk m (kbd "ESC") "abort")
  877.    M)))
  878.  
  879. ;; interact with the xselection and meta commands.
  880. (defvar *xsel-map*
  881.   (let ((m (make-sparse-keymap)))
  882.     (labels ((dk (m k c) (define-key m k c)))
  883.     (dk m (kbd "c")   "copy-last-message")
  884.     (dk m (kbd "g")   "getsel")
  885.     (dk m (kbd "m")   "meta")
  886.     (dk m (kbd "p")   "putsel")
  887.     (dk m (kbd "s")   "window-send-string")
  888.     (dk m (kbd "ESC") "abort")
  889.   M)))
  890.  
  891. ;; frequently used echoes for quick information grabbing.
  892. (defvar *echo-map*
  893.   (let ((m (make-sparse-keymap)))
  894.     (labels ((dk (m k c) (define-key m k c)))
  895.     (dk m (kbd "b")   "echo-battery")
  896.     (dk m (kbd "c")   "echo-colors-brief")
  897.     (dk m (kbd "d")   "echo-date")
  898.     (dk m (kbd "f")   "echo-free-mem")
  899.     (dk m (kbd "h")   "echo-free-hdd")
  900.     (dk m (kbd "l")   "echo-loadavg")
  901.     (dk m (kbd "m")   "echo-mifo-stumpwm")
  902.     (dk m (kbd "M")   "echo-mifo-raw")
  903.     (dk m (kbd "C-m") "echo-mifo-current-list")
  904.     (dk m (kbd "n")   "echo-wlan")
  905.     (dk m (kbd "p")   "echo-highcpu-user")
  906.     (dk m (kbd "P")   "echo-highcpu-root")
  907.     (dk m (kbd "C-p") "echo-highcpu-rest")
  908.     (dk m (kbd "u")   "echo-mail")
  909.     (dk m (kbd "v")   "echo-oss-vol")
  910.     (dk m (kbd "w")   "pout exec sdcv -nu WordNet ")
  911.     (dk m (kbd "W")   "pout exec sdcv -nu \"English Thesaurus\" ")
  912.     (dk m (kbd "ESC") "abort")
  913.    M)))
  914.  
  915. ;; frequently used commands.
  916. (defvar *frequent-map*
  917.   (let ((m (make-sparse-keymap)))
  918.     (labels ((dk (m k c) (define-key m k c)))
  919.     (dk m (kbd "2") "echo-oss-speakers")
  920.     (dk m (kbd "3") "echo-oss-headphones")
  921.     (dk m (kbd "b") "display-random-bg")
  922.     (dk m (kbd "B") "exec display -window root -resize 1600x900! /howl/foto/wall/wallpaper-31278.png")
  923.     (dk m (kbd "C-b") "exec display -window root -resize 1600x900! /howl/foto/wall/1366x768_dizorb_landscape_study_hd_wallpaper.png")
  924.     (dk m (kbd "d") "exec xmodmap /howl/conf/keymaps/dvausler-mod.xmodmap")
  925.     (dk m (kbd "h") "exec urxvt -e htop")
  926.     (dk m (kbd "l") "ror_luakit")
  927.     (dk m (kbd "m") "ror_mutt")
  928.     (dk m (kbd "q") "exec xmodmap /howl/conf/keymaps/qwerty.xmodmap")
  929.     (dk m (kbd "s") "exec urxvt -e nsudoku 12")
  930.     (dk m (kbd "x") "exec xskat -opt /howl/conf/xorg/xskat.opt -list /howl/conf/xorg/xskat.lst")
  931.     (dk m (kbd "ESC") "abort")
  932.    M)))
  933.  
  934. ;; mplayer daemon (mifo) frequently used commands.
  935. (defvar *mplayer-map1*
  936.   (let ((m (make-sparse-keymap)))
  937.     (labels ((dk (m k c) (define-key m k c)))
  938.     (dk m (kbd "0")     "exec mifo --reload 0")
  939.     (dk m (kbd "1")     "exec mifo --reload 1")
  940.     (dk m (kbd "a")     "prompt-mifo-load")
  941.     (dk m (kbd "A")     "prompt-mifo-append")
  942.     (dk m (kbd "d")     "exec sudo /etc/rc.d/mifo start")
  943.     ;(dk m (kbd "d")     "exec mifo --daemon")
  944.     (dk m (kbd "f")     "exec mifo --fullscreen")
  945.     (dk m (kbd "h")     "echo-mifo-prev")
  946.     (dk m (kbd "H")     "prompt-mifo-prev")
  947.     (dk m (kbd "j")     "prompt-mifo-next +")
  948.     (dk m (kbd "k")     "prompt-mifo-prev dir")
  949.     (dk m (kbd "l")     "echo-mifo-next")
  950.     (dk m (kbd "L")     "prompt-mifo-next")
  951.     (dk m (kbd "p")     "prompt-mifo-playlist")
  952.     (dk m (kbd "P")     "echo-mifo-playlists")
  953.     (dk m (kbd "q")     "exec sudo /etc/rc.d/mifo stop")
  954.     ;(dk m (kbd "q")     "exec mifo --quit")
  955.     (dk m (kbd "Q")     "exec sudo /etc/rc.d/mifo kill")
  956.     (dk m (kbd "r")     "echo-mifo-random")
  957.     (dk m (kbd "s")     "prompt-mifo-save")
  958.     (dk m (kbd "S")     "exec mifo --stop")
  959.     (dk m (kbd "t")     "exec mifo --toggle")
  960.     (dk m (kbd "+")     "echo-mifo-fav-add")
  961.     (dk m (kbd "-")     "echo-mifo-fav-del")
  962.     (dk m (kbd "Return")"prompt-mifo-reload")
  963.     (dk m (kbd "ESC")   "abort")
  964.    M)))
  965.  
  966. ;; mplayer daemon (mifo) useful seek commands.
  967. (defvar *mplayer-map2*
  968.   (let ((m (make-sparse-keymap)))
  969.     (labels ((dk (m k c) (define-key m k c)))
  970.     (dk m (kbd "h")     "exec mifo -c seek -7")
  971.     (dk m (kbd "H")     "exec mifo -c seek -17")
  972.     (dk m (kbd "C-h")   "exec mifo -c seek -47")
  973.     (dk m (kbd "M-h")   "exec mifo -c seek -407")
  974.     (dk m (kbd "l")     "exec mifo -c seek 5")
  975.     (dk m (kbd "L")     "exec mifo -c seek 15")
  976.     (dk m (kbd "C-l")   "exec mifo -c seek 45")
  977.     (dk m (kbd "M-l")   "exec mifo -c seek 405")
  978.     (dk m (kbd "!")     "exec mifo -c seek_chapter -1")
  979.     (dk m (kbd "@")     "exec mifo -c seek_chapter 1")
  980.     (dk m (kbd "BackSpace") "exec mifo -c seek 0 1")
  981.     (dk m (kbd "ESC")   "abort")
  982.    M)))
  983.  
  984. (setf *top-map*
  985.   (let ((m (make-sparse-keymap)))
  986.     (labels ((dk (m k c) (define-key m k c)))
  987.     ;; <numerical bindings>
  988.     (dk m (kbd "s-1")    "gselect 1")
  989.     (dk m (kbd "s-2")    "gselect 2")
  990.     (dk m (kbd "s-3")    "gselect 3")
  991.     (dk m (kbd "s-4")    "gselect 4")
  992.     (dk m (kbd "s-5")    "gselect 5")
  993.     (dk m (kbd "s-6")    "gselect 6")
  994.     (dk m (kbd "s-8")    "mark")
  995.     (dk m (kbd "s-C-8")  "clear-window-marks")
  996.     (dk m (kbd "s-M-8")  "gmove-marked")
  997.     (dk m (kbd "s-9")    "quiet-resize -10 0")
  998.     (dk m (kbd "s-0")    "quiet-resize  10 0")
  999.     (dk m (kbd "C-1")    "select-window-by-number 1")
  1000.     (dk m (kbd "C-2")    "select-window-by-number 2")
  1001.     (dk m (kbd "C-3")    "select-window-by-number 3")
  1002.     (dk m (kbd "C-4")    "select-window-by-number 4")
  1003.     (dk m (kbd "C-5")    "select-window-by-number 5")
  1004.     (dk m (kbd "C-6")    "select-window-by-number 6")
  1005.     (dk m (kbd "C-7")    "select-window-by-number 7")
  1006.     (dk m (kbd "C-8")    "select-window-by-number 8")
  1007.     (dk m (kbd "C-9")    "select-window-by-number 9")
  1008.     (dk m (kbd "C-0")    "select-window-by-number 0")
  1009.     ;; <special-char bindings>
  1010.     (dk m (kbd "s-!")    "gmove 1")
  1011.     (dk m (kbd "s-@")    "gmove 2")
  1012.     (dk m (kbd "s-#")    "gmove 3")
  1013.     (dk m (kbd "s-$")    "gmove 4")
  1014.     (dk m (kbd "s-%")    "gmove 5")
  1015.     (dk m (kbd "s-^")    "gmove 6")
  1016.     (dk m (kbd "s-*")    "pull-marked")
  1017.     (dk m (kbd "s-(")    "quiet-resize 0 -10")
  1018.     (dk m (kbd "s-)")    "quiet-resize 0  10")
  1019.     (dk m (kbd "s--")    "vsplit")
  1020.     (dk m (kbd "s-=")    "hsplit")
  1021.     (dk m (kbd "s-+")    "balance-frames")
  1022.     (dk m (kbd "s-;")    "colon")
  1023.     (dk m (kbd "s-:")    "manpage")
  1024.     (dk m (kbd "s-C-;")  "eval")
  1025.     (dk m (kbd "s-,")    "gprev")
  1026.     (dk m (kbd "s-<")    "gmove-prev")
  1027.     (dk m (kbd "s-C-,")  "gprev-with-window")
  1028.     (dk m (kbd "s-.")    "gnext")
  1029.     (dk m (kbd "s->")    "gmove-next")
  1030.     (dk m (kbd "s-C-.")  "gnext-with-window")
  1031.     (dk m (kbd "s-/")    "gother")
  1032.     (dk m (kbd "s-?")    "lastmsg")
  1033.     (dk m (kbd "s-ESC")  "exec banishmouse")
  1034.     (dk m (kbd "s-Tab")  "fother")
  1035.     (dk m (kbd "s-S-SPC")"rotate-windows")
  1036.     (dk m (kbd "s-BackSpace")       "fclear")
  1037.     (dk m (kbd "s-S-BackSpace")     "delete-window")
  1038.     (dk m (kbd "s-C-BackSpace")     "kill-window")
  1039.     (dk m (kbd "s-Return")          "exec urxvt -e tmux -S /tmp/.${UID}/tmux/xorg new-session")
  1040.     (dk m (kbd "s-S-Return")        "tmux-attach-else-new")
  1041.     (dk m (kbd "s-C-Return")        "exec urxvt")
  1042.     (dk m (kbd "s-M-Return")        "tmux-attach-rtorrent")
  1043.     (dk m (kbd "s-SunPrint_Screen") "exec import -window root ${XDG_PICTURES_DIR:-${H:-/howl}/foto}/shot/$(date +%Y_%m_%d-%H%M%S).png")
  1044.     (dk m (kbd "C-M-Delete")        "exec alock -bg image:file=${XDG_PICTURES_DIR:-${H:-/howl}/foto}/wall/beheading.png -cursor glyph -auth pam >&/dev/null")
  1045.     (dk m (kbd "C-s-Delete")        "exec alock -bg image:file=${XDG_PICTURES_DIR:-${H:-/howl}/foto}/wall/beheading.png -cursor glyph -auth pam >&/dev/null")
  1046.     ;; <alphabetic bindings>
  1047.     (dk m (kbd "s-a")    *echo-map*)
  1048.     (dk m (kbd "s-b")    "refresh")
  1049.     (dk m (kbd "s-B")    "redisplay")
  1050.     (dk m (kbd "s-c")    *xclip-primary-map*)
  1051.     (dk m (kbd "s-C")    *xclip-clipboard-map*)
  1052.     (dk m (kbd "s-d")    *mplayer-map1*)
  1053.     (dk m (kbd "s-D")    "prompt-mifo-command")
  1054.     (dk m (kbd "s-e")    "exec ")
  1055.     (dk m (kbd "s-E")    "shell-command-output")
  1056.     (dk m (kbd "s-f")    *frequent-map*)
  1057.     (dk m (kbd "s-F")    *win-frame-map*)
  1058.     (dk m (kbd "s-g")    "vgroups")
  1059.     (dk m (kbd "s-G")    "grouplist")
  1060.     (dk m (kbd "s-h")    "move-focus left")
  1061.     (dk m (kbd "s-H")    "move-window left")
  1062.     (dk m (kbd "s-C-h")  "exchange-direction left")
  1063.     (dk m (kbd "s-M-h")  "exchange-direction-remain left")
  1064.     (dk m (kbd "s-i")    "fselect")
  1065.     (dk m (kbd "s-j")    "move-focus down")
  1066.     (dk m (kbd "s-J")    "move-window down")
  1067.     (dk m (kbd "s-C-j")  "exchange-direction down")
  1068.     (dk m (kbd "s-M-j")  "exchange-direction-remain down")
  1069.     (dk m (kbd "s-k")    "move-focus up")
  1070.     (dk m (kbd "s-K")    "move-window up")
  1071.     (dk m (kbd "s-C-k")  "exchange-direction up")
  1072.     (dk m (kbd "s-M-k")  "exchange-direction-remain up")
  1073.     (dk m (kbd "s-l")    "move-focus right")
  1074.     (dk m (kbd "s-L")    "move-window right")
  1075.     (dk m (kbd "s-C-l")  "exchange-direction right")
  1076.     (dk m (kbd "s-M-l")  "exchange-direction-remain right")
  1077.     (dk m (kbd "s-m")    "master-focus")
  1078.     (dk m (kbd "s-M")    "master-swap 0")
  1079.     (dk m (kbd "s-C-m")  "master-make")
  1080.     (dk m (kbd "s-n")    "next-in-frame")
  1081.     (dk m (kbd "s-N")    "pull-hidden-next")
  1082.     (dk m (kbd "s-o")    "fullscreen")
  1083.     (dk m (kbd "s-O")    "only")
  1084.     (dk m (kbd "s-p")    "prev-in-frame")
  1085.     (dk m (kbd "s-P")    "pull-hidden-previous")
  1086.     (dk m (kbd "s-Q")    "quit")
  1087.     (dk m (kbd "s-r")    "loadrc")
  1088.     (dk m (kbd "s-R")    "restart")
  1089.     (dk m (kbd "s-s")    *mplayer-map2*)
  1090.     (dk m (kbd "s-t")    "title")
  1091.     (dk m (kbd "s-u")    "undo")
  1092.     (dk m (kbd "s-v")    "show-window-properties")
  1093.     (dk m (kbd "s-V")    "list-window-properties")
  1094.     (dk m (kbd "s-w")    "echo-frame-windows")
  1095.     (dk m (kbd "s-W")    "windowlist")
  1096.     (dk m (kbd "s-x")    *xsel-map*)
  1097.     (dk m (kbd "s-y")    "iresize")
  1098.     (dk m (kbd "s-z")    "remove-split")
  1099.     ;; <function-key bindings>
  1100.     (dk m (kbd "XF86AudioMute")         "echo-oss-volmute")
  1101.     (dk m (kbd "XF86AudioRaiseVolume")  "echo-oss-volup")
  1102.     (dk m (kbd "XF86AudioLowerVolume")  "echo-oss-voldown")
  1103.     (dk m (kbd "s-C-F9")  "dump-to-datadir rules")
  1104.     (dk m (kbd "s-C-F10") "dump-to-datadir desktop")
  1105.     (dk m (kbd "s-C-F11") "dump-to-datadir screen")
  1106.     (dk m (kbd "s-C-F12") "dump-to-datadir group")
  1107.     (dk m (kbd "s-F9")    "restore-from-datadir rules")
  1108.     (dk m (kbd "s-F10")   "restore-from-datadir desktop")
  1109.     (dk m (kbd "s-F11")   "restore-from-datadir screen")
  1110.     (dk m (kbd "s-F12")   "restore-from-datadir group")
  1111.     (dk m (kbd "s-quoteleft") "scratchpad")
  1112.    M)))
  1113.  
  1114. ;; EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement