Files
emacs/test/lisp/xt-mouse-tests.el
Basil L. Contovounesios d780007283 Add predicate for initial_terminal
This introduces the predicate frame-initial-p, which uses
struct frame.output_method or struct terminal.type to detect
initial_terminal without relying on its name (bug#80629).
For some prior discussion, see:
https://lists.gnu.org/r/emacs-devel/2019-12/msg00480.html
https://lists.gnu.org/r/emacs-devel/2020-01/msg00120.html

* doc/lispref/frames.texi (Frames): Document frame-initial-p.
(Finding All Frames): Fix grammar.
* etc/NEWS (Lisp Changes in Emacs 31.1): Announce frame-initial-p.
* lisp/desktop.el (desktop--check-dont-save):
* lisp/emacs-lisp/debug.el (debug):
* lisp/frameset.el (frameset-restore):
* lisp/menu-bar.el (menu-bar-update-buffers):
* lisp/xt-mouse.el (turn-on-xterm-mouse-tracking-on-terminal):
Use frame-initial-p instead of checking the "initial_terminal" name.
* lisp/emacs-lisp/byte-opt.el: Mark frame-initial-p as error-free.

* src/pgtkterm.c (pgtk_focus_changed): Use IS_DAEMON in place of
Fdaemonp, thus also accepting a named daemon session.
* src/terminal.c (decode_tty_terminal): Clarify commentary.
(Fframe_initial_p): New function.
(syms_of_terminal): Expose it.
(init_initial_terminal): Update commentary now that
menu-bar-update-buffers uses frame-initial-p (bug#53740).

* test/lisp/xt-mouse-tests.el (with-xterm-mouse-mode): Simulate the
lack of an initial terminal by overriding frame-initial-p now
that turn-on-xterm-mouse-tracking-on-terminal uses it.
* test/src/terminal-tests.el: New file.
2026-03-26 15:19:56 +01:00

117 lines
4.8 KiB
EmacsLisp

;;; xt-mouse-tests.el --- Test suite for xt-mouse. -*- lexical-binding: t; -*-
;; Copyright (C) 2016-2026 Free Software Foundation, Inc.
;; Author: Philipp Stephani <phst@google.com>
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 'xt-mouse)
;; FIXME: this doesn't work when called inside a non-batch mode Emacs
;; session.
(defmacro with-xterm-mouse-mode (&rest body)
"Run BODY with `xterm-mouse-mode' temporarily enabled."
(declare (indent 0))
(when noninteractive
`(let ((width (frame-width))
(height (frame-height)))
(unwind-protect
(progn
;; Make the frame huge so that the test input events below
;; don't hit the menu bar.
(set-frame-width nil (max width 2000))
(set-frame-height nil (max height 2000))
(cl-letf (;; Reset XTerm parameters so that the tests don't
;; get confused.
((terminal-parameter nil 'xterm-mouse-x) nil)
((terminal-parameter nil 'xterm-mouse-y) nil)
((terminal-parameter nil 'xterm-mouse-last-down) nil)
((terminal-parameter nil 'xterm-mouse-last-click) nil))
(unwind-protect
(progn
;; `xterm-mouse-mode' doesn't work in the initial
;; terminal. Since we can't create a second
;; terminal in batch mode, fake it temporarily.
(cl-letf (((symbol-function 'frame-initial-p) #'ignore))
(xterm-mouse-mode 1))
,@body)
(xterm-mouse-mode 0))))
(set-frame-width nil width)
(set-frame-height nil height)))))
(ert-deftest xt-mouse-tracking-basic ()
(should (equal (xterm-mouse-tracking-enable-sequence)
"\e[?1000h\e[?1003h\e[?1006h"))
(should (equal (xterm-mouse-tracking-disable-sequence)
"\e[?1006l\e[?1003l\e[?1000l"))
(with-xterm-mouse-mode
(should xterm-mouse-mode)
(should (terminal-parameter nil 'xterm-mouse-mode))
(should-not (terminal-parameter nil 'xterm-mouse-utf-8))
(let* ((unread-command-events (append "\e[M%\xD9\x81"
"\e[M'\xD9\x81" nil))
(key (read-key)))
(should (consp key))
(cl-destructuring-bind (event-type position . rest) key
(should (equal event-type 'S-mouse-2))
(should (consp position))
(cl-destructuring-bind (_ _ xy . rest) position
(should (equal xy '(184 . 95))))))))
(ert-deftest xt-mouse-tracking-utf-8 ()
(let ((xterm-mouse-utf-8 t))
(should (equal (xterm-mouse-tracking-enable-sequence)
"\e[?1000h\e[?1003h\e[?1005h\e[?1006h"))
(should (equal (xterm-mouse-tracking-disable-sequence)
"\e[?1006l\e[?1005l\e[?1003l\e[?1000l"))
(with-xterm-mouse-mode
(should xterm-mouse-mode)
(should (terminal-parameter nil 'xterm-mouse-mode))
(should (terminal-parameter nil 'xterm-mouse-utf-8))
;; The keyboard driver doesn't decode bytes in
;; `unread-command-events'.
(let* ((unread-command-events (append "\e[M%\u0640\u0131"
"\e[M'\u0640\u0131" nil))
(key (read-key)))
(should (consp key))
(cl-destructuring-bind (event-type position . rest) key
(should (equal event-type 'S-mouse-2))
(should (consp position))
(cl-destructuring-bind (_ _ xy . rest) position
(should (equal xy '(1567 . 271)))))))))
(ert-deftest xt-mouse-tracking-sgr ()
(with-xterm-mouse-mode
(should xterm-mouse-mode)
(should (terminal-parameter nil 'xterm-mouse-mode))
(should-not (terminal-parameter nil 'xterm-mouse-utf-8))
(let* ((unread-command-events (append "\e[<5;1569;273;M"
"\e[<5;1569;273;m" nil))
(key (read-key)))
(should (consp key))
(cl-destructuring-bind (event-type position . rest) key
(should (equal event-type 'S-mouse-2))
(should (consp position))
(cl-destructuring-bind (_ _ xy . rest) position
(should (equal xy '(1568 . 271))))))))
;;; xt-mouse-tests.el ends here