Minimal XGetWindowProperty Example

You can easily see the X11 properties using the xprop command, usually like xprop -root.

However, you might have some reason to directly query X11 properties from a user program. Here is an absolute minimal example of how to do this.

#include <stdio.h>
#include <X11/Xlib.h>

Display  *display;
Atom     actual_type;
int      actual_format;
long     nitems;
long     bytes;
long     *data;
int      status;

int main(void)

        int i;

        display = XOpenDisplay(0);
        if (!display) {
                printf("can't open display");

        status = XGetWindowProperty(
                RootWindow(display, 0),
                XInternAtom(display, "_NET_WORKAREA", True), //replace this with your property
        if (status != Success) {
                fprintf(stderr, "status = %d\n", status);

        printf("actual_type %d\n", actual_type);
        printf("actual_format %d\n", actual_format);
        printf("nitems %d\n", nitems);
        printf("bytes %d\n", bytes);
        for (i=0; i < nitems; i++){
                printf("data[%d] %d\n", i, data[i]);


Build it like this

ianw@lime:~$ gcc -o testx testx.c -L /usr/X11R6/lib -lX11

IA64wiki: XGetWindowProperty (last edited 2009-12-10 03:13:50 by localhost)

Gelato@UNSW is sponsored by
the University of New South Wales National ICT Australia The Gelato Federation Hewlett-Packard Company Australian Research Council
Please contact us with any questions or comments.