From 0cd4c92647f1e11f4ff8af11af906005c1a21f04 Mon Sep 17 00:00:00 2001 From: pekdon Date: Fri, 18 Jan 2002 23:01:20 +0000 Subject: bsetroot now sets backgrounds that trans Eterms can use --- ChangeLog | 2 + util/bsetroot.cc | 537 ++++++++++++++++++++++++++++++++++--------------------- util/bsetroot.hh | 4 +- 3 files changed, 335 insertions(+), 208 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6422eb9..2349251 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ Changes for 0.1.7: *02/01/18: + * Fixed bsetroot, now Eterm's, XChat's and similiar will be able to use + bsetroots background images. (Claes Nästén) * Fixed ResourceManager * Changed resources to Resource in class Fluxbox * Added Resource.hh/.cc, XrmDatabaseHelper.hh, NotCopyable.hh diff --git a/util/bsetroot.cc b/util/bsetroot.cc index 7f13854..4a610a7 100644 --- a/util/bsetroot.cc +++ b/util/bsetroot.cc @@ -14,287 +14,412 @@ #include "../src/i18n.hh" #include "bsetroot.hh" +#include 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; - img_ctrl = new BImageControl*[10]; - for (; i < getNumberOfScreens(); i++) { - img_ctrl[i] = new BImageControl(this, getScreenInfo(i), True); - - } + : BaseDisplay(argv[0], dpy_name) { - for (i = 1; i < argc; i++) { - if (! strcmp("-help", argv[i])) { - usage(); - } else if ((! strcmp("-fg", argv[i])) || - (! strcmp("-foreground", argv[i])) || - (! strcmp("-from", argv[i]))) { - if ((++i) >= argc) usage(1); + pixmaps = (Pixmap *) 0; + grad = fore = back = (char *) 0; - fore = argv[i]; - } else if ((! strcmp("-bg", argv[i])) || - (! strcmp("-background", argv[i])) || - (! strcmp("-to", argv[i]))) { - if ((++i) >= argc) usage(1); + Bool mod = False, sol = False, grd = False; + int mod_x = 0, mod_y = 0, i = 0; - back = argv[i]; - } else if (! strcmp("-solid", argv[i])) { - if ((++i) >= argc) usage(1); + img_ctrl = new BImageControl*[10]; + for (; i < getNumberOfScreens(); i++) { + img_ctrl[i] = new BImageControl(this, getScreenInfo(i), True); + } + for (i = 1; i < argc; i++) { + if (! strcmp("-help", argv[i])) { + usage(); + + } else if ((! strcmp("-fg", argv[i])) || + (! strcmp("-foreground", argv[i])) || + (! strcmp("-from", argv[i]))) { + if ((++i) >= argc) + usage(1); + fore = argv[i]; + + } else if ((! strcmp("-bg", argv[i])) || + (! strcmp("-background", argv[i])) || + (! strcmp("-to", argv[i]))) { + if ((++i) >= argc) + usage(1); + back = argv[i]; + + } else if (! strcmp("-solid", argv[i])) { + if ((++i) >= argc) + usage(1); fore = argv[i]; sol = True; - } else if (! strcmp("-mod", argv[i])) { - if ((++i) >= argc) usage(); - - mod_x = atoi(argv[i]); - - if ((++i) >= argc) usage(); - - mod_y = atoi(argv[i]); - - if (mod_x < 1) mod_x = 1; - if (mod_y < 1) mod_y = 1; - mod = True; - } else if (! strcmp("-gradient", argv[i])) { - if ((++i) >= argc) usage(); - - grad = argv[i]; - grd = True; - } else if (! strcmp("-display", argv[i])) { - // -display passed through tests ealier... we just skip it now - i++; - } else - usage(); - } + } else if (! strcmp("-mod", argv[i])) { + if ((++i) >= argc) + usage(); + mod_x = atoi(argv[i]); + if ((++i) >= argc) + usage(); + mod_y = atoi(argv[i]); + if (mod_x < 1) + mod_x = 1; + if (mod_y < 1) + mod_y = 1; + mod = True; + + } else if (! strcmp("-gradient", argv[i])) { + if ((++i) >= argc) + usage(); + + grad = argv[i]; + grd = True; + + } else if (! strcmp("-display", argv[i])) { + // -display passed through tests earlier... we just skip it now + i++; + + } else + usage(); + } - if ((mod + sol + grd) != True) { - fprintf(stderr, - I18n::instance()-> - getMessage( + if ((mod + sol + grd) != True) { + fprintf(stderr, + I18n::instance()-> + getMessage( #ifdef NLS - bsetrootSet, bsetrootMustSpecify, + bsetrootSet, bsetrootMustSpecify, #else // !NLS - 0, 0, + 0, 0, #endif // NLS - "%s: error: must specify on of: -solid, -mod, -gradient\n"), - getApplicationName()); - - usage(2); - } - - 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(); - else usage(); + "%s: error: must specify on of: -solid, -mod, -gradient\n"), + getApplicationName()); + + usage(2); + } + display = getXDisplay(); num_screens = getNumberOfScreens(); + + 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(); + else + usage(); + } bsetroot::~bsetroot(void) { - XKillClient(display, AllTemporary); + XKillClient(display, AllTemporary); - if (pixmaps) { - int i; - for (i = 0; i < num_screens; i++) - if (pixmaps[i] != None) { - XSetCloseDownMode(display, RetainTemporary); - break; - } + if (pixmaps) { // should always be true + XSetCloseDownMode(display, RetainTemporary); - delete [] pixmaps; - } + delete [] pixmaps; + } +#ifdef DEBUG + else + cerr<<"~bsetroot: why don't we have any pixmaps?"<getRootWindow(), + atom_root, 0L, 1L, false, AnyPropertyType, + &type, &format, &length, &after, &data_root); + + if (type == XA_PIXMAP) { + XGetWindowProperty(display, getScreenInfo(screen)->getRootWindow(), + atom_eroot, 0L, 1L, False, AnyPropertyType, + &type, &format, &length, &after, &data_eroot); + + if (data_root && data_eroot && type == XA_PIXMAP && + *((Pixmap *) data_root) == *((Pixmap *) data_eroot)) { + + XKillClient(display, *((Pixmap *) data_root)); + } + } + } - delete [] img_ctrl; - } - -} + atom_root = XInternAtom(display, "_XROOTPMAP_ID", false); + atom_eroot = XInternAtom(display, "ESETROOT_PMAP_ID", false); + if (atom_root == None || atom_eroot == None) { + cerr<<"couldn't create pixmap atoms, giving up!"<getRootWindow(), + atom_root, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &pixmap, 1); + XChangeProperty(display, getScreenInfo(screen)->getRootWindow(), + atom_eroot, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &pixmap, 1); + +} + +//-------------- solid -------------------- +// draws pixmaps with a single color +//----------------------------------------- void bsetroot::solid(void) { register int screen = 0; + pixmaps = new Pixmap[getNumberOfScreens()]; + for (; screen < getNumberOfScreens(); screen++) { BColor c; + GC gc; + XGCValues gcv; img_ctrl[screen]->parseColor(&c, fore); - if (! c.isAllocated()) c.setPixel(BlackPixel(getXDisplay(), screen)); + if (! c.isAllocated()) + c.setPixel(BlackPixel(getXDisplay(), screen)); + + gcv.foreground = c.getPixel(); + gc = XCreateGC(getXDisplay(), getScreenInfo(screen)->getRootWindow(), + GCForeground , &gcv); + + pixmaps[screen] = XCreatePixmap(getXDisplay(), + getScreenInfo(screen)->getRootWindow(), + getScreenInfo(screen)->getWidth(), getScreenInfo(screen)->getHeight(), + getScreenInfo(screen)->getDepth()); + + XFillRectangle(getXDisplay(), pixmaps[screen], gc, 0, 0, + getScreenInfo(screen)->getWidth(), getScreenInfo(screen)->getHeight()); + + setRootAtoms(pixmaps[screen], screen); + + XSetWindowBackgroundPixmap(getXDisplay(), + getScreenInfo(screen)->getRootWindow(), pixmaps[screen]); - XSetWindowBackground(getXDisplay(), getScreenInfo(screen)->getRootWindow(), - c.getPixel()); XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow()); + + XFreeGC(getXDisplay(), gc); } } - +//-------------- modula ------------------ +// draws pixmaps with an 16x16 pattern with +// fg and bg colors. +//----------------------------------------- void bsetroot::modula(int x, int y) { - char data[32]; - long pattern; + char data[32]; + long pattern; - register int screen, i; + register int screen, i; - pixmaps = new Pixmap[getNumberOfScreens()]; + pixmaps = new Pixmap[getNumberOfScreens()]; - for (pattern = 0, screen = 0; screen < getNumberOfScreens(); screen++) { - for (i = 0; i < 16; i++) { - pattern <<= 1; - if ((i % x) == 0) - pattern |= 0x0001; - } + for (pattern = 0, screen = 0; screen < getNumberOfScreens(); screen++) { - for (i = 0; i < 16; i++) - if ((i % y) == 0) { - data[(i * 2)] = (char) 0xff; - data[(i * 2) + 1] = (char) 0xff; - } else { - data[(i * 2)] = pattern & 0xff; - data[(i * 2) + 1] = (pattern >> 8) & 0xff; - } + for (i = 0; i < 16; i++) { + pattern <<= 1; + if ((i % x) == 0) + pattern |= 0x0001; + } - BColor f, b; - GC gc; - Pixmap bitmap; - XGCValues gcv; + for (i = 0; i < 16; i++) { + if ((i % y) == 0) { + data[(i * 2)] = (char) 0xff; + data[(i * 2) + 1] = (char) 0xff; + } else { + data[(i * 2)] = pattern & 0xff; + data[(i * 2) + 1] = (pattern >> 8) & 0xff; + } + } - bitmap = - XCreateBitmapFromData(getXDisplay(), - getScreenInfo(screen)->getRootWindow(), data, - 16, 16); + BColor f, b; + GC gc; + Pixmap bitmap, r_bitmap; + XGCValues gcv; - img_ctrl[screen]->parseColor(&f, fore); - img_ctrl[screen]->parseColor(&b, back); + bitmap = XCreateBitmapFromData(getXDisplay(), + getScreenInfo(screen)->getRootWindow(), data, 16, 16); - if (! f.isAllocated()) f.setPixel(WhitePixel(getXDisplay(), screen)); - if (! b.isAllocated()) b.setPixel(BlackPixel(getXDisplay(), screen)); + // bitmap used as tile, needs to have the same depth as background pixmap + r_bitmap = XCreatePixmap(getXDisplay(), + getScreenInfo(screen)->getRootWindow(), 16, 16, + getScreenInfo(screen)->getDepth()); - gcv.foreground = f.getPixel(); - gcv.background = b.getPixel(); + img_ctrl[screen]->parseColor(&f, fore); + img_ctrl[screen]->parseColor(&b, back); - gc = XCreateGC(getXDisplay(), getScreenInfo(screen)->getRootWindow(), - GCForeground | GCBackground, &gcv); + if (! f.isAllocated()) + f.setPixel(WhitePixel(getXDisplay(), screen)); + if (! b.isAllocated()) + b.setPixel(BlackPixel(getXDisplay(), screen)); - pixmaps[screen] = - XCreatePixmap(getXDisplay(), getScreenInfo(screen)->getRootWindow(), - 16, 16, getScreenInfo(screen)->getDepth()); + gcv.foreground = f.getPixel(); + gcv.background = b.getPixel(); - XCopyPlane(getXDisplay(), bitmap, pixmaps[screen], gc, - 0, 0, 16, 16, 0, 0, 1l); - XSetWindowBackgroundPixmap(getXDisplay(), - getScreenInfo(screen)->getRootWindow(), - pixmaps[screen]); - XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow()); + gc = XCreateGC(getXDisplay(), getScreenInfo(screen)->getRootWindow(), + GCForeground | GCBackground, &gcv); - XFreeGC(getXDisplay(), gc); - XFreePixmap(getXDisplay(), bitmap); + // copying bitmap to the one going to be used as tile + XCopyPlane(getXDisplay(), bitmap, r_bitmap, gc, + 0, 0, 16, 16, 0, 0, 1l); - if (! (getScreenInfo(screen)->getVisual()->c_class & 1)) { - XFreePixmap(getXDisplay(), pixmaps[screen]); - pixmaps[screen] = None; - } - } -} + XSetTile(getXDisplay(), gc, r_bitmap); + XSetFillStyle(getXDisplay(), gc, FillTiled); + + pixmaps[screen] = XCreatePixmap(getXDisplay(), + getScreenInfo(screen)->getRootWindow(), + getScreenInfo(screen)->getWidth(), getScreenInfo(screen)->getHeight(), + getScreenInfo(screen)->getDepth()); + + XFillRectangle(getXDisplay(), pixmaps[screen], gc, 0, 0, + getScreenInfo(screen)->getWidth(), getScreenInfo(screen)->getHeight()); + setRootAtoms(pixmaps[screen], screen); + XSetWindowBackgroundPixmap(getXDisplay(), + getScreenInfo(screen)->getRootWindow(), pixmaps[screen]); + + XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow()); + + XFreeGC(getXDisplay(), gc); + XFreePixmap(getXDisplay(), bitmap); + XFreePixmap(getXDisplay(), r_bitmap); + } +} + +//-------------- gradient ----------------- +// draws pixmaps with a fluxbox texure +//----------------------------------------- void bsetroot::gradient(void) { - register int screen; + register int screen; + // using temporaray pixmap and then copying it to background pixmap, as it'll + // get crashed somewhere on the way causing apps like XChat chrashing + // as the pixmap has been destroyed + Pixmap tmp; + pixmaps = new Pixmap[getNumberOfScreens()]; + + for (screen = 0; screen < getNumberOfScreens(); screen++) { + BTexture texture; + GC gc; + XGCValues gcv; + + img_ctrl[screen]->parseTexture(&texture, grad); + img_ctrl[screen]->parseColor(texture.getColor(), fore); + img_ctrl[screen]->parseColor(texture.getColorTo(), back); + + if (! texture.getColor()->isAllocated()) + texture.getColor()->setPixel(WhitePixel(getXDisplay(), screen)); + if (! texture.getColorTo()->isAllocated()) + texture.getColorTo()->setPixel(BlackPixel(getXDisplay(), screen)); - pixmaps = new Pixmap[getNumberOfScreens()]; + tmp = img_ctrl[screen]->renderImage(getScreenInfo(screen)->getWidth(), + getScreenInfo(screen)->getHeight(), &texture); - for (screen = 0; screen < getNumberOfScreens(); screen++) { - BTexture texture; - img_ctrl[screen]->parseTexture(&texture, grad); - img_ctrl[screen]->parseColor(texture.getColor(), fore); - img_ctrl[screen]->parseColor(texture.getColorTo(), back); + pixmaps[screen] = XCreatePixmap(getXDisplay(), + getScreenInfo(screen)->getRootWindow(), + getScreenInfo(screen)->getWidth(), getScreenInfo(screen)->getHeight(), + getScreenInfo(screen)->getDepth()); - if (! texture.getColor()->isAllocated()) - texture.getColor()->setPixel(WhitePixel(getXDisplay(), screen)); - if (! texture.getColorTo()->isAllocated()) - texture.getColorTo()->setPixel(BlackPixel(getXDisplay(), screen)); + gc = XCreateGC(getXDisplay(), getScreenInfo(screen)->getRootWindow(), + GCForeground , &gcv); - pixmaps[screen] = - img_ctrl[screen]->renderImage(getScreenInfo(screen)->getWidth(), - getScreenInfo(screen)->getHeight(), - &texture); + XCopyArea(getXDisplay(), tmp, pixmaps[screen], gc, 0, 0, + getScreenInfo(screen)->getWidth(), getScreenInfo(screen)->getHeight(), + 0, 0); + + setRootAtoms(pixmaps[screen], screen); XSetWindowBackgroundPixmap(getXDisplay(), - getScreenInfo(screen)->getRootWindow(), - pixmaps[screen]); - XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow()); + getScreenInfo(screen)->getRootWindow(), pixmaps[screen]); - if (! (getScreenInfo(screen)->getVisual()->c_class & 1)) { - img_ctrl[screen]->removeImage(pixmaps[screen]); - img_ctrl[screen]->timeout(); - pixmaps[screen] = None; - } - } -} + XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow()); + if (! (getScreenInfo(screen)->getVisual()->c_class & 1)) { + img_ctrl[screen]->removeImage(tmp); + img_ctrl[screen]->timeout(); + } + XFreeGC(getXDisplay(), gc); + } +} + +//-------------- usage -------------------- +// shows information about usage +//----------------------------------------- void bsetroot::usage(int exit_code) { - fprintf(stderr, - I18n::instance()-> - getMessage( -#ifdef NLS - bsetrootSet, bsetrootUsage, + fprintf(stderr, + I18n::instance()->getMessage( +#ifdef NLS + bsetrootSet, bsetrootUsage, #else // !NLS - 0, 0, + 0, 0, #endif // NLS - "%s 2.0 : (c) 1997-1999 Brad Hughes\n\n" - " -display display connection\n" - " -mod modula pattern\n" - " -foreground, -fg modula foreground color\n" - " -background, -bg modula background color\n\n" - " -gradient gradient texture\n" - " -from gradient start color\n" - " -to gradient end color\n\n" - " -solid solid color\n\n" - " -help print this help text and exit\n"), - getApplicationName()); - - exit(exit_code); + "%s 2.1 : (c) 2002 Claes Nasten\n" + "%s 2.0 : (c) 1997-2000 Brad Hughes\n\n" + " -display display connection\n" + " -mod modula pattern\n" + " -foreground, -fg modula foreground color\n" + " -background, -bg modula background color\n\n" + " -gradient gradient texture\n" + " -from gradient start color\n" + " -to gradient end color\n\n" + " -solid solid color\n\n" + " -help print this help text and exit\n"), + getApplicationName(), getApplicationName()); + + exit(exit_code); } int main(int argc, char **argv) { - char *display_name = (char *) 0; - int i = 1; + char *display_name = (char *) 0; + int i = 1; - NLSInit("blackbox.cat"); + NLSInit("blackbox.cat"); - for (; i < argc; i++) { - if (! strcmp(argv[i], "-display")) { - // check for -display option - - if ((++i) >= argc) { - fprintf(stderr, - I18n::instance()->getMessage( + for (; i < argc; i++) { + if (! strcmp(argv[i], "-display")) { + // check for -display option + + if ((++i) >= argc) { + fprintf(stderr, + I18n::instance()->getMessage( #ifdef NLS - mainSet, mainDISPLAYRequiresArg, + mainSet, mainDISPLAYRequiresArg, #else // !NLS - 0, 0, + 0, 0, #endif // NLS - "error: '-display' requires an argument\n")); + "error: '-display' requires an argument\n")); - ::exit(1); - } - - display_name = argv[i]; - } - } - - bsetroot app(argc, argv, display_name); - - return 0; + ::exit(1); + } + + display_name = argv[i]; + } + } + + bsetroot app(argc, argv, display_name); + + return (0); } diff --git a/util/bsetroot.hh b/util/bsetroot.hh index 1dfac2c..bf55015 100644 --- a/util/bsetroot.hh +++ b/util/bsetroot.hh @@ -4,7 +4,6 @@ #include "../src/BaseDisplay.hh" #include "../src/Image.hh" - class bsetroot : public BaseDisplay { public: bsetroot(int, char **, char * = 0); @@ -16,7 +15,8 @@ public: void modula(int, int); void solid(void); void usage(int = 0); - + void setRootAtoms(Pixmap pixmap, int screen); + private: BImageControl **img_ctrl; Pixmap *pixmaps; -- cgit v0.11.2