static void glibPrepare (CompDisplay *display, GMainContext *context) { int nFds = 0; int timeout = -1; int i; GLIB_DISPLAY (display); g_main_context_prepare (context, &gd->maxPriority); do { if (nFds > gd->fdsSize) { if (gd->fds) free (gd->fds); gd->fds = malloc ((sizeof (GPollFD) + sizeof (GLibWatch)) * nFds); if (!gd->fds) { nFds = 0; break; } gd->watch = (GLibWatch *) (gd->fds + nFds); gd->fdsSize = nFds; } nFds = g_main_context_query (context, gd->maxPriority, &timeout, gd->fds, gd->fdsSize); } while (nFds > gd->fdsSize); if (timeout < 0) timeout = INT_MAX; for (i = 0; i < nFds; i++) { gd->watch[i].display = display; gd->watch[i].index = i; gd->watch[i].handle = compAddWatchFd (gd->fds[i].fd, gd->fds[i].events, glibCollectEvents, &gd->watch[i]); } gd->nFds = nFds; gd->timeoutHandle = compAddTimeout (timeout, timeout, glibDispatchAndPrepare, display); }
static void glibWakeup (CompDisplay *display) { GLIB_DISPLAY (display); if (gd->timeoutHandle) { compRemoveTimeout (gd->timeoutHandle); compAddTimeout (0, 0, glibDispatchAndPrepare, (void *) display); gd->timeoutHandle = 0; } }
static Bool glibDispatchAndPrepare (void *closure) { CompDisplay *display = (CompDisplay *) closure; GLIB_DISPLAY (display); GMainContext *context = g_main_context_default (); glibDispatch (display, context); glibPrepare (display, context); gd->wakeupTimeoutHandle = 0; return FALSE; }
static void glibDispatch (CompDisplay *display, GMainContext *context) { int i; GLIB_DISPLAY (display); g_main_context_check (context, gd->maxPriority, gd->fds, gd->nFds); g_main_context_dispatch (context); for (i = 0; i < gd->nFds; i++) compRemoveWatchFd (gd->watch[i].handle); }
static Bool glibCollectEvents (void *closure) { GLibWatch *watch = (GLibWatch *) closure; CompDisplay *display = watch->display; GLIB_DISPLAY (display); gd->fds[watch->index].revents |= compWatchFdEvents (watch->handle); glibWakeup (display); return TRUE; }
static void glibHandleEvent (CompDisplay *d, XEvent *event) { GLIB_DISPLAY (d); if (event->type == ClientMessage) { if (event->xclient.message_type == gd->notifyAtom) glibWakeup (d); } UNWRAP (gd, d, handleEvent); (*d->handleEvent) (d, event); WRAP (gd, d, handleEvent, glibHandleEvent); }
static void glibFiniDisplay (CompPlugin *p, CompDisplay *d) { GLIB_DISPLAY (d); if (gd->timeoutHandle) compRemoveTimeout (gd->timeoutHandle); glibDispatch (d, g_main_context_default ()); UNWRAP (gd, d, handleEvent); if (gd->fds) free (gd->fds); free (gd); }