i3 - improved tiling WM


Assigned windows open urgent when not visible

Patch status: merged

Patch by Tony Crisci

Long description:

When i3 begins to manage a window, if the window opens on a workspace
that is not visible, the urgency hint on the newly managed window will
be set.

fixes #1088

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

b/src/manage.c

20
@@ -279,11 +279,17 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
21
         if ((assignment = assignment_for(cwindow, A_TO_WORKSPACE | A_TO_OUTPUT))) {
22
             DLOG("Assignment matches (%p)\n", match);
23
             if (assignment->type == A_TO_WORKSPACE) {
24
-                nc = con_descend_tiling_focused(workspace_get(assignment->dest.workspace, NULL));
25
-                DLOG("focused on ws %s: %p / %s\n", assignment->dest.workspace, nc, nc->name);
26
+                Con *assigned_ws = workspace_get(assignment->dest.workspace, NULL);
27
+                nc = con_descend_tiling_focused(assigned_ws);
28
+                DLOG("focused on ws %s: %p / %s\n", assigned_ws->name, nc, nc->name);
29
                 if (nc->type == CT_WORKSPACE)
30
                     nc = tree_open_con(nc, cwindow);
31
-                else nc = tree_open_con(nc->parent, cwindow);
32
+                else
33
+                    nc = tree_open_con(nc->parent, cwindow);
34
+
35
+                /* set the urgency hint on the window if the workspace is not visible */
36
+                if (!workspace_is_visible(assigned_ws))
37
+                    urgency_hint = true;
38
             }
39
         /* TODO: handle assignments with type == A_TO_OUTPUT */
40
         } else if (startup_ws) {

b/testcases/t/212-assign-urgency.t

46
@@ -0,0 +1,113 @@
47
+#!perl
48
+# vim:ts=4:sw=4:expandtab
49
+#
50
+# Please read the following documents before working on tests:
51
+# • http://build.i3wm.org/docs/testsuite.html
52
+#   (or docs/testsuite)
53
+#
54
+# • http://build.i3wm.org/docs/lib-i3test.html
55
+#   (alternatively: perldoc ./testcases/lib/i3test.pm)
56
+#
57
+# • http://build.i3wm.org/docs/ipc.html
58
+#   (or docs/ipc)
59
+#
60
+# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
61
+#   (unless you are already familiar with Perl)
62
+#
63
+# Tests if the urgency hint will be set appropriately when opening a window
64
+# assigned to a workspace.
65
+#
66
+use i3test i3_autostart => 0;
67
+
68
+# Based on the eponymous function in t/166-assign.t
69
+sub open_special {
70
+    my %args = @_;
71
+    $args{name} //= 'special window';
72
+
73
+    # We use dont_map because i3 will not map the window on the current
74
+    # workspace. Thus, open_window would time out in wait_for_map (2 seconds).
75
+    my $window = open_window(
76
+        %args,
77
+        wm_class => 'special',
78
+        dont_map => 1,
79
+    );
80
+    $window->map;
81
+    return $window;
82
+}
83
+
84
+#####################################################################
85
+# start a window assigned to a non-visible workspace and see that the urgency
86
+# hint is set.
87
+#####################################################################
88
+
89
+my $config = <<EOT;
90
+# i3 config file (v4)
91
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
92
+assign [class="special"] → targetws
93
+EOT
94
+
95
+my $pid = launch_with_config($config);
96
+
97
+cmd 'workspace ordinaryws';
98
+my $window = open_special;
99
+sync_with_i3;
100
+
101
+ok(get_ws('targetws')->{urgent}, 'target workspace is urgent');
102
+
103
+$window->destroy;
104
+
105
+exit_gracefully($pid);
106
+
107
+
108
+#####################################################################
109
+# start a window assigned to a visible workspace and see that the urgency hint
110
+# is not set.
111
+#####################################################################
112
+
113
+$config = <<EOT;
114
+# i3 config file (v4)
115
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
116
+assign [class="special"] → targetws
117
+EOT
118
+
119
+$pid = launch_with_config($config);
120
+
121
+cmd 'workspace targetws';
122
+$window = open_special;
123
+sync_with_i3;
124
+
125
+ok(!get_ws('targetws')->{urgent}, 'visible workspace is not urgent');
126
+
127
+$window->destroy;
128
+
129
+exit_gracefully($pid);
130
+
131
+#####################################################################
132
+# start a window assigned to a visible workspace on a different output and see
133
+# that the urgency hint is not set.
134
+#####################################################################
135
+
136
+$config = <<EOT;
137
+# i3 config file (v4)
138
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
139
+
140
+fake-outputs 1024x768+0+0,1024x768+1024+0
141
+workspace targetws output fake-0
142
+workspace ordinaryws output fake-1
143
+
144
+assign [class="special"] → targetws
145
+EOT
146
+
147
+$pid = launch_with_config($config);
148
+
149
+cmd 'workspace ordinaryws';
150
+$window = open_special;
151
+sync_with_i3;
152
+
153
+ok(!get_ws('targetws')->{urgent}, 'target workspace is not urgent');
154
+
155
+$window->destroy;
156
+
157
+exit_gracefully($pid);
158
+
159
+done_testing;