Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
clang-format: bring back ForeachMacros (#3948)
Browse files Browse the repository at this point in the history
* clang-format: bring back ForeachMacros

ForeachMacros was disabled in 4211274
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>
  • Loading branch information
xzfc and orestisfl committed Feb 19, 2020
1 parent e3f120c commit 1f0c628
Show file tree
Hide file tree
Showing 37 changed files with 363 additions and 329 deletions.
1 change: 1 addition & 0 deletions .clang-format
Expand Up @@ -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]
4 changes: 2 additions & 2 deletions i3bar/src/child.c
Expand Up @@ -90,7 +90,7 @@ static void clear_statusline(struct statusline_head *head, bool free_resources)

static void copy_statusline(struct statusline_head *from, struct statusline_head *to) {
struct status_block *current;
TAILQ_FOREACH(current, from, blocks) {
TAILQ_FOREACH (current, from, blocks) {
struct status_block *new_block = smalloc(sizeof(struct status_block));
memcpy(new_block, current, sizeof(struct status_block));
TAILQ_INSERT_TAIL(to, new_block, blocks);
Expand Down Expand Up @@ -330,7 +330,7 @@ static int stdin_end_array(void *context) {

DLOG("dumping statusline:\n");
struct status_block *current;
TAILQ_FOREACH(current, &statusline_head, blocks) {
TAILQ_FOREACH (current, &statusline_head, blocks) {
DLOG("full_text = %s\n", i3string_as_utf8(current->full_text));
DLOG("short_text = %s\n", (current->short_text == NULL ? NULL : i3string_as_utf8(current->short_text)));
DLOG("color = %s\n", current->color);
Expand Down
2 changes: 1 addition & 1 deletion i3bar/src/ipc.c
Expand Up @@ -72,7 +72,7 @@ static void got_output_reply(char *reply) {
reconfig_windows(false);

i3_output *o_walk;
SLIST_FOREACH(o_walk, outputs, slist) {
SLIST_FOREACH (o_walk, outputs, slist) {
kick_tray_clients(o_walk);
}

Expand Down
6 changes: 3 additions & 3 deletions i3bar/src/outputs.c
Expand Up @@ -304,7 +304,7 @@ void free_outputs(void) {
if (outputs == NULL) {
return;
}
SLIST_FOREACH(outputs_walk, outputs, slist) {
SLIST_FOREACH (outputs_walk, outputs, slist) {
destroy_window(outputs_walk);
if (outputs_walk->trayclients != NULL && !TAILQ_EMPTY(outputs_walk->trayclients)) {
FREE_TAILQ(outputs_walk->trayclients, trayclient);
Expand All @@ -323,7 +323,7 @@ i3_output *get_output_by_name(char *name) {
if (name == NULL) {
return NULL;
}
SLIST_FOREACH(walk, outputs, slist) {
SLIST_FOREACH (walk, outputs, slist) {
if (!strcmp(walk->name, name)) {
break;
}
Expand All @@ -338,7 +338,7 @@ i3_output *get_output_by_name(char *name) {
*/
bool output_has_focus(i3_output *output) {
i3_ws *ws_walk;
TAILQ_FOREACH(ws_walk, output->workspaces, tailq) {
TAILQ_FOREACH (ws_walk, output->workspaces, tailq) {
if (ws_walk->focused) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions i3bar/src/workspaces.c
Expand Up @@ -269,9 +269,9 @@ void free_workspaces(void) {
}
i3_ws *ws_walk;

SLIST_FOREACH(outputs_walk, outputs, slist) {
SLIST_FOREACH (outputs_walk, outputs, slist) {
if (outputs_walk->workspaces != NULL && !TAILQ_EMPTY(outputs_walk->workspaces)) {
TAILQ_FOREACH(ws_walk, outputs_walk->workspaces, tailq) {
TAILQ_FOREACH (ws_walk, outputs_walk->workspaces, tailq) {
I3STRING_FREE(ws_walk->name);
FREE(ws_walk->canonical_name);
}
Expand Down
50 changes: 25 additions & 25 deletions i3bar/src/xcb.c
Expand Up @@ -161,7 +161,7 @@ static uint32_t get_sep_offset(struct status_block *block) {
static int get_tray_width(struct tc_head *trayclients) {
trayclient *trayclient;
int tray_width = 0;
TAILQ_FOREACH_REVERSE(trayclient, trayclients, tc_head, tailq) {
TAILQ_FOREACH_REVERSE (trayclient, trayclients, tc_head, tailq) {
if (!trayclient->mapped)
continue;
tray_width += icon_size + logical_px(config.tray_padding);
Expand Down Expand Up @@ -203,7 +203,7 @@ static uint32_t predict_statusline_length(bool use_short_text) {
uint32_t width = 0;
struct status_block *block;

TAILQ_FOREACH(block, &statusline_head, blocks) {
TAILQ_FOREACH (block, &statusline_head, blocks) {
i3String *text = block->full_text;
struct status_block_render_desc *render = &block->full_render;
if (use_short_text && block->short_text != NULL) {
Expand Down Expand Up @@ -266,7 +266,7 @@ static void draw_statusline(i3_output *output, uint32_t clip_left, bool use_focu
uint32_t x = 0 - clip_left;

/* Draw the text of each block */
TAILQ_FOREACH(block, &statusline_head, blocks) {
TAILQ_FOREACH (block, &statusline_head, blocks) {
i3String *text = block->full_text;
struct status_block_render_desc *render = &block->full_render;
if (use_short_text && block->short_text != NULL) {
Expand Down Expand Up @@ -343,7 +343,7 @@ static void hide_bars(void) {
}

i3_output *walk;
SLIST_FOREACH(walk, outputs, slist) {
SLIST_FOREACH (walk, outputs, slist) {
if (!walk->active) {
continue;
}
Expand All @@ -368,7 +368,7 @@ static void unhide_bars(void) {

cont_child();

SLIST_FOREACH(walk, outputs, slist) {
SLIST_FOREACH (walk, outputs, slist) {
if (walk->bar.id == XCB_NONE) {
continue;
}
Expand Down Expand Up @@ -448,7 +448,7 @@ void init_colors(const struct xcb_color_strings_t *new_colors) {

static bool execute_custom_command(xcb_keycode_t input_code, bool event_is_release) {
binding_t *binding;
TAILQ_FOREACH(binding, &(config.bindings), bindings) {
TAILQ_FOREACH (binding, &(config.bindings), bindings) {
if ((binding->input_code != input_code) || (binding->release != event_is_release))
continue;

Expand All @@ -466,7 +466,7 @@ static void child_handle_button(xcb_button_press_event_t *event, i3_output *outp
/* x of the start of the current block relative to the statusline. */
uint32_t last_block_x = 0;
struct status_block *block;
TAILQ_FOREACH(block, &statusline_head, blocks) {
TAILQ_FOREACH (block, &statusline_head, blocks) {
i3String *text;
struct status_block_render_desc *render;
if (output->statusline_short_text && block->short_text != NULL) {
Expand Down Expand Up @@ -521,7 +521,7 @@ static void handle_button(xcb_button_press_event_t *event) {
/* Determine, which bar was clicked */
i3_output *walk;
xcb_window_t bar = event->event;
SLIST_FOREACH(walk, outputs, slist) {
SLIST_FOREACH (walk, outputs, slist) {
if (walk->bar.id == bar) {
break;
}
Expand All @@ -541,7 +541,7 @@ static void handle_button(xcb_button_press_event_t *event) {
int workspace_width = 0;
i3_ws *cur_ws = NULL, *clicked_ws = NULL, *ws_walk;

TAILQ_FOREACH(ws_walk, walk->workspaces, tailq) {
TAILQ_FOREACH (ws_walk, walk->workspaces, tailq) {
int w = predict_button_width(ws_walk->name_width);
if (x >= workspace_width && x <= workspace_width + w)
clicked_ws = ws_walk;
Expand Down Expand Up @@ -614,7 +614,7 @@ static void handle_button(xcb_button_press_event_t *event) {
/* if no workspace was clicked, focus our currently visible
* workspace if it is not already focused */
if (cur_ws == NULL) {
TAILQ_FOREACH(cur_ws, walk->workspaces, tailq) {
TAILQ_FOREACH (cur_ws, walk->workspaces, tailq) {
if (cur_ws->visible && !cur_ws->focused)
break;
}
Expand Down Expand Up @@ -672,7 +672,7 @@ static void handle_visibility_notify(xcb_visibility_notify_event_t *event) {
int num_visible = 0;
i3_output *output;

SLIST_FOREACH(output, outputs, slist) {
SLIST_FOREACH (output, outputs, slist) {
if (!output->active) {
continue;
}
Expand Down Expand Up @@ -729,22 +729,22 @@ static int reorder_trayclients_cmp(const void *_a, const void *_b) {
*/
static void configure_trayclients(void) {
i3_output *output;
SLIST_FOREACH(output, outputs, slist) {
SLIST_FOREACH (output, outputs, slist) {
if (!output->active) {
continue;
}

int count = 0;
trayclient *client;
TAILQ_FOREACH(client, output->trayclients, tailq) {
TAILQ_FOREACH (client, output->trayclients, tailq) {
if (client->mapped) {
count++;
}
}

int idx = 0;
trayclient **trayclients = smalloc(count * sizeof(trayclient *));
TAILQ_FOREACH(client, output->trayclients, tailq) {
TAILQ_FOREACH (client, output->trayclients, tailq) {
if (client->mapped) {
trayclients[idx++] = client;
}
Expand All @@ -769,13 +769,13 @@ static void configure_trayclients(void) {

static trayclient *trayclient_and_output_from_window(xcb_window_t win, i3_output **output) {
i3_output *o_walk;
SLIST_FOREACH(o_walk, outputs, slist) {
SLIST_FOREACH (o_walk, outputs, slist) {
if (!o_walk->active) {
continue;
}

trayclient *client;
TAILQ_FOREACH(client, o_walk->trayclients, tailq) {
TAILQ_FOREACH (client, o_walk->trayclients, tailq) {
if (client->win == win) {
if (output) {
*output = o_walk;
Expand Down Expand Up @@ -1118,12 +1118,12 @@ static void handle_property_notify(xcb_property_notify_event_t *event) {
static void handle_configuration_change(xcb_window_t window) {
trayclient *trayclient;
i3_output *output;
SLIST_FOREACH(output, outputs, slist) {
SLIST_FOREACH (output, outputs, slist) {
if (!output->active)
continue;

int clients = 0;
TAILQ_FOREACH_REVERSE(trayclient, output->trayclients, tc_head, tailq) {
TAILQ_FOREACH_REVERSE (trayclient, output->trayclients, tc_head, tailq) {
if (!trayclient->mapped)
continue;
clients++;
Expand Down Expand Up @@ -1733,7 +1733,7 @@ static i3_output *get_tray_output(void) {
i3_output *output = NULL;
if (TAILQ_EMPTY(&(config.tray_outputs))) {
/* No tray_output specified, use first active output. */
SLIST_FOREACH(output, outputs, slist) {
SLIST_FOREACH (output, outputs, slist) {
if (output->active) {
return output;
}
Expand All @@ -1747,8 +1747,8 @@ static i3_output *get_tray_output(void) {
/* If one or more tray_output assignments were specified, we ensure that at
* least one of them is actually an output managed by this instance. */
tray_output_t *tray_output;
TAILQ_FOREACH(tray_output, &(config.tray_outputs), tray_outputs) {
SLIST_FOREACH(output, outputs, slist) {
TAILQ_FOREACH (tray_output, &(config.tray_outputs), tray_outputs) {
SLIST_FOREACH (output, outputs, slist) {
if (output->active &&
(strcasecmp(output->name, tray_output->output) == 0 ||
(strcasecmp(tray_output->output, "primary") == 0 && output->primary))) {
Expand All @@ -1769,7 +1769,7 @@ void reconfig_windows(bool redraw_bars) {
uint32_t values[6];

i3_output *walk;
SLIST_FOREACH(walk, outputs, slist) {
SLIST_FOREACH (walk, outputs, slist) {
if (!walk->active) {
/* If an output is not active, we destroy its bar */
/* FIXME: Maybe we rather want to unmap? */
Expand Down Expand Up @@ -2032,7 +2032,7 @@ void draw_bars(bool unhide) {
uint32_t short_statusline_width = predict_statusline_length(true);

i3_output *outputs_walk;
SLIST_FOREACH(outputs_walk, outputs, slist) {
SLIST_FOREACH (outputs_walk, outputs, slist) {
int workspace_width = 0;

if (!outputs_walk->active) {
Expand All @@ -2051,7 +2051,7 @@ void draw_bars(bool unhide) {

if (!config.disable_ws) {
i3_ws *ws_walk;
TAILQ_FOREACH(ws_walk, outputs_walk->workspaces, tailq) {
TAILQ_FOREACH (ws_walk, outputs_walk->workspaces, tailq) {
DLOG("Drawing button for WS %s at x = %d, len = %d\n",
i3string_as_utf8(ws_walk->name), workspace_width, ws_walk->name_width);
color_t fg_color = colors.inactive_ws_fg;
Expand Down Expand Up @@ -2145,7 +2145,7 @@ void draw_bars(bool unhide) {
*/
void redraw_bars(void) {
i3_output *outputs_walk;
SLIST_FOREACH(outputs_walk, outputs, slist) {
SLIST_FOREACH (outputs_walk, outputs, slist) {
if (!outputs_walk->active) {
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions include/util.h
Expand Up @@ -28,15 +28,15 @@

#define NODES_FOREACH(head) \
for (Con *child = (Con *)-1; (child == (Con *)-1) && ((child = 0), true);) \
TAILQ_FOREACH(child, &((head)->nodes_head), nodes)
TAILQ_FOREACH (child, &((head)->nodes_head), nodes)

#define NODES_FOREACH_REVERSE(head) \
for (Con *child = (Con *)-1; (child == (Con *)-1) && ((child = 0), true);) \
TAILQ_FOREACH_REVERSE(child, &((head)->nodes_head), nodes_head, nodes)
TAILQ_FOREACH_REVERSE (child, &((head)->nodes_head), nodes_head, nodes)

/* greps the ->nodes of the given head and returns the first node that matches the given condition */
#define GREP_FIRST(dest, head, condition) \
NODES_FOREACH(head) { \
NODES_FOREACH (head) { \
if (!(condition)) \
continue; \
\
Expand Down
2 changes: 1 addition & 1 deletion libi3/get_colorpixel.c
Expand Up @@ -48,7 +48,7 @@ uint32_t get_colorpixel(const char *hex) {

/* Lookup this colorpixel in the cache */
struct Colorpixel *colorpixel;
SLIST_FOREACH(colorpixel, &(colorpixels), colorpixels) {
SLIST_FOREACH (colorpixel, &(colorpixels), colorpixels) {
if (strcmp(colorpixel->hex, hex) == 0)
return colorpixel->pixel;
}
Expand Down
4 changes: 2 additions & 2 deletions src/assignments.c
Expand Up @@ -21,7 +21,7 @@ void run_assignments(i3Window *window) {

/* Check if any assignments match */
Assignment *current;
TAILQ_FOREACH(current, &assignments, assignments) {
TAILQ_FOREACH (current, &assignments, assignments) {
if (current->type != A_COMMAND || !match_matches_window(&(current->match), window))
continue;

Expand Down Expand Up @@ -69,7 +69,7 @@ void run_assignments(i3Window *window) {
Assignment *assignment_for(i3Window *window, int type) {
Assignment *assignment;

TAILQ_FOREACH(assignment, &assignments, assignments) {
TAILQ_FOREACH (assignment, &assignments, assignments) {
if ((type != A_ANY && (assignment->type & type) == 0) ||
!match_matches_window(&(assignment->match), window))
continue;
Expand Down

0 comments on commit 1f0c628

Please sign in to comment.