diff options
| author | Daniel Colascione | 2018-06-11 16:08:29 -0700 |
|---|---|---|
| committer | Daniel Colascione | 2018-06-11 16:10:34 -0700 |
| commit | 4ff438a45a5d3e380622ceaf4b9aa93cf89be4c8 (patch) | |
| tree | dbbc24a5be843fbd5be0ead3784462287636c5cf | |
| parent | 6a1dfa713b70861f63def3dbb1d5b1aa6c236e79 (diff) | |
| download | emacs-4ff438a45a5d3e380622ceaf4b9aa93cf89be4c8.tar.gz emacs-4ff438a45a5d3e380622ceaf4b9aa93cf89be4c8.zip | |
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'.
| -rw-r--r-- | lisp/frame.el | 50 |
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." | |||
| 2416 | (cancel-timer blink-cursor-idle-timer) | 2416 | (cancel-timer blink-cursor-idle-timer) |
| 2417 | (setq blink-cursor-idle-timer nil))) | 2417 | (setq blink-cursor-idle-timer nil))) |
| 2418 | 2418 | ||
| 2419 | (defun blink-cursor-check () | 2419 | (defun blink-cursor--should-blink (&optional ignored-frame) |
| 2420 | "Determine whether we should be blinking. | ||
| 2421 | Returns whether we have any focused non-TTY frame. IGNORED-FRAME | ||
| 2422 | is a frame to ignore during the scan, used when we want to ignore | ||
| 2423 | a frame about to be deleted." | ||
| 2424 | (and blink-cursor-mode | ||
| 2425 | (let ((frame-list (frame-list)) | ||
| 2426 | (any-graphical-focused nil)) | ||
| 2427 | (while frame-list | ||
| 2428 | (let ((frame (pop frame-list))) | ||
| 2429 | (when (and (not (eq frame ignored-frame)) | ||
| 2430 | (display-graphic-p frame) | ||
| 2431 | (frame-focus-state frame)) | ||
| 2432 | (setf any-graphical-focused t) | ||
| 2433 | (setf frame-list nil)))) | ||
| 2434 | any-graphical-focused))) | ||
| 2435 | |||
| 2436 | (defun blink-cursor-check (&optional ignored-frame) | ||
| 2420 | "Check if cursor blinking shall be restarted. | 2437 | "Check if cursor blinking shall be restarted. |
| 2421 | This is done when a frame gets focus. Blink timers may be stopped by | 2438 | This is done when a frame gets focus. Blink timers may be |
| 2422 | `blink-cursor-suspend'." | 2439 | stopped by `blink-cursor-suspend'. Internally calls |
| 2423 | (when (and blink-cursor-mode | 2440 | `blink-cursor--should-blink' and returns its result." |
| 2424 | (not blink-cursor-idle-timer) | 2441 | (let ((should-blink (blink-cursor--should-blink ignored-frame))) |
| 2425 | (display-graphic-p)) | 2442 | (when (and should-blink (not blink-cursor-idle-timer)) |
| 2426 | (remove-hook 'post-command-hook 'blink-cursor-check) | 2443 | (remove-hook 'post-command-hook 'blink-cursor-check) |
| 2427 | (blink-cursor--start-idle-timer))) | 2444 | (blink-cursor--start-idle-timer)) |
| 2445 | should-blink)) | ||
| 2446 | |||
| 2447 | (defun blink-cursor--rescan-frames (&optional ignored-frame) | ||
| 2448 | "Called when the set of focused frames changes or when we | ||
| 2449 | delete a frame. Re-check whether we want to enable blinking. | ||
| 2450 | IGNORED-FRAME is there so we ignore a frame about to be deleted | ||
| 2451 | when we're called under via `delete-frame-functions'." | ||
| 2452 | (unless (blink-cursor-check ignored-frame) | ||
| 2453 | (blink-cursor-suspend))) | ||
| 2428 | 2454 | ||
| 2429 | (define-minor-mode blink-cursor-mode | 2455 | (define-minor-mode blink-cursor-mode |
| 2430 | "Toggle cursor blinking (Blink Cursor mode). | 2456 | "Toggle cursor blinking (Blink Cursor mode). |
| @@ -2448,11 +2474,11 @@ terminals, cursor blinking is controlled by the terminal." | |||
| 2448 | :group 'cursor | 2474 | :group 'cursor |
| 2449 | :global t | 2475 | :global t |
| 2450 | (blink-cursor-suspend) | 2476 | (blink-cursor-suspend) |
| 2451 | (remove-hook 'focus-in-hook #'blink-cursor-check) | 2477 | (remove-hook 'delete-frame-functions #'blink-cursor--rescan-frames) |
| 2452 | (remove-hook 'focus-out-hook #'blink-cursor-suspend) | 2478 | (remove-function after-focus-change-function #'blink-cursor--rescan-frames) |
| 2453 | (when blink-cursor-mode | 2479 | (when blink-cursor-mode |
| 2454 | (add-hook 'focus-in-hook #'blink-cursor-check) | 2480 | (add-function :after after-focus-change-function #'blink-cursor--rescan-frames) |
| 2455 | (add-hook 'focus-out-hook #'blink-cursor-suspend) | 2481 | (add-hook 'delete-frame-functions #'blink-cursor--rescan-frames) |
| 2456 | (blink-cursor--start-idle-timer))) | 2482 | (blink-cursor--start-idle-timer))) |
| 2457 | 2483 | ||
| 2458 | 2484 | ||