xeyes.c revision 054b3d00
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
47a1d141d5Smrgusage(void)
48a1d141d5Smrg{
49a1d141d5Smrg    fprintf(stderr,
5055074dd0Smrg	    "usage: xeyes\n"
5155074dd0Smrg	    "       [-display [{host}]:[{vs}]]\n"
5255074dd0Smrg	    "       [-geometry [{width}][x{height}][{+-}{xoff}[{+-}{yoff}]]]\n"
5355074dd0Smrg	    "       [-fg {color}] [-bg {color}] [-bd {color}] [-bw {pixels}]\n"
5455074dd0Smrg	    "       [-shape | +shape] [-outline {color}] [-center {color}]\n"
5555074dd0Smrg	    "       [-backing {backing-store}] [-distance]\n");
562ddb6cf1Smrg#ifdef XRENDER
572ddb6cf1Smrg    fprintf(stderr,
5855074dd0Smrg	    "       [-render | +render]\n");
592ddb6cf1Smrg#endif
60a1d141d5Smrg    exit(1);
61a1d141d5Smrg}
62a1d141d5Smrg
63a1d141d5Smrg/* Command line options table.  Only resources are entered here...there is a
64a1d141d5Smrg   pass over the remaining options after XtParseCommand is let loose. */
65a1d141d5Smrg
66a1d141d5Smrgstatic XrmOptionDescRec options[] = {
67a1d141d5Smrg{"-outline",	"*eyes.outline",	XrmoptionSepArg,	NULL},
68a1d141d5Smrg{"-center",	"*eyes.center",		XrmoptionSepArg,	NULL},
69a1d141d5Smrg{"-backing",	"*eyes.backingStore",	XrmoptionSepArg,	NULL},
70a1d141d5Smrg{"-shape",	"*eyes.shapeWindow",	XrmoptionNoArg,		"TRUE"},
71a1d141d5Smrg{"+shape",	"*eyes.shapeWindow",	XrmoptionNoArg,		"FALSE"},
722ddb6cf1Smrg#ifdef XRENDER
732ddb6cf1Smrg{"-render",	"*eyes.render",		XrmoptionNoArg,		"TRUE"},
742ddb6cf1Smrg{"+render",	"*eyes.render",		XrmoptionNoArg,		"FALSE"},
752ddb6cf1Smrg#endif
762ddb6cf1Smrg{"-distance",	"*eyes.distance",	XrmoptionNoArg,		"TRUE"},
77a1d141d5Smrg};
78a1d141d5Smrg
79a1d141d5Smrgstatic Atom wm_delete_window;
80a1d141d5Smrg
81a1d141d5Smrg/*ARGSUSED*/
82a1d141d5Smrgstatic void
83a1d141d5Smrgquit(Widget w, XEvent *event, String *params, Cardinal *num_params)
84a1d141d5Smrg{
8555074dd0Smrg    if (event->type == ClientMessage &&
86a1d141d5Smrg	event->xclient.data.l[0] != wm_delete_window) {
87a1d141d5Smrg	XBell(XtDisplay(w), 0);
88a1d141d5Smrg    } else {
89a1d141d5Smrg	XtDestroyApplicationContext(XtWidgetToApplicationContext(w));
90a1d141d5Smrg	exit(0);
91a1d141d5Smrg    }
92a1d141d5Smrg}
93a1d141d5Smrg
94a1d141d5Smrgstatic XtActionsRec actions[] = {
95a1d141d5Smrg    {"quit",	quit}
96a1d141d5Smrg};
97a1d141d5Smrg
98a1d141d5Smrgint
99a1d141d5Smrgmain(int argc, char **argv)
100a1d141d5Smrg{
101a1d141d5Smrg    XtAppContext app_context;
102a1d141d5Smrg    Widget toplevel;
103a1d141d5Smrg    Arg arg[2];
104a1d141d5Smrg    Cardinal i;
10555074dd0Smrg
106a1d141d5Smrg    XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL);
107a1d141d5Smrg
10855074dd0Smrg    toplevel = XtAppInitialize(&app_context, "XEyes",
109a1d141d5Smrg			       options, XtNumber(options), &argc, argv,
110a1d141d5Smrg			       NULL, arg, (Cardinal) 0);
111a1d141d5Smrg    if (argc != 1) usage();
112a1d141d5Smrg
113a1d141d5Smrg    wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW",
114a1d141d5Smrg				   False);
115a1d141d5Smrg    XtAppAddActions(app_context, actions, XtNumber(actions));
116a1d141d5Smrg    XtOverrideTranslations
117a1d141d5Smrg	(toplevel, XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
11855074dd0Smrg
119a1d141d5Smrg    i = 0;
12055074dd0Smrg    XtSetArg (arg[i], XtNiconPixmap,
121a1d141d5Smrg	      XCreateBitmapFromData (XtDisplay(toplevel),
122a1d141d5Smrg				     XtScreen(toplevel)->root,
123a1d141d5Smrg				     (char *)eyes_bits, eyes_width, eyes_height));
124a1d141d5Smrg    i++;
12555074dd0Smrg    XtSetArg (arg[i], XtNiconMask,
126a1d141d5Smrg	      XCreateBitmapFromData (XtDisplay(toplevel),
127a1d141d5Smrg				     XtScreen(toplevel)->root,
128a1d141d5Smrg				     (char *)eyesmask_bits,
129a1d141d5Smrg				     eyesmask_width, eyesmask_height));
130a1d141d5Smrg    i++;
131a1d141d5Smrg    XtSetValues (toplevel, arg, i);
132a1d141d5Smrg
133a1d141d5Smrg    (void) XtCreateManagedWidget ("eyes", eyesWidgetClass, toplevel, NULL, 0);
134a1d141d5Smrg    XtRealizeWidget (toplevel);
135a1d141d5Smrg    (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
136a1d141d5Smrg                            &wm_delete_window, 1);
137a1d141d5Smrg    XtAppMainLoop(app_context);
138a1d141d5Smrg
139a1d141d5Smrg    return 0;
140a1d141d5Smrg}
141