Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / DtSvc / DtUtil1 / WmGWsInfo.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 /* $TOG: WmGWsInfo.c /main/7 1997/11/13 14:03:00 bill $
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:     WmGWsInfo.c
38  **
39  **   Project:  DT Workspace Manager
40  **
41  **   Description: Get Dt Workspace Info
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 DtWsmGetWorkspaceInfo (display, root, aWS, ppWsInfo)
58  *
59  *
60  *  Description:
61  *  -----------
62  *  Get the contents of the _DT_WORKSPACE_INFO_<name> property 
63  *  for workspace <name>.
64  *
65  *
66  *  Inputs:
67  *  ------
68  *  display     - display 
69  *  root        - root window of screen of interest
70  *  aWS         - atom for workspace
71  *  ppWsInfo    - ptr to WS info buffer ptr (to be returned)
72  *
73  *  Outputs:
74  *  --------
75  *  *ppWsInfo   - returned ptr to WS Info. (free with XtFree).
76  *
77  *
78  *  Comments:
79  *  ---------
80  *  ptr to WorkspaceInfo should be freed by calling
81  *  DtWsmFreeWorkspaceInfo.
82  * 
83  *************************************<->***********************************/
84 int
85 DtWsmGetWorkspaceInfo(
86         Display *display,
87         Window root,
88         Atom aWS,
89         DtWsmWorkspaceInfo **ppWsInfo)
90 {
91     int rcode;
92     Atom aProperty;
93     Window wmWindow;
94     DtWsmWorkspaceInfo *pWsInfo;
95     char *pchName, *pch;
96     int  iLen;
97     int  i;
98     Window *pWin;
99     XTextProperty tp;
100     char **ppchList;
101     int count, item;
102     _DtSvcDisplayToAppContext(display);
103
104     _DtSvcAppLock(app);
105     /* 
106      * Construct atom name
107      */
108     pchName = (char *) XGetAtomName (display, aWS);
109     iLen = strlen(pchName) + strlen (_XA_DT_WORKSPACE_INFO) + 4;
110
111     pch = (char *) XtMalloc (iLen);
112     strcpy (pch, _XA_DT_WORKSPACE_INFO);
113     strcat (pch, "_");
114     strcat (pch, pchName);
115
116     aProperty = XInternAtom (display, pch, FALSE);
117
118     XFree ((char *) pchName);
119     XtFree ((char *) pch);
120     pch = NULL;
121
122     /* 
123      * Get window where property is 
124      */
125     if ((rcode=_DtGetMwmWindow (display, root, &wmWindow)) == Success)
126     {
127         if ((rcode=XGetTextProperty(
128                         display,
129                         wmWindow,
130                         &tp,
131                         aProperty))>=Success)
132         {
133             if (rcode=XmbTextPropertyToTextList (
134                                 display,
135                                 &tp,
136                                 &ppchList,
137                                 &count) >= Success)
138             {
139                 pWsInfo = (DtWsmWorkspaceInfo *)
140                         XtCalloc(1, sizeof(DtWsmWorkspaceInfo));
141
142                 pWsInfo->workspace = aWS;
143                 item = 0;
144
145                 /* title */
146                 if (item < count)
147                 {
148                     pWsInfo->pchTitle = (char *) 
149                                 XtNewString ((String) ppchList[item]);
150                     item++;
151                 }
152
153                 /* pixel set id */
154                 if (item < count)
155                 {
156                     pWsInfo->colorSetId = atoi (ppchList[item]);
157                     item++;
158                 }
159
160                 /* backdrop window (moved to end!) */
161
162                 /* backdrop background */
163                 if (item < count)
164                 {
165                     pWsInfo->bg = (unsigned long) 
166                             strtol (ppchList[item], (char **) NULL, 0);
167                     item++;
168                 }
169
170                 /* backdrop foreground */
171                 if (item < count)
172                 {
173                     pWsInfo->fg = (unsigned long) 
174                             strtol (ppchList[item], (char **) NULL, 0);
175                     item++;
176                 }
177
178                 /* backdrop name (atom) */
179                 if (item < count)
180                 {
181                     pWsInfo->backdropName = 
182                             (Atom) strtol (ppchList[item], (char **) NULL, 0);
183                     item++;
184                 }
185
186                 /* number of backdrop windows */
187                 if (item < count)
188                 {
189                     pWsInfo->numBackdropWindows = 
190                             (int) strtol (ppchList[item], (char **) NULL, 0);
191                     item++;
192                 }
193
194                 /* list of backdrop windows */
195                 if (pWsInfo->numBackdropWindows > 0 &&
196                         (item + pWsInfo->numBackdropWindows) <= count)
197                 {
198                     pWin = (Window *)
199                         XtMalloc (pWsInfo->numBackdropWindows *
200                                   sizeof (Window));
201                     for (i=0; i<pWsInfo->numBackdropWindows; i++)
202                     {
203                         pWin[i] = (Window) 
204                             strtol (ppchList[item], (char **) NULL, 0);
205                         item++;
206                     }
207                     pWsInfo->backdropWindows = pWin;
208                 }
209                 else
210                 {
211                     /* Bogus backdrop windows info */
212                     pWsInfo->numBackdropWindows = 0;
213                 }
214
215                 /* pass back ptr to filled in structure */
216                 *ppWsInfo = pWsInfo;
217
218                 /* free the converted data */
219                 XFreeStringList (ppchList);
220             }
221             else 
222             {
223                 /* conversion failed */
224                 *ppWsInfo = NULL;
225             }
226             /* free the property data */
227             if (tp.value) 
228                 XFree (tp.value);
229         }
230     }
231         
232     if (rcode >= Success) rcode=Success;
233
234     _DtSvcAppUnlock(app);
235     return(rcode);
236
237 } /* END OF FUNCTION DtWsmGetWorkspaceInfo */
238
239
240 \f
241 /*************************************<->*************************************
242  *
243  *  void DtWsmFreeWorkspaceInfo (pWsInfo)
244  *
245  *
246  *  Description:
247  *  -----------
248  *  Free a WorkspaceInfo buffer
249  *
250  *
251  *  Inputs:
252  *  ------
253  *  pWsInfo     - ptr to WS info buffer
254  *
255  *  Outputs:
256  *  --------
257  *  None
258  *
259  *  Comments:
260  *  ---------
261  * 
262  *************************************<->***********************************/
263 void
264 DtWsmFreeWorkspaceInfo(
265         DtWsmWorkspaceInfo *pWsInfo)
266 {
267     if (pWsInfo)
268     {
269         if (pWsInfo->pchTitle)
270             XtFree (pWsInfo->pchTitle);
271         if (pWsInfo->backdropWindows)
272             XtFree ((char *)pWsInfo->backdropWindows);
273         XtFree ((char *)pWsInfo);
274     }
275
276 } /* END OF FUNCTION DtWsmFreeWorkspaceInfo */