How to recode the intuition window depth button behaviour, and how to test window is "front" ?

Online Status

Hello, I'm doing the kind of intuition window the old "AmigaAMP" mp3 player used to have, that is to say with none of the official window borders, and having bitmap "skins". Then of course in that case you have to do other version of the close / resize / Depth buttons, and you have to recode their behaviour.

...And so, I have to recode the "depth" button behaviour, which is:
- If window is not front, but it front , easy with WindowToFront(w)
- if window is front, put is back easy with WindowToBack(w)

... but teh thing is: I can't find a reliable way to just test if the window is front or not ! . At some point for another project I needed to know if a given window was obscured in some way by another and I could get informations from the layer for this. But this is different, you can have a window not obscured, that is not front.

Some idea ?

Online Status

So finnaly I have:

    /* Walk layers front→back; first layer whose
     * Window is non-NULL and not a backdrop is the
     * true frontmost user window. */
    BOOL isFront = FALSE;
    struct Layer_Info *li = &CurrentMainScreen->LayerInfo;
    struct Layer *lay;
    LockLayerInfo(li);
    lay = li->top_layer;
    if (lay) {
        struct Window *w = (struct Window *)lay->Window;
        if (w && !(w->Flags & WFLG_BACKDROP)) {
            isFront = (w == CurrentMainWindow);
        }
    }
    UnlockLayerInfo(li);
    if (isFront)
        WindowToBack(CurrentMainWindow);
    else
        WindowToFront(CurrentMainWindow);