summaryrefslogtreecommitdiffstats
path: root/sway/container.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/container.c')
-rw-r--r--sway/container.c55
1 files changed, 22 insertions, 33 deletions
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
171swayc_t *new_floating_view(wlc_handle handle) { 162swayc_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
205swayc_t *destroy_output(swayc_t *output) { 196swayc_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
214swayc_t *destroy_workspace(swayc_t *workspace) { 205swayc_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