Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / lib / DtSvc / DtUtil1 / WmRmWsFcn.c
1 /*
2  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
3  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
4  * (c) Copyright 1993, 1994 Novell, Inc.                                *
5  */
6 /************************************<+>*************************************
7  ****************************************************************************
8  **
9  **   File:     WmRmWsFcn.c
10  **
11  **   RCS:      $XConsortium: WmRmWsFcn.c /main/5 1996/06/21 17:24:22 ageorge $
12  **   Project:  HP DT Workspace Manager
13  **
14  **   Description: Remove the Workspace functions on a client
15  **
16  **   (c) Copyright 1991, 1993, 1994 by Hewlett-Packard Company
17  **
18  ****************************************************************************
19  ************************************<+>*************************************/
20 #include <X11/Xlib.h>
21 #include <X11/Xutil.h>
22 #include <X11/Xatom.h>
23 #include <Dt/Wsm.h> 
24 #include <Dt/WsmP.h> 
25 #include <Xm/AtomMgr.h>
26 #include "DtSvcLock.h"
27
28 \f
29 /*************************************<->*************************************
30  *
31  *  DtWsmRemoveWorkspaceFunctions (display, client)
32  *
33  *
34  *  Description:
35  *  -----------
36  *  Request the window manager to disallow workspace functions
37  *  for this client.
38  *
39  *
40  *  Inputs:
41  *  ------
42  *  display     - display 
43  *  root        - root window of screen 
44  *
45  *  Returns:
46  *  --------
47  *  none
48  *
49  *  
50  *  Comments:
51  *  ---------
52  *  Disables f.workspace_presence, f.remove, f.occupy_all for this
53  *  client.
54  * 
55  *************************************<->***********************************/
56 void
57 DtWsmRemoveWorkspaceFunctions (Display *display, Window client)
58 {
59     DtWmHints vHints, *pHints;
60     long functions;
61     Boolean bSetHints = False;
62     _DtSvcDisplayToAppContext(display);
63
64     _DtSvcAppLock(app);
65
66     if (_DtWsmGetDtWmHints (display, client, &pHints) != Success)
67     {
68         /*
69          * There were no existing workspace hints, so we'll
70          * just use our own variable
71          */
72         pHints = &vHints;
73         pHints->flags = 0;
74     }
75
76     if (pHints->flags & DtWM_HINTS_FUNCTIONS)
77     {
78         functions = pHints->functions & 
79                 (DtWM_FUNCTION_OCCUPY_WS | DtWM_FUNCTION_ALL);
80         
81         if (functions & DtWM_FUNCTION_ALL)
82         {
83             /* 
84              * The flags are a list of functions to remove. If 
85              * the workspace functions aren't on this list, make 
86              * sure that it's put there.
87              */
88             if (!(functions & DtWM_FUNCTION_OCCUPY_WS))
89             {
90                 /* remove workspace functions */
91                 pHints->functions |=  DtWM_FUNCTION_OCCUPY_WS;
92                 bSetHints = True;
93             }
94         }
95         else
96         {
97             /*
98              * The flags are a list of functions to add. If
99              * the workspace functions are on the list, make
100              * sure they get removed.
101              */
102             if (functions & DtWM_FUNCTION_OCCUPY_WS)
103             {
104                 /* remove workspace functions */
105                 pHints->functions &=  ~DtWM_FUNCTION_OCCUPY_WS;
106                 bSetHints = True;
107             }
108         }
109     }
110     else
111     {
112         /*
113          * The hints didn't have workspace functions specified.
114          * Set the flag and remove workspace functions.
115          */
116         pHints->flags |= DtWM_HINTS_FUNCTIONS;
117         pHints->functions = DtWM_FUNCTION_OCCUPY_WS | DtWM_FUNCTION_ALL;
118         bSetHints = True;
119     }
120
121     /*
122      * If something needs to be changed, then change it.
123      */
124     if (bSetHints)
125         _DtWsmSetDtWmHints (display, client, pHints);
126
127     /*
128      * If we read these hints off the window, then be sure to free
129      * them.
130      */
131     if (pHints && (pHints != &vHints))
132     {
133         XFree ((char *)pHints);
134     }
135
136     _DtSvcAppUnlock(app);
137 } /* END OF FUNCTION DtWsmRemoveWorkspaceFunctions */
138
139
140 \f
141 /*************************************<->*************************************
142  *
143  *  DtWsmAddWorkspaceFunctions (display, client)
144  *
145  *
146  *  Description:
147  *  -----------
148  *  Request the window manager to allow workspace functions
149  *  for this client.
150  *
151  *
152  *  Inputs:
153  *  ------
154  *  display     - display 
155  *  root        - root window of screen 
156  *
157  *  Returns:
158  *  --------
159  *  none
160  *
161  *  
162  *  Comments:
163  *  ---------
164  *  Enables f.workspace_presence, f.remove, f.occupy_all for this
165  *  client.
166  * 
167  *************************************<->***********************************/
168 void
169 DtWsmAddWorkspaceFunctions (Display *display, Window client)
170 {
171     DtWmHints vHints, *pHints;
172     long functions;
173     Boolean bSetHints = False;
174     _DtSvcDisplayToAppContext(display);
175
176     _DtSvcAppLock(app);
177
178     if (_DtWsmGetDtWmHints (display, client, &pHints) != Success)
179     {
180         /*
181          * There were no existing workspace hints, so we'll
182          * just use our own variable
183          */
184         pHints = &vHints;
185         pHints->flags = 0;
186     }
187
188     if (pHints->flags & DtWM_HINTS_FUNCTIONS)
189     {
190         functions = pHints->functions & 
191                 (DtWM_FUNCTION_OCCUPY_WS | DtWM_FUNCTION_ALL);
192         
193         if (functions & DtWM_FUNCTION_ALL)
194         {
195             /* 
196              * The flags are a list of functions to remove. If 
197              * the workspace functions are on this list, make 
198              * sure that they're removed.
199              */
200             if (functions & DtWM_FUNCTION_OCCUPY_WS)
201             {
202                 /* add workspace functions */
203                 pHints->functions &=  ~DtWM_FUNCTION_OCCUPY_WS;
204                 bSetHints = True;
205             }
206         }
207         else
208         {
209             /*
210              * The flags are a list of functions to add. If
211              * the workspace functions aren't on the list, make
212              * sure they get added.
213              */
214             if (!(functions & DtWM_FUNCTION_OCCUPY_WS))
215             {
216                 /* remove workspace functions */
217                 pHints->functions |=  DtWM_FUNCTION_OCCUPY_WS;
218                 bSetHints = True;
219             }
220         }
221     }
222     else
223     {
224         /*
225          * The hints didn't have workspace functions specified.
226          * Set the flag and add workspace functions.
227          */
228         pHints->flags |= DtWM_HINTS_FUNCTIONS;
229         pHints->functions = DtWM_FUNCTION_OCCUPY_WS;
230         bSetHints = True;
231     }
232
233     /*
234      * If something needs to be changed, then change it.
235      */
236     if (bSetHints)
237         _DtWsmSetDtWmHints (display, client, pHints);
238
239     /*
240      * If we read these hints off the window, then be sure to free
241      * them.
242      */
243     if (pHints && (pHints != &vHints))
244     {
245         XFree ((char *)pHints);
246     }
247     _DtSvcAppUnlock(app);
248
249 } /* END OF FUNCTION DtWsmAddWorkspaceFunctions */
250