Function: touch-screen-handle-point-up

touch-screen-handle-point-up is a byte-compiled function defined in touch-screen.el.gz.

Signature

(touch-screen-handle-point-up POINT PREFIX CANCELED)

Documentation

Notice that POINT has been removed from the screen.

POINT should be the point currently tracked as touch-screen-current-tool. PREFIX should be a virtual function key used to look up key bindings. CANCELED should indicate whether the touch point was removed by window-system intervention rather than user action.

If an ancillary touch point is being observed, transfer touch information from touch-screen-aux-tool to touch-screen-current-tool and set the former to nil, thereby resuming gesture recognition with that tool replacing the tool removed.

Otherwise:

If the fourth element of touch-screen-current-tool is nil or restart-drag, move point to the position of POINT, selecting the window under POINT as well, and deactivate the mark; if there is a button or link at POINT, call the command bound to mouse-2 there. Otherwise, call the command bound to mouse-1.

If the fourth element of touch-screen-current-tool is mouse-drag, then generate either a mouse-1 or a drag-mouse-1 event depending on how far the position of POINT is from the starting point of the touch.

If the fourth element of touch-screen-current-tool is mouse-1-menu, then generate a down-mouse-1 event at the original position of the tool to display its bound keymap as a menu.

If the fourth element of touch-screen-current-tool is drag or held, the region is active, and the tool's initial window's selected buffer isn't read-only, display the on screen keyboard.

If the command being executed is listed in touch-screen-set-point-commands also display the on-screen keyboard if the current buffer and the character at the new point is not read-only.

Source Code

;; Defined in /usr/src/emacs/lisp/touch-screen.el.gz
(defun touch-screen-handle-point-up (point prefix canceled)
  "Notice that POINT has been removed from the screen.
POINT should be the point currently tracked as
`touch-screen-current-tool'.
PREFIX should be a virtual function key used to look up key
bindings.
CANCELED should indicate whether the touch point was removed by
window-system intervention rather than user action.

If an ancillary touch point is being observed, transfer touch
information from `touch-screen-aux-tool' to
`touch-screen-current-tool' and set the former to nil, thereby
resuming gesture recognition with that tool replacing the tool
removed.

Otherwise:

If the fourth element of `touch-screen-current-tool' is nil or
`restart-drag', move point to the position of POINT, selecting
the window under POINT as well, and deactivate the mark; if there
is a button or link at POINT, call the command bound to `mouse-2'
there.  Otherwise, call the command bound to `mouse-1'.

If the fourth element of `touch-screen-current-tool' is
`mouse-drag', then generate either a `mouse-1' or a
`drag-mouse-1' event depending on how far the position of POINT
is from the starting point of the touch.

If the fourth element of `touch-screen-current-tool' is
`mouse-1-menu', then generate a `down-mouse-1' event at the
original position of the tool to display its bound keymap as a
menu.

If the fourth element of `touch-screen-current-tool' is `drag' or
`held', the region is active, and the tool's initial window's
selected buffer isn't read-only, display the on screen keyboard.

If the command being executed is listed in
`touch-screen-set-point-commands' also display the on-screen
keyboard if the current buffer and the character at the new point
is not read-only."
  (if touch-screen-aux-tool
      (progn
        (let ((point-no (aref touch-screen-aux-tool 0))
              (relative-xy (aref touch-screen-aux-tool 3)))
          ;; Replace the current position of touch-screen-current-tool
          ;; with relative-xy and its number with point-no, but leave
          ;; other information (such as its starting position) intact:
          ;; this touchpoint is meant to continue the gesture
          ;; interrupted by the removal of the last, not to commence a
          ;; new one.
          (setcar touch-screen-current-tool point-no)
          (setcar (nthcdr 2 touch-screen-current-tool)
                  relative-xy)
          (setcar (nthcdr 9 touch-screen-current-tool)
                  relative-xy))
        (setq touch-screen-aux-tool nil))
    (let ((what (nth 3 touch-screen-current-tool))
          (posn (cdr point)) window point)
      (cond ((or (null what)
                 ;; If dragging has been restarted but the touch point
                 ;; hasn't been moved, translate the sequence into a
                 ;; regular mouse click.
                 (eq what 'restart-drag))
             ;; Don't attempt to execute commands bound to mouse events
             ;; if the touch sequence has been canceled.
             (unless canceled
               (when (windowp (posn-window posn))
                 (setq point (posn-point posn)
                       window (posn-window posn))
                 ;; Select the window that was tapped given that it
                 ;; isn't an inactive minibuffer window.
                 (when (or (not (eq window
                                    (minibuffer-window
                                     (window-frame window))))
                           (minibuffer-window-active-p window))
                   (select-window window))
                 ;; Now simulate a mouse click there.  If there is a
                 ;; link or a button, use mouse-2 to push it.
                 (let* ((event (list (if (or (mouse-on-link-p posn)
                                             (and point
                                                  (get-char-property
                                                   point 'button)))
                                         'mouse-2
                                       'mouse-1)
                                     posn))
                        ;; Look for the command bound to this event.
                        (command (key-binding (if prefix
                                                  (vector prefix
                                                          (car event))
                                                (vector (car event)))
                                              t nil posn)))
                   (deactivate-mark)
                   (when point
                     ;; This is necessary for following links.
                     (goto-char point))
                   ;; Figure out if the on screen keyboard needs to be
                   ;; displayed.
                   (when command
                     (if (or (memq command touch-screen-set-point-commands)
                             ;; Users of packages that redefine
                             ;; `mouse-set-point', or other commands
                             ;; recognized as defining the point, should
                             ;; not find the on screen keyboard
                             ;; inaccessible even with
                             ;; `touch-screen-display-keyboard' enabled.
                             touch-screen-display-keyboard)
                         (if touch-screen-translate-prompt
                             ;; Forgo displaying the virtual keyboard
                             ;; should `touch-screen-translate-prompt' be
                             ;; set, for then the key won't be delivered
                             ;; to the command loop, but rather to a
                             ;; caller of `read-key-sequence' such as
                             ;; `describe-key'.
                             (throw 'input-event event)
                           (if (or touch-screen-display-keyboard
                                   (and (or (not buffer-read-only)
                                            inhibit-read-only
                                            ;; Display the on screen
                                            ;; keyboard even if just the
                                            ;; text under point is not
                                            ;; read-only.
                                            (get-text-property
                                             point 'inhibit-read-only))
                                        ;; If the major mode has defined
                                        ;; bespoke criteria for
                                        ;; displaying the on screen
                                        ;; keyboard, consult it here.
                                        (or (not touch-screen-keyboard-function)
                                            (funcall
                                             touch-screen-keyboard-function))))
                               ;; Once the on-screen keyboard has been
                               ;; opened, add
                               ;; `touch-screen-window-selection-changed'
                               ;; as a window selection change function
                               ;; This then prevents it from being
                               ;; hidden after exiting the minibuffer.
                               (progn
                                 (add-hook
                                  'window-selection-change-functions
                                  #'touch-screen-window-selection-changed)
                                 (frame-toggle-on-screen-keyboard
                                  (selected-frame) nil))
                             ;; Otherwise, hide the on screen keyboard
                             ;; now.
                             (frame-toggle-on-screen-keyboard (selected-frame)
                                                              t))
                           ;; But if it's being called from `describe-key'
                           ;; or some such, return it as a key sequence.
                           (throw 'input-event event)))
                     ;; If not, return the event.
                     (throw 'input-event event))))))
            ((eq what 'mouse-drag)
             ;; Generate a corresponding `mouse-1' event.
             ;; Alternatively, quit if the touch sequence was canceled.
             (if canceled
                 (keyboard-quit)
               (let* ((new-window (posn-window posn))
                      (new-point (posn-point posn))
                      (old-posn (nth 4 touch-screen-current-tool))
                      (old-window (posn-window posn))
                      (old-point (posn-point posn)))
                 (throw 'input-event
                        ;; If the position of the touch point hasn't
                        ;; changed, or it doesn't start or end on a
                        ;; window...
                        (if (and (not old-point) (not new-point))
                            ;; Should old-point and new-point both equal
                            ;; nil, compare the posn areas and nominal
                            ;; column position.  If either are
                            ;; different, generate a drag event.
                            (let ((new-col-row (posn-col-row posn))
                                  (new-area (posn-area posn))
                                  (old-col-row (posn-col-row old-posn))
                                  (old-area (posn-area old-posn)))
                              (if (and (equal new-col-row old-col-row)
                                       (eq new-area old-area))
                                  ;; ... generate a mouse-1 event...
                                  (list 'mouse-1 posn)
                                ;; ... otherwise, generate a
                                ;; drag-mouse-1 event.
                                (list 'drag-mouse-1 old-posn posn)))
                          (if (and (eq new-window old-window)
                                   (eq new-point old-point)
                                   (windowp new-window)
                                   (windowp old-window))
                              ;; ... generate a mouse-1 event...
                              (list 'mouse-1 posn)
                            ;; ... otherwise, generate a drag-mouse-1
                            ;; event.
                            (list 'drag-mouse-1 old-posn posn)))))))
            ((eq what 'mouse-1-menu)
             ;; Generate a `down-mouse-1' event at the position the tap
             ;; took place, unless the touch sequence was canceled.
             (unless canceled
               (throw 'input-event
                      (list 'down-mouse-1
                            (nth 4 touch-screen-current-tool)))))
            ((or (eq what 'drag)
                 ;; Merely initiating a drag is sufficient to select a
                 ;; word if word selection is enabled.
                 (eq what 'held))
             (unless canceled
               ;; Display the on screen keyboard if the region is now
               ;; active.  Check this within the window where the tool
               ;; was first place.
               (setq window (nth 1 touch-screen-current-tool))
               (when window
                 (with-selected-window window
                   (when (and (region-active-p)
                              (not buffer-read-only))
                     ;; Once the on-screen keyboard has been opened, add
                     ;; `touch-screen-window-selection-changed' as a
                     ;; window selection change function.  This then
                     ;; prevents it from being hidden after exiting the
                     ;; minibuffer.
                     (progn
                       (add-hook 'window-selection-change-functions
                                 #'touch-screen-window-selection-changed)
                       (frame-toggle-on-screen-keyboard (selected-frame)
                                                        nil)))))))))))