Blame lib/Xm/IsMwmRun.c

Packit b099d7
/* $XConsortium: IsMwmRun.c /main/7 1996/05/21 12:02:11 pascale $ */
Packit b099d7
/*
Packit b099d7
 * Motif
Packit b099d7
 *
Packit b099d7
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are free software; you can
Packit b099d7
 * redistribute them and/or modify them under the terms of the GNU
Packit b099d7
 * Lesser General Public License as published by the Free Software
Packit b099d7
 * Foundation; either version 2 of the License, or (at your option)
Packit b099d7
 * any later version.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are distributed in the hope that
Packit b099d7
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
Packit b099d7
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Packit b099d7
 * PURPOSE. See the GNU Lesser General Public License for more
Packit b099d7
 * details.
Packit b099d7
 *
Packit b099d7
 * You should have received a copy of the GNU Lesser General Public
Packit b099d7
 * License along with these librararies and programs; if not, write
Packit b099d7
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
Packit b099d7
 * Floor, Boston, MA 02110-1301 USA
Packit b099d7
 * 
Packit b099d7
 */
Packit b099d7
/*
Packit b099d7
 * HISTORY
Packit b099d7
 */
Packit b099d7
Packit b099d7
Packit b099d7
#ifdef HAVE_CONFIG_H
Packit b099d7
#include <config.h>
Packit b099d7
#endif
Packit b099d7
Packit b099d7
Packit b099d7
#include <Xm/XmP.h>
Packit b099d7
#include <Xm/MwmUtil.h>
Packit b099d7
#include "XmI.h"
Packit b099d7
Packit b099d7
/************************************************************************
Packit b099d7
 *
Packit b099d7
 *  XmIsMotifWMRunning
Packit b099d7
 *
Packit b099d7
 ************************************************************************/
Packit b099d7
Boolean 
Packit b099d7
XmIsMotifWMRunning(
Packit b099d7
	 Widget shell )
Packit b099d7
{
Packit b099d7
    Atom	motif_wm_info_atom;
Packit b099d7
    Atom	actual_type;
Packit b099d7
    int		actual_format;
Packit b099d7
    unsigned long num_items, bytes_after;
Packit b099d7
    PropMotifWmInfo	*prop = 0;
Packit b099d7
    Window	root = RootWindowOfScreen(XtScreen(shell));
Packit b099d7
Packit b099d7
    _XmWidgetToAppContext(shell);
Packit b099d7
 
Packit b099d7
    _XmAppLock(app);
Packit b099d7
Packit b099d7
    motif_wm_info_atom = XInternAtom(XtDisplay(shell),
Packit b099d7
				       _XA_MOTIF_WM_INFO,
Packit b099d7
				       FALSE);
Packit b099d7
    _XmProcessLock();
Packit b099d7
Packit b099d7
    XGetWindowProperty (XtDisplay(shell), 
Packit b099d7
			 root,
Packit b099d7
			 motif_wm_info_atom,
Packit b099d7
			 0, (long)PROP_MOTIF_WM_INFO_ELEMENTS,
Packit b099d7
			 FALSE, motif_wm_info_atom,
Packit b099d7
			 &actual_type, &actual_format,
Packit b099d7
			 &num_items, &bytes_after,
Packit b099d7
			 (unsigned char **) &prop);
Packit b099d7
    _XmProcessUnlock();
Packit b099d7
Packit b099d7
    if ((actual_type != motif_wm_info_atom) ||
Packit b099d7
	 (actual_format != 32) ||
Packit b099d7
	 (num_items < PROP_MOTIF_WM_INFO_ELEMENTS))
Packit b099d7
      {
Packit b099d7
	   if (prop != 0) XFree((char *)prop);
Packit b099d7
           _XmAppUnlock(app);
Packit b099d7
	   return (FALSE);
Packit b099d7
      }
Packit b099d7
    else
Packit b099d7
      {
Packit b099d7
	   Window	wm_window = (Window) prop->wmWindow;
Packit b099d7
	   Window	top, parent, *children;
Packit b099d7
	   unsigned int	num_children;
Packit b099d7
	   Boolean	returnVal;
Packit b099d7
	   Cardinal	i;
Packit b099d7
Packit b099d7
	   if (XQueryTree(XtDisplay(shell),
Packit b099d7
			  root, &top, &parent,
Packit b099d7
			  &children, &num_children))
Packit b099d7
	     {
Packit b099d7
		 i = 0; 
Packit b099d7
		 while ((i < num_children) && (children[i] != wm_window))
Packit b099d7
		   i++;
Packit b099d7
		 returnVal =  (i == num_children) ? FALSE : TRUE;
Packit b099d7
	     }
Packit b099d7
	   else
Packit b099d7
	     returnVal = FALSE;
Packit b099d7
Packit b099d7
	   if (prop) XFree((char *)prop);
Packit b099d7
	   if (children) XFree((char *)children);
Packit b099d7
           _XmAppUnlock(app);
Packit b099d7
	   return (returnVal);
Packit b099d7
      }
Packit b099d7
}