Commit 2addf922 authored by Juanma Barranquero's avatar Juanma Barranquero
Browse files

lisp/desktop.el: More fixes to frame restoration.

(desktop-restore-frames): Rename from desktop-save-windows.
(desktop-restore-in-current-display): New customization option.
(desktop--excluded-frame-parameters): Add `font'.
(desktop--save-frames): Rename from desktop--save-windows.
(desktop--restore-in-this-display-p): New function.
(desktop--make-full-frame): Remove unwanted width/height from
full(width|height) frames.
(desktop--restore-frames): Rename from desktop--restore-windows.
Obey desktop-restore-current-display.  Do not delete old frames or
select a new frame unless we were able to restore at least one frame.
parent 7a3518fa
...@@ -252,7 +252,7 @@ on the given date. ...@@ -252,7 +252,7 @@ on the given date.
*** `desktop-auto-save-timeout' defines the number of seconds between *** `desktop-auto-save-timeout' defines the number of seconds between
auto-saves of the desktop. auto-saves of the desktop.
*** `desktop-save-windows' enables saving and restoring the window/frame *** `desktop-restore-frames enables saving and restoring the window/frame
configuration. configuration.
** Dired ** Dired
......
2013-07-01 Juanma Barranquero <lekktu@gmail.com>
* desktop.el (desktop-restore-frames): Rename from desktop-save-windows.
(desktop-restore-in-current-display): New customization option.
(desktop--excluded-frame-parameters): Add `font'.
(desktop--save-frames): Rename from desktop--save-windows.
(desktop--restore-in-this-display-p): New function.
(desktop--make-full-frame): Remove unwanted width/height from
full(width|height) frames.
(desktop--restore-frames): Rename from desktop--restore-windows.
Obey desktop-restore-current-display. Do not delete old frames or
select a new frame unless we were able to restore at least one frame.
2013-06-30 Michal Nazarewicz <mina86@mina86.com> 2013-06-30 Michal Nazarewicz <mina86@mina86.com>
* files.el (find-file-noselect): Simplify conditional expression. * files.el (find-file-noselect): Simplify conditional expression.
......
...@@ -371,12 +371,19 @@ modes are restored automatically; they should not be listed here." ...@@ -371,12 +371,19 @@ modes are restored automatically; they should not be listed here."
:type '(repeat symbol) :type '(repeat symbol)
:group 'desktop) :group 'desktop)
(defcustom desktop-save-windows nil (defcustom desktop-restore-frames nil
"When non-nil, save window/frame configuration to desktop file." "When non-nil, save window/frame configuration to desktop file."
:type 'boolean :type 'boolean
:group 'desktop :group 'desktop
:version "24.4") :version "24.4")
(defcustom desktop-restore-in-current-display nil
"When non-nil, frames are restored in the current display.
Otherwise they are restored, if possible, in their original displays."
:type 'boolean
:group 'desktop
:version "24.4")
(defcustom desktop-file-name-format 'absolute (defcustom desktop-file-name-format 'absolute
"Format in which desktop file names should be saved. "Format in which desktop file names should be saved.
Possible values are: Possible values are:
...@@ -872,6 +879,7 @@ DIRNAME must be the directory in which the desktop file will be saved." ...@@ -872,6 +879,7 @@ DIRNAME must be the directory in which the desktop file will be saved."
buffer-predicate buffer-predicate
buried-buffer-list buried-buffer-list
explicit-name explicit-name
font
font-backend font-backend
minibuffer minibuffer
name name
...@@ -891,12 +899,12 @@ Internal use only." ...@@ -891,12 +899,12 @@ Internal use only."
(push param params))) (push param params)))
params)) params))
(defun desktop--save-windows () (defun desktop--save-frames ()
"Save window/frame state, as a global variable. "Save window/frame state, as a global variable.
Intended to be called from `desktop-save'. Intended to be called from `desktop-save'.
Internal use only." Internal use only."
(setq desktop--saved-states (setq desktop--saved-states
(and desktop-save-windows (and desktop-restore-frames
(mapcar (lambda (frame) (mapcar (lambda (frame)
(cons (desktop--filter-frame-parms frame) (cons (desktop--filter-frame-parms frame)
(window-state-get (frame-root-window frame) t))) (window-state-get (frame-root-window frame) t)))
...@@ -944,7 +952,7 @@ and don't save the buffer if they are the same." ...@@ -944,7 +952,7 @@ and don't save the buffer if they are the same."
(insert "\n;; Global section:\n") (insert "\n;; Global section:\n")
;; Called here because we save the window/frame state as a global ;; Called here because we save the window/frame state as a global
;; variable for compatibility with previous Emacsen. ;; variable for compatibility with previous Emacsen.
(desktop--save-windows) (desktop--save-frames)
(mapc (function desktop-outvar) desktop-globals-to-save) (mapc (function desktop-outvar) desktop-globals-to-save)
(when (memq 'kill-ring desktop-globals-to-save) (when (memq 'kill-ring desktop-globals-to-save)
(insert (insert
...@@ -1003,6 +1011,10 @@ This function also sets `desktop-dirname' to nil." ...@@ -1003,6 +1011,10 @@ This function also sets `desktop-dirname' to nil."
(defvar desktop-lazy-timer nil) (defvar desktop-lazy-timer nil)
;; ---------------------------------------------------------------------------- ;; ----------------------------------------------------------------------------
(defun desktop--restore-in-this-display-p ()
(or desktop-restore-in-current-display
(and (eq system-type 'windows-nt) (not (display-graphic-p)))))
(defun desktop--find-frame-in-display (frames display) (defun desktop--find-frame-in-display (frames display)
(let (result) (let (result)
(while (and frames (not result)) (while (and frames (not result))
...@@ -1017,47 +1029,53 @@ This function also sets `desktop-dirname' to nil." ...@@ -1017,47 +1029,53 @@ This function also sets `desktop-dirname' to nil."
(params '((visibility))) (params '((visibility)))
frame) frame)
(when width (when width
(setq params (append `((user-size . t) (width . ,width)) params))) (setq params (append `((user-size . t) (width . ,width)) params)
config (assq-delete-all 'height config)))
(when height (when height
(setq params (append `((user-size . t) (height . ,height)) params))) (setq params (append `((user-size . t) (height . ,height)) params)
config (assq-delete-all 'width config)))
(setq frame (make-frame-on-display display params)) (setq frame (make-frame-on-display display params))
(modify-frame-parameters frame config) (modify-frame-parameters frame config)
frame)) frame))
(defun desktop--restore-windows () (defun desktop--restore-frames ()
"Restore window/frame configuration. "Restore window/frame configuration.
Internal use only." Internal use only."
(when (and desktop-save-windows desktop--saved-states) (when (and desktop-restore-frames desktop--saved-states)
(let ((frames (frame-list)) (let ((frames (frame-list))
(current (frame-parameter nil 'display))
(selected nil)) (selected nil))
(dolist (state desktop--saved-states) (dolist (state desktop--saved-states)
(condition-case err (condition-case err
(let* ((fconfig (car state)) (let* ((config (car state))
(display (cdr (assq 'display fconfig))) (display (if (desktop--restore-in-this-display-p)
(full (cdr (assq 'fullscreen fconfig))) (setcdr (assq 'display config) current)
(cdr (assq 'display config))))
(full (cdr (assq 'fullscreen config)))
(frame (and (not full) (frame (and (not full)
(desktop--find-frame-in-display frames display)))) (desktop--find-frame-in-display frames display))))
(cond (full (cond (full
;; treat fullscreen/maximized frames specially ;; treat fullscreen/maximized frames specially
(setq frame (desktop--make-full-frame full display fconfig))) (setq frame (desktop--make-full-frame full display config)))
(frame (frame
;; found a frame in the right display -- reuse ;; found a frame in the right display -- reuse
(setq frames (delq frame frames)) (setq frames (delq frame frames))
(modify-frame-parameters frame fconfig)) (modify-frame-parameters frame config))
(t (t
;; no frames in the display -- make a new one ;; no frames in the display -- make a new one
(setq frame (make-frame-on-display display fconfig)))) (setq frame (make-frame-on-display display config))))
;; restore windows ;; restore windows
(window-state-put (cdr state) (frame-root-window frame) 'safe) (window-state-put (cdr state) (frame-root-window frame) 'safe)
(unless selected (setq selected frame))) (unless selected (setq selected frame)))
(error (error
(message "Error restoring frame: %S" (error-message-string err))))) (message "Error restoring frame: %S" (error-message-string err)))))
(when selected
;; make sure the original selected frame is visible and selected ;; make sure the original selected frame is visible and selected
(unless (or (frame-parameter selected 'visibility) (daemonp)) (unless (or (frame-parameter selected 'visibility) (daemonp))
(modify-frame-parameters selected '((visibility . t)))) (modify-frame-parameters selected '((visibility . t))))
(select-frame-set-input-focus selected) (select-frame-set-input-focus selected)
;; delete any remaining frames ;; delete any remaining frames
(mapc #'delete-frame frames)))) (mapc #'delete-frame frames)))))
;;;###autoload ;;;###autoload
(defun desktop-read (&optional dirname) (defun desktop-read (&optional dirname)
...@@ -1127,7 +1145,7 @@ Using it may cause conflicts. Use it anyway? " owner))))) ...@@ -1127,7 +1145,7 @@ Using it may cause conflicts. Use it anyway? " owner)))))
(switch-to-buffer (car (buffer-list))) (switch-to-buffer (car (buffer-list)))
(run-hooks 'desktop-delay-hook) (run-hooks 'desktop-delay-hook)
(setq desktop-delay-hook nil) (setq desktop-delay-hook nil)
(desktop--restore-windows) (desktop--restore-frames)
(run-hooks 'desktop-after-read-hook) (run-hooks 'desktop-after-read-hook)
(message "Desktop: %d buffer%s restored%s%s." (message "Desktop: %d buffer%s restored%s%s."
desktop-buffer-ok-count desktop-buffer-ok-count
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment