X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=obt%2Fxqueue.c;h=c04b226b55ca1f9bcf2efca3e618a07226a63420;hb=4e6c0086a657399d989f2e4849f7b397d7d4efbc;hp=22a3de23578be77b060fd2b7019fec4b8fc6c9e9;hpb=fd77a0a7b3f892925f203287b8b46c6ec9be94ea;p=chaz%2Fopenbox diff --git a/obt/xqueue.c b/obt/xqueue.c index 22a3de23..c04b226b 100644 --- a/obt/xqueue.c +++ b/obt/xqueue.c @@ -327,7 +327,8 @@ typedef struct _ObtXQueueCB { static ObtXQueueCB *callbacks = NULL; static guint n_callbacks = 0; -static gboolean event_read(GIOChannel *s, GIOCondition cond, gpointer data) +static gboolean event_read(GSource *source, GSourceFunc callback, + gpointer data) { XEvent ev; @@ -340,15 +341,39 @@ static gboolean event_read(GIOChannel *s, GIOCondition cond, gpointer data) return TRUE; /* repeat */ } -void xqueue_listen(void) +static gboolean x_source_prepare(GSource *source, gint *timeout) { - GIOChannel *ch; + *timeout = -1; + return XPending(obt_display); +} + +static gboolean x_source_check(GSource *source) +{ + return XPending(obt_display); +} - g_assert(obt_display != NULL); +struct x_source { + GSource source; + + GPollFD pfd; +}; + +static GSourceFuncs x_source_funcs = { + x_source_prepare, + x_source_check, + event_read, + NULL +}; + +void xqueue_listen(void) +{ + GSource *source = g_source_new(&x_source_funcs, sizeof(struct x_source)); + struct x_source *x_source = (struct x_source *)source; + GPollFD *pfd = &x_source->pfd; - ch = g_io_channel_unix_new(ConnectionNumber(obt_display)); - g_io_add_watch(ch, G_IO_IN, event_read, NULL); - g_io_channel_unref(ch); + *pfd = (GPollFD){ ConnectionNumber(obt_display), G_IO_IN, G_IO_IN }; + g_source_add_poll(source, pfd); + g_source_attach(source, NULL); } void xqueue_add_callback(ObtXQueueFunc f, gpointer data)