Parent document is top of "Motif FAQ (Part 8 of 9)"
Previous document is "264) TOPIC: ICONIFICATION and DE-ICONIFICATION"
Next document is "266) How can I check if my application has come up iconic? I want"

265) How can I keep track of changes to iconic/normal window state?

Answer:  You can look at the WM_STATE property, but this breaks ICCCM
guidelines.  ICCCM compliant window managers will map windows in changing them
to normal state and unmap them in changing them to iconic state. Look for
StructureNotify events and check the event type:

        XtAddEventHandler (toplevel_widget,
                        StructureNotifyMask,
                        False,
                        StateWatcher,
                        (Opaque) NULL);
        ....
        void StateWatcher (w, unused, event)
        Widget w;
        caddr_t unused;
        XEvent *event;
        {
                if (event->type == MapNotify)
                        printf ("normal\n");
                else if (event->type == UnmapNotify)
                        printf ("iconified\n");
                else    printf ("other event\n");
        }


If you insist on looking at WM_STATE, here is some code (from Ken Sall) to do
it:

        /*
        ------------------------------------------------------------------
        Try a function such as CheckWinMgrState below which returns one of
        IconicState | NormalState | WithdrawnState | NULL :
        ------------------------------------------------------------------
        */
        #define WM_STATE_ELEMENTS 1

        unsigned long *CheckWinMgrState (dpy, window)
        Display *dpy;
        Window window;
        {
          unsigned long *property = NULL;
          unsigned long nitems;
          unsigned long leftover;
          Atom xa_WM_STATE, actual_type;
          int actual_format;
          int status;

            xa_WM_STATE = XInternAtom (dpy, "WM_STATE", False);

            status = XGetWindowProperty (dpy, window,
                          xa_WM_STATE, 0L, WM_STATE_ELEMENTS,
                          False, xa_WM_STATE, &actual_type, &actual_format,
                          &nitems, &leftover, (unsigned char **)&property);

            if ( ! ((status == Success) &&
                        (actual_type == xa_WM_STATE) &&
                        (nitems == WM_STATE_ELEMENTS)))
                {
                if (property)
                    {
                    XFree ((char *)property);
                    property = NULL;
                    }
                }
            return (property);
        } /* end CheckWinMgrState */


One problem with testing WM_STATE is that a race condition is possible;
immediately after testing it, it could change, and the logic proceeds to
behave as if it were in the old state.

Parent document is top of "Motif FAQ (Part 8 of 9)"
Previous document is "264) TOPIC: ICONIFICATION and DE-ICONIFICATION"
Next document is "266) How can I check if my application has come up iconic? I want"