]> git.sur5r.net Git - i3/i3/commitdiff
Fix some movement/rendering bugs
authorMichael Stapelberg <michael+git@stapelberg.de>
Mon, 23 Feb 2009 00:41:26 +0000 (01:41 +0100)
committerMichael Stapelberg <michael+git@stapelberg.de>
Mon, 23 Feb 2009 00:41:26 +0000 (01:41 +0100)
include/util.h
src/commands.c
src/handlers.c
src/layout.c
src/table.c

index 0bc3903c7c2118c59ffa9f79cd610168e3631fca..b25112878086c58d711472c4267af026683b44ac 100644 (file)
 #define _UTIL_H
 
 #define exit_if_null(pointer, ...) { if (pointer == NULL) die(__VA_ARGS__); }
+#define CIRCLEQ_NEXT_OR_NULL(head, elm, field) (CIRCLEQ_NEXT(elm, field) != CIRCLEQ_END(head) ? \
+                                                CIRCLEQ_NEXT(elm, field) : NULL)
+#define CIRCLEQ_PREV_OR_NULL(head, elm, field) (CIRCLEQ_PREV(elm, field) != CIRCLEQ_END(head) ? \
+                                                CIRCLEQ_PREV(elm, field) : NULL)
+
 
 int min(int a, int b);
 int max(int a, int b);
index 0920c2abc562c86705337fe1000afa9747701f55..8dca6a74972333dcf90b4418e9bb436f8e82fafe 100644 (file)
@@ -58,6 +58,11 @@ static void focus_window(xcb_connection_t *connection, direction_t direction) {
 
                 if (focus_window_in_container(connection, container, direction))
                         return;
+
+                if (direction == D_DOWN && cell_exists(current_col, current_row+1))
+                        current_row++;
+                else if (direction == D_UP && cell_exists(current_col, current_row-1))
+                        current_row--;
         } else if (direction == D_LEFT || direction == D_RIGHT) {
                 if (direction == D_RIGHT && cell_exists(current_col+1, current_row))
                         current_col++;
@@ -67,15 +72,13 @@ static void focus_window(xcb_connection_t *connection, direction_t direction) {
                         printf("nah, not possible\n");
                         return;
                 }
-                if (CUR_CELL->currently_focused != NULL) {
-                        xcb_set_input_focus(connection, XCB_INPUT_FOCUS_POINTER_ROOT,
-                                        CUR_CELL->currently_focused->child, XCB_CURRENT_TIME);
-                        render_layout(connection);
-                }
-
         } else {
                 printf("direction unhandled\n");
+                return;
         }
+
+        if (CUR_CELL->currently_focused != NULL)
+                set_focus(connection, CUR_CELL->currently_focused);
 }
 
 /*
@@ -108,7 +111,8 @@ static bool move_current_window_in_container(xcb_connection_t *connection, Clien
  *
  */
 static void move_current_window(xcb_connection_t *connection, direction_t direction) {
-        printf("moving window to direction %d\n", direction);
+        printf("moving window to direction %s\n", (direction == D_UP ? "up" : (direction == D_DOWN ? "down" :
+                                        (direction == D_LEFT ? "left" : "right"))));
         /* Get current window */
         Container *container = CUR_CELL,
                   *new = NULL;
@@ -116,16 +120,17 @@ static void move_current_window(xcb_connection_t *connection, direction_t direct
         /* There has to be a container, see focus_window() */
         assert(container != NULL);
 
-        /* If there is no window, we’re done */
-        if (container->currently_focused == NULL)
+        /* If there is no window or the dock window is focused, we’re done */
+        if (container->currently_focused == NULL ||
+            container->currently_focused->dock)
                 return;
 
         /* 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 *current_client = container->currently_focused;
-        Client *to_focus = CIRCLEQ_NEXT(current_client, clients);
-        if (to_focus == CIRCLEQ_END(&(container->clients)))
-                to_focus = NULL;
+        Client *to_focus = CIRCLEQ_NEXT_OR_NULL(&(container->clients), current_client, clients);
+        if (to_focus == NULL)
+                to_focus = CIRCLEQ_PREV_OR_NULL(&(container->clients), current_client, clients);
 
         switch (direction) {
                 case D_LEFT:
@@ -169,8 +174,9 @@ static void move_current_window(xcb_connection_t *connection, direction_t direct
         new->currently_focused = current_client;
 
         /* TODO: delete all empty columns/rows */
-
         render_layout(connection);
+
+        set_focus(connection, current_client);
 }
 
 /*
index 6620587921c70aad4917cd067d2de47e117546c4..21c509255cc4cea2cc8d95d690f93a10a89cbf30 100644 (file)
@@ -383,4 +383,5 @@ int window_type_handler(void *data, xcb_connection_t *conn, uint8_t state, xcb_w
         /* TODO: Implement this one. To do this, implement a little test program which sleep(1)s
          before changing this property. */
         printf("_NET_WM_WINDOW_TYPE changed, this is not yet implemented.\n");
+        return 0;
 }
index bf867ccac3d16f6f4886add2b0df2c6b515ae823..f35f4d4c6fab3a138b9c342bbc5453e7e9882bb2 100644 (file)
@@ -47,6 +47,8 @@ Rect get_unoccupied_space(Workspace *workspace) {
                                 result.height -= workspace->rect.height * default_factor_h;
                 }
 
+        printf("gots %d, %d\n", result.width, result.height);
+
         /* If every container is using the default factor, we have the whole space available */
         if (result.width == 0)
                 result.width = workspace->rect.width;
@@ -258,8 +260,6 @@ void render_layout(xcb_connection_t *connection) {
 
                 int width = r_ws->rect.width;
                 int height = r_ws->rect.height;
-                int x = r_ws->rect.x;
-                int y = r_ws->rect.y;
 
                 Client *client;
                 SLIST_FOREACH(client, &(r_ws->dock_clients), dock_clients) {
@@ -275,18 +275,26 @@ void render_layout(xcb_connection_t *connection) {
                 Rect space = get_unoccupied_space(r_ws);
                 printf("got %d / %d unoc space\n", space.width, space.height);
 
+                int xoffset[r_ws->rows];
+                int yoffset[r_ws->cols];
+                /* Initialize offsets */
+                for (int cols = 0; cols < r_ws->cols; cols++)
+                        yoffset[cols] = r_ws->rect.y;
+                for (int rows = 0; rows < r_ws->rows; rows++)
+                        xoffset[rows] = r_ws->rect.x;
+
                 /* Go through the whole table and render what’s necessary */
                 for (int cols = 0; cols < r_ws->cols; cols++)
                         for (int rows = 0; rows < r_ws->rows; rows++) {
                                 Container *container = r_ws->table[cols][rows];
-                                printf("container has %d colspan, %d rowspan\n",
+                                printf("\n========\ncontainer has %d colspan, %d rowspan\n",
                                                 container->colspan, container->rowspan);
-                                printf("container at %d, %d\n", x, y);
+                                printf("container at %d, %d\n", xoffset[rows], yoffset[cols]);
                                 /* Update position of the container */
                                 container->row = rows;
                                 container->col = cols;
-                                container->x = x;
-                                container->y = y;
+                                container->x = xoffset[rows];
+                                container->y = yoffset[cols];
                                 if (container->width_factor == 0)
                                         container->width = (width / r_ws->cols) * container->colspan;
                                 else container->width = space.width * container->width_factor;
@@ -295,7 +303,9 @@ void render_layout(xcb_connection_t *connection) {
                                 /* Render it */
                                 render_container(connection, container);
 
-                                x += container->width;
+                                xoffset[rows] += container->width;
+                                yoffset[cols] += container->height;
+                                printf("==========\n");
                         }
 
                 render_bars(connection, r_ws, width, height);
index 6d8d1ca9b956ea2c8591fdd450117cb1e5586d2a..763163718c8cbb5a2e3c9afd79178cdd87677d08 100644 (file)
@@ -85,6 +85,6 @@ void expand_table_cols(Workspace *workspace) {
  *
  */
 bool cell_exists(int col, int row) {
-        return (col >= 0 && col < c_ws->rows) &&
-                (row >= 0 && row < c_ws->cols);
+        return (col >= 0 && col < c_ws->cols) &&
+                (row >= 0 && row < c_ws->rows);
 }