Prevent touch screen translation from entering invalid state

* lisp/subr.el (touch-screen-events-received): New variable.
(read--potential-mouse-event): If a touch screen event's been
registered thus far, continue as though xterm-mouse-mode is
enabled.

* lisp/touch-screen.el (touch-screen-handle-touch): Set that
variable.  If t-s-c-t already exists but the new touch point was
assigned the same number by the system, replace the current tool
with it rather than installing it as the anciliary tool.
This commit is contained in:
Po Lu 2023-11-24 10:39:49 +08:00
parent 354a2958f9
commit 0858d10aeb
2 changed files with 38 additions and 11 deletions

View file

@ -3332,22 +3332,30 @@ only unbound fallback disabled is downcasing of the last event."
(message nil)
(use-global-map old-global-map))))
(defvar touch-screen-events-received nil
"Whether a touch screen event has ever been translated.
The value of this variable governs whether
`read--potential-mouse-event' calls read-key or read-event.")
;; FIXME: Once there's a safe way to transition away from read-event,
;; callers to this function should be updated to that way and this
;; function should be deleted.
(defun read--potential-mouse-event ()
"Read an event that might be a mouse event.
"Read an event that might be a mouse event.
This function exists for backward compatibility in code packaged
with Emacs. Do not call it directly in your own packages."
;; `xterm-mouse-mode' events must go through `read-key' as they
;; are decoded via `input-decode-map'.
(if xterm-mouse-mode
(read-key nil
;; Normally `read-key' discards all mouse button
;; down events. However, we want them here.
t)
(read-event)))
;; `xterm-mouse-mode' events must go through `read-key' as they
;; are decoded via `input-decode-map'.
(if (or xterm-mouse-mode
;; If a touch screen is being employed, then mouse events
;; are subject to translation as well.
touch-screen-events-received)
(read-key nil
;; Normally `read-key' discards all mouse button
;; down events. However, we want them here.
t)
(read-event)))
(defvar read-passwd-map
;; BEWARE: `defconst' would purecopy it, breaking the sharing with

View file

@ -1456,8 +1456,15 @@ If INTERACTIVE, execute the command associated with any event
generated instead of throwing `input-event'. Otherwise, throw
`input-event' with a single input event if that event should take
the place of EVENT within the key sequence being translated, or
`nil' if all tools have been released."
`nil' if all tools have been released.
Set `touch-screen-events-received' to `t' to indicate that touch
screen events have been received, and thus by extension require
functions undertaking event management themselves to call
`read-key' rather than `read-event'."
(interactive "e\ni\np")
(unless touch-screen-events-received
(setq touch-screen-events-received t))
(if interactive
;; Called interactively (probably from wid-edit.el.)
;; Add any event generated to `unread-command-events'.
@ -1484,7 +1491,19 @@ the place of EVENT within the key sequence being translated, or
(cancel-timer touch-screen-current-timer)
(setq touch-screen-current-timer nil))
;; If a tool already exists...
(if touch-screen-current-tool
(if (and touch-screen-current-tool
;; ..and the number of this tool is at variance with
;; that of the current tool: if a `touchscreen-end'
;; event is delivered that is somehow withheld from
;; this function and the system does not assign
;; monotonically increasing touch point identifiers,
;; then the ancillary tool will be set to a tool
;; bearing the same number as the current tool, and
;; consequently the mechanism for detecting
;; erroneously retained touch points upon the
;; registration of `touchscreen-update' events will
;; not be activated.
(not (eq touchpoint (car touch-screen-current-tool))))
;; Then record this tool as the ``auxiliary tool''.
;; Updates to the auxiliary tool are considered in unison
;; with those to the current tool; the distance between