#include <fcntl.h>
#include "all.h"
+#include "sd-daemon.h"
+
static int xkb_event_base;
int xkb_current_group;
DLOG("Done\n");
}
+/*
+ * Exit handler which destroys the main_loop. Will trigger cleanup handlers.
+ *
+ */
+static void i3_exit() {
+ ev_loop_destroy(main_loop);
+}
+
int main(int argc, char *argv[]) {
//parse_cmd("[ foo ] attach, attach ; focus");
int screens;
free(greply);
- if (force_xinerama) {
+ /* Force Xinerama (for drivers which don't support RandR yet, esp. the
+ * nVidia binary graphics driver), when specified either in the config
+ * file or on command-line */
+ if (force_xinerama || config.force_xinerama) {
xinerama_init();
} else {
DLOG("Checking for XRandR...\n");
ev_io_start(main_loop, ipc_io);
}
+ /* Also handle the UNIX domain sockets passed via socket activation */
+ int fds = sd_listen_fds(1);
+ if (fds < 0)
+ ELOG("socket activation: Error in sd_listen_fds\n");
+ else if (fds == 0)
+ DLOG("socket activation: no sockets passed\n");
+ else {
+ for (int fd = SD_LISTEN_FDS_START; fd < (SD_LISTEN_FDS_START + fds); fd++) {
+ DLOG("socket activation: also listening on fd %d\n", fd);
+ struct ev_io *ipc_io = scalloc(sizeof(struct ev_io));
+ ev_io_init(ipc_io, ipc_new_client, fd, EV_READ);
+ ev_io_start(main_loop, ipc_io);
+ }
+ }
+
/* Set up i3 specific atoms like I3_SOCKET_PATH and I3_CONFIG_PATH */
x_set_i3_atoms();
start_application(exec_always->command);
}
+ /* Make sure to destroy the event loop to invoke the cleeanup callbacks
+ * when calling exit() */
+ atexit(i3_exit);
+
ev_loop(main_loop, 0);
}