I want to know which frame on a given X11 display was most recently selected. In fact, I want to know which frame that is mapped on the current desktop was most recently selected.
I can tell what display a frame is on with the
display frame parameter, and I can enumerate all the frames on the same display as a given frame with
next-frame. I can tell whether a frame is mapped with the
visibility frame parameter. I can also call
visible-frame-alist to list visible frames. But none of this helps me know which of these was most recently selected.
If the most recently selected frame is on the display I'm interested in, the answer is
selected-frame. But what if it isn't?
How can I list all the frames (or all the frames on a given display) in the order in which they were last selected?
I want a solution that works in GNU Emacs ≥23. Ideally this should work for all supported display types, not just X11.