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
37 changed files with 363 additions and 329 deletions

View File

@ -138,7 +138,7 @@ static void _con_attach(Con *con, Con *parent, Con *previous, bool ignore_focus)
} else {
if (!ignore_focus) {
/* Get the first tiling container in focus stack */
TAILQ_FOREACH(loop, &(parent->focus_head), focused) {
TAILQ_FOREACH (loop, &(parent->focus_head), focused) {
if (loop->type == CT_FLOATING_CON)
continue;
current = loop;
@ -404,7 +404,7 @@ bool con_is_sticky(Con *con) {
return true;
Con *child;
TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
if (con_is_sticky(child))
return true;
}
@ -527,13 +527,13 @@ Con *con_get_fullscreen_con(Con *con, fullscreen_mode_t fullscreen_mode) {
TAILQ_REMOVE(&bfs_head, entry, entries);
free(entry);
TAILQ_FOREACH(child, &(current->nodes_head), nodes) {
TAILQ_FOREACH (child, &(current->nodes_head), nodes) {
entry = smalloc(sizeof(struct bfs_entry));
entry->con = child;
TAILQ_INSERT_TAIL(&bfs_head, entry, entries);
}
TAILQ_FOREACH(child, &(current->floating_head), floating_windows) {
TAILQ_FOREACH (child, &(current->floating_head), floating_windows) {
entry = smalloc(sizeof(struct bfs_entry));
entry->con = child;
TAILQ_INSERT_TAIL(&bfs_head, entry, entries);
@ -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)
return con;
TAILQ_FOREACH (con, &all_cons, all_cons) {
if (con->window != NULL && con->window->id == window) {
return con;
}
}
return NULL;
}
@ -659,7 +661,7 @@ Con *con_by_window_id(xcb_window_t window) {
*/
Con *con_by_con_id(long target) {
Con *con;
TAILQ_FOREACH(con, &all_cons, all_cons) {
TAILQ_FOREACH (con, &all_cons, all_cons) {
if (con == (Con *)target) {
return con;
}
@ -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)
return con;
TAILQ_FOREACH (con, &all_cons, all_cons) {
if (con->frame.id == frame) {
return con;
}
}
return NULL;
}
@ -697,7 +701,7 @@ Con *con_by_frame_id(xcb_window_t frame) {
*/
Con *con_by_mark(const char *mark) {
Con *con;
TAILQ_FOREACH(con, &all_cons, all_cons) {
TAILQ_FOREACH (con, &all_cons, all_cons) {
if (con_has_mark(con, mark))
return con;
}
@ -711,7 +715,7 @@ Con *con_by_mark(const char *mark) {
*/
bool con_has_mark(Con *con, const char *mark) {
mark_t *current;
TAILQ_FOREACH(current, &(con->marks_head), marks) {
TAILQ_FOREACH (current, &(con->marks_head), marks) {
if (strcmp(current->name, mark) == 0)
return true;
}
@ -774,7 +778,7 @@ void con_unmark(Con *con, const char *name) {
Con *current;
if (name == NULL) {
DLOG("Unmarking all containers.\n");
TAILQ_FOREACH(current, &all_cons, all_cons) {
TAILQ_FOREACH (current, &all_cons, all_cons) {
if (con != NULL && current != con)
continue;
@ -805,7 +809,7 @@ void con_unmark(Con *con, const char *name) {
current->mark_changed = true;
mark_t *mark;
TAILQ_FOREACH(mark, &(current->marks_head), marks) {
TAILQ_FOREACH (mark, &(current->marks_head), marks) {
if (strcmp(mark->name, name) != 0)
continue;
@ -830,8 +834,8 @@ Con *con_for_window(Con *con, i3Window *window, Match **store_match) {
//DLOG("searching con for window %p starting at con %p\n", window, con);
//DLOG("class == %s\n", window->class_class);
TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
TAILQ_FOREACH(match, &(child->swallow_head), matches) {
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
TAILQ_FOREACH (match, &(child->swallow_head), matches) {
if (!match_matches_window(match, window))
continue;
if (store_match != NULL)
@ -843,8 +847,8 @@ Con *con_for_window(Con *con, i3Window *window, Match **store_match) {
return result;
}
TAILQ_FOREACH(child, &(con->floating_head), floating_windows) {
TAILQ_FOREACH(match, &(child->swallow_head), matches) {
TAILQ_FOREACH (child, &(con->floating_head), floating_windows) {
TAILQ_FOREACH (match, &(child->swallow_head), matches) {
if (!match_matches_window(match, window))
continue;
if (store_match != NULL)
@ -863,7 +867,7 @@ static int num_focus_heads(Con *con) {
int focus_heads = 0;
Con *current;
TAILQ_FOREACH(current, &(con->focus_head), focused) {
TAILQ_FOREACH (current, &(con->focus_head), focused) {
focus_heads++;
}
@ -880,7 +884,7 @@ Con **get_focus_order(Con *con) {
Con **focus_order = smalloc(focus_heads * sizeof(Con *));
Con *current;
int idx = 0;
TAILQ_FOREACH(current, &(con->focus_head), focused) {
TAILQ_FOREACH (current, &(con->focus_head), focused) {
assert(idx < focus_heads);
focus_order[idx++] = current;
}
@ -923,8 +927,9 @@ int con_num_children(Con *con) {
Con *child;
int children = 0;
TAILQ_FOREACH(child, &(con->nodes_head), nodes)
children++;
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
children++;
}
return children;
}
@ -940,7 +945,7 @@ int con_num_visible_children(Con *con) {
int children = 0;
Con *current = NULL;
TAILQ_FOREACH(current, &(con->nodes_head), nodes) {
TAILQ_FOREACH (current, &(con->nodes_head), nodes) {
/* Visible leaf nodes are a child. */
if (!con_is_hidden(current) && con_is_leaf(current))
children++;
@ -965,11 +970,11 @@ int con_num_windows(Con *con) {
int num = 0;
Con *current = NULL;
TAILQ_FOREACH(current, &(con->nodes_head), nodes) {
TAILQ_FOREACH (current, &(con->nodes_head), nodes) {
num += con_num_windows(current);
}
TAILQ_FOREACH(current, &(con->floating_head), floating_windows) {
TAILQ_FOREACH (current, &(con->floating_head), floating_windows) {
num += con_num_windows(current);
}
@ -990,7 +995,7 @@ void con_fix_percent(Con *con) {
// with a percentage set we have
double total = 0.0;
int children_with_percent = 0;
TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
if (child->percent > 0.0) {
total += child->percent;
++children_with_percent;
@ -1000,7 +1005,7 @@ void con_fix_percent(Con *con) {
// if there were children without a percentage set, set to a value that
// will make those children proportional to all others
if (children_with_percent != children) {
TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
if (child->percent <= 0.0) {
if (children_with_percent == 0) {
total += (child->percent = 1.0);
@ -1014,11 +1019,11 @@ void con_fix_percent(Con *con) {
// if we got a zero, just distribute the space equally, otherwise
// distribute according to the proportions we got
if (total == 0.0) {
TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
child->percent = 1.0 / children;
}
} else if (total != 1.0) {
TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
child->percent /= total;
}
}
@ -1295,7 +1300,7 @@ static bool _con_move_to_con(Con *con, Con *target, bool behind_focused, bool fi
* delete it so child windows won't be created on the old workspace. */
if (!con_is_leaf(con)) {
Con *child;
TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
if (!child->window)
continue;
startup_sequence_delete_by_window(child->window);
@ -1536,7 +1541,7 @@ Con *con_descend_tiling_focused(Con *con) {
return next;
do {
before = next;
TAILQ_FOREACH(child, &(next->focus_head), focused) {
TAILQ_FOREACH (child, &(next->focus_head), focused) {
if (child->type == CT_FLOATING_CON)
continue;
@ -1571,7 +1576,7 @@ Con *con_descend_direction(Con *con, direction_t direction) {
/* Wrong orientation. We use the last focused con. Within that con,
* we recurse to chose the left/right con or at least the last
* focused one. */
TAILQ_FOREACH(current, &(con->focus_head), focused) {
TAILQ_FOREACH (current, &(con->focus_head), focused) {
if (current->type != CT_FLOATING_CON) {
most = current;
break;
@ -1596,7 +1601,7 @@ Con *con_descend_direction(Con *con, direction_t direction) {
/* Wrong orientation. We use the last focused con. Within that con,
* we recurse to chose the top/bottom con or at least the last
* focused one. */
TAILQ_FOREACH(current, &(con->focus_head), focused) {
TAILQ_FOREACH (current, &(con->focus_head), focused) {
if (current->type != CT_FLOATING_CON) {
most = current;
break;
@ -2009,7 +2014,7 @@ Rect con_minimum_size(Con *con) {
if (con->layout == L_STACKED || con->layout == L_TABBED) {
uint32_t max_width = 0, max_height = 0, deco_height = 0;
Con *child;
TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
Rect min = con_minimum_size(child);
deco_height += child->deco_rect.height;
max_width = max(max_width, min.width);
@ -2026,7 +2031,7 @@ Rect con_minimum_size(Con *con) {
if (con_is_split(con)) {
uint32_t width = 0, height = 0;
Con *child;
TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
Rect min = con_minimum_size(child);
if (con->layout == L_SPLITH) {
width += min.width;
@ -2114,7 +2119,7 @@ bool con_has_urgent_child(Con *con) {
/* We are not interested in floating windows since they can only be
* attached to a workspace → nodes_head instead of focus_head */
TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
if (con_has_urgent_child(child))
return true;
}
@ -2236,7 +2241,7 @@ char *con_get_tree_representation(Con *con) {
/* 2) append representation of children */
Con *child;
TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
char *child_txt = con_get_tree_representation(child);
char *tmp_buf;
@ -2454,7 +2459,7 @@ void con_merge_into(Con *old, Con *new) {
con_set_urgency(new, old->urgent);
mark_t *mark;
TAILQ_FOREACH(mark, &(old->marks_head), marks) {
TAILQ_FOREACH (mark, &(old->marks_head), marks) {
TAILQ_INSERT_TAIL(&(new->marks_head), mark, marks);
ipc_send_window_event("mark", new);
}