#include #include #include #include #include #include #include #include #define G_MAXLONG LONG_MAX typedef unsigned long gulong; bool get_cardinal_list(Screen *screen, Window xwindow, Atom atom, gulong **cardinals, int *len) { Display *display; Atom type; int format; gulong nitems; gulong bytes_after; gulong *nums; int err, result; display = DisplayOfScreen (screen); *cardinals = NULL; *len = 0; type = None; result = XGetWindowProperty (display, xwindow, atom, 0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems, &bytes_after, (void*)&nums); if (type != XA_CARDINAL) { XFree (nums); return false; } *cardinals = malloc(sizeof(gulong) * nitems); // Need to deallocate! memcpy (*cardinals, nums, sizeof (gulong) * nitems); *len = nitems; XFree (nums); return true; } void write_coords(gulong *p_coord, int n_coord) { if (p_coord != NULL) { int i; for (i = 0; i < n_coord; ++i) printf(" %lu", (unsigned long)p_coord[i]); printf("\n"); } else { printf("NULL\n"); } } Atom get_atom(Display *display, const char *atom_name) { const bool only_if_exists = true; return XInternAtom(display, atom_name, only_if_exists); } void print_atom(Display *display, const char *atom_name) { int screen_number = 0; Window xroot = RootWindow(display, screen_number); Screen *xscreen = ScreenOfDisplay(display, screen_number); assert(xscreen); gulong *p_coord = NULL; int n_coord = 0; get_cardinal_list(xscreen, xroot, get_atom(display, atom_name), &p_coord, &n_coord); printf(atom_name); write_coords(p_coord, n_coord); if (p_coord != NULL) free(p_coord); } int main(int argc, char** argv) { Display *display = XOpenDisplay(":0.0"); assert(display); print_atom(display, "_NET_DESKTOP_GEOMETRY"); print_atom(display, "_NET_DESKTOP_VIEWPORT"); int res = XCloseDisplay(display); printf("XCloseDisplay returned %d\n", res); return res; }