From: Michael Stapelberg Date: Wed, 4 Mar 2009 22:45:44 +0000 (+0100) Subject: Implement wrapping, selecting containers is now Mod1+Ctrl+h/j/k/l X-Git-Tag: 3.a~96 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=bde67a179ef4ce0b6d2a04fab1e1bc900d2e8d0e;p=i3%2Fi3 Implement wrapping, selecting containers is now Mod1+Ctrl+h/j/k/l --- diff --git a/i3.config b/i3.config index 2f49bbaf..69d996d2 100644 --- a/i3.config +++ b/i3.config @@ -16,11 +16,17 @@ bind Mod1+45 j bind Mod1+46 k bind Mod1+47 l +# Focus Container (Mod1+j/k/l/;) +bind Mod1+Control+44 wch +bind Mod1+Control+45 wcj +bind Mod1+Control+46 wck +bind Mod1+Control+47 wcl + # Snap (Mod1+Control+j/k/l/;) -bind Mod1+Control+44 sh -bind Mod1+Control+45 sj -bind Mod1+Control+46 sk -bind Mod1+Control+47 sl +bind Mod1+Shift+Control+44 sh +bind Mod1+Shift+Control+45 sj +bind Mod1+Shift+Control+46 sk +bind Mod1+Shift+Control+47 sl # Move (Mod1+Shift+j/k/l/;) bind Mod1+Shift+44 mh diff --git a/src/commands.c b/src/commands.c index 948e8710..810a04ba 100644 --- a/src/commands.c +++ b/src/commands.c @@ -30,24 +30,26 @@ static bool focus_window_in_container(xcb_connection_t *conn, Container *contain if (container->currently_focused == NULL) return false; + /* Get the previous/next client or wrap around */ Client *candidate = NULL; - if (direction == D_UP) - candidate = CIRCLEQ_PREV(container->currently_focused, clients); - else if (direction == D_DOWN) - candidate = CIRCLEQ_NEXT(container->currently_focused, clients); - else printf("Direction not implemented!\n"); - - /* If we don’t have anything to select, we’re done */ - if (candidate == CIRCLEQ_END(&(container->clients))) - return false; + if (direction == D_UP) { + if ((candidate = CIRCLEQ_PREV_OR_NULL(&(container->clients), container->currently_focused, clients)) == NULL) + candidate = CIRCLEQ_LAST(&(container->clients)); + } + else if (direction == D_DOWN) { + if ((candidate = CIRCLEQ_NEXT_OR_NULL(&(container->clients), container->currently_focused, clients)) == NULL) + candidate = CIRCLEQ_FIRST(&(container->clients)); + } else printf("Direction not implemented!\n"); - /* Set focus if we could successfully move */ + /* Set focus */ set_focus(conn, candidate); return true; } -static void focus_window(xcb_connection_t *conn, direction_t direction) { +typedef enum { THING_WINDOW, THING_CONTAINER } thing_t; + +static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t thing) { printf("focusing direction %d\n", direction); int new_row = current_row, @@ -61,9 +63,10 @@ static void focus_window(xcb_connection_t *conn, direction_t direction) { /* TODO: for horizontal default layout, this has to be expanded to LEFT/RIGHT */ if (direction == D_UP || direction == D_DOWN) { - /* Let’s see if we can perform up/down focus in the current container */ - if (focus_window_in_container(conn, container, direction)) - return; + if (thing == THING_WINDOW) + /* Let’s see if we can perform up/down focus in the current container */ + if (focus_window_in_container(conn, container, direction)) + return; if (direction == D_DOWN && cell_exists(current_col, current_row+1)) new_row++; @@ -467,11 +470,19 @@ void parse_command(xcb_connection_t *conn, const char *command) { return; } + enum { WITH_WINDOW, WITH_CONTAINER } with = WITH_WINDOW; + /* Is it a ? */ if (command[0] == 'w') { + command++; /* TODO: implement */ - printf("not yet implemented.\n"); - return; + if (command[0] == 'c') { + with = WITH_CONTAINER; + command++; + } else { + printf("not yet implemented.\n"); + return; + } } /* It's a normal */ @@ -522,8 +533,9 @@ void parse_command(xcb_connection_t *conn, const char *command) { return; } - if (action == ACTION_FOCUS) - focus_window(conn, direction); + if (action == ACTION_FOCUS) { + focus_thing(conn, direction, (with == WITH_WINDOW ? THING_WINDOW : THING_CONTAINER)); + } else if (action == ACTION_MOVE) move_current_window(conn, direction); else if (action == ACTION_SNAP)