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 17:26:13 +0200

> From: Manuel Giraud <[email-masked]>
> Cc: [email-masked],  [email-masked]
> Date: Fri, 18 Nov 2022 16:20:16 +0100
> 
> > This cannot be a compile-time condition, because Emacs compiled with X
> > support can still have TTY frames.  So you need to test for
> > FRAME_WINDOW_P, and only call x_y_to_hpos_vpos if FRAME_WINDOW_P
> > returns non-zero; otherwise call pixel_to_glyph_coords even in a build
> > where HAVE_WINDOW_SYSTEM is defined.
> 
> Ok.  Sorry about that.  Here is a new one.

No need to be sorry, no one can possibly remember all this stuff all
the time.

> --- a/src/keyboard.c
> +++ b/src/keyboard.c
> @@ -5974,8 +5974,20 @@ 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);
> +		if (FRAME_WINDOW_P (f))
> +		  {
> +		    struct window *menu_w = XWINDOW (f->menu_bar_window);
> +		    int x, y, dummy;
> +
> +		    x = FRAME_TO_WINDOW_PIXEL_X (menu_w, XFIXNUM (event->x));
> +		    y = FRAME_TO_WINDOW_PIXEL_Y (menu_w, XFIXNUM (event->y));
> +
> +		    x_y_to_hpos_vpos (XWINDOW (f->menu_bar_window), x, y, &column, &row,
> +				      NULL, NULL, &dummy);
> +		  }
> +		else
> +		  pixel_to_glyph_coords (f, XFIXNUM (event->x), XFIXNUM (event->y),
> +					 &column, &row, NULL, 1);

I thought you said XWINDOW (f->menu_bar_window) doesn't compile in the
"--without-x" build?  I think you need the HAVE_WINDOW_SYSTEM
condition as well.