From 1eac5f56e42e535710ebba0cdc62bfbe12760af7 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Wed, 1 May 2024 15:57:29 +0800 Subject: [PATCH] Disable on-screen keyboard outside fields in Custom buffers * lisp/cus-edit.el (Custom-display-on-screen-keyboard-p): New function. (Custom-mode): Install it as the touch-screen-keyboard-function. * lisp/touch-screen.el (touch-screen-keyboard-function): New variable. (touch-screen-handle-point-up): Don't special-case the splash screen with respect to touch-screen-display-keyboard in keeping with user feedback. (cherry picked from commit 54dbd8b4fa2253682d044cc53bd658e361bff8a0) --- lisp/cus-edit.el | 8 ++++++++ lisp/touch-screen.el | 39 +++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el index 4fff34e6130..32cfef6bae4 100644 --- a/lisp/cus-edit.el +++ b/lisp/cus-edit.el @@ -5388,6 +5388,12 @@ If several parents are listed, go to the first of them." (setq-local widget-link-suffix "")) (setq show-trailing-whitespace nil)) +(defvar touch-screen-keyboard-function) ; In touch-screen.el. + +(defun Custom-display-on-screen-keyboard-p () + "Return whether it is okay to display the virtual keyboard at point." + (get-char-property (point) 'field)) + (define-derived-mode Custom-mode nil "Custom" "Major mode for editing customization buffers. @@ -5426,6 +5432,8 @@ if that value is non-nil." custom--hidden-state 'hidden) (setq-local revert-buffer-function #'custom--revert-buffer) (setq-local text-conversion-style 'action) + (setq-local touch-screen-keyboard-function + #'Custom-display-on-screen-keyboard-p) (make-local-variable 'custom-options) (make-local-variable 'custom-local-buffer) (custom--initialize-widget-variables) diff --git a/lisp/touch-screen.el b/lisp/touch-screen.el index e44b266a617..ca02ca3caf6 100644 --- a/lisp/touch-screen.el +++ b/lisp/touch-screen.el @@ -154,6 +154,17 @@ selected.") Used in an attempt to keep this word selected during later dragging.") +;; Should this variable be documented? +(defvar-local touch-screen-keyboard-function nil + "Function that decides whether to display the on screen keyboard. +If set, this function is called with point set to the position of the +tap involved when a command listed in `touch-screen-set-point-commands' +is about to be invoked in response to a tap, the current buffer, or the +text beneath point (in the case of an `inhibit-read-only' text +property), is not read only, and `touch-screen-display-keyboard' is nil, +and should return non-nil if it is appropriate to display the on-screen +keyboard afterwards.") + ;;; Scroll gesture. @@ -1374,18 +1385,22 @@ is not read-only." ;; caller of `read-key-sequence' such as ;; `describe-key'. (throw 'input-event event) - (if (and (or (not buffer-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) - touch-screen-display-keyboard) - ;; Detect the splash screen and - ;; avoid displaying the on screen - ;; keyboard there. - (not (equal (buffer-name) "*GNU Emacs*"))) + (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' -- 2.39.5