From: Orestis Floros Date: Tue, 27 Mar 2018 22:57:54 +0000 (+0300) Subject: Move get_output_for_workspace() to i3test X-Git-Tag: 4.16~68^2~2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1d5b43c18f5de8e6282c4e78bb9db7988dab169d;p=i3%2Fi3 Move get_output_for_workspace() to i3test --- diff --git a/testcases/lib/i3test.pm.in b/testcases/lib/i3test.pm.in index 68ac1ee5..5734eca7 100644 --- a/testcases/lib/i3test.pm.in +++ b/testcases/lib/i3test.pm.in @@ -26,6 +26,7 @@ use Data::Dumper (); use Exporter (); our @EXPORT = qw( get_workspace_names + get_output_for_workspace get_unused_workspace fresh_workspace get_ws_content @@ -402,6 +403,29 @@ sub get_workspace_names { [ map { $_->{name} } @cons ] } +=head2 get_output_for_workspace() + +Returns the name of the output on which this workspace resides + + cmd 'focus output fake-1'; + cmd 'workspace 1'; + is(get_output_for_workspace('1', 'fake-0', 'Workspace 1 in output fake-0'); + +=cut +sub get_output_for_workspace { + my $ws_name = shift @_; + my $i3 = i3(get_socket_path()); + my $tree = $i3->get_tree->recv; + my @outputs = @{$tree->{nodes}}; + + foreach (grep { not $_->{name} =~ /^__/ } @outputs) { + my $output = $_->{name}; + foreach (grep { $_->{name} =~ "content" } @{$_->{nodes}}) { + return $output if $_->{nodes}[0]->{name} =~ $ws_name; + } + } +} + =head2 get_unused_workspace Returns a workspace name which has not yet been used. See also diff --git a/testcases/t/518-interpret-workspace-numbers.t b/testcases/t/518-interpret-workspace-numbers.t index e9ea76c4..7fd86d72 100644 --- a/testcases/t/518-interpret-workspace-numbers.t +++ b/testcases/t/518-interpret-workspace-numbers.t @@ -30,21 +30,6 @@ workspace 2:override output fake-1 fake-outputs 1024x768+0+0,1024x768+1024+0 EOT -my $i3 = i3(get_socket_path()); -$i3->connect->recv; - -# Returns the name of the output on which this workspace resides -sub get_output_for_workspace { - my $ws_name = shift @_; - - foreach (grep { not $_->{name} =~ /^__/ } @{$i3->get_tree->recv->{nodes}}) { - my $output = $_->{name}; - foreach (grep { $_->{name} =~ "content" } @{$_->{nodes}}) { - return $output if $_->{nodes}[0]->{name} =~ $ws_name; - } - } -} - ################################################################################ # Workspace assignments with bare numbers should be interpreted as `workspace # number` config directives. Any workspace beginning with that number should be diff --git a/testcases/t/522-rename-assigned-workspace.t b/testcases/t/522-rename-assigned-workspace.t index 5c9f2ff3..f6319729 100644 --- a/testcases/t/522-rename-assigned-workspace.t +++ b/testcases/t/522-rename-assigned-workspace.t @@ -31,21 +31,6 @@ workspace baz output fake-1 workspace 5 output left EOT -my $i3 = i3(get_socket_path()); -$i3->connect->recv; - -# Returns the name of the output on which this workspace resides -sub get_output_for_workspace { - my $ws_name = shift @_; - - foreach (grep { not $_->{name} =~ /^__/ } @{$i3->get_tree->recv->{nodes}}) { - my $output = $_->{name}; - foreach (grep { $_->{name} =~ "content" } @{$_->{nodes}}) { - return $output if $_->{nodes}[0]->{name} =~ $ws_name; - } - } -} - ########################################################################## # Renaming the workspace to an unassigned name does not move the workspace # (regression test)