+ /* Check if the window is mapped (it could be not mapped when intializing and
+ calling manage_window() for every window) */
+ if ((attr = xcb_get_window_attributes_reply(conn, cookie, 0)) == NULL) {
+ LOG("Could not get attributes\n");
+ return;
+ }
+
+ if (needs_to_be_mapped && attr->map_state != XCB_MAP_STATE_VIEWABLE) {
+ LOG("map_state unviewable\n");
+ goto out;
+ }
+
+ /* Don’t manage clients with the override_redirect flag */
+ LOG("override_redirect is %d\n", attr->override_redirect);
+ if (attr->override_redirect)
+ goto out;
+
+ /* Check if the window is already managed */
+ if (con_by_window_id(window) != NULL) {
+ LOG("already managed\n");
+ goto out;
+ }
+
+ /* Get the initial geometry (position, size, …) */
+ if ((geom = xcb_get_geometry_reply(conn, geomc, 0)) == NULL) {
+ LOG("could not get geometry\n");
+ goto out;
+ }
+
+ LOG("reparenting!\n");
+ uint32_t mask = 0;
+ uint32_t values[1];
+ mask = XCB_CW_EVENT_MASK;
+ values[0] = CHILD_EVENT_MASK;
+ xcb_change_window_attributes(conn, window, mask, values);
+
+ i3Window *cwindow = scalloc(sizeof(i3Window));
+ cwindow->id = window;
+
+ /* update as much information as possible so far (some replies may be NULL) */
+ window_update_class(cwindow, xcb_get_property_reply(conn, class_cookie, NULL));
+ window_update_name_legacy(cwindow, xcb_get_property_reply(conn, title_cookie, NULL));
+ window_update_name(cwindow, xcb_get_property_reply(conn, utf8_title_cookie, NULL));
+
+ Con *nc;
+ Match *match;
+
+ /* TODO: assignments */
+ /* TODO: two matches for one container */
+ /* See if any container swallows this new window */
+ nc = con_for_window(cwindow, &match);
+ if (nc == NULL) {
+ if (focused->type == CT_CON && con_accepts_window(focused)) {
+ LOG("using current container, focused = %p, focused->name = %s\n",
+ focused, focused->name);
+ nc = focused;
+ } else nc = tree_open_con(NULL);
+ } else {
+ if (match != NULL && match->insert_where == M_ACTIVE) {
+ /* We need to go down the focus stack starting from nc */
+ while (TAILQ_FIRST(&(nc->focus_head)) != TAILQ_END(&(nc->focus_head))) {
+ printf("walking down one step...\n");
+ nc = TAILQ_FIRST(&(nc->focus_head));
+ }
+ /* We need to open a new con */
+ /* TODO: make a difference between match-once containers (directly assign
+ * cwindow) and match-multiple (tree_open_con first) */
+ nc = tree_open_con(nc->parent);