From 2d7110279600b5c106e10c19b2d60afa88e288d1 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Thu, 14 Jul 2011 23:43:57 +0200 Subject: [PATCH] Bugfix: Switch to appropriate workspace when using 'focus' (+test) (Thanks rogutes) Fixes #432 --- src/cmdparse.y | 2 ++ testcases/t/11-goto.t | 14 +++++++++++++- testcases/t/17-workspace.t | 23 ----------------------- testcases/t/36-floating-ws-empty.t | 5 ----- testcases/t/lib/i3test.pm | 20 +++++++++++++++++++- 5 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/cmdparse.y b/src/cmdparse.y index 0b80b6b3..a8e190e7 100644 --- a/src/cmdparse.y +++ b/src/cmdparse.y @@ -412,6 +412,8 @@ focus: int count = 0; TAILQ_FOREACH(current, &owindows, owindows) { + Con *ws = con_get_workspace(current->con); + workspace_show(ws->name); LOG("focusing %p / %s\n", current->con, current->con->name); con_focus(current->con); count++; diff --git a/testcases/t/11-goto.t b/testcases/t/11-goto.t index 4eedb56c..ed8c4358 100644 --- a/testcases/t/11-goto.t +++ b/testcases/t/11-goto.t @@ -12,7 +12,7 @@ BEGIN { my $x = X11::XCB::Connection->new; my $i3 = i3("/tmp/nestedcons"); -fresh_workspace; +my $tmp = fresh_workspace; cmd 'split h'; @@ -73,5 +73,17 @@ is($focus, $top->id, "Top window focused"); $focus = focus_after(qq|[con_mark="$random_mark" con_mark="$random_mark"] focus|); is($focus, $mid->id, "goto worked"); +##################################################################### +# Check whether the focus command will switch to a different +# workspace if necessary +##################################################################### + +my $tmp2 = fresh_workspace; + +is(focused_ws(), $tmp2, 'tmp2 now focused'); + +cmd qq|[con_mark="$random_mark"] focus|; + +is(focused_ws(), $tmp, 'tmp now focused'); done_testing; diff --git a/testcases/t/17-workspace.t b/testcases/t/17-workspace.t index 32f82969..16e87ce1 100644 --- a/testcases/t/17-workspace.t +++ b/testcases/t/17-workspace.t @@ -7,11 +7,6 @@ use List::Util qw(first); use i3test; -sub workspace_exists { - my ($name) = @_; - ($name ~~ @{get_workspace_names()}) -} - my $tmp = fresh_workspace; ok(workspace_exists($tmp), 'workspace created'); # if the workspace could not be created, we cannot run any other test @@ -53,24 +48,6 @@ cmd 'open'; ok(workspace_exists($tmp), 'workspace tmp still exists'); ok(workspace_exists($otmp), 'workspace otmp created'); -sub focused_ws_con { - my $i3 = i3("/tmp/nestedcons"); - my $tree = $i3->get_tree->recv; - my @outputs = @{$tree->{nodes}}; - my @cons; - for my $output (@outputs) { - # get the first CT_CON of each output - my $content = first { $_->{type} == 2 } @{$output->{nodes}}; - my @focused = @{$content->{focus}}; - return first { $_->{id} == $focused[0] } @{$content->{nodes}}; - } -} - -sub focused_ws { - my $con = focused_ws_con; - return $con->{name}; -} - is(focused_ws(), $otmp, 'focused workspace is otmp'); cmd 'workspace prev'; diff --git a/testcases/t/36-floating-ws-empty.t b/testcases/t/36-floating-ws-empty.t index 2ea16936..67986251 100644 --- a/testcases/t/36-floating-ws-empty.t +++ b/testcases/t/36-floating-ws-empty.t @@ -17,11 +17,6 @@ my $tmp = fresh_workspace; # 1: open a floating window, get it mapped ############################################################################# -sub workspace_exists { - my ($name) = @_; - ($name ~~ @{get_workspace_names()}) -} - ok(workspace_exists($tmp), "workspace $tmp exists"); my $x = X11::XCB::Connection->new; diff --git a/testcases/t/lib/i3test.pm b/testcases/t/lib/i3test.pm index ed75faff..7bfad56a 100644 --- a/testcases/t/lib/i3test.pm +++ b/testcases/t/lib/i3test.pm @@ -14,7 +14,7 @@ use Try::Tiny; use v5.10; use Exporter (); -our @EXPORT = qw(get_workspace_names get_unused_workspace fresh_workspace get_ws_content get_ws get_focused open_empty_con open_standard_window get_dock_clients cmd does_i3_live exit_gracefully); +our @EXPORT = qw(get_workspace_names get_unused_workspace fresh_workspace get_ws_content get_ws get_focused open_empty_con open_standard_window get_dock_clients cmd does_i3_live exit_gracefully workspace_exists focused_ws); my $tester = Test::Builder->new(); @@ -167,6 +167,24 @@ sub cmd { i3("/tmp/nestedcons")->command(@_)->recv } +sub workspace_exists { + my ($name) = @_; + ($name ~~ @{get_workspace_names()}) +} + +sub focused_ws { + my $i3 = i3("/tmp/nestedcons"); + my $tree = $i3->get_tree->recv; + my @outputs = @{$tree->{nodes}}; + my @cons; + for my $output (@outputs) { + # get the first CT_CON of each output + my $content = first { $_->{type} == 2 } @{$output->{nodes}}; + my $first = first { $_->{fullscreen_mode} == 1 } @{$content->{nodes}}; + return $first->{name} + } +} + sub does_i3_live { my $tree = i3('/tmp/nestedcons')->get_tree->recv; my @nodes = @{$tree->{nodes}}; -- 2.39.5