diff options
| author | Daniel Colascione | 2018-06-08 22:47:27 -0700 |
|---|---|---|
| committer | Daniel Colascione | 2018-06-08 22:51:50 -0700 |
| commit | 6fdc3fac5658a7ab142c358cddd90f3db5665ef5 (patch) | |
| tree | 543c9c987546e0bf6dc1bf50f4e18dca097436f3 | |
| parent | f1e65b73ca20f72717d0b50fa5d983668a49bc38 (diff) | |
| download | emacs-6fdc3fac5658a7ab142c358cddd90f3db5665ef5.tar.gz emacs-6fdc3fac5658a7ab142c358cddd90f3db5665ef5.zip | |
Support terminal focus notifications
* lisp/frame.el (handle-focus-in,handle-focus-out): Make event
argument optional.
(blink-cursor-check): Make sure that the current frame is a
window-system frame before restarting the blink timer. TTY frames
can get focus, but don't need a blink timer because the terminal
will do the blinking.
* lisp/term/xterm.el
(xterm-handle-focus-in,xterm-handle-focus-out): New functions.
(xterm-rxvt-function-map): Recognize focus notification sequences.
(xterm--init-focus-tracking): New function.
(terminal-init-xterm): Call it.
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/frame.el | 7 | ||||
| -rw-r--r-- | lisp/term/xterm.el | 21 |
3 files changed, 30 insertions, 3 deletions
| @@ -576,6 +576,11 @@ manual for more details. | |||
| 576 | * Lisp Changes in Emacs 27.1 | 576 | * Lisp Changes in Emacs 27.1 |
| 577 | 577 | ||
| 578 | +++ | 578 | +++ |
| 579 | ** Emacs now requests and recognizes focus-change notifications from | ||
| 580 | terminals that support the feature, meaning that `focus-in-hook' | ||
| 581 | and `focus-out-hook' may run for TTY frames. | ||
| 582 | |||
| 583 | +++ | ||
| 579 | ** Face specifications (of the kind used in `face-remapping-alist') | 584 | ** Face specifications (of the kind used in `face-remapping-alist') |
| 580 | now support filters, allowing faces to vary between windows display | 585 | now support filters, allowing faces to vary between windows display |
| 581 | the same buffer. | 586 | the same buffer. |
diff --git a/lisp/frame.el b/lisp/frame.el index 359c5036557..c3daff44406 100644 --- a/lisp/frame.el +++ b/lisp/frame.el | |||
| @@ -129,7 +129,7 @@ appended when the minibuffer frame is created." | |||
| 129 | ;; Gildea@x.org says it is ok to ask questions before terminating. | 129 | ;; Gildea@x.org says it is ok to ask questions before terminating. |
| 130 | (save-buffers-kill-emacs)))) | 130 | (save-buffers-kill-emacs)))) |
| 131 | 131 | ||
| 132 | (defun handle-focus-in (_event) | 132 | (defun handle-focus-in (&optional _event) |
| 133 | "Handle a focus-in event. | 133 | "Handle a focus-in event. |
| 134 | Focus-in events are usually bound to this function. | 134 | Focus-in events are usually bound to this function. |
| 135 | Focus-in events occur when a frame has focus, but a switch-frame event | 135 | Focus-in events occur when a frame has focus, but a switch-frame event |
| @@ -138,7 +138,7 @@ This function runs the hook `focus-in-hook'." | |||
| 138 | (interactive "e") | 138 | (interactive "e") |
| 139 | (run-hooks 'focus-in-hook)) | 139 | (run-hooks 'focus-in-hook)) |
| 140 | 140 | ||
| 141 | (defun handle-focus-out (_event) | 141 | (defun handle-focus-out (&optional _event) |
| 142 | "Handle a focus-out event. | 142 | "Handle a focus-out event. |
| 143 | Focus-out events are usually bound to this function. | 143 | Focus-out events are usually bound to this function. |
| 144 | Focus-out events occur when no frame has focus. | 144 | Focus-out events occur when no frame has focus. |
| @@ -2339,7 +2339,8 @@ frame receives focus." | |||
| 2339 | This is done when a frame gets focus. Blink timers may be stopped by | 2339 | This is done when a frame gets focus. Blink timers may be stopped by |
| 2340 | `blink-cursor-suspend'." | 2340 | `blink-cursor-suspend'." |
| 2341 | (when (and blink-cursor-mode | 2341 | (when (and blink-cursor-mode |
| 2342 | (not blink-cursor-idle-timer)) | 2342 | (not blink-cursor-idle-timer) |
| 2343 | (display-graphic-p)) | ||
| 2343 | (remove-hook 'post-command-hook 'blink-cursor-check) | 2344 | (remove-hook 'post-command-hook 'blink-cursor-check) |
| 2344 | (blink-cursor--start-idle-timer))) | 2345 | (blink-cursor--start-idle-timer))) |
| 2345 | 2346 | ||
diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el index fea9851d720..6410a4b83c9 100644 --- a/lisp/term/xterm.el +++ b/lisp/term/xterm.el | |||
| @@ -104,6 +104,16 @@ Return the pasted text as a string." | |||
| 104 | 104 | ||
| 105 | (define-key global-map [xterm-paste] #'xterm-paste) | 105 | (define-key global-map [xterm-paste] #'xterm-paste) |
| 106 | 106 | ||
| 107 | (defun xterm-handle-focus-in () | ||
| 108 | (interactive) | ||
| 109 | (handle-focus-in)) | ||
| 110 | (define-key global-map [xterm-focus-in] #'xterm-handle-focus-in) | ||
| 111 | |||
| 112 | (defun xterm-handle-focus-out () | ||
| 113 | (interactive) | ||
| 114 | (handle-focus-out)) | ||
| 115 | (define-key global-map [xterm-focus-out] #'xterm-handle-focus-out) | ||
| 116 | |||
| 107 | (defvar xterm-rxvt-function-map | 117 | (defvar xterm-rxvt-function-map |
| 108 | (let ((map (make-sparse-keymap))) | 118 | (let ((map (make-sparse-keymap))) |
| 109 | (define-key map "\e[2~" [insert]) | 119 | (define-key map "\e[2~" [insert]) |
| @@ -136,6 +146,9 @@ Return the pasted text as a string." | |||
| 136 | ;; internally recognizes the end. | 146 | ;; internally recognizes the end. |
| 137 | (define-key map "\e[200~" [xterm-paste]) | 147 | (define-key map "\e[200~" [xterm-paste]) |
| 138 | 148 | ||
| 149 | (define-key map "\e[I" [xterm-focus-in]) | ||
| 150 | (define-key map "\e[O" [xterm-focus-out]) | ||
| 151 | |||
| 139 | map) | 152 | map) |
| 140 | "Keymap of escape sequences, shared between xterm and rxvt support.") | 153 | "Keymap of escape sequences, shared between xterm and rxvt support.") |
| 141 | 154 | ||
| @@ -817,6 +830,8 @@ We run the first FUNCTION whose STRING matches the input events." | |||
| 817 | ;; Unconditionally enable bracketed paste mode: terminals that don't | 830 | ;; Unconditionally enable bracketed paste mode: terminals that don't |
| 818 | ;; support it just ignore the sequence. | 831 | ;; support it just ignore the sequence. |
| 819 | (xterm--init-bracketed-paste-mode) | 832 | (xterm--init-bracketed-paste-mode) |
| 833 | ;; We likewise unconditionally enable support for focus tracking. | ||
| 834 | (xterm--init-focus-tracking) | ||
| 820 | 835 | ||
| 821 | (run-hooks 'terminal-init-xterm-hook)) | 836 | (run-hooks 'terminal-init-xterm-hook)) |
| 822 | 837 | ||
| @@ -832,6 +847,12 @@ We run the first FUNCTION whose STRING matches the input events." | |||
| 832 | (push "\e[?2004l" (terminal-parameter nil 'tty-mode-reset-strings)) | 847 | (push "\e[?2004l" (terminal-parameter nil 'tty-mode-reset-strings)) |
| 833 | (push "\e[?2004h" (terminal-parameter nil 'tty-mode-set-strings))) | 848 | (push "\e[?2004h" (terminal-parameter nil 'tty-mode-set-strings))) |
| 834 | 849 | ||
| 850 | (defun xterm--init-focus-tracking () | ||
| 851 | "Terminal initialization for focus tracking mode." | ||
| 852 | (send-string-to-terminal "\e[?1004h") | ||
| 853 | (push "\e[?1004l" (terminal-parameter nil 'tty-mode-reset-strings)) | ||
| 854 | (push "\e[?1004h" (terminal-parameter nil 'tty-mode-set-strings))) | ||
| 855 | |||
| 835 | (defun xterm--init-activate-get-selection () | 856 | (defun xterm--init-activate-get-selection () |
| 836 | "Terminal initialization for `gui-get-selection'." | 857 | "Terminal initialization for `gui-get-selection'." |
| 837 | (set-terminal-parameter nil 'xterm--get-selection t)) | 858 | (set-terminal-parameter nil 'xterm--get-selection t)) |