diff options
author | Jan Djärv <jan.h.d@swipnet.se> | 2013-07-16 13:41:06 +0200 |
---|---|---|
committer | Jan Djärv <jan.h.d@swipnet.se> | 2013-07-16 13:41:06 +0200 |
commit | 18c26d81cde21b841a8f5f81b81118e5f8c6b07d (patch) | |
tree | 72be27efcb214d2a038bf8551f8e88e191ec9f02 /lisp/frame.el | |
parent | c7ddc792b747fdf4fde822df0cf9c7b712be4219 (diff) | |
download | emacs-18c26d81cde21b841a8f5f81b81118e5f8c6b07d.tar.gz |
Stop cursor blink after blink-cursor-blinks (10), stop timers when not blinking.
* etc/NEWS: Document blink-cursor-blinks and blink timers stopped.
* lisp/frame.el (blink-cursor-blinks): New defcustom.
(blink-cursor-blinks-done): New defvar.
(blink-cursor-start): Set blink-cursor-blinks-done to 1.
(blink-cursor-timer-function): Check if number of blinks has been
done on X and NS.
(blink-cursor-suspend, blink-cursor-check): New defuns.
* src/frame.c (Fhandle_focus_in, Fhandle_focus_out): New functions.
(Fhandle_switch_frame): Call Fhandle_focus_in.
(syms_of_frame): defsubr handle-focus-in/out.
* src/keyboard.c (Qfocus_in, Qfocus_out): New static objects.
(make_lispy_focus_in, make_lispy_focus_out): Declare and define.
(kbd_buffer_get_event): For FOCUS_IN, make a focus_in event if no
switch frame event is made. Check ! NILP (event->arg) if X11 (moved
from xterm.c). Make focus_out event for FOCUS_OUT_EVENT if NS or X11
and there is a focused frame.
(head_table): Add focus-in and focus-out.
(keys_of_keyboard): Add focus-in and focus-out to Vspecial_event_map,
bind to handle-focus-in/out.
* src/nsterm.m (windowDidResignKey): If this is the focused frame, generate
FOCUS_OUT_EVENT.
* src/termhooks.h (enum event_kind): Add FOCUS_OUT_EVENT.
* src/xterm.c (x_focus_changed): Always generate FOCUS_IN_EVENT.
Set event->arg to Qt if switch-event shall be generated.
Generate FOCUS_OUT_EVENT for FocusOut if this is the focused frame.
Diffstat (limited to 'lisp/frame.el')
-rw-r--r-- | lisp/frame.el | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/lisp/frame.el b/lisp/frame.el index 3ac24a509a0..a37d1189552 100644 --- a/lisp/frame.el +++ b/lisp/frame.el @@ -1671,6 +1671,16 @@ left untouched. FRAME nil or omitted means use the selected frame." :type 'number :group 'cursor) +(defcustom blink-cursor-blinks 10 + "How many times to blink before using a solid cursor on NS and X. +Use 0 or negative value to blink forever." + :version "24.4" + :type 'integer + :group 'cursor) + +(defvar blink-cursor-blinks-done 1 + "Number of blinks done since we started blinking on NS and X") + (defvar blink-cursor-idle-timer nil "Timer started after `blink-cursor-delay' seconds of Emacs idle time. The function `blink-cursor-start' is called when the timer fires.") @@ -1688,6 +1698,7 @@ command starts, by installing a pre-command hook." (when (null blink-cursor-timer) ;; Set up the timer first, so that if this signals an error, ;; blink-cursor-end is not added to pre-command-hook. + (setq blink-cursor-blinks-done 1) (setq blink-cursor-timer (run-with-timer blink-cursor-interval blink-cursor-interval 'blink-cursor-timer-function)) @@ -1696,7 +1707,15 @@ command starts, by installing a pre-command hook." (defun blink-cursor-timer-function () "Timer function of timer `blink-cursor-timer'." - (internal-show-cursor nil (not (internal-show-cursor-p)))) + (internal-show-cursor nil (not (internal-show-cursor-p))) + ;; Each blink is two calls to this function. + (when (memq window-system '(x ns)) + (setq blink-cursor-blinks-done (1+ blink-cursor-blinks-done)) + (when (and (> blink-cursor-blinks 0) + (<= (* 2 blink-cursor-blinks) blink-cursor-blinks-done)) + (blink-cursor-suspend) + (add-hook 'post-command-hook 'blink-cursor-check)))) + (defun blink-cursor-end () "Stop cursor blinking. @@ -1709,6 +1728,29 @@ itself as a pre-command hook." (cancel-timer blink-cursor-timer) (setq blink-cursor-timer nil))) +(defun blink-cursor-suspend () + "Suspend cursor blinking on NS and X. +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." + (when (memq window-system '(x ns)) + (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 cursot 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)))) + (define-obsolete-variable-alias 'blink-cursor 'blink-cursor-mode "22.1") (define-minor-mode blink-cursor-mode |