summaryrefslogtreecommitdiff
path: root/src/FbTk/FbPixmap.cc
diff options
context:
space:
mode:
authorsimonb <simonb>2005-05-10 16:29:00 (GMT)
committersimonb <simonb>2005-05-10 16:29:00 (GMT)
commit5fec1906cc4faf83ec2424aa48c2a050b0254d15 (patch)
treecc65550334da8a019887fba4c0000d0422420a03 /src/FbTk/FbPixmap.cc
parentc6c7788405b8f6f5990e4ff9a69123d13b1487f4 (diff)
downloadfluxbox_lack-5fec1906cc4faf83ec2424aa48c2a050b0254d15.zip
fluxbox_lack-5fec1906cc4faf83ec2424aa48c2a050b0254d15.tar.bz2
cache the root pixmap (per screen)
Diffstat (limited to 'src/FbTk/FbPixmap.cc')
-rw-r--r--src/FbTk/FbPixmap.cc141
1 files changed, 106 insertions, 35 deletions
diff --git a/src/FbTk/FbPixmap.cc b/src/FbTk/FbPixmap.cc
index b2937c3..ce28f0e 100644
--- a/src/FbTk/FbPixmap.cc
+++ b/src/FbTk/FbPixmap.cc
@@ -24,6 +24,7 @@
24#include "FbPixmap.hh" 24#include "FbPixmap.hh"
25#include "App.hh" 25#include "App.hh"
26#include "GContext.hh" 26#include "GContext.hh"
27#include "Transparent.hh"
27 28
28#include <X11/Xutil.h> 29#include <X11/Xutil.h>
29#include <X11/Xatom.h> 30#include <X11/Xatom.h>
@@ -34,6 +35,22 @@ using namespace std;
34 35
35namespace FbTk { 36namespace FbTk {
36 37
38Pixmap *FbPixmap::m_root_pixmaps = 0;
39
40const char* FbPixmap::root_prop_ids[] = {
41 "_XROOTPMAP_ID",
42 "_XSETROOT_ID",
43 0
44};
45
46// same number as in root_prop_ids
47Atom FbPixmap::root_prop_atoms[] = {
48 None,
49 None,
50 None
51};
52
53
37FbPixmap::FbPixmap():m_pm(0), 54FbPixmap::FbPixmap():m_pm(0),
38 m_width(0), m_height(0), 55 m_width(0), m_height(0),
39 m_depth(0) { 56 m_depth(0) {
@@ -297,53 +314,107 @@ Pixmap FbPixmap::release() {
297 return ret; 314 return ret;
298} 315}
299 316
317void FbPixmap::rootwinPropertyNotify(int screen_num, Atom atom) {
318 if (!FbTk::Transparent::haveRender())
319 return;
320
321 checkAtoms();
322 for (int i=0; root_prop_ids[i] != 0; ++i) {
323 if (root_prop_atoms[i] == atom) {
324 Pixmap root_pm = None;
325 Atom real_type;
326 int real_format;
327 unsigned long items_read, items_left;
328 unsigned long *data;
329
330 unsigned int prop = 0;
331 if (XGetWindowProperty(display(),
332 RootWindow(display(), i),
333 root_prop_atoms[i],
334 0l, 1l,
335 False, XA_PIXMAP,
336 &real_type, &real_format,
337 &items_read, &items_left,
338 (unsigned char **) &data) == Success) {
339 if (real_format == 32 && items_read == 1) {
340 root_pm = (Pixmap) (*data);
341 }
342 XFree(data);
343 if (root_pm != None)
344 setRootPixmap(screen_num, root_pm);
345 }
346 break;
347 }
348 }
349}
350
351void FbPixmap::setRootPixmap(int screen_num, Pixmap pm) {
352 if (!m_root_pixmaps) {
353 m_root_pixmaps = new Pixmap[ScreenCount(display())];
354 }
355
356 m_root_pixmaps[screen_num] = pm;
357}
358
300Pixmap FbPixmap::getRootPixmap(int screen_num) { 359Pixmap FbPixmap::getRootPixmap(int screen_num) {
360 if (!FbTk::Transparent::haveRender())
361 return None;
362
363 if (!m_root_pixmaps) {
364 int numscreens = ScreenCount(display());
365 for (int i=0; i < numscreens; ++i) {
366 Atom real_type;
367 int real_format;
368 unsigned long items_read, items_left;
369 unsigned long *data;
301 370
302 Atom real_type; 371 unsigned int prop = 0;
303 int real_format; 372
304 unsigned long items_read, items_left; 373 static bool print_error = true; // print error_message only once
305 unsigned long *data; 374 static const char* error_message = { "\n\n !!! WARNING WARNING WARNING WARNING !!!!!\n"
306
307 unsigned int prop = 0;
308 static const char* prop_ids[] = {
309 "_XROOTPMAP_ID",
310 "_XSETROOT_ID",
311 0
312 };
313 static bool print_error = true; // print error_message only once
314 static const char* error_message = { "\n\n !!! WARNING WARNING WARNING WARNING !!!!!\n"
315 " if you experience problems with transparency:\n" 375 " if you experience problems with transparency:\n"
316 " you are using a wallpapersetter that \n" 376 " you are using a wallpapersetter that \n"
317 " uses _XSETROOT_ID .. which we do not support.\n" 377 " uses _XSETROOT_ID .. which we do not support.\n"
318 " consult 'fbsetbg -i' or try any other wallpapersetter\n" 378 " consult 'fbsetbg -i' or try any other wallpapersetter\n"
319 " that uses _XROOTPMAP_ID !\n" 379 " that uses _XROOTPMAP_ID !\n"
320 " !!! WARNING WARNING WARNING WARNING !!!!!!\n\n" 380 " !!! WARNING WARNING WARNING WARNING !!!!!!\n\n"
321 }; 381 };
322 382
323 Pixmap root_pm = None; 383 Pixmap root_pm = None;
324 for (prop = 0; prop_ids[prop]; prop++) { 384 for (prop = 0; root_prop_ids[prop]; prop++) {
325 if (XGetWindowProperty(display(), 385 checkAtoms();
326 RootWindow(display(), screen_num), 386 if (XGetWindowProperty(display(),
327 XInternAtom(display(), prop_ids[prop], False), 387 RootWindow(display(), i),
328 0l, 1l, 388 root_prop_atoms[i],
329 False, XA_PIXMAP, 389 0l, 1l,
330 &real_type, &real_format, 390 False, XA_PIXMAP,
331 &items_read, &items_left, 391 &real_type, &real_format,
332 (unsigned char **) &data) == Success) { 392 &items_read, &items_left,
333 if (real_format == 32 && items_read == 1) { 393 (unsigned char **) &data) == Success) {
334 if (print_error && strcmp(prop_ids[prop], "_XSETROOT_ID") == 0) { 394 if (real_format == 32 && items_read == 1) {
335 cerr<<error_message; 395 if (print_error && strcmp(root_prop_ids[prop], "_XSETROOT_ID") == 0) {
336 print_error = false; 396 cerr<<error_message;
337 } else 397 print_error = false;
338 root_pm = (Pixmap) (*data); 398 } else
399 root_pm = (Pixmap) (*data);
400 }
401 XFree(data);
402 if (root_pm != None)
403 break;
404 }
339 } 405 }
340 XFree(data); 406 setRootPixmap(i, root_pm);
341 if (root_pm != None)
342 break;
343 } 407 }
344 } 408 }
409 return m_root_pixmaps[screen_num];
410}
345 411
346 return root_pm; 412void FbPixmap::checkAtoms() {
413 for (int i=0; root_prop_ids[i] != 0; ++i) {
414 if (root_prop_atoms[i] == None) {
415 root_prop_atoms[i] = XInternAtom(display(), root_prop_ids[i], False);
416 }
417 }
347} 418}
348 419
349void FbPixmap::free() { 420void FbPixmap::free() {