took bsetroot from Blackbox moving_target.. "bsetroot now sets xrootpmap_id, pseudo transparent apps should be happy"
This commit is contained in:
parent
127252cc10
commit
6796e79827
2 changed files with 110 additions and 71 deletions
177
util/bsetroot.cc
177
util/bsetroot.cc
|
@ -12,23 +12,20 @@
|
||||||
#endif // HAVE_STDIO_H
|
#endif // HAVE_STDIO_H
|
||||||
|
|
||||||
#include "../src/i18n.h"
|
#include "../src/i18n.h"
|
||||||
|
#include "../src/BaseDisplay.h"
|
||||||
|
#include "../src/Image.h"
|
||||||
#include "bsetroot.h"
|
#include "bsetroot.h"
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
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;
|
||||||
|
|
||||||
img_ctrl = new BImageControl*[getNumberOfScreens()];
|
for (int i = 1; i < argc; i++) {
|
||||||
for (; i < getNumberOfScreens(); i++)
|
|
||||||
img_ctrl[i] = new BImageControl(*this, *getScreenInfo(i), True);
|
|
||||||
|
|
||||||
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])) ||
|
||||||
|
@ -75,19 +72,17 @@ bsetroot::bsetroot(int argc, char **argv, char *dpy_name)
|
||||||
|
|
||||||
if ((mod + sol + grd) != True) {
|
if ((mod + sol + grd) != True) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
i18n->
|
i18n->getMessage(bsetrootSet, bsetrootMustSpecify,
|
||||||
getMessage(
|
"%s: error: must specify one of: -solid, -mod, -gradient\n"),
|
||||||
#ifdef NLS
|
|
||||||
bsetrootSet, bsetrootMustSpecify,
|
|
||||||
#else // !NLS
|
|
||||||
0, 0,
|
|
||||||
#endif // NLS
|
|
||||||
"%s: error: must specify one of: -solid, -mod, -gradient\n"),
|
|
||||||
getApplicationName());
|
getApplicationName());
|
||||||
|
|
||||||
usage(2);
|
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();
|
if (sol && fore) solid();
|
||||||
else if (mod && mod_x && mod_y && fore && back) modula(mod_x, mod_y);
|
else if (mod && mod_x && mod_y && fore && back) modula(mod_x, mod_y);
|
||||||
else if (grd && grad && fore && back) gradient();
|
else if (grd && grad && fore && back) gradient();
|
||||||
|
@ -96,33 +91,75 @@ bsetroot::bsetroot(int argc, char **argv, char *dpy_name)
|
||||||
|
|
||||||
|
|
||||||
bsetroot::~bsetroot(void) {
|
bsetroot::~bsetroot(void) {
|
||||||
|
XSetCloseDownMode(getXDisplay(), RetainPermanent);
|
||||||
|
|
||||||
XKillClient(getXDisplay(), AllTemporary);
|
XKillClient(getXDisplay(), AllTemporary);
|
||||||
|
|
||||||
if (pixmaps) {
|
for (int i = 0; i < getNumberOfScreens(); i++)
|
||||||
int i;
|
delete img_ctrl[i];
|
||||||
for (i = 0; i < getNumberOfScreens(); i++)
|
|
||||||
if (pixmaps[i] != None) {
|
|
||||||
XSetCloseDownMode(getXDisplay(), RetainTemporary);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete [] pixmaps;
|
delete [] img_ctrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
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) {
|
||||||
if (img_ctrl) {
|
XChangeProperty(getXDisplay(), getScreenInfo(screen)->getRootWindow(),
|
||||||
int i = 0;
|
rootpmap_id, XA_PIXMAP, 32, mode,
|
||||||
for (; i < getNumberOfScreens(); i++)
|
(unsigned char *) &pixmap, 1);
|
||||||
delete img_ctrl[i];
|
} else {
|
||||||
|
XDeleteProperty(getXDisplay(), getScreenInfo(screen)->getRootWindow(),
|
||||||
delete [] img_ctrl;
|
rootpmap_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XUngrabServer(getXDisplay());
|
||||||
|
XFlush(getXDisplay());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
return copyP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void bsetroot::solid(void) {
|
void bsetroot::solid(void) {
|
||||||
register int screen = 0;
|
for (int screen = 0; screen < getNumberOfScreens(); screen++) {
|
||||||
|
|
||||||
for (; screen < getNumberOfScreens(); screen++) {
|
|
||||||
BColor c;
|
BColor c;
|
||||||
|
|
||||||
img_ctrl[screen]->parseColor(&c, fore);
|
img_ctrl[screen]->parseColor(&c, fore);
|
||||||
|
@ -131,6 +168,18 @@ void bsetroot::solid(void) {
|
||||||
XSetWindowBackground(getXDisplay(), getScreenInfo(screen)->getRootWindow(),
|
XSetWindowBackground(getXDisplay(), getScreenInfo(screen)->getRootWindow(),
|
||||||
c.getPixel());
|
c.getPixel());
|
||||||
XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow());
|
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];
|
char data[32];
|
||||||
long pattern;
|
long pattern;
|
||||||
|
|
||||||
register int screen, i;
|
int screen, i;
|
||||||
|
|
||||||
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++) {
|
||||||
|
@ -150,7 +197,7 @@ void bsetroot::modula(int x, int y) {
|
||||||
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;
|
||||||
|
@ -158,6 +205,7 @@ 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;
|
||||||
|
@ -181,34 +229,31 @@ 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] =
|
Pixmap pixmap = XCreatePixmap(getXDisplay(),
|
||||||
XCreatePixmap(getXDisplay(), getScreenInfo(screen)->getRootWindow(),
|
getScreenInfo(screen)->getRootWindow(),
|
||||||
16, 16, getScreenInfo(screen)->getDepth());
|
16, 16, getScreenInfo(screen)->getDepth());
|
||||||
|
|
||||||
XCopyPlane(getXDisplay(), bitmap, pixmaps[screen], gc,
|
XCopyPlane(getXDisplay(), bitmap, pixmap, gc,
|
||||||
0, 0, 16, 16, 0, 0, 1l);
|
0, 0, 16, 16, 0, 0, 1l);
|
||||||
XSetWindowBackgroundPixmap(getXDisplay(),
|
XSetWindowBackgroundPixmap(getXDisplay(),
|
||||||
getScreenInfo(screen)->getRootWindow(),
|
getScreenInfo(screen)->getRootWindow(),
|
||||||
pixmaps[screen]);
|
pixmap);
|
||||||
XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow());
|
XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow());
|
||||||
|
|
||||||
|
setPixmapProperty(screen,
|
||||||
|
duplicatePixmap(screen, pixmap, 16, 16));
|
||||||
|
|
||||||
XFreeGC(getXDisplay(), gc);
|
XFreeGC(getXDisplay(), gc);
|
||||||
XFreePixmap(getXDisplay(), bitmap);
|
XFreePixmap(getXDisplay(), bitmap);
|
||||||
|
|
||||||
if (! (getScreenInfo(screen)->getVisual()->c_class & 1)) {
|
if (! (getScreenInfo(screen)->getVisual()->c_class & 1))
|
||||||
XFreePixmap(getXDisplay(), pixmaps[screen]);
|
XFreePixmap(getXDisplay(), pixmap);
|
||||||
pixmaps[screen] = None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void bsetroot::gradient(void) {
|
void bsetroot::gradient(void) {
|
||||||
register int screen;
|
for (int screen = 0; screen < getNumberOfScreens(); screen++) {
|
||||||
|
|
||||||
pixmaps = new Pixmap[getNumberOfScreens()];
|
|
||||||
|
|
||||||
for (screen = 0; screen < getNumberOfScreens(); screen++) {
|
|
||||||
BTexture texture;
|
BTexture texture;
|
||||||
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);
|
||||||
|
@ -219,20 +264,23 @@ 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] =
|
Pixmap pixmap =
|
||||||
img_ctrl[screen]->renderImage(getScreenInfo(screen)->size().w(),
|
img_ctrl[screen]->renderImage(getScreenInfo(screen)->size().w(),
|
||||||
getScreenInfo(screen)->size().h(),
|
getScreenInfo(screen)->size().h(),
|
||||||
&texture);
|
&texture);
|
||||||
|
|
||||||
XSetWindowBackgroundPixmap(getXDisplay(),
|
XSetWindowBackgroundPixmap(getXDisplay(),
|
||||||
getScreenInfo(screen)->getRootWindow(),
|
getScreenInfo(screen)->getRootWindow(),
|
||||||
pixmaps[screen]);
|
pixmap);
|
||||||
XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow());
|
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)) {
|
if (! (getScreenInfo(screen)->getVisual()->c_class & 1)) {
|
||||||
img_ctrl[screen]->removeImage(pixmaps[screen]);
|
img_ctrl[screen]->removeImage(pixmap);
|
||||||
img_ctrl[screen]->timeout();
|
|
||||||
pixmaps[screen] = None;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -241,12 +289,7 @@ void bsetroot::gradient(void) {
|
||||||
void bsetroot::usage(int exit_code) {
|
void bsetroot::usage(int exit_code) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
i18n->
|
i18n->
|
||||||
getMessage(
|
getMessage(bsetrootSet, bsetrootUsage,
|
||||||
#ifdef NLS
|
|
||||||
bsetrootSet, bsetrootUsage,
|
|
||||||
#else // !NLS
|
|
||||||
0, 0,
|
|
||||||
#endif // NLS
|
|
||||||
"%s 2.0 : (c) 1997-1999 Brad Hughes\n\n"
|
"%s 2.0 : (c) 1997-1999 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"
|
||||||
|
@ -265,22 +308,16 @@ void bsetroot::usage(int exit_code) {
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
char *display_name = (char *) 0;
|
char *display_name = (char *) 0;
|
||||||
int i = 1;
|
|
||||||
|
|
||||||
NLSInit("openbox.cat");
|
NLSInit("openbox.cat");
|
||||||
|
|
||||||
for (; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
if (! strcmp(argv[i], "-display")) {
|
if (! strcmp(argv[i], "-display")) {
|
||||||
// check for -display option
|
// check for -display option
|
||||||
|
|
||||||
if ((++i) >= argc) {
|
if ((++i) >= argc) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
i18n->getMessage(
|
i18n->getMessage(mainSet, mainDISPLAYRequiresArg,
|
||||||
#ifdef NLS
|
|
||||||
mainSet, mainDISPLAYRequiresArg,
|
|
||||||
#else // !NLS
|
|
||||||
0, 0,
|
|
||||||
#endif // NLS
|
|
||||||
"error: '-display' requires an argument\n"));
|
"error: '-display' requires an argument\n"));
|
||||||
|
|
||||||
::exit(1);
|
::exit(1);
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
class bsetroot : public BaseDisplay {
|
class bsetroot : public BaseDisplay {
|
||||||
private:
|
private:
|
||||||
BImageControl **img_ctrl;
|
BImageControl **img_ctrl;
|
||||||
Pixmap *pixmaps;
|
|
||||||
|
|
||||||
char *fore, *back, *grad;
|
char *fore, *back, *grad;
|
||||||
|
|
||||||
|
@ -23,6 +22,9 @@ public:
|
||||||
|
|
||||||
inline virtual Bool handleSignal(int) { return False; }
|
inline virtual Bool handleSignal(int) { return False; }
|
||||||
|
|
||||||
|
void setPixmapProperty(int, Pixmap);
|
||||||
|
Pixmap duplicatePixmap(int, Pixmap, int, int);
|
||||||
|
|
||||||
void gradient(void);
|
void gradient(void);
|
||||||
void modula(int, int);
|
void modula(int, int);
|
||||||
void solid(void);
|
void solid(void);
|
||||||
|
|
Loading…
Reference in a new issue