]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix unrelated help text tooltips if a popup is shown during the delay
authorPo Lu <luangruo@yahoo.com>
Sat, 29 Jan 2022 10:53:28 +0000 (18:53 +0800)
committerPo Lu <luangruo@yahoo.com>
Sat, 29 Jan 2022 10:57:08 +0000 (18:57 +0800)
* doc/lispref/frames.texi (Pop-Up Menus): Document new hook.
* etc/NEWS: Announce `x-pre-popup-menu-hook'.
* lisp/tooltip.el (tooltip-mode): Make sure `tooltip-hide' is
run before any popup menu is displayed to prevent unrelated help
text from obscuring the popup menu if it pops up during the
tooltip delay.
* src/menu.c (x_popup_menu_1): Run said hook right before the
popup menu is displayed.
(syms_of_menu): New hook `x-pre-popup-menu-hook'.

doc/lispref/frames.texi
etc/NEWS
lisp/tooltip.el
src/menu.c

index 2eeb8b7ed74047eda502b465b7dc749409af3e8c..7d3ce9d74e4ae2919a7fb45948ea289ddac653ae 100644 (file)
@@ -3744,6 +3744,13 @@ still use a menu keymap to implement it.  To make the contents vary, add
 a hook function to @code{menu-bar-update-hook} to update the contents of
 the menu keymap as necessary.
 
+@defvar x-pre-popup-menu-hook
+  A normal hook run immediately before a pop-up menu is displayed,
+either directly by calling @code{x-popup-menu}, or through a menu
+keymap.  It won't be called if @code{x-popup-menu} returns for some
+other reason without displaying a pop-up menu.
+@end defvar
+
 @node Dialog Boxes
 @section Dialog Boxes
 @cindex dialog boxes
index 99e253319425f71b656b13363d638a37424829eb..19eee6cf1df19285040f3a77a47910cd745ad1e7 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1085,6 +1085,11 @@ This event is sent when a user performs a pinch gesture on a touchpad,
 which is comprised of placing two fingers on the touchpad and moving
 them towards or away from each other.
 
++++
+** New hook 'x-pre-popup-menu-hook'.
+This hook is run before 'x-popup-menu' is about to display a
+deck-of-cards menu on screen.
+
 ** Text security and suspiciousness
 
 +++
index 9d523e796792fe45a2419b7ef7c0279f00a82c2e..0ee3c38e26d1e993a3eb92d7222d1a72709ef8d8 100644 (file)
@@ -58,9 +58,11 @@ echo area, instead of making a pop-up window."
   (if (and tooltip-mode (fboundp 'x-show-tip))
       (progn
        (add-hook 'pre-command-hook 'tooltip-hide)
-       (add-hook 'tooltip-functions 'tooltip-help-tips))
+       (add-hook 'tooltip-functions 'tooltip-help-tips)
+        (add-hook 'x-pre-popup-menu-hook 'tooltip-hide))
     (unless (and (boundp 'gud-tooltip-mode) gud-tooltip-mode)
-      (remove-hook 'pre-command-hook 'tooltip-hide))
+      (remove-hook 'pre-command-hook 'tooltip-hide)
+      (remove-hook 'x-pre-popup-menu-hook 'tooltip-hide))
     (remove-hook 'tooltip-functions 'tooltip-help-tips))
   (setq show-help-function
        (if tooltip-mode 'tooltip-show-help 'tooltip-show-help-non-mode)))
index 18ecaf0b0bab8f1682b29fc2d832baaa46bc9a83..449f0b44aece8476e033cb752016574751fd0cc7 100644 (file)
@@ -1395,6 +1395,8 @@ x_popup_menu_1 (Lisp_Object position, Lisp_Object menu)
   record_unwind_protect_void (discard_menu_items);
 #endif
 
+  run_hook (Qx_pre_popup_menu_hook);
+
   /* Display them in a menu, but not if F is the initial frame that
      doesn't have its hooks set (e.g., in a batch session), because
      such a frame cannot display menus.  */
@@ -1408,7 +1410,11 @@ x_popup_menu_1 (Lisp_Object position, Lisp_Object menu)
   discard_menu_items ();
 #endif
 
-#ifdef HAVE_NTGUI     /* FIXME: Is it really w32-specific?  --Stef  */
+#ifdef HAVE_NTGUI     /* W32 specific because other terminals clear
+                        the grab inside their `menu_show_hook's if
+                        it's actually required (i.e. there isn't a
+                        way to query the buttons currently held down
+                        after XMenuActivate). */
   if (FRAME_W32_P (f))
     FRAME_DISPLAY_INFO (f)->grabbed = 0;
 #endif
@@ -1602,6 +1608,14 @@ syms_of_menu (void)
   staticpro (&menu_items);
 
   DEFSYM (Qhide, "hide");
+  DEFSYM (Qx_pre_popup_menu_hook, "x-pre-popup-menu-hook");
+
+  DEFVAR_LISP ("x-pre-popup-menu-hook", Vx_pre_popup_menu_hook,
+              doc: /* Hook run before `x-popup-menu' displays a popup menu.
+It is only run before the menu is really going to be displayed.  It
+won't be run if `x-popup-menu' fails or returns for some other reason
+(such as the keymap is invalid).  */);
+  Vx_pre_popup_menu_hook = Qnil;
 
   defsubr (&Sx_popup_menu);
   defsubr (&Sx_popup_dialog);