]> git.sur5r.net Git - i3/i3/blobdiff - src/mainx.c
Initial implementation of IPC via UNIX domain sockets
[i3/i3] / src / mainx.c
index 6061fd8d325bb5aa0f176c15aa9a2370646d3f28..684526c653059886e8675dde406970d0069281fa 100644 (file)
@@ -45,6 +45,9 @@
 #include "xcb.h"
 #include "xinerama.h"
 #include "manage.h"
+#include "ipc.h"
+
+xcb_connection_t *global_conn;
 
 /* This is the path to i3, copied from argv[0] when starting up */
 char **start_argv;
@@ -69,6 +72,7 @@ struct stack_wins_head stack_wins = SLIST_HEAD_INITIALIZER(stack_wins);
 xcb_event_handlers_t evenths;
 xcb_atom_t atoms[NUM_ATOMS];
 
+xcb_window_t root;
 int num_screens = 0;
 
 /* The depth of the root screen (used e.g. for creating new pixmaps later) */
@@ -111,7 +115,6 @@ int main(int argc, char *argv[], char *env[]) {
         bool autostart = true;
         xcb_connection_t *conn;
         xcb_property_handlers_t prophs;
-        xcb_window_t root;
         xcb_intern_atom_cookie_t atom_cookies[NUM_ATOMS];
 
         setlocale(LC_ALL, "");
@@ -148,12 +151,12 @@ int main(int argc, char *argv[], char *env[]) {
         memset(&evenths, 0, sizeof(xcb_event_handlers_t));
         memset(&prophs, 0, sizeof(xcb_property_handlers_t));
 
-        conn = xcb_connect(NULL, &screens);
+        conn = global_conn = xcb_connect(NULL, &screens);
 
         if (xcb_connection_has_error(conn))
                 die("Cannot open display\n");
 
-        load_configuration(conn, override_configpath);
+        load_configuration(conn, override_configpath, false);
 
         /* 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);
@@ -330,21 +333,7 @@ int main(int argc, char *argv[], char *env[]) {
 
         xcb_get_numlock_mask(conn);
 
-        /* Grab the bound keys */
-        Binding *bind;
-        TAILQ_FOREACH(bind, &bindings, bindings) {
-                LOG("Grabbing %d\n", bind->keycode);
-                if (bind->mods & BIND_MODE_SWITCH)
-                        xcb_grab_key(conn, 0, root, 0, bind->keycode, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_SYNC);
-                else {
-                        /* Grab the key in all combinations */
-                        #define GRAB_KEY(modifier) xcb_grab_key(conn, 0, root, modifier, bind->keycode, \
-                                                                XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC)
-                        GRAB_KEY(bind->mods);
-                        GRAB_KEY(bind->mods | xcb_numlock_mask);
-                        GRAB_KEY(bind->mods | xcb_numlock_mask | XCB_MOD_MASK_LOCK);
-                }
-        }
+        grab_all_keys(conn);
 
         /* Autostarting exec-lines */
         struct Autostart *exec;
@@ -380,6 +369,16 @@ int main(int argc, char *argv[], char *env[]) {
                 c_ws = &workspaces[screen->current_workspace];
         }
 
+        /* Create the UNIX domain socket for IPC */
+        int ipc_socket = ipc_create_socket("/tmp/i3.s");
+        if (ipc_socket == -1) {
+                LOG("Could not create the IPC socket, IPC disabled\n");
+        } else {
+                struct ev_io *ipc_io = scalloc(sizeof(struct ev_io));
+                ev_io_init(ipc_io, ipc_new_client, ipc_socket, EV_READ);
+                ev_io_start(loop, ipc_io);
+        }
+
         /* Handle the events which arrived until now */
         xcb_check_cb(NULL, NULL, 0);