i3 - improved tiling WM


Add a new IPC event for changes on windows.

Patch status: rejected

Patch by Piotr S. Staszewski

Long description:

Added new event id (I3_IPC_EVENT_WINDOW) so that a an IPC client can
subscribe to events on windows. Added a basic window event that gets
triggered when a window gets successfully reparented. This new event
also dumps the container data, so that IPC clients can get the initial
window name. IPC clients wishing to see window events should subscribe
to 'window'.

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

b/docs/ipc

21
@@ -621,6 +621,9 @@ output (1)::
22
 	outputs, CRTCs or output properties).
23
 mode (2)::
24
 	Sent whenever i3 changes its binding mode.
25
+window (3)::
26
+	Sent when a client's window is successfully reparented (that is when i3
27
+	has finished fitting it into a container).
28
 
29
 *Example:*
30
 --------------------------------------------------------------------
31
@@ -694,6 +697,30 @@ mode is simply named default.
32
 { "change": "default" }
33
 ---------------------------
34
 
35
+=== window event
36
+
37
+This event consists of a single serialized map containing a property
38
++window (string)+ which currently can indicate only that a new window
39
+has been successfully reparented (the value will be "new").
40
+
41
+Additionally a +container (object)+ field will be present, which consists
42
+of the window's parent container. Be aware that the container will hold
43
+the initial name of the newly reparented window (e.g. if you run urxvt
44
+with a shell that changes the title, you will still at this point get the
45
+window title as "urxvt").
46
+
47
+*Example:*
48
+---------------------------
49
+{
50
+ "window": "new",
51
+ "container": {
52
+  "id": 35569536,
53
+  "type": 2,
54
+  ...
55
+ }
56
+}
57
+---------------------------
58
+
59
 == See also (existing libraries)
60
 
61
 [[libraries]]

b/include/i3/ipc.h

66
@@ -96,4 +96,7 @@ typedef struct i3_ipc_header {
67
 /* The output event will be triggered upon mode changes */
68
 #define I3_IPC_EVENT_MODE                       (I3_IPC_EVENT_MASK | 2)
69
 
70
+/* The window event will be triggered upon window changes */
71
+#define I3_IPC_EVENT_WINDOW                     (I3_IPC_EVENT_MASK | 3)
72
+
73
 #endif

b/src/manage.c

78
@@ -10,6 +10,9 @@
79
  *
80
  */
81
 #include "all.h"
82
+#include "yajl_utils.h"
83
+
84
+#include <yajl/yajl_gen.h>
85
 
86
 /*
87
  * Go through all existing windows (if the window manager is restarted) and manage them
88
@@ -73,6 +76,35 @@ void restore_geometry(void) {
89
 }
90
 
91
 /*
92
+ * The following function sends a new window event, which consists
93
+ * of fields "window" and "container", the latter containing a dump
94
+ * of the window's container.
95
+ *
96
+ */
97
+static void ipc_send_window_new_event(Con *con) {
98
+    setlocale(LC_NUMERIC, "C");
99
+    yajl_gen gen = ygenalloc();
100
+
101
+    y(map_open);
102
+
103
+    ystr("window");
104
+    ystr("new");
105
+
106
+    ystr("container");
107
+    dump_node(gen, con, false);
108
+
109
+    y(map_close);
110
+
111
+    const unsigned char *payload;
112
+    ylength length;
113
+    y(get_buf, &payload, &length);
114
+ 
115
+    ipc_send_event("window", I3_IPC_EVENT_WINDOW, (const char *)payload);
116
+    y(free);
117
+    setlocale(LC_NUMERIC, "");
118
+}
119
+
120
+/*
121
  * Do some sanity checks and then reparent the window.
122
  *
123
  */
124
@@ -428,6 +460,9 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
125
     }
126
     tree_render();
127
 
128
+    /* Send an event about window creation */
129
+    ipc_send_window_new_event(nc);
130
+
131
 geom_out:
132
     free(geom);
133
 out: