1 /* $XConsortium: xbiff.c,v 1.19 94/04/17 20:43:28 rws Exp $ */
2 /*
3 
4 Copyright (c) 1988  X Consortium
5 
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13 
14 The above copyright notice and this permission notice shall be included
15 in all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 OTHER DEALINGS IN THE SOFTWARE.
24 
25 Except as contained in this notice, the name of the X Consortium shall
26 not be used in advertising or otherwise to promote the sale, use or
27 other dealings in this Software without prior written authorization
28 from the X Consortium.
29 
30 */
31 /* $XFree86: xc/programs/xbiff/xbiff.c,v 1.3tsi Exp $ */
32 
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <X11/Xatom.h>
36 #include <X11/Intrinsic.h>
37 #include <X11/StringDefs.h>
38 #include "Mailbox.h"
39 #include <X11/Xaw/Cardinals.h>
40 
41 static const char *ProgramName;
42 
43 static XrmOptionDescRec options[] = {
44 { "-update", "*mailbox.update", XrmoptionSepArg, (caddr_t) NULL },
45 { "-file",   "*mailbox.file", XrmoptionSepArg, (caddr_t) NULL },
46 { "-volume", "*mailbox.volume", XrmoptionSepArg, (caddr_t) NULL },
47 { "-shape",  "*mailbox.shapeWindow", XrmoptionNoArg, (caddr_t) "on" },
48 };
49 
50 static Atom wm_delete_window;
51 
quit(Widget w,XEvent * event,String * params,Cardinal * num_params)52 static void quit (Widget w, XEvent *event, String *params, Cardinal *num_params)
53 {
54     if (event->type == ClientMessage &&
55         ((Atom) event->xclient.data.l[0]) != wm_delete_window) {
56         XBell (XtDisplay(w), 0);
57         return;
58     }
59     XCloseDisplay (XtDisplay(w));
60     exit (0);
61 }
62 
63 static XtActionsRec xbiff_actions[] = {
64     { "quit", quit },
65 };
66 
Usage(void)67 static void Usage (void)
68 {
69     static const char *help_message[] = {
70 "where options include:",
71 "    -display host:dpy              X server to contact",
72 "    -geometry geom                 size of mailbox",
73 "    -file file                     file to watch",
74 "    -update seconds                how often to check for mail",
75 "    -volume percentage             how loud to ring the bell",
76 "    -bg color                      background color",
77 "    -fg color                      foreground color",
78 "    -rv                            reverse video",
79 "    -shape                         shape the window",
80 NULL};
81     const char **cpp;
82 
83     fprintf (stderr, "usage:  %s [-options ...]\n", ProgramName);
84     for (cpp = help_message; *cpp; cpp++)
85 	fprintf (stderr, "%s\n", *cpp);
86     fprintf (stderr, "\n");
87     exit (1);
88 }
89 
90 
91 int
main(int argc,char ** argv)92 main (int argc, char **argv)
93 {
94     XtAppContext xtcontext;
95     Widget toplevel;
96 
97     ProgramName = argv[0];
98 
99     XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL);
100 
101     toplevel = XtAppInitialize(&xtcontext, "XBiff", options, XtNumber (options),
102 			       &argc, argv, NULL, NULL, 0);
103     if (argc != 1) Usage ();
104 
105     /*
106      * This is a hack so that f.delete will do something useful in this
107      * single-window application.
108      */
109     wm_delete_window = XInternAtom (XtDisplay(toplevel), "WM_DELETE_WINDOW",
110                                     False);
111     XtAppAddActions (xtcontext, xbiff_actions, XtNumber(xbiff_actions));
112     XtOverrideTranslations(toplevel,
113 		   XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
114 
115     (void) XtCreateManagedWidget ("mailbox", mailboxWidgetClass, toplevel,
116 				  NULL, 0);
117     XtRealizeWidget (toplevel);
118     (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
119                             &wm_delete_window, 1);
120     XtAppMainLoop (xtcontext);
121 
122     return 0;
123 }
124