Coding style enforcement

This was done by hand, so I might have missed things. If anyone knows of
a good C style enforcement tool, let me know.
This commit is contained in:
Drew DeVault 2015-08-18 07:19:20 -04:00
parent af1b3d9755
commit 2139001c9f
11 changed files with 119 additions and 136 deletions

View file

@ -30,7 +30,6 @@ struct sway_container {
wlc_handle handle;
enum swayc_types type;
enum swayc_layouts layout;
// Not including borders or margins
@ -42,9 +41,7 @@ struct sway_container {
int x, y;
bool visible;
bool is_floating;
bool is_focused;
int weight;
@ -52,8 +49,6 @@ struct sway_container {
char *name;
list_t *children;
// Special list for floating windows in workspaces
list_t *floating;
struct sway_container *parent;
@ -62,17 +57,17 @@ struct sway_container {
swayc_t *new_output(wlc_handle handle);
swayc_t *new_workspace(swayc_t * output, const char *name);
//Creates container Around child (parent child) -> (parent (container child))
swayc_t *new_workspace(swayc_t *output, const char *name);
// Creates container Around child (parent child) -> (parent (container child))
swayc_t *new_container(swayc_t *child, enum swayc_layouts layout);
//Creates view as a sibling of current focused container, or as child of a workspace
// Creates view as a sibling of current focused container, or as child of a workspace
swayc_t *new_view(swayc_t *sibling, wlc_handle handle);
//Creates view as a new floating view which is in the active workspace
// Creates view as a new floating view which is in the active workspace
swayc_t *new_floating_view(wlc_handle handle);
swayc_t *destroy_output(swayc_t *output);
//destroys workspace if empty and returns parent pointer, else returns NULL
// Destroys workspace if empty and returns parent pointer, else returns NULL
swayc_t *destroy_workspace(swayc_t *workspace);
swayc_t *destroy_container(swayc_t *container);
swayc_t *destroy_view(swayc_t *view);
@ -80,7 +75,7 @@ swayc_t *destroy_view(swayc_t *view);
swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data);
void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *);
//Mappings
// Mappings
void set_view_visibility(swayc_t *view, void *data);
#endif

View file

@ -10,12 +10,12 @@ enum movement_direction {
MOVE_PARENT
};
//focused_container - the container found by following the `focused` pointer
//from a given container to a container with `is_focused` boolean set
//---
//focused_view - the container found by following the `focused` pointer from a
//given container to a view.
//---
// focused_container - the container found by following the `focused` pointer
// from a given container to a container with `is_focused` boolean set
// ---
// focused_view - the container found by following the `focused` pointer from a
// given container to a view.
// ---
swayc_t *get_focused_container(swayc_t *parent);
swayc_t *get_focused_view(swayc_t *parent);
@ -23,8 +23,8 @@ swayc_t *get_focused_view(swayc_t *parent);
void set_focused_container(swayc_t *container);
void set_focused_container_for(swayc_t *ancestor, swayc_t *container);
//lock focused container/view. locked by windows with OVERRIDE attribute
//and unlocked when they are destroyed
// lock focused container/view. locked by windows with OVERRIDE attribute
// and unlocked when they are destroyed
extern bool locked_container_focus;
extern bool locked_view_focus;

View file

@ -7,7 +7,7 @@
extern struct wlc_interface interface;
extern uint32_t keys_pressed[32];
//set focus to current pointer location and return focused container
// set focus to current pointer location and return focused container
swayc_t *container_under_pointer(void);
#endif

View file

@ -10,15 +10,15 @@ extern swayc_t root_container;
void init_layout(void);
void add_child(swayc_t *parent, swayc_t *child);
//Returns parent container which needs to be rearranged.
// Returns parent container which needs to be rearranged.
swayc_t *add_sibling(swayc_t *sibling, swayc_t *child);
swayc_t *replace_child(swayc_t *child, swayc_t *new_child);
swayc_t *remove_child(swayc_t *child);
//Layout
// Layout
void arrange_windows(swayc_t *container, int width, int height);
//Focus
// Focus
void unfocus_all(swayc_t *container);
void focus_view(swayc_t *view);
void focus_view_for(swayc_t *ancestor, swayc_t *container);

View file

@ -292,9 +292,11 @@ static bool cmd_layout(struct sway_config *config, int argc, char **argv) {
return false;
}
swayc_t *parent = get_focused_container(&root_container);
while (parent->type == C_VIEW) {
parent = parent->parent;
}
if (strcasecmp(argv[0], "splith") == 0) {
parent->layout = L_HORIZ;
} else if (strcasecmp(argv[0], "splitv") == 0) {
@ -343,19 +345,17 @@ static bool _do_split(struct sway_config *config, int argc, char **argv, int lay
}
swayc_t *focused = get_focused_container(&root_container);
/* Case that focus is on an workspace with 0/1 children.change its layout */
if (focused->type == C_WORKSPACE && focused->children->length <= 1) {
/* Case that focus is on an workspace with 0/1 children.change its layout */
sway_log(L_DEBUG, "changing workspace layout");
focused->layout = layout;
}
} else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) {
/* Case of no siblings. change parent layout */
else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) {
sway_log(L_DEBUG, "changing container layout");
focused->parent->layout = layout;
}
} else {
/* regular case where new split container is build around focused container
* or in case of workspace, container inherits its children */
else {
sway_log(L_DEBUG, "Adding new container around current focused container");
swayc_t *parent = new_container(focused, layout);
set_focused_container(focused);
@ -369,6 +369,7 @@ static bool cmd_split(struct sway_config *config, int argc, char **argv) {
if (!checkarg(argc, "split", EXPECTED_EQUAL_TO, 1)) {
return false;
}
if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) {
_do_split(config, argc - 1, argv + 1, L_VERT);
} else if (strcasecmp(argv[0], "h") == 0 || strcasecmp(argv[0], "horizontal") == 0) {
@ -377,6 +378,7 @@ static bool cmd_split(struct sway_config *config, int argc, char **argv) {
sway_log(L_ERROR, "Invalid split command (expected either horiziontal or vertical).");
return false;
}
return true;
}

View file

@ -15,7 +15,7 @@ static bool exists(const char *path) {
return access(path, R_OK) != -1;
}
static char* get_config_path() {
static char *get_config_path() {
char *name = "/.sway/config";
const char *home = getenv("HOME");

View file

@ -50,14 +50,7 @@ swayc_t *new_output(wlc_handle handle) {
add_child(&root_container, output);
//TODO still dont know why this is here?
// int total_width = 0;
// int i;
// for (i = 0; i < root_container.children->length; ++i) {
// total_width += ((swayc_t*)root_container.children->items[i])->width;
// }
//Create workspace
// Create workspace
char *ws_name = NULL;
if (name) {
int i;
@ -73,7 +66,8 @@ swayc_t *new_output(wlc_handle handle) {
if (!ws_name) {
ws_name = workspace_next_name();
}
//create and initilize default workspace
// create and initilize default workspace
swayc_t *ws = new_workspace(output, ws_name);
ws->is_focused = true;
@ -86,7 +80,7 @@ swayc_t *new_workspace(swayc_t *output, const char *name) {
sway_log(L_DEBUG, "Added workspace %s for output %u", name, (unsigned int)output->handle);
swayc_t *workspace = new_swayc(C_WORKSPACE);
workspace->layout = L_HORIZ; // TODO:default layout
workspace->layout = L_HORIZ; // TODO: default layout
workspace->width = output->width;
workspace->height = output->height;
workspace->name = strdup(name);
@ -112,26 +106,24 @@ swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) {
/* Container inherits all of workspaces children, layout and whatnot */
if (child->type == C_WORKSPACE) {
swayc_t *workspace = child;
//reorder focus
// reorder focus
cont->focused = workspace->focused;
workspace->focused = cont;
//set all children focu to container
// set all children focu to container
int i;
for (i = 0; i < workspace->children->length; ++i) {
((swayc_t *)workspace->children->items[i])->parent = cont;
}
//Swap children
// Swap children
list_t *tmp_list = workspace->children;
workspace->children = cont->children;
cont->children = tmp_list;
//add container to workspace chidren
// add container to workspace chidren
add_child(workspace, cont);
//give them proper layouts
// give them proper layouts
cont->layout = workspace->layout;
workspace->layout = layout;
}
//Or is built around container
else {
} else { // Or is built around container
swayc_t *parent = replace_child(child, cont);
if (parent) {
add_child(cont, child);
@ -145,7 +137,7 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) {
swayc_t *view = new_swayc(C_VIEW);
sway_log(L_DEBUG, "Adding new view %lu:%s to container %p %d",
handle, title, sibling, sibling ? sibling->type : 0);
//Setup values
// Setup values
view->handle = handle;
view->name = title ? strdup(title) : NULL;
view->visible = true;
@ -157,12 +149,11 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) {
// TODO: properly set this
view->is_floating = false;
//Case of focused workspace, just create as child of it
if (sibling->type == C_WORKSPACE) {
// Case of focused workspace, just create as child of it
add_child(sibling, view);
}
//Regular case, create as sibling of current container
else {
} else {
// Regular case, create as sibling of current container
add_sibling(sibling, view);
}
return view;
@ -173,7 +164,7 @@ swayc_t *new_floating_view(wlc_handle handle) {
swayc_t *view = new_swayc(C_VIEW);
sway_log(L_DEBUG, "Adding new view %lu:%x:%s as a floating view",
handle, wlc_view_get_type(handle), title);
//Setup values
// Setup values
view->handle = handle;
view->name = title ? strdup(title) : NULL;
view->visible = true;
@ -191,7 +182,7 @@ swayc_t *new_floating_view(wlc_handle handle) {
view->is_floating = true;
//Case of focused workspace, just create as child of it
// Case of focused workspace, just create as child of it
list_add(active_workspace->floating, view);
view->parent = active_workspace;
if (active_workspace->focused == NULL) {
@ -204,7 +195,7 @@ swayc_t *new_floating_view(wlc_handle handle) {
swayc_t *destroy_output(swayc_t *output) {
if (output->children->length == 0) {
//TODO move workspaces to other outputs
// TODO move workspaces to other outputs
}
sway_log(L_DEBUG, "OUTPUT: Destroying output '%lu'", output->handle);
free_swayc(output);
@ -212,9 +203,9 @@ swayc_t *destroy_output(swayc_t *output) {
}
swayc_t *destroy_workspace(swayc_t *workspace) {
//NOTE: This is called from elsewhere without checking children length
//TODO move containers to other workspaces?
//for now just dont delete
// NOTE: This is called from elsewhere without checking children length
// TODO move containers to other workspaces?
// for now just dont delete
if (workspace->children->length == 0) {
sway_log(L_DEBUG, "Workspace: Destroying workspace '%s'", workspace->name);
swayc_t *parent = workspace->parent;
@ -244,7 +235,7 @@ swayc_t *destroy_view(swayc_t *view) {
swayc_t *parent = view->parent;
free_swayc(view);
//Destroy empty containers
// Destroy empty containers
if (parent->type == C_CONTAINER) {
return destroy_container(parent);
}
@ -303,5 +294,3 @@ void set_view_visibility(swayc_t *view, void *data) {
}
view->visible = (*p == 2);
}

View file

@ -7,10 +7,10 @@
bool locked_container_focus = false;
bool locked_view_focus = false;
//switches parent focus to c. will switch it accordingly
//TODO, everything needs a handle, so we can set front/back position properly
// switches parent focus to c. will switch it accordingly
// TODO: Everything needs a handle, so we can set front/back position properly
static void update_focus(swayc_t *c) {
//Handle if focus switches
// Handle if focus switches
swayc_t *parent = c->parent;
if (parent->focused != c) {
switch (c->type) {
@ -18,14 +18,14 @@ static void update_focus(swayc_t *c) {
case C_OUTPUT:
wlc_output_focus(c->parent->handle);
break;
//switching workspaces
// switching workspaces
case C_WORKSPACE:
if (parent->focused) {
swayc_t *ws = parent->focused;
//hide visibility of old workspace
// hide visibility of old workspace
uint32_t mask = 1;
container_map(ws, set_view_visibility, &mask);
//set visibility of new workspace
// set visibility of new workspace
mask = 2;
container_map(c, set_view_visibility, &mask);
wlc_output_set_mask(parent->handle, 2);
@ -36,8 +36,8 @@ static void update_focus(swayc_t *c) {
default:
case C_VIEW:
case C_CONTAINER:
//TODO whatever to do when container changes
//for example, stacked and tabbing change stuff.
// TODO whatever to do when container changes
// for example, stacked and tabbing change stuff.
break;
}
}
@ -115,7 +115,7 @@ swayc_t *get_focused_container(swayc_t *parent) {
while (parent && !parent->is_focused) {
parent = parent->focused;
}
//just incase
// just incase
if (parent == NULL) {
sway_log(L_DEBUG, "get_focused_container unable to find container");
return active_workspace;
@ -140,7 +140,7 @@ void set_focused_container(swayc_t *c) {
}
if (!locked_view_focus) {
p = get_focused_view(c);
//Set focus to p
// Set focus to p
if (p && !(wlc_view_get_type(p->handle) & WLC_BIT_POPUP)) {
if (prev_view) {
wlc_view_set_state(prev_view->handle, WLC_BIT_ACTIVATED, false);
@ -175,7 +175,7 @@ void set_focused_container_for(swayc_t *a, swayc_t *c) {
}
if (!locked_view_focus) {
p = get_focused_view(c);
//Set focus to p
// Set focus to p
if (p) {
wlc_view_focus(p->handle);
wlc_view_set_state(p->handle, WLC_BIT_ACTIVATED, true);
@ -189,4 +189,3 @@ swayc_t *get_focused_view(swayc_t *parent) {
}
return parent;
}

View file

@ -23,7 +23,7 @@ static bool m2_held = false;
static bool pointer_test(swayc_t *view, void *_origin) {
const struct wlc_origin *origin = _origin;
//Determine the output that the view is under
// Determine the output that the view is under
swayc_t *parent = view;
while (parent->type != C_OUTPUT) {
parent = parent->parent;
@ -37,25 +37,25 @@ static bool pointer_test(swayc_t *view, void *_origin) {
}
swayc_t *container_under_pointer(void) {
//root.output->workspace
// root.output->workspace
if (!root_container.focused || !root_container.focused->focused) {
return NULL;
}
swayc_t *lookup = root_container.focused->focused;
//Case of empty workspace
// Case of empty workspace
if (lookup->children == 0) {
return NULL;
}
while (lookup->type != C_VIEW) {
int i;
int len;
//if tabbed/stacked go directly to focused container, otherwise search
//children
// if tabbed/stacked go directly to focused container, otherwise search
// children
if (lookup->layout == L_TABBED || lookup->layout == L_STACKED) {
lookup = lookup->focused;
continue;
}
//if workspace, search floating
// if workspace, search floating
if (lookup->type == C_WORKSPACE) {
len = lookup->floating->length;
for (i = 0; i < len; ++i) {
@ -68,7 +68,7 @@ swayc_t *container_under_pointer(void) {
continue;
}
}
//search children
// search children
len = lookup->children->length;
for (i = 0; i < len; ++i) {
if (pointer_test(lookup->children->items[i], &mouse_origin)) {
@ -76,7 +76,7 @@ swayc_t *container_under_pointer(void) {
break;
}
}
//when border and titles are done, this could happen
// when border and titles are done, this could happen
if (i == len) {
break;
}
@ -119,7 +119,7 @@ static void handle_output_resolution_change(wlc_handle output, const struct wlc_
static void handle_output_focused(wlc_handle output, bool focus) {
swayc_t *c = get_swayc_for_handle(output, &root_container);
//if for some reason this output doesnt exist, create it.
// if for some reason this output doesnt exist, create it.
if (!c) {
handle_output_created(output);
}
@ -132,12 +132,12 @@ static bool handle_view_created(wlc_handle handle) {
swayc_t *focused = get_focused_container(&root_container);
swayc_t *newview = NULL;
switch (wlc_view_get_type(handle)) {
//regular view created regularly
// regular view created regularly
case 0:
newview = new_view(focused, handle);
wlc_view_set_state(handle, WLC_BIT_MAXIMIZED, true);
break;
//takes keyboard focus
// takes keyboard focus
case WLC_BIT_OVERRIDE_REDIRECT:
sway_log(L_DEBUG, "view %ld with OVERRIDE_REDIRECT", handle);
locked_view_focus = true;
@ -145,13 +145,13 @@ static bool handle_view_created(wlc_handle handle) {
wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true);
wlc_view_bring_to_front(handle);
break;
//Takes container focus
// Takes container focus
case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED:
sway_log(L_DEBUG, "view %ld with OVERRIDE_REDIRECT|WLC_BIT_MANAGED", handle);
wlc_view_bring_to_front(handle);
locked_container_focus = true;
break;
//set modals as floating containers
// set modals as floating containers
case WLC_BIT_MODAL:
wlc_view_bring_to_front(handle);
newview = new_floating_view(handle);
@ -170,7 +170,7 @@ static void handle_view_destroyed(wlc_handle handle) {
swayc_t *view = get_swayc_for_handle(handle, &root_container);
switch (wlc_view_get_type(handle)) {
//regular view created regularly
// regular view created regularly
case 0:
case WLC_BIT_MODAL:
if (view) {
@ -178,11 +178,11 @@ static void handle_view_destroyed(wlc_handle handle) {
arrange_windows(parent, -1, -1);
}
break;
//takes keyboard focus
// takes keyboard focus
case WLC_BIT_OVERRIDE_REDIRECT:
locked_view_focus = false;
break;
//Takes container focus
// Takes container focus
case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED:
locked_container_focus = false;
case WLC_BIT_POPUP:
@ -195,7 +195,7 @@ static void handle_view_focus(wlc_handle view, bool focus) {
return;
}
static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geometry* geometry) {
static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geometry *geometry) {
sway_log(L_DEBUG, "geometry request %d x %d : %d x %d",
geometry->origin.x, geometry->origin.y, geometry->size.w,geometry->size.h);
// If the view is floating, then apply the geometry.
@ -220,20 +220,19 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s
swayc_t *c = NULL;
switch(state) {
case WLC_BIT_FULLSCREEN:
//I3 just lets it become fullscreen
// i3 just lets it become fullscreen
wlc_view_set_state(view, state, toggle);
c = get_swayc_for_handle(view, &root_container);
sway_log(L_DEBUG, "setting view %ld %s, fullscreen %d",view,c->name,toggle);
if (c) {
arrange_windows(c->parent, -1, -1);
//Set it as focused window for that workspace if its going
//fullscreen
// Set it as focused window for that workspace if its going fullscreen
if (toggle) {
swayc_t *ws = c;
while (ws->type != C_WORKSPACE) {
ws = ws->parent;
}
//Set ws focus to c
// Set ws focus to c
set_focused_container_for(ws, c);
}
}
@ -248,8 +247,8 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s
}
static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers
*modifiers, uint32_t key, uint32_t sym, enum wlc_key_state state) {
static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers,
uint32_t key, uint32_t sym, enum wlc_key_state state) {
enum { QSIZE = 32 };
if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) {
return false;
@ -261,7 +260,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
// Lowercase if necessary
sym = tolower(sym);
//Find key, if it has been pressed
// Find key, if it has been pressed
int mid = 0;
while (mid < head && keys_pressed[mid] != sym) {
++mid;
@ -295,7 +294,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
}
if (match) {
//Remove matched keys from keys_pressed
// Remove matched keys from keys_pressed
int j;
for (j = 0; j < binding->keys->length; ++j) {
uint8_t k;

View file

@ -63,8 +63,8 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child) {
swayc_t *remove_child(swayc_t *child) {
int i;
swayc_t *parent = child->parent;
// Special case for floating views
if (child->is_floating) {
// Special case for floating views
for (i = 0; i < parent->floating->length; ++i) {
if (parent->floating->items[i] == child) {
list_del(parent->floating, i);

View file

@ -17,8 +17,7 @@ static const char *verbosity_colors[] = {
void init_log(int verbosity) {
v = verbosity;
/* set FD_CLOEXEC flag to prevent programs called with exec to write into
* logs */
/* set FD_CLOEXEC flag to prevent programs called with exec to write into logs */
int i, flag;
int fd[] = { STDOUT_FILENO, STDIN_FILENO, STDERR_FILENO };
for (i = 0; i < 3; ++i) {