oclock.c revision 168023fe
1/*
2 * $Xorg: oclock.c,v 1.4 2001/02/09 02:05:33 xorgcvs Exp $
3 *
4Copyright 1989, 1998  The Open Group
5
6Permission to use, copy, modify, distribute, and sell this software and its
7documentation for any purpose is hereby granted without fee, provided that
8the above copyright notice appear in all copies and that both that
9copyright notice and this permission notice appear in supporting
10documentation.
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22Except as contained in this notice, the name of The Open Group shall not be
23used in advertising or otherwise to promote the sale, use or other dealings
24in this Software without prior written authorization from The Open Group.
25 */
26/* $XFree86: xc/programs/oclock/oclock.c,v 1.7tsi Exp $ */
27
28#include <X11/Intrinsic.h>
29#include <X11/Xatom.h>
30#include <X11/StringDefs.h>
31#include <X11/Shell.h>
32#include <X11/Xmu/Editres.h>
33#include "Clock.h"
34#include <stdio.h>
35#include <stdlib.h>
36
37#ifdef XKB
38#include <X11/extensions/XKBbells.h>
39#endif
40
41#include "oclock.bit"
42#include "oclmask.bit"
43
44static void die ( Widget w, XtPointer client_data, XtPointer call_data );
45static void save ( Widget w, XtPointer client_data, XtPointer call_data );
46static void usage ( void );
47static void quit ( Widget w, XEvent *event, String *params,
48		   Cardinal *num_params );
49
50
51static XtActionsRec actions[] = {
52    {"quit",	quit}
53};
54
55static Atom wm_delete_window;
56
57static void die(Widget w, XtPointer client_data, XtPointer call_data)
58{
59    XCloseDisplay(XtDisplay(w));
60    exit(0);
61}
62
63static void save(Widget w, XtPointer client_data, XtPointer call_data)
64{
65    return;	/* stateless */
66}
67
68/* Exit with message describing command line format */
69
70static void usage(void)
71{
72    fprintf(stderr,
73"usage: oclock\n");
74    fprintf (stderr,
75"       [-geometry [{width}][x{height}][{+-}{xoff}[{+-}{yoff}]]] [-display [{host}]:[{vs}]]\n");
76    fprintf(stderr,
77"       [-fg {color}] [-bg {color}] [-bd {color}] [-bw {pixels}]\n");
78    fprintf(stderr,
79"       [-minute {color}] [-hour {color}] [-jewel {color}]\n");
80    fprintf(stderr,
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