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