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