On May 2, 2021, at 2:49 AM, Eli Zaretskii <eliz@gnu.org> wrote:

Sure, but the event gives you the window, and through it the buffer of
that window, so I see no particular reason to make the window
selected.

A given buffer may appear in multiple windows, which likely will have different “window-start” and “window-end”.  So you have to find the line position in the buffer relevant for that particular window.  Also tying me to this is the fact that the format-mode-line method obviously uses windows, not buffers.