Skip to content

Commit

Permalink
Add spatial navigation via MOD+{H,J,K,L}
Browse files Browse the repository at this point in the history
Based on an initial patch by David Zmick.
  • Loading branch information
martanne committed Jan 5, 2017
1 parent 7e80271 commit ca6a223
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
6 changes: 4 additions & 2 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ static KeyBinding bindings[] = {
{ { MOD, 'C', }, { create, { NULL, NULL, "$CWD" } } },
{ { MOD, 'x', 'x', }, { killclient, { NULL } } },
{ { MOD, 'j', }, { focusnext, { NULL } } },
{ { MOD, 'J', }, { focusnextnm, { NULL } } },
{ { MOD, 'K', }, { focusprevnm, { NULL } } },
{ { MOD, 'J', }, { focusdown, { NULL } } },
{ { MOD, 'K', }, { focusup, { NULL } } },
{ { MOD, 'H', }, { focusleft, { NULL } } },
{ { MOD, 'L', }, { focusright, { NULL } } },
{ { MOD, 'k', }, { focusprev, { NULL } } },
{ { MOD, 'f', }, { setlayout, { "[]=" } } },
{ { MOD, 'g', }, { setlayout, { "+++" } } },
Expand Down
10 changes: 8 additions & 2 deletions dvtm.1
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,16 @@ Focus next window.
Focus previous window.
.
.It Ic Mod-J
Focus next non minimized window.
Focus window below.
.
.It Ic Mod-K
Focus previous non minimized window.
Focus window above.
.
.It Ic Mod-H
Focus window to the left.
.
.It Ic Mod-L
Focus window to the right.
.
.It Ic Mod-[0..9]
Focus the [0..9]-th window.
Expand Down
49 changes: 49 additions & 0 deletions dvtm.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ static void focusnextnm(const char *args[]);
static void focusprev(const char *args[]);
static void focusprevnm(const char *args[]);
static void focuslast(const char *args[]);
static void focusup(const char *args[]);
static void focusdown(const char *args[]);
static void focusleft(const char *args[]);
static void focusright(const char *args[]);
static void killclient(const char *args[]);
static void paste(const char *args[]);
static void quit(const char *args[]);
Expand Down Expand Up @@ -1235,6 +1239,51 @@ focuslast(const char *args[]) {
focus(lastsel);
}

static void
focusup(const char *args[]) {
if (!sel)
return;
/* avoid vertical separator, hence +1 in x direction */
Client *c = get_client_by_coord(sel->x + 1, sel->y - 1);
if (c)
focus(c);
else
focusprev(args);
}

static void
focusdown(const char *args[]) {
if (!sel)
return;
Client *c = get_client_by_coord(sel->x, sel->y + sel->h);
if (c)
focus(c);
else
focusnext(args);
}

static void
focusleft(const char *args[]) {
if (!sel)
return;
Client *c = get_client_by_coord(sel->x - 2, sel->y);
if (c)
focus(c);
else
focusprev(args);
}

static void
focusright(const char *args[]) {
if (!sel)
return;
Client *c = get_client_by_coord(sel->x + sel->w + 1, sel->y);
if (c)
focus(c);
else
focusnext(args);
}

static void
killclient(const char *args[]) {
if (!sel)
Expand Down

0 comments on commit ca6a223

Please sign in to comment.