int num_screens = 0;
/*
- * Callback for activity on the connection to the X server
+ * This callback is only a dummy, see xcb_prepare_cb and xcb_check_cb.
+ * See also man libev(3): "ev_prepare" and "ev_check" - customise your event loop
*
*/
static void xcb_got_event(EV_P_ struct ev_io *w, int revents) {
+ /* empty, because xcb_prepare_cb and xcb_check_cb are used */
+}
+
+/*
+ * Flush before blocking (and waiting for new events)
+ *
+ */
+static void xcb_prepare_cb(EV_P_ ev_prepare *w, int revents) {
+ xcb_flush(evenths.c);
+}
+
+/*
+ * Instead of polling the X connection socket we leave this to
+ * xcb_poll_for_event() which knows better than we can ever know.
+ *
+ */
+static void xcb_check_cb(EV_P_ ev_check *w, int revents) {
xcb_generic_event_t *event;
- /* When an event is available… */
while ((event = xcb_poll_for_event(evenths.c)) != NULL) {
- /* …we handle all events in a row: */
- do {
- xcb_event_handle(&evenths, event);
- xcb_aux_sync(evenths.c);
- free(event);
- } while ((event = xcb_poll_for_event(evenths.c)));
-
- /* Make sure all replies are handled/discarded */
- xcb_aux_sync(evenths.c);
-
- /* Afterwards, there may be new events available which would
- * not trigger the select() (libev) immediately, so we check
- * again (and don’t bail out of the loop). */
+ xcb_event_handle(&evenths, event);
+ free(event);
}
-
- /* Make sure all replies are handled/discarded */
- xcb_aux_sync(evenths.c);
}
int main(int argc, char *argv[], char *env[]) {
conn = xcb_connect(NULL, &screens);
+ if (xcb_connection_has_error(conn))
+ die("Cannot open display\n");
+
load_configuration(conn, override_configpath);
/* Place requests for the atoms we need as soon as possible */
REQUEST_ATOM(_NET_WM_WINDOW_TYPE);
REQUEST_ATOM(_NET_WM_DESKTOP);
REQUEST_ATOM(_NET_WM_WINDOW_TYPE_DOCK);
+ REQUEST_ATOM(_NET_WM_WINDOW_TYPE_DIALOG);
+ REQUEST_ATOM(_NET_WM_WINDOW_TYPE_UTILITY);
+ REQUEST_ATOM(_NET_WM_WINDOW_TYPE_TOOLBAR);
+ REQUEST_ATOM(_NET_WM_WINDOW_TYPE_SPLASH);
REQUEST_ATOM(_NET_WM_STRUT_PARTIAL);
REQUEST_ATOM(WM_PROTOCOLS);
REQUEST_ATOM(WM_DELETE_WINDOW);
}
/* end of ugliness */
+ /* Initialize event loop using libev */
+ struct ev_loop *loop = ev_default_loop(0);
+ if (loop == NULL)
+ die("Could not initialize libev. Bad LIBEV_FLAGS?\n");
+
+ struct ev_io *xcb_watcher = scalloc(sizeof(struct ev_io));
+ struct ev_check *xcb_check = scalloc(sizeof(struct ev_check));
+ struct ev_prepare *xcb_prepare = scalloc(sizeof(struct ev_prepare));
+
+ ev_io_init(xcb_watcher, xcb_got_event, xcb_get_file_descriptor(conn), EV_READ);
+ ev_io_start(loop, xcb_watcher);
+
+ ev_check_init(xcb_check, xcb_check_cb);
+ ev_check_start(loop, xcb_check);
+
+ ev_prepare_init(xcb_prepare, xcb_prepare_cb);
+ ev_prepare_start(loop, xcb_prepare);
+
+ /* Grab the server to delay any events until we enter the eventloop */
+ xcb_grab_server(conn);
+
xcb_event_handlers_init(conn, &evenths);
/* DEBUG: Trap all events and print them */
GET_ATOM(_NET_WM_WINDOW_TYPE);
GET_ATOM(_NET_WM_DESKTOP);
GET_ATOM(_NET_WM_WINDOW_TYPE_DOCK);
+ GET_ATOM(_NET_WM_WINDOW_TYPE_DIALOG);
+ GET_ATOM(_NET_WM_WINDOW_TYPE_UTILITY);
+ GET_ATOM(_NET_WM_WINDOW_TYPE_TOOLBAR);
+ GET_ATOM(_NET_WM_WINDOW_TYPE_SPLASH);
GET_ATOM(_NET_WM_STRUT_PARTIAL);
GET_ATOM(WM_PROTOCOLS);
GET_ATOM(WM_DELETE_WINDOW);
/* Watch _NET_WM_NAME (= title of the window in UTF-8) property */
xcb_property_set_handler(&prophs, atoms[_NET_WM_NAME], 128, handle_windowname_change, NULL);
+ /* Watch WM_TRANSIENT_FOR property (to which client this popup window belongs) */
+ xcb_property_set_handler(&prophs, WM_TRANSIENT_FOR, UINT_MAX, handle_transient_for, NULL);
+
/* Watch WM_NAME (= title of the window in compound text) property for legacy applications */
xcb_watch_wm_name(&prophs, 128, handle_windowname_change_legacy, NULL);
c_ws = &workspaces[screen->current_workspace];
}
+ /* Handle the events which arrived until now */
+ xcb_check_cb(NULL, NULL, 0);
- /* Initialize event loop using libev */
- struct ev_loop *loop = ev_default_loop(0);
- if (loop == NULL)
- die("Could not initialize libev. Bad LIBEV_FLAGS?\n");
-
- ev_io xcb_watcher;
- ev_io_init(&xcb_watcher, xcb_got_event, xcb_get_file_descriptor(conn), EV_READ);
-
- /* Call the handler to work all events which arrived before the libev-stuff was set up */
- xcb_got_event(NULL, &xcb_watcher, 0);
-
- /* Enter the libev eventloop */
- ev_io_start(loop, &xcb_watcher);
+ /* Ungrab the server to receive events and enter libev’s eventloop */
+ xcb_ungrab_server(conn);
ev_loop(loop, 0);
/* not reached */