all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Lennart Borgman <lennart.borgman@gmail.com>
To: martin rudalics <rudalics@gmx.at>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>, emacs-devel@gnu.org
Subject: Re: moving window handling into lisp
Date: Thu, 13 Aug 2009 12:25:10 +0200	[thread overview]
Message-ID: <e01d8a50908130325k52c19b75r6040d11aed098af4@mail.gmail.com> (raw)
In-Reply-To: <e01d8a50908130257v1cea32e9q8d8985359f5ed6f6@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 769 bytes --]

On Thu, Aug 13, 2009 at 11:57 AM, Lennart
Borgman<lennart.borgman@gmail.com> wrote:
> On Thu, Aug 13, 2009 at 11:55 AM, martin rudalics<rudalics@gmx.at> wrote:
>>> Ehum, as always..., here is a better, somewhat more working version... ;-)
>>
>> IIUC you're going down in some window tree and try to distribute the
>> available space among the children of each internal window.  But the
>> interesting part is when you have to backtrack because some window
>> didn't fit into its parent and you have to shrink (or enlarge) some
>> (grand-)parent's sibling.  I couldn't find that part :-(
>
>
> And that is the whole point of going up the tree and collecting sizes first...


Here is the walking down part too. You have to tell me what you are missing.

[-- Attachment #2: win-alg.el --]
[-- Type: text/plain, Size: 7559 bytes --]

;;; 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 (name width wmin wmax)
  (list (list 'name name)            ;; Easier communication ...
        (list 'child nil)            ;; Child windows
        (list 'size width wmin wmax) ;; Old size and restrictions
        (list 'compsize nil nil)     ;; Slot for computation, wmin wmax
        (list 'set-size nil)         ;; Slot for setting, wmin wmax
        ))

;; Fix-me: Make defmacro to make those getters setters... - including
;; checks...
(defun wa-name  (window) (nth 1 (nth 0 window)))
(defun wa-child (window) (nth 1 (nth 1 window)))
(defun wa-width (window) (nth 1 (nth 2 window)))
(defun wa-wmin  (window) (nth 2 (nth 2 window)))
(defun wa-wmax  (window) (nth 3 (nth 2 window)))
(defun wa-wcmin (window) (nth 1 (nth 3 window)))
(defun wa-wcmax (window) (nth 2 (nth 3 window)))
(defun wa-wset  (window) (nth 1 (nth 4 window)))

(defun wa-set-name   (window name)  (setcar (nthcdr 1 (nth 0 window)) name))
(defun wa-set-child  (window child) (setcar (nthcdr 1 (nth 1 window)) child))
(defun wa-set-width  (window width) (setcar (nthcdr 1 (nth 2 window)) width))
(defun wa-set-wmin   (window wmin)  (setcar (nthcdr 2 (nth 2 window)) wmin))
(defun wa-set-wmax   (window wmax)  (setcar (nthcdr 3 (nth 2 window)) wmax))
(defun wa-set-wcmin  (window wmin)  (setcar (nthcdr 1 (nth 3 window)) wmin))
(defun wa-set-wcmax  (window wmax)  (setcar (nthcdr 2 (nth 3 window)) wmax))
(defun wa-set-wset   (window size)  (setcar (nthcdr 1 (nth 4 window)) size))

(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
         (num 0))
    (setcar (nth 1 real-sizes) (- par-size tot-given))
    (setq children (mapcar (lambda (size)
                             (setq num (1+ num))
                             (if vertical
                                 (wa-make-window (format "%s-%d" (wa-name parent) num)
                                                 (nth 0 size)
                                                 (nth 1 size)
                                                 (nth 2 size))
                               ;;(wa-make-window size par-other-size)
                               ))
                           real-sizes))
    (wa-set-child parent children)))

(defun wa-check-fit (win)
  (let ((wmin (wa-wmin win))
        (wmax (wa-wmax win))
        (wcmin (wa-wcmin win))
        (wcmax (wa-wcmax win)))
    (when (and wmax wcmin)
      (unless (<= wcmin wmax)
        (error "Window %s is too small, min=%d, but can be max=%d" (wa-name win) wcmin wmax)))
    (when (and wcmax wmin)
      (unless (<= wcmax wmin)
        (error "Window %s's childs are too small, max=%d, but can be min=%d" (wa-name win) wcmax wmin)))))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Computation of sizes

(defun wa-clear-computed (win)
  (wa-set-wcmin win nil)
  (wa-set-wcmax win nil)
  (dolist (c (wa-child win))
    (wa-clear-computed c)))

(defun wa-compute-required (win)
  "Walk up collecting needed sizes."
  (let ((childs (wa-child win))
        (wmin (wa-wmin win))
        (wmax (wa-wmax win))
        (cmin 0)
        (cmax nil))
    (when childs
      (dolist (c childs)
        (let* ((res (wa-compute-required c))
               (res-min (nth 0 res))
               (res-max (nth 1 res)))
          ;; Just sum the MIN
          (setq cmin (+ cmin res-min))
          (if res-max
              ;; ... ok, let us sum MAX to see how big we can be ...
              (if (numberp cmax)
                  (setq cmax (+ cmax res-max))
                (setq cmax res-max))
            ;; Hurray, at least one child can grow!
            (setq cmax nil)))))
    (when wmin (setq cmin (max wmin (or cmin wmin))))
    (when wmax (setq cmax (min wmax (or cmax wmax))))
    (wa-set-wcmin win cmin)
    (wa-set-wcmax win cmax)
    (wa-check-fit win)
    (list (wa-wcmin win)
          (wa-wcmax win))))

(defun wa-compute-wanted (win strategy)
  "Walk down compute sizes."
  ;; Set root window size
  (unless (wa-wset win) (wa-set-wset win (wa-width win)))
  (let ((cmin   (wa-wcmin  win))
        (cmax   (wa-wcmax  win))
        (width  (wa-width win))
        (childs (wa-child win))
        )
  (case strategy
    ('eq-sizes
     (let (
           (rest-width width)
           (goal (/ width (length childs)))
           (rest-childs (copy-sequence childs)))
       ;; Clear childs
       (dolist (c childs) (wa-set-wset c nil))
       ;; Check child min requirements
       (dolist (c (copy-sequence rest-childs))
         (let ((wcmin (wa-wcmin c)))
           (when (and wcmin (<= goal wcmin))
             (wa-set-wset c (wa-wcmin c))
             (setq rest-childs (delete c rest-childs))
             (setq rest-width (- rest-width (wa-wcmin c))))))
       (setq goal (/ rest-width (length childs)))
       ;; Check child max requirements
       (dolist (c (copy-sequence rest-childs))
         (let ((wcmax (wa-wcmax c)))
           (when (and wcmax (>= goal wcmax))
             (wa-set-wset c (wa-wcmax c))
             (setq rest-childs (delete c rest-childs))
             (setq rest-width (- rest-width (wa-wcmax c))))))
       (setq goal (/ rest-width (length childs)))
       ;; Distribute the rest, taking care of roundings
       (wa-set-wset (car rest-childs)
                   (- rest-width (* goal (1- (length rest-childs)))))
       (dolist (c (cdr rest-childs))
         (wa-set-wset c goal))))
    (t (error "Unknown rule: %s" rule)))
  ;; Check
  (let ((w 0))
    (dolist (c childs)
      (setq w (+ w (wa-wset c))))
    (unless (= w (wa-wset win))
      (error "Bad set sizes child sum w=%d, win width=%d" w (wa-wset win))))
  ))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Testing part

(defvar wa-root-window nil)

(defun wa-add-test-childs ()
  (wa-set-child-windows wa-root-window t
                         '(nil nil nil)
                         '(5 4 nil)
                         '(8 nil nil)
                         '(4 3 nil)
                         ))

(setq wa-root-window (wa-make-window "Root" 80 nil nil))
(setq wa-root-window (wa-make-window "Root" 80 nil 8))
(setq wa-root-window (wa-make-window "Root" 80 nil 6))
(setq wa-root-window (wa-make-window "Root" 80 5 nil))
(setq wa-root-window (wa-make-window "Root" 80 15 nil))

;; (wa-child wa-root-window)
;; (wa-width wa-root-window)
;; (wa-wmin wa-root-window)
;; (wa-wmax wa-root-window)
;; (wa-clear-computed wa-root-window)

(wa-add-test-childs)
(wa-compute-required wa-root-window)
(wa-compute-wanted   wa-root-window 'eq-sizes)
(describe-variable 'wa-root-window)



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; win-alg.el ends here

  reply	other threads:[~2009-08-13 10:25 UTC|newest]

Thread overview: 130+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-27  8:32 moving window handling into lisp Miles Bader
2009-07-27 13:37 ` martin rudalics
2009-07-27 13:41   ` Lennart Borgman
2009-07-27 13:45     ` martin rudalics
2009-07-27 13:58       ` Lennart Borgman
2009-07-27 14:35         ` martin rudalics
2009-07-27 14:41           ` Lennart Borgman
2009-07-27 15:02             ` martin rudalics
2009-07-27 15:28               ` Lennart Borgman
2009-07-27 16:52                 ` martin rudalics
2009-07-27 16:58                   ` Lennart Borgman
2009-07-27 18:18                   ` Stefan Monnier
2009-07-28  7:38                     ` martin rudalics
2009-07-28  9:39                       ` Lennart Borgman
2009-07-28 12:25                         ` martin rudalics
     [not found]                           ` <e01d8a50907280532kcff2d1w15567a430668a502@mail.gmail.com>
2009-07-28 13:23                             ` martin rudalics
2009-07-28 13:44                               ` Lennart Borgman
2009-07-29  9:04                                 ` martin rudalics
2009-07-28 13:47                       ` Stefan Monnier
2009-07-28 14:11                         ` Lennart Borgman
2009-07-29  9:05                         ` martin rudalics
2009-07-29 14:05                           ` Stefan Monnier
2009-08-01  2:20                             ` Miles Bader
2009-08-03 21:29                               ` Stefan Monnier
2009-08-11  9:18                             ` martin rudalics
2009-08-11 19:16                               ` Stefan Monnier
2009-08-11 19:29                                 ` Lennart Borgman
2009-08-12  8:57                                   ` martin rudalics
2009-08-12  9:02                                     ` Lennart Borgman
2009-08-12 13:33                                       ` martin rudalics
2009-08-12 15:57                                         ` Lennart Borgman
2009-08-12 17:05                                           ` martin rudalics
2009-08-12 19:39                                             ` Lennart Borgman
2009-08-12 21:10                                               ` Lennart Borgman
2009-08-13  9:55                                                 ` martin rudalics
2009-08-13  9:57                                                   ` Lennart Borgman
2009-08-13 10:25                                                     ` Lennart Borgman [this message]
2009-08-13 11:32                                                       ` Lennart Borgman
2009-08-13 12:49                                                         ` Lennart Borgman
2009-08-13 13:56                                                           ` martin rudalics
2009-08-13 16:43                                                             ` Lennart Borgman
2009-08-13 18:07                                                               ` martin rudalics
2009-08-14  1:13                                                                 ` Lennart Borgman
2009-08-14  7:18                                                                   ` martin rudalics
2009-08-14 11:21                                                                     ` Lennart Borgman
2009-08-14 13:21                                                                       ` martin rudalics
2009-08-12  8:56                                 ` martin rudalics
2009-08-13  2:32                                   ` Stefan Monnier
2009-08-13  9:54                                     ` martin rudalics
2009-08-13 17:00                                       ` Stefan Monnier
2009-08-13 18:09                                         ` martin rudalics
2009-08-14  1:47                                           ` Stephen J. Turnbull
2009-08-14  7:17                                             ` martin rudalics
2009-08-14  6:42                                       ` Richard Stallman
2009-08-14  7:18                                         ` martin rudalics
2009-08-14 20:56                                           ` Richard Stallman
2009-08-15 10:12                                             ` martin rudalics
2009-08-15 19:47                                               ` Stefan Monnier
2009-08-14 15:39                                         ` Stefan Monnier
2009-08-14 15:42                                           ` Lennart Borgman
2009-08-14 18:26                                             ` Stefan Monnier
2009-08-15 10:12                                           ` martin rudalics
2009-08-15 11:02                                             ` Lennart Borgman
2009-08-15 12:44                                               ` martin rudalics
2009-08-15 13:35                                                 ` David Kastrup
2009-08-15 13:39                                                   ` Lennart Borgman
2009-08-15 16:11                                                     ` martin rudalics
2009-08-15 16:19                                                       ` Lennart Borgman
2009-08-15 17:37                                                         ` martin rudalics
2009-08-15 18:18                                                           ` Lennart Borgman
2009-08-16 10:25                                                             ` martin rudalics
2009-08-16 11:14                                                               ` Lennart Borgman
2009-08-16 12:12                                                                 ` David Kastrup
2009-08-16 12:19                                                                   ` Lennart Borgman
2009-08-16 15:17                                                                   ` martin rudalics
2009-08-16 16:15                                                                     ` David Kastrup
2009-08-16 19:24                                                                       ` martin rudalics
2009-08-16 12:17                                                                 ` martin rudalics
2009-08-16 12:26                                                                   ` Lennart Borgman
2009-08-16 15:18                                                                     ` martin rudalics
2009-08-15 19:05                                                           ` Stephen J. Turnbull
2009-08-16 10:26                                                             ` martin rudalics
2009-08-16 11:16                                                               ` Lennart Borgman
2009-08-16 12:17                                                                 ` martin rudalics
2009-08-16 12:29                                                                   ` Lennart Borgman
2009-08-16 15:18                                                                     ` martin rudalics
2009-08-16 14:49                                                               ` Stephen J. Turnbull
2009-08-16 15:31                                                                 ` martin rudalics
2009-08-16 16:28                                                                   ` Stephen J. Turnbull
2009-08-16 19:25                                                                     ` martin rudalics
2009-08-15 15:07                                                   ` Jan Djärv
2009-08-15 15:38                                                     ` David Kastrup
2009-08-15 16:07                                                   ` martin rudalics
2009-08-15 18:21                                                     ` Stephen J. Turnbull
2009-08-16 10:25                                                       ` martin rudalics
2009-08-15 19:51                                             ` Stefan Monnier
2009-08-16 10:26                                               ` martin rudalics
2009-08-16 11:18                                                 ` Lennart Borgman
2009-08-16 12:17                                                   ` martin rudalics
2009-08-16 12:30                                                     ` Lennart Borgman
2009-07-27 14:00   ` Miles Bader
2009-07-27 14:36     ` martin rudalics
     [not found] ` <4A87F8B8.6050102@gmx.at>
     [not found]   ` <e01d8a50908160523r12216cffm34060d2793943785@mail.gmail.com>
     [not found]     ` <4A882312.6020106@gmx.at>
     [not found]       ` <e01d8a50908191816p2d9e978dw6aa0623c79dd8699@mail.gmail.com>
     [not found]         ` <4A8D12B3.6070502@gmx.at>
     [not found]           ` <e01d8a50908200219o69f67900lb9fa9368e9aadf62@mail.gmail.com>
     [not found]             ` <4A8D46C9.1010108@gmx.at>
     [not found]               ` <e01d8a50908200622y101e5b2bq9fb5874cbb8c81fe@mail.gmail.com>
     [not found]                 ` <4A8D66D5.3000600@gmx.at>
2009-08-20 15:41                   ` Lennart Borgman
2009-08-20 18:15                     ` martin rudalics
2009-08-20 23:08                       ` Lennart Borgman
2009-08-21 12:40                         ` martin rudalics
2009-08-21 13:58                           ` Lennart Borgman
2009-08-22 11:00                             ` martin rudalics
2009-08-22 13:45                               ` Lennart Borgman
2009-08-22 14:17                                 ` martin rudalics
2009-08-21 19:34                       ` Stefan Monnier
2009-08-22 11:01                         ` martin rudalics
2009-08-21  0:19                     ` Richard Stallman
2009-08-21 12:40                       ` martin rudalics
  -- strict thread matches above, loose matches on Subject: below --
2009-08-17 19:06 grischka
2009-08-18  7:13 ` martin rudalics
2009-08-18 11:38 ` Lennart Borgman
2009-08-19  9:15   ` grischka
2009-08-19 12:45     ` martin rudalics
2009-08-20 11:45       ` grischka
2009-08-20 12:51         ` martin rudalics
2009-08-20 13:05           ` David Kastrup
2009-08-20 15:08             ` martin rudalics
2009-08-20 19:35           ` grischka
2009-08-21 12:22             ` martin rudalics
2009-08-21 19:32               ` Stefan Monnier
2009-08-22  4:55                 ` Stephen J. Turnbull
2009-08-23  1:01                   ` Stefan Monnier
2009-08-24 13:10               ` grischka
2009-08-19 13:01     ` Lennart Borgman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e01d8a50908130325k52c19b75r6040d11aed098af4@mail.gmail.com \
    --to=lennart.borgman@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=rudalics@gmx.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.