implement 'next' in the new command parser (testcase unfinished)
This commit is contained in:
parent
f10a3d9b75
commit
d8307f4b4a
|
@ -99,6 +99,7 @@ workspace { BEGIN(WANT_WS_STRING); return TOK_WORKSPACE; }
|
||||||
focus { return TOK_FOCUS; }
|
focus { return TOK_FOCUS; }
|
||||||
move { return TOK_MOVE; }
|
move { return TOK_MOVE; }
|
||||||
open { return TOK_OPEN; }
|
open { return TOK_OPEN; }
|
||||||
|
next { return TOK_NEXT; }
|
||||||
|
|
||||||
class { BEGIN(WANT_QSTRING); return TOK_CLASS; }
|
class { BEGIN(WANT_QSTRING); return TOK_CLASS; }
|
||||||
id { BEGIN(WANT_QSTRING); return TOK_ID; }
|
id { BEGIN(WANT_QSTRING); return TOK_ID; }
|
||||||
|
|
|
@ -86,6 +86,7 @@ void parse_cmd(const char *new) {
|
||||||
|
|
||||||
%union {
|
%union {
|
||||||
char *string;
|
char *string;
|
||||||
|
char chr;
|
||||||
}
|
}
|
||||||
|
|
||||||
%token TOK_ATTACH "attach"
|
%token TOK_ATTACH "attach"
|
||||||
|
@ -110,6 +111,7 @@ void parse_cmd(const char *new) {
|
||||||
%token TOK_FOCUS "focus"
|
%token TOK_FOCUS "focus"
|
||||||
%token TOK_MOVE "move"
|
%token TOK_MOVE "move"
|
||||||
%token TOK_OPEN "open"
|
%token TOK_OPEN "open"
|
||||||
|
%token TOK_NEXT "next"
|
||||||
|
|
||||||
%token TOK_CLASS "class"
|
%token TOK_CLASS "class"
|
||||||
%token TOK_ID "id"
|
%token TOK_ID "id"
|
||||||
|
@ -249,6 +251,7 @@ operation:
|
||||||
| kill
|
| kill
|
||||||
| open
|
| open
|
||||||
| fullscreen
|
| fullscreen
|
||||||
|
| next
|
||||||
;
|
;
|
||||||
|
|
||||||
exec:
|
exec:
|
||||||
|
@ -333,3 +336,18 @@ fullscreen:
|
||||||
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
next:
|
||||||
|
TOK_NEXT WHITESPACE direction
|
||||||
|
{
|
||||||
|
printf("should select next window in direction %c\n", $<chr>3);
|
||||||
|
tree_next('n', ($<chr>3 == 'v' ? VERT : HORIZ));
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
direction:
|
||||||
|
'h' { $<chr>$ = 'h'; }
|
||||||
|
| 'horizontal' { $<chr>$ = 'h'; }
|
||||||
|
| 'v' { $<chr>$ = 'v'; }
|
||||||
|
| 'vertical' { $<chr>$ = 'v'; }
|
||||||
|
;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
test:
|
test:
|
||||||
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(1)" -It/lib t/03* t/05*
|
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(1)" -It/lib t/21*
|
||||||
|
|
||||||
all: test
|
all: test
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
#!perl
|
||||||
|
# vim:ts=4:sw=4:expandtab
|
||||||
|
#
|
||||||
|
# Tests focus switching (next/prev)
|
||||||
|
#
|
||||||
|
use i3test tests => 4;
|
||||||
|
use X11::XCB qw(:all);
|
||||||
|
use v5.10;
|
||||||
|
|
||||||
|
my $i3 = i3("/tmp/nestedcons");
|
||||||
|
|
||||||
|
my $tmp = get_unused_workspace();
|
||||||
|
$i3->command("workspace $tmp")->recv;
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
# Open one container, verify that 'next v' and 'next h' do nothing
|
||||||
|
######################################################################
|
||||||
|
$i3->command('open')->recv;
|
||||||
|
|
||||||
|
my ($nodes, $focus) = get_ws_content($tmp);
|
||||||
|
my $old_focused = $focus->[0];
|
||||||
|
|
||||||
|
$i3->command('next v')->recv;
|
||||||
|
($nodes, $focus) = get_ws_content($tmp);
|
||||||
|
is($focus->[0], $old_focused, 'focus did not change with only one con');
|
||||||
|
|
||||||
|
$i3->command('next h')->recv;
|
||||||
|
($nodes, $focus) = get_ws_content($tmp);
|
||||||
|
is($focus->[0], $old_focused, 'focus did not change with only one con');
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
# Open another container, verify that 'next h' switches
|
||||||
|
######################################################################
|
||||||
|
$i3->command('open')->recv;
|
||||||
|
|
||||||
|
($nodes, $focus) = get_ws_content($tmp);
|
||||||
|
isnt($old_focused, $focus->[0], 'new container is focused');
|
||||||
|
$old_focused = $focus->[0];
|
||||||
|
|
||||||
|
$i3->command('next h')->recv;
|
||||||
|
|
||||||
|
($nodes, $focus) = get_ws_content($tmp);
|
||||||
|
isnt($focus->[0], $old_focused, 'focus did change');
|
||||||
|
|
||||||
|
#
|
||||||
|
# TODO: extend this test-case:
|
||||||
|
# - implement prev
|
||||||
|
# - wrapping (no horizontal switch possible, goes level-up)
|
||||||
|
# - going level-up "manually"
|
||||||
|
# - different synonyms (horizontal/vertical)
|
||||||
|
|
||||||
|
diag( "Testing i3, Perl $], $^X" );
|
|
@ -62,17 +62,18 @@ sub get_unused_workspace {
|
||||||
|
|
||||||
#
|
#
|
||||||
# returns the content (== tree, starting from the node of a workspace)
|
# returns the content (== tree, starting from the node of a workspace)
|
||||||
# of a workspace
|
# of a workspace. If called in array context, also includes the focus
|
||||||
|
# stack of the workspace
|
||||||
#
|
#
|
||||||
sub get_ws_content {
|
sub get_ws_content {
|
||||||
my ($name) = @_;
|
my ($name) = @_;
|
||||||
my $i3 = i3("/tmp/nestedcons");
|
my $i3 = i3("/tmp/nestedcons");
|
||||||
my $tree = $i3->get_workspaces->recv;
|
my $tree = $i3->get_workspaces->recv;
|
||||||
my @ws = map { @{$_->{nodes}} } @{$tree->{nodes}};
|
my @ws = map { @{$_->{nodes}} } @{$tree->{nodes}};
|
||||||
my @cons = map { $_->{nodes} } grep { $_->{name} eq $name } @ws;
|
my @cons = grep { $_->{name} eq $name } @ws;
|
||||||
# as there can only be one workspace with this name, we can safely
|
# as there can only be one workspace with this name, we can safely
|
||||||
# return the first entry
|
# return the first entry
|
||||||
return $cons[0];
|
return wantarray ? ($cons[0]->{nodes}, $cons[0]->{focus}) : $cons[0]->{nodes};
|
||||||
}
|
}
|
||||||
|
|
||||||
1
|
1
|
||||||
|
|
Loading…
Reference in New Issue