]> git.sur5r.net Git - i3/i3/blobdiff - src/manage.c
Remove old code from randr.c and workspace.c
[i3/i3] / src / manage.c
index 4821e28f76451e393b925adb8cab6cca6b634913..b511189c0a1b36d4207949ef0770d6ac6724e52a 100644 (file)
@@ -117,6 +117,17 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
         goto out;
     }
 
+    uint32_t mask = 0;
+    uint32_t values[1];
+
+    /* Set a temporary event mask for the new window, consisting only of
+     * PropertyChange. We need to be notified of PropertyChanges because the
+     * client can change its properties *after* we requested them but *before*
+     * we actually reparented it and have set our final event mask. */
+    mask = XCB_CW_EVENT_MASK;
+    values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE;
+    xcb_change_window_attributes(conn, window, mask, values);
+
 #define GET_PROPERTY(atom, len) xcb_get_property_unchecked(conn, false, window, atom, XCB_GET_PROPERTY_TYPE_ANY, 0, len)
 
     wm_type_cookie = GET_PROPERTY(A__NET_WM_WINDOW_TYPE, UINT32_MAX);
@@ -130,8 +141,6 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
     /* TODO: also get wm_normal_hints here. implement after we got rid of xcb-event */
 
     DLOG("reparenting!\n");
-    uint32_t mask = 0;
-    uint32_t values[1];
 
     i3Window *cwindow = scalloc(sizeof(i3Window));
     cwindow->id = window;
@@ -156,6 +165,9 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
     window_update_transient_for(cwindow, xcb_get_property_reply(conn, transient_cookie, NULL));
     window_update_strut_partial(cwindow, xcb_get_property_reply(conn, strut_cookie, NULL));
 
+    /* check if the window needs WM_TAKE_FOCUS */
+    cwindow->needs_take_focus = window_supports_protocol(cwindow->id, A_WM_TAKE_FOCUS);
+
     /* Where to start searching for a container that swallows the new one? */
     Con *search_at = croot;
 
@@ -191,38 +203,36 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
 
     DLOG("Initial geometry: (%d, %d, %d, %d)\n", geom->x, geom->y, geom->width, geom->height);
 
-    Con *nc;
+    Con *nc = NULL;
     Match *match;
 
-    /* TODO: assignments */
-    /* TODO: two matches for one container */
-
-    /* See if any container swallows this new window */
-    nc = con_for_window(search_at, 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);
+    /* check assignments first */
+    if ((match = match_by_assignment(cwindow))) {
+        DLOG("Assignment matches (%p)\n", match);
+        if (match->insert_where == M_ASSIGN_WS) {
+            nc = con_descend_focused(workspace_get(match->target_ws, NULL));
+            DLOG("focused on ws %s: %p / %s\n", match->target_ws, nc, nc->name);
+            if (nc->type == CT_WORKSPACE)
+                nc = tree_open_con(nc);
+            else nc = tree_open_con(nc->parent);
+        }
     } else {
-        /* M_ACTIVE are assignments */
-        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))) {
-                DLOG("walking down one step...\n");
-                nc = TAILQ_FIRST(&(nc->focus_head));
+        /* TODO: two matches for one container */
+
+        /* See if any container swallows this new window */
+        nc = con_for_window(search_at, 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 {
+            /* M_BELOW inserts the new window as a child of the one which was
+             * matched (e.g. dock areas) */
+            if (match != NULL && match->insert_where == M_BELOW) {
+                nc = tree_open_con(nc);
             }
-            /* 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);
-        }
-
-        /* M_BELOW inserts the new window as a child of the one which was
-         * matched (e.g. dock areas) */
-        else if (match != NULL && match->insert_where == M_BELOW) {
-            nc = tree_open_con(nc);
         }
     }