Fix some movement/rendering bugs

next
Michael Stapelberg 2009-02-23 01:41:26 +01:00
parent 4ba6ddb41c
commit fe0485f9e5
5 changed files with 44 additions and 22 deletions

View File

@ -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);

View 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, were done */
if (container->currently_focused == NULL)
/* If there is no window or the dock window is focused, were 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);
}
/*

View 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;
}

View 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 whats 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);

View 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);
}