i3 - improved tiling WM


IPC: set ws reply "num" member to -1 when named

Patch status: merged

Patch by Tony Crisci

Long description:

When a named workspace (i.e., a workspace that has a name that does not
begin with text that can be parsed as an integer greater than or equal
to zero) is represented by the ipc as a workspace json object such as
can be queried with `i3-msg -t get_workspaces`, set the num property to
-1 instead of json null.

This is for convenience of ipc consumers using type-constrained
languages such as C which have difficulty cleanly expressing nullable
integers.

fixes #1368

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

b/docs/ipc

26
@@ -156,7 +156,7 @@ following properties:
27
 
28
 num (integer)::
29
 	The logical number of the workspace. Corresponds to the command
30
-	to switch to this workspace.
31
+	to switch to this workspace. For named workspaces, this will be -1.
32
 name (string)::
33
 	The name of this workspace (by default num+1), as changed by the
34
 	user. Encoded in UTF-8.

b/src/ipc.c

39
@@ -617,10 +617,7 @@ IPC_HANDLER(get_workspaces) {
40
             y(map_open);
41
 
42
             ystr("num");
43
-            if (ws->num == -1)
44
-                y(null);
45
-            else
46
-                y(integer, ws->num);
47
+            y(integer, ws->num);
48
 
49
             ystr("name");
50
             ystr(ws->name);

b/testcases/t/139-ws-numbers.t

55
@@ -24,7 +24,7 @@ sub check_order {
56
     my ($msg) = @_;
57
 
58
     my @ws = @{$i3->get_workspaces->recv};
59
-    my @nums = map { $_->{num} } grep { defined($_->{num}) } @ws;
60
+    my @nums = map { $_->{num} } grep { $_->{num} != -1 } @ws;
61
     my @sorted = sort @nums;
62
 
63
     is_deeply(\@nums, \@sorted, $msg);