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; wlc_handle handle;
enum swayc_types type; enum swayc_types type;
enum swayc_layouts layout; enum swayc_layouts layout;
// Not including borders or margins // Not including borders or margins
@ -42,9 +41,7 @@ struct sway_container {
int x, y; int x, y;
bool visible; bool visible;
bool is_floating; bool is_floating;
bool is_focused; bool is_focused;
int weight; int weight;
@ -52,8 +49,6 @@ struct sway_container {
char *name; char *name;
list_t *children; list_t *children;
// Special list for floating windows in workspaces
list_t *floating; list_t *floating;
struct sway_container *parent; struct sway_container *parent;
@ -62,17 +57,17 @@ struct sway_container {
swayc_t *new_output(wlc_handle handle); swayc_t *new_output(wlc_handle handle);
swayc_t *new_workspace(swayc_t * output, const char *name); swayc_t *new_workspace(swayc_t *output, const char *name);
//Creates container Around child (parent child) -> (parent (container child)) // Creates container Around child (parent child) -> (parent (container child))
swayc_t *new_container(swayc_t *child, enum swayc_layouts layout); 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); 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 *new_floating_view(wlc_handle handle);
swayc_t *destroy_output(swayc_t *output); 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_workspace(swayc_t *workspace);
swayc_t *destroy_container(swayc_t *container); swayc_t *destroy_container(swayc_t *container);
swayc_t *destroy_view(swayc_t *view); 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); 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 *); void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *);
//Mappings // Mappings
void set_view_visibility(swayc_t *view, void *data); void set_view_visibility(swayc_t *view, void *data);
#endif #endif

View file

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

View file

@ -7,7 +7,7 @@
extern struct wlc_interface interface; extern struct wlc_interface interface;
extern uint32_t keys_pressed[32]; 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); swayc_t *container_under_pointer(void);
#endif #endif

View file

@ -10,15 +10,15 @@ extern swayc_t root_container;
void init_layout(void); void init_layout(void);
void add_child(swayc_t *parent, swayc_t *child); 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 *add_sibling(swayc_t *sibling, swayc_t *child);
swayc_t *replace_child(swayc_t *child, swayc_t *new_child); swayc_t *replace_child(swayc_t *child, swayc_t *new_child);
swayc_t *remove_child(swayc_t *child); swayc_t *remove_child(swayc_t *child);
//Layout // Layout
void arrange_windows(swayc_t *container, int width, int height); void arrange_windows(swayc_t *container, int width, int height);
//Focus // Focus
void unfocus_all(swayc_t *container); void unfocus_all(swayc_t *container);
void focus_view(swayc_t *view); void focus_view(swayc_t *view);
void focus_view_for(swayc_t *ancestor, swayc_t *container); void focus_view_for(swayc_t *ancestor, swayc_t *container);

View file

@ -40,37 +40,37 @@ enum expected_args {
static bool checkarg(int argc, char *name, enum expected_args type, int val) { static bool checkarg(int argc, char *name, enum expected_args type, int val) {
switch (type) { switch (type) {
case EXPECTED_MORE_THAN: case EXPECTED_MORE_THAN:
if (argc > val) { if (argc > val) {
return true; return true;
} }
sway_log(L_ERROR, "Invalid %s command." sway_log(L_ERROR, "Invalid %s command."
"(expected more than %d argument%s, got %d", "(expected more than %d argument%s, got %d",
name, val, (char*[2]){"s", ""}[argc==1], argc); name, val, (char*[2]){"s", ""}[argc==1], argc);
break; break;
case EXPECTED_AT_LEAST: case EXPECTED_AT_LEAST:
if (argc >= val) { if (argc >= val) {
return true; return true;
} }
sway_log(L_ERROR, "Invalid %s command." sway_log(L_ERROR, "Invalid %s command."
"(expected at least %d argument%s, got %d", "(expected at least %d argument%s, got %d",
name, val, (char*[2]){"s", ""}[argc==1], argc); name, val, (char*[2]){"s", ""}[argc==1], argc);
break; break;
case EXPECTED_LESS_THAN: case EXPECTED_LESS_THAN:
if (argc < val) { if (argc < val) {
return true; return true;
}; };
sway_log(L_ERROR, "Invalid %s command." sway_log(L_ERROR, "Invalid %s command."
"(expected less than %d argument%s, got %d", "(expected less than %d argument%s, got %d",
name, val, (char*[2]){"s", ""}[argc==1], argc); name, val, (char*[2]){"s", ""}[argc==1], argc);
break; break;
case EXPECTED_EQUAL_TO: case EXPECTED_EQUAL_TO:
if (argc == val) { if (argc == val) {
return true; return true;
}; };
sway_log(L_ERROR, "Invalid %s command." sway_log(L_ERROR, "Invalid %s command."
"(expected %d arguments, got %d", name, val, argc); "(expected %d arguments, got %d", name, val, argc);
break; break;
} }
return false; return false;
} }
@ -292,9 +292,11 @@ static bool cmd_layout(struct sway_config *config, int argc, char **argv) {
return false; return false;
} }
swayc_t *parent = get_focused_container(&root_container); swayc_t *parent = get_focused_container(&root_container);
while (parent->type == C_VIEW) { while (parent->type == C_VIEW) {
parent = parent->parent; parent = parent->parent;
} }
if (strcasecmp(argv[0], "splith") == 0) { if (strcasecmp(argv[0], "splith") == 0) {
parent->layout = L_HORIZ; parent->layout = L_HORIZ;
} else if (strcasecmp(argv[0], "splitv") == 0) { } 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); 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) { 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"); sway_log(L_DEBUG, "changing workspace layout");
focused->layout = layout; focused->layout = layout;
} } else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) {
/* Case of no siblings. change parent layout */ /* 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"); sway_log(L_DEBUG, "changing container layout");
focused->parent->layout = layout; focused->parent->layout = layout;
} } else {
/* regular case where new split container is build around focused container /* regular case where new split container is build around focused container
* or in case of workspace, container inherits its children */ * or in case of workspace, container inherits its children */
else {
sway_log(L_DEBUG, "Adding new container around current focused container"); sway_log(L_DEBUG, "Adding new container around current focused container");
swayc_t *parent = new_container(focused, layout); swayc_t *parent = new_container(focused, layout);
set_focused_container(focused); 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)) { if (!checkarg(argc, "split", EXPECTED_EQUAL_TO, 1)) {
return false; return false;
} }
if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) { if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) {
_do_split(config, argc - 1, argv + 1, L_VERT); _do_split(config, argc - 1, argv + 1, L_VERT);
} else if (strcasecmp(argv[0], "h") == 0 || strcasecmp(argv[0], "horizontal") == 0) { } 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)."); sway_log(L_ERROR, "Invalid split command (expected either horiziontal or vertical).");
return false; return false;
} }
return true; return true;
} }

View file

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

View file

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

View file

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

View file

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

View file

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