>From bc99736c1fe63c2facaf741c5638d645576c1d88 Mon Sep 17 00:00:00 2001 From: Morgan Veyret Date: Sun, 15 Jun 2008 00:55:06 +0200 Subject: [PATCH] Added restore-or-create options to define-frame-preference. When set to T a new group will be created if there's no match, if NIL old behavior is assumed (this is the window is placed into the current group and an error message appears). If a dump file matching group-name is present inside *group-dump-dir* it'll be used to restore the group layout upon creation. --- primitives.lisp | 8 ++++++-- window.lisp | 31 ++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/primitives.lisp b/primitives.lisp index 2326897..0debc3d 100644 --- a/primitives.lisp +++ b/primitives.lisp @@ -909,13 +909,17 @@ will have no effect.") "List of rules governing window placement. Use define-frame-preference to add rules") +(defvar *group-dump-dir* ".stumpwm.d/") (defmacro define-frame-preference (group &rest frames) (let ((x (gensym "X"))) `(dolist (,x ',frames) ;; verify the correct structure - (destructuring-bind (frame-number raise lock &rest keys &key class instance type role title) ,x - (push (list* ,group frame-number raise lock keys) *window-placement-rules*))))) + (destructuring-bind (frame-number raise lock restore-or-create + &rest keys + &key class instance type role title) ,x + (push (list* ,group frame-number raise lock restore-or-create keys) + *window-placement-rules*))))) (defun clear-window-placement-rules () (setf *window-placement-rules* nil)) diff --git a/window.lisp b/window.lisp index 8abbf15..74709e2 100644 --- a/window.lisp +++ b/window.lisp @@ -735,8 +735,9 @@ than the root window's width and height." (defun window-matches-rule-p (w rule) "Returns T if window matches rule" - (destructuring-bind (group-name frame raise lock &rest props) rule - (declare (ignore frame raise)) + (destructuring-bind (group-name frame raise lock restore-or-create + &rest props) rule + (declare (ignore frame raise restore-or-create)) (if (or lock (equal group-name (group-name (or (window-group w) (current-group))))) (apply 'window-matches-properties-p w props)))) @@ -752,14 +753,30 @@ than the root window's width and height." the window should be raised." (let ((match (rule-matching-window window))) (if match - (destructuring-bind (group-name frame raise lock &rest props) match + (destructuring-bind (group-name frame raise lock + restore-or-create dump-name + &rest props) match (declare (ignore lock props)) (let ((group (find-group screen group-name))) (if group (values group (frame-by-number group frame) raise) - (progn - (message "^B^1*Error placing window, group \"^b~a^B\" does not exist." group-name) - (values))))) + (if restore-or-create + (let ((new-group (add-group (current-screen) group-name)) + (group-dump-file (concat *group-dump-dir* + group-name))) + (if (and new-group + (probe-file group-dump-file)) + (progn (restore-group new-group + (read-dump-from-file group-dump-file)) + (values new-group + (frame-by-number new-group frame) + raise)) + (progn (message "^B^1*Error restoring group \"^b~a^B\" from \"^b~a^B\"." new-group group-dump-file) + (values new-group + (frame-by-number new-group frame) + raise)))) + (progn (message "^B^1*Error placing window, group \"^b~a^B\" does not exist." group-name) + (values)))))) (values)))) (defun sync-window-placement () @@ -919,7 +936,7 @@ needed." (declare (type window window)) ;; put it in a valid group (let ((screen (window-screen window))) - ;; Use window plaecment rules + ;; Use window placement rules (multiple-value-bind (group frame raise) (get-window-placement screen window) (declare (ignore raise)) (unless (find (window-group window) -- 1.5.5.1