Annotation of researchv9/X11/src/X.V11R1/clients/xclock/xclock.c, revision 1.1.1.1

1.1       root        1: 
                      2: /*
                      3:  * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
                      4:  * 
                      5:  *                         All Rights Reserved
                      6:  * 
                      7:  * Permission to use, copy, modify, and distribute this software and its 
                      8:  * documentation for any purpose and without fee is hereby granted, 
                      9:  * provided that the above copyright notice appear in all copies and that
                     10:  * both that copyright notice and this permission notice appear in 
                     11:  * supporting documentation, and that the name of Digital Equipment
                     12:  * Corporation not be used in advertising or publicity pertaining to
                     13:  * distribution of the software without specific, written prior permission.  
                     14:  * 
                     15:  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
                     16:  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
                     17:  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
                     18:  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
                     19:  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
                     20:  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
                     21:  * SOFTWARE.
                     22:  */
                     23: /* xclock -- 
                     24:  *  Hacked from Tony Della Fera's much hacked clock program.
                     25:  */
                     26: #ifndef lint
                     27: static char *rcsid_xclock_c = "$Header: xclock.c,v 1.27 87/09/09 12:03:33 swick Exp $";
                     28: #endif  lint
                     29: 
                     30: #include <stdio.h>
                     31: #include <strings.h>
                     32: #include <signal.h>
                     33: #include <X11/Xatom.h>
                     34: #include <X11/Xlib.h>
                     35: #include <X11/Xutil.h>
                     36: #include <X11/Intrinsic.h>
                     37: #include <X11/Atoms.h>
                     38: #include <X11/Clock.h>
                     39: #include <pwd.h>
                     40: #include "clock.bit"
                     41: 
                     42: extern void exit();
                     43: 
                     44: /* Command line options table.  Only resources are entered here...there is a
                     45:    pass over the remaining options after XtParseCommand is let loose. */
                     46: 
                     47: static XrmOptionDescRec opTable[] = {
                     48: {"=",          "geometry",     XrmoptionIsArg,         (caddr_t) NULL},
                     49: {"-bd",                XtNborder,      XrmoptionSepArg,        (caddr_t) NULL},
                     50: {"-bordercolor",XtNborder,     XrmoptionSepArg,        (caddr_t) NULL},
                     51: {"-bg",                XtNbackground,  XrmoptionSepArg,        (caddr_t) NULL},
                     52: {"-background",        XtNbackground,  XrmoptionSepArg,        (caddr_t) NULL},
                     53: {"-bw",                XtNborderWidth, XrmoptionSepArg,        (caddr_t) NULL},
                     54: {"-border",    XtNborderWidth, XrmoptionSepArg,        (caddr_t) NULL},
                     55: {"-chime",     XtNchime,       XrmoptionNoArg,         (caddr_t) "1"},
                     56: {"-fg",                XtNforeground,  XrmoptionSepArg,        (caddr_t) NULL},
                     57: {"-foreground",        XtNforeground,  XrmoptionSepArg,        (caddr_t) NULL},
                     58: {"-fn",                XtNfont,        XrmoptionSepArg,        (caddr_t) NULL},
                     59: {"-font",      XtNfont,        XrmoptionSepArg,        (caddr_t) NULL},
                     60: {"-hd",                XtNhand,        XrmoptionSepArg,        (caddr_t) NULL},
                     61: {"-hands",     XtNhand,        XrmoptionSepArg,        (caddr_t) NULL},
                     62: {"-hl",                XtNhigh,        XrmoptionSepArg,        (caddr_t) NULL},
                     63: {"-highlight", XtNhigh,        XrmoptionSepArg,        (caddr_t) NULL},
                     64: {"-u",         XtNupdate,      XrmoptionSepArg,        (caddr_t) NULL},
                     65: {"-update",    XtNupdate,      XrmoptionSepArg,        (caddr_t) NULL},
                     66: {"-padding",   XtNpadding,     XrmoptionSepArg,        (caddr_t) NULL},
                     67: {"-d",         XtNanalog,       XrmoptionNoArg,        (caddr_t) "0"},
                     68: {"-digital",   XtNanalog,       XrmoptionNoArg,        (caddr_t) "0"},
                     69: {"-analog",    XtNanalog,       XrmoptionNoArg,        (caddr_t) "1"},
                     70: {"-a",         XtNanalog,       XrmoptionNoArg,        (caddr_t) "1"},
                     71: {"-rv",                XtNreverseVideo, XrmoptionNoArg,        (caddr_t) "on"},
                     72: {"-reverse",   XtNreverseVideo, XrmoptionNoArg,        (caddr_t) "on"},
                     73: {"-active",    XtNactive,       XrmoptionNoArg,        (caddr_t) "1"},
                     74: {"+rv",                XtNreverseVideo, XrmoptionNoArg,        (caddr_t) "off"}
                     75: };
                     76: 
                     77: static char *geostr;
                     78: int analog, def_analog = 1;
                     79: 
                     80: 
                     81: static Resource rlist[]=
                     82: {
                     83:       {"geometry", "Geometry", XrmRString,
                     84:         sizeof(char *), (caddr_t) &geostr, (caddr_t) NULL},
                     85:       {XtNanalog, XtCAnalog, XrmRInt, sizeof(int), (caddr_t) & analog, 
                     86:        (caddr_t) & def_analog}
                     87: };
                     88: 
                     89: 
                     90: /*
                     91:  * Report the syntax for calling xclock.
                     92:  */
                     93: Syntax(call)
                     94:        char *call;
                     95: {
                     96:        (void) printf ("Usage: %s [-analog] [-bw <pixels>] [-digital]\n", call);
                     97:        (void) printf ("       [-fg <color>] [-bg <color>] [-hl <color>] [-bd <color>]\n");
                     98:        (void) printf ("       [-fn <font_name>] [-help] [-padding <pixels>]\n");
                     99:        (void) printf ("       [-rv] [-update <seconds>] [[<host>]:[<vs>]]\n");
                    100:        (void) printf ("       [=[<width>][x<height>][<+-><xoff>[<+-><yoff>]]]\n\n");
                    101:        exit(0);
                    102: }
                    103: 
                    104: void XtGetUsersDataBase()
                    105: {
                    106:        XrmResourceDataBase resources, userResources;
                    107:        int uid;
                    108:        extern struct passwd *getpwuid();
                    109:        struct passwd *pw;
                    110:        char filename[1024];
                    111:        FILE *f;
                    112: 
                    113:        /* Open .Xdefaults file and merge into existing data base */
                    114:        uid = getuid();
                    115:        pw = getpwuid(uid);
                    116:        if (pw) {
                    117:                (void) strcpy(filename, pw->pw_dir);
                    118:                (void) strcat(filename, "/.Xdefaults");
                    119:                f = fopen(filename, "r");
                    120:                if (f) {
                    121:                        XrmGetCurrentDataBase(&resources);
                    122:                        XrmGetDataBase(f, &userResources);
                    123:                        XrmMergeDataBases(userResources, &resources);
                    124:                        XrmSetCurrentDataBase(userResources);
                    125:                        (void) fclose(f);
                    126:                }
                    127:        }
                    128: }
                    129: 
                    130: 
                    131: void main(argc, argv)
                    132:     int argc;
                    133:     char **argv;
                    134: {
                    135:     char displayName[256];     /* will contain DISPLAY name */
                    136:     char host[256];
                    137:     Display *dpy;
                    138:     Window win;
                    139:     XrmNameList         names;
                    140:     XrmClassList classes;
                    141:     Arg arglist[20];
                    142:     int x, y;
                    143:     unsigned height, width;
                    144:     int argCount = 0;
                    145:     int flags = 0;
                    146:     XSizeHints sizehints;
                    147:     XWMHints   wmhints, *oldwmhints;
                    148: 
                    149:     (void) gethostname(host,255);
                    150:     XtSetArg(arglist[argCount], XtNlabel, host);
                    151:     argCount++;
                    152:     XtSetArg(arglist[argCount], XtNname, argv[0]);
                    153:     argCount++;
                    154:     displayName[0] = '\0';
                    155:     XtInitialize();
                    156:     XtGetUsersDataBase();
                    157:       
                    158:     XrmParseCommand( opTable, XtNumber(opTable), argv[0], &argc, argv);
                    159: 
                    160:     if(argc > 1 && index(argv[1], ':') != NULL) {
                    161:            argc--;
                    162:            (void) strncpy(displayName, argv[1], sizeof(displayName));
                    163:     }
                    164:     if (argc != 1) Syntax(argv[0]);
                    165: 
                    166:     /* Open display  */
                    167:     if (!(dpy = XOpenDisplay(displayName))) {
                    168:        (void) fprintf(stderr, "%s: Can't open display '%s'\n",
                    169:                argv[0], XDisplayName(displayName));
                    170:        exit(1);
                    171:     }
                    172:     geostr = NULL;
                    173:     XtGetResources(dpy, rlist, XtNumber(rlist),arglist,2,
                    174:                DefaultRootWindow(dpy),
                    175:                   "Xclock",  "xclock", &names, &classes);
                    176:     sizehints.flags = PMinSize | PPosition | PSize;
                    177:     if(analog) {
                    178:        sizehints.flags |= PAspect;
                    179:        sizehints.min_aspect.x = 1;
                    180:        sizehints.min_aspect.y = 1;
                    181:         sizehints.max_aspect.x = 1;
                    182:         sizehints.max_aspect.y = 1;
                    183:     }
                    184:     sizehints.min_width = sizehints.min_height = 15;
                    185:     sizehints.width = sizehints.height = 120;
                    186:     sizehints.x = 100;
                    187:     sizehints.y = 300;
                    188: 
                    189:     if( geostr != NULL ) {
                    190:          flags = XParseGeometry(geostr, &x, &y, &width, &height);
                    191:          if(WidthValue & flags) {
                    192:                sizehints.flags |= USSize;
                    193:                sizehints.width = width;
                    194:                XtSetArg(arglist[argCount], XtNwidth, width);
                    195:                argCount++;
                    196:          }
                    197:          if(HeightValue & flags) {
                    198:                sizehints.flags |= USSize;
                    199:                sizehints.height = height;
                    200:                XtSetArg(arglist[argCount], XtNheight, height);
                    201:                argCount++;
                    202:          }
                    203:          if(XValue & flags) {
                    204:            if(XNegative & flags)
                    205:              x = DisplayWidth(dpy, DefaultScreen(dpy)) + x 
                    206:                - sizehints.width;
                    207:            sizehints.flags |= USPosition;
                    208:            sizehints.x = x;
                    209:            XtSetArg(arglist[argCount], XtNx, x);
                    210:            argCount++;
                    211:          }
                    212:          if(YValue & flags) {
                    213:            if(YNegative & flags)
                    214:              y = DisplayHeight(dpy, DefaultScreen(dpy)) + y
                    215:                -sizehints.height;
                    216:            sizehints.flags |= USPosition;
                    217:            sizehints.y = y;
                    218:            XtSetArg(arglist[argCount], XtNy, y);
                    219:            argCount++;
                    220:          }
                    221:     }
                    222:     
                    223:     win = XtCreateClock(dpy, DefaultRootWindow(dpy),
                    224:                arglist, argCount);
                    225:     XtMakeMaster(dpy, win);
                    226:     
                    227:     XSetStandardProperties ( dpy, win, "xclock","Clock", 
                    228:                    XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), 
                    229:                               clock_bits, clock_width, clock_height),
                    230:                            argv, argc, &sizehints);
                    231:     oldwmhints = XGetWMHints(dpy, win);
                    232:     if (oldwmhints) {
                    233:         wmhints = *oldwmhints;
                    234:         free((char *)oldwmhints);
                    235:     } else wmhints.flags = 0;
                    236:     wmhints.flags |= InputHint /*| StateHint */;
                    237:     wmhints.input = FALSE;
                    238: /*  wmhints.initial_state = IconicState; */
                    239:     XSetWMHints( dpy, win, &wmhints);
                    240:     XMapWindow(dpy, win);                          /* Map window to screen */
                    241:     for(;;) {
                    242:        XEvent event;
                    243:          
                    244:        XtNextEvent(dpy, &event);
                    245:        (void) XtDispatchEvent(&event);
                    246:     }
                    247: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.