+(defun blink-cursor-suspend ()
+ "Suspend cursor blinking.
+This is called when no frame has focus and timers can be suspended.
+Timers are restarted by `blink-cursor-check', which is called when a
+frame receives focus."
+ (blink-cursor-end)
+ (when blink-cursor-idle-timer
+ (cancel-timer blink-cursor-idle-timer)
+ (setq blink-cursor-idle-timer nil)))
+
+(defun blink-cursor-check ()
+ "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))
+ (remove-hook 'post-command-hook 'blink-cursor-check)
+ (setq blink-cursor-idle-timer
+ (run-with-idle-timer blink-cursor-delay
+ blink-cursor-delay
+ 'blink-cursor-start))))
+