aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPo Lu2023-05-19 14:50:10 +0800
committerPo Lu2023-05-19 14:50:10 +0800
commit6d3cc725cd869a46678e5509d11cfa61bbcd8f48 (patch)
tree38dac3d5bc2ad054eb40267e617e46a4c0fd3b08
parent2e644fc13cc46edb99424223bd9dd6da57d710ce (diff)
downloademacs-6d3cc725cd869a46678e5509d11cfa61bbcd8f48.tar.gz
emacs-6d3cc725cd869a46678e5509d11cfa61bbcd8f48.zip
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'.
-rw-r--r--lisp/touch-screen.el52
1 files changed, 52 insertions, 0 deletions
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."
662(global-set-key [bottom-divider touchscreen-begin] 662(global-set-key [bottom-divider touchscreen-begin]
663 #'touch-screen-drag-mode-line) 663 #'touch-screen-drag-mode-line)
664 664
665
666
667;; Header line tapping.
668
669(defun touch-screen-tap-header-line (event)
670 "Handle a `touchscreen-begin' EVENT on the header line.
671Wait for the tap to complete, then run any command bound to
672`mouse-1' at the position of EVENT.
673
674If another keymap is bound to `down-mouse-1', then display a menu
675with its contents instead, and run the selected command."
676 (interactive "e")
677 (let* ((posn (cdadr event))
678 (object (posn-object posn))
679 ;; Look for the keymap defined by the object itself.
680 (object-keymap (and (consp object)
681 (stringp (car object))
682 (or (get-text-property (cdr object)
683 'keymap
684 (car object))
685 (get-text-property (cdr object)
686 'local-map
687 (car object)))))
688 command keymap)
689 ;; Now look for either a command bound to `mouse-1' or a keymap
690 ;; bound to `down-mouse-1'.
691 (with-selected-window (posn-window posn)
692 (setq command (lookup-key object-keymap
693 [header-line mouse-1] t)
694 keymap (lookup-key object-keymap
695 [header-line down-mouse-1] t))
696 (unless (keymapp keymap)
697 (setq keymap nil)))
698 ;; Wait for the tap to complete.
699 (when (touch-screen-track-tap event)
700 ;; Select the window whose header line was clicked.
701 (with-selected-window (posn-window posn)
702 (if keymap
703 (when-let* ((command (x-popup-menu event keymap))
704 (tem (lookup-key keymap
705 (if (consp command)
706 (apply #'vector command)
707 (vector command))
708 t)))
709 (call-interactively tem))
710 (when (commandp command)
711 (call-interactively command nil
712 (vector (list 'mouse-1 (cdadr event))))))))))
713
714(global-set-key [header-line touchscreen-begin]
715 #'touch-screen-tap-header-line)
716
665(provide 'touch-screen) 717(provide 'touch-screen)
666 718
667;;; touch-screen ends here 719;;; touch-screen ends here