Respect workspace numbers when looking for a free workspace name
Patch status: merged
Patch by Sebastian Ullrich
Long description:
This prevents a ws '1' appearing on a new output when there's already a ws '1: www' on an existing output
To apply this patch, use:
curl http://cr.i3wm.org/patch/202/raw.patch | git am
b/src/workspace.c
18 |
@@ -197,17 +197,16 @@ Con *create_workspace_on_output(Output *output, Con *content) { |
19 |
while (exists) { |
20 |
c++; |
21 |
|
22 |
- FREE(ws->name); |
23 |
- sasprintf(&(ws->name), "%d", c); |
24 |
+ ws->num = c; |
25 |
|
26 |
current = NULL; |
27 |
TAILQ_FOREACH(out, &(croot->nodes_head), nodes) |
28 |
- GREP_FIRST(current, output_get_content(out), !strcasecmp(child->name, ws->name)); |
29 |
+ GREP_FIRST(current, output_get_content(out), child->num == ws->num); |
30 |
exists = (current != NULL); |
31 |
|
32 |
- DLOG("result for ws %s / %d: exists = %d\n", ws->name, c, exists); |
33 |
+ DLOG("result for ws %d: exists = %d\n", c, exists); |
34 |
} |
35 |
- ws->num = c; |
36 |
+ sasprintf(&(ws->name), "%d", c); |
37 |
} |
38 |
con_attach(ws, content, false); |
39 |
|
b/testcases/t/515-create-workspace.t
45 |
@@ -0,0 +1,40 @@ |
46 |
+#!perl |
47 |
+# vim:ts=4:sw=4:expandtab |
48 |
+# |
49 |
+# Please read the following documents before working on tests: |
50 |
+# • http://build.i3wm.org/docs/testsuite.html |
51 |
+# (or docs/testsuite) |
52 |
+# |
53 |
+# • http://build.i3wm.org/docs/lib-i3test.html |
54 |
+# (alternatively: perldoc ./testcases/lib/i3test.pm) |
55 |
+# |
56 |
+# • http://build.i3wm.org/docs/ipc.html |
57 |
+# (or docs/ipc) |
58 |
+# |
59 |
+# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf |
60 |
+# (unless you are already familiar with Perl) |
61 |
+# |
62 |
+# Tests that new workspace names are taken from the config, |
63 |
+# then from the first free number starting with 1. |
64 |
+# |
65 |
+use i3test i3_autostart => 0; |
66 |
+ |
67 |
+my $config = <<EOT; |
68 |
+# i3 config file (v4) |
69 |
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1 |
70 |
+ |
71 |
+fake-outputs 1024x768+0+0,1024x768+1024+0 |
72 |
+ |
73 |
+bindsym 1 workspace 1: eggs |
74 |
+EOT |
75 |
+my $pid = launch_with_config($config); |
76 |
+ |
77 |
+my $i3 = i3(get_socket_path()); |
78 |
+my $ws = $i3->get_workspaces->recv; |
79 |
+ |
80 |
+is($ws->[0]->{name}, '1: eggs', 'new workspace uses config name'); |
81 |
+is($ws->[1]->{name}, '2', 'naming continues with next free number'); |
82 |
+ |
83 |
+exit_gracefully($pid); |
84 |
+ |
85 |
+done_testing; |