/* Compile with
 *
    gcc -g -O2 -Wall -o take-focus take-focus.c `pkg-config --cflags --libs x11`

 * WM_PROTOCOLS WM_TAKE_FOCUS, WM_HINTS not set,
 * is supposed to get focus, but doesn't.
 *
 * https://bugzilla.gnome.org/show_bug.cgi?id=601228
 */

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

static void
print_events(Display *display)
{
}

int main (int argc, char **argv)
{
    Display *display = XOpenDisplay(NULL);
    Window toplevel, child;
    Screen *screen = DefaultScreenOfDisplay(display);
    unsigned long blackpixel = BlackPixelOfScreen(screen);
    unsigned long whitepixel = WhitePixelOfScreen(screen);
    Atom wm_take_focus = XInternAtom(display, "WM_TAKE_FOCUS", False);
    Atom wm_protocols = XInternAtom(display, "WM_PROTOCOLS", False);

    toplevel = XCreateSimpleWindow(display, DefaultRootWindow(display),
				   0, 0, 200, 200, 0,
				   blackpixel, blackpixel);

    XChangeProperty(display, toplevel, wm_protocols, XA_ATOM, 32, PropModeReplace,
		    (unsigned char *)&wm_take_focus, 1);

    XMapWindow(display, toplevel);

    while (True) {
	XEvent xev;
	XNextEvent(display, &xev);
    }

    return 0;
}
