use one array instead of two to hold both 'names' and 'atoms' for the rootwindow

This commit is contained in:
Mathias Gumz 2010-09-14 16:59:05 +02:00
parent f39bcbd93c
commit c6047e9eba

View file

@ -43,25 +43,22 @@ namespace {
Pixmap *root_pixmaps = 0; Pixmap *root_pixmaps = 0;
const char* root_prop_ids[] = { struct RootProps {
"_XROOTPMAP_ID", const char* name;
"_XSETROOT_ID", Atom atom;
0
}; };
// same number as in root_prop_ids struct RootProps root_props[] = {
Atom root_prop_atoms[] = { { "_XROOTPMAP_ID", None },
None, { "_XSETROOT_ID", None }
None,
None
}; };
void checkAtoms() { void checkAtoms() {
Display* display = FbTk::App::instance()->display(); Display* display = FbTk::App::instance()->display();
for (int i=0; root_prop_ids[i] != 0; ++i) { for (size_t i = 0; i < sizeof(root_props)/sizeof(RootProps); ++i) {
if (root_prop_atoms[i] == None) { if (root_props[i].atom == None) {
root_prop_atoms[i] = XInternAtom(display, root_prop_ids[i], False); root_props[i].atom = XInternAtom(display, root_props[i].name, False);
} }
} }
} }
@ -372,8 +369,8 @@ bool FbPixmap::rootwinPropertyNotify(int screen_num, Atom atom) {
return false; return false;
checkAtoms(); checkAtoms();
for (int i=0; root_prop_ids[i] != 0; ++i) { for (int i=0; i < sizeof(root_props)/sizeof(RootProps); ++i) {
if (root_prop_atoms[i] == atom) { if (root_props[i].atom == atom) {
Pixmap root_pm = None; Pixmap root_pm = None;
Atom real_type; Atom real_type;
int real_format; int real_format;
@ -382,7 +379,7 @@ bool FbPixmap::rootwinPropertyNotify(int screen_num, Atom atom) {
if (XGetWindowProperty(display(), if (XGetWindowProperty(display(),
RootWindow(display(), screen_num), RootWindow(display(), screen_num),
root_prop_atoms[i], root_props[i].atom,
0l, 1l, 0l, 1l,
False, XA_PIXMAP, False, XA_PIXMAP,
&real_type, &real_format, &real_type, &real_format,
@ -427,6 +424,8 @@ Pixmap FbPixmap::getRootPixmap(int screen_num, bool force_update) {
if (root_pixmaps && !force_update) if (root_pixmaps && !force_update)
return root_pixmaps[screen_num]; return root_pixmaps[screen_num];
checkAtoms();
// else setup pixmap cache // else setup pixmap cache
int numscreens = ScreenCount(display()); int numscreens = ScreenCount(display());
for (int i=0; i < numscreens; ++i) { for (int i=0; i < numscreens; ++i) {
@ -435,9 +434,22 @@ Pixmap FbPixmap::getRootPixmap(int screen_num, bool force_update) {
unsigned long items_read, items_left; unsigned long items_read, items_left;
unsigned long *data; unsigned long *data;
unsigned int prop = 0;
static bool print_error = true; // print error_message only once static bool print_error = true; // print error_message only once
Pixmap root_pm = None;
unsigned int prop = 0;
for (prop = 0; prop < sizeof(root_props)/sizeof(RootProps); ++prop) {
if (XGetWindowProperty(display(),
RootWindow(display(), i),
root_props[prop].atom,
0l, 1l,
False, XA_PIXMAP,
&real_type, &real_format,
&items_read, &items_left,
(unsigned char **) &data) == Success) {
if (real_format == 32 && items_read == 1) {
if (print_error && strcmp(root_props[prop].name, "_XSETROOT_ID") == 0) {
static const char* error_message = { static const char* error_message = {
"\n\n !!! WARNING WARNING WARNING WARNING !!!!!\n" "\n\n !!! WARNING WARNING WARNING WARNING !!!!!\n"
" if you experience problems with transparency:\n" " if you experience problems with transparency:\n"
@ -447,20 +459,6 @@ Pixmap FbPixmap::getRootPixmap(int screen_num, bool force_update) {
" that uses _XROOTPMAP_ID !\n" " that uses _XROOTPMAP_ID !\n"
" !!! WARNING WARNING WARNING WARNING !!!!!!\n\n" " !!! WARNING WARNING WARNING WARNING !!!!!!\n\n"
}; };
Pixmap root_pm = None;
for (prop = 0; root_prop_ids[prop]; prop++) {
checkAtoms();
if (XGetWindowProperty(display(),
RootWindow(display(), i),
root_prop_atoms[prop],
0l, 1l,
False, XA_PIXMAP,
&real_type, &real_format,
&items_read, &items_left,
(unsigned char **) &data) == Success) {
if (real_format == 32 && items_read == 1) {
if (print_error && strcmp(root_prop_ids[prop], "_XSETROOT_ID") == 0) {
cerr<<error_message; cerr<<error_message;
print_error = false; print_error = false;
} else } else
@ -507,3 +505,4 @@ void FbPixmap::create(Drawable src,
} }
} // end namespace FbTk } // end namespace FbTk