Main.c 30 KB

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