Index: src/FbTk/FbPixmap.cc =================================================================== RCS file: /cvsroot/fluxbox/fluxbox/src/FbTk/FbPixmap.cc,v retrieving revision 1.12 retrieving revision 1.14 diff -u -r1.12 -r1.14 --- src/FbTk/FbPixmap.cc 6 Jul 2004 10:47:36 -0000 1.12 +++ src/FbTk/FbPixmap.cc 10 Sep 2004 15:46:08 -0000 1.14 @@ -30,21 +30,23 @@ #include <X11/Xutil.h> +#include <X11/Xatom.h> #include <iostream> using namespace std; namespace FbTk { -FbPixmap::FbPixmap():m_pm(0), - m_width(0), m_height(0), - m_depth(0) { } - -FbPixmap::FbPixmap(const FbPixmap &the_copy):m_pm(0), - m_width(0), m_height(0), - m_depth(0) { +FbPixmap::FbPixmap():m_pm(0), + m_width(0), m_height(0), + m_depth(0) { +} + +FbPixmap::FbPixmap(const FbPixmap &the_copy):FbDrawable(), m_pm(0), + m_width(0), m_height(0), + m_depth(0){ copy(the_copy); } -FbPixmap::FbPixmap(Pixmap pm):m_pm(0), +FbPixmap::FbPixmap(Pixmap pm):m_pm(0), m_width(0), m_height(0), m_depth(0) { if (pm == 0) @@ -50,19 +52,19 @@ (*this) = pm; } -FbPixmap::FbPixmap(const FbDrawable &src, +FbPixmap::FbPixmap(const FbDrawable &src, unsigned int width, unsigned int height, - int depth):m_pm(0), - m_width(0), m_height(0), + int depth):m_pm(0), + m_width(0), m_height(0), m_depth(0) { create(src.drawable(), width, height, depth); } -FbPixmap::FbPixmap(Drawable src, +FbPixmap::FbPixmap(Drawable src, unsigned int width, unsigned int height, - int depth):m_pm(0), - m_width(0), m_height(0), + int depth):m_pm(0), + m_width(0), m_height(0), m_depth(0) { create(src, width, height, depth); @@ -87,8 +89,8 @@ // get width, height and depth for the pixmap Window root; int x, y; - unsigned int border_width, bpp; - XGetGeometry(FbTk::App::instance()->display(), + unsigned int border_width, bpp; + XGetGeometry(s_display, pm, &root, &x, &y, @@ -112,20 +114,20 @@ the_copy.depth() != depth() || drawable() == 0) create_new = true; - - if (create_new) + + if (create_new) free(); if (the_copy.drawable() != 0) { if (create_new) { - create(the_copy.drawable(), + create(the_copy.drawable(), the_copy.width(), the_copy.height(), the_copy.depth()); } - + if (drawable()) { GContext gc(drawable()); - + copyArea(the_copy.drawable(), gc.gc(), 0, 0, @@ -146,7 +148,7 @@ unsigned int border_width, bpp; unsigned int new_width, new_height; - XGetGeometry(FbTk::App::instance()->display(), + XGetGeometry(s_display, pm, &root, &x, &y, @@ -155,25 +157,21 @@ &bpp); // create new pixmap and copy area create(root, new_width, new_height, bpp); - - Display *disp = FbTk::App::instance()->display(); - GC gc = XCreateGC(disp, drawable(), 0, 0); + GC gc = XCreateGC(s_display, drawable(), 0, 0); - XCopyArea(disp, pm, drawable(), gc, + XCopyArea(s_display, pm, drawable(), gc, 0, 0, width(), height(), 0, 0); - XFreeGC(disp, gc); + XFreeGC(s_display, gc); } void FbPixmap::rotate() { - Display *dpy = FbTk::App::instance()->display(); - // make an image copy - XImage *src_image = XGetImage(dpy, drawable(), + XImage *src_image = XGetImage(s_display, drawable(), 0, 0, // pos width(), height(), // size ~0, // plane mask @@ -184,11 +182,11 @@ GContext gc(drawable()); // copy new area - for (int y = 0; y < static_cast<signed>(height()); ++y) { - for (int x = 0; x < static_cast<signed>(width()); ++x) { + for (unsigned int y = 0; y < height(); ++y) { + for (unsigned int x = 0; x < width(); ++x) { gc.setForeground(XGetPixel(src_image, x, y)); // revers coordinates - XDrawPoint(dpy, new_pm.drawable(), gc.gc(), y, x); + XDrawPoint(s_display, new_pm.drawable(), gc.gc(), y, x); } } @@ -203,13 +201,12 @@ } void FbPixmap::scale(unsigned int dest_width, unsigned int dest_height) { - if (drawable() == 0 || + + if (drawable() == 0 || (dest_width == width() && dest_height == height())) return; - Display *dpy = FbTk::App::instance()->display(); - - XImage *src_image = XGetImage(dpy, drawable(), + XImage *src_image = XGetImage(s_display, drawable(), 0, 0, // pos width(), height(), // size ~0, // plane mask @@ -227,13 +224,13 @@ // start scaling float src_x = 0, src_y = 0; - for (int tx=0; tx < static_cast<signed>(dest_width); ++tx, src_x += zoom_x) { + for (unsigned int tx=0; tx < dest_width; ++tx, src_x += zoom_x) { src_y = 0; - for (int ty=0; ty < static_cast<signed>(dest_height); ++ty, src_y += zoom_y) { + for (unsigned int ty=0; ty < dest_height; ++ty, src_y += zoom_y) { gc.setForeground(XGetPixel(src_image, static_cast<int>(src_x), static_cast<int>(src_y))); - XDrawPoint(dpy, new_pm.drawable(), gc.gc(), tx, ty); + XDrawPoint(s_display, new_pm.drawable(), gc.gc(), tx, ty); } } @@ -249,23 +246,23 @@ } void FbPixmap::tile(unsigned int dest_width, unsigned int dest_height) { - if (drawable() == 0 || + if (drawable() == 0 || (dest_width == width() && dest_height == height())) return; - + FbPixmap new_pm(drawable(), width(), height(), depth()); new_pm.copy(m_pm); resize(dest_width, dest_height); - + FbTk::GContext gc(*this); - + gc.setTile(new_pm); gc.setFillStyle(FillTiled); fillRectangle(gc.gc(), 0, 0, dest_width, dest_height); - + } @@ -284,9 +281,61 @@ return ret; } +Pixmap FbPixmap::getRootPixmap(int screen_num) { + + Atom real_type; + int real_format; + unsigned long items_read, items_left; + unsigned int *data; + + unsigned int prop = 0; + static const char* prop_ids[] = { + "_XROOTPMAP_ID", + "_XSETROOT_ID", + 0 + }; + static bool print_error = true; // print error_message only once + static const char* error_message = { "\n\n !!! WARNING WARNING WARNING WARNING !!!!!\n" + " if you experience problems with transparency:\n" + " you are using a wallpapersetter that \n" + " uses _XSETROOT_ID .. which we do not support.\n" + " consult 'fbsetbg -i' or try any other wallpapersetter\n" + " that uses _XROOTPMAP_ID !\n" + " !!! WARNING WARNING WARNING WARNING !!!!!!\n\n" + }; + + Pixmap root_pm = None; + + for (prop = 0; prop_ids[prop]; prop++) { + if (XGetWindowProperty(s_display, + RootWindow(s_display, screen_num), + XInternAtom(s_display, prop_ids[prop], False), + 0L, 4, + False, XA_PIXMAP, + &real_type, &real_format, + &items_read, &items_left, + (unsigned char **) &data) == Success && + real_format == 32 && items_read == 1) { + + if (strcmp(prop_ids[prop], "_XSETROOT_ID") == 0) { + if (print_error) { + fprintf(stderr, "%s", error_message); + print_error = false; + } + } else + root_pm = (Pixmap) (*data); + + XFree(data); + break; + } + } + + return root_pm; +} + void FbPixmap::free() { if (m_pm != 0) { - XFreePixmap(FbTk::App::instance()->display(), m_pm); + XFreePixmap(s_display, m_pm); m_pm = 0; } m_width = 0; @@ -294,13 +343,13 @@ m_depth = 0; } -void FbPixmap::create(Drawable src, - unsigned int width, unsigned int height, +void FbPixmap::create(Drawable src, + unsigned int width, unsigned int height, int depth) { if (src == 0) return; - m_pm = XCreatePixmap(FbTk::App::instance()->display(), + m_pm = XCreatePixmap(s_display, src, width, height, depth); if (m_pm == 0) return; Index: src/FbTk/FbPixmap.hh =================================================================== RCS file: /cvsroot/fluxbox/fluxbox/src/FbTk/FbPixmap.hh,v retrieving revision 1.12 retrieving revision 1.13 diff -r1.12 -r1.13 70a71 > static Pixmap getRootPixmap(int screen_num); Index: src/FbTk/FbWindow.cc =================================================================== RCS file: /cvsroot/fluxbox/fluxbox/src/FbTk/FbWindow.cc,v retrieving revision 1.37 retrieving revision 1.39 diff -r1.37 -r1.39 24a25 > #include "FbPixmap.hh" 46,73c47 < namespace { < Pixmap getRootPixmap(int screen_num) { < Pixmap root_pm = 0; < // get root pixmap for transparency < Display *disp = FbTk::App::instance()->display(); < Atom real_type; < int real_format; < unsigned long items_read, items_left; < unsigned int *data; < if (XGetWindowProperty(disp, RootWindow(disp, screen_num), < XInternAtom(disp, "_XROOTPMAP_ID", false), < 0L, 1L, < false, XA_PIXMAP, &real_type, < &real_format, &items_read, &items_left, < (unsigned char **) &data) == Success && < items_read) { < root_pm = (Pixmap) (*data); < XFree(data); < } < < return root_pm; < } < < }; // end anonymous namespace < < Display *FbWindow::s_display = 0; < < FbWindow::FbWindow():m_parent(0), m_screen_num(0), m_window(0), m_x(0), m_y(0), --- > FbWindow::FbWindow():FbDrawable(), m_parent(0), m_screen_num(0), m_window(0), m_x(0), m_y(0), 75c49 < m_buffer_pm(0) { --- > m_buffer_pm(0){ 77,78d50 < if (s_display == 0) < s_display = App::instance()->display(); 88,90d59 < if (s_display == 0) < s_display = App::instance()->display(); < 101a71 > FbDrawable(), 107c77 < create(RootWindow(FbTk::App::instance()->display(), screen_num), --- > create(RootWindow(s_display, screen_num), 129c99 < FbWindow::FbWindow(Window client):m_parent(0), --- > FbWindow::FbWindow(Window client):FbDrawable(), m_parent(0), 139,141d108 < if (s_display == 0) < s_display = App::instance()->display(); < 210c177 < Pixmap root = getRootPixmap(screenNumber()); --- > Pixmap root = FbPixmap::getRootPixmap(screenNumber()); 248c215 < m_transparent.reset(new Transparent(getRootPixmap(screenNumber()), window(), alpha, screenNumber())); --- > m_transparent.reset(new Transparent(FbPixmap::getRootPixmap(screenNumber()), window(), alpha, screenNumber())); 285,286d251 < if (s_display == 0) < s_display = App::instance()->display(); 450,452d414 < if (s_display == 0) < s_display = FbTk::App::instance()->display(); < Index: src/FbTk/FbWindow.hh =================================================================== RCS file: /cvsroot/fluxbox/fluxbox/src/FbTk/FbWindow.hh,v retrieving revision 1.32 retrieving revision 1.33 diff -r1.32 -r1.33 182d181 < static Display *s_display; ///< display connection Index: src/FbTk/FbDrawable.cc =================================================================== RCS file: /cvsroot/fluxbox/fluxbox/src/FbTk/FbDrawable.cc,v retrieving revision 1.2 retrieving revision 1.3 diff -r1.2 -r1.3 29a30,38 > Display *FbDrawable::s_display = 0; > > FbDrawable::FbDrawable() { > > if (s_display == 0) { > s_display = FbTk::App::instance()->display(); > } > } > 36c45 < XCopyArea(FbTk::App::instance()->display(), --- > XCopyArea(s_display, 47c56 < XFillRectangle(FbTk::App::instance()->display(), --- > XFillRectangle(s_display, 57c66 < XDrawRectangle(FbTk::App::instance()->display(), --- > XDrawRectangle(s_display, 67c76 < XDrawLine(FbTk::App::instance()->display(), --- > XDrawLine(s_display, 78c87 < XFillPolygon(FbTk::App::instance()->display(), --- > XFillPolygon(s_display, 86c95 < XDrawPoint(FbTk::App::instance()->display(), drawable(), gc, x, y); --- > XDrawPoint(s_display, drawable(), gc, x, y); 90c99 < return XGetImage(FbTk::App::instance()->display(), drawable(), --- > return XGetImage(s_display, drawable(), Index: src/FbTk/FbDrawable.hh =================================================================== RCS file: /cvsroot/fluxbox/fluxbox/src/FbTk/FbDrawable.hh,v retrieving revision 1.4 retrieving revision 1.5 diff -r1.4 -r1.5 32a33 > FbDrawable(); 57a59,60 > protected: > static Display *s_display; // display connection // display connection