diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-18 07:19:20 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-18 07:20:34 -0400 |
commit | 2139001c9f61a84ed1ac581a54bb2bde68928afd (patch) | |
tree | a6efb486fdb71675775253d79e9550b5fc1d2f67 | |
parent | fixed floating window crashing bug (diff) | |
download | sway-2139001c9f61a84ed1ac581a54bb2bde68928afd.tar.gz sway-2139001c9f61a84ed1ac581a54bb2bde68928afd.tar.zst sway-2139001c9f61a84ed1ac581a54bb2bde68928afd.zip |
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.
-rw-r--r-- | include/container.h | 17 | ||||
-rw-r--r-- | include/focus.h | 16 | ||||
-rw-r--r-- | include/handlers.h | 2 | ||||
-rw-r--r-- | include/layout.h | 6 | ||||
-rw-r--r-- | sway/commands.c | 80 | ||||
-rw-r--r-- | sway/config.c | 2 | ||||
-rw-r--r-- | sway/container.c | 55 | ||||
-rw-r--r-- | sway/focus.c | 23 | ||||
-rw-r--r-- | sway/handlers.c | 49 | ||||
-rw-r--r-- | sway/layout.c | 2 | ||||
-rw-r--r-- | sway/log.c | 3 |
11 files changed, 119 insertions, 136 deletions
diff --git a/include/container.h b/include/container.h index 5f386368..186ee8b6 100644 --- a/include/container.h +++ b/include/container.h | |||
@@ -30,7 +30,6 @@ struct sway_container { | |||
30 | wlc_handle handle; | 30 | wlc_handle handle; |
31 | 31 | ||
32 | enum swayc_types type; | 32 | enum swayc_types type; |
33 | |||
34 | enum swayc_layouts layout; | 33 | enum swayc_layouts layout; |
35 | 34 | ||
36 | // Not including borders or margins | 35 | // Not including borders or margins |
@@ -42,9 +41,7 @@ struct sway_container { | |||
42 | int x, y; | 41 | int x, y; |
43 | 42 | ||
44 | bool visible; | 43 | bool visible; |
45 | |||
46 | bool is_floating; | 44 | bool is_floating; |
47 | |||
48 | bool is_focused; | 45 | bool is_focused; |
49 | 46 | ||
50 | int weight; | 47 | int weight; |
@@ -52,8 +49,6 @@ struct sway_container { | |||
52 | char *name; | 49 | char *name; |
53 | 50 | ||
54 | list_t *children; | 51 | list_t *children; |
55 | |||
56 | // Special list for floating windows in workspaces | ||
57 | list_t *floating; | 52 | list_t *floating; |
58 | 53 | ||
59 | struct sway_container *parent; | 54 | struct sway_container *parent; |
@@ -62,17 +57,17 @@ struct sway_container { | |||
62 | 57 | ||
63 | 58 | ||
64 | swayc_t *new_output(wlc_handle handle); | 59 | swayc_t *new_output(wlc_handle handle); |
65 | swayc_t *new_workspace(swayc_t * output, const char *name); | 60 | swayc_t *new_workspace(swayc_t *output, const char *name); |
66 | //Creates container Around child (parent child) -> (parent (container child)) | 61 | // Creates container Around child (parent child) -> (parent (container child)) |
67 | swayc_t *new_container(swayc_t *child, enum swayc_layouts layout); | 62 | swayc_t *new_container(swayc_t *child, enum swayc_layouts layout); |
68 | //Creates view as a sibling of current focused container, or as child of a workspace | 63 | // Creates view as a sibling of current focused container, or as child of a workspace |
69 | swayc_t *new_view(swayc_t *sibling, wlc_handle handle); | 64 | swayc_t *new_view(swayc_t *sibling, wlc_handle handle); |
70 | //Creates view as a new floating view which is in the active workspace | 65 | // Creates view as a new floating view which is in the active workspace |
71 | swayc_t *new_floating_view(wlc_handle handle); | 66 | swayc_t *new_floating_view(wlc_handle handle); |
72 | 67 | ||
73 | 68 | ||
74 | swayc_t *destroy_output(swayc_t *output); | 69 | swayc_t *destroy_output(swayc_t *output); |
75 | //destroys workspace if empty and returns parent pointer, else returns NULL | 70 | // Destroys workspace if empty and returns parent pointer, else returns NULL |
76 | swayc_t *destroy_workspace(swayc_t *workspace); | 71 | swayc_t *destroy_workspace(swayc_t *workspace); |
77 | swayc_t *destroy_container(swayc_t *container); | 72 | swayc_t *destroy_container(swayc_t *container); |
78 | swayc_t *destroy_view(swayc_t *view); | 73 | swayc_t *destroy_view(swayc_t *view); |
@@ -80,7 +75,7 @@ swayc_t *destroy_view(swayc_t *view); | |||
80 | swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data); | 75 | swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data); |
81 | void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); | 76 | void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); |
82 | 77 | ||
83 | //Mappings | 78 | // Mappings |
84 | void set_view_visibility(swayc_t *view, void *data); | 79 | void set_view_visibility(swayc_t *view, void *data); |
85 | 80 | ||
86 | #endif | 81 | #endif |
diff --git a/include/focus.h b/include/focus.h index 185910f3..410ed134 100644 --- a/include/focus.h +++ b/include/focus.h | |||
@@ -10,12 +10,12 @@ enum movement_direction { | |||
10 | MOVE_PARENT | 10 | MOVE_PARENT |
11 | }; | 11 | }; |
12 | 12 | ||
13 | //focused_container - the container found by following the `focused` pointer | 13 | // focused_container - the container found by following the `focused` pointer |
14 | //from a given container to a container with `is_focused` boolean set | 14 | // from a given container to a container with `is_focused` boolean set |
15 | //--- | 15 | // --- |
16 | //focused_view - the container found by following the `focused` pointer from a | 16 | // focused_view - the container found by following the `focused` pointer from a |
17 | //given container to a view. | 17 | // given container to a view. |
18 | //--- | 18 | // --- |
19 | 19 | ||
20 | swayc_t *get_focused_container(swayc_t *parent); | 20 | swayc_t *get_focused_container(swayc_t *parent); |
21 | swayc_t *get_focused_view(swayc_t *parent); | 21 | swayc_t *get_focused_view(swayc_t *parent); |
@@ -23,8 +23,8 @@ swayc_t *get_focused_view(swayc_t *parent); | |||
23 | void set_focused_container(swayc_t *container); | 23 | void set_focused_container(swayc_t *container); |
24 | void set_focused_container_for(swayc_t *ancestor, swayc_t *container); | 24 | void set_focused_container_for(swayc_t *ancestor, swayc_t *container); |
25 | 25 | ||
26 | //lock focused container/view. locked by windows with OVERRIDE attribute | 26 | // lock focused container/view. locked by windows with OVERRIDE attribute |
27 | //and unlocked when they are destroyed | 27 | // and unlocked when they are destroyed |
28 | 28 | ||
29 | extern bool locked_container_focus; | 29 | extern bool locked_container_focus; |
30 | extern bool locked_view_focus; | 30 | extern bool locked_view_focus; |
diff --git a/include/handlers.h b/include/handlers.h index 6b642419..c25c3309 100644 --- a/include/handlers.h +++ b/include/handlers.h | |||
@@ -7,7 +7,7 @@ | |||
7 | extern struct wlc_interface interface; | 7 | extern struct wlc_interface interface; |
8 | extern uint32_t keys_pressed[32]; | 8 | extern uint32_t keys_pressed[32]; |
9 | 9 | ||
10 | //set focus to current pointer location and return focused container | 10 | // set focus to current pointer location and return focused container |
11 | swayc_t *container_under_pointer(void); | 11 | swayc_t *container_under_pointer(void); |
12 | 12 | ||
13 | #endif | 13 | #endif |
diff --git a/include/layout.h b/include/layout.h index 26d00ce4..282f92ee 100644 --- a/include/layout.h +++ b/include/layout.h | |||
@@ -10,15 +10,15 @@ extern swayc_t root_container; | |||
10 | void init_layout(void); | 10 | void init_layout(void); |
11 | 11 | ||
12 | void add_child(swayc_t *parent, swayc_t *child); | 12 | void add_child(swayc_t *parent, swayc_t *child); |
13 | //Returns parent container which needs to be rearranged. | 13 | // Returns parent container which needs to be rearranged. |
14 | swayc_t *add_sibling(swayc_t *sibling, swayc_t *child); | 14 | swayc_t *add_sibling(swayc_t *sibling, swayc_t *child); |
15 | swayc_t *replace_child(swayc_t *child, swayc_t *new_child); | 15 | swayc_t *replace_child(swayc_t *child, swayc_t *new_child); |
16 | swayc_t *remove_child(swayc_t *child); | 16 | swayc_t *remove_child(swayc_t *child); |
17 | 17 | ||
18 | //Layout | 18 | // Layout |
19 | void arrange_windows(swayc_t *container, int width, int height); | 19 | void arrange_windows(swayc_t *container, int width, int height); |
20 | 20 | ||
21 | //Focus | 21 | // Focus |
22 | void unfocus_all(swayc_t *container); | 22 | void unfocus_all(swayc_t *container); |
23 | void focus_view(swayc_t *view); | 23 | void focus_view(swayc_t *view); |
24 | void focus_view_for(swayc_t *ancestor, swayc_t *container); | 24 | void focus_view_for(swayc_t *ancestor, swayc_t *container); |
diff --git a/sway/commands.c b/sway/commands.c index 7e9169e8..51de7a50 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -40,37 +40,37 @@ enum expected_args { | |||
40 | 40 | ||
41 | static bool checkarg(int argc, char *name, enum expected_args type, int val) { | 41 | static bool checkarg(int argc, char *name, enum expected_args type, int val) { |
42 | switch (type) { | 42 | switch (type) { |
43 | case EXPECTED_MORE_THAN: | 43 | case EXPECTED_MORE_THAN: |
44 | if (argc > val) { | 44 | if (argc > val) { |
45 | return true; | 45 | return true; |
46 | } | 46 | } |
47 | sway_log(L_ERROR, "Invalid %s command." | 47 | sway_log(L_ERROR, "Invalid %s command." |
48 | "(expected more than %d argument%s, got %d", | 48 | "(expected more than %d argument%s, got %d", |
49 | name, val, (char*[2]){"s", ""}[argc==1], argc); | 49 | name, val, (char*[2]){"s", ""}[argc==1], argc); |
50 | break; | 50 | break; |
51 | case EXPECTED_AT_LEAST: | 51 | case EXPECTED_AT_LEAST: |
52 | if (argc >= val) { | 52 | if (argc >= val) { |
53 | return true; | 53 | return true; |
54 | } | 54 | } |
55 | sway_log(L_ERROR, "Invalid %s command." | 55 | sway_log(L_ERROR, "Invalid %s command." |
56 | "(expected at least %d argument%s, got %d", | 56 | "(expected at least %d argument%s, got %d", |
57 | name, val, (char*[2]){"s", ""}[argc==1], argc); | 57 | name, val, (char*[2]){"s", ""}[argc==1], argc); |
58 | break; | 58 | break; |
59 | case EXPECTED_LESS_THAN: | 59 | case EXPECTED_LESS_THAN: |
60 | if (argc < val) { | 60 | if (argc < val) { |
61 | return true; | 61 | return true; |
62 | }; | 62 | }; |
63 | sway_log(L_ERROR, "Invalid %s command." | 63 | sway_log(L_ERROR, "Invalid %s command." |
64 | "(expected less than %d argument%s, got %d", | 64 | "(expected less than %d argument%s, got %d", |
65 | name, val, (char*[2]){"s", ""}[argc==1], argc); | 65 | name, val, (char*[2]){"s", ""}[argc==1], argc); |
66 | break; | 66 | break; |
67 | case EXPECTED_EQUAL_TO: | 67 | case EXPECTED_EQUAL_TO: |
68 | if (argc == val) { | 68 | if (argc == val) { |
69 | return true; | 69 | return true; |
70 | }; | 70 | }; |
71 | sway_log(L_ERROR, "Invalid %s command." | 71 | sway_log(L_ERROR, "Invalid %s command." |
72 | "(expected %d arguments, got %d", name, val, argc); | 72 | "(expected %d arguments, got %d", name, val, argc); |
73 | break; | 73 | break; |
74 | } | 74 | } |
75 | return false; | 75 | return false; |
76 | } | 76 | } |
@@ -292,9 +292,11 @@ static bool cmd_layout(struct sway_config *config, int argc, char **argv) { | |||
292 | return false; | 292 | return false; |
293 | } | 293 | } |
294 | swayc_t *parent = get_focused_container(&root_container); | 294 | swayc_t *parent = get_focused_container(&root_container); |
295 | |||
295 | while (parent->type == C_VIEW) { | 296 | while (parent->type == C_VIEW) { |
296 | parent = parent->parent; | 297 | parent = parent->parent; |
297 | } | 298 | } |
299 | |||
298 | if (strcasecmp(argv[0], "splith") == 0) { | 300 | if (strcasecmp(argv[0], "splith") == 0) { |
299 | parent->layout = L_HORIZ; | 301 | parent->layout = L_HORIZ; |
300 | } else if (strcasecmp(argv[0], "splitv") == 0) { | 302 | } 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 | |||
343 | } | 345 | } |
344 | swayc_t *focused = get_focused_container(&root_container); | 346 | swayc_t *focused = get_focused_container(&root_container); |
345 | 347 | ||
346 | /* Case that focus is on an workspace with 0/1 children.change its layout */ | ||
347 | if (focused->type == C_WORKSPACE && focused->children->length <= 1) { | 348 | if (focused->type == C_WORKSPACE && focused->children->length <= 1) { |
349 | /* Case that focus is on an workspace with 0/1 children.change its layout */ | ||
348 | sway_log(L_DEBUG, "changing workspace layout"); | 350 | sway_log(L_DEBUG, "changing workspace layout"); |
349 | focused->layout = layout; | 351 | focused->layout = layout; |
350 | } | 352 | } else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) { |
351 | /* Case of no siblings. change parent layout */ | 353 | /* Case of no siblings. change parent layout */ |
352 | else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) { | ||
353 | sway_log(L_DEBUG, "changing container layout"); | 354 | sway_log(L_DEBUG, "changing container layout"); |
354 | focused->parent->layout = layout; | 355 | focused->parent->layout = layout; |
355 | } | 356 | } else { |
356 | /* regular case where new split container is build around focused container | 357 | /* regular case where new split container is build around focused container |
357 | * or in case of workspace, container inherits its children */ | 358 | * or in case of workspace, container inherits its children */ |
358 | else { | ||
359 | sway_log(L_DEBUG, "Adding new container around current focused container"); | 359 | sway_log(L_DEBUG, "Adding new container around current focused container"); |
360 | swayc_t *parent = new_container(focused, layout); | 360 | swayc_t *parent = new_container(focused, layout); |
361 | set_focused_container(focused); | 361 | set_focused_container(focused); |
@@ -369,6 +369,7 @@ static bool cmd_split(struct sway_config *config, int argc, char **argv) { | |||
369 | if (!checkarg(argc, "split", EXPECTED_EQUAL_TO, 1)) { | 369 | if (!checkarg(argc, "split", EXPECTED_EQUAL_TO, 1)) { |
370 | return false; | 370 | return false; |
371 | } | 371 | } |
372 | |||
372 | if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) { | 373 | if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) { |
373 | _do_split(config, argc - 1, argv + 1, L_VERT); | 374 | _do_split(config, argc - 1, argv + 1, L_VERT); |
374 | } else if (strcasecmp(argv[0], "h") == 0 || strcasecmp(argv[0], "horizontal") == 0) { | 375 | } 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) { | |||
377 | sway_log(L_ERROR, "Invalid split command (expected either horiziontal or vertical)."); | 378 | sway_log(L_ERROR, "Invalid split command (expected either horiziontal or vertical)."); |
378 | return false; | 379 | return false; |
379 | } | 380 | } |
381 | |||
380 | return true; | 382 | return true; |
381 | } | 383 | } |
382 | 384 | ||
diff --git a/sway/config.c b/sway/config.c index 95d605a3..6d39839d 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -15,7 +15,7 @@ static bool exists(const char *path) { | |||
15 | return access(path, R_OK) != -1; | 15 | return access(path, R_OK) != -1; |
16 | } | 16 | } |
17 | 17 | ||
18 | static char* get_config_path() { | 18 | static char *get_config_path() { |
19 | char *name = "/.sway/config"; | 19 | char *name = "/.sway/config"; |
20 | const char *home = getenv("HOME"); | 20 | const char *home = getenv("HOME"); |
21 | 21 | ||
diff --git a/sway/container.c b/sway/container.c index 2b9f7554..e679e823 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -50,14 +50,7 @@ swayc_t *new_output(wlc_handle handle) { | |||
50 | 50 | ||
51 | add_child(&root_container, output); | 51 | add_child(&root_container, output); |
52 | 52 | ||
53 | //TODO still dont know why this is here? | 53 | // Create workspace |
54 | // int total_width = 0; | ||
55 | // int i; | ||
56 | // for (i = 0; i < root_container.children->length; ++i) { | ||
57 | // total_width += ((swayc_t*)root_container.children->items[i])->width; | ||
58 | // } | ||
59 | |||
60 | //Create workspace | ||
61 | char *ws_name = NULL; | 54 | char *ws_name = NULL; |
62 | if (name) { | 55 | if (name) { |
63 | int i; | 56 | int i; |
@@ -73,7 +66,8 @@ swayc_t *new_output(wlc_handle handle) { | |||
73 | if (!ws_name) { | 66 | if (!ws_name) { |
74 | ws_name = workspace_next_name(); | 67 | ws_name = workspace_next_name(); |
75 | } | 68 | } |
76 | //create and initilize default workspace | 69 | |
70 | // create and initilize default workspace | ||
77 | swayc_t *ws = new_workspace(output, ws_name); | 71 | swayc_t *ws = new_workspace(output, ws_name); |
78 | ws->is_focused = true; | 72 | ws->is_focused = true; |
79 | 73 | ||
@@ -86,7 +80,7 @@ swayc_t *new_workspace(swayc_t *output, const char *name) { | |||
86 | sway_log(L_DEBUG, "Added workspace %s for output %u", name, (unsigned int)output->handle); | 80 | sway_log(L_DEBUG, "Added workspace %s for output %u", name, (unsigned int)output->handle); |
87 | swayc_t *workspace = new_swayc(C_WORKSPACE); | 81 | swayc_t *workspace = new_swayc(C_WORKSPACE); |
88 | 82 | ||
89 | workspace->layout = L_HORIZ; // TODO:default layout | 83 | workspace->layout = L_HORIZ; // TODO: default layout |
90 | workspace->width = output->width; | 84 | workspace->width = output->width; |
91 | workspace->height = output->height; | 85 | workspace->height = output->height; |
92 | workspace->name = strdup(name); | 86 | workspace->name = strdup(name); |
@@ -112,26 +106,24 @@ swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) { | |||
112 | /* Container inherits all of workspaces children, layout and whatnot */ | 106 | /* Container inherits all of workspaces children, layout and whatnot */ |
113 | if (child->type == C_WORKSPACE) { | 107 | if (child->type == C_WORKSPACE) { |
114 | swayc_t *workspace = child; | 108 | swayc_t *workspace = child; |
115 | //reorder focus | 109 | // reorder focus |
116 | cont->focused = workspace->focused; | 110 | cont->focused = workspace->focused; |
117 | workspace->focused = cont; | 111 | workspace->focused = cont; |
118 | //set all children focu to container | 112 | // set all children focu to container |
119 | int i; | 113 | int i; |
120 | for (i = 0; i < workspace->children->length; ++i) { | 114 | for (i = 0; i < workspace->children->length; ++i) { |
121 | ((swayc_t *)workspace->children->items[i])->parent = cont; | 115 | ((swayc_t *)workspace->children->items[i])->parent = cont; |
122 | } | 116 | } |
123 | //Swap children | 117 | // Swap children |
124 | list_t *tmp_list = workspace->children; | 118 | list_t *tmp_list = workspace->children; |
125 | workspace->children = cont->children; | 119 | workspace->children = cont->children; |
126 | cont->children = tmp_list; | 120 | cont->children = tmp_list; |
127 | //add container to workspace chidren | 121 | // add container to workspace chidren |
128 | add_child(workspace, cont); | 122 | add_child(workspace, cont); |
129 | //give them proper layouts | 123 | // give them proper layouts |
130 | cont->layout = workspace->layout; | 124 | cont->layout = workspace->layout; |
131 | workspace->layout = layout; | 125 | workspace->layout = layout; |
132 | } | 126 | } else { // Or is built around container |
133 | //Or is built around container | ||
134 | else { | ||
135 | swayc_t *parent = replace_child(child, cont); | 127 | swayc_t *parent = replace_child(child, cont); |
136 | if (parent) { | 128 | if (parent) { |
137 | add_child(cont, child); | 129 | add_child(cont, child); |
@@ -145,7 +137,7 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { | |||
145 | swayc_t *view = new_swayc(C_VIEW); | 137 | swayc_t *view = new_swayc(C_VIEW); |
146 | sway_log(L_DEBUG, "Adding new view %lu:%s to container %p %d", | 138 | sway_log(L_DEBUG, "Adding new view %lu:%s to container %p %d", |
147 | handle, title, sibling, sibling ? sibling->type : 0); | 139 | handle, title, sibling, sibling ? sibling->type : 0); |
148 | //Setup values | 140 | // Setup values |
149 | view->handle = handle; | 141 | view->handle = handle; |
150 | view->name = title ? strdup(title) : NULL; | 142 | view->name = title ? strdup(title) : NULL; |
151 | view->visible = true; | 143 | view->visible = true; |
@@ -157,23 +149,22 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { | |||
157 | // TODO: properly set this | 149 | // TODO: properly set this |
158 | view->is_floating = false; | 150 | view->is_floating = false; |
159 | 151 | ||
160 | //Case of focused workspace, just create as child of it | ||
161 | if (sibling->type == C_WORKSPACE) { | 152 | if (sibling->type == C_WORKSPACE) { |
153 | // Case of focused workspace, just create as child of it | ||
162 | add_child(sibling, view); | 154 | add_child(sibling, view); |
163 | } | 155 | } else { |
164 | //Regular case, create as sibling of current container | 156 | // Regular case, create as sibling of current container |
165 | else { | ||
166 | add_sibling(sibling, view); | 157 | add_sibling(sibling, view); |
167 | } | 158 | } |
168 | return view; | 159 | return view; |
169 | } | 160 | } |
170 | 161 | ||
171 | swayc_t *new_floating_view(wlc_handle handle) { | 162 | swayc_t *new_floating_view(wlc_handle handle) { |
172 | const char *title = wlc_view_get_title(handle); | 163 | const char *title = wlc_view_get_title(handle); |
173 | swayc_t *view = new_swayc(C_VIEW); | 164 | swayc_t *view = new_swayc(C_VIEW); |
174 | sway_log(L_DEBUG, "Adding new view %lu:%x:%s as a floating view", | 165 | sway_log(L_DEBUG, "Adding new view %lu:%x:%s as a floating view", |
175 | handle, wlc_view_get_type(handle), title); | 166 | handle, wlc_view_get_type(handle), title); |
176 | //Setup values | 167 | // Setup values |
177 | view->handle = handle; | 168 | view->handle = handle; |
178 | view->name = title ? strdup(title) : NULL; | 169 | view->name = title ? strdup(title) : NULL; |
179 | view->visible = true; | 170 | view->visible = true; |
@@ -191,7 +182,7 @@ swayc_t *new_floating_view(wlc_handle handle) { | |||
191 | 182 | ||
192 | view->is_floating = true; | 183 | view->is_floating = true; |
193 | 184 | ||
194 | //Case of focused workspace, just create as child of it | 185 | // Case of focused workspace, just create as child of it |
195 | list_add(active_workspace->floating, view); | 186 | list_add(active_workspace->floating, view); |
196 | view->parent = active_workspace; | 187 | view->parent = active_workspace; |
197 | if (active_workspace->focused == NULL) { | 188 | if (active_workspace->focused == NULL) { |
@@ -204,7 +195,7 @@ swayc_t *new_floating_view(wlc_handle handle) { | |||
204 | 195 | ||
205 | swayc_t *destroy_output(swayc_t *output) { | 196 | swayc_t *destroy_output(swayc_t *output) { |
206 | if (output->children->length == 0) { | 197 | if (output->children->length == 0) { |
207 | //TODO move workspaces to other outputs | 198 | // TODO move workspaces to other outputs |
208 | } | 199 | } |
209 | sway_log(L_DEBUG, "OUTPUT: Destroying output '%lu'", output->handle); | 200 | sway_log(L_DEBUG, "OUTPUT: Destroying output '%lu'", output->handle); |
210 | free_swayc(output); | 201 | free_swayc(output); |
@@ -212,9 +203,9 @@ swayc_t *destroy_output(swayc_t *output) { | |||
212 | } | 203 | } |
213 | 204 | ||
214 | swayc_t *destroy_workspace(swayc_t *workspace) { | 205 | swayc_t *destroy_workspace(swayc_t *workspace) { |
215 | //NOTE: This is called from elsewhere without checking children length | 206 | // NOTE: This is called from elsewhere without checking children length |
216 | //TODO move containers to other workspaces? | 207 | // TODO move containers to other workspaces? |
217 | //for now just dont delete | 208 | // for now just dont delete |
218 | if (workspace->children->length == 0) { | 209 | if (workspace->children->length == 0) { |
219 | sway_log(L_DEBUG, "Workspace: Destroying workspace '%s'", workspace->name); | 210 | sway_log(L_DEBUG, "Workspace: Destroying workspace '%s'", workspace->name); |
220 | swayc_t *parent = workspace->parent; | 211 | swayc_t *parent = workspace->parent; |
@@ -244,7 +235,7 @@ swayc_t *destroy_view(swayc_t *view) { | |||
244 | swayc_t *parent = view->parent; | 235 | swayc_t *parent = view->parent; |
245 | free_swayc(view); | 236 | free_swayc(view); |
246 | 237 | ||
247 | //Destroy empty containers | 238 | // Destroy empty containers |
248 | if (parent->type == C_CONTAINER) { | 239 | if (parent->type == C_CONTAINER) { |
249 | return destroy_container(parent); | 240 | return destroy_container(parent); |
250 | } | 241 | } |
@@ -303,5 +294,3 @@ void set_view_visibility(swayc_t *view, void *data) { | |||
303 | } | 294 | } |
304 | view->visible = (*p == 2); | 295 | view->visible = (*p == 2); |
305 | } | 296 | } |
306 | |||
307 | |||
diff --git a/sway/focus.c b/sway/focus.c index 14d27184..99cb2570 100644 --- a/sway/focus.c +++ b/sway/focus.c | |||
@@ -7,10 +7,10 @@ | |||
7 | bool locked_container_focus = false; | 7 | bool locked_container_focus = false; |
8 | bool locked_view_focus = false; | 8 | bool locked_view_focus = false; |
9 | 9 | ||
10 | //switches parent focus to c. will switch it accordingly | 10 | // switches parent focus to c. will switch it accordingly |
11 | //TODO, everything needs a handle, so we can set front/back position properly | 11 | // TODO: Everything needs a handle, so we can set front/back position properly |
12 | static void update_focus(swayc_t *c) { | 12 | static void update_focus(swayc_t *c) { |
13 | //Handle if focus switches | 13 | // Handle if focus switches |
14 | swayc_t *parent = c->parent; | 14 | swayc_t *parent = c->parent; |
15 | if (parent->focused != c) { | 15 | if (parent->focused != c) { |
16 | switch (c->type) { | 16 | switch (c->type) { |
@@ -18,14 +18,14 @@ static void update_focus(swayc_t *c) { | |||
18 | case C_OUTPUT: | 18 | case C_OUTPUT: |
19 | wlc_output_focus(c->parent->handle); | 19 | wlc_output_focus(c->parent->handle); |
20 | break; | 20 | break; |
21 | //switching workspaces | 21 | // switching workspaces |
22 | case C_WORKSPACE: | 22 | case C_WORKSPACE: |
23 | if (parent->focused) { | 23 | if (parent->focused) { |
24 | swayc_t *ws = parent->focused; | 24 | swayc_t *ws = parent->focused; |
25 | //hide visibility of old workspace | 25 | // hide visibility of old workspace |
26 | uint32_t mask = 1; | 26 | uint32_t mask = 1; |
27 | container_map(ws, set_view_visibility, &mask); | 27 | container_map(ws, set_view_visibility, &mask); |
28 | //set visibility of new workspace | 28 | // set visibility of new workspace |
29 | mask = 2; | 29 | mask = 2; |
30 | container_map(c, set_view_visibility, &mask); | 30 | container_map(c, set_view_visibility, &mask); |
31 | wlc_output_set_mask(parent->handle, 2); | 31 | wlc_output_set_mask(parent->handle, 2); |
@@ -36,8 +36,8 @@ static void update_focus(swayc_t *c) { | |||
36 | default: | 36 | default: |
37 | case C_VIEW: | 37 | case C_VIEW: |
38 | case C_CONTAINER: | 38 | case C_CONTAINER: |
39 | //TODO whatever to do when container changes | 39 | // TODO whatever to do when container changes |
40 | //for example, stacked and tabbing change stuff. | 40 | // for example, stacked and tabbing change stuff. |
41 | break; | 41 | break; |
42 | } | 42 | } |
43 | } | 43 | } |
@@ -115,7 +115,7 @@ swayc_t *get_focused_container(swayc_t *parent) { | |||
115 | while (parent && !parent->is_focused) { | 115 | while (parent && !parent->is_focused) { |
116 | parent = parent->focused; | 116 | parent = parent->focused; |
117 | } | 117 | } |
118 | //just incase | 118 | // just incase |
119 | if (parent == NULL) { | 119 | if (parent == NULL) { |
120 | sway_log(L_DEBUG, "get_focused_container unable to find container"); | 120 | sway_log(L_DEBUG, "get_focused_container unable to find container"); |
121 | return active_workspace; | 121 | return active_workspace; |
@@ -140,7 +140,7 @@ void set_focused_container(swayc_t *c) { | |||
140 | } | 140 | } |
141 | if (!locked_view_focus) { | 141 | if (!locked_view_focus) { |
142 | p = get_focused_view(c); | 142 | p = get_focused_view(c); |
143 | //Set focus to p | 143 | // Set focus to p |
144 | if (p && !(wlc_view_get_type(p->handle) & WLC_BIT_POPUP)) { | 144 | if (p && !(wlc_view_get_type(p->handle) & WLC_BIT_POPUP)) { |
145 | if (prev_view) { | 145 | if (prev_view) { |
146 | wlc_view_set_state(prev_view->handle, WLC_BIT_ACTIVATED, false); | 146 | 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) { | |||
175 | } | 175 | } |
176 | if (!locked_view_focus) { | 176 | if (!locked_view_focus) { |
177 | p = get_focused_view(c); | 177 | p = get_focused_view(c); |
178 | //Set focus to p | 178 | // Set focus to p |
179 | if (p) { | 179 | if (p) { |
180 | wlc_view_focus(p->handle); | 180 | wlc_view_focus(p->handle); |
181 | wlc_view_set_state(p->handle, WLC_BIT_ACTIVATED, true); | 181 | wlc_view_set_state(p->handle, WLC_BIT_ACTIVATED, true); |
@@ -189,4 +189,3 @@ swayc_t *get_focused_view(swayc_t *parent) { | |||
189 | } | 189 | } |
190 | return parent; | 190 | return parent; |
191 | } | 191 | } |
192 | |||
diff --git a/sway/handlers.c b/sway/handlers.c index ebfd22ad..cd97ab43 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -23,7 +23,7 @@ static bool m2_held = false; | |||
23 | 23 | ||
24 | static bool pointer_test(swayc_t *view, void *_origin) { | 24 | static bool pointer_test(swayc_t *view, void *_origin) { |
25 | const struct wlc_origin *origin = _origin; | 25 | const struct wlc_origin *origin = _origin; |
26 | //Determine the output that the view is under | 26 | // Determine the output that the view is under |
27 | swayc_t *parent = view; | 27 | swayc_t *parent = view; |
28 | while (parent->type != C_OUTPUT) { | 28 | while (parent->type != C_OUTPUT) { |
29 | parent = parent->parent; | 29 | parent = parent->parent; |
@@ -37,25 +37,25 @@ static bool pointer_test(swayc_t *view, void *_origin) { | |||
37 | } | 37 | } |
38 | 38 | ||
39 | swayc_t *container_under_pointer(void) { | 39 | swayc_t *container_under_pointer(void) { |
40 | //root.output->workspace | 40 | // root.output->workspace |
41 | if (!root_container.focused || !root_container.focused->focused) { | 41 | if (!root_container.focused || !root_container.focused->focused) { |
42 | return NULL; | 42 | return NULL; |
43 | } | 43 | } |
44 | swayc_t *lookup = root_container.focused->focused; | 44 | swayc_t *lookup = root_container.focused->focused; |
45 | //Case of empty workspace | 45 | // Case of empty workspace |
46 | if (lookup->children == 0) { | 46 | if (lookup->children == 0) { |
47 | return NULL; | 47 | return NULL; |
48 | } | 48 | } |
49 | while (lookup->type != C_VIEW) { | 49 | while (lookup->type != C_VIEW) { |
50 | int i; | 50 | int i; |
51 | int len; | 51 | int len; |
52 | //if tabbed/stacked go directly to focused container, otherwise search | 52 | // if tabbed/stacked go directly to focused container, otherwise search |
53 | //children | 53 | // children |
54 | if (lookup->layout == L_TABBED || lookup->layout == L_STACKED) { | 54 | if (lookup->layout == L_TABBED || lookup->layout == L_STACKED) { |
55 | lookup = lookup->focused; | 55 | lookup = lookup->focused; |
56 | continue; | 56 | continue; |
57 | } | 57 | } |
58 | //if workspace, search floating | 58 | // if workspace, search floating |
59 | if (lookup->type == C_WORKSPACE) { | 59 | if (lookup->type == C_WORKSPACE) { |
60 | len = lookup->floating->length; | 60 | len = lookup->floating->length; |
61 | for (i = 0; i < len; ++i) { | 61 | for (i = 0; i < len; ++i) { |
@@ -68,7 +68,7 @@ swayc_t *container_under_pointer(void) { | |||
68 | continue; | 68 | continue; |
69 | } | 69 | } |
70 | } | 70 | } |
71 | //search children | 71 | // search children |
72 | len = lookup->children->length; | 72 | len = lookup->children->length; |
73 | for (i = 0; i < len; ++i) { | 73 | for (i = 0; i < len; ++i) { |
74 | if (pointer_test(lookup->children->items[i], &mouse_origin)) { | 74 | if (pointer_test(lookup->children->items[i], &mouse_origin)) { |
@@ -76,7 +76,7 @@ swayc_t *container_under_pointer(void) { | |||
76 | break; | 76 | break; |
77 | } | 77 | } |
78 | } | 78 | } |
79 | //when border and titles are done, this could happen | 79 | // when border and titles are done, this could happen |
80 | if (i == len) { | 80 | if (i == len) { |
81 | break; | 81 | break; |
82 | } | 82 | } |
@@ -119,7 +119,7 @@ static void handle_output_resolution_change(wlc_handle output, const struct wlc_ | |||
119 | 119 | ||
120 | static void handle_output_focused(wlc_handle output, bool focus) { | 120 | static void handle_output_focused(wlc_handle output, bool focus) { |
121 | swayc_t *c = get_swayc_for_handle(output, &root_container); | 121 | swayc_t *c = get_swayc_for_handle(output, &root_container); |
122 | //if for some reason this output doesnt exist, create it. | 122 | // if for some reason this output doesnt exist, create it. |
123 | if (!c) { | 123 | if (!c) { |
124 | handle_output_created(output); | 124 | handle_output_created(output); |
125 | } | 125 | } |
@@ -132,12 +132,12 @@ static bool handle_view_created(wlc_handle handle) { | |||
132 | swayc_t *focused = get_focused_container(&root_container); | 132 | swayc_t *focused = get_focused_container(&root_container); |
133 | swayc_t *newview = NULL; | 133 | swayc_t *newview = NULL; |
134 | switch (wlc_view_get_type(handle)) { | 134 | switch (wlc_view_get_type(handle)) { |
135 | //regular view created regularly | 135 | // regular view created regularly |
136 | case 0: | 136 | case 0: |
137 | newview = new_view(focused, handle); | 137 | newview = new_view(focused, handle); |
138 | wlc_view_set_state(handle, WLC_BIT_MAXIMIZED, true); | 138 | wlc_view_set_state(handle, WLC_BIT_MAXIMIZED, true); |
139 | break; | 139 | break; |
140 | //takes keyboard focus | 140 | // takes keyboard focus |
141 | case WLC_BIT_OVERRIDE_REDIRECT: | 141 | case WLC_BIT_OVERRIDE_REDIRECT: |
142 | sway_log(L_DEBUG, "view %ld with OVERRIDE_REDIRECT", handle); | 142 | sway_log(L_DEBUG, "view %ld with OVERRIDE_REDIRECT", handle); |
143 | locked_view_focus = true; | 143 | locked_view_focus = true; |
@@ -145,13 +145,13 @@ static bool handle_view_created(wlc_handle handle) { | |||
145 | wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); | 145 | wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); |
146 | wlc_view_bring_to_front(handle); | 146 | wlc_view_bring_to_front(handle); |
147 | break; | 147 | break; |
148 | //Takes container focus | 148 | // Takes container focus |
149 | case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED: | 149 | case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED: |
150 | sway_log(L_DEBUG, "view %ld with OVERRIDE_REDIRECT|WLC_BIT_MANAGED", handle); | 150 | sway_log(L_DEBUG, "view %ld with OVERRIDE_REDIRECT|WLC_BIT_MANAGED", handle); |
151 | wlc_view_bring_to_front(handle); | 151 | wlc_view_bring_to_front(handle); |
152 | locked_container_focus = true; | 152 | locked_container_focus = true; |
153 | break; | 153 | break; |
154 | //set modals as floating containers | 154 | // set modals as floating containers |
155 | case WLC_BIT_MODAL: | 155 | case WLC_BIT_MODAL: |
156 | wlc_view_bring_to_front(handle); | 156 | wlc_view_bring_to_front(handle); |
157 | newview = new_floating_view(handle); | 157 | newview = new_floating_view(handle); |
@@ -170,7 +170,7 @@ static void handle_view_destroyed(wlc_handle handle) { | |||
170 | swayc_t *view = get_swayc_for_handle(handle, &root_container); | 170 | swayc_t *view = get_swayc_for_handle(handle, &root_container); |
171 | 171 | ||
172 | switch (wlc_view_get_type(handle)) { | 172 | switch (wlc_view_get_type(handle)) { |
173 | //regular view created regularly | 173 | // regular view created regularly |
174 | case 0: | 174 | case 0: |
175 | case WLC_BIT_MODAL: | 175 | case WLC_BIT_MODAL: |
176 | if (view) { | 176 | if (view) { |
@@ -178,11 +178,11 @@ static void handle_view_destroyed(wlc_handle handle) { | |||
178 | arrange_windows(parent, -1, -1); | 178 | arrange_windows(parent, -1, -1); |
179 | } | 179 | } |
180 | break; | 180 | break; |
181 | //takes keyboard focus | 181 | // takes keyboard focus |
182 | case WLC_BIT_OVERRIDE_REDIRECT: | 182 | case WLC_BIT_OVERRIDE_REDIRECT: |
183 | locked_view_focus = false; | 183 | locked_view_focus = false; |
184 | break; | 184 | break; |
185 | //Takes container focus | 185 | // Takes container focus |
186 | case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED: | 186 | case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED: |
187 | locked_container_focus = false; | 187 | locked_container_focus = false; |
188 | case WLC_BIT_POPUP: | 188 | case WLC_BIT_POPUP: |
@@ -195,7 +195,7 @@ static void handle_view_focus(wlc_handle view, bool focus) { | |||
195 | return; | 195 | return; |
196 | } | 196 | } |
197 | 197 | ||
198 | static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geometry* geometry) { | 198 | static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geometry *geometry) { |
199 | sway_log(L_DEBUG, "geometry request %d x %d : %d x %d", | 199 | sway_log(L_DEBUG, "geometry request %d x %d : %d x %d", |
200 | geometry->origin.x, geometry->origin.y, geometry->size.w,geometry->size.h); | 200 | geometry->origin.x, geometry->origin.y, geometry->size.w,geometry->size.h); |
201 | // If the view is floating, then apply the geometry. | 201 | // 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 | |||
220 | swayc_t *c = NULL; | 220 | swayc_t *c = NULL; |
221 | switch(state) { | 221 | switch(state) { |
222 | case WLC_BIT_FULLSCREEN: | 222 | case WLC_BIT_FULLSCREEN: |
223 | //I3 just lets it become fullscreen | 223 | // i3 just lets it become fullscreen |
224 | wlc_view_set_state(view, state, toggle); | 224 | wlc_view_set_state(view, state, toggle); |
225 | c = get_swayc_for_handle(view, &root_container); | 225 | c = get_swayc_for_handle(view, &root_container); |
226 | sway_log(L_DEBUG, "setting view %ld %s, fullscreen %d",view,c->name,toggle); | 226 | sway_log(L_DEBUG, "setting view %ld %s, fullscreen %d",view,c->name,toggle); |
227 | if (c) { | 227 | if (c) { |
228 | arrange_windows(c->parent, -1, -1); | 228 | arrange_windows(c->parent, -1, -1); |
229 | //Set it as focused window for that workspace if its going | 229 | // Set it as focused window for that workspace if its going fullscreen |
230 | //fullscreen | ||
231 | if (toggle) { | 230 | if (toggle) { |
232 | swayc_t *ws = c; | 231 | swayc_t *ws = c; |
233 | while (ws->type != C_WORKSPACE) { | 232 | while (ws->type != C_WORKSPACE) { |
234 | ws = ws->parent; | 233 | ws = ws->parent; |
235 | } | 234 | } |
236 | //Set ws focus to c | 235 | // Set ws focus to c |
237 | set_focused_container_for(ws, c); | 236 | set_focused_container_for(ws, c); |
238 | } | 237 | } |
239 | } | 238 | } |
@@ -248,8 +247,8 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s | |||
248 | } | 247 | } |
249 | 248 | ||
250 | 249 | ||
251 | static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers | 250 | static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, |
252 | *modifiers, uint32_t key, uint32_t sym, enum wlc_key_state state) { | 251 | uint32_t key, uint32_t sym, enum wlc_key_state state) { |
253 | enum { QSIZE = 32 }; | 252 | enum { QSIZE = 32 }; |
254 | if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) { | 253 | if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) { |
255 | return false; | 254 | return false; |
@@ -261,7 +260,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier | |||
261 | // Lowercase if necessary | 260 | // Lowercase if necessary |
262 | sym = tolower(sym); | 261 | sym = tolower(sym); |
263 | 262 | ||
264 | //Find key, if it has been pressed | 263 | // Find key, if it has been pressed |
265 | int mid = 0; | 264 | int mid = 0; |
266 | while (mid < head && keys_pressed[mid] != sym) { | 265 | while (mid < head && keys_pressed[mid] != sym) { |
267 | ++mid; | 266 | ++mid; |
@@ -295,7 +294,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier | |||
295 | } | 294 | } |
296 | 295 | ||
297 | if (match) { | 296 | if (match) { |
298 | //Remove matched keys from keys_pressed | 297 | // Remove matched keys from keys_pressed |
299 | int j; | 298 | int j; |
300 | for (j = 0; j < binding->keys->length; ++j) { | 299 | for (j = 0; j < binding->keys->length; ++j) { |
301 | uint8_t k; | 300 | uint8_t k; |
diff --git a/sway/layout.c b/sway/layout.c index d072c410..e2ea46a7 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -63,8 +63,8 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child) { | |||
63 | swayc_t *remove_child(swayc_t *child) { | 63 | swayc_t *remove_child(swayc_t *child) { |
64 | int i; | 64 | int i; |
65 | swayc_t *parent = child->parent; | 65 | swayc_t *parent = child->parent; |
66 | // Special case for floating views | ||
67 | if (child->is_floating) { | 66 | if (child->is_floating) { |
67 | // Special case for floating views | ||
68 | for (i = 0; i < parent->floating->length; ++i) { | 68 | for (i = 0; i < parent->floating->length; ++i) { |
69 | if (parent->floating->items[i] == child) { | 69 | if (parent->floating->items[i] == child) { |
70 | list_del(parent->floating, i); | 70 | list_del(parent->floating, i); |
@@ -17,8 +17,7 @@ static const char *verbosity_colors[] = { | |||
17 | 17 | ||
18 | void init_log(int verbosity) { | 18 | void init_log(int verbosity) { |
19 | v = verbosity; | 19 | v = verbosity; |
20 | /* set FD_CLOEXEC flag to prevent programs called with exec to write into | 20 | /* set FD_CLOEXEC flag to prevent programs called with exec to write into logs */ |
21 | * logs */ | ||
22 | int i, flag; | 21 | int i, flag; |
23 | int fd[] = { STDOUT_FILENO, STDIN_FILENO, STDERR_FILENO }; | 22 | int fd[] = { STDOUT_FILENO, STDIN_FILENO, STDERR_FILENO }; |
24 | for (i = 0; i < 3; ++i) { | 23 | for (i = 0; i < 3; ++i) { |