WmMain.c 6.1 KB

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