]> git.sur5r.net Git - i3/i3/blobdiff - src/main.c
Bugfix: Correctly set the _NET_CLIENT_LIST_STACKING hint (fixes chromium tabbar)
[i3/i3] / src / main.c
index 16df027bcc4690df0043af1b0becff16866df30d..5306774462f3a302ae07e6fd9b10d27ecfd96131 100644 (file)
@@ -16,9 +16,12 @@ char **start_argv;
 
 xcb_connection_t *conn;
 
+xcb_screen_t *root_screen;
 xcb_window_t root;
 uint8_t root_depth;
 
+struct ev_loop *main_loop;
+
 xcb_key_symbols_t *keysyms;
 
 /* Those are our connections to X11 for use with libXcursor and XKB */
@@ -30,9 +33,16 @@ struct bindings_head *bindings;
 /* The list of exec-lines */
 struct autostarts_head autostarts = TAILQ_HEAD_INITIALIZER(autostarts);
 
+/* The list of exec_always lines */
+struct autostarts_always_head autostarts_always = TAILQ_HEAD_INITIALIZER(autostarts_always);
+
 /* The list of assignments */
 struct assignments_head assignments = TAILQ_HEAD_INITIALIZER(assignments);
 
+/* The list of workspace assignments (which workspace should end up on which
+ * output) */
+struct ws_assignments_head ws_assignments = TAILQ_HEAD_INITIALIZER(ws_assignments);
+
 /* We hope that those are supported and set them to true */
 bool xcursor_supported = true;
 bool xkb_supported = true;
@@ -64,7 +74,14 @@ static void xcb_check_cb(EV_P_ ev_check *w, int revents) {
 
     while ((event = xcb_poll_for_event(conn)) != NULL) {
         if (event->response_type == 0) {
-            ELOG("X11 Error received! sequence %x\n", event->sequence);
+            if (event_is_ignored(event->sequence, 0))
+                DLOG("Expected X11 Error received for sequence %x\n", event->sequence);
+            else {
+                xcb_generic_error_t *error = (xcb_generic_error_t*)event;
+                ELOG("X11 Error received! sequence 0x%x, error_code = %d\n",
+                     error->sequence, error->error_code);
+            }
+            free(event);
             continue;
         }
 
@@ -174,6 +191,8 @@ int main(int argc, char *argv[]) {
     if (!isatty(fileno(stdout)))
         setbuf(stdout, NULL);
 
+    init_logging();
+
     start_argv = argv;
 
     while ((opt = getopt_long(argc, argv, "c:CvaL:hld:V", long_options, &option_index)) != -1) {
@@ -250,9 +269,17 @@ int main(int argc, char *argv[]) {
     if (xcb_connection_has_error(conn))
         errx(EXIT_FAILURE, "Cannot open display\n");
 
-    xcb_screen_t *root_screen = xcb_aux_get_screen(conn, screens);
+    /* Initialize the libev event loop. This needs to be done before loading
+     * the config file because the parser will install an ev_child watcher
+     * for the nagbar when config errors are found. */
+    main_loop = EV_DEFAULT;
+    if (main_loop == NULL)
+            die("Could not initialize libev. Bad LIBEV_FLAGS?\n");
+
+    root_screen = xcb_aux_get_screen(conn, screens);
     root = root_screen->root;
     root_depth = root_screen->root_depth;
+    xcb_get_geometry_cookie_t gcookie = xcb_get_geometry(conn, root);
 
     load_configuration(conn, override_configpath, false);
     if (only_check_config) {
@@ -261,7 +288,11 @@ int main(int argc, char *argv[]) {
     }
 
     if (config.ipc_socket_path == NULL) {
-        config.ipc_socket_path = getenv("I3SOCK");
+        /* Fall back to a file name in /tmp/ based on the PID */
+        if ((config.ipc_socket_path = getenv("I3SOCK")) == NULL)
+            config.ipc_socket_path = get_process_filename("ipc-socket");
+        else
+            config.ipc_socket_path = sstrdup(config.ipc_socket_path);
     }
 
     uint32_t mask = XCB_CW_EVENT_MASK;
@@ -276,6 +307,13 @@ int main(int argc, char *argv[]) {
     cookie = xcb_change_window_attributes_checked(conn, root, mask, values);
     check_error(conn, cookie, "Another window manager seems to be running");
 
+    xcb_get_geometry_reply_t *greply = xcb_get_geometry_reply(conn, gcookie, NULL);
+    if (greply == NULL) {
+        ELOG("Could not get geometry of the root window, exiting\n");
+        return 1;
+    }
+    DLOG("root geometry reply: (%d, %d) %d x %d\n", greply->x, greply->y, greply->width, greply->height);
+
     /* Place requests for the atoms we need as soon as possible */
     #define xmacro(atom) \
         xcb_intern_atom_cookie_t atom ## _cookie = xcb_intern_atom(conn, 0, strlen(#atom), #atom);
@@ -298,6 +336,20 @@ int main(int argc, char *argv[]) {
         /*init_xkb();*/
     }
 
+    /* Set a cursor for the root window (otherwise the root window will show no
+       cursor until the first client is launched). */
+    if (xcursor_supported) {
+        xcursor_set_root_cursor();
+    } else {
+        xcb_cursor_t cursor_id = xcb_generate_id(conn);
+        i3Font cursor_font = load_font("cursor", false);
+        int xcb_cursor = xcursor_get_xcb_cursor(XCURSOR_CURSOR_POINTER);
+        xcb_create_glyph_cursor(conn, cursor_id, cursor_font.id, cursor_font.id,
+                xcb_cursor, xcb_cursor + 1, 0, 0, 0, 65535, 65535, 65535);
+        xcb_change_window_attributes(conn, root, XCB_CW_CURSOR, &cursor_id);
+        xcb_free_cursor(conn, cursor_id);
+    }
+
     if (xkb_supported) {
         int errBase,
             major = XkbMajorVersion,
@@ -345,7 +397,7 @@ int main(int argc, char *argv[]) {
 #include "atoms.xmacro"
 #undef xmacro
     };
-    xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_SUPPORTED, A_ATOM, 32, 7, supported_atoms);
+    xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_SUPPORTED, A_ATOM, 32, 16, supported_atoms);
     /* Set up the window manager’s name */
     xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_SUPPORTING_WM_CHECK, A_WINDOW, 32, 1, &root);
     xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_WM_NAME, A_UTF8_STRING, 8, strlen("i3"), "i3");
@@ -360,13 +412,15 @@ int main(int argc, char *argv[]) {
     bool needs_tree_init = true;
     if (layout_path) {
         LOG("Trying to restore the layout from %s...", layout_path);
-        needs_tree_init = !tree_restore(layout_path);
+        needs_tree_init = !tree_restore(layout_path, greply);
         if (delete_layout_path)
             unlink(layout_path);
         free(layout_path);
     }
     if (needs_tree_init)
-        tree_init();
+        tree_init(greply);
+
+    free(greply);
 
     if (force_xinerama) {
         xinerama_init();
@@ -377,44 +431,42 @@ int main(int argc, char *argv[]) {
 
     tree_render();
 
-    struct ev_loop *loop = ev_loop_new(0);
-    if (loop == NULL)
-            die("Could not initialize libev. Bad LIBEV_FLAGS?\n");
-
     /* Create the UNIX domain socket for IPC */
-    if (config.ipc_socket_path != NULL) {
-        int ipc_socket = ipc_create_socket(config.ipc_socket_path);
-        if (ipc_socket == -1) {
-            ELOG("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);
-        }
+    int ipc_socket = ipc_create_socket(config.ipc_socket_path);
+    if (ipc_socket == -1) {
+        ELOG("Could not create the IPC socket, IPC disabled\n");
+    } else {
+        free(config.ipc_socket_path);
+        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(main_loop, ipc_io);
     }
 
+    /* Set up i3 specific atoms like I3_SOCKET_PATH and I3_CONFIG_PATH */
+    x_set_i3_atoms();
+
     struct ev_io *xcb_watcher = scalloc(sizeof(struct ev_io));
     struct ev_io *xkb = 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_io_start(main_loop, xcb_watcher);
 
 
     if (xkb_supported) {
         ev_io_init(xkb, xkb_got_event, ConnectionNumber(xkbdpy), EV_READ);
-        ev_io_start(loop, xkb);
+        ev_io_start(main_loop, xkb);
 
         /* Flush the buffer so that libev can properly get new events */
         XFlush(xkbdpy);
     }
 
     ev_check_init(xcb_check, xcb_check_cb);
-    ev_check_start(loop, xcb_check);
+    ev_check_start(main_loop, xcb_check);
 
     ev_prepare_init(xcb_prepare, xcb_prepare_cb);
-    ev_prepare_start(loop, xcb_prepare);
+    ev_prepare_start(main_loop, xcb_prepare);
 
     xcb_flush(conn);
 
@@ -436,5 +488,12 @@ int main(int argc, char *argv[]) {
         }
     }
 
-    ev_loop(loop, 0);
+    /* Autostarting exec_always-lines */
+    struct Autostart *exec_always;
+    TAILQ_FOREACH(exec_always, &autostarts_always, autostarts_always) {
+        LOG("auto-starting (always!) %s\n", exec_always->command);
+        start_application(exec_always->command);
+    }
+
+    ev_loop(main_loop, 0);
 }