;; vtwm-squeezed-window2.gwm --- VTWM Squeezed Title Window 
;;
;; Author: Anders Holst  (aho@sans.kth.se)  
;; Copyright (C) 1995  Anders Holst
;; Version: vtwm-1.0
;; Last change: 6/6 1995
;;
;; This file is copyrighted under the same terms as the rest of GWM
;; (see the X Inc license for details). There is no warranty that it
;; works. 
;;
;; --------------------------------------------------------------------- 
;;
;; This file defines squeezed title style windows for the VTWM profile.
;; It requires that the normal "vtwm-window.gwm" is already loaded.
;; Use 'set-window' to specify which windows should have squeezed titles.
;;
;; The windows defined here are slightly different from those in
;; "vtwm-squeezed-window.gwm", in that the title is never truncated. This
;; looks better, but makes resize more complicated, and slightly
;; unintuitive in some cases.
;;

(defaults-to 
  vtwm-squeezed-hilite-size 11           ;; Size of area showing focus
  vtwm-squeezed-title-position 'left     ;; Left, right or center
)

(defun vtwm-squeezed2-innerbar ()
  (with (borderwidth 0
         cols (vtwm-get-color)
         vtwm-title-foreground (or (# 0 cols) vtwm-title-foreground)
         vtwm-title-background (or (# 1 cols) vtwm-title-background)
         property (+ (list 'fg vtwm-title-foreground
                           'bg vtwm-title-background)
                     property)
         background vtwm-title-background
         fsm (vtwm-titlebar-fsm) 
         plug-separator 0
         borderpixel vtwm-bordercolor
         bar-min-width 1 bar-max-width 10000
         bar-list (+ (vtwm-make-pluglist vtwm-left-plugs)
                     (list (vtwm-space-plug 5)
                           (vtwm-name-plug) 
                           (with (borderwidth 3
                                  borderpixel vtwm-title-background
                                  fsm (fsm-make vtwm-titlebar-inner-behavior)
                                  bar-min-width vtwm-squeezed-hilite-size
                                  bar-max-width vtwm-squeezed-hilite-size)
                             (bar-make ()))
                           (vtwm-space-plug 2))
                     (vtwm-make-pluglist vtwm-right-plugs)))
    (apply bar-make bar-list)))

(defun vtwm-squeezed2-titlebar ()
  (with (borderwidth 0
         tile t
         background vtwm-bordercolor
         fsm (fsm-make vtwm-squeezed2-resize-behavior1)
         bar-max-width 10000
         plug-separator 0)
    (bar-make (with (fsm (vtwm-borderbar-fsm))
                (bar-make (with (tile t
                                 background vtwm-bordercolor
                                 bar-min-width vtwm-borderwidth
                                 bar-max-width 10000)
                          (if (= vtwm-squeezed-title-position 'right)
                              (bar-make ()
                                        (with (tile ()) (bar-make ))
                                        (with (tile ()) 
                                          (bar-make (bar-make )
                                                    (vtwm-squeezed2-innerbar)))
                                        (with (tile ()) (bar-make )))
                            (= vtwm-squeezed-title-position 'center)
                              (bar-make ()
                                        (with (tile ()) (bar-make ))
                                        (with (tile ()) 
                                          (bar-make (bar-make )
                                                    (vtwm-squeezed2-innerbar)))
                                        (with (tile ()) (bar-make ))
                                        ())
                            (bar-make (with (tile ()) (bar-make ))
                                      (with (tile ()) 
                                        (bar-make (bar-make )
                                                  (vtwm-squeezed2-innerbar)))
                                      (with (tile ()) (bar-make ))
                                      ())))
                          (with (tile ()
                                 background vtwm-bordercolor
                                 bar-min-width vtwm-borderwidth
                                 bar-max-width vtwm-borderwidth)
                                (bar-make )))))))

(defun vtwm-squeezed2-leftborder ()
  (with (borderwidth 0
         tile t
         background vtwm-bordercolor
         fsm (fsm-make vtwm-squeezed2-resize-behavior1)
         plug-separator 0
         border (with (tile ()
                            fsm (vtwm-borderbar-fsm)
                            background vtwm-bordercolor
                            bar-min-width vtwm-borderwidth
                            bar-max-width vtwm-borderwidth)
                        (bar-make )))
    (if (or (= vtwm-squeezed-title-position 'right)
            (= vtwm-squeezed-title-position 'center))
        (bar-make (with (fsm ())
                    (bar-make () border)))
      border)))

(defun vtwm-squeezed2-rightborder ()
  (with (borderwidth 0
         tile t
         background vtwm-bordercolor
         fsm (fsm-make vtwm-squeezed2-resize-behavior1)
         plug-separator 0
         border (with (tile ()
                            fsm (vtwm-borderbar-fsm)
                            background vtwm-bordercolor
                            bar-min-width vtwm-borderwidth
                            bar-max-width vtwm-borderwidth)
                        (bar-make )))
    (if (not (= vtwm-squeezed-title-position 'right))
        (bar-make (with (fsm ())
                    (bar-make border ())))
      border)))

(: vtwm-squeezed2-resize-behavior1
   (state-make 
    (on geometry-change (send-user-event 'bar-resize wob-parent))))

(: vtwm-squeezed2-resize-behavior2
   (state-make 
    (on (user-event 'bar-resize)
        (with (newsize (+ window-client-width (* 2 vtwm-borderwidth))
               oldsize wob-width)
          (if (not (= oldsize newsize))
              (wob-tile (pixmap-make newsize
                                     vtwm-borderwidth)))))))

(defun vtwm-squeezed2-bottomborder-fsm ()
  (fsm-make
    (state-make
     vtwm-squeezed2-resize-behavior2
     vtwm-borderbar-behavior
     standard-title-behavior)))

(defun vtwm-squeezed2-bottomborder ()
  (with (borderwidth 0
         tile t
         background vtwm-bordercolor
         fsm () 
         plug-separator 0
         bottom (with (tile ()
                       fsm (vtwm-squeezed2-bottomborder-fsm)
                       background vtwm-bordercolor
                       bar-min-width vtwm-borderwidth
                       bar-max-width vtwm-borderwidth)
                  (plug-make (pixmap-make (+ window-client-width 
                                             (* 2 vtwm-borderwidth))
                                          vtwm-borderwidth))))
    (if (= vtwm-squeezed-title-position 'right)
        (bar-make () bottom)
      (= vtwm-squeezed-title-position 'center)
        (bar-make () bottom ())
        (bar-make bottom ()))))

(defun vtwm-squeezed-window2 ()
  (with (inner-borderwidth 0
         borderwidth 0
         fsm (vtwm-titled-window-fsm)
         borderpixel vtwm-bordercolor)
    (window-make (vtwm-squeezed2-titlebar)
                 (vtwm-squeezed2-leftborder)
                 (vtwm-squeezed2-rightborder)
                 (vtwm-squeezed2-bottomborder)
                 ())))

