swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Saving window positions


From: Marcus G. Daniels
Subject: Re: Saving window positions
Date: 06 Jul 1998 21:06:11 -0700

>>>>> "ST" == Sven N Thommesen <address@hidden> writes:

ST> If there was a way for our intrepid Swarm programmers to get
ST> absolute coordinates saved, we wouldn't have to worry about all
ST> this. 

To reiterate, the problem is that a `desk' is private window manager
data structure -- there isn't a standard interface to get this
information as there is for geometry.  That means either using a
private window manager protocol (presumably with some linked-in interface
library), or handle the window archiving and repositioning entirely using
the window manager.  For Swarm to support desks, we'd end up needing 
support code specific to each window manager.  Yuck.

Instead, here's an example of desk-aware geometry archiving.  It's for
Scwm 0.7, a Scheme-based window manager that otherwise resembles
fvwm2.  http://web.mit.edu/mstachow/www/scwm.html

By appending the Scheme code below into your .scwmrc, the middle mouse
button gets bound to a Swarm window-archiving feature.  Note that this
completely sidesteps the existing `Save' button; all the work is done
by the window manager.

I did modify the Swarm to set X resource names for Tk windows
to be the same as the Swarm archiving keys -- if this Scwm config fails
to work, let me know and I'll point you to a current Swarm snapshot. 
I didn't test this configuration with Swarm 1.2.

(define *home-vicinity* (make-vicinity (getenv "HOME")))   
(use-modules (ice-9 slib)
             (app scwm flux))

(define *windowinfo-alist* '())

(require 'alist)

(define (swarm-windows)
    (let loop ((l (list-all-windows)))
         (if (null? l)
             '()
             (let* ((swarm-sig "Swarm-")
                    (swarm-len (string-length swarm-sig))
                    (w (car l))
                    (class (window-class w)))
               (if (and (>= (string-length class) swarm-len)
                        (string=? (substring class 0 swarm-len)
                                  swarm-sig))
                   (cons (make-windowinfo
                          (string->symbol (window-class w))
                          (string->symbol (window-resource w))
                          (window-desk w)
                          (window-position w))
                         (loop (cdr l)))
                   (loop (cdr l)))))))

(define windowinfo (make-record-type "WINDOW" '(class resource desk position)))
(define make-windowinfo (record-constructor windowinfo))
(define windowinfo-class (record-accessor windowinfo 'class))
(define windowinfo-resource (record-accessor windowinfo 'resource))
(define windowinfo-desk (record-accessor windowinfo 'desk))
(define windowinfo-position (record-accessor windowinfo 'position))

(define (find-window class-sym name-sym)
    (let ((matching-windows
           (list-windows 
            #:only
            (lambda (w)
              (and (eq? (string->symbol (window-class w)) class-sym)
                   (eq? (string->symbol (window-resource w)) name-sym))))))
      (if matching-windows
          (if (= (length matching-windows) 1)
              (car matching-windows)
              #f)
          #f)))

(define (reposition wi)
    (let ((position (windowinfo-position wi))
          (w (find-window (windowinfo-class wi)
                          (windowinfo-resource wi))))
      (if w
          (begin
           (move-window-to-desk (windowinfo-desk wi) w)
           (move-to (car position) (car (cdr position)) w))
          #f)))

(define (load-swarm-windows)
    (let loop ((wipairl *windowinfo-alist*))
         (if (null? wipairl)
             #f
             (begin
              (reposition (cdr (car wipairl)))
              (loop (cdr wipairl))))))

(define (windowinfo-expr wi)
    `(make-windowinfo
      ',(windowinfo-class wi)
      ',(windowinfo-resource wi)
      ,(windowinfo-desk wi)
      ',(windowinfo-position wi)))

(define (windowinfo-key wi)
    `'(,(windowinfo-class wi) . ,(windowinfo-resource wi)))

(define windowinfo-replace (alist-associator equal?))
(define windowinfo-find (alist-inquirer equal?))

(define (update-windowinfo-alist)
    (let loop ((wil (swarm-windows)))
         (let ((wi (car wil)))
           (set! *windowinfo-alist* 
                 (windowinfo-replace *windowinfo-alist*
                                     (cons (windowinfo-class wi)
                                           (windowinfo-resource wi))
                                     windowinfo)))))

(define (save-swarm-window-layout)
    (with-output-to-file 
        (in-vicinity *home-vicinity* ".swarmArchiver.scm")
      (lambda ()
        (write (list 'set!
                     '*windowinfo-alist*
                     (cons
                      'list
                      (let loop ((wil (swarm-windows)))
                           (if (null? wil)
                               '()
                                (let ((wi (car wil)))
                                  (cons
                                   (list
                                    'cons
                                    (windowinfo-key wi)
                                    (windowinfo-expr wi))
                                   (loop (cdr wil))))))))))))

(define (load-swarm-archive)
    (load (in-vicinity *home-vicinity* ".swarmArchiver.scm")))

(bind-mouse 'root 2
            (lambda ()
              (popup-menu
               (menu (list
                      (menuitem "Save Swarm Window Configuration"
                                #:action (lambda ()
                                           (update-windowinfo-alist)
                                           (save-swarm-window-layout)))
                      (menuitem "Recover Swarm Window Configuration"
                                #:action
                                (lambda ()
                                  (load-swarm-archive)
                                  (load-swarm-windows))))))))

(define (reposition-window w)
    (let ((windowinfo 
           (windowinfo-find *windowinfo-alist*
                            (cons (string->symbol (window-class w))
                                  (string->symbol (window-resource w))))))
      (if windowinfo
          (reposition windowinfo)
          #f)))

(add-hook! before-new-window-hook (lambda (w) (set-random-placement! #t w)))
(add-hook! after-new-window-hook reposition-window)
(load-swarm-archive)

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]