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