i3 - improved tiling WM


Fix restarting with 32bit depth windows (v4)

Patch status: superseded

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 a typo in previous patch.

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

b/include/con.h

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

b/include/data.h

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

b/src/con.c

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

b/src/handlers.c

118
@@ -357,7 +357,7 @@ static void handle_configure_request(xcb_configure_request_event_t *event) {
119
         Rect newrect = floatingcon->rect;
120
 
121
         if (event->value_mask & XCB_CONFIG_WINDOW_X) {
122
-            newrect.x = event->x + (-1) * bsr.x;
123
+            newrect.x = event->x;// + (-1) * bsr.x;
124
             DLOG("proposed x = %d, new x is %d\n", event->x, newrect.x);
125
         }
126
         if (event->value_mask & XCB_CONFIG_WINDOW_Y) {

b/src/ipc.c

131
@@ -354,6 +354,11 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
132
     }
133
     y(array_close);
134
 
135
+    if (inplace_restart && con->window != NULL) {
136
+        ystr("depth");
137
+        y(integer, con->depth);
138
+    }
139
+
140
     y(map_close);
141
 }
142
 

b/src/load_layout.c

147
@@ -51,12 +51,12 @@ static int json_start_map(void *ctx) {
148
             if (last_key && strcasecmp(last_key, "floating_nodes") == 0) {
149
                 DLOG("New floating_node\n");
150
                 Con *ws = con_get_workspace(json_node);
151
-                json_node = con_new(NULL, NULL);
152
+                json_node = con_new_skeleton(NULL, NULL);
153
                 json_node->parent = ws;
154
                 DLOG("Parent is workspace = %p\n", ws);
155
             } else {
156
                 Con *parent = json_node;
157
-                json_node = con_new(NULL, NULL);
158
+                json_node = con_new_skeleton(NULL, NULL);
159
                 json_node->parent = parent;
160
             }
161
         }
162
@@ -69,6 +69,8 @@ static int json_end_map(void *ctx) {
163
     if (!parsing_swallows && !parsing_rect && !parsing_window_rect && !parsing_geometry) {
164
         LOG("attaching\n");
165
         con_attach(json_node, json_node->parent, true);
166
+        LOG("Creating window\n");
167
+        x_con_init(json_node, json_node->depth);
168
         json_node = json_node->parent;
169
     }
170
     if (parsing_rect)
171
@@ -277,6 +279,9 @@ static int json_int(void *ctx, long val) {
172
     if (strcasecmp(last_key, "current_border_width") == 0)
173
         json_node->current_border_width = val;
174
 
175
+    if (strcasecmp(last_key, "depth") == 0)
176
+        json_node->depth = val;
177
+
178
     if (!parsing_swallows && strcasecmp(last_key, "id") == 0)
179
         json_node->old_id = val;
180