From 511fa0d3963313274ae2b74fc26fde52ddbddb42 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sun, 24 Nov 2013 21:41:02 -0500 Subject: [PATCH] * lisp/frame.el (handle-focus-in, handle-focus-out): Move from frame.c. Remove blink-cursor code. (blink-cursor-timer-function, blink-cursor-suspend): Don't special-case GUIs. (blink-cursor-mode): Use focus-in/out-hook. * src/frame.c (Fhandle_focus_in, Fhandle_focus_out): Move to frame.el. (syms_of_frame): Don't defsubr them. --- lisp/ChangeLog | 16 ++++++++++++---- lisp/frame.el | 45 ++++++++++++++++++++++++++++++--------------- src/ChangeLog | 5 +++++ src/frame.c | 30 ++---------------------------- 4 files changed, 49 insertions(+), 47 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f2d2f732222..d8b176fad65 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2013-11-25 Stefan Monnier + + * frame.el (handle-focus-in, handle-focus-out): Move from frame.c. + Remove blink-cursor code. + (blink-cursor-timer-function, blink-cursor-suspend): + Don't special-case GUIs. + (blink-cursor-mode): Use focus-in/out-hook. + 2013-11-25 Dmitry Gutov * vc/vc-git.el (vc-git-annotate-extract-revision-at-line): Make it @@ -86,13 +94,13 @@ 2013-11-21 Leo Liu - * progmodes/octave.el (octave-mode, inferior-octave-mode): Fix - obsolete variable comment-use-global-state. + * progmodes/octave.el (octave-mode, inferior-octave-mode): + Fix obsolete variable comment-use-global-state. 2013-11-21 Rüdiger Sonderfeld - * progmodes/octave.el (octave-mode-map, octave-mode-menu): Add - `octave-source-file'. + * progmodes/octave.el (octave-mode-map, octave-mode-menu): + Add `octave-source-file'. (octave-source-file): New function. (Bug#15935) 2013-11-21 Kenjiro Nakayama (tiny change) diff --git a/lisp/frame.el b/lisp/frame.el index 87756f78f1c..57f9395b935 100644 --- a/lisp/frame.el +++ b/lisp/frame.el @@ -120,6 +120,21 @@ appended when the minibuffer frame is created." (delete-frame frame t) ;; Gildea@x.org says it is ok to ask questions before terminating. (save-buffers-kill-emacs)))) + +(defun handle-focus-in (_event) + "Handle a focus-in event. +Focus-in events are usually bound to this function. +Focus-in events occur when a frame has focus, but a switch-frame event +is not generated. +This function runs the hook `focus-in-hook'." + (run-hooks 'focus-in-hook)) + +(defun handle-focus-out (_event) + "Handle a focus-out event. +Focus-out events are usually bound to this function. +Focus-out events occur when no frame has focus. +This function runs the hook `focus-out-hook'." + (run-hooks 'focus-out-hook)) ;;;; Arrangement of frames at startup @@ -1727,12 +1742,11 @@ command starts, by installing a pre-command hook." "Timer function of timer `blink-cursor-timer'." (internal-show-cursor nil (not (internal-show-cursor-p))) ;; Each blink is two calls to this function. - (when (memq window-system '(x ns w32)) - (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)))) + (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 () @@ -1747,15 +1761,14 @@ itself as a pre-command hook." (setq blink-cursor-timer nil))) (defun blink-cursor-suspend () - "Suspend cursor blinking on NS, X and W32. + "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." - (when (memq window-system '(x ns w32)) - (blink-cursor-end) - (when blink-cursor-idle-timer - (cancel-timer blink-cursor-idle-timer) - (setq blink-cursor-idle-timer nil)))) + (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. @@ -1789,13 +1802,15 @@ terminals, cursor blinking is controlled by the terminal." (if blink-cursor-idle-timer (cancel-timer blink-cursor-idle-timer)) (setq blink-cursor-idle-timer nil) (blink-cursor-end) + (remove-hook 'focus-in-hook #'blink-cursor-check) + (remove-hook 'focus-out-hook #'blink-cursor-suspend) (when blink-cursor-mode - ;; Hide the cursor. - ;;(internal-show-cursor nil nil) + (add-hook 'focus-in-hook #'blink-cursor-check) + (add-hook 'focus-out-hook #'blink-cursor-suspend) (setq blink-cursor-idle-timer (run-with-idle-timer blink-cursor-delay blink-cursor-delay - 'blink-cursor-start)))) + #'blink-cursor-start)))) ;; Frame maximization/fullscreen diff --git a/src/ChangeLog b/src/ChangeLog index 7f417ccca8a..9947ba4b070 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2013-11-25 Stefan Monnier + + * frame.c (Fhandle_focus_in, Fhandle_focus_out): Move to frame.el. + (syms_of_frame): Don't defsubr them. + 2013-11-25 Glenn Morris * lread.c (load_path_default): Change the sense of the argument. diff --git a/src/frame.c b/src/frame.c index fbfc7722681..84293e27d0d 100644 --- a/src/frame.c +++ b/src/frame.c @@ -887,31 +887,6 @@ This function returns FRAME, or nil if FRAME has been deleted. */) return do_switch_frame (frame, 1, 0, norecord); } -DEFUN ("handle-focus-in", Fhandle_focus_in, Shandle_focus_in, 1, 1, "e", - doc: /* Handle a focus-in event. -Focus in events are usually bound to this function. -Focus in events occur when a frame has focus, but a switch-frame event -is not generated. -This function runs the hook `focus-in-hook'. -It also checks if blink-cursor timers should be turned on again. */) - (Lisp_Object event) -{ - Frun_hooks (1, &Qfocus_in_hook); - return call0 (intern ("blink-cursor-check")); -} - -DEFUN ("handle-focus-out", Fhandle_focus_out, Shandle_focus_out, 1, 1, "e", - doc: /* Handle a focus-out event. -Focus out events are usually bound to this function. -Focus out events occur when no frame has focus. -This function runs the hook `focus-out-hook'. -It also checks if blink-cursor timers should be turned off. */) - (Lisp_Object event) -{ - Frun_hooks (1, &Qfocus_out_hook); - return call0 (intern ("blink-cursor-suspend")); -} - DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e", doc: /* Handle a switch-frame event EVENT. Switch-frame events are usually bound to this function. @@ -926,7 +901,8 @@ to that frame. */) /* Preserve prefix arg that the command loop just cleared. */ kset_prefix_arg (current_kboard, Vcurrent_prefix_arg); Frun_hooks (1, &Qmouse_leave_buffer_hook); - Fhandle_focus_in (event); // switch-frame implies a focus in. + /* `switch-frame' implies a focus in. */ + call1 (intern ("handle-focus-in"), event); return do_switch_frame (event, 0, 0, Qnil); } @@ -4542,8 +4518,6 @@ automatically. See also `mouse-autoselect-window'. */); defsubr (&Swindow_system); defsubr (&Smake_terminal_frame); defsubr (&Shandle_switch_frame); - defsubr (&Shandle_focus_in); - defsubr (&Shandle_focus_out); defsubr (&Sselect_frame); defsubr (&Sselected_frame); defsubr (&Sframe_list); -- 2.39.2