; (c) 1992 J.Harper
; macro	to stack windows

; (stackwins <dir> <type>)
; <dir>	    `x' or `y' (direction to stack in)
; <type>    `a', `v' or `f' (what windows to stack)

; now ignores sleeping windows.

(macro `stackwins'
{
    (local
	`maxx'   (info `screenx')
	`maxy'   (info `screeny')
	`maxwin' @
	`actwin' 0
	`i'      @
	`type'   (arg 2 `s' `type (a/v/f)> ')
    )

    (select
	(== (type) `a')
	{
	    (= `maxwin' (info `windows'))
	}
	(== (type) `v')
	{
	    (= `maxwin' (info `views'))
	}
	(== (type) `f')
	{
	    (= `maxwin' (info `files'))
	}
	{
	    (settitle (format `error: unknown type %s' (type)))
	    (return)
	}
    )

    (= `i' 0)
    (while {(!=	(i) (maxwin))}
    {
	(if (! (info `asleep'))
	{
	    (= `actwin' (+ (actwin) 1))
	})
	(= `i' (+ (i) 1))
	(nextwind (type))
    })

    (if	(== (arg 1 `s' `direction (x/y)> ') `y')
    {
	(local
	    `sizey' (/ (maxy) (actwin))
	    `curry' 0
	)

	(= `i' 0)
	(while {(!= (i)	(maxwin))}
	{
	    (if	(! (info `asleep'))
	    {
		(position 0 (curry) (maxx) (sizey))
		(= `curry' (+ (curry) (sizey)))
	    })
	    (nextwind (type))
	    (= `i' (+ (i) 1))
	})
    }
    {
	(local
	    `sizex' (/ (maxx) (actwin))
	    `currx' 0
	)

	(= `i' 0)
	(while {(!= (i)	(maxwin))}
	{
	    (if	(! (info `asleep'))
	    {
		(position (currx) 0 (sizex) (maxy))
		(= `currx' (+ (currx) (sizex)))
	    })
	    (nextwind (type))
	    (= `i' (+ (i) 1))
	})
    })
})

