#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);
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++;
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);
}
/*
*
*/
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;
/* 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:
new->currently_focused = current_client;
/* TODO: delete all empty columns/rows */
-
render_layout(connection);
+
+ set_focus(connection, current_client);
}
/*
/* 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;
}
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;
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) {
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;
/* 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);
*
*/
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);
}