From 10186a7a29f75e6a450e3137e6a71b5aa48a495d Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 10 Apr 2011 14:28:34 +0200 Subject: [PATCH] "Handle" events during startup (FS#877) awesome.c contains this comment: There can be no events yet, so if his function returns something, it must be an error. Sadly, this wasn't true. It seems like something managed to generate MappingNotify events (no idea how). Fix this by discarding all pending events after our GrabServer, but before we ask for SubstructureRedirect on the root window. Signed-off-by: Uli Schlachter --- awesome.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/awesome.c b/awesome.c index f2beadee..9327808a 100644 --- a/awesome.c +++ b/awesome.c @@ -320,6 +320,7 @@ main(int argc, char **argv) ssize_t cmdlen = 1; xdgHandle xdg; bool no_argb = false; + xcb_generic_event_t *event; static struct option long_options[] = { { "help", 0, NULL, 'h' }, @@ -446,10 +447,6 @@ main(int argc, char **argv) /* initialize dbus */ a_dbus_init(); - /* Grab server */ - xcb_grab_server(globalconf.connection); - xcb_flush(globalconf.connection); - /* Get the file descriptor corresponding to the X connection */ xfd = xcb_get_file_descriptor(globalconf.connection); ev_io_init(&xio, &a_xcb_io_cb, xfd, EV_READ); @@ -461,6 +458,22 @@ main(int argc, char **argv) ev_prepare_start(globalconf.loop, &a_refresh); ev_unref(globalconf.loop); + /* Grab server */ + xcb_grab_server(globalconf.connection); + + /* Make sure there are no pending events. Since we didn't really do anything + * at all yet, we will just discard all events which we received so far. + * The above GrabServer should make sure no new events are generated. */ + xcb_aux_sync(globalconf.connection); + while ((event = xcb_poll_for_event(globalconf.connection)) != NULL) + { + /* Make sure errors are printed */ + uint8_t response_type = XCB_EVENT_RESPONSE_TYPE(event); + if(response_type == 0) + event_handle(event); + p_delete(&event); + } + { const uint32_t select_input_val = XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT;