From 1fe80a5db8c2608faf1710ef555a54b1c97bd067 Mon Sep 17 00:00:00 2001 From: Nikos Tsipinakis Date: Fri, 11 May 2018 16:32:38 +0300 Subject: [PATCH] Refactor x event to use g_source_add_unix_fd According to the glib docs we should use g_source_add_unix_fd rather than g_source_add_poll. Additionally, this helps us with memory management since we don't have to handle the allocation of dpy_pollfd. --- src/x11/x.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/x11/x.c b/src/x11/x.c index c10574e..e6bd542 100644 --- a/src/x11/x.c +++ b/src/x11/x.c @@ -467,13 +467,6 @@ static void x_set_wm(Window win) GSource* x_win_reg_source(window_x11 *win) { - GPollFD *dpy_pollfd = g_malloc0(sizeof(dpy_pollfd)); - - *dpy_pollfd = (GPollFD) { - xctx.dpy->fd, - G_IO_IN | G_IO_HUP | G_IO_ERR, 0 - }; - // Static is necessary here because glib keeps the pointer and we need // to keep the reference alive. static GSourceFuncs xsrc_fn = { @@ -491,7 +484,7 @@ GSource* x_win_reg_source(window_x11 *win) xsrc->dpy = xctx.dpy; xsrc->w = win->xwin; - g_source_add_poll((GSource*) xsrc_fn, dpy_pollfd); + g_source_add_unix_fd((GSource*) xsrc, xctx.dpy->fd, G_IO_IN | G_IO_HUP | G_IO_ERR); g_source_attach((GSource*) xsrc, NULL);