;; xwemrc.el --- xwem configurations.

;; Last-Modified:  <2005-01-22 00:49:16 (steve)>

;; Copyright (C) 2004, 2005 Steve Youngs

;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions
;; are met:
;;
;; 1. Redistributions of source code must retain the above copyright
;;    notice, this list of conditions and the following disclaimer.
;;
;; 2. Redistributions in binary form must reproduce the above copyright
;;    notice, this list of conditions and the following disclaimer in the
;;    documentation and/or other materials provided with the distribution.
;;
;; 3. Neither the name of the author nor the names of any contributors
;;    may be used to endorse or promote products derived from this software
;;    without specific prior written permission.

;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;; DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

;;;;;         **** W A R N I N G ****
;;;
;;;  This configuration will only work in the latest XWEM (version 2)
;;;
;;;  There is also a lot of stuff here that may not be so good
;;;  for a novice user.  My advice is _DON'T_ use this as your
;;;  ~/.xwem/xwemrc.el, but takes bits from it a little at a time
;;;  as you become more familiar with XWEM.  If you need help you
;;;  can email me at <steve@xwem.org>, or the XWEM mailing
;;;  list (better) at <xwem-devel@xwem.org>.
;;;
;;;;;         **** W A R N I N G ****

;; Are you reading this online at
;; <http://www.xwem.org/xwemrc.html>?
;; Get the source here

;;; ~/.xinitrc settings
;;
;; I've found the following settings in ~/.xinitrc to work best for me
;; (I'm using Xorg 6.7.0)...
;;
;; ----------- cut here ------------
;; # Some environmental trickery to work around some problems I'm having
;; # with xwem.
;; if [ "x$XWEM_RUNNING" != "x" ]; then
;;     unset XWEM_RUNNING
;; fi
;;
;; # Allow access for localhost
;; xhost localhost
;;
;; # Swap some modifier keys around and define a `Hyper' key.
;; xmodmap -e "remove mod4 = Super_L"
;; xmodmap -e "add mod3 = Super_L"
;; xmodmap -e "add mod3 = Super_R"
;; xmodmap -e "keycode 117 = Hyper_R"
;; xmodmap -e "add mod4 = Hyper_R"
;;
;; # Using XEmacs as the window manager with the "XWEM" package.
;; export XWEM_RUNNING=notyet
;; exec xemacs
;; ----------- cut here ------------

;; What the hell is that $XWEM_RUNNING variable all about?
;;
;; I use it for those times where you want to do something that doesn't
;; make any sense if you are running XWEM, like setting XEmacs frame
;; geometry from lisp.  I also use it for when I want to start another
;; XEmacs instance and I don't want the 2nd XEmacs trying to spawn
;; another copy of XWEM.
;;
;; It also allows me to run a WM other than XWEM and I don't have to
;; worry about changing my XEmacs settings to prevent XWEM from
;; loading.
;;
;; At the end of my ~/.xemacs/init.el I load XWEM with...
;;
;; (when (and (string= "notyet" (getenv "XWEM_RUNNING"))
;;            (device-on-window-system-p))
;;   (xwem-init)
;;   (setenv "XWEM_RUNNING" "yes"))
;;
;; And then I can test the value of $XWEM_RUNNING to determine whether
;; or not "XWEM-unfriendly" things should be allowed to load.

;;; Code:

;:*=======================
;:* Debugging
;; If you are having problems, uncomment this and it will log
;; terabytes of info to a "*xwem-debug*" buffer.  The contents of
;; which can sometimes be very helpful for tracking down bugs
;; (hint: include it in bug reports)
;;
;(setq xwem-debug t)
;(setq stack-trace-on-error t)
;; Or if you wish to start debugging in mid-session, run this command.
(defun xwem-turn-on-debug ()
  (interactive)
  (setf (X-Dpy-log-buffer (xwem-dpy)) "*xwem-debug*")
  (X-Dpy-set-log-routines (xwem-dpy) xwem-debug-routines))

;:*=======================
;:* Requires
;; Make sure we have what we need.
;;
;; `xwem-use-presetup' is a safeguard for novice users, to make sure
;; certain crucial things are loaded.  I've got this test here in case
;; I ever switch `xwem-use-presetup' off.
(unless xwem-use-presetup
  (require 'xwem-clgen)
  (require 'xwem-transient)
  (require 'xwem-netwm))

(require 'xwem-launcher)
(require 'xwem-clswi)
(require 'xwem-strokes)
(require 'xwem-rooticon)

;:*=======================
;:* Problematic XEmacs code
;; This section is for XEmacs things that don't play nice with XWEM.
;; Some could be XEmacs' fault, some could be XWEM's fault.  If you
;; are lost for ideas about what to hack on XWEM, look here. :-)
;;
;; Balloon help transients are still broken so unconditionally turn
;; them off.
(balloon-help-mode -1)
;; Make `find-function' work with xwem functions.
(setq find-function-regexp
      (concat "^\\s-*(\\(def[^cgvW]\\w+\\*?"
              "\\|define-function"
              "\\|define-obsolete-function-alias"
              "\\|define-compatible-function-alias"
              "\\|define-derived-mode"
              "\\|define-xwem-command"
              "\\)\\s-+%s\\(\\s-\\|$\\)"))

;:*=======================
;:* Misc settings.
(setq
 xwem-cl-other-strategy 'sameframe
 xwem-cursor-default-foreground-color "red"
 xwem-cursor-help-background-color "black"
 xwem-cursor-quote-background-color "black"
 xwem-cursor-quote-foreground-color "blanchedalmond"
 xwem-cursor-wait-foreground-color "cyan"
 xwem-default-focus-mode 'follow-mouse
 xwem-frame-cursor-foreground-color "red"
 xwem-frame-cursor-grab-foreground-color "blanchedalmond"
 xwem-keymacro-show-macro nil
 xwem-launcher-beep-done t
 xwem-minibuffer-active-border-color "yellow"
 xwem-minibuffer-bgcol "black"
 xwem-minibuffer-emacs-frames-has-minibuffer nil
 xwem-minibuffer-width 58
 xwem-sound-default-alist '((default :sound bass :volume 100)
                            (undefined-key :sound drum :volume 100)
                            (command-fail :sound bass :volume 100)
                            (quit :sound quiet :volume 100)
                            (ready :sound cuckoo :volume 100)
                            (alarm :sound cuckoo :volume 100)
                            (msg-warning :sound clink :volume 100)
                            (msg-error :sound bong :volume 100))
 xwem-sound-extension-list ".au:.wav"
 xwem-strokes-file "sy-xwem-strokes.el"
 xwem-time-auto-start nil
 xwem-time-time-color "yellow"
 xwem-tray-cursor-foreground-color "yellow"
 xwem-xterm-program "xterm -bg black -fg white")

;:*=======================
;:* Special Frames
;; Set the geometry of XWEM special frames (help windows etc)
(setq special-display-frame-plist
      (xwem-misc-merge-plists
       special-display-frame-plist
       '(top 350 left 100 width 80 height 20)))

(setq xwem-special-default-strategy 'someshit)

;:*=======================
;:* Vertical Bar
;; Sometimes it is good to have a visual indicator that your lines of
;; code are just way too long.
(defvar sy-xwem-vline-win nil)
(define-xwem-command sy-xwem-set-vline (&optional column colour)
  "Setup one-pixel wide vertical line at COLUMN.
    
COLOUR is vline colour default \"red\".
Default COLUMN is value of `fill-column'."
  (xwem-interactive 
   (list (or (and xwem-prefix-arg (prefix-numeric-value xwem-prefix-arg))
             fill-column)))
  (unless colour
    (setq colour "red"))
    
  (let (cxwin)
    (setq cxwin
          (X-Win-find-or-make
           (xwem-dpy)
           (float
            (string-to-int (frame-property (selected-frame) 'window-id)))))
    (when (X-Win-p sy-xwem-vline-win)
      (XDestroyWindow (xwem-dpy) sy-xwem-vline-win)
      (setq sy-xwem-vline-win nil))
    (when (> column 0)
      (setq
       sy-xwem-vline-win
       (XCreateWindow
        (xwem-dpy) cxwin
        (+ (frame-property (selected-frame) 'internal-border-width)
           (* (font-width (face-font 'default)) column))
        0 1
        (* (frame-height (selected-frame))
           (font-height (face-font 'default)))
        0 nil nil nil
        (make-X-Attr :background-pixel
                     (XAllocNamedColor
                      (xwem-dpy) (XDefaultColormap (xwem-dpy)) colour))))
      (XMapWindow (xwem-dpy) sy-xwem-vline-win))))

(define-xwem-command sy-xwem-unset-vline ()
  "*Turn off the vertical line created by `sy-xwem-set-vline'.

This works by side-effect of setting the vertical line to column zero."
  (xwem-interactive)
  (sy-xwem-set-vline 0))
    
(define-key xwem-global-map (xwem-kbd "H-c m V") 'sy-xwem-set-vline)
(define-key xwem-global-map (xwem-kbd "H-c m v") 'sy-xwem-unset-vline)

;:*=======================
;:* Worklog
;; Now you can prove that you aren't wasting hours surfing the
;; web... or maybe you can prove that you are. :-)
;;
;; XWEM's worklogger allows you to track how much time you spend doing
;; different tasks.  You can set it up to be more or less dynamic and
;; automatic (see `xwem-worklog-tasks-description') and at the same
;; time you still have manual control for those "tasks" that can't be
;; made dynamic (see my task: "Smoke").
;;
;; Worklog keys are prefixed with `H-W', do `H-W H-h' to see what's
;; available.
;;
;; You might not want to set things up as I have because I have some
;; pretty strange work habits.  Basically I am never not "at work" so
;; I've set things up to...
;;
;;      - not warn me about logging out/in
;;      - automatically log out at log out time
;;      - immediately log in after a log out
(setq
 xwem-worklog-auto-worklog-file t
 xwem-worklog-day-ends 23
 xwem-worklog-day-start 0
 xwem-worklog-dockapp-diagram-type '3d
 xwem-worklog-file "~/.xwem/worklog"
 xwem-worklog-logout-auto-period 0.01
 xwem-worklog-silent t
 xwem-worklog-tasks-description
 '(("Web browsing"
    (:key [(hyper ?w)] :color "dodgerblue" :cost 0)
    (or (application "mozilla")
        (name "Links")
        (buffer-major-mode w3-mode)
        (and (application "xemacs")
             (name "W3:.*"))
        (buffer-major-mode w3m-mode)
        (and (application "xemacs")
             (name "\\*w3m\\*"))))
   ("Mail reading"
    (:key [(hyper ?m) ?r] :color "blue1" :cost 0)
    (or (buffer-major-mode gnus-group-mode)
        (buffer-major-mode gnus-article-mode)
        (buffer-major-mode gnus-summary-mode)
        (and (application "xemacs")
             (name "\\*\\(Group\\|Summary\\|Article\\)"))))
   ("Mail writing"
    (:key [(hyper ?m) ?w] :color "blue4" :cost 0)
    (or (buffer-major-mode message-mode)
        (buffer-major-mode bbdb-mode)
        (and (application "xemacs")
             (name "\\*\\(BBDB\\*\\|mail\\*\\|wide reply\\|reply\\)"))))
   ("Chatting"
    (:key [?C] :color "palegreen" :cost 0)
    (or (buffer-major-mode erc-mode)
        (buffer-major-mode riece-channel-list-mode)
        (buffer-major-mode riece-channel-mode)
        (buffer-major-mode riece-command-mode)
        (buffer-major-mode riece-dialogue-mode)
        (buffer-major-mode riece-others-mode)
        (buffer-major-mode riece-user-list-mode)
        (name "BitchX:BaBy!")
        (and (application "xemacs")
             (name "\\(#eicq\\|#xemacs\\|#sxemacs\\|irc\\.freenode\\.org\\)"))
        (buffer-major-mode eicq-buddy-mode)
        (buffer-major-mode eicq-log-mode)
        (and (application "xemacs")
             (name ".*\\*Status\\*.*"))
        (name ".*[LlMm][Ii][Cc][Qq].*")))
   ("Info/man reading"
    (:key [(hyper ?i)] :color "cyan" :cost 10)
    (or (buffer-major-mode Manual-mode)
        (buffer-major-mode Info-mode)
        (buffer-major-mode hyper-apropos-mode)
        (and
         (application "xemacs")
         (name
          ".*\\(\\*info\\*\\|Man: \\|\\*Help\\*\\|\\*Hyper Apropos\\*\\).*"))
        (class-name "Xman")))
   ("Emacs lisping"
    (:key [(hyper ?e)] :color "yellow2" :cost 0)
    (or (buffer-major-mode emacs-lisp-mode)
        (and (application "xemacs")
             (name ".*\\.el\\.*"))))
   ("C coding"
    (:key [(hyper ?p)] :color "magenta" :cost 100)
    (or (buffer-major-mode cvs-mode)
        (buffer-major-mode c-mode)
        (buffer-major-mode gdb-mode)
        (and (or (application "xemacs")
                 (and (class-inst "^.term$")
                      (class-name "^.Term$")))
             (name ".*\\(gdb\\|\\*cvs\\*\\|\\.[ch]\\).*"))))
   ("WorkProject"
    (:key [(hyper ?c)] :color "green2" :cost 200))
   ("Administrivia"
    (:key [(hyper ?a)] :color "lightblue" :cost 150)
    (or (buffer-major-mode emoney-mode)
        (buffer-major-mode eshell-mode)
        (buffer-major-mode shell-mode)
        (name "xsensors 0.46")
        (application "xterm")
        (name "top")
        (name "tcpdump")
        (name "ssh")))
   ("Movies"
    (:key [(hyper ?M)] :color "blanchedalmond" :cost 0)
    (name "xine.*"))
   ("Smoke" (:key [(hyper ?s)] :color "red3" :cost -50))
   ("Nothing"
    (:key [(hyper ?n)] :color "gray80" :cost 50)
    (or (and (application "xemacs")
             (name ".*\\*scratch\\*.*"))
        (eval t)))))

;; The defcustom's in xwem-worklog.el don't allow for dynamic updating
;; of the task list so I pull in xwem-worklog.el _after_ I have set
;; the task list.
(require 'xwem-worklog)
(define-key xwem-global-map (xwem-kbd "H-W") 'xwem-worklog-prefix)
;; To ensure that the _last_ thing the logout hook does is to login
;; again, use the APPEND arg to add-hook here.
(add-hook 'xwem-worklog-logout-hook 'xwem-worklog-login t)

;:*=======================
;:* Desktop Config save/load
;; Make sure your XWEM set up is retained across XWEM sessions.
;;
;; Unfortunately this doesn't reload the clients you had running in
;; the last session, but at least you don't have to create, name,
;; split, and position your frames each time.
;;
;; Client reloading is coming soon!!
;;
;; This is a slightly more advanced way of organising desktop configs.
;; Normally, you'd simply do :
;;
;;    (xwem-desktop-load)
;;    (add-hook xwem-exit-hook 'xwem-desktop-save)
;;
;; But I have some things that I only want to save one time (my frames
;; configs) and other things that I want to save every time (histories,
;; macros, etc).  This set up allows me to do that.

;; A file for saving the "one time configs" (frames).
(setq one-time-file (expand-file-name "one-time-desktop.el" xwem-dir))

;; Goals to save/restore on any session
(setq xwem-desktop-goals
      '((keymap . xwem-user-macros-prefix) ; Save my `H-m'
        (xwem-launcher-history . 100)   ; Save `H-!', `H-x r' history
        (xwem-read-expression-history . 100))) ; Save `H-:' history

;; Load the desktop config (this loads the stuff that I save from each
;; session).
(xwem-desktop-load)

;; Convenience function to add to the exit hook if needed (this saves
;; the configs that I only want saved once, ie _not_ on every session)
(defun sy-save-xwem-one-time-config ()
  (let ((xwem-desktop-goals '(frames-config)))
    (xwem-desktop-save one-time-file)))

;; If the "one time config" file exists, load it.  If it doesn't,
;; create it on exit.
(if (file-exists-p one-time-file)
    (xwem-desktop-load one-time-file)
  (add-hook 'xwem-exit-hook 'sy-save-xwem-one-time-config))

;; Save goals on exit (things I want to save after _every_ session)
(add-hook 'xwem-exit-hook 'xwem-desktop-save)

;:*=======================
;:* Punch holes through to the root window
;; I don't know of any other WM that can do this.  Needless to say,
;; this is pretty darn cool. :-)
(require 'xwem-holer)
(define-key xwem-global-map (xwem-kbd "H-x h") 'xwem-holer-prefix)

;:*=======================
;:* XWEM Registers
;; This has other uses too, but I use it predominately as a very
;; efficient client switcher.  Add a client to a register with...
;;   `H-x / c'
;; (`c' being any single character), and then no matter where you
;; are you can switch back to this client with...
;;   `H-x j c'.
(require 'xwem-register)

;; Automatically put new client in registers.  Adding stuff to this
;; variable will mean that when you start the client in question it
;; will automatically be assigned to a register (ie, no need to
;; manually set it with `H-x / c'.
(setq xwem-registers-auto-registers
      '((?g (buffer-major-mode gnus-group-mode))
        (?$ (buffer-major-mode emoney-mode))
        (?e (buffer-major-mode eicq-log-mode))
        (?x (application "xemacs"))
        (?m (application "mozilla"))
        (?b (name ".*[Bb]itch[Xx].*"))))

;; Show register(if any) in client's tab
(defun sy-xwem-check-register (cl)
  "Return xwem register where CL stored.
    If no register return \"-\"."
  (let ((rs xwem-registers))
    (while (and rs
                (or (not (eq (cadr (car rs)) 'XWEM-CLIENT))
                    (not (eq (caddr (car rs)) cl))))
      (setq rs (cdr rs)))
    (if rs
        (char-to-string (car (car rs)))
      "")))

(defadvice xwem-register-client (around call-client-change activate)
  "Call client change hook."
  (let ((rval (xwem-register-get (event-key (ad-get-arg 0)))))
    ad-do-it

    (when (and (xwem-cl-p rval)
               (not (eq rval (xwem-cl-selected))))
      (run-hook-with-args 'xwem-cl-change-hook rval))

    (run-hook-with-args 'xwem-cl-change-hook (xwem-cl-selected))))

;; Additional tabber face, will be used in `xwem-tab-default-format'
(define-xwem-face xwem-tabber-face1
  `(((frame-selected tab-selected)
     (:foreground "red" :bold t))
    ((frame-selected tab-nonselected)
     (:foreground "red2"))
    ((frame-nonselected tab-selected)
     (:foreground "red3" :bold t))
    ((frame-nonselected tab-nonselected)
     (:foreground "red4"))
    (t (:foreground "red")))
  "Additional face for tabber.")

(setq xwem-tab-default-format
      " %i  %*%#%I%1%{(sy-xwem-check-register cl)%}%0  %n")

;:*=======================
;:* Launcher Abbrevs
;; Abbrevs for `H-x r' (`xwem-launch-program').  They work just like
;; normal XEmacs abbrevs.  Simply do: `H-x r ABBREVNAME<SPACE>'
(define-abbrev-table 'xwem-launcher-abbrev-table
  '(("215d" "~/test-it/XEmacs-21.5/debug-mule/src/xemacs" nil 0)
    ("215o" "~/test-it/XEmacs-21.5/opt-mule/src/xemacs" nil 0)
    ("bitch" "xterm -bg black -fg white -T BitchX:BaBy! -e BitchX" nil 0)
    ("eicq" "xterm -bg black -fg white -T SSH:eicq -e ssh eicq" nil 0)
    ("ian" "xterm -bg black -fg white -T SSH:vk4kij -e ssh ian-online" nil 0)
    ("irc" "xterm -bg black -fg white -T BitchX:BaBy! -e BitchX" nil 0)
    ("links" "links -g" nil 0)
    ("michelle"
     "xterm -bg black -fg white -T SSH:michelle -e ssh michelle" nil 0)
    ("micq"
     "xterm -bg black -fg white -T mICQ:JackaLX -sb -sl 256 -rightbar -e micq"
     nil 0)
    ("mozilla" "mozilla -splash" nil 0)
    ("news" "xterm -bg black -fg white -T SSH:news -e ssh news" nil 0)
    ("pysol" "/usr/local/games/pysol-4.81/pysol" nil 0)
    ("root" "xterm -bg black -fg red -T SSH:root -e ssh local" nil 0)
    ("sf" "xterm -bg black -fg white -T SSH:sf -e ssh eicq" nil 0)
    ("sql" "xterm -bg black -fg white -T SSH:sql -e ssh sql" nil 0)
    ("squid" "xterm -bg black -fg white -T SSH:squid -e ssh squid" nil 0)
    ("sunsite"
     "xterm -bg black -fg white -T SSH:sunsite.dk -e ssh xemacs-cvs" nil 0)
    ("tcpdump"
     "xterm -bg yellow -sl 4096 -T tcpdump:eth0 -e sudo tcpdump -api eth0"
     nil 0)
    ("tlinks" "links" nil 0)
    ("top" "xterm -bg black -fg white -e top" nil 0)
    ("tux" "xterm -bg black -fg white -T SSH:tux -e ssh xemacs-ftp" nil 0)
    ("xine" "xine --fullscreen" nil 0)
    ("yahoo" "/opt/ymessenger/bin/ymessenger" nil 0)))

;:*=======================
;:* Put Current Date in the dock area.
;; Here's a reasonable example of using XWEM OSD's (On Screen Display)
(require 'xwem-osd)
(defvar sy-osd-date nil)
(copy-face 'default 'sy-osd-date-face)
(set-face-foreground 'sy-osd-date-face "blanchedalmond")

(defvar sy-osd-date-keymap
  (let ((map (make-sparse-keymap 'sy-osd-date-keymap)))
    (define-key map [button3] '(lambda () (interactive) (calendar)))
    map)
  "Keymap for date OSD.")

(defun sy-show-date-osd ()
  "*Display the current date using OSD."
  (interactive)
  (let* ((face `sy-osd-date-face)
         (text (format-time-string "%a, %b %e"))
         (width (+ 3 (X-Text-width
                      (xwem-dpy)
                      (X-Font-get (xwem-dpy)
                                  (face-font-name face))
                      text)))
         (height (+ 3 (X-Text-height
                       (xwem-dpy)
                       (X-Font-get (xwem-dpy)
                                   (face-font-name face))
                       text))))
    (setq sy-osd-date (xwem-osd-create-dock
                       (xwem-dpy)
                       width
                       height
                       (list 'keymap sy-osd-date-keymap)))
    (xwem-osd-set-color sy-osd-date (face-foreground-name face))
    (xwem-osd-set-font sy-osd-date (face-font-name face))
    (xwem-osd-text sy-osd-date text)
    (xwem-osd-show sy-osd-date)))

(defun sy-update-osd-date-maybe (&optional force)
  "Update the OSD date at midnight.

 Optional Argument FORCE means to update the date now."
  (let* ((now (decode-time))
         (cur-hour (nth 2 now))
         (cur-min (nth 1 now))
         (cur-comp-time (+ (* cur-hour 60) cur-min)))
    (when (or force (= 0 cur-comp-time))
      (when (xwem-osd-p sy-osd-date)
        (xwem-osd-text sy-osd-date (format-time-string "%a, %b %e"))))))

(defun sy-update-osd-date ()
  "*Force update of the OSD date."
  (interactive)
  (when (xwem-osd-p sy-osd-date)
    (sy-update-osd-date-maybe t)))

(defun sy-delete-osd-date ()
  "*Delete the OSD date."
  (interactive)
  (when (xwem-osd-p sy-osd-date)
    (when (itimerp "sy-osd-date-itimer")
      (delete-itimer "sy-osd-date-itimer"))
    (xwem-osd-destroy sy-osd-date)))

;:*=======================
;:* XWEM Frames
(define-key xwem-global-map [(meta shift button1)] 'xwem-frame-imove)
(define-key xwem-global-map [(meta shift button3)] 'xwem-frame-iresize)
(setq xwem-frame-autoiconify-mode 'intersect
      xwem-frame-imove-mode 'opaque
      xwem-frame-on-delim-resize-mode 'opaque)

;; Fast frame switcher
(defun sy-xwem-switch-frame (key)
  "To be used by H-C-<digit> bindings."
  (interactive (list (event-key xwem-last-event)))
  (xwem-frame-switch-nth (- (char-to-int key) 48)))

(define-key xwem-global-map (xwem-kbd "H-C-0") 'sy-xwem-switch-frame)
(define-key xwem-global-map (xwem-kbd "H-C-1") 'sy-xwem-switch-frame)
(define-key xwem-global-map (xwem-kbd "H-C-2") 'sy-xwem-switch-frame)
(define-key xwem-global-map (xwem-kbd "H-C-3") 'sy-xwem-switch-frame)
(define-key xwem-global-map (xwem-kbd "H-C-4") 'sy-xwem-switch-frame)
(define-key xwem-global-map (xwem-kbd "H-C-5") 'sy-xwem-switch-frame)
(define-key xwem-global-map (xwem-kbd "H-C-6") 'sy-xwem-switch-frame)
(define-key xwem-global-map (xwem-kbd "H-C-7") 'sy-xwem-switch-frame)
(define-key xwem-global-map (xwem-kbd "H-C-8") 'sy-xwem-switch-frame)
(define-key xwem-global-map (xwem-kbd "H-C-9") 'sy-xwem-switch-frame)

(define-xwem-command sy-xwem-switch-frame-by-name (name)
  "Switch to xwem frame named by NAME."
  (xwem-interactive
   (list (xwem-completing-read "XWEM Frame: "
                               (mapcar (lambda (f) (list (xwem-frame-name f)))
                                       xwem-frames-list))))
  (let ((frame (xwem-frame-find 'name name)))
    (when (xwem-frame-p frame)
      (xwem-select-frame frame))))

(define-key xwem-global-map (xwem-kbd "H-C-n") 'sy-xwem-switch-frame-by-name)

;:*=======================
;:* Sounds
(xwem-sound-load-default)

;:*=======================
;:* Icons
(defconst sy-icons-dir (file-name-as-directory
                        (expand-file-name "etc/icons" (getenv "HOME")))
  "The directory where I keep my icons.")

(push '("mini-bitchx.xpm" (name ".*[Bb]itch[Xx].*")) xwem-icons-list)


;:*=======================
;:* Launcher Dockapp
;; This puts "Client launcher buttons" in the dock area.
(defun xwem-my-start-ldocks ()
  "Start my launch docks."
  (xwem-tray-delimeter nil nil "blue")
  (xwem-launch-button-start
   (expand-file-name "mini-xterm.xpm" xwem-icons-dir)
   '(cmd . "xterm -bg black -fg white"))
  (xwem-launch-button-start
   (expand-file-name "mini-xemacs.xpm" xwem-icons-dir)
   '(elisp . "(make-frame)"))
  (xwem-launch-button-start
   (expand-file-name "mini-mozilla1.xpm" xwem-icons-dir)
   '(cmd . "mozilla -splash"))
  (xwem-launch-button-start
   (expand-file-name "links.xpm" sy-icons-dir)
   '(cmd . "links -g")))

;:*=======================
;:* Weather
;; Display the current local temp in the dock area (and more info via
;; a popup win).
(require 'xwem-weather)
(customize-set-variable 'xwem-weather-update-frequency 3600)

;:*=======================
;:* Hooks
;; Because of some strangeness with xwem-tray these things need to be
;; loaded in a particular order.

(defun sy-xwem-hooks ()
  (progn
    (xwem-worklog-start-dockapp)
    (xwem-framei-init)
    (xwem-framei-dockapp)
    (xwem-time)
    (sy-show-date-osd)
    (xwem-weather-init)
    (start-itimer "sy-osd-date-itimer"
                  'sy-update-osd-date-maybe
                  60 60)
    (xwem-recover-turn-on)
    (xwem-my-start-ldocks)))

(add-hook 'xwem-after-init-hook 'sy-xwem-hooks)

;:*=======================
;:* Attempt to recover from a desync
;; Recovering from xlib/X server desyncs `xwem-recover-turn-on' is
;; loaded above in `xwem-after-init-hook' so things should just happen
;; automagically, but I bind `H-C-g' here to force a manual recover.
(define-key xwem-global-map (xwem-kbd "H-C-g") 'xwem-recover-do-recover)

;:*=======================
;:* Themes (what's a WM without themes)
;; XWEM themes are brand new and still very much in their infancy.  No
;; doubt this section will change often and dramatically.
;;
;; Configuring your own themes isn't exactly all that user friendly
;; right now.  The custom interface for it is badly broken.  For now,
;; just copy the definition of one of the themes in xwem-theme.el (or
;; this one) and manually tweak it to your own liking.  Make sure you
;; give it a new name though.
;;
;; I'm not sure if this is a bug or a feature (I hope, "feature"),
;; but it is possible to use multiple themes at the same time.  You
;; can apply the theme settings on a global basis, or on a per frame
;; basis, or even on a per client basis.  This makes XWEM themes
;; incredibly flexible, and incredibly cool. :-)
(require 'xwem-theme)
(make-face 'xwem-tray-delimiter-face)
(make-face 'xwem-window-outline-face)
(make-face 'xwem-window-delimiter-face)
(defvar xwem-theme-steve
  `((face xwem-tabber-face
     (((frame-selected tab-selected)
       (:foreground "white" :background "gray20"
        :font "-*-times-medium-r-*-*-14-*-*-*-*-*-*-*" :bold t))
      ((delimiter-left frame-selected tab-selected)
       (:foreground "white"))
      ((delimiter-right frame-selected tab-selected)
       (:foreground "black"))

      ((frame-selected tab-nonselected)
       (:foreground "black" 
                    :background "gray80"
                    :font "-*-times-medium-r-*-*-14-*-*-*-*-*-*-*"))
      ((delimiter-left frame-selected tab-nonselected)
       (:foreground "white"))
      ((delimiter-right frame-selected tab-nonselected)
       (:foreground "black"))

      ((frame-nonselected tab-selected)
       (:foreground "gray80" :background "gray40"
        :font "-*-times-medium-r-*-*-14-*-*-*-*-*-*-*" :bold t))
      ((delimiter-left frame-nonselected tab-selected)
       (:foreground "white"))
      ((delimiter-right frame-nonselected tab-selected)
       (:foreground "black"))

      ((frame-nonselected tab-nonselected)
       (:foreground "black"
                    :background "gray40"
                    :font "-*-times-medium-r-*-*-14-*-*-*-*-*-*-*"))
      ((delimiter-left frame-nonselected tab-nonselected)
       (:foreground "white"))
      ((delimiter-right frame-nonselected tab-nonselected)
       (:foreground "black"))

      (t (:foreground "white"))))

    (face x-border-face
     (((selected) (:foreground "white"))
      (t (:foreground "dark"))))

    (face xwem-frame-inner-border-face
     (((light nonselected)
       (:foreground "gray80"))
      ((medium nonselected)
       (:foreground "gray50"))
      ((dark nonselected)
       (:foreground "gray20"))
      ((light selected)
       (:foreground "white"))
      ((medium selected)
       (:foreground "gray50"))
      ((dark selected)
       (:foreground "dark"))))

    (face xwem-launch-dock-face
     (((background-light)
       (:foreground "gray70"))
      ((background-light shadow-light)
       (:foreground "white"))
      ((background-light shadow-dark)
       (:foreground "black"))
      ((background-dark)
       (:foreground "gray50"))
      ((background-dark shadow-light)
       (:foreground "white"))
      ((background-dark shadow-dark)
       (:foreground "black"))
      (t (:foreground "gray70" :background "black"))))

    (face xwem-strokes-face
     (((background light)
       (:foreground "dimgray" :background "black"))
      ((background dark)
       (:foreground "lightgray" :background "black"))
      ((background begin light)
       (:foreground "darkslategrey" :background "black"
        :line-width 12 :cap-style X-CapRound))
      ((background begin dark)
       (:foreground "grey" :background "black"
        :line-width 12 :cap-style X-CapRound))
      (t (:foreground "dimgray" :background "black"
          :line-width 6 :cap-style X-CapRound
          :subwindow-mode X-IncludeInferiors
          :function (eval xwem-strokes-gc-function)))))

    (face xwem-tray-delimiter-face
     (((background light)
       (:foreground "gray40"))
      ((background light shadow)
       (:foreground "gray30"))
      ((background dark)
       (:foreground "gray70"))
      ((background dark shadow)
       (:foreground "gray80"))))

    (face xwem-window-outline-face
     (((frame-selected win-selected)
       (:foreground "dark" :background "dark"))
      ((frame-selected win-nonselected)
       (:foreground "gray50" :background "gray50"))
      ((frame-nonselected win-selected)
       (:foreground "gray20" :background "gray20"))
      ((frame-nonselected win-nonselected)
       (:foreground "gray60" :background "gray40"))))

    (face xwem-window-delimiter-face
     (((horizontal)
       (:foreground "gray30" :background "black"))
      ((horizontal shadow)
       (:foreground "gray10" :background "black"))
      ((horizontal light shadow)
       (:foreground "gray80" :background "black"))
      ((vertical)
       (:foreground "gray10" :background "black"))
      ((shadow vertical)
       (:foreground "gray40" :background "black"))
      ((light shadow vertical)
       (:foreground "white" :background "black"))
      (t (:foreground "gray20" :background "black"))))

    ;; Frames properties
    (frame-property inner-border-width 3)
    (frame-property inner-border-thickness 1)
    (frame-property title-height 20)

    ;; Clients properties
    (client-property x-border-width 3)

    ;; Custom settings
    (custom xwem-cursor-help-foreground-color "#888888")
    (custom xwem-cursor-help-background-color "#080808")
    (custom xwem-root-cursor-foreground-color "black")
    (custom xwem-root-cursor-background-color "white")
    (custom xwem-frame-cursor-foreground-color "white")
    (custom xwem-frame-cursor-background-color "black")
    (custom xwem-minibuffer-bgcol "gray50")
    (custom xwem-minibuffer-passive-border-color "gray70")
    (custom xwem-minibuffer-active-border-color "red")
    )
  "Steve's xwem theme.")

;; Add this theme to the global list of themes so it is available via
;; 'M-x xwem-theme-set'
(push (intern (symbol-name 'xwem-theme-steve)) xwem-theme-themes)
;; Apply the theme globally
(xwem-theme-apply xwem-theme-steve)

;;::::::::::::::::::::::: Testing Stuff below here ::::::::::::::::::::::::

;;::::::::::::::::::::::: End of Testing Stuff ::::::::::::::::::::::::::::
;;; End of xwemrc.el

; Put the normal local variables declaration here
;time-stamp-start: "Last-Modified:[     ]+\\\\?[\"<]+"
;time-stamp-end: "\\\\?[\">]"
;time-stamp-line-limit: 10
;time-stamp-format: "%4y-%02m-%02d %02H:%02M:%02S (%u)"
;End: 

Created with XEmacs Valid HTML 4.01! Valid CSS!
Copyright © 2004, 2005 Steve Youngs
Verbatim copying and distribution is permitted in any medium, providing this notice is preserved.
Last modified: Sat Jan 22 00:53:19 EST 2005