Bugfixes: Various fixes when cleaning up the table/rendering

This commit is contained in:
Michael Stapelberg 2009-03-03 03:40:57 +01:00
parent 16a514b9c1
commit a12ca34d1c
2 changed files with 37 additions and 23 deletions

View File

@ -26,10 +26,14 @@
#include "layout.h"
/* This macro copies the old value of the given variable, changes the variable to contain
th new one and returns true if it changed */
#define HAS_CHANGED(value, new) (old_value = value, old_value != (value = new))
the new one and returns true if it changed.
Note that when combining multiple HAS_CHANGED statements, you need to use different variables.
If someone by chance knows why this is necessary (order of expressions in gcc?) and/or can
come up with a fix, please mail me. */
#define HAS_CHANGED(temp, value, new) (temp = value, temp != (value = new))
static int old_value;
static int old_value_1;
static int old_value_2;
/*
* Gets the unoccupied space (= space which is available for windows which were resized by the user)
@ -253,15 +257,15 @@ void render_container(xcb_connection_t *connection, Container *container) {
/* Check if we changed client->x or client->y by updating it.
* Note the bitwise OR instead of logical OR to force evaluation of both statements */
if (client->force_reconfigure |
HAS_CHANGED(client->rect.x, container->x) |
HAS_CHANGED(client->rect.y, container->y +
HAS_CHANGED(old_value_1, client->rect.x, container->x) |
HAS_CHANGED(old_value_2, client->rect.y, container->y +
(container->height / num_clients) * current_client))
reposition_client(connection, client);
/* TODO: vertical default layout */
if (client->force_reconfigure |
HAS_CHANGED(client->rect.width, container->width) |
HAS_CHANGED(client->rect.height, container->height / num_clients))
HAS_CHANGED(old_value_1, client->rect.width, container->width) |
HAS_CHANGED(old_value_2, client->rect.height, container->height / num_clients))
resize_client(connection, client);
client->force_reconfigure = false;
@ -279,8 +283,8 @@ void render_container(xcb_connection_t *connection, Container *container) {
xcb_map_window(connection, stack_win->window);
/* Check if we need to reconfigure our stack title window */
if (HAS_CHANGED(stack_win->width, container->width) |
HAS_CHANGED(stack_win->height, decoration_height * num_clients)) {
if (HAS_CHANGED(old_value_1, stack_win->width, container->width) |
HAS_CHANGED(old_value_2, stack_win->height, decoration_height * num_clients)) {
xcb_configure_window(connection, stack_win->window,
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, &(stack_win->width));
@ -294,13 +298,13 @@ void render_container(xcb_connection_t *connection, Container *container) {
/* Check if we changed client->x or client->y by updating it.
* Note the bitwise OR instead of logical OR to force evaluation of both statements */
if (client->force_reconfigure |
HAS_CHANGED(client->rect.x, container->x) |
HAS_CHANGED(client->rect.y, container->y + (decoration_height * num_clients)))
HAS_CHANGED(old_value_1, client->rect.x, container->x) |
HAS_CHANGED(old_value_2, client->rect.y, container->y + (decoration_height * num_clients)))
reposition_client(connection, client);
if (client->force_reconfigure |
HAS_CHANGED(client->rect.width, container->width) |
HAS_CHANGED(client->rect.height, container->height - (decoration_height * num_clients)))
HAS_CHANGED(old_value_1, client->rect.width, container->width) |
HAS_CHANGED(old_value_2, client->rect.height, container->height - (decoration_height * num_clients)))
resize_client(connection, client);
client->force_reconfigure = false;
@ -319,13 +323,13 @@ static void render_bars(xcb_connection_t *connection, Workspace *r_ws, int width
Client *client;
SLIST_FOREACH(client, &(r_ws->dock_clients), dock_clients) {
if (client->force_reconfigure |
HAS_CHANGED(client->rect.x, 0) |
HAS_CHANGED(client->rect.y, height))
HAS_CHANGED(old_value_1, client->rect.x, 0) |
HAS_CHANGED(old_value_2, client->rect.y, height))
reposition_client(connection, client);
if (client->force_reconfigure |
HAS_CHANGED(client->rect.width, width) |
HAS_CHANGED(client->rect.height, client->desired_height))
HAS_CHANGED(old_value_1, client->rect.width, width) |
HAS_CHANGED(old_value_2, client->rect.height, client->desired_height))
resize_client(connection, client);
client->force_reconfigure = false;

View File

@ -110,6 +110,7 @@ static void move_columns_from(Workspace *workspace, int cols) {
printf("moving cols = %d to cols -1 = %d\n", cols, cols-1);
workspace->table[cols-1][rows] = workspace->table[cols][rows];
workspace->table[cols-1][rows]->col--;
workspace->table[cols][rows] = NULL;
}
}
@ -121,6 +122,7 @@ static void move_rows_from(Workspace *workspace, int rows) {
printf("moving rows = %d to rows -1 = %d\n", rows, rows - 1);
workspace->table[cols][rows-1] = workspace->table[cols][rows];
workspace->table[cols][rows-1]->row--;
workspace->table[cols][rows] = NULL;
}
}
@ -130,35 +132,43 @@ static void move_rows_from(Workspace *workspace, int rows) {
*
*/
void cleanup_table(xcb_connection_t *conn, Workspace *workspace) {
/* Check for empty columns */
for (int cols = 0; cols < workspace->cols;) {
printf("cleanup_table()\n");
/* Check for empty columns if we got more than one column */
for (int cols = 0; (workspace->cols > 1) && (cols < workspace->cols);) {
bool completely_empty = true;
for (int rows = 0; rows < workspace->rows; rows++)
if (workspace->table[cols][rows]->currently_focused != NULL) {
completely_empty = false;
break;
}
if (completely_empty && cols > 0) {
if (completely_empty) {
printf("Removing completely empty column %d\n", cols);
if (cols < (workspace->cols - 1))
move_columns_from(workspace, cols+1);
shrink_table_cols(workspace);
if (workspace->current_col >= workspace->cols)
workspace->current_col = workspace->cols - 1;
} else cols++;
}
/* Check for empty rows */
for (int rows = 0; rows < workspace->rows;) {
/* Check for empty rows if we got more than one row*/
for (int rows = 0; (workspace->rows > 1) && (rows < workspace->rows);) {
bool completely_empty = true;
for (int cols = 0; cols < workspace->cols; cols++)
if (workspace->table[cols][rows]->currently_focused != NULL) {
completely_empty = false;
break;
}
if (completely_empty && rows > 0) {
if (completely_empty) {
printf("Removing completely empty row %d\n", rows);
if (rows < (workspace->rows - 1))
move_rows_from(workspace, rows+1);
shrink_table_rows(workspace);
if (workspace->current_row >= workspace->rows)
workspace->current_row = workspace->rows - 1;
} else rows++;
}