all repos — fluxbox @ a7967dfb25c2f6df31e84d3ffdab952d44efaab1

custom fork of the fluxbox windowmanager

put App::instance()->display() to FbDrawable::s_display to avoid too much
unnecessary calls
akir akir
commit

a7967dfb25c2f6df31e84d3ffdab952d44efaab1

parent

631dfbbc6377b0338b56131e51b37fe836ff96bf

M src/FbTk/FbDrawable.ccsrc/FbTk/FbDrawable.cc

@@ -19,7 +19,7 @@ // 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. -// $Id: FbDrawable.cc,v 1.2 2003/09/06 15:39:06 fluxgen Exp $ +// $Id: FbDrawable.cc,v 1.3 2004/09/10 15:46:08 akir Exp $ #include "FbDrawable.hh"

@@ -27,13 +27,22 @@ #include "App.hh"

namespace FbTk { +Display *FbDrawable::s_display = 0; + +FbDrawable::FbDrawable() { + + if (s_display == 0) { + s_display = FbTk::App::instance()->display(); + } +} + void FbDrawable::copyArea(Drawable src, GC gc, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height) { if (drawable() == 0 || src == 0 || gc == 0) return; - XCopyArea(FbTk::App::instance()->display(), + XCopyArea(s_display, src, drawable(), gc, src_x, src_y, width, height,

@@ -44,7 +53,7 @@ void FbDrawable::fillRectangle(GC gc, int x, int y,

unsigned int width, unsigned int height) { if (drawable() == 0 || gc == 0) return; - XFillRectangle(FbTk::App::instance()->display(), + XFillRectangle(s_display, drawable(), gc, x, y, width, height);

@@ -54,7 +63,7 @@ void FbDrawable::drawRectangle(GC gc, int x, int y,

unsigned int width, unsigned int height) { if (drawable() == 0 || gc == 0) return; - XDrawRectangle(FbTk::App::instance()->display(), + XDrawRectangle(s_display, drawable(), gc, x, y, width, height);

@@ -64,7 +73,7 @@ void FbDrawable::drawLine(GC gc, int start_x, int start_y,

int end_x, int end_y) { if (drawable() == 0 || gc == 0) return; - XDrawLine(FbTk::App::instance()->display(), + XDrawLine(s_display, drawable(), gc, start_x, start_y,

@@ -75,7 +84,7 @@ void FbDrawable::fillPolygon(GC gc, XPoint *points, int npoints,

int shape, int mode) { if (drawable() == 0 || gc == 0 || points == 0 || npoints == 0) return; - XFillPolygon(FbTk::App::instance()->display(), + XFillPolygon(s_display, drawable(), gc, points, npoints, shape, mode); }

@@ -83,11 +92,11 @@

void FbDrawable::drawPoint(GC gc, int x, int y) { if (drawable() == 0 || gc == 0) return; - XDrawPoint(FbTk::App::instance()->display(), drawable(), gc, x, y); + XDrawPoint(s_display, drawable(), gc, x, y); } XImage *FbDrawable::image(int x, int y, unsigned int width, unsigned int height) const { - return XGetImage(FbTk::App::instance()->display(), drawable(), + return XGetImage(s_display, drawable(), x, y, width, height, AllPlanes, // plane mask ZPixmap);
M src/FbTk/FbDrawable.hhsrc/FbTk/FbDrawable.hh

@@ -19,7 +19,7 @@ // 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. -// $Id: FbDrawable.hh,v 1.4 2003/12/16 17:06:49 fluxgen Exp $ +// $Id: FbDrawable.hh,v 1.5 2004/09/10 15:46:08 akir Exp $ #ifndef FBTK_FBDRAWABLE_HH #define FBTK_FBDRAWABLE_HH

@@ -30,6 +30,7 @@

/// Basic drawing functions for X drawables class FbDrawable { public: + FbDrawable(); virtual ~FbDrawable() { } virtual void copyArea(Drawable src, GC gc, int src_x, int src_y,

@@ -55,6 +56,8 @@ /// X drawable

virtual Drawable drawable() const = 0; virtual unsigned int width() const = 0; virtual unsigned int height() const = 0; +protected: + static Display *s_display; // display connection // display connection }; } // end namespace FbTk
M src/FbTk/FbPixmap.ccsrc/FbTk/FbPixmap.cc

@@ -19,7 +19,7 @@ // 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. -// $Id: FbPixmap.cc,v 1.13 2004/09/09 14:29:10 akir Exp $ +// $Id: FbPixmap.cc,v 1.14 2004/09/10 15:46:08 akir Exp $ #include "FbPixmap.hh" #include "App.hh"

@@ -32,17 +32,18 @@ using namespace std;

namespace FbTk { -FbPixmap::FbPixmap():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):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)

@@ -51,19 +52,19 @@ // assign X pixmap to this

(*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);

@@ -88,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,

@@ -113,20 +114,20 @@ the_copy.height() != height() ||

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,

@@ -147,7 +148,7 @@ int x, y;

unsigned int border_width, bpp; unsigned int new_width, new_height; - XGetGeometry(FbTk::App::instance()->display(), + XGetGeometry(s_display, pm, &root, &x, &y,

@@ -156,25 +157,21 @@ &border_width,

&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

@@ -185,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); } }

@@ -204,14 +201,12 @@ m_pm = new_pm.release();

} 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

@@ -229,13 +224,13 @@ float zoom_y = static_cast<float>(height())/static_cast<float>(dest_height);

// 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); } }

@@ -251,23 +246,23 @@ m_pm = new_pm.release();

} 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); - + }

@@ -287,45 +282,60 @@ return ret;

} Pixmap FbPixmap::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); -/* TODO: analyze why this doesnt work - } else if (XGetWindowProperty(disp, RootWindow(disp, screen_num), - XInternAtom(disp, "_XSETROOT_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; + 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;

@@ -333,13 +343,13 @@ m_height = 0;

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;
M src/FbTk/FbWindow.ccsrc/FbTk/FbWindow.cc

@@ -19,7 +19,7 @@ // 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. -// $Id: FbWindow.cc,v 1.38 2004/09/09 14:29:10 akir Exp $ +// $Id: FbWindow.cc,v 1.39 2004/09/10 15:46:08 akir Exp $ #include "FbWindow.hh" #include "FbPixmap.hh"

@@ -44,14 +44,10 @@ #endif

namespace FbTk { -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), m_width(0), m_height(0), m_border_width(0), m_depth(0), m_destroy(true), - m_buffer_pm(0) { + m_buffer_pm(0){ - if (s_display == 0) - s_display = App::instance()->display(); } FbWindow::FbWindow(const FbWindow& the_copy):m_parent(the_copy.parent()),

@@ -61,9 +57,6 @@ m_width(the_copy.width()), m_height(the_copy.height()),

m_border_width(the_copy.borderWidth()), m_depth(the_copy.depth()), m_destroy(true), m_buffer_pm(0) { - if (s_display == 0) - s_display = App::instance()->display(); - the_copy.m_window = 0; }

@@ -75,12 +68,13 @@ bool override_redirect,

bool save_unders, int depth, int class_type): + FbDrawable(), m_parent(0), m_screen_num(screen_num), m_destroy(true), m_buffer_pm(0) { - create(RootWindow(FbTk::App::instance()->display(), screen_num), + create(RootWindow(s_display, screen_num), x, y, width, height, eventmask, override_redirect, save_unders, depth, class_type); };

@@ -102,7 +96,7 @@

}; -FbWindow::FbWindow(Window client):m_parent(0), +FbWindow::FbWindow(Window client):FbDrawable(), m_parent(0), m_screen_num(0), m_window(0), m_x(0), m_y(0),

@@ -112,9 +106,6 @@ m_depth(0),

m_destroy(false), // don't destroy this window m_buffer_pm(0) { - if (s_display == 0) - s_display = App::instance()->display(); - setNew(client); }

@@ -258,8 +249,6 @@ return *this;

} void FbWindow::setNew(Window win) { - if (s_display == 0) - s_display = App::instance()->display(); if (m_window != 0 && m_destroy) XDestroyWindow(s_display, m_window);

@@ -422,9 +411,6 @@ unsigned int width, unsigned int height,

long eventmask, bool override_redirect, bool save_unders, int depth, int class_type) { - - if (s_display == 0) - s_display = FbTk::App::instance()->display(); m_border_width = 0;
M src/FbTk/FbWindow.hhsrc/FbTk/FbWindow.hh

@@ -19,7 +19,7 @@ // 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. -// $Id: FbWindow.hh,v 1.32 2004/06/13 00:32:40 fluxgen Exp $ +// $Id: FbWindow.hh,v 1.33 2004/09/10 15:46:08 akir Exp $ #ifndef FBTK_FBWINDOW_HH #define FBTK_FBWINDOW_HH

@@ -179,7 +179,6 @@ bool override_redirect,

bool save_unders, int depth, int class_type); - static Display *s_display; ///< display connection const FbWindow *m_parent; ///< parent FbWindow int m_screen_num; ///< screen num on which this window exist mutable Window m_window; ///< the X window