diff --git a/awesome.c b/awesome.c index eb48d5615..8f530bf1a 100644 --- a/awesome.c +++ b/awesome.c @@ -34,6 +34,8 @@ #include #include +#include + #include #include #include @@ -61,6 +63,12 @@ bool running = true; AwesomeConf globalconf; +#define a_thread_refresh(id, fct) \ + do { \ + if(pthread_create(id, NULL, fct, NULL)) \ + perror("error creating thread\n"); \ + } while(0) + typedef struct { xcb_window_t id; @@ -284,6 +292,7 @@ main(int argc, char **argv) xcb_generic_event_t *ev; struct sockaddr_un *addr; client_t *c; + pthread_t tid_layout, tid_statusbar; static struct option long_options[] = { {"help", 0, NULL, 'h'}, @@ -504,38 +513,40 @@ main(int argc, char **argv) break; buf[r] = '\0'; luaA_docmd(buf); - statusbar_refresh(NULL); - layout_refresh(NULL); } if(dbusfd >= 0 && FD_ISSET(dbusfd, &rd)) a_dbus_process_requests(&dbusfd); - /* two level XPending: - * we need to first check we have XEvent to handle + /* Two level polling: + * We need to first check we have an event to handle * and if so, we handle them all in a round. * Then when we have refresh()'ed stuff so maybe new XEvent * are available and select() won't tell us, so let's check - * with XPending() again. + * with xcb_poll_for_event() again. */ while((ev = xcb_poll_for_event(globalconf.connection))) { do { xcb_handle_event(globalconf.evenths, ev); - /* need to resync */ xcb_aux_sync(globalconf.connection); - p_delete(&ev); } while((ev = xcb_poll_for_event(globalconf.connection))); - statusbar_refresh(NULL); - layout_refresh(NULL); + a_thread_refresh(&tid_statusbar, &statusbar_refresh); + a_thread_refresh(&tid_layout, &layout_refresh); + pthread_join(tid_statusbar, NULL); + pthread_join(tid_layout, NULL); /* need to resync */ xcb_aux_sync(globalconf.connection); } + a_thread_refresh(&tid_statusbar, &statusbar_refresh); + a_thread_refresh(&tid_layout, &layout_refresh); + pthread_join(tid_statusbar, NULL); + pthread_join(tid_layout, NULL); xcb_aux_sync(globalconf.connection); }