Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / DtSvc / DtUtil1 / WmGWsList.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 /* $XConsortium: WmGWsList.c /main/6 1996/06/21 17:24:26 ageorge $
24  *
25  * (c) Copyright 1996 Digital Equipment Corporation.
26  * (c) Copyright 1992-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.
32  */
33
34 /************************************<+>*************************************
35  ****************************************************************************
36  **
37  **   File:     WmGetWsLis.c
38  **
39  **   Project:  DT Workspace Manager
40  **
41  **   Description: Get Dt Workspace List
42  **
43  ****************************************************************************
44  ************************************<+>*************************************/
45 #include <stdio.h>
46 #include <X11/Xlib.h>
47 #include <X11/Xutil.h>
48 #include <Dt/Wsm.h> 
49 #include <Dt/WsmP.h> 
50 #include <Xm/Xm.h>
51 #include <Xm/AtomMgr.h>
52 #include <X11/Xatom.h>
53 #include "DtSvcLock.h"
54
55 /*************************************<->*************************************
56  *
57  *  int DtWsmGetWorkspaceList (display, root, ppWorkspaceList,
58  *                                                      pNumWorkspaces)
59  *
60  *
61  *  Description:
62  *  -----------
63  *  Get the contents of the _DT_WORKSPACE_LIST property 
64  *
65  *
66  *  Inputs:
67  *  ------
68  *  display     - display 
69  *  root        - root window of screen of interest
70  *  pNumWorkspaces - the number of workspaces returned
71  *  ppWorkspaceList - pointer to a pointer to return
72  *
73  *  Outputs:
74  *  --------
75  *  *ppDtWmHints-points to the Workspace List
76  *                (NOTE: This should be freed using XFree)
77  *
78  *  Comments:
79  *  ---------
80  * 
81  *************************************<->***********************************/
82 int
83 DtWsmGetWorkspaceList(
84         Display *display,
85         Window root,
86         Atom **ppWorkspaceList,
87         int *pNumWorkspaces)
88 {
89     Atom actualType;
90     int actualFormat;
91     unsigned long leftover, items, length, oldlength;
92     int rcode;
93     Atom property;
94     Window wmWindow;
95     _DtSvcDisplayToAppContext(display);
96
97     _DtSvcAppLock(app);
98
99     if ((rcode=_DtGetMwmWindow (display, root, &wmWindow)) == Success)
100     {
101
102         property = XmInternAtom(display, _XA_DT_WORKSPACE_LIST, False); 
103         length = BUFSIZ;
104
105         *ppWorkspaceList = NULL;
106         if ((rcode=XGetWindowProperty(
107                         display,
108                         wmWindow,
109                         property,
110                         0L,                             /* offset */
111                         length,
112                         False,                          /* delete */
113                         XA_ATOM,                        /* req_type */
114                         &actualType,
115                         &actualFormat,
116                         &items,                         /* items returned */
117                         &leftover,
118                         (unsigned char **)ppWorkspaceList))==Success)
119         {
120
121             if (actualType != XA_ATOM)
122             {
123                 /* wrong type, force failure */
124                 rcode = BadValue;
125                 if (actualType != None)
126                 {
127                     XFree ((char *)*ppWorkspaceList);
128                 }
129                 *ppWorkspaceList = NULL;
130             }
131             else
132             {
133                 *pNumWorkspaces = (int) items;
134             }
135         }
136     }
137         
138     _DtSvcAppUnlock(app);
139     return(rcode);
140
141 } /* END OF FUNCTION DtWsmGetWorkspaceList */
142
143 /*************************************<->*************************************
144  *
145  *  int DtWsmGetCurrentWorkspace (display, root, paWorkspace)
146  *
147  *
148  *  Description:
149  *  -----------
150  *  Get the contents of the _DT_WORKSPACE_CURRENT property 
151  *
152  *
153  *  Inputs:
154  *  ------
155  *  display     - display 
156  *  root        - root window of screen of interest
157  *  paWorkspace  - pointer to a Atom of current workspace (returned)
158  *
159  *  Outputs:
160  *  --------
161  *  *paWorkspace - atom for current workspace (represents "name"
162  *                 of workspace). 
163  *
164  *  Comments:
165  *  ---------
166  *  The Atom is copied to the caller's space. Nothing needs to be
167  *  freed.
168  * 
169  *************************************<->***********************************/
170 int
171 DtWsmGetCurrentWorkspace (
172         Display *display,
173         Window root,
174         Atom *paWorkspace)
175 {
176     Atom actualType;
177     int actualFormat;
178     unsigned long leftover, items, length;
179     int rcode;
180     Atom property;
181     Window wmWindow;
182     Atom *paTemp;
183     _DtSvcDisplayToAppContext(display);
184
185     _DtSvcAppLock(app);
186     if ((rcode=_DtGetMwmWindow (display, root, &wmWindow)) == Success)
187     {
188
189         property = XmInternAtom(display, _XA_DT_WORKSPACE_CURRENT, False); 
190         length = 1;
191
192         if ((rcode=XGetWindowProperty(
193                         display,
194                         wmWindow,
195                         property,
196                         0L,                             /* offset */
197                         length,
198                         False,                          /* delete */
199                         XA_ATOM,                        /* req_type */
200                         &actualType,
201                         &actualFormat,
202                         &items,                         /* items returned */
203                         &leftover,
204                         (unsigned char **)&paTemp))==Success)
205         {
206
207             if (actualType != XA_ATOM)
208             {
209                 /* wrong type, force failure */
210                 rcode = BadValue;
211                 if (actualType != None)
212                 {
213                     XFree ((char *)paTemp);
214                 }
215             }
216             else
217             {
218                 *paWorkspace = *paTemp;
219                 XFree((char *) paTemp);
220             }
221         }
222     }
223         
224     _DtSvcAppUnlock(app);
225     return(rcode);
226
227 } /* END OF FUNCTION DtWsmGetCurrentWorkspace */
228