From 098b0e69763080bad408ed73592b26eecdf1f93e Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Fri, 22 Feb 2019 19:41:30 +0200 Subject: [PATCH] create_workspace_on_output: send workspace init event Fixes #3595 Like the issue mentions: > instead of the newly created workspace (not referenced by variable > here) the `"init"` event is fired with the current workspace (`ws`). Plus, there was another issue where duplicate workspace init events where being sent because of workspace_get(). 304-ipc-workspace-init.t: Subtest "move workspace to output" fails with current next. Fixes #3631 No event was being sent here: https://github.com/i3/i3/blob/2d6e09a66ad9b3e01588c515ae66476de8903754/src/randr.c#L487 533-randr15.t: I confirmed that SKIP still works if the xrandr command fails. Added test fails with current next. --- src/workspace.c | 9 ++-- testcases/t/304-ipc-workspace-init.t | 69 ++++++++++++++++++++++++++++ testcases/t/533-randr15.t | 14 ++++-- 3 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 testcases/t/304-ipc-workspace-init.t diff --git a/src/workspace.c b/src/workspace.c index 2af88d73..5c2c48fa 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -289,6 +289,7 @@ Con *create_workspace_on_output(Output *output, Con *content) { ws->workspace_layout = config.default_layout; _workspace_apply_default_orientation(ws); + ipc_send_workspace_event("init", ws, NULL); return ws; } @@ -1004,13 +1005,11 @@ bool workspace_move_to_output(Con *ws, Output *output) { break; } - /* if we couldn't create the workspace using an assignment, create - * it on the output */ + /* if we couldn't create the workspace using an assignment, create it on + * the output. Workspace init IPC events are sent either by + * workspace_get or create_workspace_on_output. */ if (!used_assignment) create_workspace_on_output(current_output, ws->parent); - - /* notify the IPC listeners */ - ipc_send_workspace_event("init", ws, NULL); } DLOG("Detaching\n"); diff --git a/testcases/t/304-ipc-workspace-init.t b/testcases/t/304-ipc-workspace-init.t new file mode 100644 index 00000000..0eb838dc --- /dev/null +++ b/testcases/t/304-ipc-workspace-init.t @@ -0,0 +1,69 @@ +#!perl +# vim:ts=4:sw=4:expandtab +# +# Please read the following documents before working on tests: +# • https://build.i3wm.org/docs/testsuite.html +# (or docs/testsuite) +# +# • https://build.i3wm.org/docs/lib-i3test.html +# (alternatively: perldoc ./testcases/lib/i3test.pm) +# +# • https://build.i3wm.org/docs/ipc.html +# (or docs/ipc) +# +# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf +# (unless you are already familiar with Perl) +# +# Test that the workspace init event is correctly sent. +# Ticket: #3631 +# Bug still in: 4.16-85-g2d6e09a6 + +use i3test i3_config => <{change} eq 'init' } @events; + my $len = scalar @init; + is($len, $num_events, "Received $num_events workspace::init event"); + $num_events = $len if $len < $num_events; + for my $idx (0 .. $num_events - 1) { + my $name = shift; + my $output = shift; + is($init[$idx]->{current}->{name}, $name, "workspace name $name matches"); + is($init[$idx]->{current}->{output}, $output, "workspace output $output matches"); + } +} + +subtest 'focus outputs', \&workspace_init_subtest, 'focus output fake-1, focus output fake-0', 0; +subtest 'new workspaces', \&workspace_init_subtest, + 'workspace a, workspace b, workspace a, workspace a', 3, 'a', + 'fake-0', 'b', 'fake-0', 'a', 'fake-0'; +open_window; # Prevent workspace "a" from being deleted. +subtest 'return on existing workspace', \&workspace_init_subtest, + 'workspace a, workspace b, workspace a', 1, 'b', 'fake-0'; +subtest 'assigned workspace is already open', \&workspace_init_subtest, + 'workspace X, workspace b, workspace a', 1, 'b', 'fake-1'; +subtest 'assigned workspace was deleted and now is initialized again', \&workspace_init_subtest, + 'workspace X, workspace b, workspace a', 2, 'X', 'fake-1', 'b', 'fake-1'; +subtest 'move workspace to output', \&workspace_init_subtest, + 'move workspace to output fake-1, move workspace to output fake-0', 2, '1', 'fake-0', 'X', + 'fake-1'; +subtest 'move window to workspace', \&workspace_init_subtest, 'move to workspace b', 1, 'b', + 'fake-0'; +subtest 'back_and_forth', \&workspace_init_subtest, + 'workspace b, workspace back_and_forth, workspace b', 1, + 'a', 'fake-0'; +subtest 'move window to workspace back_and_forth', \&workspace_init_subtest, + 'move window to workspace back_and_forth', 1, 'a', 'fake-0'; + +done_testing; diff --git a/testcases/t/533-randr15.t b/testcases/t/533-randr15.t index 9bbdd74b..51d1c9f6 100644 --- a/testcases/t/533-randr15.t +++ b/testcases/t/533-randr15.t @@ -130,10 +130,16 @@ $tree = i3->get_tree->recv; is_deeply(\@outputs, [ '__i3', 'default' ], 'outputs are __i3 and default'); SKIP: { - skip 'xrandr --setmonitor failed (xrandr too old?)', 1 unless - system(q|xrandr --setmonitor up2414q 3840/527x2160/296+1280+0 none|) == 0; - - sync_with_i3; + my @events = events_for( + sub { + skip 'xrandr --setmonitor failed (xrandr too old?)', 1 + unless system(q|xrandr --setmonitor up2414q 3840/527x2160/296+1280+0 none|) == 0; + }, + "workspace"); + + my @init = grep { $_->{change} eq 'init' } @events; + is(scalar @init, 1, 'Received 1 workspace::init event'); + is($init[0]->{current}->{output}, 'up2414q', 'Workspace initialized in up2414q'); $tree = i3->get_tree->recv; @outputs = map { $_->{name} } @{$tree->{nodes}}; -- 2.39.2