Main.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  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. **
  25. ** File: Main.c
  26. **
  27. ** Project: DT 3.0
  28. **
  29. ** Description: main Dtstyle program
  30. **
  31. **
  32. ****************************************************************************
  33. ************************************<+>*************************************/
  34. /*$TOG: Main.c /main/16 1998/07/30 12:32:34 mgreess $*/
  35. /*
  36. * (c) Copyright 1997, The Open Group
  37. */
  38. /*
  39. * (c) Copyright 1996 Digital Equipment Corporation.
  40. * (c) Copyright 1990, 1993, 1996 Hewlett-Packard Company.
  41. * (c) Copyright 1996 International Business Machines Corp.
  42. * (c) Copyright 1996 Sun Microsystems, Inc.
  43. * (c) Copyright 1996 Novell, Inc.
  44. * (c) Copyright 1996 FUJITSU LIMITED.
  45. * (c) Copyright 1996 Hitachi.
  46. */
  47. /*+++++++++++++++++++++++++++++++++++++++*/
  48. /* include files */
  49. /*+++++++++++++++++++++++++++++++++++++++*/
  50. #include "signal.h"
  51. #include <sys/wait.h>
  52. #ifdef TIME
  53. # include <time.h>
  54. #endif
  55. #ifndef NO_MESSAGE_CATALOG
  56. # include <Dt/MsgCatP.h>
  57. # define TRUE 1
  58. # define FALSE 0
  59. #endif
  60. #include <locale.h>
  61. /* #include <sys/dir.h> */
  62. #include <X11/Xlib.h>
  63. #include <Xm/MwmUtil.h>
  64. #include <Xm/Xm.h>
  65. #include <Xm/XmP.h>
  66. #include <Xm/MessageB.h>
  67. #include <Dt/GetDispRes.h>
  68. #include <Dt/EnvControlP.h>
  69. #include <Dt/Message.h>
  70. #include <Dt/SessionM.h>
  71. #include <Dt/UserMsg.h>
  72. #include <Dt/Wsm.h>
  73. #include <Dt/DtNlUtils.h>
  74. #include <Dt/DtosP.h>
  75. #include "MainWin.h"
  76. #include "ColorMain.h"
  77. #include "ColorFile.h"
  78. #include "Resource.h"
  79. #include "Protocol.h"
  80. /*+++++++++++++++++++++++++++++++++++++++*/
  81. /* include extern functions */
  82. /*+++++++++++++++++++++++++++++++++++++++*/
  83. #include "Main.h"
  84. /*+++++++++++++++++++++++++++++++++++++++*/
  85. /* Local #defines */
  86. /*+++++++++++++++++++++++++++++++++++++++*/
  87. #define STYLE_LOCK "STYLE_LOCK"
  88. #define SYS_FILE_SEARCH_PATH "DTPMSYSFILESEARCHPATH"
  89. #define MAX_STR_LEN 128
  90. /*+++++++++++++++++++++++++++++++++++++++*/
  91. /* Internal Functions */
  92. /*+++++++++++++++++++++++++++++++++++++++*/
  93. static int ErrorHandler(
  94. Display *disp,
  95. XErrorEvent *event ) ;
  96. static int IOErrorHandler(
  97. Display *disp ) ;
  98. static void ToolkitErrorHandler(
  99. char *message) ;
  100. static void errParentMap(
  101. Widget w,
  102. XtPointer client_data,
  103. XEvent *event) ;
  104. static void UnmanageCB(
  105. Widget w,
  106. XtPointer client_data,
  107. XtPointer call_data) ;
  108. static void DestroyCB(
  109. Widget w,
  110. XtPointer client_data,
  111. XtPointer call_data) ;
  112. static Boolean NewCreateD( XtPointer shell) ;
  113. static Boolean NewAddTo( XtPointer shell) ;
  114. static Boolean NewCreateTop1( XtPointer shell) ;
  115. static Boolean NewCreateTop2( XtPointer shell) ;
  116. static Boolean NewAddSysPath( XtPointer shell) ;
  117. static Boolean NewAddDirectories( XtPointer shell) ;
  118. static Boolean NewAddHomePath( XtPointer shell) ;
  119. static Boolean NewReadPal( XtPointer shell) ;
  120. static Boolean NewInitPal( XtPointer shell) ;
  121. static Boolean NewAllocColor( XtPointer shell) ;
  122. static Boolean NewBottomColor( XtPointer shell) ;
  123. static Boolean NewCreateButtons( XtPointer shell) ;
  124. extern void WaitChildDeath(void);
  125. /*++++++++++++++++++++++++++++++++++++++*/
  126. /* Internal Variables */
  127. /*++++++++++++++++++++++++++++++++++++++*/
  128. static XrmOptionDescRec option_list[] =
  129. {
  130. { "-session", "session", XrmoptionSepArg, NULL },
  131. };
  132. /*++++++++++++++++++++++++++++++++++++++*/
  133. /* Global Variables */
  134. /*++++++++++++++++++++++++++++++++++++++*/
  135. Style style;
  136. char *progName;
  137. /*+++++++++++++++++++++++++++++++++++++++++++*/
  138. /*Misc functions all the dialogs use */
  139. /*+++++++++++++++++++++++++++++++++++++++++++*/
  140. /*+++++++++++++++++++++++++++++++++++++++++++*/
  141. /* raise a dialog window above peer dialogs */
  142. /* Needs the SHELL of the dialog, not the */
  143. /* dialog box. */
  144. /*+++++++++++++++++++++++++++++++++++++++++++*/
  145. void
  146. raiseWindow(
  147. Window dialogWin )
  148. {
  149. static int changeMask = CWStackMode;
  150. static XWindowChanges windowChanges = {0,0,0,0,0,0,Above};
  151. XReconfigureWMWindow(style.display, dialogWin,
  152. style.screenNum, changeMask, &windowChanges);
  153. }
  154. /************************************************************************
  155. * CenterMsgCB
  156. * - to be used with message dialogs (assumptions are being made that
  157. * parent is dialog shell, and child is bb, due to Xm hacks for them)
  158. * (eg. it sets bb x,y to 0,0 and parents x,y to x,y set for bb)
  159. * - parent for positioning only (may not be real parent)
  160. * - use client_data for parent... if NULL, use style.errParent if ok,
  161. * - or main style.shell (makes this routine more generally usefull)
  162. *
  163. ************************************************************************/
  164. void
  165. CenterMsgCB(
  166. Widget w,
  167. XtPointer client_data,
  168. XtPointer call_data )
  169. {
  170. int n;
  171. Position newX, newY;
  172. Arg args[4];
  173. Widget shell;
  174. /* figure out what to use as "visual" parent */
  175. shell = (Widget)client_data;
  176. if (shell == NULL)
  177. {
  178. if (!style.errParent || !XtParent(style.errParent) ||
  179. !XtIsManaged(style.errParent))
  180. shell = style.shell;
  181. else
  182. shell = XtParent(style.errParent);
  183. }
  184. else
  185. shell = XtParent(shell);
  186. /* calculate new x,y to be centered in visualParent */
  187. newX = XtX(shell) + XtWidth(shell)/2 - XtWidth(w)/2;
  188. newY = XtY(shell) + XtHeight(shell)/2 - XtHeight(w)/2;
  189. if (newX < 0) newX = 0;
  190. if (newY < 0) newY = 0;
  191. n = 0;
  192. XtSetArg(args[n], XmNx, newX); n++;
  193. XtSetArg(args[n], XmNy, newY); n++;
  194. XtSetValues(w, args, n);
  195. }
  196. /*************************************************************/
  197. /* ErrDialog */
  198. /* Put up an error dialog and block until the user clicks OK */
  199. /* by default, there is no cancel or help button, but the */
  200. /* dialog is created with autoUnmanage false, and ok/cancel */
  201. /* callbacks to do the unmanage, so that a help button can */
  202. /* be used */
  203. /*************************************************************/
  204. void
  205. ErrDialog(
  206. char *errString,
  207. Widget visualParent )
  208. {
  209. int n;
  210. Arg args[10];
  211. XmString ok;
  212. /* create the compound string */
  213. style.tmpXmStr = CMPSTR(errString);
  214. style.errParent = visualParent;
  215. if (style.errDialog == NULL) /* create it */
  216. {
  217. ok = XmStringCreateLocalized((String) _DtOkString);
  218. n = 0;
  219. XtSetArg(args[n], XmNokLabelString, ok); n++;
  220. XtSetArg(args[n], XmNmessageString, style.tmpXmStr); n++;
  221. XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
  222. XtSetArg (args[n], XmNautoUnmanage, False); n++;
  223. XtSetArg (args[n], XmNdefaultPosition, False); n++;
  224. style.errDialog = XmCreateErrorDialog(style.shell,"ErrorNotice",args,n);
  225. XtAddCallback (style.errDialog, XmNokCallback, UnmanageCB, NULL);
  226. XtAddCallback (style.errDialog, XmNcancelCallback, UnmanageCB, NULL);
  227. XtAddCallback (style.errDialog, XmNmapCallback, CenterMsgCB, NULL);
  228. XtUnmanageChild ( XmMessageBoxGetChild (style.errDialog,
  229. XmDIALOG_CANCEL_BUTTON));
  230. XtUnmanageChild ( XmMessageBoxGetChild (style.errDialog,
  231. XmDIALOG_HELP_BUTTON));
  232. /* set the dialog shell parent title */
  233. n=0;
  234. XtSetArg (args[n], XmNmwmInputMode,
  235. MWM_INPUT_PRIMARY_APPLICATION_MODAL); n++;
  236. XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
  237. XtSetArg (args[n], XmNtitle, ((char *)GETMESSAGE(2, 3, "Error"))); n++;
  238. XtSetValues (XtParent(style.errDialog), args, n);
  239. }
  240. else /* change the string */
  241. {
  242. n = 0;
  243. XtSetArg(args[n], XmNmessageString, style.tmpXmStr); n++;
  244. XtSetValues (style.errDialog, args, n);
  245. }
  246. /* free the compound string */
  247. XmStringFree (style.tmpXmStr);
  248. if (XtIsManaged(style.errParent) || XtParent(style.errParent) == NULL)
  249. {
  250. XtManageChild(style.errDialog);
  251. /* ring the bell (PM behavior) */
  252. XBell(style.display, 0);
  253. }
  254. else
  255. {
  256. XtAddEventHandler(XtParent(style.errParent), StructureNotifyMask, 0,
  257. (XtEventHandler)errParentMap, NULL);
  258. }
  259. }
  260. static void
  261. errParentMap(
  262. Widget w,
  263. XtPointer client_data,
  264. XEvent *event )
  265. {
  266. if (event->type == MapNotify)
  267. {
  268. XtManageChild(style.errDialog);
  269. /* ring the bell (PM behavior) */
  270. XBell(style.display, 0);
  271. XtRemoveEventHandler(XtParent(style.errParent), StructureNotifyMask,
  272. 0, (XtEventHandler)errParentMap, NULL);
  273. }
  274. }
  275. /*********************************************************/
  276. /* InfoDialog */
  277. /* Put up a modeless info dialog. */
  278. /* There is no cancel or help button. */
  279. /* Dialog is created with autoUnmanage true. */
  280. /* An ok callback is added which will destroy the dialog */
  281. /* and optionally unmap the parent. */
  282. /*********************************************************/
  283. void
  284. InfoDialog(
  285. char *infoString,
  286. Widget parent,
  287. Boolean unmapParent )
  288. {
  289. int n;
  290. Arg args[10];
  291. static XmString ok = NULL;
  292. Widget w;
  293. /* create the compound string */
  294. style.tmpXmStr = CMPSTR(infoString);
  295. if (ok == NULL)
  296. ok = CMPSTR((String) _DtOkString);
  297. /* create it */
  298. n = 0;
  299. XtSetArg(args[n], XmNokLabelString, ok); n++;
  300. XtSetArg(args[n], XmNmessageString, style.tmpXmStr); n++;
  301. XtSetArg(args[n], XmNdialogStyle, XmDIALOG_MODELESS); n++;
  302. XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
  303. w = XmCreateInformationDialog(parent, "Notice", args, n);
  304. if (unmapParent)
  305. XtAddCallback (w, XmNokCallback, DestroyCB, parent);
  306. else
  307. XtAddCallback (w, XmNokCallback, DestroyCB, NULL);
  308. XtUnmanageChild ( XmMessageBoxGetChild(w, XmDIALOG_CANCEL_BUTTON) );
  309. XtUnmanageChild ( XmMessageBoxGetChild(w, XmDIALOG_HELP_BUTTON) );
  310. /* set the dialog shell parent title */
  311. n=0;
  312. XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
  313. XtSetArg (args[n], XmNtitle, ((char *)GETMESSAGE(2, 2, "Notice"))); n++;
  314. XtSetValues (XtParent(w), args, n);
  315. /* free the compound string */
  316. XmStringFree (style.tmpXmStr);
  317. /* manage the info dialog */
  318. XtManageChild(w);
  319. }
  320. /*++++++++++++++++++++++++++++++++++++++*/
  321. /* UnmanageCB */
  322. /*++++++++++++++++++++++++++++++++++++++*/
  323. static void
  324. UnmanageCB(
  325. Widget w,
  326. XtPointer client_data,
  327. XtPointer call_data )
  328. {
  329. XtUnmanageChild(w);
  330. }
  331. /*++++++++++++++++++++++++++++++++++++++*/
  332. /* DestroyCB */
  333. /*++++++++++++++++++++++++++++++++++++++*/
  334. static void
  335. DestroyCB(
  336. Widget w,
  337. XtPointer client_data,
  338. XtPointer call_data )
  339. {
  340. XtDestroyWidget(XtParent(w));
  341. if (client_data != NULL)
  342. XtUnmanageChild((Widget)client_data);
  343. }
  344. /**********************************************************/
  345. /* putDialog */
  346. /* move a dialog up so it isn't covering the main window */
  347. /* Or down if there is no room up. */
  348. /* note: "parent" needs to have valid x,y information... */
  349. /* ex: a child of dialog shell doesn't, its parent */
  350. /* does, so the parent shell would be passed in */
  351. /**********************************************************/
  352. void
  353. putDialog(
  354. Widget parent,
  355. Widget dialog )
  356. {
  357. int n;
  358. Position newX, newY, pY, pX;
  359. Dimension pHeight, myHeight, pWidth, myWidth;
  360. Arg args[4];
  361. pX = XtX(parent);
  362. pY = XtY(parent);
  363. pHeight = XtHeight(parent);
  364. pWidth = XtWidth(parent);
  365. myHeight = XtHeight(dialog);
  366. myWidth = XtWidth(dialog);
  367. if ((newY = pY - myHeight +5) < 0)
  368. newY = pY + pHeight;
  369. newX = pX + pWidth/2 - myWidth/2;
  370. n = 0;
  371. XtSetArg(args[n], XmNx, newX); n++;
  372. XtSetArg(args[n], XmNy, newY); n++;
  373. XtSetValues(dialog,args,n);
  374. #ifdef PutDDEBUG
  375. printf("newX, newY, pY, pX;\n");
  376. printf("%d %d %d %d\n",newX, newY, pY, pX);
  377. printf("pHeight, myHeight, pWidth, myWidth;\n");
  378. printf("%d %d %d %d\n", pHeight, myHeight, pWidth, myWidth);
  379. #endif
  380. }
  381. /*++++++++++++++++++++++++++++++++++++++*/
  382. /* main */
  383. /*++++++++++++++++++++++++++++++++++++++*/
  384. int
  385. main(
  386. int argc,
  387. char **argv )
  388. {
  389. int n;
  390. Arg args[MAX_ARGS];
  391. XEvent event;
  392. XPropertyEvent *pEvent=(XPropertyEvent *)&event;
  393. long mwmFunc;
  394. Boolean useMaskRtn, useIconFileCacheRtn;
  395. char *dirs = NULL;
  396. char *string;
  397. Visual *visual;
  398. #ifdef USERHELP
  399. malloc_check(1);
  400. malloc_trace(0);
  401. #endif
  402. XtSetLanguageProc(NULL, NULL, NULL);
  403. _DtEnvControl(DT_ENV_SET);
  404. /* Initialize the toolkit and open the display */
  405. style.shell =
  406. XtInitialize(argv[0], XMCLASS, option_list, 1, (int *)&argc, argv);
  407. /* Allow all WS manipulation functions except resize and maximize */
  408. mwmFunc = MWM_FUNC_ALL ^ (MWM_FUNC_RESIZE | MWM_FUNC_MAXIMIZE);
  409. n = 0;
  410. XtSetArg(args[n], XmNmwmFunctions, mwmFunc); n++;
  411. XtSetArg(args[n], XmNuseAsyncGeometry, True); n++;
  412. XtSetValues(style.shell, args, n);
  413. /* initialize global style data */
  414. style.display = XtDisplay(style.shell);
  415. style.screen = DefaultScreenOfDisplay(style.display);
  416. style.screenNum = DefaultScreen(style.display);
  417. style.colormap = DefaultColormap(style.display, style.screenNum);
  418. style.root = DefaultRootWindow(style.display);
  419. style.execName = argv[0];
  420. style.errDialog = NULL;
  421. style.tmpXmStr = NULL;
  422. style.home = (char *) XtMalloc(strlen((char *) getenv("HOME")) + 1);
  423. strcpy(style.home, (char *) getenv("HOME"));
  424. style.colorDialog = NULL;
  425. style.backdropDialog = NULL;
  426. style.fontDialog = NULL;
  427. style.kbdDialog = NULL;
  428. style.mouseDialog = NULL;
  429. style.audioDialog = NULL;
  430. style.screenDialog = NULL;
  431. style.startupDialog = NULL;
  432. style.dtwmDialog = NULL;
  433. style.i18nDialog = NULL;
  434. visual = XDefaultVisual(style.display,style.screenNum);
  435. style.visualClass = visual->class;
  436. if (progName = DtStrrchr(argv[0], '/')) progName++;
  437. else progName = argv[0];
  438. /* Get the lock established to ensure only one dtstyle process
  439. * is running per screen .. first malloc enough space*/
  440. if (_DtGetLock (style.display, STYLE_LOCK) == 0)
  441. {
  442. _DtSimpleError (progName, DtError, NULL, "%s",
  443. ((char *)GETMESSAGE(2, 5, "Style Manager is already running, second attempt aborted.")));
  444. exit(1);
  445. }
  446. InitDtstyleProtocol();
  447. SetWindowProperties();
  448. /* Register error handlers */
  449. XSetErrorHandler(ErrorHandler);
  450. XSetIOErrorHandler(IOErrorHandler);
  451. XtAppSetErrorHandler(XtWidgetToApplicationContext(style.shell),
  452. ToolkitErrorHandler);
  453. XtAddEventHandler(style.shell, StructureNotifyMask, 0,
  454. (XtEventHandler)MwmReparentNotify, NULL);
  455. /* set up resolution dependent layout variables */
  456. switch (_DtGetDisplayResolution(style.display, style.screenNum))
  457. {
  458. case LOW_RES_DISPLAY:
  459. style.horizontalSpacing =
  460. style.verticalSpacing = 3;
  461. break;
  462. case MED_RES_DISPLAY:
  463. style.horizontalSpacing =
  464. style.verticalSpacing = 5;
  465. break;
  466. case HIGH_RES_DISPLAY:
  467. style.horizontalSpacing =
  468. style.verticalSpacing = 8;
  469. break;
  470. }
  471. GetApplicationResources();
  472. XmeGetIconControlInfo(style.screen, &useMaskRtn,
  473. &style.useMultiColorIcons, &useIconFileCacheRtn);
  474. /* add the directory $HOME/.dt/backdrops */
  475. string = (char *)XtMalloc(strlen(style.home) + strlen("/.dt/backdrops:") + 1);
  476. sprintf(string, "%s/.dt/backdrops:", style.home);
  477. dirs = (char *)XtCalloc(1, strlen("/etc/dt/backdrops:/usr/dt/backdrops") +
  478. (style.xrdb.backdropDir == NULL ? 2 :
  479. strlen(style.xrdb.backdropDir)) +
  480. strlen(string) + 2);
  481. strcpy(dirs, string);
  482. if (style.xrdb.backdropDir)
  483. {
  484. strcat(dirs, style.xrdb.backdropDir);
  485. strcat(dirs, ":");
  486. }
  487. strcat(dirs, "/etc/dt/backdrops:/usr/dt/backdrops");
  488. _DtWsmSetBackdropSearchPath(style.screen, dirs, style.useMultiColorIcons);
  489. XtFree((char *)string);
  490. XtFree((char *)dirs);
  491. style.count = 0;
  492. /* if this is started from save session we need to set up the BMS
  493. first, otherwise do it after making the window. (for user perception
  494. for how long it takes for the dtstyle to come up) */
  495. if(style.xrdb.session != NULL) {
  496. DtInitialize (style.display, style.shell, progName, progName);
  497. /*Restore a session or build and display the main Window.*/
  498. if(!restoreSession(style.shell,style.xrdb.session))
  499. init_mainWindow(style.shell);
  500. }
  501. else {
  502. init_mainWindow(style.shell);
  503. DtInitialize (style.display, style.shell, progName, progName);
  504. InitializeAtoms();
  505. CheckMonitor(style.shell);
  506. GetDefaultPal(style.shell);
  507. }
  508. signal(SIGINT,(void (*)())activateCB_exitBtn);
  509. signal(SIGTERM,(void (*)())activateCB_exitBtn);
  510. /* to avoid defunct screen saver processes */
  511. signal(SIGCHLD, (void (*)())WaitChildDeath);
  512. /* backdrop dialog needs to know when the workspace changes to recolor
  513. the bitmap displayed in the dialog */
  514. ListenForWorkspaceChange();
  515. /* if using COLOR builtin, style.workProcs is True */
  516. if ((XmeUseColorObj() != FALSE) && style.workProcs)
  517. XtAppAddWorkProc(XtWidgetToApplicationContext(style.shell),
  518. NewCreateD, style.shell);
  519. XtAppMainLoop(XtWidgetToApplicationContext(style.shell));
  520. return 0;
  521. }
  522. /************************************************************************
  523. *
  524. * ErrorHandler
  525. *
  526. ************************************************************************/
  527. static int
  528. ErrorHandler(
  529. Display *disp,
  530. XErrorEvent *event )
  531. {
  532. #define _DTSTYLE_BUFSIZE 1024
  533. char errmsg[_DTSTYLE_BUFSIZE];
  534. _DtPrintDefaultErrorSafe(disp, event, errmsg, _DTSTYLE_BUFSIZE);
  535. _DtSimpleError(progName, DtWarning, NULL, errmsg, NULL);
  536. /* We do not want to exit here lets try to continue... */
  537. return 1;
  538. }
  539. /************************************************************************
  540. *
  541. * IOErrorHandler
  542. *
  543. ************************************************************************/
  544. static int
  545. IOErrorHandler (Display *display)
  546. {
  547. #ifdef DEBUG
  548. Warning ("X IO error occurred during generic operation");
  549. #endif /* DEBUG */
  550. exit (1);
  551. return 1;
  552. }
  553. /************************************************************************
  554. *
  555. * ToolkitErrorHandler
  556. *
  557. * All Xt memory allocation errors should fall through to this routine.
  558. * There is no need to check for Xtmalloc errors where they are used.
  559. *
  560. ************************************************************************/
  561. static void
  562. ToolkitErrorHandler(
  563. char *message )
  564. {
  565. _DtSimpleError (progName, DtError, NULL,
  566. GETMESSAGE(2, 6, "An X Toolkit error occurred... Exiting.\n"));
  567. exit (1);
  568. }
  569. static Boolean
  570. NewCreateD(
  571. XtPointer shell )
  572. {
  573. #ifdef TIME
  574. struct timeval first, second, lapsed;
  575. struct timezone tzp;
  576. gettimeofday(&first, &tzp);
  577. #endif
  578. /* Create the Dialog Box Dialog */
  579. CreateDialogBoxD((Widget)shell);
  580. #ifdef TIME
  581. gettimeofday(&second, &tzp);
  582. if(first.tv_usec > second.tv_usec){
  583. second.tv_usec += 1000000;
  584. second.tv_sec--;
  585. }
  586. printf("CreateDialogBoxD elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
  587. #endif
  588. XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewAddTo, shell);
  589. return(True);
  590. }
  591. static Boolean
  592. NewAddTo(
  593. XtPointer shell )
  594. {
  595. #ifdef TIME
  596. struct timeval first, second, lapsed;
  597. struct timezone tzp;
  598. gettimeofday(&first, &tzp);
  599. #endif
  600. /* Create the Dialog Box Dialog */
  601. AddToDialogBox();
  602. #ifdef TIME
  603. gettimeofday(&second, &tzp);
  604. if(first.tv_usec > second.tv_usec){
  605. second.tv_usec += 1000000;
  606. second.tv_sec--;
  607. }
  608. printf("AddToDialogBox elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
  609. #endif
  610. XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewCreateTop1, shell);
  611. return(True);
  612. }
  613. static Boolean
  614. NewCreateTop1(
  615. XtPointer shell )
  616. {
  617. #ifdef TIME
  618. struct timeval first, second, lapsed;
  619. struct timezone tzp;
  620. gettimeofday(&first, &tzp);
  621. #endif
  622. /* Create the top portion of the color dialog */
  623. CreateTopColor1();
  624. #ifdef TIME
  625. gettimeofday(&second, &tzp);
  626. if(first.tv_usec > second.tv_usec){
  627. second.tv_usec += 1000000;
  628. second.tv_sec--;
  629. }
  630. printf("CreateTopColor1 elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
  631. #endif
  632. XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewCreateTop2, shell);
  633. return(True);
  634. }
  635. static Boolean
  636. NewCreateTop2(
  637. XtPointer shell )
  638. {
  639. #ifdef TIME
  640. struct timeval first, second, lapsed;
  641. struct timezone tzp;
  642. gettimeofday(&first, &tzp);
  643. #endif
  644. /* Create the top portion of the color dialog */
  645. CreateTopColor2();
  646. #ifdef TIME
  647. gettimeofday(&second, &tzp);
  648. if(first.tv_usec > second.tv_usec){
  649. second.tv_usec += 1000000;
  650. second.tv_sec--;
  651. }
  652. printf("CreateTopColor2 elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
  653. #endif
  654. XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewAddSysPath, shell);
  655. return(True);
  656. }
  657. static Boolean
  658. NewAddSysPath(
  659. XtPointer shell )
  660. {
  661. #ifdef TIME
  662. struct timeval first, second, lapsed;
  663. struct timezone tzp;
  664. gettimeofday(&first, &tzp);
  665. #endif
  666. /* initialize the system directory */
  667. AddSystemPath();
  668. #ifdef TIME
  669. gettimeofday(&second, &tzp);
  670. if(first.tv_usec > second.tv_usec){
  671. second.tv_usec += 1000000;
  672. second.tv_sec--;
  673. }
  674. printf("AddSystemPath elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
  675. #endif
  676. XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewAddDirectories, shell);
  677. return(True);
  678. }
  679. static Boolean
  680. NewAddDirectories(
  681. XtPointer shell )
  682. {
  683. #ifdef TIME
  684. struct timeval first, second, lapsed;
  685. struct timezone tzp;
  686. gettimeofday(&first, &tzp);
  687. #endif
  688. /* initialize the directorys list in the resource */
  689. if(style.xrdb.paletteDir != NULL)
  690. AddDirectories(style.xrdb.paletteDir);
  691. else
  692. style.count++;
  693. #ifdef TIME
  694. gettimeofday(&second, &tzp);
  695. if(first.tv_usec > second.tv_usec){
  696. second.tv_usec += 1000000;
  697. second.tv_sec--;
  698. }
  699. printf("AddDirectories elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
  700. #endif
  701. XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewAddHomePath, shell);
  702. return(True);
  703. }
  704. static Boolean
  705. NewAddHomePath(
  706. XtPointer shell )
  707. {
  708. #ifdef TIME
  709. struct timeval first, second, lapsed;
  710. struct timezone tzp;
  711. gettimeofday(&first, &tzp);
  712. #endif
  713. /* initialize the home directory */
  714. AddHomePath();
  715. #ifdef TIME
  716. gettimeofday(&second, &tzp);
  717. if(first.tv_usec > second.tv_usec){
  718. second.tv_usec += 1000000;
  719. second.tv_sec--;
  720. }
  721. printf("AddHomePath elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
  722. #endif
  723. XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewReadPal, shell);
  724. return(True);
  725. }
  726. static Boolean
  727. NewReadPal(
  728. XtPointer shell )
  729. {
  730. #ifdef TIME
  731. struct timeval first, second, lapsed;
  732. struct timezone tzp;
  733. gettimeofday(&first, &tzp);
  734. #endif
  735. /* Read in the palettes one at a time */
  736. if (ReadPaletteLoop(True)) {
  737. #ifdef TIME
  738. gettimeofday(&second, &tzp);
  739. if(first.tv_usec > second.tv_usec){
  740. second.tv_usec += 1000000;
  741. second.tv_sec--;
  742. }
  743. printf("ReadPaletteLoop DONE elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
  744. #endif
  745. /* Stop work procs if no palettes found - fatal color error.
  746. * When the color button is pressed, the regular processing
  747. * will pick up on NumOfPalettes == 0 and post an error
  748. * dialog */
  749. if (NumOfPalettes == 0)
  750. return(True);
  751. loadDatabase();
  752. XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewInitPal, shell);
  753. return(True);
  754. }
  755. #ifdef TIME
  756. gettimeofday(&second, &tzp);
  757. if(first.tv_usec > second.tv_usec){
  758. second.tv_usec += 1000000;
  759. second.tv_sec--;
  760. }
  761. printf("ReadPaletteLoop NOT DONE elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
  762. #endif
  763. return(False);
  764. }
  765. static Boolean
  766. NewInitPal(
  767. XtPointer shell )
  768. {
  769. #ifdef TIME
  770. struct timeval first, second, lapsed;
  771. struct timezone tzp;
  772. gettimeofday(&first, &tzp);
  773. #endif
  774. /* initialize the palette list */
  775. if(InitializePaletteList((Widget)shell, paletteList, True)) {
  776. #ifdef TIME
  777. gettimeofday(&second, &tzp);
  778. if(first.tv_usec > second.tv_usec){
  779. second.tv_usec += 1000000;
  780. second.tv_sec--;
  781. }
  782. printf("InitializePaletteList DONE elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
  783. #endif
  784. XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewAllocColor, shell);
  785. return(True);
  786. }
  787. #ifdef TIME
  788. gettimeofday(&second, &tzp);
  789. if(first.tv_usec > second.tv_usec){
  790. second.tv_usec += 1000000;
  791. second.tv_sec--;
  792. }
  793. printf("InitializePaletteList NOT DONE elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
  794. #endif
  795. return(False);
  796. }
  797. static Boolean
  798. NewAllocColor(
  799. XtPointer shell )
  800. {
  801. #ifdef TIME
  802. struct timeval first, second, lapsed;
  803. struct timezone tzp;
  804. gettimeofday(&first, &tzp);
  805. #endif
  806. /* initialize pixels to the right color */
  807. AllocatePaletteCells((Widget)shell);
  808. #ifdef TIME
  809. gettimeofday(&second, &tzp);
  810. if(first.tv_usec > second.tv_usec){
  811. second.tv_usec += 1000000;
  812. second.tv_sec--;
  813. }
  814. printf("AllocatePaletteCells elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
  815. #endif
  816. XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewBottomColor, shell);
  817. return(True);
  818. }
  819. static Boolean
  820. NewBottomColor(
  821. XtPointer shell )
  822. {
  823. #ifdef TIME
  824. struct timeval first, second, lapsed;
  825. struct timezone tzp;
  826. gettimeofday(&first, &tzp);
  827. #endif
  828. /* Create the bottom portion of the color dialog */
  829. CreateBottomColor();
  830. #ifdef TIME
  831. gettimeofday(&second, &tzp);
  832. if(first.tv_usec > second.tv_usec){
  833. second.tv_usec += 1000000;
  834. second.tv_sec--;
  835. }
  836. printf("CreateBottomColor elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
  837. #endif
  838. XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewCreateButtons, shell);
  839. return(True);
  840. }
  841. static Boolean
  842. NewCreateButtons(
  843. XtPointer shell )
  844. {
  845. #ifdef TIME
  846. struct timeval first, second, lapsed;
  847. struct timezone tzp;
  848. gettimeofday(&first, &tzp);
  849. #endif
  850. /* initialize pixels to the right color */
  851. CreatePaletteButtons(style.buttonsForm);
  852. #ifdef TIME
  853. gettimeofday(&second, &tzp);
  854. if(first.tv_usec > second.tv_usec){
  855. second.tv_usec += 1000000;
  856. second.tv_sec--;
  857. }
  858. printf("CreatePaletteButtons elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
  859. #endif
  860. return(True);
  861. }
  862. /*************************************<->*************************************
  863. *
  864. * WaitChildDeath()
  865. *
  866. *
  867. * Description:
  868. * -----------
  869. * When a SIGCHLD signal comes in, wait for all child processes to die.
  870. *
  871. *
  872. * Inputs:
  873. * ------
  874. *
  875. * Outputs:
  876. * -------
  877. *
  878. *
  879. * Comments:
  880. * --------
  881. *
  882. *************************************<->***********************************/
  883. void
  884. WaitChildDeath( void )
  885. {
  886. int stat_loc;
  887. pid_t pid;
  888. pid = wait(&stat_loc);
  889. signal(SIGCHLD,(void (*)())WaitChildDeath);
  890. }