From: Michael Stapelberg Date: Mon, 23 Feb 2009 00:41:26 +0000 (+0100) Subject: Fix some movement/rendering bugs X-Git-Tag: 3.a~169 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=fe0485f9e50d44eac292307a99889d72895cff50;p=i3%2Fi3 Fix some movement/rendering bugs --- diff --git a/include/util.h b/include/util.h index 0bc3903c..b2511287 100644 --- a/include/util.h +++ b/include/util.h @@ -16,6 +16,11 @@ #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); diff --git a/src/commands.c b/src/commands.c index 0920c2ab..8dca6a74 100644 --- a/src/commands.c +++ b/src/commands.c @@ -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); } /* diff --git a/src/handlers.c b/src/handlers.c index 66205879..21c50925 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -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; } diff --git a/src/layout.c b/src/layout.c index bf867cca..f35f4d4c 100644 --- a/src/layout.c +++ b/src/layout.c @@ -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); diff --git a/src/table.c b/src/table.c index 6d8d1ca9..76316371 100644 --- a/src/table.c +++ b/src/table.c @@ -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); }