emacs-diffs
[Top][All Lists]
Advanced

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

feature/android 6d3cc725cd8: Make tapping on header lines behave reasona


From: Po Lu
Subject: feature/android 6d3cc725cd8: Make tapping on header lines behave reasonably
Date: Fri, 19 May 2023 02:51:16 -0400 (EDT)

branch: feature/android
commit 6d3cc725cd869a46678e5509d11cfa61bbcd8f48
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Make tapping on header lines behave reasonably
    
    * lisp/touch-screen.el (touch-screen-tap-header-line): New
    function.
    ([header-line touchscreen-begin]): Define to
    `touch-screen-tap-header-line'.
---
 lisp/touch-screen.el | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/lisp/touch-screen.el b/lisp/touch-screen.el
index a7fa5b4829c..2db8b62f6f9 100644
--- a/lisp/touch-screen.el
+++ b/lisp/touch-screen.el
@@ -662,6 +662,58 @@ bound, run that command instead."
 (global-set-key [bottom-divider touchscreen-begin]
                 #'touch-screen-drag-mode-line)
 
+
+
+;; Header line tapping.
+
+(defun touch-screen-tap-header-line (event)
+  "Handle a `touchscreen-begin' EVENT on the header line.
+Wait for the tap to complete, then run any command bound to
+`mouse-1' at the position of EVENT.
+
+If another keymap is bound to `down-mouse-1', then display a menu
+with its contents instead, and run the selected command."
+  (interactive "e")
+  (let* ((posn (cdadr event))
+         (object (posn-object posn))
+         ;; Look for the keymap defined by the object itself.
+         (object-keymap (and (consp object)
+                             (stringp (car object))
+                             (or (get-text-property (cdr object)
+                                                    'keymap
+                                                    (car object))
+                                 (get-text-property (cdr object)
+                                                    'local-map
+                                                    (car object)))))
+         command keymap)
+    ;; Now look for either a command bound to `mouse-1' or a keymap
+    ;; bound to `down-mouse-1'.
+    (with-selected-window (posn-window posn)
+      (setq command (lookup-key object-keymap
+                               [header-line mouse-1] t)
+            keymap (lookup-key object-keymap
+                              [header-line down-mouse-1] t))
+      (unless (keymapp keymap)
+       (setq keymap nil)))
+    ;; Wait for the tap to complete.
+    (when (touch-screen-track-tap event)
+      ;; Select the window whose header line was clicked.
+      (with-selected-window (posn-window posn)
+        (if keymap
+            (when-let* ((command (x-popup-menu event keymap))
+                        (tem (lookup-key keymap
+                                         (if (consp command)
+                                             (apply #'vector command)
+                                           (vector command))
+                                         t)))
+              (call-interactively tem))
+          (when (commandp command)
+            (call-interactively command nil
+                                (vector (list 'mouse-1 (cdadr event))))))))))
+
+(global-set-key [header-line touchscreen-begin]
+                #'touch-screen-tap-header-line)
+
 (provide 'touch-screen)
 
 ;;; touch-screen ends here



reply via email to

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