Annotation of 43BSDTahoe/new/X/xsetroot/xsetroot.c, revision 1.1

1.1     ! root        1: #include <X/mit-copyright.h>
        !             2: 
        !             3: /* Copyright 1985 Massachusetts Institute of Technology */
        !             4: 
        !             5: /*
        !             6:  * xsetroot.c  MIT Project Athena, X Window system root window 
        !             7:  *             parameter setting utility.  This program will set 
        !             8:  *             various parameters of the X root window.
        !             9:  *
        !            10:  *  Author:    Tony Della Fera, DEC
        !            11:  *             28-Nov-84
        !            12:  */
        !            13: #ifndef lint
        !            14: static char *rcsid_xsetroot_c = "$Header: xsetroot.c,v 10.10 86/11/25 13:37:47 jg Rel $";
        !            15: #endif
        !            16: 
        !            17: #include <X/Xlib.h>
        !            18: #include <stdio.h>
        !            19: #include <strings.h>
        !            20: #define NULL 0
        !            21: 
        !            22: #define MAX(a, b) (a) > (b) ? (a) : (b)
        !            23: #define MIN(a, b) (a) < (b) ? (a) : (b)
        !            24: #define ABS(a) (a) < 0 ? -(a) : (a)
        !            25: 
        !            26: #define DEF_MSE_COLOR          BlackPixel
        !            27: #define DEF_SOLID_COLOR                WhitePixel
        !            28: #define DEF_FG_COLOR           BlackPixel
        !            29: #define DEF_BG_COLOR           WhitePixel
        !            30: #define DEF_ROOT_NAME          " X Root Window "
        !            31: 
        !            32: #define BITMAP_SIZE            16
        !            33: #define BITMAP_HOT             8
        !            34: 
        !            35: #define FAILURE                        0
        !            36: 
        !            37: typedef enum bool {FALSE, TRUE} bool;
        !            38: 
        !            39: static unsigned short solid_line = 0xffff;
        !            40: 
        !            41: static short gray_bits[BITMAP_SIZE] = {
        !            42:     0xaaaa, 0x5555, 0xaaaa, 0x5555,
        !            43:     0xaaaa, 0x5555, 0xaaaa, 0x5555,
        !            44:     0xaaaa, 0x5555, 0xaaaa, 0x5555,
        !            45:     0xaaaa, 0x5555, 0xaaaa, 0x5555
        !            46: };
        !            47: 
        !            48: main(argc, argv)
        !            49:     int argc;
        !            50:     char **argv;
        !            51: {
        !            52:     register int i;
        !            53:     register int x;
        !            54:     register int y;
        !            55:     register unsigned short pattern_line = 0;
        !            56:     int mse = DEF_MSE_COLOR;
        !            57:     int solid = DEF_SOLID_COLOR;
        !            58:     int fg = DEF_FG_COLOR;
        !            59:     int bg = DEF_BG_COLOR;
        !            60:     int width;
        !            61:     int height;
        !            62:     int x_hot;
        !            63:     int y_hot;
        !            64:     int xmod;
        !            65:     int ymod;
        !            66:     char *def_val;
        !            67:     char *strind;
        !            68:     char *root_name;
        !            69:     char *cursor_fname;
        !            70:     char *mask_fname;
        !            71:     char *bitmap_fname;
        !            72:     char *mse_name = NULL;
        !            73:     char *solid_name = NULL;
        !            74:     char *fg_name = NULL;
        !            75:     char *bg_name = NULL;
        !            76:     char display[40];
        !            77:     bool def_sw = FALSE;
        !            78:     bool name_sw = FALSE;
        !            79:     bool cursor_sw = FALSE;
        !            80:     bool solid_sw = FALSE;
        !            81:     bool invert_sw = FALSE;
        !            82:     bool gray_sw = FALSE;
        !            83:     bool bitmap_sw = FALSE;
        !            84:     bool mod_sw = FALSE;
        !            85: 
        !            86:     short *cursor_bits;
        !            87:     short *mask_bits;
        !            88:     short *bkgnd_bits;
        !            89: 
        !            90:     Color color_def;
        !            91:     Cursor cursor;
        !            92:     Bitmap bkgnd_bitmap;
        !            93:     Pixmap bkgnd_pixmap;
        !            94: 
        !            95:     display[0] = '\0';
        !            96:     
        !            97:     /*
        !            98:      * Get X defaults.
        !            99:      */
        !           100:     def_val = XGetDefault(argv[0], "Foreground");
        !           101:     fg_name = def_val;
        !           102: 
        !           103:     def_val = XGetDefault(argv[0], "Background");
        !           104:     bg_name = def_val;
        !           105: 
        !           106:     def_val = XGetDefault(argv[0], "Mouse");
        !           107:     mse_name = def_val;
        !           108: 
        !           109:     /*
        !           110:      * Parse argument list.
        !           111:      */
        !           112:     for (i = 1; i < argc; i++) {
        !           113:         strind = index(argv[i], ':');
        !           114:         if(strind != NULL) {
        !           115:             (void) strncpy(display, argv[i], sizeof(display));
        !           116:            if (argc == 2) def_sw = TRUE;
        !           117:             continue;
        !           118:         }
        !           119:         strind = index (argv[i], '-');
        !           120:         if (strind == NULL) Syntax(argv[0]);
        !           121:         if (strncmp(argv[i], "-help", 5) == 0) {
        !           122:             Syntax(argv[0]);
        !           123:         }
        !           124:         if (strncmp(argv[i], "-def", 4) == 0) {
        !           125:            def_sw = TRUE;
        !           126:            continue;
        !           127:         }
        !           128:         if (strncmp(argv[i], "-fg", 3) == 0) {
        !           129:             if (++i >= argc) Syntax(argv[0]);
        !           130:            fg_name = argv[i];
        !           131:            continue;
        !           132:        }
        !           133:         if (strncmp(argv[i], "-bg", 3) == 0) {
        !           134:             if (++i >= argc) Syntax(argv[0]);
        !           135:            bg_name = argv[i];
        !           136:            continue;
        !           137:        }
        !           138:         if (strncmp(argv[i], "-invert", 7) == 0) {
        !           139:            invert_sw = TRUE;
        !           140:            continue;
        !           141:        }
        !           142:         if (strncmp(argv[i], "-name", 5) == 0) {
        !           143:            if (++i >= argc) Syntax(argv[0]);
        !           144:             root_name = argv[i];
        !           145:            name_sw = TRUE;
        !           146:             continue;
        !           147:         }
        !           148:        if (strncmp(argv[i], "-cursor", 7) == 0) {
        !           149:             if (++i >= argc) Syntax(argv[0]);
        !           150:            cursor_fname = argv[i];
        !           151:             if (++i >= argc) Syntax(argv[0]);
        !           152:            mask_fname = argv[i];
        !           153:            cursor_sw = TRUE;
        !           154:            continue;
        !           155:        }
        !           156:        if (strncmp(argv[i], "-solid", 6) == 0) {
        !           157:            if (
        !           158:                gray_sw == TRUE ||
        !           159:                bitmap_sw == TRUE ||
        !           160:                mod_sw == TRUE
        !           161:            ) Syntax(argv[0]);
        !           162:             if (++i >= argc) Syntax(argv[0]);
        !           163:            solid_name = argv[i];
        !           164:            solid_sw = TRUE;
        !           165:            continue;
        !           166:        }
        !           167:        if (
        !           168:            (strncmp(argv[i], "-gray", 5) == 0) ||
        !           169:            (strncmp(argv[i], "-grey", 5) == 0)
        !           170:        ){
        !           171:            if (
        !           172:                solid_sw == TRUE ||
        !           173:                bitmap_sw == TRUE ||
        !           174:                mod_sw == TRUE
        !           175:            ) Syntax(argv[0]);
        !           176:            gray_sw = TRUE;
        !           177:            continue;
        !           178:        }
        !           179:        if (strncmp(argv[i], "-bitmap", 7) == 0) {
        !           180:            if (
        !           181:                gray_sw == TRUE ||
        !           182:                solid_sw == TRUE ||
        !           183:                mod_sw == TRUE
        !           184:            ) Syntax(argv[0]);
        !           185:             if (++i >= argc) Syntax(argv[0]);
        !           186:            bitmap_fname = argv[i];
        !           187:            bitmap_sw = TRUE;
        !           188:            continue;
        !           189:        }
        !           190:         if (strncmp(argv[i], "-mod", 5) == 0) {
        !           191:            if (
        !           192:                gray_sw == TRUE ||
        !           193:                bitmap_sw == TRUE ||
        !           194:                solid_sw == TRUE
        !           195:            ) Syntax(argv[0]);
        !           196:             if (++i >= argc) Syntax(argv[0]);
        !           197:             xmod = atoi(argv[i]);
        !           198:             if (++i >= argc) Syntax(argv[0]);
        !           199:             ymod = atoi(argv[i]);
        !           200:            mod_sw = TRUE;
        !           201:             continue;
        !           202:         }
        !           203:         Syntax(argv[0]);
        !           204:     }
        !           205:     
        !           206:     /*
        !           207:      * If there are no arguments then restore defaults.
        !           208:      */
        !           209:     if (argc == 1) def_sw = TRUE;
        !           210: 
        !           211:     /*
        !           212:      * Open the display.
        !           213:      */
        !           214:     if (XOpenDisplay(display) == NULL) {
        !           215:        fprintf(stderr, "%s: Can't open display '%s'\n",
        !           216:                argv[0], XDisplayName(display));
        !           217:        exit(1);
        !           218:     }
        !           219: 
        !           220:     /*
        !           221:      * Parse color definintions.
        !           222:      */
        !           223:     if ((DisplayCells() > 2) && (solid_name != NULL)) {
        !           224:        if (
        !           225:            XParseColor(solid_name, &color_def) &&
        !           226:            XGetHardwareColor(&color_def)
        !           227:        ) solid = color_def.pixel;
        !           228:     }
        !           229:     else if (solid_name && strcmp(solid_name, "black") == 0) solid = BlackPixel;
        !           230:     else if (solid_name && strcmp(solid_name, "white") == 0) solid = WhitePixel;
        !           231: 
        !           232:     if ((DisplayCells() > 2) && (fg_name != NULL)) {
        !           233:        if (
        !           234:            XParseColor(fg_name, &color_def) &&
        !           235:            XGetHardwareColor(&color_def)
        !           236:        ) fg = color_def.pixel;
        !           237:     }
        !           238:     else if (solid_name && strcmp(fg_name, "black") == 0) fg = BlackPixel;
        !           239:     else if (solid_name && strcmp(fg_name, "white") == 0) fg = WhitePixel;
        !           240: 
        !           241:     if ((DisplayCells() > 2) && (bg_name != NULL)) {
        !           242:        if (
        !           243:            XParseColor(bg_name, &color_def) &&
        !           244:            XGetHardwareColor(&color_def)
        !           245:        ) bg = color_def.pixel;
        !           246:     }
        !           247:     else if (bg_name && strcmp(bg_name, "black") == 0) bg = BlackPixel;
        !           248:     else if (bg_name && strcmp(bg_name, "white") == 0) bg = WhitePixel;
        !           249: 
        !           250:     if ((DisplayCells() > 2) && (mse_name != NULL)) {
        !           251:        if (
        !           252:            XParseColor(mse_name, &color_def) &&
        !           253:            XGetHardwareColor(&color_def)
        !           254:        ) mse = color_def.pixel;
        !           255:     }
        !           256:     else if (mse_name && strcmp(mse_name, "black") == 0) mse = BlackPixel;
        !           257:     else if (mse_name && strcmp(mse_name, "white") == 0) mse = WhitePixel;
        !           258: 
        !           259:     /*
        !           260:      * Set the root window name if a new root name supplied.
        !           261:      */
        !           262:     if (name_sw == TRUE) XStoreName(RootWindow, root_name);
        !           263: 
        !           264:     /*
        !           265:      * Set cursor if a cursor is supplied.
        !           266:      */
        !           267:     if (cursor_sw == TRUE) {
        !           268:        int status;
        !           269:        /*
        !           270:         * Open and read the mask file.
        !           271:         */
        !           272:        status = XReadBitmapFile(
        !           273:            mask_fname, 
        !           274:            &width, &height, &mask_bits,
        !           275:            NULL, NULL
        !           276:        );
        !           277:        if (status == 0) Error ("Unable to open mask file");
        !           278:        else if (status < 0) Error ("Unable to parse mask file");
        !           279:        else if ((width != BITMAP_SIZE) || (height != BITMAP_SIZE))
        !           280:            Error("Invaild mask Bitmap size");
        !           281:        /*
        !           282:         * Open and read the cursor file.
        !           283:         */
        !           284:        status = XReadBitmapFile(
        !           285:            cursor_fname,
        !           286:            &width, &height, &cursor_bits,
        !           287:            &x_hot, &y_hot
        !           288:        );
        !           289:        if (status == 0) Error ("Unable to open cursor file");
        !           290:        else if (status < 0) Error("Unable to parse cursor file");
        !           291:        else if ((width != BITMAP_SIZE) || (height != BITMAP_SIZE))
        !           292:            Error("Invaild cursor Bitmap size");
        !           293:        
        !           294: 
        !           295:        /*
        !           296:         * If there is no hot spot defined  or if the one defined is
        !           297:         * invalid, place the hot spot at BITMAP_HOT.
        !           298:         */
        !           299:        if (
        !           300:            (x_hot >= BITMAP_SIZE) || (x_hot < 0)
        !           301:        ){
        !           302:            x_hot = BITMAP_HOT;
        !           303:        }
        !           304:        if (
        !           305:            (y_hot >= BITMAP_SIZE) || (y_hot < 0)
        !           306:        ){
        !           307:            y_hot = BITMAP_HOT;
        !           308:        }
        !           309:        
        !           310:        /*
        !           311:         * Create the cursor.
        !           312:         */
        !           313:        cursor = XCreateCursor(
        !           314:            width, height,
        !           315:            cursor_bits, mask_bits,
        !           316:            x_hot, y_hot,
        !           317:            mse, bg,
        !           318:            GXcopy
        !           319:        );
        !           320:        if (cursor == FAILURE) Error("Unable to store cursor");
        !           321: 
        !           322:        /*
        !           323:         * Define the root window's cursor to be the new
        !           324:         * cursor.
        !           325:         */
        !           326:        XDefineCursor(RootWindow, cursor);
        !           327:     }
        !           328: 
        !           329:     /*
        !           330:      * Set background to a solid color if requested.
        !           331:      */
        !           332:     if (solid_sw == TRUE) {
        !           333:        /*
        !           334:         * Create the tile Pixmap.
        !           335:         */
        !           336:        bkgnd_pixmap = XMakeTile(solid);
        !           337:        if (bkgnd_pixmap == FAILURE) Error("Unable to store solid Pixmap");
        !           338:        /*
        !           339:         * Change the window.
        !           340:         */
        !           341:        XChangeBackground(RootWindow, bkgnd_pixmap);
        !           342:        Done();
        !           343:     }
        !           344:        
        !           345:     /*
        !           346:      * Set background to a gray pattern if requested.
        !           347:      */
        !           348:     if (gray_sw == TRUE) {
        !           349:        /*
        !           350:         * Create the Bitmap.
        !           351:         */
        !           352:        bkgnd_bitmap = XStoreBitmap(BITMAP_SIZE, BITMAP_SIZE, gray_bits);
        !           353:        if (bkgnd_bitmap == FAILURE) Error("Unable to store gray Bitmap");
        !           354:        /*
        !           355:         * Create the tile Pixmap.
        !           356:         */
        !           357:        if (invert_sw == TRUE) {
        !           358:            bkgnd_pixmap = XMakePixmap(bkgnd_bitmap, bg, fg);
        !           359:        }
        !           360:        else {
        !           361:            bkgnd_pixmap = XMakePixmap(bkgnd_bitmap, fg, bg);
        !           362:        }
        !           363:        if (bkgnd_pixmap == FAILURE) Error("Unable to store gray Pixmap");
        !           364:        /*
        !           365:         * Change the window.
        !           366:         */
        !           367:        XChangeBackground(RootWindow, bkgnd_pixmap);
        !           368:        Done();
        !           369:     }
        !           370:        
        !           371:     /*
        !           372:      * Set background to a bitmap pattern if requested.
        !           373:      */
        !           374:     if (bitmap_sw == TRUE) {
        !           375:        int status;
        !           376:        /*
        !           377:         * Open and read the bitmap file.
        !           378:         */
        !           379:        status = XReadBitmapFile(
        !           380:            bitmap_fname,
        !           381:            &width, &height, &bkgnd_bits,
        !           382:            &x_hot, &y_hot
        !           383:        );
        !           384:        if (status == 0) Error ("Unable to open Bitmap file");
        !           385:        else if (status < 0) Error("Unable to parse Bitmap file");
        !           386:        else if ((width != BITMAP_SIZE) || (height != BITMAP_SIZE))
        !           387:            Error("Invaild Bitmap size");
        !           388:        bkgnd_bitmap = XStoreBitmap (width, height, bkgnd_bits);
        !           389:        if (bkgnd_bitmap == FAILURE)
        !           390:            Error("Unable to store Bitmap");
        !           391:        
        !           392:        /*
        !           393:         * Create the tile pixmap.
        !           394:         */
        !           395:        if (invert_sw == TRUE) {
        !           396:            bkgnd_pixmap = XMakePixmap(bkgnd_bitmap, bg, fg);
        !           397:        }
        !           398:        else {
        !           399:            bkgnd_pixmap = XMakePixmap(bkgnd_bitmap, fg, bg);
        !           400:        }
        !           401:        if (bkgnd_pixmap == FAILURE) Error("Unable to store Pixmap");
        !           402:        /*
        !           403:         * Change the window.
        !           404:         */
        !           405:        XChangeBackground(RootWindow, bkgnd_pixmap);
        !           406:        Done();
        !           407:     }
        !           408: 
        !           409:     /*
        !           410:      * Set background to a modula pattern if requested.
        !           411:      */
        !           412:     if (mod_sw == TRUE) {
        !           413:        bkgnd_bits = (short *) malloc (BITMAP_SIZE*sizeof(short));
        !           414:        /*
        !           415:         * Compute modula bits.
        !           416:         */
        !           417:        for (x = 0; x < BITMAP_SIZE; x++) {
        !           418:            pattern_line <<= 1;
        !           419:            if (x % xmod == 0) pattern_line |= 0x0001;
        !           420:        }
        !           421:        for (y = 0; y < BITMAP_SIZE; y++) {
        !           422:            if (y % ymod == 0) {
        !           423:                bkgnd_bits[y] = solid_line;
        !           424:            }
        !           425:            else {
        !           426:                bkgnd_bits[y] = pattern_line;
        !           427:            }
        !           428:        }
        !           429:        /*
        !           430:         * Create and store the pattern pixmap.
        !           431:         */
        !           432:        bkgnd_bitmap = XStoreBitmap(BITMAP_SIZE, BITMAP_SIZE, bkgnd_bits);
        !           433:        if (bkgnd_bitmap == FAILURE) Error("Error storing bitmap");
        !           434:        if (invert_sw == TRUE) {
        !           435:            bkgnd_pixmap = XMakePixmap(bkgnd_bitmap, bg, fg);
        !           436:        }
        !           437:        else {
        !           438:            bkgnd_pixmap = XMakePixmap(bkgnd_bitmap, fg, bg);
        !           439:        }
        !           440:        if (bkgnd_pixmap == FAILURE) Error("Error storing pixmap");
        !           441:        XChangeBackground(RootWindow, bkgnd_pixmap);
        !           442:        Done();
        !           443:     }
        !           444: 
        !           445:     /*
        !           446:      * If we got here then check to see if the default switch is on
        !           447:      * OR if there were no arguments.
        !           448:      */
        !           449:     if (def_sw == TRUE) {
        !           450:        if (name_sw == FALSE) XStoreName(RootWindow, DEF_ROOT_NAME);
        !           451:        if (cursor_sw == FALSE) XUndefineCursor(RootWindow);
        !           452:        XChangeBackground(RootWindow, (Pixmap)0);
        !           453:        Done();
        !           454:     }
        !           455:     else XFlush();
        !           456:     exit(0);
        !           457: }
        !           458: 
        !           459: 
        !           460: 
        !           461: /*
        !           462:  * Clear the root window, flush all output and exit.
        !           463:  */
        !           464: Done()
        !           465: {
        !           466:     XClear(RootWindow);
        !           467:     XFlush();
        !           468:     exit(0);
        !           469: }
        !           470: 
        !           471: 
        !           472: 
        !           473: /*
        !           474:  * Report an internal error.
        !           475:  */
        !           476: Error(description)
        !           477:     char *description;
        !           478: {
        !           479:     printf ("\nxsetroot: %s.\n\n", description);
        !           480:     exit(1);
        !           481: }
        !           482: 
        !           483: 
        !           484: 
        !           485: /*
        !           486:  * Report the syntax for calling xsetroot.
        !           487:  */
        !           488: Syntax(call)
        !           489:     char *call;
        !           490: {
        !           491:     printf("\nUsage: %s [-help] [-def] [-fg <color>] [-bg <color>] [-invert]\n", call);
        !           492:     printf("         [-name <string>] [-cursor <cursor file> <mask file>]\n");
        !           493:     printf("         [-solid <color>] [-gray, -grey] [-bitmap <file>]\n");
        !           494:     printf("         [-mod <x> <y>] [[<host>]:<vs>]\n");
        !           495:     printf("\nNOTE: *** Use only one of [-solid] [-gray, -grey] [-bitmap] [-mod] ***\n\n");
        !           496:     exit(1);
        !           497: }
        !           498: 
        !           499: /* End of xsetroot.c */

unix.superglobalmegacorp.com

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