bsetroot now sets backgrounds that trans Eterms can use

This commit is contained in:
pekdon 2002-01-18 23:01:20 +00:00
parent 74454c8f2a
commit 0cd4c92647
3 changed files with 328 additions and 201 deletions

View file

@ -1,5 +1,7 @@
Changes for 0.1.7: Changes for 0.1.7:
*02/01/18: *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 * Fixed ResourceManager
* Changed resources to Resource<T> in class Fluxbox * Changed resources to Resource<T> in class Fluxbox
* Added Resource.hh/.cc, XrmDatabaseHelper.hh, NotCopyable.hh * Added Resource.hh/.cc, XrmDatabaseHelper.hh, NotCopyable.hh

View file

@ -14,62 +14,70 @@
#include "../src/i18n.hh" #include "../src/i18n.hh"
#include "bsetroot.hh" #include "bsetroot.hh"
#include <iostream>
bsetroot::bsetroot(int argc, char **argv, char *dpy_name) bsetroot::bsetroot(int argc, char **argv, char *dpy_name)
: BaseDisplay(argv[0], dpy_name) : BaseDisplay(argv[0], dpy_name) {
{
pixmaps = (Pixmap *) 0; pixmaps = (Pixmap *) 0;
grad = fore = back = (char *) 0; grad = fore = back = (char *) 0;
Bool mod = False, sol = False, grd = False; Bool mod = False, sol = False, grd = False;
int mod_x = 0, mod_y = 0, i = 0; int mod_x = 0, mod_y = 0, i = 0;
img_ctrl = new BImageControl*[10]; img_ctrl = new BImageControl*[10];
for (; i < getNumberOfScreens(); i++) { for (; i < getNumberOfScreens(); i++) {
img_ctrl[i] = new BImageControl(this, getScreenInfo(i), True); img_ctrl[i] = new BImageControl(this, getScreenInfo(i), True);
} }
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (! strcmp("-help", argv[i])) { if (! strcmp("-help", argv[i])) {
usage(); usage();
} else if ((! strcmp("-fg", argv[i])) || } else if ((! strcmp("-fg", argv[i])) ||
(! strcmp("-foreground", argv[i])) || (! strcmp("-foreground", argv[i])) ||
(! strcmp("-from", argv[i]))) { (! strcmp("-from", argv[i]))) {
if ((++i) >= argc) usage(1); if ((++i) >= argc)
usage(1);
fore = argv[i]; fore = argv[i];
} else if ((! strcmp("-bg", argv[i])) || } else if ((! strcmp("-bg", argv[i])) ||
(! strcmp("-background", argv[i])) || (! strcmp("-background", argv[i])) ||
(! strcmp("-to", argv[i]))) { (! strcmp("-to", argv[i]))) {
if ((++i) >= argc) usage(1); if ((++i) >= argc)
usage(1);
back = argv[i]; back = argv[i];
} else if (! strcmp("-solid", argv[i])) {
if ((++i) >= argc) usage(1);
} else if (! strcmp("-solid", argv[i])) {
if ((++i) >= argc)
usage(1);
fore = argv[i]; fore = argv[i];
sol = True; sol = True;
} else if (! strcmp("-mod", argv[i])) { } else if (! strcmp("-mod", argv[i])) {
if ((++i) >= argc) usage(); if ((++i) >= argc)
usage();
mod_x = atoi(argv[i]); mod_x = atoi(argv[i]);
if ((++i) >= argc)
if ((++i) >= argc) usage(); usage();
mod_y = atoi(argv[i]); mod_y = atoi(argv[i]);
if (mod_x < 1)
if (mod_x < 1) mod_x = 1; mod_x = 1;
if (mod_y < 1) mod_y = 1; if (mod_y < 1)
mod_y = 1;
mod = True; mod = True;
} else if (! strcmp("-gradient", argv[i])) { } else if (! strcmp("-gradient", argv[i])) {
if ((++i) >= argc) usage(); if ((++i) >= argc)
usage();
grad = argv[i]; grad = argv[i];
grd = True; grd = True;
} else if (! strcmp("-display", argv[i])) { } else if (! strcmp("-display", argv[i])) {
// -display passed through tests ealier... we just skip it now // -display passed through tests earlier... we just skip it now
i++; i++;
} else } else
usage(); usage();
} }
@ -89,28 +97,33 @@ bsetroot::bsetroot(int argc, char **argv, char *dpy_name)
usage(2); 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();
display = getXDisplay(); display = getXDisplay();
num_screens = getNumberOfScreens(); 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) { bsetroot::~bsetroot(void) {
XKillClient(display, AllTemporary); XKillClient(display, AllTemporary);
if (pixmaps) { if (pixmaps) { // should always be true
int i;
for (i = 0; i < num_screens; i++)
if (pixmaps[i] != None) {
XSetCloseDownMode(display, RetainTemporary); XSetCloseDownMode(display, RetainTemporary);
break;
}
delete [] pixmaps; delete [] pixmaps;
} }
#ifdef DEBUG
else
cerr<<"~bsetroot: why don't we have any pixmaps?"<<endl;
#endif // DEBUG
if (img_ctrl) { if (img_ctrl) {
int i = 0; int i = 0;
@ -119,26 +132,101 @@ bsetroot::~bsetroot(void) {
delete [] img_ctrl; delete [] img_ctrl;
} }
}
//------------ setRootAtoms ---------------
// set root pixmap atoms so that apps like
// Eterm and xchat will be able to use
// transparent background
//-----------------------------------------
void bsetroot::setRootAtoms(Pixmap pixmap, int screen) {
Atom atom_root, atom_eroot, type;
unsigned char *data_root, *data_eroot;
int format;
unsigned long length, after;
atom_root = XInternAtom(display, "_XROOTMAP_ID", true);
atom_eroot = XInternAtom(display, "ESETROOT_PMAP_ID", true);
// doing this to clean up after old background
if (atom_root != None && atom_eroot != None) {
XGetWindowProperty(display, getScreenInfo(screen)->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));
}
}
}
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!"<<endl;
exit(1);
}
// setting new background atoms
XChangeProperty(display, getScreenInfo(screen)->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) { void bsetroot::solid(void) {
register int screen = 0; register int screen = 0;
pixmaps = new Pixmap[getNumberOfScreens()];
for (; screen < getNumberOfScreens(); screen++) { for (; screen < getNumberOfScreens(); screen++) {
BColor c; BColor c;
GC gc;
XGCValues gcv;
img_ctrl[screen]->parseColor(&c, fore); 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()); 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) { void bsetroot::modula(int x, int y) {
char data[32]; char data[32];
long pattern; long pattern;
@ -148,13 +236,14 @@ void bsetroot::modula(int x, int y) {
pixmaps = new Pixmap[getNumberOfScreens()]; pixmaps = new Pixmap[getNumberOfScreens()];
for (pattern = 0, screen = 0; screen < getNumberOfScreens(); screen++) { for (pattern = 0, screen = 0; screen < getNumberOfScreens(); screen++) {
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
pattern <<= 1; pattern <<= 1;
if ((i % x) == 0) if ((i % x) == 0)
pattern |= 0x0001; pattern |= 0x0001;
} }
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++) {
if ((i % y) == 0) { if ((i % y) == 0) {
data[(i * 2)] = (char) 0xff; data[(i * 2)] = (char) 0xff;
data[(i * 2) + 1] = (char) 0xff; data[(i * 2) + 1] = (char) 0xff;
@ -162,22 +251,28 @@ void bsetroot::modula(int x, int y) {
data[(i * 2)] = pattern & 0xff; data[(i * 2)] = pattern & 0xff;
data[(i * 2) + 1] = (pattern >> 8) & 0xff; data[(i * 2) + 1] = (pattern >> 8) & 0xff;
} }
}
BColor f, b; BColor f, b;
GC gc; GC gc;
Pixmap bitmap; Pixmap bitmap, r_bitmap;
XGCValues gcv; XGCValues gcv;
bitmap = bitmap = XCreateBitmapFromData(getXDisplay(),
XCreateBitmapFromData(getXDisplay(), getScreenInfo(screen)->getRootWindow(), data, 16, 16);
getScreenInfo(screen)->getRootWindow(), data,
16, 16); // 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());
img_ctrl[screen]->parseColor(&f, fore); img_ctrl[screen]->parseColor(&f, fore);
img_ctrl[screen]->parseColor(&b, back); img_ctrl[screen]->parseColor(&b, back);
if (! f.isAllocated()) f.setPixel(WhitePixel(getXDisplay(), screen)); if (! f.isAllocated())
if (! b.isAllocated()) b.setPixel(BlackPixel(getXDisplay(), screen)); f.setPixel(WhitePixel(getXDisplay(), screen));
if (! b.isAllocated())
b.setPixel(BlackPixel(getXDisplay(), screen));
gcv.foreground = f.getPixel(); gcv.foreground = f.getPixel();
gcv.background = b.getPixel(); gcv.background = b.getPixel();
@ -185,35 +280,50 @@ void bsetroot::modula(int x, int y) {
gc = XCreateGC(getXDisplay(), getScreenInfo(screen)->getRootWindow(), gc = XCreateGC(getXDisplay(), getScreenInfo(screen)->getRootWindow(),
GCForeground | GCBackground, &gcv); GCForeground | GCBackground, &gcv);
pixmaps[screen] = // copying bitmap to the one going to be used as tile
XCreatePixmap(getXDisplay(), getScreenInfo(screen)->getRootWindow(), XCopyPlane(getXDisplay(), bitmap, r_bitmap, gc,
16, 16, getScreenInfo(screen)->getDepth());
XCopyPlane(getXDisplay(), bitmap, pixmaps[screen], gc,
0, 0, 16, 16, 0, 0, 1l); 0, 0, 16, 16, 0, 0, 1l);
XSetWindowBackgroundPixmap(getXDisplay(),
XSetTile(getXDisplay(), gc, r_bitmap);
XSetFillStyle(getXDisplay(), gc, FillTiled);
pixmaps[screen] = XCreatePixmap(getXDisplay(),
getScreenInfo(screen)->getRootWindow(), getScreenInfo(screen)->getRootWindow(),
pixmaps[screen]); 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()); XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow());
XFreeGC(getXDisplay(), gc); XFreeGC(getXDisplay(), gc);
XFreePixmap(getXDisplay(), bitmap); XFreePixmap(getXDisplay(), bitmap);
XFreePixmap(getXDisplay(), r_bitmap);
if (! (getScreenInfo(screen)->getVisual()->c_class & 1)) {
XFreePixmap(getXDisplay(), pixmaps[screen]);
pixmaps[screen] = None;
}
} }
} }
//-------------- gradient -----------------
// draws pixmaps with a fluxbox texure
//-----------------------------------------
void bsetroot::gradient(void) { 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()]; pixmaps = new Pixmap[getNumberOfScreens()];
for (screen = 0; screen < getNumberOfScreens(); screen++) { for (screen = 0; screen < getNumberOfScreens(); screen++) {
BTexture texture; BTexture texture;
GC gc;
XGCValues gcv;
img_ctrl[screen]->parseTexture(&texture, grad); img_ctrl[screen]->parseTexture(&texture, grad);
img_ctrl[screen]->parseColor(texture.getColor(), fore); img_ctrl[screen]->parseColor(texture.getColor(), fore);
img_ctrl[screen]->parseColor(texture.getColorTo(), back); img_ctrl[screen]->parseColor(texture.getColorTo(), back);
@ -223,35 +333,50 @@ void bsetroot::gradient(void) {
if (! texture.getColorTo()->isAllocated()) if (! texture.getColorTo()->isAllocated())
texture.getColorTo()->setPixel(BlackPixel(getXDisplay(), screen)); texture.getColorTo()->setPixel(BlackPixel(getXDisplay(), screen));
pixmaps[screen] = tmp = img_ctrl[screen]->renderImage(getScreenInfo(screen)->getWidth(),
img_ctrl[screen]->renderImage(getScreenInfo(screen)->getWidth(), getScreenInfo(screen)->getHeight(), &texture);
getScreenInfo(screen)->getHeight(),
&texture); pixmaps[screen] = XCreatePixmap(getXDisplay(),
getScreenInfo(screen)->getRootWindow(),
getScreenInfo(screen)->getWidth(), getScreenInfo(screen)->getHeight(),
getScreenInfo(screen)->getDepth());
gc = XCreateGC(getXDisplay(), getScreenInfo(screen)->getRootWindow(),
GCForeground , &gcv);
XCopyArea(getXDisplay(), tmp, pixmaps[screen], gc, 0, 0,
getScreenInfo(screen)->getWidth(), getScreenInfo(screen)->getHeight(),
0, 0);
setRootAtoms(pixmaps[screen], screen);
XSetWindowBackgroundPixmap(getXDisplay(), XSetWindowBackgroundPixmap(getXDisplay(),
getScreenInfo(screen)->getRootWindow(), getScreenInfo(screen)->getRootWindow(), pixmaps[screen]);
pixmaps[screen]);
XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow()); XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow());
if (! (getScreenInfo(screen)->getVisual()->c_class & 1)) { if (! (getScreenInfo(screen)->getVisual()->c_class & 1)) {
img_ctrl[screen]->removeImage(pixmaps[screen]); img_ctrl[screen]->removeImage(tmp);
img_ctrl[screen]->timeout(); img_ctrl[screen]->timeout();
pixmaps[screen] = None;
} }
XFreeGC(getXDisplay(), gc);
} }
} }
//-------------- usage --------------------
// shows information about usage
//-----------------------------------------
void bsetroot::usage(int exit_code) { void bsetroot::usage(int exit_code) {
fprintf(stderr, fprintf(stderr,
I18n::instance()-> I18n::instance()->getMessage(
getMessage(
#ifdef NLS #ifdef NLS
bsetrootSet, bsetrootUsage, bsetrootSet, bsetrootUsage,
#else // !NLS #else // !NLS
0, 0, 0, 0,
#endif // NLS #endif // NLS
"%s 2.0 : (c) 1997-1999 Brad Hughes\n\n" "%s 2.1 : (c) 2002 Claes Nasten\n"
"%s 2.0 : (c) 1997-2000 Brad Hughes\n\n"
" -display <string> display connection\n" " -display <string> display connection\n"
" -mod <x> <y> modula pattern\n" " -mod <x> <y> modula pattern\n"
" -foreground, -fg <color> modula foreground color\n" " -foreground, -fg <color> modula foreground color\n"
@ -261,7 +386,7 @@ void bsetroot::usage(int exit_code) {
" -to <color> gradient end color\n\n" " -to <color> gradient end color\n\n"
" -solid <color> solid color\n\n" " -solid <color> solid color\n\n"
" -help print this help text and exit\n"), " -help print this help text and exit\n"),
getApplicationName()); getApplicationName(), getApplicationName());
exit(exit_code); exit(exit_code);
} }
@ -296,5 +421,5 @@ int main(int argc, char **argv) {
bsetroot app(argc, argv, display_name); bsetroot app(argc, argv, display_name);
return 0; return (0);
} }

View file

@ -4,7 +4,6 @@
#include "../src/BaseDisplay.hh" #include "../src/BaseDisplay.hh"
#include "../src/Image.hh" #include "../src/Image.hh"
class bsetroot : public BaseDisplay { class bsetroot : public BaseDisplay {
public: public:
bsetroot(int, char **, char * = 0); bsetroot(int, char **, char * = 0);
@ -16,6 +15,7 @@ public:
void modula(int, int); void modula(int, int);
void solid(void); void solid(void);
void usage(int = 0); void usage(int = 0);
void setRootAtoms(Pixmap pixmap, int screen);
private: private:
BImageControl **img_ctrl; BImageControl **img_ctrl;