void SetDeskPageBackground(const Command *c) { Display *dpy2 = NULL; Window root2 = None; int screen2; Pixmap pix = None; current_colorset = -1; /* FvwmBacker bg preperation */ switch (c->type) { case 1: /* solid colors */ case 2: /* colorset */ dpy2 = XOpenDisplay(displayName); if (!dpy2) { fvwm_msg(ERR, "FvwmBacker", "Fail to create a forking dpy, Exit!"); exit(2); } screen2 = DefaultScreen(dpy2); root2 = RootWindow(dpy2, screen2); if (RetainPixmap) { XSetCloseDownMode(dpy2, RetainPermanent); } XGrabServer(dpy2); DeleteRootAtoms(dpy2, root2); switch (c->type) { case 2: current_colorset = c->colorset; /* Process a colorset */ if (CSET_IS_TRANSPARENT(c->colorset)) { fvwm_msg(ERR,"FvwmBacker", "You cannot " "use a transparent colorset as " "background!"); XUngrabServer(dpy2); XCloseDisplay(dpy2); return; } else if (Pdepth != DefaultDepth(dpy2, screen2)) { fvwm_msg(ERR,"FvwmBacker", "You cannot " "use a colorset background if\n" "the fvwm depth is not equal " "to the root depth!"); XUngrabServer(dpy2); XCloseDisplay(dpy2); return; } else if (RetainPixmap) { pix = CreateBackgroundPixmap( dpy2, root2, MyDisplayWidth, MyDisplayHeight, &Colorset[c->colorset], DefaultDepth(dpy2, screen2), DefaultGC(dpy2, screen2), False); if (pix != None) { XSetWindowBackgroundPixmap( dpy2, root2, pix); XClearWindow(dpy2, root2); } } else { SetWindowBackground( dpy2, root2, MyDisplayWidth, MyDisplayHeight, &Colorset[c->colorset], DefaultDepth(dpy2, screen2), DefaultGC(dpy2, screen2), True); } break; case 1: /* Process a solid color request */ if (RetainPixmap) { GC gc; XGCValues xgcv; xgcv.foreground = c->solidColor; gc = fvwmlib_XCreateGC( dpy2, root2, GCForeground, &xgcv); pix = XCreatePixmap( dpy2, root2, 1, 1, DefaultDepth(dpy2, screen2)); XFillRectangle( dpy2, pix, gc, 0, 0, 1, 1); XFreeGC(dpy2, gc); } XSetWindowBackground(dpy2, root2, c->solidColor); XClearWindow(dpy2, root2); break; } SetRootAtoms(dpy2, root2, pix); XUngrabServer(dpy2); XCloseDisplay(dpy2); /* this XSync, Ungrab, ...etc */ break; case -1: case 0: default: if(c->cmdStr != NULL) { SendFvwmPipe(fvwm_fd, c->cmdStr, (unsigned long)0); } break; } }
/* Draws a colorset background into the specified rectangle in the target * drawable. */ void SetClippedRectangleBackground( Display *dpy, Window win, int x, int y, int width, int height, XRectangle *clip, colorset_t *colorset, unsigned int depth, GC gc) { GC draw_gc; Pixmap pixmap2; Pixmap pixmap = None; static int last_depth = -1; static GC last_gc = None; XGCValues xgcv; Pixmap clipmask = None; GC clip_gc = None; Bool keep_aspect = (colorset->pixmap_type == PIXMAP_STRETCH_ASPECT); Bool stretch_x = (colorset->pixmap_type == PIXMAP_STRETCH_X) || (colorset->pixmap_type == PIXMAP_STRETCH); Bool stretch_y = (colorset->pixmap_type == PIXMAP_STRETCH_Y) || (colorset->pixmap_type == PIXMAP_STRETCH); int dest_x, dest_y, dest_w, dest_h; if (clip) { dest_x = clip->x; dest_y = clip->y; dest_w = clip->width; dest_h = clip->height; } else { dest_x = x; dest_y = y; dest_w = width; dest_h = height; } if (CSETS_IS_TRANSPARENT_PR_TINT(colorset)) { XClearArea(dpy, win, dest_x, dest_y, dest_w, dest_h, False); PGraphicsTintRectangle( dpy, win, colorset->tint, colorset->tint_percent, win, True, gc, None, None, dest_x, dest_y, dest_w, dest_h); return; } if (CSETS_IS_TRANSPARENT_PR_PURE(colorset)) { XClearArea(dpy, win, dest_x, dest_y, dest_w, dest_h, False); /* don't do anything */ return; } if (CSETS_IS_TRANSPARENT_ROOT(colorset)) { /* FIXME: optimize this ! */ x = y = 0; width = width + dest_x; height = height + dest_y; } /* minimize gc creation by remembering the last requested depth */ if (last_gc != None && depth != last_depth) { XFreeGC(dpy, last_gc); last_gc = None; } if (last_gc == None) { last_gc = fvwmlib_XCreateGC(dpy, win, 0, &xgcv); } draw_gc = last_gc; last_depth = depth; if (FHaveShapeExtension && colorset->shape_mask != None) { clipmask = CreateBackgroundPixmap( dpy, 0, width, height, colorset, 1, None, True); if (clipmask) { /* create a GC for clipping */ xgcv.clip_x_origin = x; xgcv.clip_y_origin = y; xgcv.clip_mask = clipmask; clip_gc = fvwmlib_XCreateGC( dpy, win, GCClipXOrigin | GCClipYOrigin | GCClipMask, &xgcv); draw_gc = clip_gc; } } if (!colorset->pixmap) { /* use the bg pixel */ XSetForeground(dpy, draw_gc, colorset->bg); XFillRectangle( dpy, win, draw_gc, dest_x, dest_y, dest_w, dest_h); } else { pixmap = CreateBackgroundPixmap( dpy, win, width, height, colorset, depth, gc, False); if (keep_aspect) { /* nothing to do */ } if (stretch_x || stretch_y) { if (!stretch_x && colorset->width != width) { pixmap2 = CreateStretchXPixmap( dpy, pixmap, colorset->width, height, depth, width, gc); XFreePixmap(dpy, pixmap); pixmap = pixmap2; } if (!stretch_y && colorset->height != height) { pixmap2 = CreateStretchYPixmap( dpy, pixmap, width, colorset->height, depth, height, gc); XFreePixmap(dpy, pixmap); pixmap = pixmap2; } } else { pixmap2 = CreateTiledPixmap( dpy, pixmap, colorset->width, colorset->height, width, height, depth, gc); XFreePixmap(dpy, pixmap); pixmap = pixmap2; } if (pixmap) { /* Copy the pixmap into the rectangle. */ XCopyArea( dpy, pixmap, win, draw_gc, dest_x - x, dest_y - y, dest_w, dest_h, dest_x, dest_y); XFreePixmap(dpy, pixmap); } } if (FHaveShapeExtension) { if (clipmask != None) { XFreePixmap(dpy, clipmask); } if (clip_gc != None) { XFreeGC(dpy, clip_gc); } } return; }
/* Draws a colorset background into the specified rectangle in the target * drawable. */ void SetRectangleBackground( Display *dpy, Window win, int x, int y, int width, int height, colorset_struct *colorset, unsigned int depth, GC gc) { GC draw_gc; Pixmap pixmap2; Pixmap pixmap = None; static int last_depth = -1; static GC last_gc = None; XGCValues xgcv; Pixmap clipmask = None; GC clip_gc = None; Bool keep_aspect = (colorset->pixmap_type == PIXMAP_STRETCH_ASPECT); Bool stretch_x = (colorset->pixmap_type == PIXMAP_STRETCH_X) || (colorset->pixmap_type == PIXMAP_STRETCH); Bool stretch_y = (colorset->pixmap_type == PIXMAP_STRETCH_Y) || (colorset->pixmap_type == PIXMAP_STRETCH); if (colorset->pixmap == ParentRelative) { XClearArea(dpy, win, x, y, width, height, False); /* don't do anything */ return; } /* minimize gc creation by remembering the last requested depth */ if (last_gc != None && depth != last_depth) { XFreeGC(dpy, last_gc); last_gc = None; } if (last_gc == None) { last_gc = fvwmlib_XCreateGC(dpy, win, 0, &xgcv); } draw_gc = last_gc; last_depth = depth; if (FHaveShapeExtension && colorset->shape_mask != None) { clipmask = CreateBackgroundPixmap( dpy, 0, width, height, colorset, 1, None, True); if (clipmask) { /* create a GC for clipping */ xgcv.clip_x_origin = x; xgcv.clip_y_origin = y; xgcv.clip_mask = clipmask; clip_gc = fvwmlib_XCreateGC( dpy, win, GCClipXOrigin|GCClipYOrigin|GCClipMask, &xgcv); draw_gc = clip_gc; } } if (!colorset->pixmap) { /* use the bg pixel */ XSetForeground(dpy, draw_gc, colorset->bg); XFillRectangle(dpy, win, draw_gc, x, y, width, height); } else { pixmap = CreateBackgroundPixmap( dpy, win, width, height, colorset, depth, gc, False); if (keep_aspect) { /* nothing to do */ } if (stretch_x || stretch_y) { if (!stretch_x && colorset->width != width) { pixmap2 = CreateStretchXPixmap( dpy, pixmap, colorset->width, height, depth, width, gc); XFreePixmap(dpy, pixmap); pixmap = pixmap2; } if (!stretch_y && colorset->height != height) { pixmap2 = CreateStretchYPixmap( dpy, pixmap, width, colorset->height, depth, width, gc); XFreePixmap(dpy, pixmap); pixmap = pixmap2; } } else { pixmap2 = CreateTiledPixmap( dpy, pixmap, colorset->width, colorset->height, width, height, depth, gc); XFreePixmap(dpy, pixmap); pixmap = pixmap2; } if (pixmap) { /* Copy the pixmap into the rectangle. */ XCopyArea(dpy, pixmap, win, draw_gc, 0, 0, width, height, x, y); XFreePixmap(dpy, pixmap); } } if (FHaveShapeExtension) { if (clipmask != None) XFreePixmap(dpy, clipmask); if (clip_gc != None) XFreeGC(dpy, clip_gc); } }
/* sets a window background from a colorset * if width or height are zero the window size is queried */ void SetWindowBackgroundWithOffset( Display *dpy, Window win, int x_off, int y_off, unsigned int width, unsigned int height, colorset_t *colorset, unsigned int depth, GC gc, Bool clear_area) { Pixmap pixmap = None; Pixmap mask = None; union { XID junk; unsigned int ui_junk; int i_junk; } XID_int; if (0 == width || 0 == height) { if (!XGetGeometry( dpy, win, &XID_int.junk, &XID_int.i_junk, &XID_int.i_junk, (unsigned int *)&width, (unsigned int *)&height, &XID_int.ui_junk, &XID_int.ui_junk)) { return; } } if (FHaveShapeExtension && colorset->shape_mask) { mask = CreateBackgroundPixmap( dpy, None, width, height, colorset, 1, None, True); if (mask != None) { FShapeCombineMask( dpy, win, FShapeBounding, 0, 0, mask, FShapeSet); XFreePixmap(dpy, mask); } } if (!colorset->pixmap) { /* use the bg pixel */ XSetWindowBackground(dpy, win, colorset->bg); if (clear_area) { XClearArea(dpy, win, 0, 0, width, height, True); } } else { pixmap = CreateOffsetBackgroundPixmap( dpy, win, x_off, y_off, width, height, colorset, depth, gc, False); if (pixmap) { XSetWindowBackgroundPixmap(dpy, win, pixmap); if (clear_area) { XClearArea(dpy, win, 0, 0, width, height, True); } if (pixmap != ParentRelative) { XFreePixmap(dpy, pixmap); } } } return; }
/* sets a window background from a colorset * if width or height are zero the window size is queried */ void SetWindowBackgroundWithOffset( Display *dpy, Window win, int x_off, int y_off, int width, int height, colorset_struct *colorset, unsigned int depth, GC gc, Bool clear_area) { Pixmap pixmap = None; Pixmap mask = None; XID junk; if (0 == width || 0 == height) { if (!XGetGeometry( dpy, win, &junk, (int *)&junk, (int *)&junk, (unsigned int *)&width, (unsigned int *)&height, (unsigned int *)&junk, (unsigned int *)&junk)) { return; } } if (FHaveShapeExtension && colorset->shape_mask) { mask = CreateBackgroundPixmap( dpy, 0, width, height, colorset, 1, None, True); if (mask != None) { FShapeCombineMask( dpy, win, FShapeBounding, 0, 0, mask, FShapeSet); XFreePixmap(dpy, mask); } } if (!colorset->pixmap) { /* use the bg pixel */ XSetWindowBackground(dpy, win, colorset->bg); if (clear_area) { XClearArea(dpy, win, 0, 0, width, height, True); } } else { if (colorset->pixmap == ParentRelative) { pixmap = ParentRelative; } else { pixmap = CreateBackgroundPixmap( dpy, win, width, height, colorset, depth, gc, False); } if (x_off != 0 || y_off != 0) { Pixmap p2; p2 = ScrollPixmap( dpy, pixmap, gc, x_off, y_off, width, height, depth); if (p2 != None && p2 != ParentRelative && p2 != pixmap) { XFreePixmap(dpy, pixmap); pixmap = p2; } } if (pixmap) { XSetWindowBackgroundPixmap(dpy, win, pixmap); if (clear_area) { XClearArea(dpy, win, 0, 0, width, height, True); } if (colorset->pixmap != ParentRelative) { XFreePixmap(dpy, pixmap); } } } return; }