Thursday, February 19, 2009

Got atoms?



This is a piece of useful code I forgot to save a while back so I had to take some time to research it again. It's for getting Xlib window property information. Change the XA_STRING to fit your needs based on the types in X11/Xatom.h.


Atom* atoms;
int num_prop_return = 0;
atoms = XListProperties(m_display, window, &num_prop_return);

for(int i = 0; i < num_prop_return; i++) {
Atom atom = *atoms;
QString name = XGetAtomName(m_display, atom);
atoms++;

Atom type;
int format;
long offset = 0;
long length = 8192;
unsigned long nitems, after;
unsigned char *data = 0;
XGetWindowProperty(m_display,
window,
atom,
offset,
length,
False,
XA_STRING,
&type,
&format,
&nitems,
&after,
&data);
qDebug() << name << QString::fromLatin1((const char*) data);
}

XFree(atoms);



References:
Xlib Properties and Atoms
qapplication_x11.cpp

0 comments: