i3 - improved tiling WM


Implement the window::move event

Patch status: merged

Patch by Tony Crisci

Long description:

The window::move event should be emitted when the window moves position
in the tree.

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

b/docs/ipc

19
@@ -720,6 +720,7 @@ This event consists of a single serialized map containing a property
20
 * +focus+ - the window has received input focus
21
 * +title+ - the window's title has changed
22
 * +fullscreen_mode+ - the window has entered or exited fullscreen mode
23
+* +move+ - the window has changed its position in the tree
24
 
25
 Additionally a +container (object)+ field will be present, which consists
26
 of the window's parent container. Be aware that for the "new" event, the

b/src/con.c

31
@@ -832,6 +832,8 @@ void con_move_to_workspace(Con *con, Con *workspace, bool fix_coordinates, bool
32
     }
33
 
34
     CALL(parent, on_remove_child);
35
+
36
+    ipc_send_window_event("move", con);
37
 }
38
 
39
 /*

b/src/move.c

44
@@ -206,6 +206,7 @@ void tree_move(int direction) {
45
                 TAILQ_INSERT_HEAD(&(swap->parent->focus_head), con, focused);
46
 
47
                 DLOG("Swapped.\n");
48
+                ipc_send_window_event("move", con);
49
                 return;
50
             }
51
 
52
@@ -213,6 +214,7 @@ void tree_move(int direction) {
53
                 /*  If we couldn't find a place to move it on this workspace,
54
                  *  try to move it to a workspace on a different output */
55
                 move_to_output_directed(con, direction);
56
+                ipc_send_window_event("move", con);
57
                 return;
58
             }
59
 
60
@@ -264,4 +266,5 @@ end:
61
     FREE(con->deco_render_params);
62
 
63
     tree_flatten(croot);
64
+    ipc_send_window_event("move", con);
65
 }

b/testcases/t/231-ipc-window-move.t

71
@@ -0,0 +1,61 @@
72
+#!perl
73
+# vim:ts=4:sw=4:expandtab
74
+#
75
+# Please read the following documents before working on tests:
76
+# • http://build.i3wm.org/docs/testsuite.html
77
+#   (or docs/testsuite)
78
+#
79
+# • http://build.i3wm.org/docs/lib-i3test.html
80
+#   (alternatively: perldoc ./testcases/lib/i3test.pm)
81
+#
82
+# • http://build.i3wm.org/docs/ipc.html
83
+#   (or docs/ipc)
84
+#
85
+# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
86
+#   (unless you are already familiar with Perl)
87
+#
88
+# Tests that the ipc window::move event works properly
89
+#
90
+# Bug still in: 4.8-7-gf4a8253
91
+use i3test;
92
+
93
+my $i3 = i3(get_socket_path());
94
+$i3->connect()->recv;
95
+
96
+my $cv;
97
+my $t;
98
+
99
+sub reset_test {
100
+    $cv = AE::cv;
101
+    $t = AE::timer(0.5, 0, sub { $cv->send(0); });
102
+}
103
+
104
+reset_test;
105
+
106
+$i3->subscribe({
107
+        window => sub {
108
+            my ($e) = @_;
109
+            if ($e->{change} eq 'move') {
110
+                $cv->send($e->{container});
111
+            }
112
+        },
113
+    })->recv;
114
+
115
+my $dummy_window = open_window;
116
+my $window = open_window;
117
+
118
+cmd 'move right';
119
+my $con = $cv->recv;
120
+
121
+ok($con, 'moving a window should emit the window::move event');
122
+is($con->{window}, $window->{id}, 'the event should contain info about the window');
123
+
124
+reset_test;
125
+
126
+cmd 'move to workspace ws_new';
127
+$con = $cv->recv;
128
+
129
+ok($con, 'moving a window to a different workspace should emit the window::move event');
130
+is($con->{window}, $window->{id}, 'the event should contain info about the window');
131
+
132
+done_testing;