+ }
+
+ printf("using format \"%s\"\n", format);
+
+ if (socket_path == NULL)
+ socket_path = root_atom_contents("I3_SOCKET_PATH");
+
+ if (socket_path == NULL)
+ socket_path = "/tmp/i3-ipc.sock";
+
+ sockfd = ipc_connect(socket_path);
+
+ if (prompt != NULL)
+ prompt_offset = predict_text_width(prompt);
+
+ int screens;
+ conn = xcb_connect(NULL, &screens);
+ if (!conn || xcb_connection_has_error(conn))
+ die("Cannot open display\n");
+
+ root_screen = xcb_aux_get_screen(conn, screens);
+ root = root_screen->root;
+
+ symbols = xcb_key_symbols_alloc(conn);
+
+ font = load_font(pattern, true);
+ set_font(&font);
+
+ /* Open an input window */
+ win = xcb_generate_id(conn);
+ xcb_create_window(
+ conn,
+ XCB_COPY_FROM_PARENT,
+ win, /* the window id */
+ root, /* parent == root */
+ 50, 50, 500, font.height + 8, /* dimensions */
+ 0, /* X11 border = 0, we draw our own */
+ XCB_WINDOW_CLASS_INPUT_OUTPUT,
+ XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */
+ XCB_CW_BACK_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK,
+ (uint32_t[]){
+ 0, /* back pixel: black */
+ 1, /* override redirect: don’t manage this window */
+ XCB_EVENT_MASK_EXPOSURE
+ });
+
+ /* Map the window (make it visible) */
+ xcb_map_window(conn, win);
+
+ /* Create pixmap */
+ pixmap = xcb_generate_id(conn);
+ pixmap_gc = xcb_generate_id(conn);
+ xcb_create_pixmap(conn, root_screen->root_depth, pixmap, win, 500, font.height + 8);
+ xcb_create_gc(conn, pixmap_gc, pixmap, 0, 0);
+
+ /* Set input focus (we have override_redirect=1, so the wm will not do
+ * this for us) */
+ xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, win, XCB_CURRENT_TIME);
+
+ /* Grab the keyboard to get all input */
+ xcb_flush(conn);
+
+ /* Try (repeatedly, if necessary) to grab the keyboard. We might not
+ * get the keyboard at the first attempt because of the keybinding
+ * still being active when started via a wm’s keybinding. */
+ xcb_grab_keyboard_cookie_t cookie;
+ xcb_grab_keyboard_reply_t *reply = NULL;
+
+ int count = 0;
+ while ((reply == NULL || reply->status != XCB_GRAB_STATUS_SUCCESS) && (count++ < 500)) {
+ cookie = xcb_grab_keyboard(conn, false, win, XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
+ reply = xcb_grab_keyboard_reply(conn, cookie, NULL);
+ usleep(1000);
+ }
+
+ if (reply->status != XCB_GRAB_STATUS_SUCCESS) {
+ fprintf(stderr, "Could not grab keyboard, status = %d\n", reply->status);
+ exit(-1);
+ }
+
+ xcb_flush(conn);
+
+ xcb_generic_event_t *event;
+ while ((event = xcb_wait_for_event(conn)) != NULL) {
+ if (event->response_type == 0) {
+ fprintf(stderr, "X11 Error received! sequence %x\n", event->sequence);
+ continue;