i3 - improved tiling WM


Implement the ipc window::floating event

Patch status: needinfo

Patch by Tony Crisci

Long description:

The window::floating event will be sent when a container becomes
floating.

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

b/src/floating.c

17
@@ -298,16 +298,22 @@ void floating_enable(Con *con, bool automatic) {
18
 
19
     /* Check if we need to re-assign it to a different workspace because of its
20
      * coordinates and exit if that was done successfully. */
21
-    if (floating_maybe_reassign_ws(nc))
22
+    if (floating_maybe_reassign_ws(nc)) {
23
+        ipc_send_window_event("floating", con);
24
         return;
25
+    }
26
 
27
     /* Sanitize coordinates: Check if they are on any output */
28
-    if (get_output_containing(nc->rect.x, nc->rect.y) != NULL)
29
+    if (get_output_containing(nc->rect.x, nc->rect.y) != NULL) {
30
+        ipc_send_window_event("floating", con);
31
         return;
32
+    }
33
 
34
     ELOG("No output found at destination coordinates, centering floating window on current ws\n");
35
     nc->rect.x = ws->rect.x + (ws->rect.width / 2) - (nc->rect.width / 2);
36
     nc->rect.y = ws->rect.y + (ws->rect.height / 2) - (nc->rect.height / 2);
37
+
38
+    ipc_send_window_event("floating", con);
39
 }
40
 
41
 void floating_disable(Con *con, bool automatic) {
42
@@ -351,6 +357,8 @@ void floating_disable(Con *con, bool automatic) {
43
 
44
     if (set_focus)
45
         con_focus(con);
46
+
47
+    ipc_send_window_event("floating", con);
48
 }
49
 
50
 /*

b/testcases/t/231-ipc-floating-event.t

56
@@ -0,0 +1,59 @@
57
+#!perl
58
+# vim:ts=4:sw=4:expandtab
59
+#
60
+# Please read the following documents before working on tests:
61
+# • http://build.i3wm.org/docs/testsuite.html
62
+#   (or docs/testsuite)
63
+#
64
+# • http://build.i3wm.org/docs/lib-i3test.html
65
+#   (alternatively: perldoc ./testcases/lib/i3test.pm)
66
+#
67
+# • http://build.i3wm.org/docs/ipc.html
68
+#   (or docs/ipc)
69
+#
70
+# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
71
+#   (unless you are already familiar with Perl)
72
+#
73
+# TODO: Description of this file.
74
+# Ticket: #999
75
+# Bug still in: 4.8-7-gf4a8253
76
+use i3test;
77
+
78
+my $i3 = i3(get_socket_path());
79
+$i3->connect->recv;
80
+
81
+my $cv = AnyEvent->condvar;
82
+
83
+$i3->subscribe({
84
+        window => sub {
85
+            my ($event) = @_;
86
+            $cv->send($event) if $event->{change} eq 'floating';
87
+        }
88
+    })->recv;
89
+
90
+my $t;
91
+$t = AnyEvent->timer(
92
+    after => 0.5,
93
+    cb => sub {
94
+        $cv->send(0);
95
+    }
96
+);
97
+
98
+my $win = open_window();
99
+
100
+cmd '[id="' . $win->{id} . '"] floating enable';
101
+my $e = $cv->recv;
102
+
103
+isnt($e, 0, 'floating a container should send an ipc window event');
104
+is($e->{container}->{window}, $win->{id}, 'the event should contain information about the window');
105
+is($e->{container}->{floating}, 'user_on', 'the container should be floating');
106
+
107
+$cv = AnyEvent->condvar;
108
+cmd '[id="' . $win->{id} . '"] floating disable';
109
+my $e = $cv->recv;
110
+
111
+isnt($e, 0, 'disabling floating on a container should send an ipc window event');
112
+is($e->{container}->{window}, $win->{id}, 'the event should contain information about the window');
113
+is($e->{container}->{floating}, 'user_off', 'the container should not be floating');
114
+
115
+done_testing;