diff options
Diffstat (limited to 'sway/container.c')
-rw-r--r-- | sway/container.c | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/sway/container.c b/sway/container.c index 3534721d..2b9f7554 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -27,10 +27,7 @@ static void free_swayc(swayc_t *c) { | |||
27 | list_free(c->children); | 27 | list_free(c->children); |
28 | } | 28 | } |
29 | if (c->parent) { | 29 | if (c->parent) { |
30 | if (c->parent->focused == c) { | 30 | remove_child(c); |
31 | c->parent->focused = NULL; | ||
32 | } | ||
33 | remove_child(c->parent, c); | ||
34 | } | 31 | } |
35 | if (c->name) { | 32 | if (c->name) { |
36 | free(c->name); | 33 | free(c->name); |
@@ -39,17 +36,11 @@ static void free_swayc(swayc_t *c) { | |||
39 | } | 36 | } |
40 | 37 | ||
41 | /* New containers */ | 38 | /* New containers */ |
42 | static void add_output_widths(swayc_t *container, void *_width) { | ||
43 | int *width = _width; | ||
44 | if (container->type == C_OUTPUT) { | ||
45 | *width += container->width; | ||
46 | } | ||
47 | } | ||
48 | 39 | ||
49 | swayc_t *new_output(wlc_handle handle) { | 40 | swayc_t *new_output(wlc_handle handle) { |
50 | const struct wlc_size* size = wlc_output_get_resolution(handle); | 41 | const struct wlc_size* size = wlc_output_get_resolution(handle); |
51 | const char *name = wlc_output_get_name(handle); | 42 | const char *name = wlc_output_get_name(handle); |
52 | sway_log(L_DEBUG, "Added output %u %s", (unsigned int)handle, name); | 43 | sway_log(L_DEBUG, "Added output %lu:%s", handle, name); |
53 | 44 | ||
54 | swayc_t *output = new_swayc(C_OUTPUT); | 45 | swayc_t *output = new_swayc(C_OUTPUT); |
55 | output->width = size->w; | 46 | output->width = size->w; |
@@ -59,9 +50,12 @@ swayc_t *new_output(wlc_handle handle) { | |||
59 | 50 | ||
60 | add_child(&root_container, output); | 51 | add_child(&root_container, output); |
61 | 52 | ||
62 | //TODO something with this | 53 | //TODO still dont know why this is here? |
63 | int total_width = 0; | 54 | // int total_width = 0; |
64 | container_map(&root_container, add_output_widths, &total_width); | 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 | // } | ||
65 | 59 | ||
66 | //Create workspace | 60 | //Create workspace |
67 | char *ws_name = NULL; | 61 | char *ws_name = NULL; |
@@ -79,7 +73,10 @@ swayc_t *new_output(wlc_handle handle) { | |||
79 | if (!ws_name) { | 73 | if (!ws_name) { |
80 | ws_name = workspace_next_name(); | 74 | ws_name = workspace_next_name(); |
81 | } | 75 | } |
82 | new_workspace(output, ws_name); | 76 | //create and initilize default workspace |
77 | swayc_t *ws = new_workspace(output, ws_name); | ||
78 | ws->is_focused = true; | ||
79 | |||
83 | free(ws_name); | 80 | free(ws_name); |
84 | 81 | ||
85 | return output; | 82 | return output; |
@@ -118,6 +115,11 @@ swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) { | |||
118 | //reorder focus | 115 | //reorder focus |
119 | cont->focused = workspace->focused; | 116 | cont->focused = workspace->focused; |
120 | workspace->focused = cont; | 117 | workspace->focused = cont; |
118 | //set all children focu to container | ||
119 | int i; | ||
120 | for (i = 0; i < workspace->children->length; ++i) { | ||
121 | ((swayc_t *)workspace->children->items[i])->parent = cont; | ||
122 | } | ||
121 | //Swap children | 123 | //Swap children |
122 | list_t *tmp_list = workspace->children; | 124 | list_t *tmp_list = workspace->children; |
123 | workspace->children = cont->children; | 125 | workspace->children = cont->children; |
@@ -139,14 +141,15 @@ swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) { | |||
139 | } | 141 | } |
140 | 142 | ||
141 | swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { | 143 | swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { |
142 | const char *title = wlc_view_get_title(handle); | 144 | const char *title = wlc_view_get_title(handle); |
143 | swayc_t *view = new_swayc(C_VIEW); | 145 | swayc_t *view = new_swayc(C_VIEW); |
144 | sway_log(L_DEBUG, "Adding new view %u:%s to container %p %d", | 146 | sway_log(L_DEBUG, "Adding new view %lu:%s to container %p %d", |
145 | (unsigned int)handle, title, sibling, sibling?sibling->type:0); | 147 | handle, title, sibling, sibling ? sibling->type : 0); |
146 | //Setup values | 148 | //Setup values |
147 | view->handle = handle; | 149 | view->handle = handle; |
148 | view->name = title ? strdup(title) : NULL; | 150 | view->name = title ? strdup(title) : NULL; |
149 | view->visible = true; | 151 | view->visible = true; |
152 | view->is_focused = true; | ||
150 | 153 | ||
151 | view->desired_width = -1; | 154 | view->desired_width = -1; |
152 | view->desired_height = -1; | 155 | view->desired_height = -1; |
@@ -168,8 +171,8 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { | |||
168 | swayc_t *new_floating_view(wlc_handle handle) { | 171 | swayc_t *new_floating_view(wlc_handle handle) { |
169 | const char *title = wlc_view_get_title(handle); | 172 | const char *title = wlc_view_get_title(handle); |
170 | swayc_t *view = new_swayc(C_VIEW); | 173 | swayc_t *view = new_swayc(C_VIEW); |
171 | sway_log(L_DEBUG, "Adding new view %u:%s as a floating view", | 174 | sway_log(L_DEBUG, "Adding new view %lu:%x:%s as a floating view", |
172 | (unsigned int)handle, title); | 175 | handle, wlc_view_get_type(handle), title); |
173 | //Setup values | 176 | //Setup values |
174 | view->handle = handle; | 177 | view->handle = handle; |
175 | view->name = title ? strdup(title) : NULL; | 178 | view->name = title ? strdup(title) : NULL; |
@@ -197,12 +200,13 @@ swayc_t *new_floating_view(wlc_handle handle) { | |||
197 | return view; | 200 | return view; |
198 | } | 201 | } |
199 | 202 | ||
203 | /* Destroy container */ | ||
200 | 204 | ||
201 | swayc_t *destroy_output(swayc_t *output) { | 205 | swayc_t *destroy_output(swayc_t *output) { |
202 | if (output->children->length == 0) { | 206 | if (output->children->length == 0) { |
203 | //TODO move workspaces to other outputs | 207 | //TODO move workspaces to other outputs |
204 | } | 208 | } |
205 | sway_log(L_DEBUG, "OUTPUT: Destroying output '%u'", (unsigned int)output->handle); | 209 | sway_log(L_DEBUG, "OUTPUT: Destroying output '%lu'", output->handle); |
206 | free_swayc(output); | 210 | free_swayc(output); |
207 | return &root_container; | 211 | return &root_container; |
208 | } | 212 | } |
@@ -244,7 +248,6 @@ swayc_t *destroy_view(swayc_t *view) { | |||
244 | if (parent->type == C_CONTAINER) { | 248 | if (parent->type == C_CONTAINER) { |
245 | return destroy_container(parent); | 249 | return destroy_container(parent); |
246 | } | 250 | } |
247 | |||
248 | return parent; | 251 | return parent; |
249 | } | 252 | } |
250 | 253 | ||
@@ -300,3 +303,5 @@ void set_view_visibility(swayc_t *view, void *data) { | |||
300 | } | 303 | } |
301 | view->visible = (*p == 2); | 304 | view->visible = (*p == 2); |
302 | } | 305 | } |
306 | |||
307 | |||