diff options
| author | Juanma Barranquero | 2013-06-30 07:08:23 +0200 |
|---|---|---|
| committer | Juanma Barranquero | 2013-06-30 07:08:23 +0200 |
| commit | a47cbd64fa3565207417a49af9f3cfe1154b2f6e (patch) | |
| tree | 9a131cf103e2b6d048e34b9fd29c3bf5ff924339 | |
| parent | 6dbafa3000c0f39834f36adcd56d9332f7f1bc85 (diff) | |
| download | emacs-a47cbd64fa3565207417a49af9f3cfe1154b2f6e.tar.gz emacs-a47cbd64fa3565207417a49af9f3cfe1154b2f6e.zip | |
Some fixes and improvements for desktop frame restoration.
It is still experimental and disabled by default.
* lisp/desktop.el (desktop--save-windows): Put the selected frame at
the head of the list.
(desktop--make-full-frame): New function.
(desktop--restore-windows): Try to re-select the frame that was
selected upon saving. Do not abort if some frames fail to restore,
just show an error message and contnue. Set up maximized frames so
they have default non-maximized dimensions.
| -rw-r--r-- | lisp/ChangeLog | 12 | ||||
| -rw-r--r-- | lisp/desktop.el | 58 |
2 files changed, 54 insertions, 16 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index aa2b3505411..4100efc4d6d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2013-06-30 Juanma Barranquero <lekktu@gmail.com> | ||
| 2 | |||
| 3 | Some fixes and improvements for desktop frame restoration. | ||
| 4 | It is still experimental and disabled by default. | ||
| 5 | * desktop.el (desktop--save-windows): Put the selected frame at | ||
| 6 | the head of the list. | ||
| 7 | (desktop--make-full-frame): New function. | ||
| 8 | (desktop--restore-windows): Try to re-select the frame that was | ||
| 9 | selected upon saving. Do not abort if some frames fail to restore, | ||
| 10 | just show an error message and contnue. Set up maximized frames so | ||
| 11 | they have default non-maximized dimensions. | ||
| 12 | |||
| 1 | 2013-06-30 Dmitry Gutov <dgutov@yandex.ru> | 13 | 2013-06-30 Dmitry Gutov <dgutov@yandex.ru> |
| 2 | 14 | ||
| 3 | * progmodes/ruby-mode.el (ruby-syntax-propertize-function): Don't | 15 | * progmodes/ruby-mode.el (ruby-syntax-propertize-function): Don't |
diff --git a/lisp/desktop.el b/lisp/desktop.el index 68c2b26b5d7..7d4ea20c210 100644 --- a/lisp/desktop.el +++ b/lisp/desktop.el | |||
| @@ -900,7 +900,8 @@ Internal use only." | |||
| 900 | (mapcar (lambda (frame) | 900 | (mapcar (lambda (frame) |
| 901 | (cons (desktop--filter-frame-parms frame) | 901 | (cons (desktop--filter-frame-parms frame) |
| 902 | (window-state-get (frame-root-window frame) t))) | 902 | (window-state-get (frame-root-window frame) t))) |
| 903 | (frame-list)))) | 903 | (cons (selected-frame) |
| 904 | (delq (selected-frame) (frame-list)))))) | ||
| 904 | (desktop-outvar 'desktop--saved-states)) | 905 | (desktop-outvar 'desktop--saved-states)) |
| 905 | 906 | ||
| 906 | ;;;###autoload | 907 | ;;;###autoload |
| @@ -1010,28 +1011,53 @@ This function also sets `desktop-dirname' to nil." | |||
| 1010 | (setq frames (cdr frames)))) | 1011 | (setq frames (cdr frames)))) |
| 1011 | result)) | 1012 | result)) |
| 1012 | 1013 | ||
| 1014 | (defun desktop--make-full-frame (full display config) | ||
| 1015 | (let ((width (and (eq full 'fullheight) (cdr (assq 'width config)))) | ||
| 1016 | (height (and (eq full 'fullwidth) (cdr (assq 'height config)))) | ||
| 1017 | (params '((visibility))) | ||
| 1018 | frame) | ||
| 1019 | (when width | ||
| 1020 | (setq params (append `((user-size . t) (width . ,width)) params))) | ||
| 1021 | (when height | ||
| 1022 | (setq params (append `((user-size . t) (height . ,height)) params))) | ||
| 1023 | (setq frame (make-frame-on-display display params)) | ||
| 1024 | (modify-frame-parameters frame config) | ||
| 1025 | frame)) | ||
| 1026 | |||
| 1013 | (defun desktop--restore-windows () | 1027 | (defun desktop--restore-windows () |
| 1014 | "Restore window/frame configuration. | 1028 | "Restore window/frame configuration. |
| 1015 | Internal use only." | 1029 | Internal use only." |
| 1016 | (when (and desktop-save-windows desktop--saved-states) | 1030 | (when (and desktop-save-windows desktop--saved-states) |
| 1017 | (condition-case nil | 1031 | (let ((frames (frame-list)) |
| 1018 | (let ((frames (frame-list))) | 1032 | (selected nil)) |
| 1019 | (dolist (state desktop--saved-states) | 1033 | (dolist (state desktop--saved-states) |
| 1034 | (condition-case err | ||
| 1020 | (let* ((fconfig (car state)) | 1035 | (let* ((fconfig (car state)) |
| 1021 | (display (cdr (assq 'display fconfig))) | 1036 | (display (cdr (assq 'display fconfig))) |
| 1022 | (frame (desktop--find-frame-in-display frames display))) | 1037 | (full (cdr (assq 'fullscreen fconfig))) |
| 1023 | (if (not frame) | 1038 | (frame (and (not full) |
| 1024 | ;; no frames in the display -- make a new one | 1039 | (desktop--find-frame-in-display frames display)))) |
| 1025 | (setq frame (make-frame-on-display display fconfig)) | 1040 | (cond (full |
| 1026 | ;; found one -- reuse and remove from list | 1041 | ;; treat fullscreen/maximized frames specially |
| 1027 | (setq frames (delq frame frames)) | 1042 | (setq frame (desktop--make-full-frame full display fconfig))) |
| 1028 | (modify-frame-parameters frame fconfig)) | 1043 | (frame |
| 1044 | ;; found a frame in the right display -- reuse | ||
| 1045 | (setq frames (delq frame frames)) | ||
| 1046 | (modify-frame-parameters frame fconfig)) | ||
| 1047 | (t | ||
| 1048 | ;; no frames in the display -- make a new one | ||
| 1049 | (setq frame (make-frame-on-display display fconfig)))) | ||
| 1029 | ;; restore windows | 1050 | ;; restore windows |
| 1030 | (window-state-put (cdr state) (frame-root-window frame) 'safe))) | 1051 | (window-state-put (cdr state) (frame-root-window frame) 'safe) |
| 1031 | ;; delete any remaining frames | 1052 | (unless selected (setq selected frame))) |
| 1032 | (mapc #'delete-frame frames)) | 1053 | (error |
| 1033 | (error | 1054 | (message "Error restoring frame: %S" (error-message-string err))))) |
| 1034 | (message "Error loading window configuration from desktop file"))))) | 1055 | ;; make sure the original selected frame is visible and selected |
| 1056 | (unless (or (frame-parameter selected 'visibility) (daemonp)) | ||
| 1057 | (modify-frame-parameters selected '((visibility . t)))) | ||
| 1058 | (select-frame-set-input-focus selected) | ||
| 1059 | ;; delete any remaining frames | ||
| 1060 | (mapc #'delete-frame frames)))) | ||
| 1035 | 1061 | ||
| 1036 | ;;;###autoload | 1062 | ;;;###autoload |
| 1037 | (defun desktop-read (&optional dirname) | 1063 | (defun desktop-read (&optional dirname) |