summaryrefslogtreecommitdiff
path: root/lisp/frame.el
diff options
context:
space:
mode:
authorDaniel Colascione <dancol@dancol.org>2018-06-11 16:08:29 -0700
committerDaniel Colascione <dancol@dancol.org>2018-06-11 16:10:34 -0700
commit4ff438a45a5d3e380622ceaf4b9aa93cf89be4c8 (patch)
treedbbc24a5be843fbd5be0ead3784462287636c5cf /lisp/frame.el
parent6a1dfa713b70861f63def3dbb1d5b1aa6c236e79 (diff)
downloademacs-4ff438a45a5d3e380622ceaf4b9aa93cf89be4c8.tar.gz
Make blink-cursor-mode use new focus functions
* lisp/frame.el (blink-cursor--should-blink): New function. (blink-cursor-check): Call it. (blink-cursor--rescan-frames): New function. (blink-cursor-mode): Wire up `blink-cursor--rescan-frames`; stop using `focus-in-hook' and `focus-out-hook'.
Diffstat (limited to 'lisp/frame.el')
-rw-r--r--lisp/frame.el50
1 files changed, 38 insertions, 12 deletions
diff --git a/lisp/frame.el b/lisp/frame.el
index 2a2391e8a53..a0e7b35a138 100644
--- a/lisp/frame.el
+++ b/lisp/frame.el
@@ -2416,15 +2416,41 @@ frame receives focus."
(cancel-timer blink-cursor-idle-timer)
(setq blink-cursor-idle-timer nil)))
-(defun blink-cursor-check ()
+(defun blink-cursor--should-blink (&optional ignored-frame)
+ "Determine whether we should be blinking.
+Returns whether we have any focused non-TTY frame. IGNORED-FRAME
+is a frame to ignore during the scan, used when we want to ignore
+a frame about to be deleted."
+ (and blink-cursor-mode
+ (let ((frame-list (frame-list))
+ (any-graphical-focused nil))
+ (while frame-list
+ (let ((frame (pop frame-list)))
+ (when (and (not (eq frame ignored-frame))
+ (display-graphic-p frame)
+ (frame-focus-state frame))
+ (setf any-graphical-focused t)
+ (setf frame-list nil))))
+ any-graphical-focused)))
+
+(defun blink-cursor-check (&optional ignored-frame)
"Check if cursor blinking shall be restarted.
-This is done when a frame gets focus. Blink timers may be stopped by
-`blink-cursor-suspend'."
- (when (and blink-cursor-mode
- (not blink-cursor-idle-timer)
- (display-graphic-p))
- (remove-hook 'post-command-hook 'blink-cursor-check)
- (blink-cursor--start-idle-timer)))
+This is done when a frame gets focus. Blink timers may be
+stopped by `blink-cursor-suspend'. Internally calls
+`blink-cursor--should-blink' and returns its result."
+ (let ((should-blink (blink-cursor--should-blink ignored-frame)))
+ (when (and should-blink (not blink-cursor-idle-timer))
+ (remove-hook 'post-command-hook 'blink-cursor-check)
+ (blink-cursor--start-idle-timer))
+ should-blink))
+
+(defun blink-cursor--rescan-frames (&optional ignored-frame)
+ "Called when the set of focused frames changes or when we
+delete a frame. Re-check whether we want to enable blinking.
+IGNORED-FRAME is there so we ignore a frame about to be deleted
+when we're called under via `delete-frame-functions'."
+ (unless (blink-cursor-check ignored-frame)
+ (blink-cursor-suspend)))
(define-minor-mode blink-cursor-mode
"Toggle cursor blinking (Blink Cursor mode).
@@ -2448,11 +2474,11 @@ terminals, cursor blinking is controlled by the terminal."
:group 'cursor
:global t
(blink-cursor-suspend)
- (remove-hook 'focus-in-hook #'blink-cursor-check)
- (remove-hook 'focus-out-hook #'blink-cursor-suspend)
+ (remove-hook 'delete-frame-functions #'blink-cursor--rescan-frames)
+ (remove-function after-focus-change-function #'blink-cursor--rescan-frames)
(when blink-cursor-mode
- (add-hook 'focus-in-hook #'blink-cursor-check)
- (add-hook 'focus-out-hook #'blink-cursor-suspend)
+ (add-function :after after-focus-change-function #'blink-cursor--rescan-frames)
+ (add-hook 'delete-frame-functions #'blink-cursor--rescan-frames)
(blink-cursor--start-idle-timer)))