>From d001740b0f59cdc2165d62e05c7f2cb5ff8ab6b4 Mon Sep 17 00:00:00 2001 From: Alexander Gramiak Date: Tue, 3 Oct 2017 17:11:08 -0600 Subject: [PATCH] Allow mouse clicks to be prefix keys (Bug#14793) * src/keyboard.c (read_char): Check used_mouse_menu after calling read_char_x_menu_prompt. (read_char_x_menu_prompt): Pass used_mouse_menu to x_popup_menu and return nil if it wasn't set to true. * src/menu.c (Fx_popup_menu): Extract into a new function. (x_popup_menu): New function. Don't error if used_mouse_menu is null, and set used_mouse_menu if there was no error. * src/keyboard.h: Declare x_popup_menu. --- src/keyboard.c | 21 +++++++++++++-------- src/keyboard.h | 3 +++ src/menu.c | 11 ++++++++++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/keyboard.c b/src/keyboard.c index e8701b8870..5912f89115 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -2682,11 +2682,15 @@ read_char (int commandflag, Lisp_Object map, { c = read_char_x_menu_prompt (map, prev_event, used_mouse_menu); - /* Now that we have read an event, Emacs is not idle. */ - if (!end_time) - timer_stop_idle (); + /* Only exit if a mouse menu was actually used successfully. */ + if (*used_mouse_menu) + { + /* Now that we have read an event, Emacs is not idle. */ + if (!end_time) + timer_stop_idle (); - goto exit; + goto exit; + } } /* Maybe autosave and/or garbage collect due to idleness. */ @@ -8457,8 +8461,11 @@ read_char_x_menu_prompt (Lisp_Object map, /* Display the menu and get the selection. */ Lisp_Object value; - value = Fx_popup_menu (prev_event, get_keymap (map, 0, 1)); - if (CONSP (value)) + value = x_popup_menu (prev_event, get_keymap (map, 0, 1), used_mouse_menu); + + if (!*used_mouse_menu) + value = Qnil; + else if (CONSP (value)) { Lisp_Object tem; @@ -8489,8 +8496,6 @@ read_char_x_menu_prompt (Lisp_Object map, } else if (NILP (value)) value = Qt; - if (used_mouse_menu) - *used_mouse_menu = true; return value; } return Qnil ; diff --git a/src/keyboard.h b/src/keyboard.h index a2a5f8f21d..954485c78b 100644 --- a/src/keyboard.h +++ b/src/keyboard.h @@ -360,6 +360,9 @@ enum menu_item_idx extern void unuse_menu_items (void); +extern Lisp_Object +x_popup_menu (Lisp_Object position, Lisp_Object menu, bool *used_mouse_menu); + /* This is how to deal with multibyte text if HAVE_MULTILINGUAL_MENU isn't defined. The use of HAVE_MULTILINGUAL_MENU could probably be confined to an extended version of this with sections of code below diff --git a/src/menu.c b/src/menu.c index d569b4b29b..257c67f6a4 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1157,6 +1157,12 @@ keyboard input, then this normally results in a quit and event (indicating that the user invoked the menu with the mouse) then no quit occurs and `x-popup-menu' returns nil. */) (Lisp_Object position, Lisp_Object menu) +{ + return x_popup_menu (position, menu, NULL); +} + +Lisp_Object +x_popup_menu (Lisp_Object position, Lisp_Object menu, bool *used_mouse_menu) { Lisp_Object keymap, tem, tem2; int xpos = 0, ypos = 0; @@ -1439,7 +1445,10 @@ no quit occurs and `x-popup-menu' returns nil. */) FRAME_DISPLAY_INFO (f)->grabbed = 0; #endif - if (error_name) error ("%s", error_name); + if (error_name && !used_mouse_menu) + error ("%s", error_name); + else if (!error_name && used_mouse_menu) + *used_mouse_menu = true; return selection; } -- 2.14.2