Annotation of researchv9/X11/src/X.V11R1/clients/xsetroot/xsetroot.c, revision 1.1

1.1     ! root        1: /* Copyright 1987, Massachusetts Institute of Technology */
        !             2: 
        !             3: #include <X11/Xlib.h>
        !             4: #include <X11/Xutil.h>
        !             5: #include <stdio.h>
        !             6: 
        !             7: /*
        !             8:  * xsetroot.c  MIT Project Athena, X Window system root window 
        !             9:  *             parameter setting utility.  This program will set 
        !            10:  *             various parameters of the X root window.
        !            11:  *
        !            12:  *  Author:    Mark Lillibridge, MIT Project Athena
        !            13:  *             11-Jun-87
        !            14:  */
        !            15: 
        !            16: /* Include routines to handle parsing defaults */
        !            17: #include "wsimple.h"
        !            18: 
        !            19: #include "X11/bitmaps/gray"
        !            20: 
        !            21: usage()
        !            22: {
        !            23:        outl("%s: usage: %s [-fg <color>] [-bg <color>] [-rv] [-help] [-def] [-name <string>] [-cursor <cursor file> <mask file>] [-solid <color>] [-gray] [-grey] [-bitmap <filename>] [-mod <x> <y>] [<host>:<display>]\n\nNOTE: *** Use only one of -solid, -gray, -grey, -bitmap, and -mod ***\n\n", program_name, program_name);
        !            24:        exit(1);
        !            25: }
        !            26: 
        !            27: extern Pixmap MakeModulaBitmap();
        !            28: 
        !            29: main(argc, argv) 
        !            30:      int argc;
        !            31:      char **argv;
        !            32: {
        !            33:   int excl = 0;
        !            34:   int restore_defaults = 0;
        !            35:   char *name = 0;
        !            36:   char *cursor_file = 0;
        !            37:   char *cursor_mask = 0;
        !            38:   Cursor cursor;
        !            39:   char *solid_color = 0;
        !            40:   int gray = 0;
        !            41:   char *bitmap_file = 0;
        !            42:   int mod_x = -1;
        !            43:   int mod_y = -1;
        !            44:   register int i;
        !            45:   Pixmap bitmap;
        !            46:   int ww, hh;
        !            47: 
        !            48:   INIT_NAME;
        !            49: 
        !            50:   /* Handle command line arguments, open the display */
        !            51:   Get_X_Options(&argc, argv);
        !            52: 
        !            53:   for (i = 1; i < argc; i++) {
        !            54:     if (!strcmp("-", argv[i]))
        !            55:       continue;
        !            56:     if (!strcmp("-help", argv[i]))
        !            57:       usage();
        !            58:     if (!strcmp("-def", argv[i])) {
        !            59:       restore_defaults = 1;
        !            60:       continue;
        !            61:     }
        !            62:     if (!strcmp("-name", argv[i])) {
        !            63:       if (++i>=argc) usage();
        !            64:       name = argv[i];
        !            65:       continue;
        !            66:     }
        !            67:     if (!strcmp("-cursor", argv[i])) {
        !            68:       if (i++>=argc) usage();
        !            69:       cursor_file = argv[i];
        !            70:       if (i++>=argc) usage();
        !            71:       cursor_mask = argv[i];
        !            72:       continue;
        !            73:     }
        !            74:     if (!strcmp("-solid", argv[i])) {
        !            75:       if (i++>=argc) usage();
        !            76:       solid_color = argv[i];
        !            77:       excl++;
        !            78:       continue;
        !            79:     }
        !            80:     if (!strcmp("-gray", argv[i]) || !strcmp("-grey", argv[i])) {
        !            81:       gray = 1;
        !            82:       excl++;
        !            83:       continue;
        !            84:     }
        !            85:     if (!strcmp("-bitmap", argv[i])) {
        !            86:       if (++i>=argc) usage();
        !            87:       bitmap_file = argv[i];
        !            88:       excl++;
        !            89:       continue;
        !            90:     }
        !            91:     if (!strcmp("-mod", argv[i])) {
        !            92:       if (++i>=argc) usage();
        !            93:       mod_x = atoi(argv[i]);
        !            94:       if (++i>=argc) usage();
        !            95:       mod_y = atoi(argv[i]);
        !            96:       excl++;
        !            97:       continue;
        !            98:     }
        !            99:     usage();
        !           100:   } 
        !           101: 
        !           102:   /* Check for multiple use of exclusive options */
        !           103:   if (excl > 1)
        !           104:     usage();
        !           105: 
        !           106:   /* If there are no arguments then restore defaults. */
        !           107:   if (argc == 1 || (argc == 2 && !strcmp(argv[1],"-")))
        !           108:     restore_defaults = 1;
        !           109: 
        !           110:   /* Resolve the X options */
        !           111:   Resolve_X_Options();
        !           112: 
        !           113:   /* Handle a cursor file */
        !           114:   if (cursor_file) {
        !           115:          cursor = CreateCursorFromFiles(cursor_file, cursor_mask, fore_color,
        !           116:                                         back_color);
        !           117: 
        !           118:          XDefineCursor(dpy, RootWindow(dpy, screen), cursor);
        !           119: 
        !           120:          XFreeCursor(dpy, cursor);
        !           121:   }
        !           122: 
        !           123:   /* Handle -gray and -grey options */
        !           124:   if (gray)
        !           125:     SetBackgroundToData(gray_bits, gray_width, gray_height);
        !           126: 
        !           127:   /* Handle -solid option */
        !           128:   if (solid_color)
        !           129:     XSetWindowBackground(dpy, RootWindow(dpy, screen),
        !           130:                         Resolve_Color(RootWindow(dpy, screen),
        !           131:                                       solid_color));
        !           132: 
        !           133:   /* Handle -bitmap option */
        !           134:   if (bitmap_file) {
        !           135:          bitmap = ReadBitmapFile(RootWindow(dpy, screen), bitmap_file,
        !           136:                                  &ww, &hh, 0, 0);
        !           137:          SetBackgroundToBitmap(bitmap, ww, hh);
        !           138:   }
        !           139: 
        !           140:   /* Handle set background to a modula pattern */
        !           141:   if (mod_x != -1)
        !           142:     SetBackgroundToBitmap(MakeModulaBitmap(mod_x, mod_y), 16, 16);
        !           143: 
        !           144:   /* Handle set name */
        !           145:   if (name)
        !           146:     XStoreName(dpy, RootWindow(dpy, screen), name);
        !           147: 
        !           148:   /* Handle restore defaults */
        !           149:   if (restore_defaults) {
        !           150:     if (!cursor_file)
        !           151:       XUndefineCursor(dpy, RootWindow(dpy, screen)); 
        !           152:     if (!excl)
        !           153:       XSetWindowBackgroundPixmap(dpy, RootWindow(dpy, screen), (Pixmap) 0);
        !           154:   }
        !           155: 
        !           156:   /* Clear the root window, flush all output and exit. */
        !           157:   XClearWindow(dpy, RootWindow(dpy, screen));
        !           158:   XCloseDisplay(dpy);
        !           159: }
        !           160: 
        !           161: 
        !           162: /*
        !           163:  * SetBackgroundToBitmap: Set the root window background to a caller supplied 
        !           164:  *                        bitmap.
        !           165:  */
        !           166: SetBackgroundToBitmap(bitmap, width, height)
        !           167:      Pixmap bitmap;
        !           168:      int width, height;
        !           169: {
        !           170:        Pixmap pix;
        !           171:        GC gc;
        !           172:        XGCValues gc_init;
        !           173:        long temp;
        !           174: 
        !           175:        gc_init.foreground = Resolve_Color(RootWindow(dpy,screen),fore_color);
        !           176:        gc_init.background = Resolve_Color(RootWindow(dpy,screen),back_color);
        !           177:        if (reverse) {
        !           178:                temp=gc_init.foreground;
        !           179:                gc_init.foreground=gc_init.background;
        !           180:                gc_init.background=temp;
        !           181:        }
        !           182:        gc = XCreateGC(dpy, RootWindow(dpy, screen),GCForeground|GCBackground,
        !           183:                       &gc_init);
        !           184: 
        !           185:        pix = Bitmap_To_Pixmap(dpy, RootWindow(dpy, screen), gc, bitmap,
        !           186:                               width, height);
        !           187: 
        !           188:        XSetWindowBackgroundPixmap(dpy, RootWindow(dpy, screen), pix);
        !           189: }
        !           190: 
        !           191: 
        !           192: /*
        !           193:  * SetBackgroundToData: As SetBackgroundToBitmap but uses the data for
        !           194:  *                      a bitmap instead of an actual bitmap.  Data format
        !           195:  *                      is that used by XCreateBitmapFromData.
        !           196:  */
        !           197: SetBackgroundToData(data, width, height)
        !           198: char *data;
        !           199: int width, height;
        !           200: {
        !           201:        Pixmap bitmap;
        !           202: 
        !           203:        bitmap = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
        !           204:                                       data, width, height);
        !           205: 
        !           206:        SetBackgroundToBitmap(bitmap, width, height);
        !           207: }
        !           208: 
        !           209: 
        !           210: /*
        !           211:  * CreateCursorFromFiles: make a cursor of the right colors from two bitmap
        !           212:  *                        files.
        !           213:  */
        !           214: #define BITMAP_HOT_DEFAULT 8
        !           215: 
        !           216: CreateCursorFromFiles(cursor_file, mask_file, fore_color, back_color)
        !           217: char *cursor_file, *mask_file;
        !           218: char *fore_color, *back_color;
        !           219: {
        !           220:        Pixmap cursor_bitmap, mask_bitmap;
        !           221:        int width, height, ww, hh, x_hot, y_hot;
        !           222:        Cursor cursor;
        !           223:        XColor fg, bg, temp, NameToXColor();
        !           224: 
        !           225:        fg = NameToXColor(fore_color);
        !           226:        bg = NameToXColor(back_color);
        !           227:        if (reverse) {
        !           228:                temp = fg; fg = bg; bg = temp;
        !           229:        }
        !           230: 
        !           231:        cursor_bitmap = ReadBitmapFile(RootWindow(dpy, screen),
        !           232:                                       cursor_file, &width, &height,
        !           233:                                       &x_hot, &y_hot);
        !           234:        mask_bitmap = ReadBitmapFile(RootWindow(dpy, screen), mask_file,
        !           235:                                     &ww, &hh, 0, 0);
        !           236: 
        !           237:        if (width != ww || height != hh)
        !           238:          Fatal_Error("Dimensions of cursor bitmap and cursor mask bitmap are different!");
        !           239: 
        !           240:        if (x_hot == -1) {
        !           241:                x_hot = BITMAP_HOT_DEFAULT;
        !           242:                y_hot = BITMAP_HOT_DEFAULT;
        !           243:        }
        !           244: 
        !           245:        cursor = XCreatePixmapCursor(dpy, cursor_bitmap, mask_bitmap, &fg, &bg,
        !           246:                                     x_hot, y_hot);
        !           247: 
        !           248:        return(cursor);
        !           249: }
        !           250: 
        !           251: 
        !           252: /*
        !           253:  * MakeModulaBitmap: Returns a modula bitmap based on an x & y mod.
        !           254:  */
        !           255: Pixmap MakeModulaBitmap(mod_x, mod_y)
        !           256: int mod_x, mod_y;
        !           257: {
        !           258:        int i;
        !           259:        long pattern_line = 0;
        !           260:        char modula_data[16*16/8];
        !           261: 
        !           262:        if (mod_x<1)
        !           263:          mod_x=1;
        !           264:        if (mod_y<1)
        !           265:          mod_y=1;
        !           266: 
        !           267:        for (i=0; i<16; i++) {
        !           268:                pattern_line <<=1;
        !           269:                if (i % mod_x == 0) pattern_line |= 0x0001;
        !           270:        }
        !           271:        for (i=0; i<16; i++) {
        !           272:                if (i % mod_y) {
        !           273:                        modula_data[i*2] = 0xff;
        !           274:                        modula_data[i*2+1] = 0xff;
        !           275:                } else {
        !           276:                        modula_data[i*2] = pattern_line & 0xff;
        !           277:                        modula_data[i*2+1] = (pattern_line>>8) & 0xff;
        !           278:                }
        !           279:        }
        !           280: 
        !           281: 
        !           282:        return(XCreateBitmapFromData(dpy, RootWindow(dpy, screen), modula_data,
        !           283:                                     16, 16));
        !           284: }
        !           285: 
        !           286: 
        !           287: /*
        !           288:  * NameToXColor: Convert the name of a color to its Xcolor value.
        !           289:  */
        !           290: XColor NameToXColor(name)
        !           291: char *name;
        !           292: {
        !           293:        XColor c;
        !           294:        Colormap cmap;
        !           295:        
        !           296:        cmap = DefaultColormap(dpy, screen);
        !           297: 
        !           298:        if (!XParseColor(dpy, cmap, name, &c))
        !           299:          Fatal_Error("unknown color or bad color format: %s", name);
        !           300: 
        !           301:        return(c);
        !           302: }

unix.superglobalmegacorp.com

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