2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: GetMwmW.c /main/5 1996/05/20 16:07:08 drk $
25 * (c) Copyright 1996 Digital Equipment Corporation.
26 * (c) Copyright 1990,1993,1994,1996 Hewlett-Packard Company.
27 * (c) Copyright 1993,1994,1996 International Business Machines Corp.
28 * (c) Copyright 1993,1994,1996 Sun Microsystems, Inc.
29 * (c) Copyright 1993,1994,1996 Novell, Inc.
30 * (c) Copyright 1996 FUJITSU LIMITED.
31 * (c) Copyright 1996 Hitachi.
34 /************************************<+>*************************************
35 ****************************************************************************
39 ** Project: DT Workspace Manager
41 ** Description: Gets the mwm window id.
43 ****************************************************************************
44 ************************************<+>*************************************/
47 #include <X11/Xutil.h>
48 #include <Xm/MwmUtil.h>
50 #include <Xm/AtomMgr.h>
54 /******** Public Function Declarations ********/
56 extern int _DtGetMwmWindow(
61 /******** End Public Function Declarations ********/
63 /******** Static Function Declarations ********/
65 static int _GetMwmWindow(
71 /******** End Static Function Declarations ********/
74 /*************************************<->*************************************
76 * int _GetMwmWindow (display, root, pMwmWindow, property)
81 * Get the Motif Window manager window
87 * root - root window of screen
88 * pMwmWindow - pointer to a window (to be returned)
89 * property - the property atom
93 * *pMwmWindow - mwm window id, if successful
94 * Return - status from XGetWindowProperty
98 * This can fail if mwm is not managing the screen for the root window
101 *************************************<->***********************************/
111 unsigned long nitems;
112 unsigned long leftover;
113 PropMotifWmInfo *pWmInfo = NULL;
115 Window wroot, wparent, *pchildren;
116 unsigned int nchildren;
119 if ((rcode=XGetWindowProperty(display,root,
120 property,0L, PROP_MWM_INFO_ELEMENTS,
122 &actualType,&actualFormat,
123 &nitems,&leftover,(unsigned char **)&pWmInfo))==Success)
126 if (actualType != property)
128 /* wrong type, force failure */
133 rcode = BadWindow; /* assume the worst */
136 * The mwm window should be a direct child of root
138 if (XQueryTree (display, root, &wroot, &wparent,
139 &pchildren, &nchildren))
143 for (i = 0; (i < nchildren) && (rcode != Success); i++)
145 if (pchildren[i] == pWmInfo->wmWindow)
152 if (rcode == Success);
154 *pMwmWindow = pWmInfo->wmWindow;
159 XFree ((char *)pchildren);
166 XFree ((char *)pWmInfo);
172 } /* END OF FUNCTION _GetMwmWindow */
175 /*************************************<->*************************************
177 * int _DtGetMwmWindow (display, root, pMwmWindow)
182 * Get the Motif Window manager window
188 * root - root window of screen
189 * pMwmWindow - pointer to a window (to be returned)
193 * *pMwmWindow - mwm window id, if successful
194 * Return - status from XGetWindowProperty
198 * This can fail if mwm is not managing the screen for the root window
201 *************************************<->***********************************/
210 xa_MWM_INFO = XmInternAtom (display, _XA_MWM_INFO, False);
211 return (_GetMwmWindow (display, root, pMwmWindow, xa_MWM_INFO));