1
;; sm-load.jl -- session manager code to reload a saved session
2
;; $Id: load.jl,v 1.10 2001/01/29 01:34:37 jsh Exp $
4
;; Copyright (C) 1999 John Harper <john@dcs.warwick.ac.uk>
6
;; This file is part of sawmill.
8
;; sawmill is free software; you can redistribute it and/or modify it
9
;; under the terms of the GNU General Public License as published by
10
;; the Free Software Foundation; either version 2, or (at your option)
13
;; sawmill is distributed in the hope that it will be useful, but
14
;; WITHOUT ANY WARRANTY; without even the implied warranty of
15
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
;; GNU General Public License for more details.
18
;; You should have received a copy of the GNU General Public License
19
;; along with sawmill; see the file COPYING. If not, write to
20
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
;; This currently assumes that load-session is called before any
25
;; windows are adopted. If this isn't the case apply-to-window
26
;; will need extra code to act on the restored state (which would
27
;; otherwise be done by functions in the add-window-hook)
29
(define-structure sawfish.wm.session.load
38
sawfish.wm.session.init
39
sawfish.wm.session.util)
41
(define restored-session nil)
43
(define (load-session filename)
44
(setq restored-session nil)
45
(when (file-exists-p filename)
46
(let ((file (open-file filename 'read)))
51
(setq restored-session (cons (read file)
54
(setq restored-session (nreverse restored-session))))
56
(map-windows match-window)))))
58
;; Scan restored-session for window W
59
(define (match-window w)
60
(let ((item (catch 'found
62
(when (match-window-to-alist w x)
66
(setq restored-session (delq item restored-session))
67
(apply-to-window w item))))
69
;; Match window W to ALIST
70
(define (match-window-to-alist w alist)
71
(let ((client-id (sm-get-window-prop w 'SM_CLIENT_ID))
72
(role (nth 2 (get-x-property w 'WM_WINDOW_ROLE)))
73
(class (sm-get-window-prop w 'WM_CLASS))
74
(command (sm-get-window-prop w 'WM_COMMAND)))
76
(when (not (eq (not (cdr (assq 'client-id alist))) (not client-id)))
77
;; one has a client-id, the other doesn't -- no match
81
(unless (string= client-id (cdr (assq 'client-id alist)))
84
;; no SM_CLIENT_ID, so try matching WM_COMMAND
85
((and command (cdr (assq 'command alist)))
86
(unless (string= command (cdr (assq 'command alist)))
88
;; no WM_COMMAND so no match
92
(if (and role (cdr (assq 'role alist)))
93
(unless (string= role (cdr (assq 'role alist)))
95
;; no WM_WINDOW_ROLE, so try matching WM_CLASS
96
(when (and class (cdr (assq 'class alist))
97
(not (string= class (cdr (assq 'class alist)))))
100
;; XXX match on WM_NAME and WM_CLIENT_MACHINE..?
102
;; if we got here it must be a match
105
;; Apply saved state in ALIST to W. This assumes that the add window
106
;; hook hasn't been called yet
107
(define (apply-to-window w alist)
109
(when (setq tem (cdr (assq 'dimensions alist)))
110
(resize-window-to w (car tem) (cdr tem)))
112
(when (setq tem (cdr (assq sym alist)))
113
(window-put w sym tem))) sm-saved-window-properties)
114
(call-window-hook 'sm-restore-window-hook w (list alist))))
116
(add-hook 'before-add-window-hook match-window))