1a1d141d5Smrg/*
2a1d141d5Smrg
3a1d141d5SmrgCopyright (c) 1991  X Consortium
4a1d141d5Smrg
5a1d141d5SmrgPermission is hereby granted, free of charge, to any person obtaining
6a1d141d5Smrga copy of this software and associated documentation files (the
7a1d141d5Smrg"Software"), to deal in the Software without restriction, including
8a1d141d5Smrgwithout limitation the rights to use, copy, modify, merge, publish,
9a1d141d5Smrgdistribute, sublicense, and/or sell copies of the Software, and to
10a1d141d5Smrgpermit persons to whom the Software is furnished to do so, subject to
11a1d141d5Smrgthe following conditions:
12a1d141d5Smrg
13a1d141d5SmrgThe above copyright notice and this permission notice shall be included
14a1d141d5Smrgin all copies or substantial portions of the Software.
15a1d141d5Smrg
16a1d141d5SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17a1d141d5SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18a1d141d5SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19a1d141d5SmrgIN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
20a1d141d5SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21a1d141d5SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22a1d141d5SmrgOTHER DEALINGS IN THE SOFTWARE.
23a1d141d5Smrg
24a1d141d5SmrgExcept as contained in this notice, the name of the X Consortium shall
25a1d141d5Smrgnot be used in advertising or otherwise to promote the sale, use or
26a1d141d5Smrgother dealings in this Software without prior written authorization
27a1d141d5Smrgfrom the X Consortium.
28a1d141d5Smrg
29a1d141d5Smrg*/
30a1d141d5Smrg
312ddb6cf1Smrg#ifdef HAVE_CONFIG_H
322ddb6cf1Smrg# include "config.h"
332ddb6cf1Smrg#endif
342ddb6cf1Smrg
35a1d141d5Smrg#include <X11/Intrinsic.h>
36a1d141d5Smrg#include <X11/StringDefs.h>
37a1d141d5Smrg#include <X11/Shell.h>
38a1d141d5Smrg#include "Eyes.h"
3955074dd0Smrg#include <stdio.h>
4055074dd0Smrg#include <stdlib.h>
41a1d141d5Smrg#include "eyes.bit"
42a1d141d5Smrg#include "eyesmask.bit"
43a1d141d5Smrg
44a1d141d5Smrg/* Exit with message describing command line format */
45a1d141d5Smrg
46054b3d00Smrgstatic void _X_NORETURN
473bee1c92Smrgusage(int exitval)
48a1d141d5Smrg{
49a1d141d5Smrg    fprintf(stderr,
503bee1c92Smrg	    "usage: xeyes [-display [{host}]:{vs}]\n"
513bee1c92Smrg	    "             [-geometry [{width}][x{height}][{+-}{xoff}[{+-}{yoff}]]]\n"
523bee1c92Smrg	    "             [-fg {color}] [-bg {color}] [-bd {color}] [-bw {pixels}]\n"
533bee1c92Smrg	    "             [-shape | +shape] [-outline {color}] [-center {color}]\n"
543bee1c92Smrg	    "             [-backing {backing-store}] [-distance]\n"
553bee1c92Smrg	    "             [-biblicallyAccurate]\n"
562ddb6cf1Smrg#ifdef XRENDER
573bee1c92Smrg	    "             [-render | +render]\n"
5826df5c7cSmrg#endif
5926df5c7cSmrg#ifdef PRESENT
603bee1c92Smrg	    "             [-present | +present]\n"
612ddb6cf1Smrg#endif
623bee1c92Smrg            "       xeyes -help\n"
633bee1c92Smrg            "       xeyes -version\n");
643bee1c92Smrg    exit(exitval);
65a1d141d5Smrg}
66a1d141d5Smrg
67a1d141d5Smrg/* Command line options table.  Only resources are entered here...there is a
68a1d141d5Smrg   pass over the remaining options after XtParseCommand is let loose. */
69a1d141d5Smrg
70a1d141d5Smrgstatic XrmOptionDescRec options[] = {
7126df5c7cSmrg{(char *)"-outline",	(char *)"*eyes.outline",	XrmoptionSepArg,	NULL},
7226df5c7cSmrg{(char *)"-center",	(char *)"*eyes.center",		XrmoptionSepArg,	NULL},
7326df5c7cSmrg{(char *)"-backing",	(char *)"*eyes.backingStore",	XrmoptionSepArg,	NULL},
7426df5c7cSmrg{(char *)"-shape",	(char *)"*eyes.shapeWindow",	XrmoptionNoArg,		(char *)"TRUE"},
7526df5c7cSmrg{(char *)"+shape",	(char *)"*eyes.shapeWindow",	XrmoptionNoArg,		(char *)"FALSE"},
762ddb6cf1Smrg#ifdef XRENDER
7726df5c7cSmrg{(char *)"-render",	(char *)"*eyes.render",		XrmoptionNoArg,		(char *)"TRUE"},
7826df5c7cSmrg{(char *)"+render",	(char *)"*eyes.render",		XrmoptionNoArg,		(char *)"FALSE"},
7926df5c7cSmrg#endif
8026df5c7cSmrg#ifdef PRESENT
8126df5c7cSmrg{(char *)"-present",	(char *)"*eyes.present",	XrmoptionNoArg,		(char *)"TRUE"},
8226df5c7cSmrg{(char *)"+present",	(char *)"*eyes.present",	XrmoptionNoArg,		(char *)"FALSE"},
832ddb6cf1Smrg#endif
8426df5c7cSmrg{(char *)"-distance",	(char *)"*eyes.distance",	XrmoptionNoArg,		(char *)"TRUE"},
853bee1c92Smrg{(char *)"-biblicallyAccurate",	(char *)"*eyes.biblicallyAccurate",	XrmoptionNoArg,		(char *)"TRUE"},
86a1d141d5Smrg};
87a1d141d5Smrg
88a1d141d5Smrgstatic Atom wm_delete_window;
89a1d141d5Smrg
90a1d141d5Smrg/*ARGSUSED*/
91a1d141d5Smrgstatic void
92a1d141d5Smrgquit(Widget w, XEvent *event, String *params, Cardinal *num_params)
93a1d141d5Smrg{
9455074dd0Smrg    if (event->type == ClientMessage &&
95a1d141d5Smrg	event->xclient.data.l[0] != wm_delete_window) {
96a1d141d5Smrg	XBell(XtDisplay(w), 0);
97a1d141d5Smrg    } else {
98a1d141d5Smrg	XtDestroyApplicationContext(XtWidgetToApplicationContext(w));
99a1d141d5Smrg	exit(0);
100a1d141d5Smrg    }
101a1d141d5Smrg}
102a1d141d5Smrg
103a1d141d5Smrgstatic XtActionsRec actions[] = {
10426df5c7cSmrg    {(char *) "quit",	quit}
105a1d141d5Smrg};
106a1d141d5Smrg
107a1d141d5Smrgint
108a1d141d5Smrgmain(int argc, char **argv)
109a1d141d5Smrg{
110a1d141d5Smrg    XtAppContext app_context;
111a1d141d5Smrg    Widget toplevel;
112a1d141d5Smrg    Arg arg[2];
113a1d141d5Smrg    Cardinal i;
11455074dd0Smrg
115a1d141d5Smrg    XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL);
116a1d141d5Smrg
1173bee1c92Smrg    /* Handle args that don't require opening a display */
1183bee1c92Smrg    for (int n = 1; n < argc; n++) {
1193bee1c92Smrg	const char *argn = argv[n];
1203bee1c92Smrg	/* accept single or double dash for -help & -version */
1213bee1c92Smrg	if (argn[0] == '-' && argn[1] == '-') {
1223bee1c92Smrg	    argn++;
1233bee1c92Smrg	}
1243bee1c92Smrg	if (strcmp(argn, "-help") == 0) {
1253bee1c92Smrg	    usage(0);
1263bee1c92Smrg	}
1273bee1c92Smrg	if (strcmp(argn, "-version") == 0) {
1283bee1c92Smrg	    puts(PACKAGE_STRING);
1293bee1c92Smrg	    exit(0);
1303bee1c92Smrg	}
1313bee1c92Smrg    }
1323bee1c92Smrg
13355074dd0Smrg    toplevel = XtAppInitialize(&app_context, "XEyes",
134a1d141d5Smrg			       options, XtNumber(options), &argc, argv,
135a1d141d5Smrg			       NULL, arg, (Cardinal) 0);
1363bee1c92Smrg
1373bee1c92Smrg    if (argc != 1) {
1383bee1c92Smrg	fputs("Unknown argument(s):", stderr);
1393bee1c92Smrg	for (int n = 1; n < argc; n++) {
1403bee1c92Smrg	    if ((n < (argc -1)) || (argv[n][0] == '-')) {
1413bee1c92Smrg		fprintf(stderr, " %s", argv[n]);
1423bee1c92Smrg	    }
1433bee1c92Smrg	}
1443bee1c92Smrg	fputs("\n\n", stderr);
1453bee1c92Smrg	usage(1);
1463bee1c92Smrg    }
147a1d141d5Smrg
148a1d141d5Smrg    wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW",
149a1d141d5Smrg				   False);
150a1d141d5Smrg    XtAppAddActions(app_context, actions, XtNumber(actions));
151a1d141d5Smrg    XtOverrideTranslations
152a1d141d5Smrg	(toplevel, XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
15355074dd0Smrg
154a1d141d5Smrg    i = 0;
15555074dd0Smrg    XtSetArg (arg[i], XtNiconPixmap,
156a1d141d5Smrg	      XCreateBitmapFromData (XtDisplay(toplevel),
157a1d141d5Smrg				     XtScreen(toplevel)->root,
158a1d141d5Smrg				     (char *)eyes_bits, eyes_width, eyes_height));
159a1d141d5Smrg    i++;
16055074dd0Smrg    XtSetArg (arg[i], XtNiconMask,
161a1d141d5Smrg	      XCreateBitmapFromData (XtDisplay(toplevel),
162a1d141d5Smrg				     XtScreen(toplevel)->root,
163a1d141d5Smrg				     (char *)eyesmask_bits,
164a1d141d5Smrg				     eyesmask_width, eyesmask_height));
165a1d141d5Smrg    i++;
166a1d141d5Smrg    XtSetValues (toplevel, arg, i);
167a1d141d5Smrg
168a1d141d5Smrg    (void) XtCreateManagedWidget ("eyes", eyesWidgetClass, toplevel, NULL, 0);
169a1d141d5Smrg    XtRealizeWidget (toplevel);
170a1d141d5Smrg    (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
171a1d141d5Smrg                            &wm_delete_window, 1);
172a1d141d5Smrg    XtAppMainLoop(app_context);
173a1d141d5Smrg
174a1d141d5Smrg    return 0;
175a1d141d5Smrg}
176