[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 4ff438a 5/5: Make blink-cursor-mode use new focus f
From: |
Daniel Colascione |
Subject: |
[Emacs-diffs] master 4ff438a 5/5: Make blink-cursor-mode use new focus functions |
Date: |
Mon, 11 Jun 2018 19:11:00 -0400 (EDT) |
branch: master
commit 4ff438a45a5d3e380622ceaf4b9aa93cf89be4c8
Author: Daniel Colascione <address@hidden>
Commit: Daniel Colascione <address@hidden>
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'.
---
lisp/frame.el | 50 ++++++++++++++++++++++++++++++++++++++------------
1 file changed, 38 insertions(+), 12 deletions(-)
diff --git a/lisp/frame.el b/lisp/frame.el
index 2a2391e..a0e7b35 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)))