i3 - improved tiling WM


Fix restarting with 32bit depth windows (v5)

Patch status: merged

Patch by Yuxuan Shui

Long description:

What I do in this patch is:

1. Split the con_new() function, so I can create a Con without actually
create a window.
2. Store the depth of Cons in the layout file when i3 is restarting.

Fix typos and mis-staged files in previous patch.

To apply this patch, use:
curl http://cr.i3wm.org/patch/108/raw.patch | git am

b/include/con.h

24
@@ -14,8 +14,13 @@
25
 
26
 /**
27
  * Create a new container (and attach it to the given parent, if not NULL).
28
- * This function initializes the data structures and creates the appropriate
29
- * X11 IDs using x_con_init().
30
+ * This function only initializes the data structures.
31
+ *
32
+ */
33
+Con *con_new_skeleton(Con *parent, i3Window *window);
34
+
35
+
36
+/* A wrapper for con_new_skeleton, to retain the old con_new behaviour
37
  *
38
  */
39
 Con *con_new(Con *parent, i3Window *window);

b/include/data.h

44
@@ -584,6 +584,9 @@ struct Con {
45
     /* The ID of this container before restarting. Necessary to correctly
46
      * interpret back-references in the JSON (such as the focus stack). */
47
     int old_id;
48
+
49
+    /* Depth of the container window */
50
+    uint16_t depth;
51
 };
52
 
53
 #endif

b/src/con.c

58
@@ -44,11 +44,10 @@ static void con_force_split_parents_redraw(Con *con) {
59
 
60
 /*
61
  * Create a new container (and attach it to the given parent, if not NULL).
62
- * This function initializes the data structures and creates the appropriate
63
- * X11 IDs using x_con_init().
64
+ * This function only initializes the data structures.
65
  *
66
  */
67
-Con *con_new(Con *parent, i3Window *window) {
68
+Con *con_new_skeleton(Con *parent, i3Window *window) {
69
     Con *new = scalloc(sizeof(Con));
70
     new->on_remove_child = con_on_remove_child;
71
     TAILQ_INSERT_TAIL(&all_cons, new, all_cons);
72
@@ -56,6 +55,10 @@ Con *con_new(Con *parent, i3Window *window) {
73
     new->window = window;
74
     new->border_style = config.default_border;
75
     new->current_border_width = -1;
76
+    if (window)
77
+        new->depth = window->depth;
78
+    else
79
+        new->depth = XCB_COPY_FROM_PARENT;
80
     static int cnt = 0;
81
     DLOG("opening window %d\n", cnt);
82
 
83
@@ -66,10 +69,6 @@ Con *con_new(Con *parent, i3Window *window) {
84
     cnt++;
85
     if ((cnt % (sizeof(colors) / sizeof(char*))) == 0)
86
         cnt = 0;
87
-    if (window)
88
-        x_con_init(new, window->depth);
89
-    else
90
-        x_con_init(new, XCB_COPY_FROM_PARENT);
91
 
92
     TAILQ_INIT(&(new->floating_head));
93
     TAILQ_INIT(&(new->nodes_head));
94
@@ -82,6 +81,15 @@ Con *con_new(Con *parent, i3Window *window) {
95
     return new;
96
 }
97
 
98
+/* A wrapper for con_new_skeleton, to retain the old con_new behaviour
99
+ *
100
+ */
101
+Con *con_new(Con *parent, i3Window *window) {
102
+    Con *new = con_new_skeleton(parent, window);
103
+    x_con_init(new, new->depth);
104
+    return new;
105
+}
106
+
107
 /*
108
  * Attaches the given container to the given parent. This happens when moving
109
  * a container or when inserting a new container at a specific place in the

b/src/ipc.c

114
@@ -354,6 +354,11 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
115
     }
116
     y(array_close);
117
 
118
+    if (inplace_restart && con->window != NULL) {
119
+        ystr("depth");
120
+        y(integer, con->depth);
121
+    }
122
+
123
     y(map_close);
124
 }
125
 

b/src/load_layout.c

130
@@ -51,12 +51,12 @@ static int json_start_map(void *ctx) {
131
             if (last_key && strcasecmp(last_key, "floating_nodes") == 0) {
132
                 DLOG("New floating_node\n");
133
                 Con *ws = con_get_workspace(json_node);
134
-                json_node = con_new(NULL, NULL);
135
+                json_node = con_new_skeleton(NULL, NULL);
136
                 json_node->parent = ws;
137
                 DLOG("Parent is workspace = %p\n", ws);
138
             } else {
139
                 Con *parent = json_node;
140
-                json_node = con_new(NULL, NULL);
141
+                json_node = con_new_skeleton(NULL, NULL);
142
                 json_node->parent = parent;
143
             }
144
         }
145
@@ -69,6 +69,8 @@ static int json_end_map(void *ctx) {
146
     if (!parsing_swallows && !parsing_rect && !parsing_window_rect && !parsing_geometry) {
147
         LOG("attaching\n");
148
         con_attach(json_node, json_node->parent, true);
149
+        LOG("Creating window\n");
150
+        x_con_init(json_node, json_node->depth);
151
         json_node = json_node->parent;
152
     }
153
     if (parsing_rect)
154
@@ -277,6 +279,9 @@ static int json_int(void *ctx, long val) {
155
     if (strcasecmp(last_key, "current_border_width") == 0)
156
         json_node->current_border_width = val;
157
 
158
+    if (strcasecmp(last_key, "depth") == 0)
159
+        json_node->depth = val;
160
+
161
     if (!parsing_swallows && strcasecmp(last_key, "id") == 0)
162
         json_node->old_id = val;
163