
;;File: placements.gwm -- functions to automatically place windows on screen
;;Author: colas@mirsa.inria.fr (Colas NAHABOO) -- Bull Research FRANCE
;;Author: Frederic CHARTON
;;Revision: 1.0 -- Sep 12 1989
;;State: Exp
;;GWM Version: 1.4

; PLACEMENTS
; ==========

(de user-positioning (flag)
    (if flag
	(if (and (not window-was-on-screen) 
		 (not window-starts-iconic)
                 (not window-is-transient-for)
		 interactivePlacement
		 (not (and window-user-set-position
			   (= window-status 'window))))
	    (progn (: l (current-mouse-position))
		   (if (member 'placement showFeedback)
		       (progn
			 (meter-open-in-place)
			 (meter-update	(+ "( " (itoa window-x) " , "
					   (itoa window-y) ")    "
					   (itoa window-width) " x "
					   (itoa window-height)))))
		   (: x (# 0 l))
		   (: y (# 1 l))
		   (with (move-meter 1) (move-window x y))
		   (process-exposes)
		   (: new-window window)
		   (with (cursor place-cursor) (move-window))
		   (if (member 'placement showFeedback) (meter-close))
		   )
	  (if (< window-y 0)(move-window window-x 0))
	  )))

(defun meter-open-in-place ()
  (with (position (meter 'x 0 'y 0))
    (meter-open (nth 1 position) (nth 3 position) " ")))

; Icon Placement :
; --------------
(defun placement (flag)
 (if iconAutoPlace
    (if flag				; open new window
      (if (member window (list-of-windows))
	(with (thePlace (auto-get-place)
	       X (# 0 thePlace)
  	       Y (# 1 thePlace)
	      )
	 (## 'X window X)
	 (## 'Y window Y)
	 (eval (+ '(move-window) (XY-to-xy X Y)))
	 (set-icon-of-array X Y window)
	)
      )
	; close managed window
	(with (X (# 'X window-property) 
	       Y (# 'Y window-property)
	      )
	  (if X (set-icon-of-array X Y ()))
	)
    )
  (with (window window-window)
   (move-window window-icon (+ window-x window-client-x)
		(+ window-y window-client-y))
   )))
