1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-21 06:55:39 +00:00

Enable canceling tap gestures

* doc/lispref/commands.texi (Touchscreen Events): Relate new
THRESHOLD argument to touch-screen-track-tap.

* lisp/button.el (push-button):

* lisp/wid-edit.el (widget-button--check-and-call-button):
Provide a threshold to enable canceling button presses.

* lisp/touch-screen.el (touch-screen-track-tap): Enable
canceling tap gestures and resuming touch sequence translation
if the touch point exceeds a set threshold.
This commit is contained in:
Po Lu 2023-11-11 18:03:33 +08:00
parent f2b162f8ee
commit 68b8df57c7
4 changed files with 45 additions and 8 deletions

View File

@ -2207,7 +2207,7 @@ below is from commands bound directly to @code{touchscreen-begin}
events; they allow responding to commonly used touch screen gestures
separately from mouse event translation.
@defun touch-screen-track-tap event &optional update data
@defun touch-screen-track-tap event &optional update data threshold
This function is used to track a single ``tap'' gesture originating
from the @code{touchscreen-begin} event @var{event}, often used to
set the point or to activate a button. It waits for a
@ -2220,6 +2220,14 @@ contains at least one touchpoint with the same identifier as in
the list of touchpoints in that @code{touchscreen-update} event, and
@var{data}.
If @var{threshold} is non-@code{nil} and such an event indicates that
the touchpoint represented by @var{event} has moved beyond a threshold
of either @var{threshold} or 10 pixels if it is not a number from the
position of @var{event}, @code{nil} is returned and mouse event
translation is resumed for that touchpoint, so as not to impede the
recognition of any subsequent touchscreen gesture arising from its
sequence.
If any other event arrives in the mean time, @code{nil} is returned.
The caller should not perform any action in that case.
@end defun

View File

@ -495,7 +495,7 @@ pushing a button, use the `button-describe' command."
(if (eq (car-safe pos) 'touchscreen-down)
;; If touch-screen-track tap returns nil, then the
;; tap was cancelled.
(when (touch-screen-track-tap pos)
(when (touch-screen-track-tap pos nil nil t)
(push-button (posn-point posn) t))
(push-button (posn-point posn) t))))))
;; POS is just normal position

View File

@ -1539,7 +1539,7 @@ if POSN is on a link or a button, or `mouse-1' otherwise."
;; Exports. These functions are intended for use externally.
(defun touch-screen-track-tap (event &optional update data)
(defun touch-screen-track-tap (event &optional update data threshold)
"Track a single tap starting from EVENT.
EVENT should be a `touchscreen-begin' event.
@ -1549,16 +1549,45 @@ a `touchscreen-update' event is received in the mean time and
contains a touch point with the same ID as in EVENT, call UPDATE
with that event and DATA.
If THRESHOLD is non-nil, enforce a threshold of movement that is
either itself or 10 pixels when it is not a number. If the touch
point moves beyond that threshold EVENT on any axis, return nil
immediately, and further resume mouse event translation for the
touch point at hand.
Return nil immediately if any other kind of event is received;
otherwise, return t once the `touchscreen-end' event arrives."
(let ((disable-inhibit-text-conversion t))
(let ((disable-inhibit-text-conversion t)
(threshold (and threshold (or (and (numberp threshold)
threshold)
10)))
(original-x-y (posn-x-y (cdadr event)))
(original-window (posn-window (cdadr event))))
(catch 'finish
(while t
(let ((new-event (read-event nil)))
(let ((new-event (read-event nil))
touch-point)
(cond
((eq (car-safe new-event) 'touchscreen-update)
(when (and update (assq (caadr event) (cadr new-event)))
(funcall update new-event data)))
(when (setq touch-point (assq (caadr event) (cadr new-event)))
(when update
(funcall update new-event data))
(when threshold
(setq touch-point (cdr touch-point))
;; Detect the touch point moving past the threshold.
(let* ((x-y (touch-screen-relative-xy touch-point
original-window))
(x (car x-y)) (y (cdr x-y)))
(when (or (> (abs (- x (car original-x-y))) threshold)
(> (abs (- y (cdr original-x-y))) threshold))
;; Resume normal touch-screen to mouse event
;; translation for this touch sequence by
;; supplying both the event starting it and the
;; motion event that overstepped the threshold to
;; touch-screen-handle-touch.
(touch-screen-handle-touch event nil t)
(touch-screen-handle-touch new-event nil t)
(throw 'finish nil))))))
((eq (car-safe new-event) 'touchscreen-end)
(throw 'finish
;; Now determine whether or not the `touchscreen-end'

View File

@ -1127,7 +1127,7 @@ If nothing was called, return non-nil."
;; This a touchscreen event and must be handled
;; specially through `touch-screen-track-tap'.
(progn
(unless (touch-screen-track-tap event)
(unless (touch-screen-track-tap event nil nil t)
(throw 'button-press-cancelled t)))
(unless (widget-apply button :mouse-down-action event)
(let ((track-mouse t))