;;;; .gwmrc.gwm file for gamadrid

;;=============================================================================
;; File loads
;;=============================================================================

(load 'utils)				; Things like defaults, autoload.
(load 'deltabutton)			; Want deltabutton.
(load 'move-opaque)
(load 'trace-func)

;;=============================================================================
;; Initializations.
;;=============================================================================

(setq move-grid-style 4)
(setq resize-grid-style move-grid-style)

;; Abstract the button numbers.
(setq left-button 1)
(setq middle-button 2)
(setq right-button 3)

;; Get some colors
(setq black (color-make 'black))
(setq white (color-make 'white))

;; Get some fonts
(setq title-font (font-make "lucidasans-10"))
(setq icon-font (font-make "lucidasans-10"))

(setq grabs (list (button any with-alt) (button any (together with-alt with-shift))))
(setq opening '(progn))
(setq closing '(progn))

(setq borderwidth 0)

;;=============================================================================
;; State machines
;; Mouse bindings for windows (ALT qualified in clients)
;; Presses --  Left - Up
;;           Middle - Down
;;            Right - Iconify
;;
;; Deltas  --  Left - Raise & Move
;;           Middle - Resize
;;            Right - Move (No raise)
;;=============================================================================

(setq standard-window-behavior
      (state-make
       (on (button left-button (together with-alt with-shift))
	   ())
       (on (buttonpress left-button with-alt)
	   (if (deltabutton)
	       (progn (raise-window)
		      (move-window))
	       (raise-window)))	; Changes needed here
       (on (buttonpress middle-button with-alt)
	   (if (deltabutton)
	       (resize-window)
	       (lower-window)))
       (on (buttonpress right-button with-alt)
	   (if (deltabutton)
	       (move-window)
	       (iconify-window)))
       (on enter-window (set-focus window))
       (on leave-window (set-focus ()))
       (on focus-in  (send-user-event 'focus-in))
       (on focus-out (send-user-event 'focus-out))))
      
(setq window-fsm (fsm-make standard-window-behavior))

(setq standard-title-behavior
      (state-make
       (on (buttonpress left-button alone)
	   (if (deltabutton)	;!!! Put these in one place
	       (move-window)
	       (raise-window)))
       (on (buttonpress middle-button alone)
	   (lower-window))
       (on leave-window ())		; Trap this.  Don't let it
					; fall through to standard-window...
					; (since we're only leaving
					; the titlebar, and possibly,
					; not the whole window) 
       (on (user-event 'focus-in)
	   (wob-background white))
       (on (user-event 'focus-out)
	   (wob-background black))
       standard-window-behavior)))

(setq title-bar-fsm (fsm-make standard-title-behavior))

;;; Mouse bindings for icons.
;; Right now, anything but a left press will de-iconify.
;;  A left press will move the window.
(setq icon-fsm
      (fsm-make
       (state-make
	(on (buttonpress right-button with-alt)
	    (iconify-window))
	(on (buttonpress any any)
	    (move-window)))))

(setq root-fsm
      (fsm-make
       (state-make
	(on (buttonrelease 1 with-alt)
	    (restart))
	(on (buttonrelease 2 with-alt)
	    (end)))))

;;; The default state.  Waits for a click.
;(setq ipf-state1 
;      (state-make 
;       (on buttonpress any alone (? 1) ipf-state2)))

(setq iconify-plug-fsm
      (fsm-make
       (state-make)))

(setq iconify-plug-fsm icon-fsm)
(setq iconify-plug '(with (fsm iconify-plug-fsm background black foreground white)
			  (plug-make (pixmap-make 'iconify))))

(setq window-title-bar
      (with (background black foreground white 
			fsm title-bar-fsm plug-separator 0)
	    (bar-make iconify-plug
;	    (bar-make '(plug-make
;			(with (background black foreground white)
;			      (pixmap-make 'iconify)))
		      '(plug-make
			(with (background black foreground white)
			      (label-make window-name title-font)))
		      ())))

;; qjb's q-win
;(load 'q-win)

(defun describe-window ()
  (list
   (with (fsm window-fsm)
;	 (q-win))
	 (window-make 'window-title-bar () () () ()))
   (with (fsm icon-fsm)
	 (window-make () () () () (plug-make 
				   (label-make 
				    window-icon-name icon-font))))))

(defun describe-screen ()
  (with (opening '(bell) fsm root-fsm)
	(window-make () () () () ())))
	    
