i3 - improved tiling WM


Fix workspaces' and window's urgency on window move

Patch status: needinfo

Patch by Yuriy Taraday

Long description:

- window keeps urgent flag if it's moved to another workspace;
- old workspace's urgent flag is unset if it was the only urgent window
  in this workspace;
- target workspace's urgent flag is set if the window is urgent.

Fixes bug #1187

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

b/src/con.c

20
@@ -765,11 +765,21 @@ void con_move_to_workspace(Con *con, Con *workspace, bool fix_coordinates, bool
21
          * new workspace is hidden and it's necessary to immediately switch
22
          * back to the originally-focused workspace. */
23
         Con *old_focus = TAILQ_FIRST(&(output_get_content(dest_output)->focus_head));
24
+        /* We need to keep urgency flag in case we're not planning to keep
25
+         * focus on this container. */
26
+        bool con_urgent = con->urgent;
27
         con_focus(con_descend_focused(con));
28
 
29
         /* Restore focus if the output's focused workspace has changed. */
30
-        if (con_get_workspace(focused) != old_focus)
31
+        if (con_get_workspace(focused) != old_focus) {
32
             con_focus(old_focus);
33
+            /* If the container was urgent we should reraise urgency flag */
34
+            if (con_urgent) {
35
+                con->urgent = true;
36
+                con_update_parents_urgency(con);
37
+                workspace_update_urgent_flag(workspace);
38
+            }
39
+        }
40
     }
41
 
42
     /* 8: when moving to another workspace, we leave the focus on the current
43
@@ -818,6 +828,9 @@ void con_move_to_workspace(Con *con, Con *workspace, bool fix_coordinates, bool
44
     }
45
 
46
     CALL(parent, on_remove_child);
47
+    /* This would clear urgency flag from workspace if we just moved the only
48
+     * urgent container out of it. */
49
+    workspace_update_urgent_flag(current_ws);
50
 }
51
 
52
 /*

b/testcases/t/113-urgent.t

57
@@ -307,6 +307,22 @@ for ($type = 1; $type <= 2; $type++) {
58
     my $ws = get_ws($tmp);
59
     ok(!$ws->{urgent}, 'urgent flag not set on workspace');
60
 
61
+##############################################################################
62
+# Check if urgent flag migrates with a window to a new workspace
63
+##############################################################################
64
+    my $ws1 = fresh_workspace;
65
+    my $ws2 = fresh_workspace;
66
+    cmd "workspace $ws1";
67
+    my $w1 = open_window;
68
+    my $w2 = open_window;
69
+    set_urgency($w1, 1, $type);
70
+    sync_with_i3;
71
+    cmd '[id="' . $w1->id . '"] move to workspace ' . $ws2;
72
+    my $w = get_ws($ws1);
73
+    ok(!$w->{urgent}, 'Workspace we migrated window from is not urgent anymore');
74
+    my $w = get_ws($ws2);
75
+    ok($w->{urgent}, 'Workspace we migrated window to is now urgent');
76
+
77
     exit_gracefully($pid);
78
 }
79