// Copyright (c) 2002 Henrik Kinnunen (fluxgen at linuxmail.org) // Copyright (c) 1997 - 2000 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 // $Id$ #include "bsetroot.hh" #include "../src/FbTk/I18n.hh" #include "../src/FbTk/ImageControl.hh" #include "../src/FbTk/GContext.hh" #include "../src/FbRootWindow.hh" #ifdef HAVE_CONFIG_H #include "config.h" #endif // HAVE_CONFIG_H #include #ifdef HAVE_CSTRING #include #else #include #endif #ifdef HAVE_CSTDLIB #include #else #include #endif #ifdef HAVE_CSTDIO #include #else #include #endif #include using namespace std; bsetroot::bsetroot(int argc, char **argv, char *dpy_name) : FbTk::App(dpy_name), m_app_name(argv[0]) { pixmaps = (Pixmap *) 0; grad = fore = back = (char *) 0; bool mod = false, sol = false, grd = false; int mod_x = 0, mod_y = 0, i = 0; img_ctrl = new FbTk::ImageControl*[ScreenCount(display())]; for (; i < ScreenCount(display()); i++) { img_ctrl[i] = new FbTk::ImageControl(i, true); } for (i = 1; i < argc; i++) { if (! strcmp("-help", argv[i])) { usage(); } else if ((! strcmp("-fg", argv[i])) || (! strcmp("-foreground", argv[i])) || (! strcmp("-from", argv[i]))) { if ((++i) >= argc) usage(1); fore = argv[i]; } else if ((! strcmp("-bg", argv[i])) || (! strcmp("-background", argv[i])) || (! strcmp("-to", argv[i]))) { if ((++i) >= argc) usage(1); back = argv[i]; } else if (! strcmp("-solid", argv[i])) { if ((++i) >= argc) usage(1); fore = argv[i]; sol = true; } else if (! strcmp("-mod", argv[i])) { if ((++i) >= argc) usage(); mod_x = atoi(argv[i]); if ((++i) >= argc) usage(); mod_y = atoi(argv[i]); if (mod_x < 1) mod_x = 1; if (mod_y < 1) mod_y = 1; mod = true; } else if (! strcmp("-gradient", argv[i])) { if ((++i) >= argc) usage(); grad = argv[i]; grd = true; } else if (! strcmp("-display", argv[i])) { // -display passed through tests earlier... we just skip it now i++; } else usage(); } if ((mod + sol + grd) != true) { _FB_USES_NLS; cerr<> 8) & 0xff; } } Pixmap bitmap, r_bitmap; 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()); FbTk::Color f(fore, screen), b(back, screen); if (! f.isAllocated()) f.setPixel(WhitePixel(display(), screen)); if (! b.isAllocated()) b.setPixel(BlackPixel(display(), screen)); FbTk::GContext gc(root); 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); gc.setTile(r_bitmap); gc.setFillStyle(FillTiled); pixmaps[screen] = XCreatePixmap(display(), root.window(), root.width(), root.height(), root.depth()); XFillRectangle(display(), pixmaps[screen], gc.gc(), 0, 0, root.width(), root.height()); setRootAtoms(pixmaps[screen], screen); root.setBackgroundPixmap(pixmaps[screen]); root.clear(); XFreePixmap(display(), bitmap); XFreePixmap(display(), r_bitmap); } } /** draws pixmaps with a fluxbox texure */ void bsetroot::gradient() { // 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[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); 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)); tmp = img_ctrl[screen]->renderImage(root.width(), root.height(), texture); pixmaps[screen] = XCreatePixmap(display(), root.window(), root.width(), root.height(), root.depth()); XCopyArea(display(), tmp, pixmaps[screen], gc.gc(), 0, 0, root.width(), root.height(), 0, 0); setRootAtoms(pixmaps[screen], screen); root.setBackgroundPixmap(pixmaps[screen]); root.clear(); if (! (root.visual()->c_class & 1)) { img_ctrl[screen]->removeImage(tmp); img_ctrl[screen]->cleanCache(); } } } /** Shows information about usage */ void bsetroot::usage(int exit_code) { _FB_USES_NLS; cerr< 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", "bsetroot usage options")<= argc) { _FB_USES_NLS; cerr<<_FBTEXT(main, DISPLAYRequiresArg, "error: '-display' requires an argument", "option requires an argument")<