/* * $TOG: xsetroot.c /main/24 1998/02/09 14:12:40 kaleb $ * Copyright 1987, 1998 The Open Group All Rights Reserved. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ /* * xsetroot.c MIT Project Athena, X Window System root window * parameter setting utility. This program will set * various parameters of the X root window. * * Author: Mark Lillibridge, MIT Project Athena * 11-Jun-87 */ #include #include #include #include #include "X11/bitmaps/gray" #define Dynamic 1 char *program_name; Display *dpy; int screen; Window root; char *fore_color = NULL; char *back_color = NULL; int reverse = 0; int save_colors = 0; int unsave_past = 0; Pixmap save_pixmap = (Pixmap)None; Pixmap MakeModulaBitmap(), ReadBitmapFile(); XColor NameToXColor(); unsigned long NameToPixel(); Cursor CreateCursorFromName(); void FixupState(); void SetBackgroundToBitmap(Pixmap bitmap, unsigned int width, unsigned int height); void doit(argc, argv) int argc; char **argv; { int excl = 0; int nonexcl = 0; int restore_defaults = 0; char *display_name = NULL; char *name = NULL; char *cursor_file = NULL; char *cursor_mask = NULL; char *cursor_name = NULL; char *solid_color = NULL; Cursor cursor; int gray = 0; char *bitmap_file = NULL; int mod_x = 0; int mod_y = 0; register int i; unsigned int ww, hh; Pixmap bitmap; program_name=argv[0]; dpy = XOpenDisplay(display_name); screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); /* Handle -gray and -grey options */ bitmap = XCreateBitmapFromData(dpy, root, gray_bits, gray_width, gray_height); SetBackgroundToBitmap(bitmap, gray_width, gray_height); FixupState(); XCloseDisplay(dpy); } /* Free past incarnation if needed, and retain state if needed. */ void FixupState() { Atom prop, type; int format; unsigned long length, after; unsigned char *data; if (!(DefaultVisual(dpy, screen)->class & Dynamic)) unsave_past = 0; if (!unsave_past && !save_colors) return; prop = XInternAtom(dpy, "_XSETROOT_ID", False); if (unsave_past) { (void)XGetWindowProperty(dpy, root, prop, 0L, 1L, True, AnyPropertyType, &type, &format, &length, &after, &data); if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0)) XKillClient(dpy, *((Pixmap *)data)); else if (type != None) fprintf(stderr, "%s: warning: _XSETROOT_ID property is garbage\n", program_name); } if (save_colors) { if (!save_pixmap) save_pixmap = XCreatePixmap(dpy, root, 1, 1, 1); XChangeProperty(dpy, root, prop, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &save_pixmap, 1); XSetCloseDownMode(dpy, RetainPermanent); } } /* * SetBackgroundToBitmap: Set the root window background to a caller supplied * bitmap. */ void SetBackgroundToBitmap(bitmap, width, height) Pixmap bitmap; unsigned int width, height; { Pixmap pix; GC gc; XGCValues gc_init; gc_init.foreground = NameToPixel(fore_color, BlackPixel(dpy, screen)); gc_init.background = NameToPixel(back_color, WhitePixel(dpy, screen)); if (reverse) { unsigned long temp=gc_init.foreground; gc_init.foreground=gc_init.background; gc_init.background=temp; } gc = XCreateGC(dpy, root, GCForeground|GCBackground, &gc_init); pix = XCreatePixmap(dpy, root, width, height, (unsigned int)DefaultDepth(dpy, screen)); XCopyPlane(dpy, bitmap, pix, gc, 0, 0, width, height, 0, 0, (unsigned long)1); XSetWindowBackgroundPixmap(dpy, root, pix); XFreeGC(dpy, gc); XFreePixmap(dpy, bitmap); if (save_colors) save_pixmap = pix; else XFreePixmap(dpy, pix); XClearWindow(dpy, root); unsave_past = 1; } unsigned long NameToPixel(name, pixel) char *name; unsigned long pixel; { XColor ecolor; if (!name || !*name) return pixel; if (!XParseColor(dpy,DefaultColormap(dpy,screen),name,&ecolor)) { fprintf(stderr,"%s: unknown color \"%s\"\n",program_name,name); return 1; } if (!XAllocColor(dpy, DefaultColormap(dpy, screen),&ecolor)) { fprintf(stderr, "%s: unable to allocate color for \"%s\"\n", program_name, name); return 1; } if ((ecolor.pixel != BlackPixel(dpy, screen)) && (ecolor.pixel != WhitePixel(dpy, screen)) && (DefaultVisual(dpy, screen)->class & Dynamic)) save_colors = 1; return(ecolor.pixel); }