Skip to content

Commit

Permalink
* core/core-display-init.el: Bump graphic frame initialization to aft…
Browse files Browse the repository at this point in the history
…er-make-frame-functions (#16755)

* * core/core-display-init.el: Bump graphic frame initilization to after-make-frame-functions

* core-display-init.el: Run all after-display-init functions after error

* core-display-init.el: Improve docstrings and error messages

---------

Co-authored-by: Aaron L. Zeng <[email protected]>
  • Loading branch information
sunlin7 and bcc32 authored Dec 29, 2024
1 parent e133574 commit 0898770
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions core/core-display-init.el
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"List of functions to be run after the display system is initialized.")

(defun spacemacs--display-system-initialized-p ()
"Dectect the display system initialized or not."
"Return non-nil if the display system has been initialized."
(cond ((boundp 'ns-initialized) ns-initialized)
;; w32-initialized gets set too early, so
;; if we're on Windows, check the list of fonts
Expand All @@ -36,19 +36,27 @@
;; fallback to normal loading behavior only if in a GUI
(t (display-graphic-p))))

(define-advice server-create-window-system-frame
(:after (&rest _) spacemacs-init-display)
"After Emacs server creates a frame, run functions queued in
`SPACEMACS--AFTER-DISPLAY-SYSTEM-INIT-LIST' to do any setup that needs to have
the display system initialized."
(defun spacemacs//init-window-frame (frame)
"After Emacs creates a window frame FRAME, run enqueued functions.
Functions are called with FRAME selected.
Queued functions are added to
`spacemacs--after-display-system-init-list' and are run once,
only after the display system has been initialized."
(when (spacemacs--display-system-initialized-p)
(mapc #'funcall (reverse spacemacs--after-display-system-init-list))
(advice-remove 'server-create-window-system-frame
#'server-create-window-system-frame@spacemacs-init-display)))
(dolist (f (reverse spacemacs--after-display-system-init-list))
(with-demoted-errors "spacemacs|do-after-display-system-init: %S"
(with-selected-frame frame
(funcall f))))
(remove-hook 'after-make-frame-functions #'spacemacs//init-window-frame)))

(add-hook 'after-make-frame-functions #'spacemacs//init-window-frame)

(defmacro spacemacs|do-after-display-system-init (&rest body)
"If the display-system is initialized, run `BODY', otherwise,
add it to a queue of actions to perform after the first graphical frame is
"If the display system is initialized, run BODY.
Otherwise, enqueue it until after the first graphical frame is
created."
`(if (not (spacemacs--display-system-initialized-p))
(push (lambda () ,@body) spacemacs--after-display-system-init-list)
Expand Down

0 comments on commit 0898770

Please sign in to comment.