@@ -72,6 +72,7 @@ void arrange_windows(swayc_t *container, int width, int height) {
72
72
switch (container -> layout ) {
73
73
case L_HORIZ :
74
74
default :
75
+ sway_log (L_DEBUG , "Arranging %p horizontally" , container );
75
76
for (i = 0 ; i < container -> children -> length ; ++ i ) {
76
77
swayc_t * child = container -> children -> items [i ];
77
78
double percent = child -> weight / total_weight ;
@@ -85,6 +86,7 @@ void arrange_windows(swayc_t *container, int width, int height) {
85
86
}
86
87
break ;
87
88
case L_VERT :
89
+ sway_log (L_DEBUG , "Arranging %p vertically" , container );
88
90
for (i = 0 ; i < container -> children -> length ; ++ i ) {
89
91
swayc_t * child = container -> children -> items [i ];
90
92
double percent = child -> weight / total_weight ;
@@ -166,6 +168,22 @@ void add_view(wlc_handle view_handle) {
166
168
arrange_windows (parent , -1 , -1 );
167
169
}
168
170
171
+ int remove_container_from_parent (swayc_t * parent , swayc_t * container ) {
172
+ int i ;
173
+ for (i = 0 ; i < parent -> children -> length ; ++ i ) {
174
+ if (parent -> children -> items [i ] == container ) {
175
+ list_del (parent -> children , i );
176
+ break ;
177
+ }
178
+ }
179
+
180
+ if (parent -> focused == container ) {
181
+ parent -> focused = NULL ;
182
+ }
183
+
184
+ return i ;
185
+ }
186
+
169
187
void destroy_view (swayc_t * view ) {
170
188
if (view == NULL ) {
171
189
sway_log (L_DEBUG , "Warning: NULL passed into destroy_view" );
@@ -234,30 +252,32 @@ void add_child(swayc_t *parent, swayc_t *child) {
234
252
list_add (parent -> children , child );
235
253
}
236
254
255
+ swayc_t * create_container (swayc_t * parent , wlc_handle handle ) {
256
+ swayc_t * c = calloc (1 , sizeof (swayc_t ));
257
+ c -> weight = 1 ;
258
+ c -> handle = handle ;
259
+ c -> parent = parent ;
260
+ c -> layout = L_NONE ;
261
+ c -> type = C_CONTAINER ;
262
+ c -> children = create_list ();
263
+ return c ;
264
+ }
265
+
237
266
void add_output (wlc_handle output ) {
238
267
sway_log (L_DEBUG , "Adding output %d" , output );
239
268
const struct wlc_size * size = wlc_output_get_resolution (output );
240
269
241
- swayc_t * container = calloc (1 , sizeof (swayc_t ));
242
- container -> weight = 1 ;
243
- container -> handle = output ;
270
+ swayc_t * container = create_container (& root_container , output );
244
271
container -> type = C_OUTPUT ;
245
- container -> children = create_list ();
246
- container -> parent = & root_container ;
247
- container -> layout = L_NONE ;
248
272
container -> width = size -> w ;
249
273
container -> height = size -> h ;
250
274
add_child (& root_container , container );
251
275
252
- swayc_t * workspace = calloc (1 , sizeof (swayc_t ));
253
- workspace -> weight = 1 ;
254
- workspace -> handle = -1 ;
276
+ swayc_t * workspace = create_container (container , -1 );
255
277
workspace -> type = C_WORKSPACE ;
256
- workspace -> parent = container ;
257
278
workspace -> width = size -> w ; // TODO: gaps
258
279
workspace -> height = size -> h ;
259
280
workspace -> layout = L_HORIZ ; // TODO: Get default layout from config
260
- workspace -> children = create_list ();
261
281
add_child (container , workspace );
262
282
263
283
if (root_container .focused == NULL ) {
0 commit comments