Subject: bug#59351: 29.0.50; [PATCH] Fix mouse click position to menu bar entry

From: Eli Zaretskii <[email-masked]>
Date: Fri, 18 Nov 2022 13:58:19 +0200

> Cc: [email-masked]
> From: Manuel Giraud <[email-masked]>
> Date: Fri, 18 Nov 2022 12:01:15 +0100
> 
> diff --git a/src/keyboard.c b/src/keyboard.c
> index 069cf0627b..5cc7209846 100644
> --- a/src/keyboard.c
> +++ b/src/keyboard.c
> @@ -5974,8 +5974,17 @@ make_lispy_event (struct input_event *event)
>  	       in a menu (non-toolkit version).  */
>  	    if (!toolkit_menubar_in_use (f))
>  	      {
> -		pixel_to_glyph_coords (f, XFIXNUM (event->x), XFIXNUM (event->y),
> -				       &column, &row, NULL, 1);
> +		int dummy;
> +
> +		/* I guess this works because the menu bar is always
> +		   at position (0, 0) in a frame.  Should this changed
> +		   and we need a way to calculate the correct position
> +		   into the menu bar from the position of the event in
> +		   the frame.  */
> +		x_y_to_hpos_vpos (XWINDOW (f->menu_bar_window),
> +				  XFIXNUM (event->x), XFIXNUM (event->y),
> +				  &column, &row,
> +				  NULL, NULL, &dummy);

Did you test the results on a TTY frame that has a mouse?

Also, does this work after the user clicks the menu bar and Emacs
drops down a menu for the menu item on which the user clicked?  I
don't remember what happens to the pseudo-window geometry when that
happens.