How to determine if a window is clicked on its title bar

As you know, only window buttons etc have an action on clicked … windows have on became key and on became main, but no on clicked action handlers.

So how do I determine if a window down in the stack of windows has been clicked … is it became main??

The goal is to rearrange the elements in a windows array {w1, w2, etc} when for example, w2 is clicked on … here, I then through my subroutine I reset the windows array to {w2, w1, etc}. This subroutine is no big deal, but where to place it is.

Any ideas?