aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorPo Lu2023-05-16 15:54:50 +0800
committerPo Lu2023-05-16 15:54:50 +0800
commitbb8bf9203ed33de0bb269c8ff69067aa7b3a692a (patch)
tree9aeb35760a2997f734b3f706048e381300b514c1 /lisp
parent44da7d75ed3fa6322d64d66d250bc78e91636ff5 (diff)
downloademacs-bb8bf9203ed33de0bb269c8ff69067aa7b3a692a.tar.gz
emacs-bb8bf9203ed33de0bb269c8ff69067aa7b3a692a.zip
Add touchscreen support to the tab bar
* lisp/menu-bar.el (popup-menu-normalize-position): Normalize `touchscreen-begin' events correctly. * lisp/tab-bar.el (tab-bar-mouse-context-menu): New argument POSN. Use it if specified. (touch-screen-track-tap, tab-bar-handle-timeout) (tab-bar-touchscreen-begin): New functions. (tab-bar-map): Bind [tab-bar touchscreen-begin]. * lisp/touch-screen.el (touch-screen-track-drag): Fix doc string. * src/dispextern.h: Export `get_tab_bar_item_kbd'. * src/keyboard.c (coords_in_tab_bar_window): New function. (make_lispy_event): Adjust touchscreen begin event mouse position list for tab bar. * src/xdisp.c (tab_bar_item_info): Allow CLOSE_P to be NULL. (get_tab_bar_item): Adjust doc string. (get_tab_bar_item_kbd): New function.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/menu-bar.el15
-rw-r--r--lisp/tab-bar.el83
-rw-r--r--lisp/touch-screen.el2
3 files changed, 90 insertions, 10 deletions
diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el
index 949d805465d..da002a46621 100644
--- a/lisp/menu-bar.el
+++ b/lisp/menu-bar.el
@@ -2669,20 +2669,25 @@ FROM-MENU-BAR, if non-nil, means we are dropping one of menu-bar's menus."
2669POSITION can be an event, a posn- value, a value having the 2669POSITION can be an event, a posn- value, a value having the
2670form ((XOFFSET YOFFSET) WINDOW), or nil. 2670form ((XOFFSET YOFFSET) WINDOW), or nil.
2671If nil, the current mouse position is used, or nil if there is no mouse." 2671If nil, the current mouse position is used, or nil if there is no mouse."
2672 (pcase position 2672 (cond
2673 ;; nil -> mouse cursor position 2673 ;; nil -> mouse cursor position
2674 ('nil 2674 ((eq position nil)
2675 (let ((mp (mouse-pixel-position))) 2675 (let ((mp (mouse-pixel-position)))
2676 (list (list (cadr mp) (cddr mp)) (car mp)))) 2676 (list (list (cadr mp) (cddr mp)) (car mp))))
2677 ;; Value returned from `event-end' or `posn-at-point'. 2677 ;; Value returned from `event-end' or `posn-at-point'.
2678 ((pred posnp) 2678 ((posnp position)
2679 (let ((xy (posn-x-y position))) 2679 (let ((xy (posn-x-y position)))
2680 (list (list (car xy) (cdr xy)) 2680 (list (list (car xy) (cdr xy))
2681 (posn-window position)))) 2681 (posn-window position))))
2682 ;; `touchscreen-begin' or `touchscreen-end' event.
2683 ((or (eq (car-safe position) 'touchscreen-begin)
2684 (eq (car-safe position) 'touchscreen-end))
2685 position)
2682 ;; Event. 2686 ;; Event.
2683 ((pred eventp) 2687 ((eventp position)
2684 (popup-menu-normalize-position (event-end position))) 2688 (popup-menu-normalize-position (event-end position)))
2685 (_ position))) 2689 ;; Some other value.
2690 (t position)))
2686 2691
2687(defcustom tty-menu-open-use-tmm nil 2692(defcustom tty-menu-open-use-tmm nil
2688 "If non-nil, \\[menu-bar-open] on a TTY will invoke `tmm-menubar'. 2693 "If non-nil, \\[menu-bar-open] on a TTY will invoke `tmm-menubar'.
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 9d703b5d048..1a33eda0866 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -341,10 +341,12 @@ only when you click on its \"x\" close button."
341 (unless (eq tab-number t) 341 (unless (eq tab-number t)
342 (tab-bar-close-tab tab-number)))) 342 (tab-bar-close-tab tab-number))))
343 343
344(defun tab-bar-mouse-context-menu (event) 344(defun tab-bar-mouse-context-menu (event &optional posn)
345 "Pop up the context menu for the tab on which you click." 345 "Pop up the context menu for the tab on which you click.
346EVENT is a mouse or touch screen event. POSN is nil or the
347position of EVENT."
346 (interactive "e") 348 (interactive "e")
347 (let* ((item (tab-bar--event-to-item (event-start event))) 349 (let* ((item (tab-bar--event-to-item (or posn (event-start event))))
348 (tab-number (tab-bar--key-to-number (nth 0 item))) 350 (tab-number (tab-bar--key-to-number (nth 0 item)))
349 (menu (make-sparse-keymap (propertize "Context Menu" 'hide t)))) 351 (menu (make-sparse-keymap (propertize "Context Menu" 'hide t))))
350 352
@@ -397,6 +399,78 @@ at the mouse-down event to the position at mouse-up event."
397 (tab-bar-move-tab-to 399 (tab-bar-move-tab-to
398 (if (null to) (1+ (tab-bar--current-tab-index)) to) from)))) 400 (if (null to) (1+ (tab-bar--current-tab-index)) to) from))))
399 401
402
403
404;;; Tab bar touchscreen support.
405
406(declare-function touch-screen-track-tap "touch-screen.el")
407
408(defun tab-bar-handle-timeout ()
409 "Handle a touch-screen timeout on the tab bar.
410Beep, then throw to `context-menu' and return."
411 (beep)
412 (throw 'context-menu 'context-menu))
413
414(defun tab-bar-touchscreen-begin (event)
415 "Handle a touchscreen begin EVENT on the tab bar.
416
417Determine where the touch was made. If it was made on a tab
418itself, start a timer set to go off after a certain amount of
419time, and wait for the touch point to be released, and either
420display a context menu or select a tab as appropriate.
421
422Otherwise, if it was made on a button, close or create a tab as
423appropriate."
424 (interactive "e")
425 (let* ((posn (cdadr event))
426 (item (tab-bar--event-to-item posn))
427 (number (tab-bar--key-to-number (car item)))
428 timer)
429 (when (eq (catch 'context-menu
430 (cond ((integerp number)
431 ;; The touch began on a tab. Start a context
432 ;; menu timer and start tracking the tap.
433 (unwind-protect
434 (progn
435 (setq timer (run-at-time touch-screen-delay nil
436 #'tab-bar-handle-timeout))
437 ;; Now wait for the tap to complete.
438 (when (touch-screen-track-tap event)
439 ;; And select the tab, or close it,
440 ;; depending on whether or not the
441 ;; close button was pressed.
442 (if (caddr item)
443 (tab-bar-close-tab number)
444 (tab-bar-select-tab number))))
445 ;; Cancel the timer.
446 (cancel-timer timer)))
447 ((and (memq (car item) '(add-tab history-back
448 history-forward))
449 (functionp (cadr item)))
450 ;; This is some kind of button. Wait for the
451 ;; tap to complete and press it.
452 (when (touch-screen-track-tap event)
453 (call-interactively (cadr item))))
454 (t
455 ;; The touch began on the tab bar itself.
456 ;; Start a context menu timer and start
457 ;; tracking the tap, but don't do anything
458 ;; afterwards.
459 (unwind-protect
460 (progn
461 (setq timer (run-at-time touch-screen-delay nil
462 #'tab-bar-handle-timeout))
463 ;; Now wait for the tap to complete.
464 (touch-screen-track-tap event))
465 ;; Cancel the timer.
466 (cancel-timer timer)))))
467 'context-menu)
468 ;; Display the context menu in response to a time out waiting
469 ;; for the tap to complete.
470 (tab-bar-mouse-context-menu event posn))))
471
472
473
400(defvar-keymap tab-bar-map 474(defvar-keymap tab-bar-map
401 :doc "Keymap for the commands used on the tab bar." 475 :doc "Keymap for the commands used on the tab bar."
402 "<down-mouse-1>" #'tab-bar-mouse-down-1 476 "<down-mouse-1>" #'tab-bar-mouse-down-1
@@ -418,7 +492,8 @@ at the mouse-down event to the position at mouse-up event."
418 "S-<wheel-up>" #'tab-bar-move-tab-backward 492 "S-<wheel-up>" #'tab-bar-move-tab-backward
419 "S-<wheel-down>" #'tab-bar-move-tab 493 "S-<wheel-down>" #'tab-bar-move-tab
420 "S-<wheel-left>" #'tab-bar-move-tab-backward 494 "S-<wheel-left>" #'tab-bar-move-tab-backward
421 "S-<wheel-right>" #'tab-bar-move-tab) 495 "S-<wheel-right>" #'tab-bar-move-tab
496 "<touchscreen-begin>" #'tab-bar-touchscreen-begin)
422 497
423(global-set-key [tab-bar] 498(global-set-key [tab-bar]
424 `(menu-item ,(purecopy "tab bar") ,(make-sparse-keymap) 499 `(menu-item ,(purecopy "tab bar") ,(make-sparse-keymap)
diff --git a/lisp/touch-screen.el b/lisp/touch-screen.el
index 31d46b062ed..a7fa5b4829c 100644
--- a/lisp/touch-screen.el
+++ b/lisp/touch-screen.el
@@ -529,7 +529,7 @@ otherwise, return t once the `touchscreen-end' event arrives."
529 529
530(defun touch-screen-track-drag (event update &optional data) 530(defun touch-screen-track-drag (event update &optional data)
531 "Track a single drag starting from EVENT. 531 "Track a single drag starting from EVENT.
532EVENT should be a `touchscreen-end' event. 532EVENT should be a `touchscreen-begin' event.
533 533
534Read touch screen events until a `touchscreen-end' event is 534Read touch screen events until a `touchscreen-end' event is
535received with the same ID as in EVENT. For each 535received with the same ID as in EVENT. For each