2014-12-20 23:09:40 +00:00
|
|
|
#lang racket/base
|
|
|
|
|
2014-12-22 22:14:13 +00:00
|
|
|
(provide (except-out (struct-out window) window)
|
|
|
|
(struct-out absolute-size)
|
|
|
|
(struct-out relative-size)
|
|
|
|
make-window
|
|
|
|
window-split
|
2014-12-27 23:16:28 +00:00
|
|
|
window-command
|
2014-12-22 22:14:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
(require racket/match)
|
|
|
|
|
2014-12-20 23:09:40 +00:00
|
|
|
(require "buffer.rkt")
|
2014-12-22 22:14:13 +00:00
|
|
|
(require "lists.rkt")
|
|
|
|
|
|
|
|
;; A SizeSpec is either
|
|
|
|
;; -- (absolute-size PositiveInteger), a specific size in screen rows
|
|
|
|
;; -- (relative-size PositiveReal), a weighted window size
|
|
|
|
(struct absolute-size (lines) #:prefab)
|
|
|
|
(struct relative-size (weight) #:prefab)
|
|
|
|
|
|
|
|
(struct window (id ;; Symbol
|
|
|
|
[buffer #:mutable] ;; Buffer
|
2014-12-22 22:17:05 +00:00
|
|
|
) #:prefab)
|
2014-12-22 22:14:13 +00:00
|
|
|
|
|
|
|
(define (make-window initial-buffer)
|
|
|
|
(window (gensym 'window)
|
|
|
|
initial-buffer))
|
|
|
|
|
|
|
|
(define (scale-size s)
|
|
|
|
(match s
|
|
|
|
[(absolute-size _) s] ;; can't scale fixed-size windows
|
|
|
|
[(relative-size w) (relative-size (/ w 2))]))
|
2014-12-20 23:09:40 +00:00
|
|
|
|
2014-12-22 22:14:13 +00:00
|
|
|
(define (window-split w ws #:proportional? [proportional? #f])
|
|
|
|
(replacef ws
|
|
|
|
(lambda (e) (eq? (car e) w))
|
|
|
|
(lambda (e)
|
|
|
|
(define new-size (if proportional? (cadr e) (scale-size (cadr e))))
|
|
|
|
(list (list w new-size)
|
|
|
|
(list (make-window (window-buffer w)) new-size)))))
|
2014-12-27 23:16:28 +00:00
|
|
|
|
|
|
|
(define (window-command selector window
|
|
|
|
#:keyseq [keyseq #f]
|
|
|
|
#:prefix-arg [prefix-arg '#:default])
|
|
|
|
(command selector (window-buffer window) #:window window #:keyseq keyseq #:prefix-arg prefix-arg))
|