X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=obt%2Fmainloop.c;h=753662569013c66d14bd95e58c19340b9646f05e;hb=d9d65b73853d485852f6d6bf6808af0ebb6a90f5;hp=bf866aec5e250deda309cecd2bd8b371a763e583;hpb=31f0c8c1ad8c9acf369ab8336765f4bf673b8e21;p=chaz%2Fopenbox diff --git a/obt/mainloop.c b/obt/mainloop.c index bf866aec..75366256 100644 --- a/obt/mainloop.c +++ b/obt/mainloop.c @@ -19,6 +19,7 @@ #include "obt/mainloop.h" #include "obt/display.h" +#include "obt/xqueue.h" #include "obt/util.h" #ifdef HAVE_STDIO_H @@ -155,7 +156,7 @@ ObtMainLoop *obt_main_loop_new(void) { ObtMainLoop *loop; - loop = g_new0(ObtMainLoop, 1); + loop = g_slice_new0(ObtMainLoop); loop->ref = 1; FD_ZERO(&loop->fd_set); loop->fd_x = -1; @@ -223,7 +224,7 @@ void obt_main_loop_unref(ObtMainLoop *loop) for (it = loop->timers; it; it = g_slist_next(it)) { ObtMainLoopTimer *t = it->data; if (t->destroy) t->destroy(t->data); - g_free(t); + g_slice_free(ObtMainLoopTimer, t); } g_slist_free(loop->timers); loop->timers = NULL; @@ -249,7 +250,7 @@ void obt_main_loop_unref(ObtMainLoop *loop) } } - obt_free0(loop, ObtMainLoop, 1); + g_slice_free(ObtMainLoop, loop); } } @@ -296,18 +297,18 @@ void obt_main_loop_run(ObtMainLoop *loop) loop->signal_fired = FALSE; sigprocmask(SIG_SETMASK, &oldset, NULL); - } else if (loop->display && XPending(loop->display)) { - do { - XNextEvent(loop->display, &e); + } else if (loop->display && xqueue_pending_local()) { + while (xqueue_next_local(&e) && loop->run) { + if (e.type == MappingNotify) + XRefreshKeyboardMapping(&e.xmapping); for (it = loop->x_handlers; it; it = g_slist_next(it)) { ObtMainLoopXHandlerType *h = it->data; h->func(&e, h->data); } - } while (XPending(loop->display) && loop->run); + } } else { /* this only runs if there were no x events received */ - timer_dispatch(loop, (GTimeVal**)&wait); selset = loop->fd_set; @@ -345,7 +346,7 @@ void obt_main_loop_x_add(ObtMainLoop *loop, { ObtMainLoopXHandlerType *h; - h = g_new(ObtMainLoopXHandlerType, 1); + h = g_slice_new(ObtMainLoopXHandlerType); h->loop = loop; h->func = handler; h->data = data; @@ -374,7 +375,7 @@ void obt_main_loop_x_remove(ObtMainLoop *loop, if (h->func == handler) { loop->x_handlers = g_slist_delete_link(loop->x_handlers, it); if (h->destroy) h->destroy(h->data); - g_free(h); + g_slice_free(ObtMainLoopXHandlerType, h); } } @@ -422,7 +423,7 @@ void obt_main_loop_signal_add(ObtMainLoop *loop, g_return_if_fail(signal < NUM_SIGNALS); - h = g_new(ObtMainLoopSignalHandlerType, 1); + h = g_slice_new(ObtMainLoopSignalHandlerType); h->loop = loop; h->signal = signal; h->func = handler; @@ -470,7 +471,7 @@ void obt_main_loop_signal_remove(ObtMainLoop *loop, g_slist_delete_link(loop->signal_handlers[i], it); if (h->destroy) h->destroy(h->data); - g_free(h); + g_slice_free(ObtMainLoopSignalHandlerType, h); } } } @@ -502,7 +503,7 @@ void obt_main_loop_fd_add(ObtMainLoop *loop, { ObtMainLoopFdHandlerType *h; - h = g_new(ObtMainLoopFdHandlerType, 1); + h = g_slice_new(ObtMainLoopFdHandlerType); h->loop = loop; h->fd = fd; h->func = handler; @@ -522,6 +523,7 @@ static void fd_handler_destroy(gpointer data) if (h->destroy) h->destroy(h->data); + g_slice_free(ObtMainLoopFdHandlerType, h); } void obt_main_loop_fd_remove(ObtMainLoop *loop, @@ -564,7 +566,7 @@ void obt_main_loop_timeout_add(ObtMainLoop *loop, GEqualFunc cmp, GDestroyNotify notify) { - ObtMainLoopTimer *t = g_new(ObtMainLoopTimer, 1); + ObtMainLoopTimer *t = g_slice_new(ObtMainLoopTimer); g_assert(microseconds > 0); /* if it's 0 it'll cause an infinite loop */ @@ -652,7 +654,7 @@ static void timer_dispatch(ObtMainLoop *loop, GTimeVal **wait) loop->timers = g_slist_delete_link(loop->timers, it); if (curr->destroy) curr->destroy(curr->data); - g_free(curr); + g_slice_free(ObtMainLoopTimer, curr); continue; } @@ -673,7 +675,7 @@ static void timer_dispatch(ObtMainLoop *loop, GTimeVal **wait) } else { if (curr->destroy) curr->destroy(curr->data); - g_free(curr); + g_slice_free(ObtMainLoopTimer, curr); } /* the timer queue has been shuffled, start from the beginning