Fix some movement/rendering bugs
This commit is contained in:
parent
4ba6ddb41c
commit
fe0485f9e5
@ -16,6 +16,11 @@
|
|||||||
#define _UTIL_H
|
#define _UTIL_H
|
||||||
|
|
||||||
#define exit_if_null(pointer, ...) { if (pointer == NULL) die(__VA_ARGS__); }
|
#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 min(int a, int b);
|
||||||
int max(int a, int b);
|
int max(int a, int b);
|
||||||
|
@ -58,6 +58,11 @@ static void focus_window(xcb_connection_t *connection, direction_t direction) {
|
|||||||
|
|
||||||
if (focus_window_in_container(connection, container, direction))
|
if (focus_window_in_container(connection, container, direction))
|
||||||
return;
|
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) {
|
} else if (direction == D_LEFT || direction == D_RIGHT) {
|
||||||
if (direction == D_RIGHT && cell_exists(current_col+1, current_row))
|
if (direction == D_RIGHT && cell_exists(current_col+1, current_row))
|
||||||
current_col++;
|
current_col++;
|
||||||
@ -67,15 +72,13 @@ static void focus_window(xcb_connection_t *connection, direction_t direction) {
|
|||||||
printf("nah, not possible\n");
|
printf("nah, not possible\n");
|
||||||
return;
|
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 {
|
} else {
|
||||||
printf("direction unhandled\n");
|
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) {
|
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 */
|
/* Get current window */
|
||||||
Container *container = CUR_CELL,
|
Container *container = CUR_CELL,
|
||||||
*new = NULL;
|
*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() */
|
/* There has to be a container, see focus_window() */
|
||||||
assert(container != NULL);
|
assert(container != NULL);
|
||||||
|
|
||||||
/* If there is no window, we’re done */
|
/* If there is no window or the dock window is focused, we’re done */
|
||||||
if (container->currently_focused == NULL)
|
if (container->currently_focused == NULL ||
|
||||||
|
container->currently_focused->dock)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* As soon as the client is moved away, the next client in the old
|
/* 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. */
|
* container needs to get focus, if any. Therefore, we save it here. */
|
||||||
Client *current_client = container->currently_focused;
|
Client *current_client = container->currently_focused;
|
||||||
Client *to_focus = CIRCLEQ_NEXT(current_client, clients);
|
Client *to_focus = CIRCLEQ_NEXT_OR_NULL(&(container->clients), current_client, clients);
|
||||||
if (to_focus == CIRCLEQ_END(&(container->clients)))
|
if (to_focus == NULL)
|
||||||
to_focus = NULL;
|
to_focus = CIRCLEQ_PREV_OR_NULL(&(container->clients), current_client, clients);
|
||||||
|
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case D_LEFT:
|
case D_LEFT:
|
||||||
@ -169,8 +174,9 @@ static void move_current_window(xcb_connection_t *connection, direction_t direct
|
|||||||
new->currently_focused = current_client;
|
new->currently_focused = current_client;
|
||||||
|
|
||||||
/* TODO: delete all empty columns/rows */
|
/* TODO: delete all empty columns/rows */
|
||||||
|
|
||||||
render_layout(connection);
|
render_layout(connection);
|
||||||
|
|
||||||
|
set_focus(connection, current_client);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -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
|
/* TODO: Implement this one. To do this, implement a little test program which sleep(1)s
|
||||||
before changing this property. */
|
before changing this property. */
|
||||||
printf("_NET_WM_WINDOW_TYPE changed, this is not yet implemented.\n");
|
printf("_NET_WM_WINDOW_TYPE changed, this is not yet implemented.\n");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
24
src/layout.c
24
src/layout.c
@ -47,6 +47,8 @@ Rect get_unoccupied_space(Workspace *workspace) {
|
|||||||
result.height -= workspace->rect.height * default_factor_h;
|
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 every container is using the default factor, we have the whole space available */
|
||||||
if (result.width == 0)
|
if (result.width == 0)
|
||||||
result.width = workspace->rect.width;
|
result.width = workspace->rect.width;
|
||||||
@ -258,8 +260,6 @@ void render_layout(xcb_connection_t *connection) {
|
|||||||
|
|
||||||
int width = r_ws->rect.width;
|
int width = r_ws->rect.width;
|
||||||
int height = r_ws->rect.height;
|
int height = r_ws->rect.height;
|
||||||
int x = r_ws->rect.x;
|
|
||||||
int y = r_ws->rect.y;
|
|
||||||
|
|
||||||
Client *client;
|
Client *client;
|
||||||
SLIST_FOREACH(client, &(r_ws->dock_clients), dock_clients) {
|
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);
|
Rect space = get_unoccupied_space(r_ws);
|
||||||
printf("got %d / %d unoc space\n", space.width, space.height);
|
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 */
|
/* Go through the whole table and render what’s necessary */
|
||||||
for (int cols = 0; cols < r_ws->cols; cols++)
|
for (int cols = 0; cols < r_ws->cols; cols++)
|
||||||
for (int rows = 0; rows < r_ws->rows; rows++) {
|
for (int rows = 0; rows < r_ws->rows; rows++) {
|
||||||
Container *container = r_ws->table[cols][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);
|
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 */
|
/* Update position of the container */
|
||||||
container->row = rows;
|
container->row = rows;
|
||||||
container->col = cols;
|
container->col = cols;
|
||||||
container->x = x;
|
container->x = xoffset[rows];
|
||||||
container->y = y;
|
container->y = yoffset[cols];
|
||||||
if (container->width_factor == 0)
|
if (container->width_factor == 0)
|
||||||
container->width = (width / r_ws->cols) * container->colspan;
|
container->width = (width / r_ws->cols) * container->colspan;
|
||||||
else container->width = space.width * container->width_factor;
|
else container->width = space.width * container->width_factor;
|
||||||
@ -295,7 +303,9 @@ void render_layout(xcb_connection_t *connection) {
|
|||||||
/* Render it */
|
/* Render it */
|
||||||
render_container(connection, container);
|
render_container(connection, container);
|
||||||
|
|
||||||
x += container->width;
|
xoffset[rows] += container->width;
|
||||||
|
yoffset[cols] += container->height;
|
||||||
|
printf("==========\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
render_bars(connection, r_ws, width, height);
|
render_bars(connection, r_ws, width, height);
|
||||||
|
@ -85,6 +85,6 @@ void expand_table_cols(Workspace *workspace) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
bool cell_exists(int col, int row) {
|
bool cell_exists(int col, int row) {
|
||||||
return (col >= 0 && col < c_ws->rows) &&
|
return (col >= 0 && col < c_ws->cols) &&
|
||||||
(row >= 0 && row < c_ws->cols);
|
(row >= 0 && row < c_ws->rows);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user