i3 - improved tiling WM


Fix restarting with 32bit depth windows

Patch status: superseded

Patch by Yuxuan Shui

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

b/include/con.h

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

b/include/data.h

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

b/src/con.c

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

b/src/ipc.c

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

b/src/load_layout.c

131
@@ -27,6 +27,7 @@ static bool parsing_rect;
132
 static bool parsing_window_rect;
133
 static bool parsing_geometry;
134
 static bool parsing_focus;
135
+static bool parsing_depth;
136
 struct Match *current_swallow;
137
 
138
 /* This list is used for reordering the focus stack after parsing the 'focus'
139
@@ -51,12 +52,12 @@ static int json_start_map(void *ctx) {
140
             if (last_key && strcasecmp(last_key, "floating_nodes") == 0) {
141
                 DLOG("New floating_node\n");
142
                 Con *ws = con_get_workspace(json_node);
143
-                json_node = con_new(NULL, NULL);
144
+                json_node = con_new_sketelon(NULL, NULL);
145
                 json_node->parent = ws;
146
                 DLOG("Parent is workspace = %p\n", ws);
147
             } else {
148
                 Con *parent = json_node;
149
-                json_node = con_new(NULL, NULL);
150
+                json_node = con_new_sketelon(NULL, NULL);
151
                 json_node->parent = parent;
152
             }
153
         }
154
@@ -69,6 +70,8 @@ static int json_end_map(void *ctx) {
155
     if (!parsing_swallows && !parsing_rect && !parsing_window_rect && !parsing_geometry) {
156
         LOG("attaching\n");
157
         con_attach(json_node, json_node->parent, true);
158
+        LOG("Creating window\n");
159
+        x_con_init(json_node, json_node->depth);
160
         json_node = json_node->parent;
161
     }
162
     if (parsing_rect)
163
@@ -77,6 +80,8 @@ static int json_end_map(void *ctx) {
164
         parsing_window_rect = false;
165
     if (parsing_geometry)
166
         parsing_geometry = false;
167
+    if (parsing_depth)
168
+        parsing_depth = false;
169
     return 1;
170
 }
171
 
172
@@ -277,6 +282,9 @@ static int json_int(void *ctx, long val) {
173
     if (strcasecmp(last_key, "current_border_width") == 0)
174
         json_node->current_border_width = val;
175
 
176
+    if (strcasecmp(last_key, "depth") == 0)
177
+        json_node->depth = val;
178
+
179
     if (!parsing_swallows && strcasecmp(last_key, "id") == 0)
180
         json_node->old_id = val;
181