Receving events on the root window



How does one set up to receive events on the root window in gtk+ 2.0?

I need this to write a small window manager.

The code I have written but that works partially is as follows:

<< code start >>

GdkFilterReturn event_hdlr(GdkXEvent *xev, GdkEvent *event,
                                               gpointer cb_data)
{
        printf("%d\n", ((XEvent *)xev)->type);

        return GDK_FILTER_CONTINUE;
}

int
err_hdlr (Display *d, XErrorEvent *e)
{
        printf("%p\n", e);

        return 0;
}


int
main(int argc, char *argv[])
{
        gtk_init(&argc, &argv);

        XSetErrorHandler(err_hdlr);

        XSelectInput (GDK_DISPLAY (), GDK_ROOT_WINDOW (), ButtonPressMask
|
KeyPressMask);

        gdk_window_add_filter(NULL, event_hdlr, NULL);

        gdk_flush();

        gdk_window_set_cursor(gdk_get_default_root_window(),
gdk_cursor_new(GDK_LEFT_PTR));

        gtk_main();

        return 0;
}

<< code end >>

I always get a event-type of -1.

Thanks.

-Ram




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]