Main.c 30 KB

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