clang-format: bring back ForeachMacros (#3948)

* clang-format: bring back ForeachMacros

ForeachMacros was disabled in 4211274fcd
due to the breakage of include/queue.h. The currently used version,
clang-format-6.0 doesn't break it.

* Add curly braces

Co-authored-by: Orestis Floros <orestisflo@gmail.com>
This commit is contained in:
xzfc 2020-02-19 10:31:09 +00:00 committed by GitHub
parent e3f120c0b6
commit 1f0c628cde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 363 additions and 329 deletions

View File

@ -9,3 +9,4 @@ PointerBindsToType: false
ColumnLimit: 0
SpaceBeforeParens: ControlStatements
SortIncludes: false
ForEachMacros: [ TAILQ_FOREACH, TAILQ_FOREACH_REVERSE, SLIST_FOREACH, CIRCLEQ_FOREACH, CIRCLEQ_FOREACH_REVERSE, NODES_FOREACH, NODES_FOREACH_REVERSE, FOREACH_NONINTERNAL]

View File

@ -646,9 +646,11 @@ bool con_has_parent(Con *con, Con *parent) {
*/
Con *con_by_window_id(xcb_window_t window) {
Con *con;
TAILQ_FOREACH(con, &all_cons, all_cons)
if (con->window != NULL && con->window->id == window)
TAILQ_FOREACH (con, &all_cons, all_cons) {
if (con->window != NULL && con->window->id == window) {
return con;
}
}
return NULL;
}
@ -684,9 +686,11 @@ bool con_exists(Con *con) {
*/
Con *con_by_frame_id(xcb_window_t frame) {
Con *con;
TAILQ_FOREACH(con, &all_cons, all_cons)
if (con->frame.id == frame)
TAILQ_FOREACH (con, &all_cons, all_cons) {
if (con->frame.id == frame) {
return con;
}
}
return NULL;
}
@ -923,8 +927,9 @@ int con_num_children(Con *con) {
Con *child;
int children = 0;
TAILQ_FOREACH(child, &(con->nodes_head), nodes)
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
children++;
}
return children;
}

View File

@ -1033,8 +1033,9 @@ bool parse_file(const char *f, bool use_nagbar) {
destwalk = new;
while (walk < (buf + stbuf.st_size)) {
/* Find the next variable */
SLIST_FOREACH(current, &variables, variables)
SLIST_FOREACH (current, &variables, variables) {
current->next_match = strcasestr(walk, current->key);
}
nearest = NULL;
int distance = stbuf.st_size;
SLIST_FOREACH (current, &variables, variables) {

View File

@ -18,9 +18,11 @@ static int num_screens;
*/
static Output *get_screen_at(unsigned int x, unsigned int y) {
Output *output;
TAILQ_FOREACH(output, &outputs, outputs)
if (output->rect.x == x && output->rect.y == y)
TAILQ_FOREACH (output, &outputs, outputs) {
if (output->rect.x == x && output->rect.y == y) {
return output;
}
}
return NULL;
}

View File

@ -160,13 +160,14 @@ static void handle_enter_notify(xcb_enter_notify_event_t *event) {
layout_t layout = (enter_child ? con->parent->layout : con->layout);
if (layout == L_DEFAULT) {
Con *child;
TAILQ_FOREACH(child, &(con->nodes_head), nodes)
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
if (rect_contains(child->deco_rect, event->event_x, event->event_y)) {
LOG("using child %p / %s instead!\n", child, child->name);
con = child;
break;
}
}
}
if (config.disable_focus_follows_mouse)
return;

View File

@ -83,7 +83,7 @@ void restore_geometry(void) {
DLOG("Restoring geometry\n");
Con *con;
TAILQ_FOREACH(con, &all_cons, all_cons)
TAILQ_FOREACH (con, &all_cons, all_cons) {
if (con->window) {
DLOG("Re-adding X11 border of %d px\n", con->border_width);
con->window_rect.width += (2 * con->border_width);
@ -93,6 +93,7 @@ void restore_geometry(void) {
xcb_reparent_window(conn, con->window->id, root,
con->rect.x, con->rect.y);
}
}
/* Strictly speaking, this line doesnt really belong here, but since we
* are syncing, lets un-register as a window manager first */

View File

@ -16,9 +16,11 @@
Con *output_get_content(Con *output) {
Con *child;
TAILQ_FOREACH(child, &(output->nodes_head), nodes)
if (child->type == CT_CON)
TAILQ_FOREACH (child, &(output->nodes_head), nodes) {
if (child->type == CT_CON) {
return child;
}
}
return NULL;
}

View File

@ -32,9 +32,11 @@ static bool has_randr_1_5 = false;
*/
static Output *get_output_by_id(xcb_randr_output_t id) {
Output *output;
TAILQ_FOREACH(output, &outputs, outputs)
if (output->id == id)
TAILQ_FOREACH (output, &outputs, outputs) {
if (output->id == id) {
return output;
}
}
return NULL;
}

View File

@ -130,8 +130,9 @@ void render_con(Con *con) {
/* in a stacking or tabbed container, we ensure the focused client is raised */
if (con->layout == L_STACKED || con->layout == L_TABBED) {
TAILQ_FOREACH_REVERSE(child, &(con->focus_head), focus_head, focused)
TAILQ_FOREACH_REVERSE (child, &(con->focus_head), focus_head, focused) {
x_raise_con(child);
}
if ((child = TAILQ_FIRST(&(con->focus_head)))) {
/* By rendering the stacked container again, we handle the case
* that we have a non-leaf-container inside the stack. In that
@ -313,8 +314,9 @@ static void render_output(Con *con) {
continue;
child->rect.height = 0;
TAILQ_FOREACH(dockchild, &(child->nodes_head), nodes)
TAILQ_FOREACH (dockchild, &(child->nodes_head), nodes) {
child->rect.height += dockchild->geometry.height;
}
height -= child->rect.height;
}

View File

@ -431,15 +431,17 @@ static void mark_unmapped(Con *con) {
Con *current;
con->mapped = false;
TAILQ_FOREACH(current, &(con->nodes_head), nodes)
TAILQ_FOREACH (current, &(con->nodes_head), nodes) {
mark_unmapped(current);
}
if (con->type == CT_WORKSPACE) {
/* We need to call mark_unmapped on floating nodes as well since we can
* make containers floating. */
TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
TAILQ_FOREACH (current, &(con->floating_head), floating_windows) {
mark_unmapped(current);
}
}
}
/*
* Renders the tree, that is rendering all outputs using render_con() and

View File

@ -388,9 +388,10 @@ static void workspace_reassign_sticky(Con *con) {
LOG("re-assigned window from src %p to dest %p\n", src, current);
}
TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
TAILQ_FOREACH (current, &(con->floating_head), floating_windows) {
workspace_reassign_sticky(current);
}
}
/*
* Callback to reset the urgent flag of the given con to false. May be started by
@ -828,13 +829,17 @@ Con *workspace_back_and_forth_get(void) {
static bool get_urgency_flag(Con *con) {
Con *child;
TAILQ_FOREACH(child, &(con->nodes_head), nodes)
if (child->urgent || get_urgency_flag(child))
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
if (child->urgent || get_urgency_flag(child)) {
return true;
}
}
TAILQ_FOREACH(child, &(con->floating_head), floating_windows)
if (child->urgent || get_urgency_flag(child))
TAILQ_FOREACH (child, &(con->floating_head), floating_windows) {
if (child->urgent || get_urgency_flag(child)) {
return true;
}
}
return false;
}

24
src/x.c
View File

@ -92,9 +92,11 @@ initial_mapping_head =
*/
static con_state *state_for_frame(xcb_window_t window) {
con_state *state;
CIRCLEQ_FOREACH(state, &state_head, state)
if (state->id == window)
CIRCLEQ_FOREACH (state, &state_head, state) {
if (state->id == window) {
return state;
}
}
/* TODO: better error handling? */
ELOG("No state found for window 0x%08x\n", window);
@ -726,11 +728,13 @@ void x_deco_recurse(Con *con) {
con_state *state = state_for_frame(con->frame.id);
if (!leaf) {
TAILQ_FOREACH(current, &(con->nodes_head), nodes)
TAILQ_FOREACH (current, &(con->nodes_head), nodes) {
x_deco_recurse(current);
}
TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
TAILQ_FOREACH (current, &(con->floating_head), floating_windows) {
x_deco_recurse(current);
}
if (state->mapped) {
draw_util_copy_surface(&(con->frame_buffer), &(con->frame), 0, 0, 0, 0, con->rect.width, con->rect.height);
@ -1116,12 +1120,14 @@ static void x_push_node_unmaps(Con *con) {
}
/* handle all children and floating windows of this node */
TAILQ_FOREACH(current, &(con->nodes_head), nodes)
TAILQ_FOREACH (current, &(con->nodes_head), nodes) {
x_push_node_unmaps(current);
}
TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
TAILQ_FOREACH (current, &(con->floating_head), floating_windows) {
x_push_node_unmaps(current);
}
}
/*
* Returns true if the given container is currently attached to its parent.
@ -1178,9 +1184,11 @@ void x_push_changes(Con *con) {
/* count first, necessary to (re)allocate memory for the bottom-to-top
* stack afterwards */
int cnt = 0;
CIRCLEQ_FOREACH_REVERSE(state, &state_head, state)
if (con_has_managed_window(state->con))
CIRCLEQ_FOREACH_REVERSE (state, &state_head, state) {
if (con_has_managed_window(state->con)) {
cnt++;
}
}
/* The bottom-to-top window stack of all windows which are managed by i3.
* Used for x_get_window_stack(). */

View File

@ -21,9 +21,11 @@ static int num_screens;
*/
static Output *get_screen_at(unsigned int x, unsigned int y) {
Output *output;
TAILQ_FOREACH(output, &outputs, outputs)
if (output->rect.x == x && output->rect.y == y)
TAILQ_FOREACH (output, &outputs, outputs) {
if (output->rect.x == x && output->rect.y == y) {
return output;
}
}
return NULL;
}