main.c revision d859ff80
1/* $XConsortium: main.c,v 2.30 95/01/25 14:33:57 swick Exp $ 2 * 3 * 4 * COPYRIGHT 1987, 1989 5 * DIGITAL EQUIPMENT CORPORATION 6 * MAYNARD, MASSACHUSETTS 7 * ALL RIGHTS RESERVED. 8 * 9 * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND 10 * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION. 11 * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR 12 * ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 13 * 14 * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT 15 * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN 16 * ADDITION TO THAT SET FORTH ABOVE. 17 * 18 * Permission to use, copy, modify, and distribute this software and its 19 * documentation for any purpose and without fee is hereby granted, provided 20 * that the above copyright notice appear in all copies and that both that 21 * copyright notice and this permission notice appear in supporting 22 * documentation, and that the name of Digital Equipment Corporation not be 23 * used in advertising or publicity pertaining to distribution of the software 24 * without specific, written prior permission. 25 */ 26/* $XFree86: xc/programs/xmh/main.c,v 1.2 2001/08/01 00:45:06 tsi Exp $ */ 27 28#include "xmh.h" 29#include "actions.h" 30 31Display *theDisplay; /* Display variable. */ 32Widget toplevel; /* The top level widget (A hack %%%). */ 33char *progName; /* Program name. */ 34char *homeDir; /* User's home directory. */ 35Atom wm_protocols; /* WM_PROTOCOLS atom for this display */ 36Atom wm_delete_window; /* see ICCCM on Window Deletion */ 37Atom wm_save_yourself; /* see ICCCM on session management */ 38Atom protocolList[2]; /* contains the two above */ 39 40struct _resources app_resources; 41 42char *draftFile; /* Filename of draft. */ 43char *xmhDraftFile; /* Filename for sending. */ 44Toc *folderList; /* Array of folders. */ 45int numFolders; /* Number of entries in above array. */ 46Toc InitialFolder; /* Toc containing initial folder. */ 47Toc DraftsFolder; /* Toc containing drafts. */ 48Scrn *scrnList; /* Array of scrns in use. */ 49int numScrns; /* Number of scrns in above array. */ 50Widget NoMenuForButton; /* Flag menu widget value: no menu */ 51Widget LastMenuButtonPressed; /* to `toggle' menu buttons */ 52Widget NullSource; /* null text widget source */ 53Dimension rootwidth; /* Dimensions of root window. */ 54Dimension rootheight; 55Pixmap MenuItemBitmap; /* Options menu item checkmark */ 56XtTranslations NoTextSearchAndReplace; /* no-op ^S and ^R in Text */ 57 58struct _LastInput lastInput; 59 60Boolean subProcessRunning; /* interlock for DoCommand/CheckMail */ 61 62/*ARGSUSED*/ 63static void NeedToCheckScans( 64 XtPointer client_data, 65 XtIntervalId *id) /* unused */ 66{ 67 int i; 68 if (!subProcessRunning) { 69 DEBUG("[magic toc check ...") 70 for (i = 0; i < numScrns; i++) { 71 if (scrnList[i]->toc) 72 TocRecheckValidity(scrnList[i]->toc); 73 if (scrnList[i]->msg) 74 TocRecheckValidity(MsgGetToc(scrnList[i]->msg)); 75 } 76 DEBUG(" done]\n") 77 } 78 (void) XtAppAddTimeOut((XtAppContext)client_data, 79 (unsigned long) app_resources.rescan_interval, 80 NeedToCheckScans, client_data); 81} 82 83/*ARGSUSED*/ 84static void Checkpoint( 85 XtPointer client_data, 86 XtIntervalId *id) /* unused */ 87{ 88 if (!subProcessRunning) { 89 Cardinal n = 1; 90 String params = "wm_save_yourself"; 91 DEBUG("(Checkpointing...") 92 XmhWMProtocols(NULL, NULL, ¶ms, &n); 93 DEBUG(" done)\n") 94 } 95 (void) XtAppAddTimeOut((XtAppContext)client_data, 96 (unsigned long) app_resources.checkpoint_interval, 97 Checkpoint, client_data); 98} 99 100/*ARGSUSED*/ 101static void CheckMail( 102 XtPointer client_data, 103 XtIntervalId *id) /* unused */ 104{ 105 if (!subProcessRunning) { 106 DEBUG("(Checking for new mail...") 107 XmhCheckForNewMail(NULL, NULL, NULL, NULL); 108 DEBUG(" done)\n") 109 } 110 (void) XtAppAddTimeOut((XtAppContext)client_data, 111 (unsigned long) app_resources.mail_interval, 112 CheckMail, client_data); 113} 114 115/* Main loop. */ 116 117#ifdef DEBUG_CLEANUP 118Boolean ExitLoop = FALSE; 119#endif 120 121int main(int argc, char **argv) 122{ 123 XtAppContext appCtx; 124 125 InitializeWorld(argc, argv); 126 subProcessRunning = False; 127 appCtx = XtWidgetToApplicationContext(toplevel); 128 (void) XtAppSetWarningMsgHandler(appCtx, PopupWarningHandler); 129 130 if (app_resources.new_mail_check && app_resources.mail_interval > 0) { 131 app_resources.mail_interval *= 60000; 132 (void) XtAppAddTimeOut(appCtx, (unsigned long) 0, 133 CheckMail, (XtPointer)appCtx); 134 } 135 if (app_resources.rescan_interval > 0) { 136 app_resources.rescan_interval *= 60000; 137 (void) XtAppAddTimeOut(appCtx, 138 (unsigned long) app_resources.rescan_interval, 139 NeedToCheckScans, (XtPointer)appCtx); 140 } 141 if (app_resources.make_checkpoints && 142 app_resources.checkpoint_interval > 0) { 143 app_resources.checkpoint_interval *= 60000; 144 (void) XtAppAddTimeOut(appCtx, (unsigned long) 145 app_resources.checkpoint_interval, 146 Checkpoint, (XtPointer)appCtx); 147 } 148 149 lastInput.win = -1; /* nothing mapped yet */ 150#ifdef DEBUG_CLEANUP 151 while (!ExitLoop) { 152#else 153 for (;;) { 154#endif 155 XEvent ev; 156 XtAppNextEvent( appCtx, &ev ); 157 if (ev.type == KeyPress) { 158 lastInput.win = ev.xany.window; 159 lastInput.x = ev.xkey.x_root; 160 lastInput.y = ev.xkey.y_root; 161 } else if (ev.type == ButtonPress) { 162 lastInput.win = ev.xany.window; 163 lastInput.x = ev.xbutton.x_root; 164 lastInput.y = ev.xbutton.y_root; 165 } 166 XtDispatchEvent( &ev ); 167 } 168#ifdef DEBUG_CLEANUP 169 XtDestroyApplicationContext(appCtx); 170#endif 171 exit(0); 172} 173