home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / clients / oclock / oclock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-10  |  4.3 KB  |  135 lines

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