X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=util%2Fbsetroot.cc;h=470ca7b3ead64d6d89cb67fb7dcf25212603ce46;hb=3531afa1cca6fe135013b925999d3b62291c0acb;hp=d9cd4fb2d494e7a247590c8b1313e8e7940da2c2;hpb=d2bcec1cda227de11fef6c62a6f4aae357c3760f;p=chaz%2Fopenbox diff --git a/util/bsetroot.cc b/util/bsetroot.cc index d9cd4fb2..470ca7b3 100644 --- a/util/bsetroot.cc +++ b/util/bsetroot.cc @@ -1,34 +1,62 @@ +// -*- mode++; indent-tabs-mode: nil; c-basic-offset: 2; -*- +// Window.cc for Blackbox - an X11 Window manager +// Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry +// Copyright (c) 1997 - 2000, 2002 Brad Hughes +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + #ifdef HAVE_CONFIG_H # include "../config.h" #endif // HAVE_CONFIG_H -#ifdef STDC_HEADERS -# include +extern "C" { +#ifdef HAVE_STDLIB_H # include -#endif // STDC_HEADERS +#endif // HAVE_STDLIB_H + +#ifdef HAVE_STRING_H +# include +#endif // HAVE_STRING_H #ifdef HAVE_STDIO_H # include #endif // HAVE_STDIO_H +} + +#include "../src/i18n.hh" +#include "../src/GCCache.hh" +#include "../src/Texture.hh" +#include "../src/Util.hh" +#include "bsetroot.hh" -#include "../src/i18n.h" -#include "bsetroot.h" +I18n i18n; 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; + bool mod = False, sol = False, grd = False; + 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])) || @@ -75,19 +103,17 @@ bsetroot::bsetroot(int argc, char **argv, char *dpy_name) 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(bsetrootSet, bsetrootMustSpecify, + "%s: error: must specify one of: -solid, -mod, -gradient\n"), getApplicationName()); - + usage(2); } - + + img_ctrl = new BImageControl*[getNumberOfScreens()]; + for (unsigned int s = 0; s < getNumberOfScreens(); ++s) + img_ctrl[s] = new BImageControl(this, getScreenInfo(s), 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(); @@ -96,41 +122,96 @@ bsetroot::bsetroot(int argc, char **argv, char *dpy_name) 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; - } + std::for_each(img_ctrl, img_ctrl + getNumberOfScreens(), PointerAssassin()); + + delete [] img_ctrl; +} - delete [] pixmaps; + +// adapted from wmsetbg +void bsetroot::setPixmapProperty(int screen, Pixmap pixmap) { + static Atom rootpmap_id = None, esetroot_id = None; + Atom type; + int format; + unsigned long length, after; + unsigned char *data; + const ScreenInfo *screen_info = getScreenInfo(screen); + + if (rootpmap_id == None) { + rootpmap_id = XInternAtom(getXDisplay(), "_XROOTPMAP_ID", False); + esetroot_id = XInternAtom(getXDisplay(), "ESETROOT_PMAP_ID", False); } - if (img_ctrl) { - int i = 0; - for (; i < getNumberOfScreens(); i++) - delete img_ctrl[i]; + XGrabServer(getXDisplay()); + + /* Clear out the old pixmap */ + XGetWindowProperty(getXDisplay(), screen_info->getRootWindow(), + rootpmap_id, 0L, 1L, False, XA_PIXMAP, + &type, &format, &length, &after, &data); + if (type == XA_PIXMAP && format == 32) { + XKillClient(getXDisplay(), *((Pixmap *) data)); + XSync(getXDisplay(), False); + XFree(data); + } - delete [] img_ctrl; + if (pixmap) { + XChangeProperty(getXDisplay(), screen_info->getRootWindow(), + rootpmap_id, XA_PIXMAP, 32, PropModeReplace, + (unsigned char *) &pixmap, 1); + XChangeProperty(getXDisplay(), screen_info->getRootWindow(), + esetroot_id, XA_PIXMAP, 32, PropModeReplace, + (unsigned char *) &pixmap, 1); + } else { + XDeleteProperty(getXDisplay(), screen_info->getRootWindow(), + rootpmap_id); + XDeleteProperty(getXDisplay(), screen_info->getRootWindow(), + esetroot_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) { - register int screen = 0; + for (unsigned int screen = 0; screen < getNumberOfScreens(); screen++) { + BColor c(fore, this, screen); + const ScreenInfo *screen_info = getScreenInfo(screen); + + XSetWindowBackground(getXDisplay(), screen_info->getRootWindow(), + c.pixel()); + XClearWindow(getXDisplay(), screen_info->getRootWindow()); - for (; screen < getNumberOfScreens(); screen++) { - BColor c; + Pixmap pixmap = XCreatePixmap(getXDisplay(), + screen_info->getRootWindow(), + 8, 8, DefaultDepth(getXDisplay(), screen)); + BPen pen(c); + XFillRectangle(getXDisplay(), pixmap, pen.gc(), 0, 0, 8, 8); - img_ctrl[screen]->parseColor(&c, fore); - if (! c.isAllocated()) c.setPixel(BlackPixel(getXDisplay(), screen)); + setPixmapProperty(screen, duplicatePixmap(screen, pixmap, 8, 8)); - XSetWindowBackground(getXDisplay(), getScreenInfo(screen)->getRootWindow(), - c.getPixel()); - XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow()); + XFreePixmap(getXDisplay(), pixmap); } } @@ -139,9 +220,7 @@ void bsetroot::modula(int x, int y) { char data[32]; long pattern; - register int screen, i; - - pixmaps = new Pixmap[getNumberOfScreens()]; + unsigned int screen, i; for (pattern = 0, screen = 0; screen < getNumberOfScreens(); screen++) { for (i = 0; i < 16; i++) { @@ -150,147 +229,127 @@ void bsetroot::modula(int x, int y) { 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)] = static_cast(0xff); + data[(i * 2) + 1] = static_cast(0xff); } else { data[(i * 2)] = pattern & 0xff; data[(i * 2) + 1] = (pattern >> 8) & 0xff; } + } - BColor f, b; + BColor f(fore, this, screen), b(back, this, screen); GC gc; Pixmap bitmap; - XGCValues gcv; + const ScreenInfo *screen_info = getScreenInfo(screen); bitmap = XCreateBitmapFromData(getXDisplay(), - getScreenInfo(screen)->getRootWindow(), data, + screen_info->getRootWindow(), data, 16, 16); - img_ctrl[screen]->parseColor(&f, fore); - img_ctrl[screen]->parseColor(&b, back); - - if (! f.isAllocated()) f.setPixel(WhitePixel(getXDisplay(), screen)); - if (! b.isAllocated()) b.setPixel(BlackPixel(getXDisplay(), screen)); - - gcv.foreground = f.getPixel(); - gcv.background = b.getPixel(); + XGCValues gcv; + gcv.foreground = f.pixel(); + gcv.background = b.pixel(); - gc = XCreateGC(getXDisplay(), getScreenInfo(screen)->getRootWindow(), + gc = XCreateGC(getXDisplay(), screen_info->getRootWindow(), GCForeground | GCBackground, &gcv); - pixmaps[screen] = - XCreatePixmap(getXDisplay(), getScreenInfo(screen)->getRootWindow(), - 16, 16, getScreenInfo(screen)->getDepth()); + Pixmap pixmap = XCreatePixmap(getXDisplay(), + screen_info->getRootWindow(), + 16, 16, screen_info->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]); - XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow()); + screen_info->getRootWindow(), + pixmap); + XClearWindow(getXDisplay(), screen_info->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 (! (screen_info->getVisual()->c_class & 1)) + XFreePixmap(getXDisplay(), pixmap); } } void bsetroot::gradient(void) { - register int screen; + for (unsigned int screen = 0; screen < getNumberOfScreens(); screen++) { + BTexture texture(grad, this, screen, img_ctrl[screen]); + const ScreenInfo *screen_info = getScreenInfo(screen); - pixmaps = new Pixmap[getNumberOfScreens()]; + texture.setColor(BColor(fore, this, screen)); + texture.setColorTo(BColor(back, this, screen)); - 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); + Pixmap pixmap = + img_ctrl[screen]->renderImage(screen_info->getWidth(), + screen_info->getHeight(), + texture); - if (! texture.getColor()->isAllocated()) - texture.getColor()->setPixel(WhitePixel(getXDisplay(), screen)); - if (! texture.getColorTo()->isAllocated()) - texture.getColorTo()->setPixel(BlackPixel(getXDisplay(), screen)); + XSetWindowBackgroundPixmap(getXDisplay(), + screen_info->getRootWindow(), + pixmap); + XClearWindow(getXDisplay(), screen_info->getRootWindow()); - pixmaps[screen] = - img_ctrl[screen]->renderImage(getScreenInfo(screen)->getWidth(), - getScreenInfo(screen)->getHeight(), - &texture); + setPixmapProperty(screen, + duplicatePixmap(screen, pixmap, + screen_info->getWidth(), + screen_info->getHeight())); - XSetWindowBackgroundPixmap(getXDisplay(), - getScreenInfo(screen)->getRootWindow(), - pixmaps[screen]); - XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow()); - - if (! (getScreenInfo(screen)->getVisual()->c_class & 1)) { - img_ctrl[screen]->removeImage(pixmaps[screen]); - img_ctrl[screen]->timeout(); - pixmaps[screen] = None; + if (! (screen_info->getVisual()->c_class & 1)) { + 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 - "%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); -} + fprintf(stderr, + i18n(bsetrootSet, bsetrootUsage, + "%s 2.0\n\n" + "Copyright (c) 1997-2000, 2002 Bradley T Hughes\n" + "Copyright (c) 2001-2002 Sean 'Shaleh' Perry\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); +} int main(int argc, char **argv) { char *display_name = (char *) 0; - int i = 1; - - NLSInit("openbox.cat"); - - for (; i < argc; i++) { + + i18n.openCatalog("blackbox.cat"); + + 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 - "error: '-display' requires an argument\n")); - + fprintf(stderr, i18n(mainSet, mainDISPLAYRequiresArg, + "error: '-display' requires an argument\n")); + ::exit(1); } - + display_name = argv[i]; } } - + bsetroot app(argc, argv, display_name); - + return 0; }