;;; win-alg.el --- Window size computation ;; ;; Author: Lennart Borgman (lennart O borgman A gmail O com) ;; Created: 2009-08-12 Wed ;; Version: 0.1 ;; Last-Updated: 2009-08-12 Wed ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; Code: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Window creation etc ;;(defun wa-make-window (width wmin wmax height hmin hmax) (defun wa-make-window (width wmin wmax) (list (list 'child nil) ;; Child (list 'size width wmin wmax) ;; Actual values (list 'compsize nil nil) ;; Slot for computation, wmin wmax )) (defun wa-child (window) (nth 1 (nth 0 window))) (defun wa-width (window) (nth 1 (nth 1 window))) (defun wa-wmin (window) (nth 2 (nth 1 window))) (defun wa-wmax (window) (nth 3 (nth 1 window))) (defun wa-set-child (window child) (setcar (nthcdr 1 (nth 0 window)) child)) (defun wa-set-width (window) (setcar (nthcdr 1 (nth 1 window)))) (defun wa-set-wmin (window) (setcar (nthcdr 2 (nth 1 window)))) (defun wa-set-wmax (window) (setcar (nthcdr 3 (nth 1 window)))) (defvar wa-root-window nil) (setq wa-root-window (wa-make-window 80 nil nil)) (defun wa-set-child-windows (parent vertical &rest sizes) (dolist (s sizes) (assert (= 3 (length s)) t)) (let* ((tot-given (apply '+ (mapcar (lambda (s) (car s)) (cdr sizes)))) (par-size (if vertical (wa-width parent) (wa-height parent))) ;;(par-other-size (if vertical (wa-height parent) (wa-width parent))) (real-sizes (copy-sequence sizes)) children) (setcar (nth 1 real-sizes) (- par-size tot-given)) (setq children (mapcar (lambda (size) (if vertical (wa-make-window (nth 0 size) (nth 1 size) (nth 2 size)) ;;(wa-make-window size par-other-size) )) real-sizes)) (wa-set-child parent children))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Computation of sizes (defun wa-compute-required (win) (let ((cmin (or (wa-wmin win) most-negative-fixnum)) (cmax (or (wa-wmax win) most-positive-fixnum))) (dolist (c (wa-child win)) (let ((res (wa-compute-required c))) (setq cmin (max (nth 0 res) cmin)) (setq cmax (max (nth 1 res) cmax)))) (assert (eq 'compsize (car (nth 2 win)))) (setcar (nthcdr 1 (nth 2 win)) cmin) (setcar (nthcdr 2 (nth 2 win)) cmax) (list cmin cmax))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Testing part ;; (wa-test) ;; (wa-child wa-root-window) ;; (wa-width wa-root-window) ;; (wa-wmin wa-root-window) ;; (wa-wmax wa-root-window) ;; (wa-compute-required wa-root-window) (defun wa-test () (wa-set-child-windows wa-root-window t '(nil nil nil) '(5 4 nil) '(8 nil nil) '(4 3 nil) )) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; win-alg.el ends here