emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 0858d10aebe: Prevent touch screen translation from entering inval


From: Po Lu
Subject: master 0858d10aebe: Prevent touch screen translation from entering invalid state
Date: Thu, 23 Nov 2023 21:40:43 -0500 (EST)

branch: master
commit 0858d10aebed44f7d66548d061af03b3cb136d04
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    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.
---
 lisp/subr.el         | 26 +++++++++++++++++---------
 lisp/touch-screen.el | 23 +++++++++++++++++++++--
 2 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index 304b71e6168..7f2dcdc4d90 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -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
diff --git a/lisp/touch-screen.el b/lisp/touch-screen.el
index f6a47e69d81..56adb75cefc 100644
--- a/lisp/touch-screen.el
+++ b/lisp/touch-screen.el
@@ -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]