Subject: Re: bug#69236: 29.1; Unwanted Focus Shift when Clicking Menu Functions in Emacs Mode Line

From: Eli Zaretskii <[email-masked]>
Date: Sun, 18 Feb 2024 21:36:57 +0200

[Please use Reply All to reply, to have the bug tracker CC'ed.]

> Date: Sun, 18 Feb 2024 20:25:50 +0100
> From: Gabriele Nicolardi <[email-masked]>
> 
> When things do work I get:
> 
>  <help-echo> <down-mouse-1> ;; mouse-minor-mode-menu
>  q <return>                 ;; exit-minibuffer
>  <help-echo> C-h l          ;; view-lossage
> 
> When things doesn't work I get:
> 
>  <help-echo> <down-mouse-1>           ;; mouse-minor-mode-menu
>  <mouse-1> <mouse-1>                  ;; mouse-select-window
>  <help-echo> C-x o                    ;; other-window
>  <return>                             ;; exit-minibuffer
>  C-h l                                ;; view-lossage
> 
> I see the <mouse-1> event but i click the mouse just one time. Other users reported the same issue so I
> presume it is not a hardware problem (the mouse...).
> 
> I also find that this code:
> 
> (defmacro with-ignore-mouse-events (&rest body)
>   "Macro to ignore mouse events before evaluating BODY."
>   `(progn
>      (when (input-pending-p)
>        (let ((event (read-event)))
>          (if (mouse-event-p event)
>              (let ((button (event-basic-type event)))
>                (if (eq button 'mouse-1)
>                    (ignore)
>                  (setq unread-command-events (list event))))
>            (setq unread-command-events (list event)))))
>      ,@body))
> 
> (defun mwe-function-1 ()
>   "MWE function 1"
>   (interactive)
>   (unwind-protect
>       (query-replace "foo" "bar" nil (point-min) (point-max))
>     ;; UNWINDFORMS
>     (read-string "function 1 executed")))
> 
> (defun mwe-function-1* ()
>   (interactive)
>   (with-ignore-mouse-events
>    (mwe-function-1)))
> 
> fixes the problem. (I need to use mwe-function-1* in the menu definition).

So the problem is fixed, and we can close this bug?  Or is there still
something left to investigate and/or fix?