]> git.sur5r.net Git - i3/i3/commitdiff
Implement moving up/down (not complete yet)
authorMichael Stapelberg <michael+git@stapelberg.de>
Tue, 10 Feb 2009 00:44:36 +0000 (01:44 +0100)
committerMichael Stapelberg <michael+git@stapelberg.de>
Tue, 10 Feb 2009 00:44:36 +0000 (01:44 +0100)
mainx.c
queue.h

diff --git a/mainx.c b/mainx.c
index d00dde69894d3606fd55edbd1f70e82fefe475c7..c743e74b492f14d71b585e44eb6ac6fd1c93e46c 100644 (file)
--- a/mainx.c
+++ b/mainx.c
@@ -652,32 +652,90 @@ static void move_current_window(xcb_connection_t *connection, direction_t direct
 
        Client *current_client = container->currently_focused;
 
-       if (direction == D_RIGHT) {
-               printf("ok, moving right\n");
-               expand_table_cols();
-
-               Container *new = table[current_col+1][current_row];
+       Container *new;
+       int new_current_col = current_col,
+           new_current_row = current_row;
+       /* As soon as the client is moved away, the next client in the old
+        * container needs to get focus, if any. Therefore, we save it here. */
+       Client *to_focus = CIRCLEQ_NEXT(current_client, clients);
+       if (to_focus == CIRCLEQ_END(&(container->clients)))
+               to_focus = NULL;
+
+       switch (direction) {
+               case D_LEFT:
+                       printf("moving left\n");
+                       if (current_col == 0)
+                               return;
+
+                       new = table[current_col-1][current_row];
+                       new_current_col--;
+                       break;
+               case D_RIGHT:
+                       printf("ok, moving right\n");
+                       if (current_col == (table_dims.x-1)) {
+                               printf("need to expand\n");
+                               expand_table_cols();
+                       }
 
-               /* As soon as the client is moved away, the next client in the old
-                * container needs to get focus, if any. Therefore, we save it here. */
-               Client *to_focus = CIRCLEQ_NEXT(current_client, clients);
-               if (to_focus == CIRCLEQ_END(&(container->clients)))
-                       to_focus = NULL;
+                       new = table[current_col+1][current_row];
+                       new_current_col++;
+                       break;
+               case D_UP:
+                       /* TODO: impl */
+                       printf("moving up\n");
+                       Client *prev = CIRCLEQ_PREV(current_client, clients);
+                       if (prev != CIRCLEQ_END(&(container->clients))) {
+                               printf("i can do that\n");
+                               /* We can move the client inside its current container */
+                               CIRCLEQ_REMOVE(&(container->clients), current_client, clients);
+                               CIRCLEQ_INSERT_BEFORE(&(container->clients), prev, current_client, clients);
+                               render_layout(connection);
+                               return;
+                       }
 
-               /* Remove it from the old container and put it into the new one */
-               CIRCLEQ_REMOVE(&(container->clients), current_client, clients);
-               CIRCLEQ_INSERT_TAIL(&(new->clients), current_client, clients);
+                       /* TODO: push the client into the container above */
+                       return;
+               case D_DOWN:
+                       printf("moving down\n");
+                       Client *next = CIRCLEQ_NEXT(current_client, clients);
+                       if (next != CIRCLEQ_END(&(container->clients))) {
+                               printf("i can do that\n");
+                               /* We can move the client inside its current container */
+                               CIRCLEQ_REMOVE(&(container->clients), current_client, clients);
+                               CIRCLEQ_INSERT_AFTER(&(container->clients), next, current_client, clients);
+                               render_layout(connection);
+                               return;
+                       }
 
-               /* Update data structures */
-               current_client->container = new;
-               container->currently_focused = to_focus;
-               new->currently_focused = current_client;
+                       /* We need to create a new container or push the client
+                          into the container below */
+                       if (current_row == (table_dims.y-1)) {
+                               printf("creating a new container\n");
+                               expand_table_rows();
+                               new = table[current_col][current_row+1];
+                               new_current_row++;
+                       }
+                               /* TODO: check if there is another container below and move
+                                  it there */
 
-               current_col++;
 
-               printf("done\n");
+                       break;
        }
 
+       /* Remove it from the old container and put it into the new one */
+       CIRCLEQ_REMOVE(&(container->clients), current_client, clients);
+       CIRCLEQ_INSERT_TAIL(&(new->clients), current_client, clients);
+
+       /* Update data structures */
+       current_client->container = new;
+       container->currently_focused = to_focus;
+       new->currently_focused = current_client;
+
+       /* TODO: delete all empty columns/rows */
+
+       current_col = new_current_col;
+       current_row = new_current_row;
+
        render_layout(connection);
 }
 
@@ -987,10 +1045,16 @@ int main(int argc, char *argv[], char *env[]) {
        //xcb_grab_key(c, 0, root, 0, 38, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
 
        xcb_grab_key(c, 0, root, 0, 30, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
-       xcb_grab_key(c, 0, root, XCB_MOD_MASK_CONTROL | XCB_MOD_MASK_1, 57, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
-       xcb_grab_key(c, 0, root, XCB_MOD_MASK_CONTROL | XCB_MOD_MASK_1, 28, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
-       xcb_grab_key(c, 0, root, XCB_MOD_MASK_CONTROL | XCB_MOD_MASK_1, 27, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
-       xcb_grab_key(c, 0, root, XCB_MOD_MASK_CONTROL | XCB_MOD_MASK_1, 40, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
+       xcb_grab_key(c, 0, root, XCB_MOD_MASK_1, 57, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
+       xcb_grab_key(c, 0, root, XCB_MOD_MASK_1, 28, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
+       xcb_grab_key(c, 0, root, XCB_MOD_MASK_1, 27, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
+       xcb_grab_key(c, 0, root, XCB_MOD_MASK_1, 40, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
+
+       xcb_grab_key(c, 0, root, XCB_MOD_MASK_CONTROL, 57, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
+       xcb_grab_key(c, 0, root, XCB_MOD_MASK_CONTROL, 28, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
+       xcb_grab_key(c, 0, root, XCB_MOD_MASK_CONTROL, 27, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
+       xcb_grab_key(c, 0, root, XCB_MOD_MASK_CONTROL, 40, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
+
 
        //xcb_grab_key(c, 0, root, XCB_BUTTON_MASK_ANY, 40, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
        start_application(TERMINAL, NULL);
diff --git a/queue.h b/queue.h
index 60a31a17310d63507ea49741ea335dc82b224cc9..56d9c4af6cb5063aa76c7b2e11874f346d472319 100644 (file)
--- a/queue.h
+++ b/queue.h
@@ -512,12 +512,12 @@ struct {                                                          \
 #define CIRCLEQ_REPLACE(head, elm, elm2, field) do {                   \
        if (((elm2)->field.cqe_next = (elm)->field.cqe_next) ==         \
            CIRCLEQ_END(head))                                          \
-               (head).cqh_last = (elm2);                               \
+               (head)->cqh_last = (elm2);                              \
        else                                                            \
                (elm2)->field.cqe_next->field.cqe_prev = (elm2);        \
        if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) ==         \
            CIRCLEQ_END(head))                                          \
-               (head).cqh_first = (elm2);                              \
+               (head)->cqh_first = (elm2);                             \
        else                                                            \
                (elm2)->field.cqe_prev->field.cqe_next = (elm2);        \
        _Q_INVALIDATE((elm)->field.cqe_prev);                           \