#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])) ||
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();
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);
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);
}
}
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++) {
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;
data[(i * 2)] = pattern & 0xff;
data[(i * 2) + 1] = (pattern >> 8) & 0xff;
}
+ }
BColor f, b;
GC gc;
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);
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);
}
}
}
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 <string> display connection\n"
" -mod <x> <y> modula pattern\n"
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);