Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / DtSvc / DtUtil2 / GetEmbed.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /*
24  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
25  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
26  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
27  * (c) Copyright 1993, 1994 Novell, Inc.                                *
28  */
29 /************************************<+>*************************************
30  ****************************************************************************
31  **
32  **   File:     GetEmbed.c
33  **
34  **   RCS:      $XConsortium: GetEmbed.c /main/5 1996/05/20 16:09:08 drk $
35  **   Project:  DT Workspace Manager
36  **
37  **   Description: Get workspace embedded clients property.
38  **
39  **   (c) Copyright 1990, 1993 by Hewlett-Packard Company
40  **
41  ****************************************************************************
42  ************************************<+>*************************************/
43 #include <stdio.h>
44 #include <X11/Xlib.h>
45 #include <X11/Xutil.h>
46 #include <Dt/Wsm.h> 
47 #include <Dt/WsmP.h> 
48 #include <Xm/Xm.h> 
49 #include <Xm/AtomMgr.h>
50
51 \f
52 /*************************************<->*************************************
53  *
54  *  int _DtGetEmbeddedClients (display, root, ppEmbeddedClients, 
55  *                                      pNumEmbeddedClients)
56  *
57  *
58  *  Description:
59  *  -----------
60  *  Get the contents of the _DT_WORKSPACE_EMBEDDED_CLIENTS property 
61  *  from a root window. This is a array of top-level windows that are
62  *  embedded in the front panel of the window manager. They would
63  *  not be picked up ordinarily by a session manager in a normal
64  *  search for top-level windows because they are reparented to 
65  *  the front panel which itself is a top-level window.
66  *
67  *
68  *  Inputs:
69  *  ------
70  *  display             - display 
71  *  root                - root window to get info from
72  *  ppEmbeddedClients   - pointer to a pointer (to be returned)
73  *  pNumEmbeddedClients - pointer to a number (to be returned)
74  *
75  *  Outputs:
76  *  -------
77  *  *ppEmbeddedClients  - pointer to a array of window IDs (top-level
78  *                        windows for embedded clients)
79  *                        (NOTE: This should be freed using XFree)
80  *  *pNumEmbeddedClients- number of window IDs in array
81  *  Return              - Success if property fetched ok.
82  *                        Failure returns are from XGetWindowProperty
83  * 
84  *  Comments:
85  *  --------
86  *  Use XFree to free the returned data.
87  * 
88  *************************************<->***********************************/
89 int 
90 _DtGetEmbeddedClients(
91         Display *display,
92         Window root,
93         Atom **ppEmbeddedClients,
94         unsigned long *pNumEmbeddedClients )
95 {
96     Atom actualType;
97     int actualFormat;
98     unsigned long leftover;
99     int rcode;
100     Atom property;
101
102     *ppEmbeddedClients = NULL;
103     property = XmInternAtom (display,
104                             _XA_DT_WORKSPACE_EMBEDDED_CLIENTS, False);
105
106     if ((rcode=XGetWindowProperty(display,
107                          root,
108                          property,
109                          0L, 
110                          (long)BUFSIZ,
111                          False,
112                          property,
113                          &actualType,
114                          &actualFormat,
115                          pNumEmbeddedClients,
116                          &leftover,
117                          (unsigned char **)ppEmbeddedClients))==Success)
118     {
119
120         if (actualType != property)
121         {
122             /* wrong type, force failure */
123             *pNumEmbeddedClients = 0;
124             rcode = BadValue;
125             if (actualType != None)
126             {
127                 XFree ((char *) *ppEmbeddedClients);
128             }
129         }
130     }
131         
132     return(rcode);
133 }