xeyes.c revision 2ddb6cf1
1/* $XConsortium: xeyes.c,v 1.16 94/04/17 20:45:23 rws Exp $ */ 2/* 3 4Copyright (c) 1991 X Consortium 5 6Permission is hereby granted, free of charge, to any person obtaining 7a copy of this software and associated documentation files (the 8"Software"), to deal in the Software without restriction, including 9without limitation the rights to use, copy, modify, merge, publish, 10distribute, sublicense, and/or sell copies of the Software, and to 11permit persons to whom the Software is furnished to do so, subject to 12the following conditions: 13 14The above copyright notice and this permission notice shall be included 15in all copies or substantial portions of the Software. 16 17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR 21OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23OTHER DEALINGS IN THE SOFTWARE. 24 25Except as contained in this notice, the name of the X Consortium shall 26not be used in advertising or otherwise to promote the sale, use or 27other dealings in this Software without prior written authorization 28from the X Consortium. 29 30*/ 31/* $XFree86: xc/programs/xeyes/xeyes.c,v 1.3 2000/02/17 14:00:35 dawes Exp $ */ 32 33#ifdef HAVE_CONFIG_H 34# include "config.h" 35#endif 36 37#include <X11/Intrinsic.h> 38#include <X11/StringDefs.h> 39#include <X11/Shell.h> 40#include "Eyes.h" 41#include <stdio.h> 42#include <stdlib.h> 43#include "eyes.bit" 44#include "eyesmask.bit" 45 46/* Exit with message describing command line format */ 47 48static void 49usage(void) 50{ 51 fprintf(stderr, 52"usage: xeyes\n"); 53 fprintf (stderr, 54" [-geometry [{width}][x{height}][{+-}{xoff}[{+-}{yoff}]]] [-display [{host}]:[{vs}]]\n"); 55 fprintf(stderr, 56" [-fg {color}] [-bg {color}] [-bd {color}] [-bw {pixels}]"); 57 fprintf(stderr, " [-shape | +shape]"); 58 fprintf(stderr, "\n"); 59 fprintf(stderr, 60" [-outline {color}] [-center {color}] [-backing {backing-store}] [-distance]\n"); 61#ifdef XRENDER 62 fprintf(stderr, 63" [-render | +render]\n"); 64#endif 65 exit(1); 66} 67 68/* Command line options table. Only resources are entered here...there is a 69 pass over the remaining options after XtParseCommand is let loose. */ 70 71static XrmOptionDescRec options[] = { 72{"-outline", "*eyes.outline", XrmoptionSepArg, NULL}, 73{"-center", "*eyes.center", XrmoptionSepArg, NULL}, 74{"-backing", "*eyes.backingStore", XrmoptionSepArg, NULL}, 75{"-shape", "*eyes.shapeWindow", XrmoptionNoArg, "TRUE"}, 76{"+shape", "*eyes.shapeWindow", XrmoptionNoArg, "FALSE"}, 77#ifdef XRENDER 78{"-render", "*eyes.render", XrmoptionNoArg, "TRUE"}, 79{"+render", "*eyes.render", XrmoptionNoArg, "FALSE"}, 80#endif 81{"-distance", "*eyes.distance", XrmoptionNoArg, "TRUE"}, 82}; 83 84static Atom wm_delete_window; 85 86/*ARGSUSED*/ 87static void 88quit(Widget w, XEvent *event, String *params, Cardinal *num_params) 89{ 90 if (event->type == ClientMessage && 91 event->xclient.data.l[0] != wm_delete_window) { 92 XBell(XtDisplay(w), 0); 93 } else { 94 XtDestroyApplicationContext(XtWidgetToApplicationContext(w)); 95 exit(0); 96 } 97} 98 99static XtActionsRec actions[] = { 100 {"quit", quit} 101}; 102 103int 104main(int argc, char **argv) 105{ 106 XtAppContext app_context; 107 Widget toplevel; 108 Arg arg[2]; 109 Cardinal i; 110 111 XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL); 112 113 toplevel = XtAppInitialize(&app_context, "XEyes", 114 options, XtNumber(options), &argc, argv, 115 NULL, arg, (Cardinal) 0); 116 if (argc != 1) usage(); 117 118 wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", 119 False); 120 XtAppAddActions(app_context, actions, XtNumber(actions)); 121 XtOverrideTranslations 122 (toplevel, XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()")); 123 124 i = 0; 125 XtSetArg (arg[i], XtNiconPixmap, 126 XCreateBitmapFromData (XtDisplay(toplevel), 127 XtScreen(toplevel)->root, 128 (char *)eyes_bits, eyes_width, eyes_height)); 129 i++; 130 XtSetArg (arg[i], XtNiconMask, 131 XCreateBitmapFromData (XtDisplay(toplevel), 132 XtScreen(toplevel)->root, 133 (char *)eyesmask_bits, 134 eyesmask_width, eyesmask_height)); 135 i++; 136 XtSetValues (toplevel, arg, i); 137 138 (void) XtCreateManagedWidget ("eyes", eyesWidgetClass, toplevel, NULL, 0); 139 XtRealizeWidget (toplevel); 140 (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel), 141 &wm_delete_window, 1); 142 XtAppMainLoop(app_context); 143 144 return 0; 145} 146