#include <xcb/xcb_icccm.h>
#include <xcb/xinerama.h>
+#include <ev.h>
+
#include "config.h"
#include "data.h"
#include "debug.h"
int num_screens = 0;
+/*
+ * 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;
+
+ while ((event = xcb_poll_for_event(evenths.c)) != NULL) {
+ xcb_event_handle(&evenths, event);
+ free(event);
+ }
+}
+
int main(int argc, char *argv[], char *env[]) {
int i, screens, opt;
char *override_configpath = NULL;
memset(&evenths, 0, sizeof(xcb_event_handlers_t));
memset(&prophs, 0, sizeof(xcb_property_handlers_t));
- load_configuration(override_configpath);
-
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 */
#define REQUEST_ATOM(name) atom_cookies[name] = xcb_intern_atom(conn, 0, strlen(#name), #name);
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];
}
- /* Enter xcb’s event handler */
- xcb_event_wait_for_event_loop(&evenths);
+ /* Handle the events which arrived until now */
+ xcb_check_cb(NULL, NULL, 0);
+
+ /* Ungrab the server to receive events and enter libev’s eventloop */
+ xcb_ungrab_server(conn);
+ ev_loop(loop, 0);
/* not reached */
return 0;