]> git.sur5r.net Git - i3/i3/commitdiff
Implement wrapping, selecting containers is now Mod1+Ctrl+h/j/k/l
authorMichael Stapelberg <michael+x200@stapelberg.de>
Wed, 4 Mar 2009 22:45:44 +0000 (23:45 +0100)
committerMichael Stapelberg <michael+x200@stapelberg.de>
Wed, 4 Mar 2009 22:45:44 +0000 (23:45 +0100)
i3.config
src/commands.c

index 2f49bbaf468a3bcc49511aa2c0d55988d220de8e..69d996d223242f60563e571af5b0be20cf90006d 100644 (file)
--- 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
index 948e8710a4550548c718d1d8b89e48a1d973c0e0..810a04ba32b943a6d3cfdaa6d5a042198bd25796 100644 (file)
@@ -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 <with>? */
         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 <cmd> */
@@ -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)