From d68e4710fed1ae28cb5889579d63f1cdc40157c9 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 8 Jun 2011 20:49:49 +0200 Subject: [PATCH] CONFIG BREAK: kick the 'next'/'prev' commands, introduce 'focus left' etc. Instead of the cryptic next/prev commands, we now provide an argument to the focus command. Userguide and default config is updated. --- docs/userguide | 13 ++++---- i3.config | 16 ++++----- src/cmdparse.l | 1 - src/cmdparse.y | 52 ++++++++++++++++-------------- testcases/t/06-focus.t | 8 ++--- testcases/t/11-goto.t | 4 +-- testcases/t/21-next-prev.t | 32 ++++++------------ testcases/t/24-move.t | 4 +-- testcases/t/29-focus-after-close.t | 4 +-- testcases/t/31-stacking-order.t | 8 ++--- testcases/t/40-focus-lost.t | 2 +- 11 files changed, 66 insertions(+), 78 deletions(-) diff --git a/docs/userguide b/docs/userguide index aea0e760..b7a8ff09 100644 --- a/docs/userguide +++ b/docs/userguide @@ -629,23 +629,22 @@ bindsym Mod1+t mode toggle === Focusing/Moving containers -To change the focus, use one of the +prev h+, +next v+, +prev v+ and +next h+ -commands, meaning left, down, up, right (respectively). +To change the focus, use the focus command: +focus left+, +focus right+, +focus down+ and +focus up+. For moving, use +move left+, +move right+, +move down+ and +move up+. *Examples*: ---------------------- # Focus clients on the left, bottom, top, right: -bindsym Mod1+j prev h -bindsym Mod1+k next v -bindsym Mod1+j prev v -bindsym Mod1+semicolon next h +bindsym Mod1+j focus left +bindsym Mod1+k focus down +bindsym Mod1+l focus up +bindsym Mod1+semicolon focus right # Move client to the left, bottom, top, right: bindsym Mod1+j move left bindsym Mod1+k move down -bindsym Mod1+j move up +bindsym Mod1+l move up bindsym Mod1+semicolon move right ---------------------- diff --git a/i3.config b/i3.config index b0cbc926..847c4b14 100644 --- a/i3.config +++ b/i3.config @@ -57,16 +57,16 @@ bindsym Mod1+Shift+j reload bindsym Mod1+Shift+l exit # Focus (Mod1+n/r/t/d) -bindsym Mod1+n prev h -bindsym Mod1+r next v -bindsym Mod1+t prev v -bindsym Mod1+d next h +bindsym Mod1+n focus left +bindsym Mod1+r focus down +bindsym Mod1+t focus up +bindsym Mod1+d focus right # alternatively, you can use the cursor keys: -bindsym Mod1+Left prev h -bindsym Mod1+Right next h -bindsym Mod1+Down next v -bindsym Mod1+Up prev v +bindsym Mod1+Left focus left +bindsym Mod1+Down focus down +bindsym Mod1+Up focus up +bindsym Mod1+Right focus right # Move bindsym Mod1+Shift+n move left diff --git a/src/cmdparse.l b/src/cmdparse.l index b366e48b..91aed5e3 100644 --- a/src/cmdparse.l +++ b/src/cmdparse.l @@ -120,7 +120,6 @@ workspace { WS_STRING; return TOK_WORKSPACE; } focus { return TOK_FOCUS; } move { return TOK_MOVE; } open { return TOK_OPEN; } -next { return TOK_NEXT; } prev { return TOK_PREV; } split { return TOK_SPLIT; } horizontal { return TOK_HORIZONTAL; } diff --git a/src/cmdparse.y b/src/cmdparse.y index f3475d9d..08f02c61 100644 --- a/src/cmdparse.y +++ b/src/cmdparse.y @@ -140,7 +140,6 @@ char *parse_cmd(const char *new) { %token TOK_FOCUS "focus" %token TOK_MOVE "move" %token TOK_OPEN "open" -%token TOK_NEXT "next" %token TOK_PREV "prev" %token TOK_SPLIT "split" %token TOK_HORIZONTAL "horizontal" @@ -333,8 +332,6 @@ operation: | kill | open | fullscreen - | next - | prev | split | mode | level @@ -400,6 +397,33 @@ focus: tree_render(); } + | TOK_FOCUS direction + { + int direction = $2; + switch (direction) { + case TOK_LEFT: + LOG("Focusing left\n"); + tree_next('p', HORIZ); + break; + case TOK_RIGHT: + LOG("Focusing right\n"); + tree_next('n', HORIZ); + break; + case TOK_UP: + LOG("Focusing up\n"); + tree_next('p', VERT); + break; + case TOK_DOWN: + LOG("Focusing down\n"); + tree_next('n', VERT); + break; + default: + ELOG("Invalid focus direction (%d)\n", direction); + break; + } + + tree_render(); + } ; kill: @@ -469,28 +493,6 @@ fullscreen: } ; -next: - TOK_NEXT direction - { - /* TODO: use matches */ - printf("should select next window in direction %c\n", $2); - tree_next('n', ($2 == 'v' ? VERT : HORIZ)); - - tree_render(); - } - ; - -prev: - TOK_PREV direction - { - /* TODO: use matches */ - printf("should select prev window in direction %c\n", $2); - tree_next('p', ($2 == 'v' ? VERT : HORIZ)); - - tree_render(); - } - ; - split: TOK_SPLIT direction { diff --git a/testcases/t/06-focus.t b/testcases/t/06-focus.t index 798a5e69..826588d5 100644 --- a/testcases/t/06-focus.t +++ b/testcases/t/06-focus.t @@ -44,20 +44,20 @@ sub focus_after { $focus = $x->input_focus; is($focus, $bottom->id, "Latest window focused"); -$focus = focus_after("prev v"); +$focus = focus_after('focus up'); is($focus, $mid->id, "Middle window focused"); -$focus = focus_after("prev v"); +$focus = focus_after('focus up'); is($focus, $top->id, "Top window focused"); ##################################################################### # Test focus wrapping ##################################################################### -$focus = focus_after("prev v"); +$focus = focus_after('focus up'); is($focus, $bottom->id, "Bottom window focused (wrapping to the top works)"); -$focus = focus_after("next v"); +$focus = focus_after('focus down'); is($focus, $top->id, "Top window focused (wrapping to the bottom works)"); ############################################### diff --git a/testcases/t/11-goto.t b/testcases/t/11-goto.t index 929af5c2..7aebc880 100644 --- a/testcases/t/11-goto.t +++ b/testcases/t/11-goto.t @@ -45,7 +45,7 @@ sub focus_after { $focus = $x->input_focus; is($focus, $bottom->id, "Latest window focused"); -$focus = focus_after("prev h"); +$focus = focus_after('focus left'); is($focus, $mid->id, "Middle window focused"); ##################################################################### @@ -59,7 +59,7 @@ is($focus, $mid->id, "focus unchanged"); $i3->command("mark $random_mark")->recv; -$focus = focus_after("prev h"); +$focus = focus_after('focus left'); is($focus, $top->id, "Top window focused"); $focus = focus_after(qq|[con_mark="$random_mark"] focus|); diff --git a/testcases/t/21-next-prev.t b/testcases/t/21-next-prev.t index 042573a4..447be315 100644 --- a/testcases/t/21-next-prev.t +++ b/testcases/t/21-next-prev.t @@ -8,23 +8,23 @@ use i3test; my $tmp = fresh_workspace; ###################################################################### -# Open one container, verify that 'next v' and 'next h' do nothing +# Open one container, verify that 'focus down' and 'focus right' do nothing ###################################################################### cmd 'open'; my ($nodes, $focus) = get_ws_content($tmp); my $old_focused = $focus->[0]; -cmd 'next v'; +cmd 'focus down'; ($nodes, $focus) = get_ws_content($tmp); is($focus->[0], $old_focused, 'focus did not change with only one con'); -cmd 'next h'; +cmd 'focus right'; ($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 +# Open another container, verify that 'focus right' switches ###################################################################### my $left = $old_focused; @@ -38,44 +38,32 @@ cmd 'open'; isnt($old_focused, $focus->[0], 'new container is focused'); my $right = $focus->[0]; -cmd 'next h'; +cmd 'focus right'; ($nodes, $focus) = get_ws_content($tmp); isnt($focus->[0], $right, 'focus did change'); is($focus->[0], $left, 'left container focused (wrapping)'); -cmd 'next h'; +cmd 'focus right'; ($nodes, $focus) = get_ws_content($tmp); is($focus->[0], $mid, 'middle container focused'); -cmd 'next h'; +cmd 'focus right'; ($nodes, $focus) = get_ws_content($tmp); is($focus->[0], $right, 'right container focused'); -cmd 'prev h'; +cmd 'focus left'; ($nodes, $focus) = get_ws_content($tmp); is($focus->[0], $mid, 'middle container focused'); -cmd 'prev h'; +cmd 'focus left'; ($nodes, $focus) = get_ws_content($tmp); is($focus->[0], $left, 'left container focused'); -cmd 'prev h'; +cmd 'focus left'; ($nodes, $focus) = get_ws_content($tmp); is($focus->[0], $right, 'right container focused'); -###################################################################### -# Test synonyms (horizontal/vertical instead of h/v) -###################################################################### - -cmd 'prev horizontal'; -($nodes, $focus) = get_ws_content($tmp); -is($focus->[0], $mid, 'middle container focused'); - -cmd 'next horizontal'; -($nodes, $focus) = get_ws_content($tmp); -is($focus->[0], $right, 'right container focused'); - ###################################################################### # Test focus command ###################################################################### diff --git a/testcases/t/24-move.t b/testcases/t/24-move.t index ebb7dc66..9d200aa9 100644 --- a/testcases/t/24-move.t +++ b/testcases/t/24-move.t @@ -121,11 +121,11 @@ cmd "open"; cmd "open"; cmd "split v"; cmd "open"; -cmd "prev h"; +cmd 'focus left'; cmd "split v"; cmd "open"; cmd "move right"; -cmd "prev h"; +cmd 'focus left'; cmd "move right"; $content = get_ws_content($otmp); diff --git a/testcases/t/29-focus-after-close.t b/testcases/t/29-focus-after-close.t index b34e6686..dec9bb92 100644 --- a/testcases/t/29-focus-after-close.t +++ b/testcases/t/29-focus-after-close.t @@ -64,11 +64,11 @@ cmd 'split v'; $first = open_empty_con($i3); my $bottom = open_empty_con($i3); -cmd 'prev v'; +cmd 'focus up'; cmd 'split h'; my $middle = open_empty_con($i3); my $right = open_empty_con($i3); -cmd 'next v'; +cmd 'focus down'; # We have the following layout now (second is focused): # .----------------------------. diff --git a/testcases/t/31-stacking-order.t b/testcases/t/31-stacking-order.t index 78a35cce..4ffafa17 100644 --- a/testcases/t/31-stacking-order.t +++ b/testcases/t/31-stacking-order.t @@ -28,10 +28,10 @@ isnt($first, $second, 'two different containers opened'); cmd 'layout stacking'; is(get_focused($tmp), $second, 'second container still focused'); -cmd 'next v'; +cmd 'focus down'; is(get_focused($tmp), $first, 'first container focused'); -cmd 'prev v'; +cmd 'focus up'; is(get_focused($tmp), $second, 'second container focused again'); ############################################################## @@ -42,10 +42,10 @@ cmd 'level up'; cmd 'split h'; cmd 'level down'; -cmd 'next v'; +cmd 'focus down'; is(get_focused($tmp), $first, 'first container focused'); -cmd 'prev v'; +cmd 'focus up'; is(get_focused($tmp), $second, 'second container focused again'); diff --git a/testcases/t/40-focus-lost.t b/testcases/t/40-focus-lost.t index 4158d1f9..a39d74ca 100644 --- a/testcases/t/40-focus-lost.t +++ b/testcases/t/40-focus-lost.t @@ -36,7 +36,7 @@ diag("left = " . $left->id . ", mid = " . $mid->id . ", right = " . $right->id); is($x->input_focus, $right->id, 'Right window focused'); -cmd 'prev h'; +cmd 'focus left'; is($x->input_focus, $mid->id, 'Mid window focused'); -- 2.39.5