From 50c1268f5ebf97df7172e70a304928974e0823ae Mon Sep 17 00:00:00 2001 From: Cagebreak Signing Key 3 Date: Wed, 3 Jun 2020 16:20:02 +0200 Subject: [PATCH] Apply clang-format --- fuzz/fuzz-lib.c | 112 +++++++++++++++++++++++++--------------------- fuzz/fuzz-lib.h | 21 ++++++--- fuzz/fuzz-parse.c | 12 +++-- render.c | 29 ++++++------ view.c | 33 +++++++------- xdg_shell.c | 16 +++---- 6 files changed, 120 insertions(+), 103 deletions(-) diff --git a/fuzz/fuzz-lib.c b/fuzz/fuzz-lib.c index b5376e5..e99a21f 100644 --- a/fuzz/fuzz-lib.c +++ b/fuzz/fuzz-lib.c @@ -20,21 +20,21 @@ #include #include -#include -#include +#include +#include #include +#include #include #include #include #include #include #include +#include #include #include #include #include -#include -#include #if CG_HAS_XWAYLAND #include #endif @@ -46,12 +46,12 @@ #include #endif +#include "../idle_inhibit_v1.h" #include "../keybinding.h" #include "../output.h" #include "../parse.h" #include "../seat.h" #include "../server.h" -#include "../idle_inhibit_v1.h" #include "../xdg_shell.h" #if CG_HAS_XWAYLAND #include "../xwayland.h" @@ -172,17 +172,18 @@ LLVMFuzzerInitialize(int *argc, char ***argv) { } server.backend = backend; - struct wlr_backend *headless_backend=wlr_headless_backend_create(server.wl_display, NULL); + struct wlr_backend *headless_backend = + wlr_headless_backend_create(server.wl_display, NULL); if(!headless_backend) { wlr_log(WLR_ERROR, "Unable to create the wlroots headless backend"); ret = 1; goto end; } - wlr_headless_add_output(headless_backend,600,300); - + wlr_headless_add_output(headless_backend, 600, 300); if(!wlr_multi_backend_add(backend, headless_backend)) { - wlr_log(WLR_ERROR, "Unable to insert headless backend into multi backend"); + wlr_log(WLR_ERROR, + "Unable to insert headless backend into multi backend"); ret = 1; goto end; }; @@ -389,7 +390,7 @@ LLVMFuzzerInitialize(int *argc, char ***argv) { /* Place the cursor to the topl left of the output layout. */ wlr_cursor_warp(server.seat->cursor, NULL, 0, 0); atexit(cleanup); - //server.wl_display->run = 1; + // server.wl_display->run = 1; return 0; end: cleanup(); @@ -398,57 +399,59 @@ end: void move_cursor(char *line, struct cg_server *server) { - return;//TODO - long del=0; + return; // TODO + long del = 0; char *delstr = strtok_r(NULL, ";", &line); - enum wlr_axis_orientation orientation = (*(line++)=='0')? WLR_AXIS_ORIENTATION_VERTICAL:WLR_AXIS_ORIENTATION_HORIZONTAL; + enum wlr_axis_orientation orientation = + (*(line++) == '0') ? WLR_AXIS_ORIENTATION_VERTICAL + : WLR_AXIS_ORIENTATION_HORIZONTAL; if(delstr == NULL) { return; } - del=strtol(delstr,NULL,10); - struct wlr_event_pointer_axis event = { - .device = NULL, - .time_msec = 0, - .source = WLR_AXIS_SOURCE_WHEEL, - .orientation = orientation, - .delta = del * 15, - .delta_discrete = del - }; - //TODO dispatch_cursor_axis(server->seat->cursor, &event); + del = strtol(delstr, NULL, 10); + struct wlr_event_pointer_axis event = {.device = NULL, + .time_msec = 0, + .source = WLR_AXIS_SOURCE_WHEEL, + .orientation = orientation, + .delta = del * 15, + .delta_discrete = del}; + // TODO dispatch_cursor_axis(server->seat->cursor, &event); } -void add_output_callback(struct wlr_backend *backend, void *data) { - long *dims=data; +void +add_output_callback(struct wlr_backend *backend, void *data) { + long *dims = data; wlr_headless_add_output(backend, dims[0], dims[1]); } void create_output(char *line, struct cg_server *server) { char *widthstr = strtok_r(NULL, ";", &line); - long dims[2]= {600, 200}; + long dims[2] = {600, 200}; if(widthstr != NULL) { - dims[0]=strtol(widthstr,NULL,10); + dims[0] = strtol(widthstr, NULL, 10); if(line[0] != '\0') { ++line; } } char *heightstr = strtok_r(NULL, ";", &line); if(heightstr != NULL) { - dims[1]=strtol(heightstr,NULL,10); + dims[1] = strtol(heightstr, NULL, 10); } long max_dim = 10000; - if (dims[0] > max_dim || dims[0] <= 0 ) { + if(dims[0] > max_dim || dims[0] <= 0) { wlr_log(WLR_ERROR, "height out of range."); return; - } else if (dims[1] > max_dim || dims[1] <= 0) { + } else if(dims[1] > max_dim || dims[1] <= 0) { wlr_log(WLR_ERROR, "width out of range."); return; } wlr_multi_for_each_backend(server->backend, add_output_callback, dims); } -void add_input_device_callback(struct wlr_backend *backend, void *data) { - enum wlr_input_device_type *type=data; +void +add_input_device_callback(struct wlr_backend *backend, void *data) { + enum wlr_input_device_type *type = data; wlr_headless_add_input_device(backend, *type); } @@ -456,33 +459,37 @@ void create_input_device(char *line, struct cg_server *server) { enum wlr_input_device_type type; if(*line != '\0') { - if(strncmp(line,"kbd",3) == 0) { + if(strncmp(line, "kbd", 3) == 0) { type = WLR_INPUT_DEVICE_KEYBOARD; - wlr_multi_for_each_backend(server->backend, add_input_device_callback, &type); - } else if(strncmp(line,"ptr",3) == 0) { + wlr_multi_for_each_backend(server->backend, + add_input_device_callback, &type); + } else if(strncmp(line, "ptr", 3) == 0) { type = WLR_INPUT_DEVICE_POINTER; - wlr_multi_for_each_backend(server->backend, add_input_device_callback, &type); - } else if(strncmp(line,"tch",3) == 0) { + wlr_multi_for_each_backend(server->backend, + add_input_device_callback, &type); + } else if(strncmp(line, "tch", 3) == 0) { type = WLR_INPUT_DEVICE_TOUCH; - wlr_multi_for_each_backend(server->backend, add_input_device_callback, &type); + wlr_multi_for_each_backend(server->backend, + add_input_device_callback, &type); } } } void destroy_input_device(char *line, struct cg_server *server) { - long devn=0; + long devn = 0; if(line[0] != '\0') { - devn = strtol(line+1,NULL,10); + devn = strtol(line + 1, NULL, 10); } if(line != NULL) { - if(strncmp(line,"k",1) == 0) { + if(strncmp(line, "k", 1) == 0) { if(wl_list_empty(&server->seat->keyboard_groups)) { return; } devn = devn % wl_list_length(&server->seat->keyboard_groups); struct cg_keyboard_group *group, *group_tmp; - wl_list_for_each_safe(group, group_tmp, &server->seat->keyboard_groups, link) { + wl_list_for_each_safe(group, group_tmp, + &server->seat->keyboard_groups, link) { if(devn == 0) { wl_list_remove(&group->link); wlr_keyboard_group_destroy(group->wlr_group); @@ -492,55 +499,56 @@ destroy_input_device(char *line, struct cg_server *server) { } --devn; } - } else if(strncmp(line,"p",1) == 0) { + } else if(strncmp(line, "p", 1) == 0) { if(wl_list_empty(&server->seat->pointers)) { return; } devn = devn % wl_list_length(&server->seat->pointers); struct cg_pointer *pointer, *pointer_tmp; - wl_list_for_each_safe(pointer, pointer_tmp, &server->seat->pointers, link) { + wl_list_for_each_safe(pointer, pointer_tmp, &server->seat->pointers, + link) { if(devn == 0) { pointer->destroy.notify(&pointer->destroy, NULL); break; } --devn; } - } else if(strncmp(line,"t",1) == 0) { + } else if(strncmp(line, "t", 1) == 0) { if(wl_list_empty(&server->seat->touch)) { return; } devn = devn % wl_list_length(&server->seat->touch); struct cg_touch *touch, *touch_tmp; - wl_list_for_each_safe(touch, touch_tmp, &server->seat->touch, link) { + wl_list_for_each_safe(touch, touch_tmp, &server->seat->touch, + link) { if(devn == 0) { touch->destroy.notify(&touch->destroy, NULL); break; } --devn; } - } } } void destroy_output(char *line, struct cg_server *server) { - if(wl_list_length(&server->outputs)<2) { + if(wl_list_length(&server->outputs) < 2) { return; } char *outpnstr = strtok_r(NULL, ";", &line); long outpn = 0; if(outpnstr != NULL) { - outpn=strtol(outpnstr,NULL,10); + outpn = strtol(outpnstr, NULL, 10); } - outpn=outpn%wl_list_length(&server->outputs); + outpn = outpn % wl_list_length(&server->outputs); struct cg_output *it; - wl_list_for_each(it,&server->outputs,link) { + wl_list_for_each(it, &server->outputs, link) { if(outpn == 0) { break; } else { --outpn; } } - it->damage_destroy.notify(&it->damage_destroy,NULL); + it->damage_destroy.notify(&it->damage_destroy, NULL); } diff --git a/fuzz/fuzz-lib.h b/fuzz/fuzz-lib.h index 95007b3..0ea499b 100644 --- a/fuzz/fuzz-lib.h +++ b/fuzz/fuzz-lib.h @@ -25,18 +25,25 @@ struct wlr_xwayland *xwayland; struct wlr_xcursor_manager *xcursor_manager; #endif -void cleanup(); +void +cleanup(); -int LLVMFuzzerInitialize(int *argc, char ***argv); +int +LLVMFuzzerInitialize(int *argc, char ***argv); -void move_cursor(char *line, struct cg_server *server); +void +move_cursor(char *line, struct cg_server *server); -void create_output(char *line, struct cg_server *server); +void +create_output(char *line, struct cg_server *server); -void create_input_device(char *line, struct cg_server *server); +void +create_input_device(char *line, struct cg_server *server); -void destroy_input_device(char *line, struct cg_server *server); +void +destroy_input_device(char *line, struct cg_server *server); -void destroy_output(char *line, struct cg_server *server); +void +destroy_output(char *line, struct cg_server *server); #endif diff --git a/fuzz/fuzz-parse.c b/fuzz/fuzz-parse.c index 1403eda..8aded78 100644 --- a/fuzz/fuzz-parse.c +++ b/fuzz/fuzz-parse.c @@ -11,20 +11,20 @@ #include #include +#include #include #include #include -#include -#include "config.h" #include "../keybinding.h" #include "../message.h" #include "../output.h" #include "../parse.h" #include "../seat.h" #include "../server.h" -#include "../workspace.h" #include "../view.h" +#include "../workspace.h" +#include "config.h" #if CG_HAS_XWAYLAND #include "../xwayland.h" #endif @@ -39,7 +39,7 @@ set_configuration(struct cg_server *server, char *content) { line[strcspn(line, "\n")] = '\0'; if(*line != '\0' && *line != '#') { char *errstr; - server->running=true; + server->running = true; if(parse_rc_line(server, line, &errstr) != 0) { if(errstr != NULL) { free(errstr); @@ -69,9 +69,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { run_action(KEYBINDING_LAYOUT_FULLSCREEN, &server, (union keybinding_params){.c = NULL}); struct cg_output *output; - wl_list_for_each(output, &server.outputs, link) { - message_clear(output); - } + wl_list_for_each(output, &server.outputs, link) { message_clear(output); } for(unsigned int i = 3; server.modes[i] != NULL; ++i) { free(server.modes[i]); } diff --git a/render.c b/render.c index 649f9bc..e1ca1c1 100644 --- a/render.c +++ b/render.c @@ -103,10 +103,12 @@ render_surface_iterator(struct cg_output *output, struct wlr_surface *surface, wlr_output->transform_matrix); if(data->tile_width != 0) { - box->width = box->width > data->tile_width ? data->tile_width:box->width; + box->width = + box->width > data->tile_width ? data->tile_width : box->width; } if(data->tile_height != 0) { - box->height = box->height > data->tile_height ? data->tile_height:box->height; + box->height = + box->height > data->tile_height ? data->tile_height : box->height; } render_texture(wlr_output, output_damage, texture, box, matrix); } @@ -116,8 +118,8 @@ render_drag_icons(struct cg_output *output, pixman_region32_t *damage, struct wl_list *drag_icons) { struct render_data data = { .damage = damage, - .tile_width = 0, - .tile_height = 0, + .tile_width = 0, + .tile_height = 0, }; output_drag_icons_for_each_surface(output, drag_icons, render_surface_iterator, &data); @@ -131,17 +133,18 @@ render_view_toplevels(struct cg_view *view, struct cg_output *output, pixman_region32_t *damage) { struct render_data data = { .damage = damage, - .tile_width = 0, - .tile_height = 0, + .tile_width = 0, + .tile_height = 0, }; - //TODO: improve run time behaviour of view_get_tile - struct cg_tile *view_tile=view_get_tile(view); + // TODO: improve run time behaviour of view_get_tile + struct cg_tile *view_tile = view_get_tile(view); if(view_tile != NULL) { - if(view_tile->tile.width != view->wlr_surface->current.width || view_tile->tile.height != view->wlr_surface->current.height) { + if(view_tile->tile.width != view->wlr_surface->current.width || + view_tile->tile.height != view->wlr_surface->current.height) { view_damage_whole(view); } - data.tile_width=view_tile->tile.width; - data.tile_height=view_tile->tile.height; + data.tile_width = view_tile->tile.width; + data.tile_height = view_tile->tile.height; } double ox, oy; @@ -167,8 +170,8 @@ render_view_popups(struct cg_view *view, struct cg_output *output, pixman_region32_t *damage) { struct render_data data = { .damage = damage, - .tile_width = 0, - .tile_height = 0, + .tile_width = 0, + .tile_height = 0, }; output_view_for_each_popup(output, view, render_popup_iterator, &data); } diff --git a/view.c b/view.c index 1329e57..142ac36 100644 --- a/view.c +++ b/view.c @@ -14,11 +14,11 @@ #include #include #include +#include #include #include #include #include -#include #include "output.h" #include "seat.h" @@ -46,14 +46,14 @@ view_get_prev_view(struct cg_view *view) { } void -view_damage_child(struct cg_view_child *child, int x, int y,bool whole); +view_damage_child(struct cg_view_child *child, int x, int y, bool whole); static void view_child_handle_commit(struct wl_listener *listener, void *_data) { struct cg_view_child *child = wl_container_of(listener, child, commit); - int x,y; + int x, y; child->get_coords(child, &x, &y); - view_damage_child(child,child->view->ox+x,child->view->oy+y,false); + view_damage_child(child, child->view->ox + x, child->view->oy + y, false); } static void @@ -73,9 +73,9 @@ view_child_finish(struct cg_view_child *child) { return; } - int x,y; + int x, y; child->get_coords(child, &x, &y); - view_damage_child(child,child->view->ox+x,child->view->oy+y,true); + view_damage_child(child, child->view->ox + x, child->view->oy + y, true); wl_list_remove(&child->link); wl_list_remove(&child->commit.link); @@ -124,10 +124,10 @@ subsurface_get_coords(struct cg_view_child *child, int *x, int *y) { *y = 0; if(!(child->view && child->view->impl)) { - while (surface && wlr_surface_is_subsurface(surface)) { + while(surface && wlr_surface_is_subsurface(surface)) { struct wlr_subsurface *subsurface = - wlr_subsurface_from_wlr_surface(surface); - if (subsurface == NULL) { + wlr_subsurface_from_wlr_surface(surface); + if(subsurface == NULL) { break; } *x += subsurface->current.x; @@ -135,7 +135,6 @@ subsurface_get_coords(struct cg_view_child *child, int *x, int *y) { surface = subsurface->parent; } } - } static void @@ -202,7 +201,9 @@ view_is_visible(const struct cg_view *view) { void view_damage(struct cg_view *view, bool whole) { struct cg_tile *view_tile = view_get_tile(view); - if(view_tile != NULL&&(view->wlr_surface->current.width != view_tile->tile.width || view->wlr_surface->current.height != view_tile->tile.height)) { + if(view_tile != NULL && + (view->wlr_surface->current.width != view_tile->tile.width || + view->wlr_surface->current.height != view_tile->tile.height)) { view_maximize(view, &view_tile->tile); } output_damage_surface(view->workspace->output, view->wlr_surface, view->ox, @@ -210,7 +211,7 @@ view_damage(struct cg_view *view, bool whole) { } void -view_damage_child(struct cg_view_child *child, int x, int y,bool whole) { +view_damage_child(struct cg_view_child *child, int x, int y, bool whole) { output_damage_surface(child->view->workspace->output, child->wlr_surface, x, y, whole); } @@ -279,10 +280,10 @@ view_unmap(struct cg_view *view) { .focused_surface == NULL || view->workspace->server->seat->seat->keyboard_state .focused_surface == view->wlr_surface) && - view->workspace->server->curr_output - ->workspaces[view->workspace->server->curr_output - ->curr_workspace] - ->focused_tile == view_tile) { + view->workspace->server->curr_output + ->workspaces[view->workspace->server->curr_output + ->curr_workspace] + ->focused_tile == view_tile) { seat_set_focus(view->workspace->server->seat, prev); } else { view_tile->view = prev; diff --git a/xdg_shell.c b/xdg_shell.c index ce6d93b..59b3334 100644 --- a/xdg_shell.c +++ b/xdg_shell.c @@ -16,8 +16,8 @@ #include #include #include -#include #include +#include #include "output.h" #include "server.h" @@ -120,7 +120,8 @@ popup_unconstrain(struct cg_xdg_popup *popup) { wlr_xdg_popup_unconstrain_from_box(popup->wlr_popup, &output_toplevel_box); } -static void xdg_popup_get_coords(struct cg_view_child *child, int *x, int *y) { +static void +xdg_popup_get_coords(struct cg_view_child *child, int *x, int *y) { if(!child) { return; } @@ -130,11 +131,9 @@ static void xdg_popup_get_coords(struct cg_view_child *child, int *x, int *y) { int x_offset = -surface->geometry.x; int y_offset = -surface->geometry.y; - wlr_xdg_popup_get_toplevel_coords(surface->popup, - x_offset + surface->popup->geometry.x, - y_offset + surface->popup->geometry.y, - x, y); - + wlr_xdg_popup_get_toplevel_coords( + surface->popup, x_offset + surface->popup->geometry.x, + y_offset + surface->popup->geometry.y, x, y); } static void @@ -216,7 +215,8 @@ static void maximize(struct cg_view *view, int width, int height) { struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view); wlr_xdg_toplevel_set_size(xdg_shell_view->xdg_surface, width, height); - enum wlr_edges edges = WLR_EDGE_LEFT|WLR_EDGE_RIGHT|WLR_EDGE_TOP|WLR_EDGE_BOTTOM; + enum wlr_edges edges = + WLR_EDGE_LEFT | WLR_EDGE_RIGHT | WLR_EDGE_TOP | WLR_EDGE_BOTTOM; wlr_xdg_toplevel_set_tiled(xdg_shell_view->xdg_surface, edges); }