main.c revision c9e2be55
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#define MAIN 1			/* Makes global.h actually declare vars */
29#include "xmh.h"
30#include "actions.h"
31
32/*ARGSUSED*/
33static void NeedToCheckScans(
34    XtPointer client_data,
35    XtIntervalId *id)		/* unused */
36{
37    int i;
38    if (!subProcessRunning) {
39        DEBUG("[magic toc check ...")
40	for (i = 0; i < numScrns; i++) {
41	    if (scrnList[i]->toc)
42		TocRecheckValidity(scrnList[i]->toc);
43	    if (scrnList[i]->msg)
44		TocRecheckValidity(MsgGetToc(scrnList[i]->msg));
45	}
46        DEBUG(" done]\n")
47    }
48    (void) XtAppAddTimeOut((XtAppContext)client_data,
49			   (unsigned long) app_resources.rescan_interval,
50			   NeedToCheckScans, client_data);
51}
52
53/*ARGSUSED*/
54static void Checkpoint(
55    XtPointer client_data,
56    XtIntervalId *id)		/* unused */
57{
58    if (!subProcessRunning) {
59	Cardinal n = 1;
60	String params = "wm_save_yourself";
61	DEBUG("(Checkpointing...")
62	XmhWMProtocols(NULL, NULL, &params, &n);
63        DEBUG(" done)\n")
64    }
65    (void) XtAppAddTimeOut((XtAppContext)client_data,
66			   (unsigned long) app_resources.checkpoint_interval,
67			   Checkpoint, client_data);
68}
69
70/*ARGSUSED*/
71static void CheckMail(
72    XtPointer client_data,
73    XtIntervalId *id)		/* unused */
74{
75    if (!subProcessRunning) {
76        DEBUG("(Checking for new mail...")
77        XmhCheckForNewMail(NULL, NULL, NULL, NULL);
78        DEBUG(" done)\n")
79    }
80    (void) XtAppAddTimeOut((XtAppContext)client_data,
81			   (unsigned long) app_resources.mail_interval,
82			   CheckMail, client_data);
83}
84
85/* Main loop. */
86
87#ifdef DEBUG_CLEANUP
88Boolean ExitLoop = FALSE;
89#endif
90
91int main(int argc, char **argv)
92{
93    XtAppContext appCtx;
94
95    InitializeWorld(argc, argv);
96    subProcessRunning = False;
97    appCtx = XtWidgetToApplicationContext(toplevel);
98    (void) XtAppSetWarningMsgHandler(appCtx, PopupWarningHandler);
99
100    if (app_resources.new_mail_check && app_resources.mail_interval > 0) {
101	app_resources.mail_interval *= 60000;
102	(void) XtAppAddTimeOut(appCtx, (unsigned long) 0,
103			       CheckMail, (XtPointer)appCtx);
104    }
105    if (app_resources.rescan_interval > 0) {
106	app_resources.rescan_interval *= 60000;
107	(void) XtAppAddTimeOut(appCtx,
108			       (unsigned long) app_resources.rescan_interval,
109			       NeedToCheckScans, (XtPointer)appCtx);
110    }
111    if (app_resources.make_checkpoints &&
112	app_resources.checkpoint_interval > 0) {
113	app_resources.checkpoint_interval *= 60000;
114	(void) XtAppAddTimeOut(appCtx, (unsigned long)
115			       app_resources.checkpoint_interval,
116			       Checkpoint, (XtPointer)appCtx);
117    }
118
119    lastInput.win = -1;		/* nothing mapped yet */
120#ifdef DEBUG_CLEANUP
121    while (!ExitLoop) {
122#else
123    for (;;) {
124#endif
125	XEvent ev;
126	XtAppNextEvent( appCtx, &ev );
127	if (ev.type == KeyPress) {
128	    lastInput.win = ev.xany.window;
129	    lastInput.x = ev.xkey.x_root;
130	    lastInput.y = ev.xkey.y_root;
131	} else if (ev.type == ButtonPress) {
132	    lastInput.win = ev.xany.window;
133	    lastInput.x = ev.xbutton.x_root;
134	    lastInput.y = ev.xbutton.y_root;
135	}
136	XtDispatchEvent( &ev );
137    }
138#ifdef DEBUG_CLEANUP
139    XtDestroyApplicationContext(appCtx);
140#endif
141    exit(0);
142}
143