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.
This commit is contained in:
Nikos Tsipinakis 2018-05-11 16:32:38 +03:00
parent adc075bf2c
commit 1fe80a5db8

View File

@ -467,13 +467,6 @@ static void x_set_wm(Window win)
GSource* x_win_reg_source(window_x11 *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 // Static is necessary here because glib keeps the pointer and we need
// to keep the reference alive. // to keep the reference alive.
static GSourceFuncs xsrc_fn = { static GSourceFuncs xsrc_fn = {
@ -491,7 +484,7 @@ GSource* x_win_reg_source(window_x11 *win)
xsrc->dpy = xctx.dpy; xsrc->dpy = xctx.dpy;
xsrc->w = win->xwin; 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); g_source_attach((GSource*) xsrc, NULL);