From 26944bea991c712adbe6774d822b9cefc785b7d9 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 15 Feb 2009 02:30:18 +0100 Subject: [PATCH] Use c99 --- Makefile | 1 + src/commands.c | 16 ++++++---------- src/layout.c | 6 +++--- src/table.c | 11 +++-------- src/xinerama.c | 3 +-- 5 files changed, 14 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 3a88cd96..28b7a636 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ UNAME=$(shell uname) DEBUG=1 +CFLAGS += -std=c99 CFLAGS += -Wall CFLAGS += -Iinclude CFLAGS += -I/usr/local/include diff --git a/src/commands.c b/src/commands.c index deaa8868..6c9ba500 100644 --- a/src/commands.c +++ b/src/commands.c @@ -182,7 +182,6 @@ static void snap_current_container(xcb_connection_t *connection, direction_t dir printf("snapping container to direction %d\n", direction); Container *container = CUR_CELL; - int i; assert(container != NULL); @@ -202,7 +201,7 @@ static void snap_current_container(xcb_connection_t *connection, direction_t dir /* Check if there are other cells with rowspan, which are in our way. * If so, reduce their rowspan. */ - for (i = container->row-1; i >= 0; i--) { + for (int i = container->row-1; i >= 0; i--) { printf("we got cell %d, %d with rowspan %d\n", container->col+1, i, CUR_TABLE[container->col+1][i]->rowspan); while ((CUR_TABLE[container->col+1][i]->rowspan-1) >= (container->row - i)) @@ -224,7 +223,7 @@ static void snap_current_container(xcb_connection_t *connection, direction_t dir return; } - for (i = container->col-1; i >= 0; i--) { + for (int i = container->col-1; i >= 0; i--) { printf("we got cell %d, %d with colspan %d\n", i, container->row+1, CUR_TABLE[i][container->row+1]->colspan); while ((CUR_TABLE[i][container->row+1]->colspan-1) >= (container->col - i)) @@ -241,7 +240,6 @@ static void snap_current_container(xcb_connection_t *connection, direction_t dir } static void show_workspace(xcb_connection_t *conn, int workspace) { - int cols, rows; Client *client; xcb_window_t root = xcb_setup_roots_iterator(xcb_get_setup(conn)).data->root; /* t_ws (to workspace) is just a convenience pointer to the workspace we’re switching to */ @@ -286,11 +284,10 @@ static void show_workspace(xcb_connection_t *conn, int workspace) { //xcb_grab_server(conn); /* Unmap all clients of the current workspace */ - for (cols = 0; cols < c_ws->cols; cols++) - for (rows = 0; rows < c_ws->rows; rows++) { + for (int cols = 0; cols < c_ws->cols; cols++) + for (int rows = 0; rows < c_ws->rows; rows++) CIRCLEQ_FOREACH(client, &(c_ws->table[cols][rows]->clients), clients) xcb_unmap_window(conn, client->frame); - } c_ws = &workspaces[workspace-1]; current_row = c_ws->current_row; @@ -298,11 +295,10 @@ static void show_workspace(xcb_connection_t *conn, int workspace) { printf("new current row = %d, current col = %d\n", current_row, current_col); /* Map all clients on the new workspace */ - for (cols = 0; cols < c_ws->cols; cols++) - for (rows = 0; rows < c_ws->rows; rows++) { + for (int cols = 0; cols < c_ws->cols; cols++) + for (int rows = 0; rows < c_ws->rows; rows++) CIRCLEQ_FOREACH(client, &(c_ws->table[cols][rows]->clients), clients) xcb_map_window(conn, client->frame); - } /* Restore focus on the new workspace */ if (CUR_CELL->currently_focused != NULL) diff --git a/src/layout.c b/src/layout.c index 75b66c80..e88a54e6 100644 --- a/src/layout.c +++ b/src/layout.c @@ -159,8 +159,8 @@ static void render_container(xcb_connection_t *connection, Container *container) } void render_layout(xcb_connection_t *connection) { - int cols, rows; i3Screen *screen; + TAILQ_FOREACH(screen, &virtual_screens, screens) { /* r_ws (rendering workspace) is just a shortcut to the Workspace being currently rendered */ Workspace *r_ws = &(workspaces[screen->current_workspace]); @@ -177,8 +177,8 @@ void render_layout(xcb_connection_t *connection) { width / r_ws->cols, height / r_ws->rows); /* Go through the whole table and render what’s necessary */ - for (cols = 0; cols < r_ws->cols; cols++) - for (rows = 0; rows < r_ws->rows; rows++) { + 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", container->colspan, container->rowspan); diff --git a/src/table.c b/src/table.c index c3f8bea7..41efde0b 100644 --- a/src/table.c +++ b/src/table.c @@ -36,10 +36,9 @@ int current_row = 0; * */ void init_table() { - int i; memset(workspaces, 0, sizeof(workspaces)); - for (i = 0; i < 10; i++) { + for (int i = 0; i < 10; i++) { workspaces[i].screen = NULL; expand_table_cols(&(workspaces[i])); expand_table_rows(&(workspaces[i])); @@ -60,11 +59,9 @@ static void new_container(Workspace *workspace, Container **container) { * */ void expand_table_rows(Workspace *workspace) { - int c; - workspace->rows++; - for (c = 0; c < workspace->cols; c++) { + for (int c = 0; c < workspace->cols; c++) { workspace->table[c] = realloc(workspace->table[c], sizeof(Container*) * workspace->rows); new_container(workspace, &(workspace->table[c][workspace->rows-1])); } @@ -75,13 +72,11 @@ void expand_table_rows(Workspace *workspace) { * */ void expand_table_cols(Workspace *workspace) { - int c; - workspace->cols++; workspace->table = realloc(workspace->table, sizeof(Container**) * workspace->cols); workspace->table[workspace->cols-1] = calloc(sizeof(Container*) * workspace->rows, 1); - for (c = 0; c < workspace->rows; c++) + for (int c = 0; c < workspace->rows; c++) new_container(workspace, &(workspace->table[workspace->cols-1][c])); } diff --git a/src/xinerama.c b/src/xinerama.c index b69d3806..4c8ffa88 100644 --- a/src/xinerama.c +++ b/src/xinerama.c @@ -78,7 +78,6 @@ static void disable_xinerama(xcb_connection_t *connection) { void initialize_xinerama(xcb_connection_t *conn) { xcb_xinerama_query_screens_reply_t *reply; xcb_xinerama_screen_info_t *screen_info; - int screen; if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) { printf("Xinerama extension not found, disabling.\n"); @@ -101,7 +100,7 @@ void initialize_xinerama(xcb_connection_t *conn) { num_screens = xcb_xinerama_query_screens_screen_info_length(reply); /* Just go through each workspace and associate as many screens as we can. */ - for (screen = 0; screen < num_screens; screen++) { + for (int screen = 0; screen < num_screens; screen++) { i3Screen *s = get_screen_at(screen_info[screen].x_org, screen_info[screen].y_org); if (s!= NULL) { /* This screen already exists. We use the littlest screen so that the user -- 2.39.5