
;;;
;;; Change the background on entering a different workspace.
;;;
;; put these in rc:
;; (require 'workspace-background)
;; (add-hook 'after-initialization-hook wb-switch)
;; (add-hook 'enter-workspace-hook wb-switch)
;;
;; Sorry for no customization. I don't know how to write them yet.
;; Fortunately the setting is straightforward.

(provide 'workspace-background)


(defvar wb-proc nil)                    ; process setting the background
(defvar wb-cmd "qiv")                   ; command to set the background
(defvar wb-picture-path "/usr/share/data/pictures")
(defvar wb-picture-list '(("Dark_Wood.png" . t) ;tile
                          ("imga010_1600.jpg" . nil)
                          ("autumn.jpg" . t)))

(defun wb-set (picture)
  "(wb-set picture): set the background of current workspace based on the information of picture (picture . t)."
  (if (and wb-proc                      ; a process exists, running or not.
           (process-running-p wb-proc)) ; this process is running
      (progn
        (signal-process wb-proc 'INT)))     ;stop it first

  ;; make a new process, because the signaled process may still be running.
  (setq wb-proc (make-process))
  (start-process wb-proc wb-cmd
                 (if (cdr picture) "--root_t" "--root")
                 (concat wb-picture-path "/"
                         (car picture))))


(defun wb-switch ()
  "wb-switch: called on entering a new workspace."
  (wb-set (nth current-workspace wb-picture-list)))

