previous-window

previous-window is a built-in function in `C source code'.

(previous-window &optional WINDOW MINIBUF ALL-FRAMES)

Return live window before WINDOW in the cyclic ordering of windows.
WINDOW must be a live window and defaults to the selected one. The
optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
consider.

MINIBUF nil or omitted means consider the minibuffer window only if the
minibuffer is active. MINIBUF t means consider the minibuffer window
even if the minibuffer is not active. Any other value means do not
consider the minibuffer window even if the minibuffer is active.

ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
plus the minibuffer window if specified by the MINIBUF argument. If the
minibuffer counts, consider all windows on all frames that share that
minibuffer too. The following non-nil values of ALL-FRAMES have special
meanings:

- t means consider all windows on all existing frames.

- `visible' means consider all windows on all visible frames.

- 0 (the number zero) means consider all windows on all visible and
iconified frames.

- A frame means consider all windows on that frame only.

Anything else means consider all windows on WINDOW's frame and no
others.

If you use consistent values for MINIBUF and ALL-FRAMES, you can
use `previous-window' to iterate through the entire cycle of
acceptable windows, eventually ending up back at the window you
started with. `next-window' traverses the same cycle, in the
reverse order.