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
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
\f
;; 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.
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'