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