From 7d4546ba5b7f2b0bc848ee1e15e0c93a70ba3d04 Mon Sep 17 00:00:00 2001 From: markt Date: Thu, 29 Jun 2006 05:05:30 +0000 Subject: Make fbsetroot set one screen at a time --- ChangeLog | 2 + util/fbsetroot.cc | 212 ++++++++++++++++++++++++------------------------------ util/fbsetroot.hh | 6 +- 3 files changed, 99 insertions(+), 121 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3d9e9d3..2c6bc8d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ (Format: Year/Month/Day) Changes for 1.0rc2: *06/06/29: + * Make fbsetroot set one screen at a time (Mark) + util/fbsetroot.cc/hh * Fix fbsetroot segfault when DISPLAY is unset (Mark) util/fbsetroot.cc *06/06/28: diff --git a/util/fbsetroot.cc b/util/fbsetroot.cc index 24d8c50..e5ae64c 100644 --- a/util/fbsetroot.cc +++ b/util/fbsetroot.cc @@ -55,18 +55,16 @@ using namespace std; fbsetroot::fbsetroot(int argc, char **argv, char *dpy_name) : FbTk::App(dpy_name), m_app_name(argv[0]) { - pixmaps = (Pixmap *) 0; + pixmap = (Pixmap *) 0; + screen = DefaultScreen(FbTk::App::instance()->display()); 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, i = 1; - img_ctrl = new FbTk::ImageControl*[ScreenCount(display())]; - for (; i < ScreenCount(display()); i++) { - img_ctrl[i] = new FbTk::ImageControl(i, true); - } + img_ctrl = new FbTk::ImageControl(screen); - for (i = 1; i < argc; i++) { + for (; i < argc; i++) { if (! strcmp("-help", argv[i])) { usage(); @@ -127,8 +125,6 @@ fbsetroot::fbsetroot(int argc, char **argv, char *dpy_name) exit(2); } - num_screens = ScreenCount(display()); - if (sol && fore) solid(); else if (mod && mod_x && mod_y && fore && back) @@ -144,18 +140,13 @@ fbsetroot::fbsetroot(int argc, char **argv, char *dpy_name) fbsetroot::~fbsetroot() { XKillClient(display(), AllTemporary); - if (pixmaps) { // should always be true + if (pixmap) { // should always be true XSetCloseDownMode(display(), RetainTemporary); - delete [] pixmaps; + delete pixmap; } - if (img_ctrl != 0) { - for (int i=0; i < num_screens; i++) - delete img_ctrl[i]; - - delete [] img_ctrl; - } + delete img_ctrl; } /** @@ -209,34 +200,27 @@ void fbsetroot::setRootAtoms(Pixmap pixmap, int screen) { Draws pixmaps with a single color */ void fbsetroot::solid() { - register int screen = 0; - - pixmaps = new Pixmap[ScreenCount(display())]; - - for (; screen < ScreenCount(display()); screen++) { + FbTk::Color c(fore, screen); + if (! c.isAllocated()) + c.setPixel(BlackPixel(display(), screen)); - FbTk::Color c(fore, screen); - if (! c.isAllocated()) - c.setPixel(BlackPixel(display(), screen)); - - FbRootWindow root(screen); + FbRootWindow root(screen); - FbTk::GContext gc(root); - gc.setForeground(c); + FbTk::GContext gc(root); + gc.setForeground(c); - pixmaps[screen] = XCreatePixmap(display(), - root.window(), - root.width(), root.height(), - root.depth()); + pixmap = new Pixmap(XCreatePixmap(display(), + root.window(), + root.width(), root.height(), + root.depth())); - XFillRectangle(display(), pixmaps[screen], gc.gc(), 0, 0, - root.width(), root.height()); + XFillRectangle(display(), *pixmap, gc.gc(), 0, 0, + root.width(), root.height()); - setRootAtoms(pixmaps[screen], screen); + setRootAtoms(*pixmap, screen); - root.setBackgroundPixmap(pixmaps[screen]); - root.clear(); - } + root.setBackgroundPixmap(*pixmap); + root.clear(); } /** @@ -245,77 +229,73 @@ void fbsetroot::solid() { */ void fbsetroot::modula(int x, int y) { char data[32]; - long pattern; + long pattern = 0; - register int screen, i; + register int i; - pixmaps = new Pixmap[ScreenCount(display())]; - - for (pattern = 0, screen = 0; screen < ScreenCount(display()); screen++) { - FbRootWindow root(screen); + FbRootWindow root(screen); - for (i = 0; i < 16; i++) { - pattern <<= 1; - if ((i % x) == 0) - pattern |= 0x0001; - } + for (i = 0; i < 16; i++) { + pattern <<= 1; + if ((i % x) == 0) + pattern |= 0x0001; + } - 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++) { + 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; } + } - Pixmap bitmap, r_bitmap; + Pixmap bitmap, r_bitmap; - bitmap = XCreateBitmapFromData(display(), - root.window(), data, 16, 16); + bitmap = XCreateBitmapFromData(display(), + root.window(), data, 16, 16); - // bitmap used as tile, needs to have the same depth as background pixmap - r_bitmap = XCreatePixmap(display(), - root.window(), 16, 16, - root.depth()); + // bitmap used as tile, needs to have the same depth as background pixmap + r_bitmap = XCreatePixmap(display(), + root.window(), 16, 16, + root.depth()); - FbTk::Color f(fore, screen), b(back, screen); + FbTk::Color f(fore, screen), b(back, screen); - if (! f.isAllocated()) - f.setPixel(WhitePixel(display(), screen)); - if (! b.isAllocated()) - b.setPixel(BlackPixel(display(), screen)); + if (! f.isAllocated()) + f.setPixel(WhitePixel(display(), screen)); + if (! b.isAllocated()) + b.setPixel(BlackPixel(display(), screen)); - FbTk::GContext gc(root); + FbTk::GContext gc(root); - gc.setForeground(f); - gc.setBackground(b); + gc.setForeground(f); + gc.setBackground(b); - // copying bitmap to the one going to be used as tile - XCopyPlane(display(), bitmap, r_bitmap, gc.gc(), - 0, 0, 16, 16, 0, 0, 1l); + // copying bitmap to the one going to be used as tile + XCopyPlane(display(), bitmap, r_bitmap, gc.gc(), + 0, 0, 16, 16, 0, 0, 1l); - gc.setTile(r_bitmap); - gc.setFillStyle(FillTiled); + gc.setTile(r_bitmap); + gc.setFillStyle(FillTiled); - pixmaps[screen] = XCreatePixmap(display(), - root.window(), - root.width(), root.height(), - root.depth()); + pixmap = new Pixmap(XCreatePixmap(display(), + root.window(), + root.width(), root.height(), + root.depth())); - XFillRectangle(display(), pixmaps[screen], gc.gc(), 0, 0, - root.width(), root.height()); + XFillRectangle(display(), *pixmap, gc.gc(), 0, 0, + root.width(), root.height()); - setRootAtoms(pixmaps[screen], screen); - root.setBackgroundPixmap(pixmaps[screen]); - root.clear(); + setRootAtoms(*pixmap, screen); + root.setBackgroundPixmap(*pixmap); + root.clear(); - XFreePixmap(display(), bitmap); - XFreePixmap(display(), r_bitmap); - } + XFreePixmap(display(), bitmap); + XFreePixmap(display(), r_bitmap); } /** @@ -326,52 +306,48 @@ void fbsetroot::gradient() { // get crashed somewhere on the way causing apps like XChat chrashing // as the pixmap has been destroyed Pixmap tmp; - pixmaps = new Pixmap[ScreenCount(display())]; // we must insert gradient text string texture_value = grad ? grad : "solid"; texture_value.insert(0, "gradient "); FbTk::Texture texture; texture.setFromString(texture_value.c_str()); - - for (int screen = 0; screen < ScreenCount(display()); screen++) { - FbRootWindow root(screen); + FbRootWindow root(screen); - FbTk::GContext gc(root); - texture.color().setFromString(fore, screen); - texture.colorTo().setFromString(back, screen); + FbTk::GContext gc(root); + texture.color().setFromString(fore, screen); + texture.colorTo().setFromString(back, screen); - if (! texture.color().isAllocated()) - texture.color().setPixel(WhitePixel(display(), screen)); - if (! texture.colorTo().isAllocated()) - texture.colorTo().setPixel(BlackPixel(display(), screen)); + if (! texture.color().isAllocated()) + texture.color().setPixel(WhitePixel(display(), screen)); - tmp = img_ctrl[screen]->renderImage(root.width(), root.height(), - texture); + if (! texture.colorTo().isAllocated()) + texture.colorTo().setPixel(BlackPixel(display(), screen)); - pixmaps[screen] = XCreatePixmap(display(), - root.window(), - root.width(), root.height(), - root.depth()); + tmp = img_ctrl->renderImage(root.width(), root.height(), texture); - - XCopyArea(display(), tmp, pixmaps[screen], gc.gc(), 0, 0, - root.width(), root.height(), - 0, 0); + pixmap = new Pixmap(XCreatePixmap(display(), + root.window(), + root.width(), root.height(), + root.depth())); - setRootAtoms(pixmaps[screen], screen); - root.setBackgroundPixmap(pixmaps[screen]); - root.clear(); + XCopyArea(display(), tmp, *pixmap, gc.gc(), 0, 0, + root.width(), root.height(), + 0, 0); - if (! (root.visual()->c_class & 1)) { - img_ctrl[screen]->removeImage(tmp); - img_ctrl[screen]->cleanCache(); - } + setRootAtoms(*pixmap, screen); + root.setBackgroundPixmap(*pixmap); + root.clear(); + + if (! (root.visual()->c_class & 1)) { + img_ctrl->removeImage(tmp); + img_ctrl->cleanCache(); } + } /** diff --git a/util/fbsetroot.hh b/util/fbsetroot.hh index 21edaa9..6deb4b6 100644 --- a/util/fbsetroot.hh +++ b/util/fbsetroot.hh @@ -43,11 +43,11 @@ public: void setRootAtoms(Pixmap pixmap, int screen); private: - FbTk::ImageControl **img_ctrl; - Pixmap *pixmaps; + FbTk::ImageControl *img_ctrl; + Pixmap *pixmap; + int screen; char *fore, *back, *grad; - int num_screens; char *m_app_name; }; -- cgit v0.11.2