From 5ed119141d10a09c4cd767c42a25a285f4f844ce Mon Sep 17 00:00:00 2001 From: Daniel Colascione Date: Tue, 12 Jun 2018 23:09:23 -0700 Subject: [PATCH] Ignore focus events for dead frames Frames can die between the time we generate a focus event and the time we get around to processing it. Do run after-focus-change-function, since that's idempotent and we want to make sure not to miss any changes. * lisp/frame.el (handle-focus-in, handle-focus-out): Check for dead frames. --- lisp/frame.el | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lisp/frame.el b/lisp/frame.el index 7dbd346bd91..70b4b242a02 100644 --- a/lisp/frame.el +++ b/lisp/frame.el @@ -209,11 +209,12 @@ the window system." (interactive "e") (unless (eq (car-safe event) 'focus-in) (error "handle-focus-in should handle focus-in events")) - (internal-handle-focus-in event) (let ((frame (nth 1 event))) - (setf (frame-parameter frame 'last-focus-update) t) - (run-hooks 'focus-in-hook) - (funcall after-focus-change-function))) + (when (frame-live-p frame) + (internal-handle-focus-in event) + (setf (frame-parameter frame 'last-focus-update) t) + (run-hooks 'focus-in-hook))) + (funcall after-focus-change-function)) (defun handle-focus-out (event) "Handle a focus-out event. @@ -225,9 +226,10 @@ that's not the whole story: see `after-focus-change-function'." (unless (eq (car event) 'focus-out) (error "handle-focus-out should handle focus-out events")) (let ((frame (nth 1 event))) - (setf (frame-parameter frame 'last-focus-update) nil) - (run-hooks 'focus-out-hook) - (funcall after-focus-change-function))) + (when (frame-live-p frame) + (setf (frame-parameter frame 'last-focus-update) nil) + (run-hooks 'focus-out-hook))) + (funcall after-focus-change-function)) (defun handle-move-frame (event) "Handle a move-frame event. -- 2.39.2