Fix xt-mouse on terminals that report UTF-8 encoded coordinates

* lisp/xt-mouse.el (xterm-mouse--read-coordinate): Fix conversion
of mouse coordinates in rxvt-unicode.  Patches by Vladimir
Panteleev <git@cy.md> and Jared Finder <jared@finder.org>.
(Bug#61022)
This commit is contained in:
Eli Zaretskii 2023-01-26 10:54:43 +02:00
parent 4bf7cb71ed
commit f8c95d1a76

View file

@ -151,16 +151,22 @@ If `xterm-mouse-utf-8' was non-nil when
`turn-on-xterm-mouse-tracking-on-terminal' was called, reads the `turn-on-xterm-mouse-tracking-on-terminal' was called, reads the
coordinate as an UTF-8 code unit sequence; otherwise, reads a coordinate as an UTF-8 code unit sequence; otherwise, reads a
single byte." single byte."
(let ((previous-keyboard-coding-system (keyboard-coding-system))) (let ((previous-keyboard-coding-system (keyboard-coding-system))
(utf-8-p (terminal-parameter nil 'xterm-mouse-utf-8))
;; Prevent conversions inside 'read-char' due to input method,
;; when we call 'read-char' below with 2nd argument non-nil.
(input-method-function nil))
(unwind-protect (unwind-protect
(progn (progn
(set-keyboard-coding-system (set-keyboard-coding-system (if utf-8-p 'utf-8-unix 'no-conversion))
(if (terminal-parameter nil 'xterm-mouse-utf-8) (read-char nil
'utf-8-unix ;; Force 'read-char' to decode UTF-8 sequences if
'no-conversion)) ;; 'xterm-mouse-utf-8' is non-nil.
;; Wait only a little; we assume that the entire escape sequence utf-8-p
;; has already been sent when this function is called. ;; Wait only a little; we assume that the entire
(read-char nil nil 0.1)) ;; escape sequence has already been sent when
;; this function is called.
0.1))
(set-keyboard-coding-system previous-keyboard-coding-system)))) (set-keyboard-coding-system previous-keyboard-coding-system))))
;; In default mode, each numeric parameter of XTerm's mouse report is ;; In default mode, each numeric parameter of XTerm's mouse report is