;; *** layout ******************************************************** (define (get-root-layout root-wm) (letrec ((loop (lambda (wm) (let ((children (filter (lambda (x) x) (map (lambda (c) (get-manager-by-window root-wm (client:window c))) (wm-clients wm))))) (cons (manager-type-name (wm:type wm)) (cons (get-options-diff (wm:options wm)) (map loop children))))))) (cddr (loop (root-wm:initial-manager root-wm))))) (define (create-root-layout root-wm layout) (letrec ((loop (lambda (parent spec) (let ((type (car spec)) (options (cadr spec)) (more (cddr spec))) (let* ((type2 (cond ((eq? 'split type) (manager-type split)) ((eq? 'switch type) (manager-type switch)) ((eq? 'move type) (manager-type move)))) ;; else error ?! (def-opt (get-option-value (root-wm:options root-wm) (cond ((eq? 'split type) 'default-split-options) ((eq? 'switch type) 'default-switch-options) ((eq? 'move type) 'default-move-options)))) (wm (create-new-manager root-wm type2 options def-opt parent))) (for-each (lambda (spec) (loop wm spec)) more)))))) (for-each (lambda (spec) (loop (root-wm:initial-manager root-wm) spec)) layout))) (define (layout-filename dpy) (let ((dir (resolve-tilde-file-name "~/.orion-wm"))) (if (not (file-exists? dir)) (create-directory dir)) (string-append dir "/layout-" (display:name dpy)))) (define (backup-layout root-wm) (call-with-output-file (layout-filename (root-wm:dpy root-wm)) (lambda (p) (for-each (lambda (spec) (write spec p)) (get-root-layout root-wm))))) (define (restore-layout root-wm) (let* ((fn (layout-filename (root-wm:dpy root-wm))) (layout (if (file-exists? fn) (call-with-input-file fn (lambda (p) (port->sexp-list p))) ;; if no layout file exists, one switch-wm ;; workspace is the default '((switch ()))))) (create-root-layout root-wm layout))) ;; *** configuration ************************************************* (define (config-filename dpy) (let ((dir (resolve-tilde-file-name "~/.orion-wm"))) (if (not (file-exists? dir)) (create-directory dir)) (string-append dir "/config-" (display:name dpy)))) (define (load-configuration dpy) (let ((filename (config-filename dpy))) (if (file-exists? filename) (call-with-current-continuation (lambda (return) (with-handler (lambda (condition punt) (mdisplay "error loading configuration file " filename ".\n") (mdisplay "problem is: " condition "\n") (mdisplay "ignoring it...\n") (return '())) (lambda () (load-config-file filename) (let ((config-file (reify-structure 'config-file))) (load-structure config-file) (let ((get (lambda (n) (rt-structure-binding config-file n)))) (append (list (cons 'default-split-options (get 'split-options)) (cons 'default-switch-options (get 'switch-options)) (cons 'default-move-options (get 'move-options))) (get 'root-options)))))))) ;; TODO: maybe create a file with default-config-file in it '()))) (define default-config-file '( (define-structure config-file config-file-interface (open scheme xlib config-file-utils) (begin ;; your options here )) ))