From 25d2215b00c954c0b938a57511ada391c53bcb69 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Sat, 20 Jul 2024 11:28:47 +0800 Subject: [PATCH] Respect mouse-fine-graned-tracking in touch screen simple translation * lisp/touch-screen.el (touch-screen-current-tool): Expand doc string. (touch-screen-handle-point-update): Record extents of glyph beneath the mouse as computed by `remember_mouse_glyph' if necessary, and defer generation of mouse-movement events till the mouse exit it. * src/xdisp.c (Fremember_mouse_glyph): New function. (syms_of_xdisp): Define new subr. (cherry picked from commit 892abde34e052f7a9b1b27fcb27ded13b4ba3c04) --- lisp/touch-screen.el | 80 ++++++++++++++++++++++++++++++++++++++------ src/xdisp.c | 19 +++++++++++ 2 files changed, 88 insertions(+), 11 deletions(-) diff --git a/lisp/touch-screen.el b/lisp/touch-screen.el index f04775b0bc6..ce9a5146bba 100644 --- a/lisp/touch-screen.el +++ b/lisp/touch-screen.el @@ -33,13 +33,35 @@ (defvar touch-screen-current-tool nil "The touch point currently being tracked, or nil. -If non-nil, this is a list of ten elements: the ID of the touch -point being tracked, the window where the touch began, a cons -holding the last registered position of the touch point, relative -to that window, a field used to store data while tracking the -touch point, the initial position of the touchpoint, another four -fields to used store data while tracking the touch point, and the -last known position of the touch point. +If non-nil, this is a list of ten elements, which might be +accessed as follows: + + (nth 0 touch-screen-current-tool) + The ID of the touch point being tracked. + + (nth 1 touch-screen-current-tool) + The window where the touch sequence being monitored commenced. + + (nth 2 touch-screen-current-tool) + A cons holding the last registered position of the touch + point, relative to that window. + + (nth 3 touch-screen-current-tool) + A field holding a symbol identifying the gesture being + observed while tracking the said touch point. + + (nth 4 touch-screen-current-tool) + The initial position of the touchpoint. + + (nth 5 touch-screen-current-tool) + (nth 6 touch-screen-current-tool) + (nth 7 touch-screen-current-tool) + (nth 8 touch-screen-current-tool) + A further four fields to used store data while tracking the + touch point. + + (nth 9 touch-screen-current-tool) + The last known position of the touch point. See `touch-screen-handle-point-update' and `touch-screen-handle-point-up' for the meanings of the fourth @@ -1027,6 +1049,8 @@ When ARG is t, set the fourth element of (let ((posn (nth 4 touch-screen-current-tool))) (throw 'input-event (list 'touchscreen-hold posn)))))) +(declare-function remember-mouse-glyph "xdisp.c") + (defun touch-screen-handle-point-update (point) "Notice that the touch point POINT has changed position. Perform the editing operations or throw to the input translation @@ -1077,8 +1101,7 @@ then move point to the position of POINT." (what (nth 3 touch-screen-current-tool)) (posn (cdr point)) ;; Now get the position of X and Y relative to WINDOW. - (relative-xy - (touch-screen-relative-xy posn window))) + (relative-xy (touch-screen-relative-xy posn window))) ;; Update the 10th field of the tool list with RELATIVE-XY. (setcar (nthcdr 9 touch-screen-current-tool) relative-xy) (cond ((or (null what) @@ -1128,8 +1151,43 @@ then move point to the position of POINT." ;; point of the event. Generate a mouse-motion event if ;; mouse movement is being tracked. (when track-mouse - (throw 'input-event (list 'mouse-movement - (cdr point))))) + (let ((mouse-rect (nth 5 touch-screen-current-tool)) + (edges (window-inside-pixel-edges window))) + ;; If fine-grained tracking is enabled, disregard the + ;; mouse rect. Apply the same criteria as + ;; `remember_mouse_glyph', which see. + (if (or mouse-fine-grained-tracking + window-resize-pixelwise) + (throw 'input-event (list 'mouse-movement posn)) + ;; Otherwise, generate an event only if POINT falls + ;; outside the extents of the mouse rect, and record + ;; the extents of the glyph beneath point as the next + ;; mouse rect. + (let ((point relative-xy) + (frame-offsets (if (framep window) + '(0 . 0) + (cons (car edges) (cadr edges))))) + (when (or (not mouse-rect) + (< (car point) (- (car mouse-rect) + (car frame-offsets))) + (> (car point) (+ (- (car mouse-rect) 1 + (car frame-offsets)) + (caddr mouse-rect))) + (< (cdr point) (- (cadr mouse-rect) + (cdr frame-offsets))) + (> (cdr point) (+ (- (cadr mouse-rect) 1 + (cdr frame-offsets)) + (cadddr mouse-rect)))) + ;; Record the extents of this glyph. + (setcar (nthcdr 5 touch-screen-current-tool) + (remember-mouse-glyph (or (and (framep window) window) + (window-frame window)) + (+ (car point) + (car frame-offsets)) + (+ (cdr point) + (cdr frame-offsets)))) + ;; Generate the movement. + (throw 'input-event (list 'mouse-movement posn)))))))) ((eq what 'held) (let* ((posn (cdr point))) ;; Now start dragging. diff --git a/src/xdisp.c b/src/xdisp.c index 8c7e8e5cb43..74ccfd9e745 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -3006,6 +3006,24 @@ remember_mouse_glyph (struct frame *f, int gx, int gy, NativeRectangle *rect) #endif } +DEFUN ("remember-mouse-glyph", Fremember_mouse_glyph, Sremember_mouse_glyph, + 3, 3, 0, + doc: /* Return the extents of glyph in FRAME for mouse event generation. +Return a rectangle (X Y WIDTH HEIGHT) representing the confines, in +pixel coordinates, of the glyph at X, Y and in FRAME, or, should +`mouse-fine-grained-tracking' or `window-resize-pixelwise` be enabled, +an approximation thereof. All coordinates are relative to the origin +point of FRAME. */) + (Lisp_Object frame, Lisp_Object x, Lisp_Object y) +{ + struct frame *f = decode_window_system_frame (frame); + NativeRectangle r; + + CHECK_FIXNUM (x); + CHECK_FIXNUM (y); + remember_mouse_glyph (f, XFIXNUM (x), XFIXNUM (y), &r); + return list4i (r.x, r.y, r.width, r.height); +} #endif /* HAVE_WINDOW_SYSTEM */ @@ -37263,6 +37281,7 @@ be let-bound around code that needs to disable messages temporarily. */); defsubr (&Strace_to_stderr); #endif #ifdef HAVE_WINDOW_SYSTEM + defsubr (&Sremember_mouse_glyph); defsubr (&Stab_bar_height); defsubr (&Stool_bar_height); defsubr (&Slookup_image_map); -- 2.39.2