From 6796e798277cc4821c955d425f4994f1484d35df Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Sun, 28 Apr 2002 19:35:59 +0000 Subject: [PATCH] took bsetroot from Blackbox moving_target.. "bsetroot now sets xrootpmap_id, pseudo transparent apps should be happy" --- util/bsetroot.cc | 175 ++++++++++++++++++++++++++++------------------- util/bsetroot.h | 4 +- 2 files changed, 109 insertions(+), 70 deletions(-) diff --git a/util/bsetroot.cc b/util/bsetroot.cc index db789612..cb37cb6b 100644 --- a/util/bsetroot.cc +++ b/util/bsetroot.cc @@ -12,23 +12,20 @@ #endif // HAVE_STDIO_H #include "../src/i18n.h" +#include "../src/BaseDisplay.h" +#include "../src/Image.h" #include "bsetroot.h" bsetroot::bsetroot(int argc, char **argv, char *dpy_name) : BaseDisplay(argv[0], dpy_name) { - pixmaps = (Pixmap *) 0; grad = fore = back = (char *) 0; Bool mod = False, sol = False, grd = False; - int mod_x = 0, mod_y = 0, i = 0; + int mod_x = 0, mod_y = 0; - img_ctrl = new BImageControl*[getNumberOfScreens()]; - for (; i < getNumberOfScreens(); i++) - img_ctrl[i] = new BImageControl(*this, *getScreenInfo(i), True); - - for (i = 1; i < argc; i++) { + for (int i = 1; i < argc; i++) { if (! strcmp("-help", argv[i])) { usage(); } else if ((! strcmp("-fg", argv[i])) || @@ -75,19 +72,17 @@ bsetroot::bsetroot(int argc, char **argv, char *dpy_name) if ((mod + sol + grd) != True) { fprintf(stderr, - i18n-> - getMessage( -#ifdef NLS - bsetrootSet, bsetrootMustSpecify, -#else // !NLS - 0, 0, -#endif // NLS - "%s: error: must specify one of: -solid, -mod, -gradient\n"), + i18n->getMessage(bsetrootSet, bsetrootMustSpecify, + "%s: error: must specify one of: -solid, -mod, -gradient\n"), getApplicationName()); usage(2); } + img_ctrl = new BImageControl*[getNumberOfScreens()]; + for (int i = 0; i < getNumberOfScreens(); i++) + img_ctrl[i] = new BImageControl(*this, *getScreenInfo(i), True); + if (sol && fore) solid(); else if (mod && mod_x && mod_y && fore && back) modula(mod_x, mod_y); else if (grd && grad && fore && back) gradient(); @@ -96,33 +91,75 @@ bsetroot::bsetroot(int argc, char **argv, char *dpy_name) bsetroot::~bsetroot(void) { + XSetCloseDownMode(getXDisplay(), RetainPermanent); + XKillClient(getXDisplay(), AllTemporary); - if (pixmaps) { - int i; - for (i = 0; i < getNumberOfScreens(); i++) - if (pixmaps[i] != None) { - XSetCloseDownMode(getXDisplay(), RetainTemporary); - break; - } + for (int i = 0; i < getNumberOfScreens(); i++) + delete img_ctrl[i]; - delete [] pixmaps; - } + delete [] img_ctrl; +} - if (img_ctrl) { - int i = 0; - for (; i < getNumberOfScreens(); i++) - delete img_ctrl[i]; +// adapted from wmsetbg +void bsetroot::setPixmapProperty(int screen, Pixmap pixmap) { + static Atom rootpmap_id = None; + Atom type; + int format; + unsigned long length, after; + unsigned char *data; + int mode; + + if (rootpmap_id == None) + rootpmap_id = XInternAtom(getXDisplay(), "_XROOTPMAP_ID", False); - delete [] img_ctrl; + XGrabServer(getXDisplay()); + + /* Clear out the old pixmap */ + XGetWindowProperty(getXDisplay(), getScreenInfo(screen)->getRootWindow(), + rootpmap_id, 0L, 1L, False, AnyPropertyType, + &type, &format, &length, &after, &data); + + if ((type == XA_PIXMAP) && (format == 32) && (length == 1)) { + XKillClient(getXDisplay(), *((Pixmap *)data)); + XSync(getXDisplay(), False); + mode = PropModeReplace; + } else { + mode = PropModeAppend; } + if (pixmap) { + XChangeProperty(getXDisplay(), getScreenInfo(screen)->getRootWindow(), + rootpmap_id, XA_PIXMAP, 32, mode, + (unsigned char *) &pixmap, 1); + } else { + XDeleteProperty(getXDisplay(), getScreenInfo(screen)->getRootWindow(), + rootpmap_id); + } + + XUngrabServer(getXDisplay()); + XFlush(getXDisplay()); } -void bsetroot::solid(void) { - register int screen = 0; +// adapted from wmsetbg +Pixmap bsetroot::duplicatePixmap(int screen, Pixmap pixmap, + int width, int height) { + XSync(getXDisplay(), False); + + Pixmap copyP = XCreatePixmap(getXDisplay(), + getScreenInfo(screen)->getRootWindow(), + width, height, + DefaultDepth(getXDisplay(), screen)); + XCopyArea(getXDisplay(), pixmap, copyP, DefaultGC(getXDisplay(), screen), + 0, 0, width, height, 0, 0); + XSync(getXDisplay(), False); - for (; screen < getNumberOfScreens(); screen++) { + return copyP; +} + + +void bsetroot::solid(void) { + for (int screen = 0; screen < getNumberOfScreens(); screen++) { BColor c; img_ctrl[screen]->parseColor(&c, fore); @@ -131,6 +168,18 @@ void bsetroot::solid(void) { XSetWindowBackground(getXDisplay(), getScreenInfo(screen)->getRootWindow(), c.getPixel()); XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow()); + + Pixmap pixmap = XCreatePixmap(getXDisplay(), + getScreenInfo(screen)->getRootWindow(), + 8, 8, DefaultDepth(getXDisplay(), screen)); + XSetForeground(getXDisplay(), DefaultGC(getXDisplay(), screen), + c.getPixel()); + XFillRectangle(getXDisplay(), pixmap, DefaultGC(getXDisplay(), screen), + 0, 0, 8, 8); + + setPixmapProperty(screen, duplicatePixmap(screen, pixmap, 8, 8)); + + XFreePixmap(getXDisplay(), pixmap); } } @@ -139,9 +188,7 @@ void bsetroot::modula(int x, int y) { char data[32]; long pattern; - register int screen, i; - - pixmaps = new Pixmap[getNumberOfScreens()]; + int screen, i; for (pattern = 0, screen = 0; screen < getNumberOfScreens(); screen++) { for (i = 0; i < 16; i++) { @@ -150,7 +197,7 @@ void bsetroot::modula(int x, int y) { pattern |= 0x0001; } - for (i = 0; i < 16; i++) + for (i = 0; i < 16; i++) { if ((i % y) == 0) { data[(i * 2)] = (char) 0xff; data[(i * 2) + 1] = (char) 0xff; @@ -158,6 +205,7 @@ void bsetroot::modula(int x, int y) { data[(i * 2)] = pattern & 0xff; data[(i * 2) + 1] = (pattern >> 8) & 0xff; } + } BColor f, b; GC gc; @@ -181,34 +229,31 @@ void bsetroot::modula(int x, int y) { gc = XCreateGC(getXDisplay(), getScreenInfo(screen)->getRootWindow(), GCForeground | GCBackground, &gcv); - pixmaps[screen] = - XCreatePixmap(getXDisplay(), getScreenInfo(screen)->getRootWindow(), - 16, 16, getScreenInfo(screen)->getDepth()); + Pixmap pixmap = XCreatePixmap(getXDisplay(), + getScreenInfo(screen)->getRootWindow(), + 16, 16, getScreenInfo(screen)->getDepth()); - XCopyPlane(getXDisplay(), bitmap, pixmaps[screen], gc, + XCopyPlane(getXDisplay(), bitmap, pixmap, gc, 0, 0, 16, 16, 0, 0, 1l); XSetWindowBackgroundPixmap(getXDisplay(), getScreenInfo(screen)->getRootWindow(), - pixmaps[screen]); + pixmap); XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow()); + setPixmapProperty(screen, + duplicatePixmap(screen, pixmap, 16, 16)); + XFreeGC(getXDisplay(), gc); XFreePixmap(getXDisplay(), bitmap); - if (! (getScreenInfo(screen)->getVisual()->c_class & 1)) { - XFreePixmap(getXDisplay(), pixmaps[screen]); - pixmaps[screen] = None; - } + if (! (getScreenInfo(screen)->getVisual()->c_class & 1)) + XFreePixmap(getXDisplay(), pixmap); } } void bsetroot::gradient(void) { - register int screen; - - pixmaps = new Pixmap[getNumberOfScreens()]; - - for (screen = 0; screen < getNumberOfScreens(); screen++) { + for (int screen = 0; screen < getNumberOfScreens(); screen++) { BTexture texture; img_ctrl[screen]->parseTexture(&texture, grad); img_ctrl[screen]->parseColor(texture.getColor(), fore); @@ -219,20 +264,23 @@ void bsetroot::gradient(void) { if (! texture.getColorTo()->isAllocated()) texture.getColorTo()->setPixel(BlackPixel(getXDisplay(), screen)); - pixmaps[screen] = + Pixmap pixmap = img_ctrl[screen]->renderImage(getScreenInfo(screen)->size().w(), getScreenInfo(screen)->size().h(), &texture); XSetWindowBackgroundPixmap(getXDisplay(), getScreenInfo(screen)->getRootWindow(), - pixmaps[screen]); + pixmap); XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow()); + setPixmapProperty(screen, + duplicatePixmap(screen, pixmap, + getScreenInfo(screen)->size().w(), + getScreenInfo(screen)->size().h())); + if (! (getScreenInfo(screen)->getVisual()->c_class & 1)) { - img_ctrl[screen]->removeImage(pixmaps[screen]); - img_ctrl[screen]->timeout(); - pixmaps[screen] = None; + img_ctrl[screen]->removeImage(pixmap); } } } @@ -241,12 +289,7 @@ void bsetroot::gradient(void) { void bsetroot::usage(int exit_code) { fprintf(stderr, i18n-> - getMessage( -#ifdef NLS - bsetrootSet, bsetrootUsage, -#else // !NLS - 0, 0, -#endif // NLS + getMessage(bsetrootSet, bsetrootUsage, "%s 2.0 : (c) 1997-1999 Brad Hughes\n\n" " -display display connection\n" " -mod modula pattern\n" @@ -265,22 +308,16 @@ void bsetroot::usage(int exit_code) { int main(int argc, char **argv) { char *display_name = (char *) 0; - int i = 1; NLSInit("openbox.cat"); - for (; i < argc; i++) { + for (int i = 1; i < argc; i++) { if (! strcmp(argv[i], "-display")) { // check for -display option if ((++i) >= argc) { fprintf(stderr, - i18n->getMessage( -#ifdef NLS - mainSet, mainDISPLAYRequiresArg, -#else // !NLS - 0, 0, -#endif // NLS + i18n->getMessage(mainSet, mainDISPLAYRequiresArg, "error: '-display' requires an argument\n")); ::exit(1); diff --git a/util/bsetroot.h b/util/bsetroot.h index ca535562..aa6f65a7 100644 --- a/util/bsetroot.h +++ b/util/bsetroot.h @@ -8,7 +8,6 @@ class bsetroot : public BaseDisplay { private: BImageControl **img_ctrl; - Pixmap *pixmaps; char *fore, *back, *grad; @@ -23,6 +22,9 @@ public: inline virtual Bool handleSignal(int) { return False; } + void setPixmapProperty(int, Pixmap); + Pixmap duplicatePixmap(int, Pixmap, int, int); + void gradient(void); void modula(int, int); void solid(void); -- 2.45.2