Fix warnings in dtwm
[oweals/cde.git] / cde / programs / dtwm / WmMain.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 1989, 1990, 1991, 1992 OPEN SOFTWARE FOUNDATION, INC. 
25  * ALL RIGHTS RESERVED 
26 */ 
27 /* 
28  * Motif Release 1.2.1
29 */ 
30 #ifdef REV_INFO
31 #ifndef lint
32 static char rcsid[] = "$TOG: WmMain.c /main/8 1998/04/20 13:01:09 mgreess $"
33 #endif
34 #endif
35 /*
36  * (c) Copyright 1987, 1988, 1989, 1990 HEWLETT-PACKARD COMPANY */
37
38 /*
39  * Included Files:
40  */
41
42 #include "WmGlobal.h"
43
44 #ifndef NO_MULTIBYTE
45 #include <locale.h>
46 #endif
47 #ifdef WSM
48 #include <Dt/Message.h>
49 #include <Dt/EnvControlP.h>
50 #endif /* WSM */
51 /*
52  * include extern functions
53  */
54
55 #include "WmCEvent.h"
56 #include "WmEvent.h"
57 #include "WmInitWs.h"
58 #include "WmError.h"
59 #ifdef WSM
60 #include "WmIPC.h"
61 #include "WmBackdrop.h"
62 #endif /* WSM */
63
64
65 /*
66  * Function Declarations:
67  */
68 #ifdef WSM
69 int WmReturnIdentity (int argc, char *argv[], char *environ[]);
70 #define ManagedRoot(w) (!XFindContext (DISPLAY, (w), wmGD.screenContextType, \
71 (caddr_t *)&pSD) ? (SetActiveScreen (pSD), True) : \
72 (IsBackdropWindow (ACTIVE_PSD, (w))))
73 #else /* WSM */
74 #define ManagedRoot(w) (!XFindContext (DISPLAY, (w), wmGD.screenContextType, \
75 (caddr_t *)&pSD) ? (SetActiveScreen (pSD), True) : False)
76 #endif /* WSM */
77
78 WmScreenData *pSD;
79
80 /*
81  * Global Variables:
82  */
83
84 WmGlobalData wmGD;
85 #ifndef NO_MESSAGE_CATALOG
86 NlsStrings wmNLS;
87 #endif
88 #ifdef WSM
89 int WmIdentity;
90 #endif /* WSM */
91
92
93 \f
94 /*************************************<->*************************************
95  *
96  *  main (argc, argv, environ)
97  *
98  *
99  *  Description:
100  *  -----------
101  *  This is the main window manager function.  It calls window manager
102  *  initializtion functions and has the main event processing loop.
103  *
104  *
105  *  Inputs:
106  *  ------
107  *  argc = number of command line arguments (+1)
108  *
109  *  argv = window manager command line arguments
110  *
111  *  environ = window manager environment
112  *
113  *************************************<->***********************************/
114
115 int
116 main (int argc, char *argv [], char *environ [])
117 {
118     XEvent      event;
119     Boolean     dispatchEvent;
120
121     setlocale(LC_ALL, "");
122
123 #ifndef NO_MULTIBYTE
124 #ifdef WSM
125     /*
126      * Set up environment variables for this HP DT client
127      */
128     _DtEnvControl(DT_ENV_SET);
129
130     /*
131      * Force LANG lookup early. 
132      * (Front end may change $LANG to 'C' as part
133      *  of string space reduction optimization.)
134      */
135      {
136          char * foo = ((char *)GETMESSAGE(44, 1, ""));
137      }
138 #endif /* WSM */
139     XtSetLanguageProc (NULL, (XtLanguageProc)NULL, NULL);
140 #endif
141 #ifdef WSM
142     /*  
143      * Get Identity
144      */
145     WmIdentity = WmReturnIdentity(argc, argv, environ);
146 #endif /* WSM */
147
148     /*
149      * Initialize the workspace:
150      */
151
152     InitWmGlobal (argc, argv, environ);
153 #ifdef WSM
154
155     /*
156      * Set up PATH variable if it must run as standalone command
157      * invoker
158      */
159     if (wmGD.dtLite)
160     {
161         _DtEnvControl(DT_ENV_SET_BIN);
162     }
163 #endif /* WSM */
164     
165     /*
166      * MAIN EVENT HANDLING LOOP:
167      */
168
169     for (;;)
170     {
171         XtAppNextEvent (wmGD.mwmAppContext, &event);
172
173
174         /*
175          * Check for, and process non-widget events.  The events may be
176          * reported to the root window, to some client frame window,
177          * to an icon window, or to a "special" window management window.
178          * The lock modifier is "filtered" out for window manager processing.
179          */
180
181         wmGD.attributesWindow = 0L;
182
183 #ifdef WSM
184         if ((event.type == ButtonPress) || 
185             (event.type == ButtonRelease))
186         {
187             if ((wmGD.evLastButton.button != 0) &&
188                 ReplayedButtonEvent (&(wmGD.evLastButton), 
189                                      &(event.xbutton)))
190             {
191                 wmGD.bReplayedButton = True;
192             }
193             else
194             {
195                 /* save this button for next comparison */
196                 memcpy (&wmGD.evLastButton, &event, sizeof (XButtonEvent));
197                 wmGD.bReplayedButton = False;
198             }
199         }
200 #endif /* WSM */
201         dispatchEvent = True;
202         if (wmGD.menuActive)
203         {
204             /*
205              * Do special menu event preprocessing.
206              */
207
208             if (wmGD.checkHotspot || wmGD.menuUnpostKeySpec ||
209                 wmGD.menuActive->accelKeySpecs)
210             {
211                 dispatchEvent = WmDispatchMenuEvent ((XButtonEvent *) &event);
212             }
213         }
214
215         if (dispatchEvent)
216         {
217             if (ManagedRoot(event.xany.window))
218             {
219                 dispatchEvent = WmDispatchWsEvent (&event);
220             }
221             else
222             {
223                 dispatchEvent = WmDispatchClientEvent (&event);
224             }
225
226             if (dispatchEvent)
227             {
228                 /*
229                  * Dispatch widget related event:
230                  */
231
232                 XtDispatchEvent (&event);
233             }
234         }
235     }
236
237 } /* END OF FUNCTION main */
238
239 #ifdef WSM
240 /******************************<->*************************************
241  *
242  *  WmReturnIdentity (argc, argv, environ)
243  *
244  *
245  *  Description:
246  *  -----------
247  *  This function checks the last component of the (path)name
248  *  contained in argv[0] and makes a global decision as to whether
249  *  it should fetch resources as mwm or dtwm.
250  *
251  *  Inputs:
252  *  ------
253  *  argc = number of command line arguments (+1)
254  *
255  *  argv = window manager command line arguments
256  *
257  *  environ = window manager environment
258  *
259  ******************************<->***********************************/
260
261 int WmReturnIdentity ( int argc, char *argv[], char *environ[]) 
262 {
263         char *tempString;
264         char *origPtr;
265
266         /* assume it's dtwm until proven differently */
267
268         int retVal = DT_MWM;
269
270         if (!(tempString = 
271               (char *)(XtMalloc ((unsigned int)(strlen (argv[0]) + 1)))))
272         {
273                 Warning(((char *)GETMESSAGE(44, 2, "Insufficient memory for name of window manager")));
274                 exit(WM_ERROR_EXIT_VALUE);
275         }
276
277         origPtr = tempString;
278
279         if (strrchr(argv[0], '/'))
280         {
281                 
282                 strcpy(tempString, (strrchr(argv[0], '/')));
283
284                 tempString++;
285         }
286         else
287                 strcpy(tempString, argv[0]);
288
289         if (!(strcmp(tempString, WM_RESOURCE_NAME)))
290         /*
291          *
292          *   If it's explicity "mwm", then set our identity anew.
293          *
294          */
295         {
296                 retVal = MWM;
297         }
298
299         XtFree((char *)origPtr);
300
301         return(retVal);
302
303 } /* END OF FUNCTION WmReturnIdentity */
304 #endif /* WSM */
305 #ifdef WSM
306 /*************************     eof   ******************************/
307 #endif /* WSM */