xeyes.c revision 26df5c7c
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"); 5926df5c7cSmrg#endif 6026df5c7cSmrg#ifdef PRESENT 6126df5c7cSmrg fprintf(stderr, 6226df5c7cSmrg " [-present | +present]\n"); 632ddb6cf1Smrg#endif 64a1d141d5Smrg exit(1); 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"}, 85a1d141d5Smrg}; 86a1d141d5Smrg 87a1d141d5Smrgstatic Atom wm_delete_window; 88a1d141d5Smrg 89a1d141d5Smrg/*ARGSUSED*/ 90a1d141d5Smrgstatic void 91a1d141d5Smrgquit(Widget w, XEvent *event, String *params, Cardinal *num_params) 92a1d141d5Smrg{ 9355074dd0Smrg if (event->type == ClientMessage && 94a1d141d5Smrg event->xclient.data.l[0] != wm_delete_window) { 95a1d141d5Smrg XBell(XtDisplay(w), 0); 96a1d141d5Smrg } else { 97a1d141d5Smrg XtDestroyApplicationContext(XtWidgetToApplicationContext(w)); 98a1d141d5Smrg exit(0); 99a1d141d5Smrg } 100a1d141d5Smrg} 101a1d141d5Smrg 102a1d141d5Smrgstatic XtActionsRec actions[] = { 10326df5c7cSmrg {(char *) "quit", quit} 104a1d141d5Smrg}; 105a1d141d5Smrg 106a1d141d5Smrgint 107a1d141d5Smrgmain(int argc, char **argv) 108a1d141d5Smrg{ 109a1d141d5Smrg XtAppContext app_context; 110a1d141d5Smrg Widget toplevel; 111a1d141d5Smrg Arg arg[2]; 112a1d141d5Smrg Cardinal i; 11355074dd0Smrg 114a1d141d5Smrg XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL); 115a1d141d5Smrg 11655074dd0Smrg toplevel = XtAppInitialize(&app_context, "XEyes", 117a1d141d5Smrg options, XtNumber(options), &argc, argv, 118a1d141d5Smrg NULL, arg, (Cardinal) 0); 119a1d141d5Smrg if (argc != 1) usage(); 120a1d141d5Smrg 121a1d141d5Smrg wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", 122a1d141d5Smrg False); 123a1d141d5Smrg XtAppAddActions(app_context, actions, XtNumber(actions)); 124a1d141d5Smrg XtOverrideTranslations 125a1d141d5Smrg (toplevel, XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()")); 12655074dd0Smrg 127a1d141d5Smrg i = 0; 12855074dd0Smrg XtSetArg (arg[i], XtNiconPixmap, 129a1d141d5Smrg XCreateBitmapFromData (XtDisplay(toplevel), 130a1d141d5Smrg XtScreen(toplevel)->root, 131a1d141d5Smrg (char *)eyes_bits, eyes_width, eyes_height)); 132a1d141d5Smrg i++; 13355074dd0Smrg XtSetArg (arg[i], XtNiconMask, 134a1d141d5Smrg XCreateBitmapFromData (XtDisplay(toplevel), 135a1d141d5Smrg XtScreen(toplevel)->root, 136a1d141d5Smrg (char *)eyesmask_bits, 137a1d141d5Smrg eyesmask_width, eyesmask_height)); 138a1d141d5Smrg i++; 139a1d141d5Smrg XtSetValues (toplevel, arg, i); 140a1d141d5Smrg 141a1d141d5Smrg (void) XtCreateManagedWidget ("eyes", eyesWidgetClass, toplevel, NULL, 0); 142a1d141d5Smrg XtRealizeWidget (toplevel); 143a1d141d5Smrg (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel), 144a1d141d5Smrg &wm_delete_window, 1); 145a1d141d5Smrg XtAppMainLoop(app_context); 146a1d141d5Smrg 147a1d141d5Smrg return 0; 148a1d141d5Smrg} 149