Subject: bug#61241: 29.0.60; Incoherent last_mouse_window (xterm.c) between XInput and XInput 2

From: Adrián Medraño Calvo <[email-masked]>
Date: Tue, 13 May 2025 17:49:16 +0200

> On 22. Aug 2023, at 08:59, Po Lu <[email-masked]> wrote:
> 
> Thanks.  Taking into account your experiences with the TEST extension,
> I'm inclined towards believing that such a change is TRT, but the
> variable should be made terminal-local instead.  (Emacs Lisp does
> provide such a facility.)
> 
> Also, there are a few difficulties with the patch you attached.  First
> of all, it obsoletes an existing variable without due reason, and that
> should be avoided.  Secondly, :version specifiers within the patch
> should be revised to mention Emacs 30, since such a large change is not
> apposite for the release branch.
> 
> Finally, you missed the new terminal backend introduced in Emacs 30,
> src/androidterm.c.

Dear Po Lu,

in the summer of 2024 I implemented a patch incorporating your suggestions.
A couple of days ago I had a new look with the intention of finally submitting
it.  The patch corrects most of the issues you pointed out back then: nothing
is touched in lisp/window.el, the variable is made terminal-local and it is
implemented for androidterm as well.  I don’t know how to indicate the :version
for this terminal-local variable in the C code –or whether it’s possible–,
please indicate how to do so (or simply edit the patch, as you prefer).

A surprise emerged while rebasing to master: I discovered that since commit 2e8ef0910412aef8f9f1beba7c942473ad8602bb ("Protect against GCing of
last_mouse_window”) all `last_mouse_window` of different terminals were merged
into a single global variable.  This is equivalent to my proposal in "Expose last
window under pointer to Lisp” of 2023-08-22.  This commit solves the original
issue and, if you find it satisfactory, would allow to happily close this ticket.

If you still think that implementing it as a terminal-local variable is necessary
or preferable, I’m attaching the patch I described above.  Note that I revert the
changes introduced in 2e8ef09104 in my patch (please review attentively).

Thank you for your patience and, as always, thank you for your work in Emacs.

Kind regards,
Adrián.