oclock.c revision 49e82ceb
1/* 2 3Copyright 1989, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21Except as contained in this notice, the name of The Open Group shall not be 22used in advertising or otherwise to promote the sale, use or other dealings 23in this Software without prior written authorization from The Open Group. 24 25 */ 26 27#ifdef HAVE_CONFIG_H 28#include "config.h" 29#endif 30 31#include <X11/Intrinsic.h> 32#include <X11/Xatom.h> 33#include <X11/StringDefs.h> 34#include <X11/Shell.h> 35#include <X11/Xmu/Editres.h> 36#include "Clock.h" 37#include <stdio.h> 38#include <stdlib.h> 39 40#ifdef XKB 41#include <X11/extensions/XKBbells.h> 42#endif 43 44#include "oclock.bit" 45#include "oclmask.bit" 46 47static void die ( Widget w, XtPointer client_data, XtPointer call_data ); 48static void save ( Widget w, XtPointer client_data, XtPointer call_data ); 49static void usage ( void ); 50static void quit ( Widget w, XEvent *event, String *params, 51 Cardinal *num_params ); 52 53 54static XtActionsRec actions[] = { 55 {"quit", quit} 56}; 57 58static Atom wm_delete_window; 59 60static void die(Widget w, XtPointer client_data, XtPointer call_data) 61{ 62 XCloseDisplay(XtDisplay(w)); 63 exit(0); 64} 65 66static void save(Widget w, XtPointer client_data, XtPointer call_data) 67{ 68 return; /* stateless */ 69} 70 71/* Exit with message describing command line format */ 72 73static void usage(void) 74{ 75 fprintf(stderr, 76"usage: oclock\n" 77" [-geometry [{width}][x{height}][{+-}{xoff}[{+-}{yoff}]]]\n" 78" [-display [{host}]:[{vs}]]\n" 79" [-fg {color}] [-bg {color}] [-bd {color}] [-bw {pixels}]\n" 80" [-minute {color}] [-hour {color}] [-jewel {color}]\n" 81" [-backing {backing-store}] [-shape] [-noshape] [-transparent]\n"); 82 exit(1); 83} 84 85/* Command line options table. Only resources are entered here...there is a 86 pass over the remaining options after XtParseCommand is let loose. */ 87 88static XrmOptionDescRec options[] = { 89{"-fg", "*Foreground", XrmoptionSepArg, NULL}, 90{"-bg", "*Background", XrmoptionSepArg, NULL}, 91{"-foreground", "*Foreground", XrmoptionSepArg, NULL}, 92{"-background", "*Background", XrmoptionSepArg, NULL}, 93{"-minute", "*clock.minute", XrmoptionSepArg, NULL}, 94{"-hour", "*clock.hour", XrmoptionSepArg, NULL}, 95{"-jewel", "*clock.jewel", XrmoptionSepArg, NULL}, 96{"-backing", "*clock.backingStore", XrmoptionSepArg, NULL}, 97{"-shape", "*clock.shapeWindow", XrmoptionNoArg, "TRUE"}, 98{"-noshape", "*clock.shapeWindow", XrmoptionNoArg, "FALSE"}, 99{"-transparent","*clock.transparent", XrmoptionNoArg, "TRUE"}, 100}; 101 102int 103main(int argc, char *argv[]) 104{ 105 XtAppContext xtcontext; 106 Widget toplevel; 107 Arg arg[2]; 108 int i; 109 110 toplevel = XtOpenApplication(&xtcontext, "Clock", 111 options, XtNumber(options), &argc, argv, NULL, 112 sessionShellWidgetClass, NULL, 0); 113 if (argc != 1) usage(); 114 XtAddCallback(toplevel, XtNsaveCallback, save, NULL); 115 XtAddCallback(toplevel, XtNdieCallback, die, NULL); 116 117 XtAppAddActions 118 (xtcontext, actions, XtNumber(actions)); 119 XtOverrideTranslations 120 (toplevel, XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()")); 121 122 i = 0; 123 XtSetArg (arg[i], XtNiconPixmap, 124 XCreateBitmapFromData (XtDisplay(toplevel), 125 XtScreen(toplevel)->root, 126 (char *)oclock_bits, 127 oclock_width, oclock_height)); 128 i++; 129 XtSetArg (arg[i], XtNiconMask, 130 XCreateBitmapFromData (XtDisplay(toplevel), 131 XtScreen(toplevel)->root, 132 (char *)oclmask_bits, 133 oclmask_width, oclmask_height)); 134 i++; 135 XtSetValues (toplevel, arg, i); 136 137 (void) XtCreateManagedWidget("clock", clockWidgetClass, toplevel, NULL, 0); 138 XtRealizeWidget (toplevel); 139 140 wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", 141 False); 142 (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel), 143 &wm_delete_window, 1); 144 145 XtAddEventHandler(toplevel, (EventMask) 0, TRUE, 146 _XEditResCheckMessages, NULL); 147 148 XtAppMainLoop(xtcontext); 149 exit(0); 150} 151 152static void quit(Widget w, XEvent *event, String *params, Cardinal *num_params) 153{ 154 Arg arg; 155 156 if (event->type == ClientMessage && 157 event->xclient.data.l[0] != wm_delete_window) { 158#ifdef XKB 159 XkbStdBell(XtDisplay(w), XtWindow(w), 0, XkbBI_BadValue); 160#else 161 XBell(XtDisplay(w), 0); 162#endif 163 } else { 164 XtSetArg(arg, XtNjoinSession, False); 165 XtSetValues(w, &arg, (Cardinal)1); 166 die(w, NULL, NULL); 167 } 168} 169