16ea72052Smrg/* 249e82cebSmrg 36ea72052SmrgCopyright 1989, 1998 The Open Group 46ea72052Smrg 56ea72052SmrgPermission to use, copy, modify, distribute, and sell this software and its 66ea72052Smrgdocumentation for any purpose is hereby granted without fee, provided that 76ea72052Smrgthe above copyright notice appear in all copies and that both that 86ea72052Smrgcopyright notice and this permission notice appear in supporting 96ea72052Smrgdocumentation. 106ea72052Smrg 116ea72052SmrgThe above copyright notice and this permission notice shall be included in 126ea72052Smrgall copies or substantial portions of the Software. 136ea72052Smrg 146ea72052SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 156ea72052SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 166ea72052SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 176ea72052SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 186ea72052SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 196ea72052SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 206ea72052Smrg 216ea72052SmrgExcept as contained in this notice, the name of The Open Group shall not be 226ea72052Smrgused in advertising or otherwise to promote the sale, use or other dealings 236ea72052Smrgin this Software without prior written authorization from The Open Group. 2449e82cebSmrg 256ea72052Smrg */ 2649e82cebSmrg 2749e82cebSmrg#ifdef HAVE_CONFIG_H 2849e82cebSmrg#include "config.h" 2949e82cebSmrg#endif 306ea72052Smrg 316ea72052Smrg#include <X11/Intrinsic.h> 326ea72052Smrg#include <X11/Xatom.h> 336ea72052Smrg#include <X11/StringDefs.h> 346ea72052Smrg#include <X11/Shell.h> 356ea72052Smrg#include <X11/Xmu/Editres.h> 366ea72052Smrg#include "Clock.h" 3749e82cebSmrg#include <stdio.h> 386ea72052Smrg#include <stdlib.h> 396ea72052Smrg 406ea72052Smrg#ifdef XKB 416ea72052Smrg#include <X11/extensions/XKBbells.h> 426ea72052Smrg#endif 436ea72052Smrg 446ea72052Smrg#include "oclock.bit" 456ea72052Smrg#include "oclmask.bit" 466ea72052Smrg 476ea72052Smrgstatic void die ( Widget w, XtPointer client_data, XtPointer call_data ); 486ea72052Smrgstatic void save ( Widget w, XtPointer client_data, XtPointer call_data ); 49e32e2dabSmrgstatic void usage ( int exitval ); 5049e82cebSmrgstatic void quit ( Widget w, XEvent *event, String *params, 516ea72052Smrg Cardinal *num_params ); 526ea72052Smrg 536ea72052Smrg 546ea72052Smrgstatic XtActionsRec actions[] = { 556ea72052Smrg {"quit", quit} 566ea72052Smrg}; 576ea72052Smrg 586ea72052Smrgstatic Atom wm_delete_window; 596ea72052Smrg 60168023feSmrgstatic void die(Widget w, XtPointer client_data, XtPointer call_data) 616ea72052Smrg{ 626ea72052Smrg XCloseDisplay(XtDisplay(w)); 636ea72052Smrg exit(0); 646ea72052Smrg} 656ea72052Smrg 66168023feSmrgstatic void save(Widget w, XtPointer client_data, XtPointer call_data) 676ea72052Smrg{ 686ea72052Smrg return; /* stateless */ 696ea72052Smrg} 706ea72052Smrg 716ea72052Smrg/* Exit with message describing command line format */ 726ea72052Smrg 73e32e2dabSmrgstatic void usage(int exitval) 746ea72052Smrg{ 756ea72052Smrg fprintf(stderr, 7649e82cebSmrg"usage: oclock\n" 7749e82cebSmrg" [-geometry [{width}][x{height}][{+-}{xoff}[{+-}{yoff}]]]\n" 7849e82cebSmrg" [-display [{host}]:[{vs}]]\n" 7949e82cebSmrg" [-fg {color}] [-bg {color}] [-bd {color}] [-bw {pixels}]\n" 8049e82cebSmrg" [-minute {color}] [-hour {color}] [-jewel {color}]\n" 81e32e2dabSmrg" [-backing {backing-store}] [-shape] [-noshape] [-transparent]\n" 82e32e2dabSmrg" [-help] [-version]\n" 83e32e2dabSmrg ); 84e32e2dabSmrg exit(exitval); 856ea72052Smrg} 866ea72052Smrg 876ea72052Smrg/* Command line options table. Only resources are entered here...there is a 886ea72052Smrg pass over the remaining options after XtParseCommand is let loose. */ 896ea72052Smrg 906ea72052Smrgstatic XrmOptionDescRec options[] = { 916ea72052Smrg{"-fg", "*Foreground", XrmoptionSepArg, NULL}, 926ea72052Smrg{"-bg", "*Background", XrmoptionSepArg, NULL}, 936ea72052Smrg{"-foreground", "*Foreground", XrmoptionSepArg, NULL}, 946ea72052Smrg{"-background", "*Background", XrmoptionSepArg, NULL}, 956ea72052Smrg{"-minute", "*clock.minute", XrmoptionSepArg, NULL}, 966ea72052Smrg{"-hour", "*clock.hour", XrmoptionSepArg, NULL}, 976ea72052Smrg{"-jewel", "*clock.jewel", XrmoptionSepArg, NULL}, 986ea72052Smrg{"-backing", "*clock.backingStore", XrmoptionSepArg, NULL}, 996ea72052Smrg{"-shape", "*clock.shapeWindow", XrmoptionNoArg, "TRUE"}, 1006ea72052Smrg{"-noshape", "*clock.shapeWindow", XrmoptionNoArg, "FALSE"}, 1016ea72052Smrg{"-transparent","*clock.transparent", XrmoptionNoArg, "TRUE"}, 1026ea72052Smrg}; 1036ea72052Smrg 10449e82cebSmrgint 1056ea72052Smrgmain(int argc, char *argv[]) 1066ea72052Smrg{ 1076ea72052Smrg XtAppContext xtcontext; 1086ea72052Smrg Widget toplevel; 1096ea72052Smrg Arg arg[2]; 1106ea72052Smrg int i; 11149e82cebSmrg 112e32e2dabSmrg /* Handle args that don't require opening a display */ 113e32e2dabSmrg for (int n = 1; n < argc; n++) { 114e32e2dabSmrg const char *argn = argv[n]; 115e32e2dabSmrg /* accept single or double dash for -help & -version */ 116e32e2dabSmrg if (argn[0] == '-' && argn[1] == '-') { 117e32e2dabSmrg argn++; 118e32e2dabSmrg } 119e32e2dabSmrg if (strcmp(argn, "-help") == 0) { 120e32e2dabSmrg usage(0); 121e32e2dabSmrg } 122e32e2dabSmrg if (strcmp(argn, "-version") == 0) { 123e32e2dabSmrg puts(PACKAGE_STRING); 124e32e2dabSmrg exit(0); 125e32e2dabSmrg } 126e32e2dabSmrg } 127e32e2dabSmrg 1286ea72052Smrg toplevel = XtOpenApplication(&xtcontext, "Clock", 1296ea72052Smrg options, XtNumber(options), &argc, argv, NULL, 1306ea72052Smrg sessionShellWidgetClass, NULL, 0); 131e32e2dabSmrg if (argc != 1) { 132e32e2dabSmrg fputs("Unknown argument(s):", stderr); 133e32e2dabSmrg for (int n = 1; n < argc; n++) { 134e32e2dabSmrg fprintf(stderr, " %s", argv[n]); 135e32e2dabSmrg } 136e32e2dabSmrg fputs("\n\n", stderr); 137e32e2dabSmrg usage(1); 138e32e2dabSmrg } 1396ea72052Smrg XtAddCallback(toplevel, XtNsaveCallback, save, NULL); 1406ea72052Smrg XtAddCallback(toplevel, XtNdieCallback, die, NULL); 1416ea72052Smrg 1426ea72052Smrg XtAppAddActions 1436ea72052Smrg (xtcontext, actions, XtNumber(actions)); 1446ea72052Smrg XtOverrideTranslations 1456ea72052Smrg (toplevel, XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()")); 1466ea72052Smrg 1476ea72052Smrg i = 0; 14849e82cebSmrg XtSetArg (arg[i], XtNiconPixmap, 1496ea72052Smrg XCreateBitmapFromData (XtDisplay(toplevel), 1506ea72052Smrg XtScreen(toplevel)->root, 151f3e6ffc5Smrg (const char *)oclock_bits, 1526ea72052Smrg oclock_width, oclock_height)); 1536ea72052Smrg i++; 1546ea72052Smrg XtSetArg (arg[i], XtNiconMask, 1556ea72052Smrg XCreateBitmapFromData (XtDisplay(toplevel), 1566ea72052Smrg XtScreen(toplevel)->root, 157f3e6ffc5Smrg (const char *)oclmask_bits, 1586ea72052Smrg oclmask_width, oclmask_height)); 1596ea72052Smrg i++; 1606ea72052Smrg XtSetValues (toplevel, arg, i); 1616ea72052Smrg 1626ea72052Smrg (void) XtCreateManagedWidget("clock", clockWidgetClass, toplevel, NULL, 0); 1636ea72052Smrg XtRealizeWidget (toplevel); 1646ea72052Smrg 1656ea72052Smrg wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", 1666ea72052Smrg False); 1676ea72052Smrg (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel), 1686ea72052Smrg &wm_delete_window, 1); 1696ea72052Smrg 17049e82cebSmrg XtAddEventHandler(toplevel, (EventMask) 0, TRUE, 1716ea72052Smrg _XEditResCheckMessages, NULL); 1726ea72052Smrg 1736ea72052Smrg XtAppMainLoop(xtcontext); 1746ea72052Smrg exit(0); 1756ea72052Smrg} 1766ea72052Smrg 177168023feSmrgstatic void quit(Widget w, XEvent *event, String *params, Cardinal *num_params) 1786ea72052Smrg{ 1796ea72052Smrg Arg arg; 1806ea72052Smrg 18149e82cebSmrg if (event->type == ClientMessage && 182f3e6ffc5Smrg (Atom)event->xclient.data.l[0] != wm_delete_window) { 1836ea72052Smrg#ifdef XKB 1846ea72052Smrg XkbStdBell(XtDisplay(w), XtWindow(w), 0, XkbBI_BadValue); 1856ea72052Smrg#else 1866ea72052Smrg XBell(XtDisplay(w), 0); 1876ea72052Smrg#endif 1886ea72052Smrg } else { 1896ea72052Smrg XtSetArg(arg, XtNjoinSession, False); 1906ea72052Smrg XtSetValues(w, &arg, (Cardinal)1); 1916ea72052Smrg die(w, NULL, NULL); 1926ea72052Smrg } 1936ea72052Smrg} 194