 <p>It looks like the <a href="http://standards.freedesktop.org/wm-spec/wm-spec-latest.html#id2550663" rel="nofollow">EWMH</a> properties <code>_NET_CURRENT_DESKTOP</code> and <code>_NET_DESKTOP_NAMES</code> are what you're looking for. With Xlib, you'd use the <a href="http://tronche.com/gui/x/xlib/window-information/XGetWindowProperty.html" rel="nofollow">XGetWindowProperty</a> function.</p>