i3 - improved tiling WM


Fix restarting with 32bit depth windows (v3)

Patch status: needinfo

Patch by Yuxuan Shui

Long description:

Fix a typo in previous patch.

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

b/include/con.h

18
@@ -12,10 +12,15 @@
19
 #ifndef I3_CON_H
20
 #define I3_CON_H
21
 
22
-/**
23
+/*
24
  * Create a new container (and attach it to the given parent, if not NULL).
25
- * This function initializes the data structures and creates the appropriate
26
- * X11 IDs using x_con_init().
27
+ * This function only initializes the data structures.
28
+ *
29
+ */
30
+Con *con_new_sketelon(Con *parent, i3Window *window);
31
+
32
+
33
+/* A wrapper for con_new_sketelon, to retain the old con_new behaviour
34
  *
35
  */
36
 Con *con_new(Con *parent, i3Window *window);

b/include/data.h

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

b/src/con.c

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

b/src/ipc.c

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

b/src/load_layout.c

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