Implement the window::floating event
Patch status: merged
Patch by Tony Crisci
Long description:
The window::floating event should be emitted when a window transitions to or from the floating state.
To apply this patch, use:
curl http://cr.i3wm.org/patch/599/raw.patch | git am
b/docs/ipc
18 |
@@ -722,6 +722,7 @@ This event consists of a single serialized map containing a property |
19 |
* +title+ - the window's title has changed |
20 |
* +fullscreen_mode+ - the window has entered or exited fullscreen mode |
21 |
* +move+ - the window has changed its position in the tree |
22 |
+* +floating+ - the window has transitioned to or from floating |
23 |
|
24 |
Additionally a +container (object)+ field will be present, which consists |
25 |
of the window's parent container. Be aware that for the "new" event, the |
b/src/floating.c
30 |
@@ -298,16 +298,22 @@ void floating_enable(Con *con, bool automatic) { |
31 |
|
32 |
/* Check if we need to re-assign it to a different workspace because of its |
33 |
* coordinates and exit if that was done successfully. */ |
34 |
- if (floating_maybe_reassign_ws(nc)) |
35 |
+ if (floating_maybe_reassign_ws(nc)) { |
36 |
+ ipc_send_window_event("floating", con); |
37 |
return; |
38 |
+ } |
39 |
|
40 |
/* Sanitize coordinates: Check if they are on any output */ |
41 |
- if (get_output_containing(nc->rect.x, nc->rect.y) != NULL) |
42 |
+ if (get_output_containing(nc->rect.x, nc->rect.y) != NULL) { |
43 |
+ ipc_send_window_event("floating", con); |
44 |
return; |
45 |
+ } |
46 |
|
47 |
ELOG("No output found at destination coordinates, centering floating window on current ws\n"); |
48 |
nc->rect.x = ws->rect.x + (ws->rect.width / 2) - (nc->rect.width / 2); |
49 |
nc->rect.y = ws->rect.y + (ws->rect.height / 2) - (nc->rect.height / 2); |
50 |
+ |
51 |
+ ipc_send_window_event("floating", con); |
52 |
} |
53 |
|
54 |
void floating_disable(Con *con, bool automatic) { |
55 |
@@ -351,6 +357,8 @@ void floating_disable(Con *con, bool automatic) { |
56 |
|
57 |
if (set_focus) |
58 |
con_focus(con); |
59 |
+ |
60 |
+ ipc_send_window_event("floating", con); |
61 |
} |
62 |
|
63 |
/* |
b/testcases/t/231-ipc-floating-event.t
69 |
@@ -0,0 +1,59 @@ |
70 |
+#!perl |
71 |
+# vim:ts=4:sw=4:expandtab |
72 |
+# |
73 |
+# Please read the following documents before working on tests: |
74 |
+# • http://build.i3wm.org/docs/testsuite.html |
75 |
+# (or docs/testsuite) |
76 |
+# |
77 |
+# • http://build.i3wm.org/docs/lib-i3test.html |
78 |
+# (alternatively: perldoc ./testcases/lib/i3test.pm) |
79 |
+# |
80 |
+# • http://build.i3wm.org/docs/ipc.html |
81 |
+# (or docs/ipc) |
82 |
+# |
83 |
+# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf |
84 |
+# (unless you are already familiar with Perl) |
85 |
+# |
86 |
+# Test that the window::floating event works correctly. This event should be |
87 |
+# emitted when a window transitions to or from the floating state. |
88 |
+# Bug still in: 4.8-7-gf4a8253 |
89 |
+use i3test; |
90 |
+ |
91 |
+my $i3 = i3(get_socket_path()); |
92 |
+$i3->connect->recv; |
93 |
+ |
94 |
+my $cv = AnyEvent->condvar; |
95 |
+ |
96 |
+$i3->subscribe({ |
97 |
+ window => sub { |
98 |
+ my ($event) = @_; |
99 |
+ $cv->send($event) if $event->{change} eq 'floating'; |
100 |
+ } |
101 |
+ })->recv; |
102 |
+ |
103 |
+my $t; |
104 |
+$t = AnyEvent->timer( |
105 |
+ after => 0.5, |
106 |
+ cb => sub { |
107 |
+ $cv->send(0); |
108 |
+ } |
109 |
+); |
110 |
+ |
111 |
+my $win = open_window(); |
112 |
+ |
113 |
+cmd '[id="' . $win->{id} . '"] floating enable'; |
114 |
+my $e = $cv->recv; |
115 |
+ |
116 |
+isnt($e, 0, 'floating a container should send an ipc window event'); |
117 |
+is($e->{container}->{window}, $win->{id}, 'the event should contain information about the window'); |
118 |
+is($e->{container}->{floating}, 'user_on', 'the container should be floating'); |
119 |
+ |
120 |
+$cv = AnyEvent->condvar; |
121 |
+cmd '[id="' . $win->{id} . '"] floating disable'; |
122 |
+my $e = $cv->recv; |
123 |
+ |
124 |
+isnt($e, 0, 'disabling floating on a container should send an ipc window event'); |
125 |
+is($e->{container}->{window}, $win->{id}, 'the event should contain information about the window'); |
126 |
+is($e->{container}->{floating}, 'user_off', 'the container should not be floating'); |
127 |
+ |
128 |
+done_testing; |