home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / demos / xeyes / xeyes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-18  |  4.0 KB  |  124 lines

  1. /* $XConsortium: xeyes.c,v 1.15 91/07/18 16:46:26 rws Exp $ */
  2. /*
  3.  * Copyright 1991 Massachusetts Institute of Technology
  4.  *
  5.  * Permission to use, copy, modify, distribute, and sell this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both that
  8.  * copyright notice and this permission notice appear in supporting
  9.  * documentation, and that the name of M.I.T. not be used in advertising or
  10.  * publicity pertaining to distribution of the software without specific,
  11.  * written prior permission.  M.I.T. makes no representations about the
  12.  * suitability of this software for any purpose.  It is provided "as is"
  13.  * without express or implied warranty.
  14.  *
  15.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  16.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  17.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  19.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  20.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  *
  22.  */
  23.  
  24. #include <X11/Intrinsic.h>
  25. #include <X11/StringDefs.h>
  26. #include <X11/Shell.h>
  27. #include "Eyes.h"
  28. #include <stdio.h> 
  29. #include "eyes.bit"
  30. #include "eyesmask.bit"
  31.  
  32. extern void exit();
  33. static void quit();
  34.  
  35. /* Exit with message describing command line format */
  36.  
  37. void usage()
  38. {
  39.     fprintf(stderr,
  40. "usage: xeyes\n");
  41.     fprintf (stderr, 
  42. "       [-geometry [{width}][x{height}][{+-}{xoff}[{+-}{yoff}]]] [-display [{host}]:[{vs}]]\n");
  43.     fprintf(stderr,
  44. "       [-fg {color}] [-bg {color}] [-bd {color}] [-bw {pixels}]");
  45.     fprintf(stderr, " [-shape | +shape]");
  46.     fprintf(stderr, "\n");
  47.     fprintf(stderr,
  48. "       [-outline {color}] [-center {color}] [-backing {backing-store}]\n");
  49.     exit(1);
  50. }
  51.  
  52. /* Command line options table.  Only resources are entered here...there is a
  53.    pass over the remaining options after XtParseCommand is let loose. */
  54.  
  55. static XrmOptionDescRec options[] = {
  56. {"-outline",    "*eyes.outline",    XrmoptionSepArg,    NULL},
  57. {"-center",    "*eyes.center",        XrmoptionSepArg,    NULL},
  58. {"-backing",    "*eyes.backingStore",    XrmoptionSepArg,    NULL},
  59. {"-shape",    "*eyes.shapeWindow",    XrmoptionNoArg,        "TRUE"},
  60. {"+shape",    "*eyes.shapeWindow",    XrmoptionNoArg,        "FALSE"},
  61. };
  62.  
  63. static XtActionsRec actions[] = {
  64.     {"quit",    quit}
  65. };
  66.  
  67. static Atom wm_delete_window;
  68.  
  69. void main(argc, argv)
  70.     int argc;
  71.     char **argv;
  72. {
  73.     XtAppContext app_context;
  74.     Widget toplevel;
  75.     Arg arg[2];
  76.     Cardinal i;
  77.     
  78.     toplevel = XtAppInitialize(&app_context, "XEyes", 
  79.                    options, XtNumber(options), &argc, argv,
  80.                    NULL, arg, (Cardinal) 0);
  81.     if (argc != 1) usage();
  82.     XtAppAddActions(app_context, actions, XtNumber(actions));
  83.     XtOverrideTranslations
  84.     (toplevel, XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
  85.     
  86.     i = 0;
  87.     XtSetArg (arg[i], XtNiconPixmap, 
  88.           XCreateBitmapFromData (XtDisplay(toplevel),
  89.                      XtScreen(toplevel)->root,
  90.                      (char *)eyes_bits, eyes_width, eyes_height));
  91.     i++;
  92.     XtSetArg (arg[i], XtNiconMask, 
  93.           XCreateBitmapFromData (XtDisplay(toplevel),
  94.                      XtScreen(toplevel)->root,
  95.                      (char *)eyesmask_bits,
  96.                      eyesmask_width, eyesmask_height));
  97.     i++;
  98.     XtSetValues (toplevel, arg, i);
  99.  
  100.     (void) XtCreateManagedWidget ("eyes", eyesWidgetClass, toplevel, NULL, 0);
  101.     XtRealizeWidget (toplevel);
  102.     wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW",
  103.                    False);
  104.     (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
  105.                             &wm_delete_window, 1);
  106.     XtAppMainLoop(app_context);
  107. }
  108.  
  109. /*ARGSUSED*/
  110. static void quit(w, event, params, num_params)
  111.     Widget w;
  112.     XEvent *event;
  113.     String *params;
  114.     Cardinal *num_params;
  115. {
  116.     if (event->type == ClientMessage && 
  117.     event->xclient.data.l[0] != wm_delete_window) {
  118.     XBell(XtDisplay(w), 0);
  119.     } else {
  120.     XtDestroyApplicationContext(XtWidgetToApplicationContext(w));
  121.     exit(0);
  122.     }
  123. }
  124.