summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/layout.h1
-rw-r--r--include/log.h2
-rw-r--r--include/workspace.h1
-rw-r--r--sway/commands.c45
-rw-r--r--sway/container.c6
-rw-r--r--sway/focus.c8
-rw-r--r--sway/handlers.c202
-rw-r--r--sway/layout.c12
-rw-r--r--sway/log.c59
-rw-r--r--sway/workspace.c57
10 files changed, 209 insertions, 184 deletions
diff --git a/include/layout.h b/include/layout.h
index 282f92ee..98fdb531 100644
--- a/include/layout.h
+++ b/include/layout.h
@@ -10,6 +10,7 @@ extern swayc_t root_container;
10void init_layout(void); 10void init_layout(void);
11 11
12void add_child(swayc_t *parent, swayc_t *child); 12void add_child(swayc_t *parent, swayc_t *child);
13void add_floating(swayc_t *ws, swayc_t *child);
13// Returns parent container which needs to be rearranged. 14// Returns parent container which needs to be rearranged.
14swayc_t *add_sibling(swayc_t *sibling, swayc_t *child); 15swayc_t *add_sibling(swayc_t *sibling, swayc_t *child);
15swayc_t *replace_child(swayc_t *child, swayc_t *new_child); 16swayc_t *replace_child(swayc_t *child, swayc_t *new_child);
diff --git a/include/log.h b/include/log.h
index 44f84940..7aea2ded 100644
--- a/include/log.h
+++ b/include/log.h
@@ -1,6 +1,7 @@
1#ifndef _SWAY_LOG_H 1#ifndef _SWAY_LOG_H
2#define _SWAY_LOG_H 2#define _SWAY_LOG_H
3#include <stdbool.h> 3#include <stdbool.h>
4#include "container.h"
4 5
5typedef enum { 6typedef enum {
6 L_SILENT = 0, 7 L_SILENT = 0,
@@ -15,4 +16,5 @@ void sway_log(int verbosity, const char* format, ...) __attribute__((format(prin
15void sway_abort(const char* format, ...) __attribute__((format(printf,1,2))); 16void sway_abort(const char* format, ...) __attribute__((format(printf,1,2)));
16bool sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3))); 17bool sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3)));
17 18
19void layout_log(const swayc_t *c, int depth);
18#endif 20#endif
diff --git a/include/workspace.h b/include/workspace.h
index 8ce39bbd..042a15d9 100644
--- a/include/workspace.h
+++ b/include/workspace.h
@@ -15,6 +15,5 @@ void workspace_output_next();
15void workspace_next(); 15void workspace_next();
16void workspace_output_prev(); 16void workspace_output_prev();
17void workspace_prev(); 17void workspace_prev();
18void layout_log(const swayc_t *c, int depth);
19 18
20#endif 19#endif
diff --git a/sway/commands.c b/sway/commands.c
index ab24f6ae..cc51717b 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -186,43 +186,28 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) {
186 if (view->type != C_VIEW) { 186 if (view->type != C_VIEW) {
187 return true; 187 return true;
188 } 188 }
189 int i;
190 // Change from nonfloating to floating 189 // Change from nonfloating to floating
191 if (!view->is_floating) { 190 if (!view->is_floating) {
192 view->is_floating = true; 191 //Remove view from its current location
193 for (i = 0; i < view->parent->children->length; i++) { 192 destroy_container(remove_child(view));
194 if (view->parent->children->items[i] == view) { 193
195 // Try to use desired geometry to set w/h 194 //and move it into workspace floating
196 if (view->desired_width != -1) { 195 add_floating(active_workspace,view);
197 view->width = view->desired_width; 196 view->x = (active_workspace->width - view->width)/2;
198 } 197 view->y = (active_workspace->height - view->height)/2;
199 if (view->desired_height != -1) { 198 if (view->desired_width != -1) {
200 view->height = view->desired_height; 199 view->width = view->desired_width;
201 } 200 }
202 201 if (view->desired_height != -1) {
203 // Swap from the list of whatever container the view was in 202 view->height = view->desired_height;
204 // to the workspace->floating list
205 list_del(view->parent->children, i);
206 list_add(active_workspace->floating, view);
207 destroy_container(view->parent);
208
209 // Set the new position of the container and arrange windows
210 view->x = (active_workspace->width - view->width)/2;
211 view->y = (active_workspace->height - view->height)/2;
212 sway_log(L_INFO, "Setting container %p to floating at coordinates X:%d Y:%d, W:%d, H:%d", view, view->x, view->y, view->width, view->height);
213 // Change parent to active_workspace
214 view->parent = active_workspace;
215 arrange_windows(active_workspace, -1, -1);
216 return true;
217 }
218 } 203 }
204 arrange_windows(active_workspace, -1, -1);
219 } else { 205 } else {
220 // Delete the view from the floating list and unset its is_floating flag 206 // Delete the view from the floating list and unset its is_floating flag
221 // Using length-1 as the index is safe because the view must be the currently 207 // Using length-1 as the index is safe because the view must be the currently
222 // focused floating output 208 // focused floating output
223 list_del(active_workspace->floating, active_workspace->floating->length - 1); 209 remove_child(view);
224 view->is_floating = false; 210 view->is_floating = false;
225 active_workspace->focused = NULL;
226 // Get the properly focused container, and add in the view there 211 // Get the properly focused container, and add in the view there
227 swayc_t *focused = container_under_pointer(); 212 swayc_t *focused = container_under_pointer();
228 // If focused is null, it's because the currently focused container is a workspace 213 // If focused is null, it's because the currently focused container is a workspace
@@ -242,10 +227,10 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) {
242 add_sibling(focused, view); 227 add_sibling(focused, view);
243 } 228 }
244 // Refocus on the view once its been put back into the layout 229 // Refocus on the view once its been put back into the layout
245 set_focused_container(view);
246 arrange_windows(active_workspace, -1, -1); 230 arrange_windows(active_workspace, -1, -1);
247 return true; 231 return true;
248 } 232 }
233 set_focused_container(view);
249 } 234 }
250 235
251 return true; 236 return true;
diff --git a/sway/container.c b/sway/container.c
index ec4d48b8..0a89f634 100644
--- a/sway/container.c
+++ b/sway/container.c
@@ -200,8 +200,9 @@ swayc_t *new_floating_view(wlc_handle handle) {
200 // Set the geometry of the floating view 200 // Set the geometry of the floating view
201 const struct wlc_geometry* geometry = wlc_view_get_geometry(handle); 201 const struct wlc_geometry* geometry = wlc_view_get_geometry(handle);
202 202
203 view->x = geometry->origin.x; 203 //give it requested geometry, but place in center
204 view->y = geometry->origin.y; 204 view->x = (active_workspace->width - geometry->size.w) / 2;
205 view->y = (active_workspace->height- geometry->size.h) / 2;
205 view->width = geometry->size.w; 206 view->width = geometry->size.w;
206 view->height = geometry->size.h; 207 view->height = geometry->size.h;
207 208
@@ -260,7 +261,6 @@ swayc_t *destroy_container(swayc_t *container) {
260 sway_log(L_DEBUG, "Container: Destroying container '%p'", container); 261 sway_log(L_DEBUG, "Container: Destroying container '%p'", container);
261 swayc_t *parent = container->parent; 262 swayc_t *parent = container->parent;
262 free_swayc(container); 263 free_swayc(container);
263
264 container = parent; 264 container = parent;
265 } 265 }
266 return container; 266 return container;
diff --git a/sway/focus.c b/sway/focus.c
index 1f17dfc9..7023d37d 100644
--- a/sway/focus.c
+++ b/sway/focus.c
@@ -146,6 +146,9 @@ void set_focused_container(swayc_t *c) {
146 // update container focus from here to root, making necessary changes along 146 // update container focus from here to root, making necessary changes along
147 // the way 147 // the way
148 swayc_t *p = c; 148 swayc_t *p = c;
149 if (p->type != C_OUTPUT && p->type != C_ROOT) {
150 p->is_focused = true;
151 }
149 while (p != &root_container) { 152 while (p != &root_container) {
150 update_focus(p); 153 update_focus(p);
151 p = p->parent; 154 p = p->parent;
@@ -168,8 +171,11 @@ void set_focused_container(swayc_t *c) {
168 } 171 }
169 // activate current focus 172 // activate current focus
170 if (p->type == C_VIEW) { 173 if (p->type == C_VIEW) {
171 wlc_view_focus(p->handle);
172 wlc_view_set_state(p->handle, WLC_BIT_ACTIVATED, true); 174 wlc_view_set_state(p->handle, WLC_BIT_ACTIVATED, true);
175 //set focus if view_focus is unlocked
176 if (!locked_view_focus) {
177 wlc_view_focus(p->handle);
178 }
173 } 179 }
174 } 180 }
175} 181}
diff --git a/sway/handlers.c b/sway/handlers.c
index e785e9c5..3ae33294 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -15,6 +15,7 @@
15#include "focus.h" 15#include "focus.h"
16 16
17uint32_t keys_pressed[32]; 17uint32_t keys_pressed[32];
18int keys_pressed_length = 0;
18 19
19static struct wlc_origin mouse_origin; 20static struct wlc_origin mouse_origin;
20 21
@@ -23,6 +24,15 @@ static bool dragging = false;
23static bool m2_held = false; 24static bool m2_held = false;
24static bool resizing = false; 25static bool resizing = false;
25 26
27static bool floating_mod_pressed(void) {
28 int i = 0;
29 while (i < keys_pressed_length) {
30 if (keys_pressed[i++] == config->floating_mod)
31 return true;
32 }
33 return false;
34}
35
26static bool pointer_test(swayc_t *view, void *_origin) { 36static bool pointer_test(swayc_t *view, void *_origin) {
27 const struct wlc_origin *origin = _origin; 37 const struct wlc_origin *origin = _origin;
28 // Determine the output that the view is under 38 // Determine the output that the view is under
@@ -139,35 +149,54 @@ static void handle_output_focused(wlc_handle output, bool focus) {
139} 149}
140 150
141static bool handle_view_created(wlc_handle handle) { 151static bool handle_view_created(wlc_handle handle) {
142 swayc_t *focused = get_focused_container(&root_container); 152 // if view is child of another view, the use that as focused container
153 wlc_handle parent = wlc_view_get_parent(handle);
154 swayc_t *focused = NULL;
143 swayc_t *newview = NULL; 155 swayc_t *newview = NULL;
156
157 // Get parent container, to add view in
158 if (parent) {
159 focused = get_swayc_for_handle(parent, &root_container);
160 }
161 if (!focused || focused->type == C_OUTPUT) {
162 focused = get_focused_container(&root_container);
163 }
164 sway_log(L_DEBUG, "creating view %ld with type %x, state %x, with parent %ld",
165 handle, wlc_view_get_type(handle), wlc_view_get_state(handle), parent);
166
167 // TODO properly figure out how each window should be handled.
144 switch (wlc_view_get_type(handle)) { 168 switch (wlc_view_get_type(handle)) {
145 // regular view created regularly 169 // regular view created regularly
146 case 0: 170 case 0:
147 newview = new_view(focused, handle); 171 newview = new_view(focused, handle);
148 wlc_view_set_state(handle, WLC_BIT_MAXIMIZED, true); 172 wlc_view_set_state(handle, WLC_BIT_MAXIMIZED, true);
149 break; 173 break;
150 // takes keyboard focus 174
175 // Dmenu keeps viewfocus, but others with this flag dont, for now simulate
176 // dmenu
151 case WLC_BIT_OVERRIDE_REDIRECT: 177 case WLC_BIT_OVERRIDE_REDIRECT:
152 sway_log(L_DEBUG, "view %ld with OVERRIDE_REDIRECT", handle); 178// locked_view_focus = true;
153 locked_view_focus = true;
154 wlc_view_focus(handle); 179 wlc_view_focus(handle);
155 wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); 180 wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true);
156 wlc_view_bring_to_front(handle); 181 wlc_view_bring_to_front(handle);
157 break; 182 break;
158 // Takes container focus 183
184 // Firefox popups have this flag set.
159 case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED: 185 case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED:
160 sway_log(L_DEBUG, "view %ld with OVERRIDE_REDIRECT|WLC_BIT_MANAGED", handle);
161 wlc_view_bring_to_front(handle); 186 wlc_view_bring_to_front(handle);
162 locked_container_focus = true; 187 locked_container_focus = true;
163 break; 188 break;
164 // set modals as floating containers 189
190 // Modals, get focus, popups do not
165 case WLC_BIT_MODAL: 191 case WLC_BIT_MODAL:
192 wlc_view_focus(handle);
166 wlc_view_bring_to_front(handle); 193 wlc_view_bring_to_front(handle);
167 newview = new_floating_view(handle); 194 newview = new_floating_view(handle);
168 case WLC_BIT_POPUP: 195 case WLC_BIT_POPUP:
196 wlc_view_bring_to_front(handle);
169 break; 197 break;
170 } 198 }
199
171 if (newview) { 200 if (newview) {
172 set_focused_container(newview); 201 set_focused_container(newview);
173 swayc_t *output = newview->parent; 202 swayc_t *output = newview->parent;
@@ -187,19 +216,19 @@ static void handle_view_destroyed(wlc_handle handle) {
187 // regular view created regularly 216 // regular view created regularly
188 case 0: 217 case 0:
189 case WLC_BIT_MODAL: 218 case WLC_BIT_MODAL:
219 case WLC_BIT_POPUP:
190 if (view) { 220 if (view) {
191 swayc_t *parent = destroy_view(view); 221 swayc_t *parent = destroy_view(view);
192 arrange_windows(parent, -1, -1); 222 arrange_windows(parent, -1, -1);
193 } 223 }
194 break; 224 break;
195 // takes keyboard focus 225 // DMENU has this flag, and takes view_focus, but other things with this
226 // flag dont
196 case WLC_BIT_OVERRIDE_REDIRECT: 227 case WLC_BIT_OVERRIDE_REDIRECT:
197 locked_view_focus = false; 228// locked_view_focus = false;
198 break; 229 break;
199 // Takes container focus
200 case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED: 230 case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED:
201 locked_container_focus = false; 231 locked_container_focus = false;
202 case WLC_BIT_POPUP:
203 break; 232 break;
204 } 233 }
205 set_focused_container(get_focused_view(&root_container)); 234 set_focused_container(get_focused_view(&root_container));
@@ -267,7 +296,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
267 if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) { 296 if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) {
268 return false; 297 return false;
269 } 298 }
270 static uint8_t head = 0;
271 bool cmd_success = false; 299 bool cmd_success = false;
272 300
273 struct sway_mode *mode = config->current_mode; 301 struct sway_mode *mode = config->current_mode;
@@ -276,13 +304,15 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
276 304
277 // Find key, if it has been pressed 305 // Find key, if it has been pressed
278 int mid = 0; 306 int mid = 0;
279 while (mid < head && keys_pressed[mid] != sym) { 307 while (mid < keys_pressed_length && keys_pressed[mid] != sym) {
280 ++mid; 308 ++mid;
281 } 309 }
282 if (state == WLC_KEY_STATE_PRESSED && mid == head && head + 1 < QSIZE) { 310 //Add or remove key depending on state
283 keys_pressed[head++] = sym; 311 if (state == WLC_KEY_STATE_PRESSED && mid == keys_pressed_length && keys_pressed_length + 1 < QSIZE) {
284 } else if (state == WLC_KEY_STATE_RELEASED && mid < head) { 312 keys_pressed[keys_pressed_length++] = sym;
285 memmove(keys_pressed + mid, keys_pressed + mid + 1, sizeof*keys_pressed * (--head - mid)); 313 } else if (state == WLC_KEY_STATE_RELEASED && mid < keys_pressed_length) {
314 memmove(keys_pressed + mid, keys_pressed + mid + 1, sizeof*keys_pressed * (--keys_pressed_length - mid));
315 keys_pressed[keys_pressed_length] = 0;
286 } 316 }
287 // TODO: reminder to check conflicts with mod+q+a versus mod+q 317 // TODO: reminder to check conflicts with mod+q+a versus mod+q
288 int i; 318 int i;
@@ -296,7 +326,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
296 match = false; 326 match = false;
297 xkb_keysym_t *key = binding->keys->items[j]; 327 xkb_keysym_t *key = binding->keys->items[j];
298 uint8_t k; 328 uint8_t k;
299 for (k = 0; k < head; ++k) { 329 for (k = 0; k < keys_pressed_length; ++k) {
300 if (keys_pressed[k] == *key) { 330 if (keys_pressed[k] == *key) {
301 match = true; 331 match = true;
302 break; 332 break;
@@ -312,8 +342,9 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
312 int j; 342 int j;
313 for (j = 0; j < binding->keys->length; ++j) { 343 for (j = 0; j < binding->keys->length; ++j) {
314 uint8_t k; 344 uint8_t k;
315 for (k = 0; k < head; ++k) { 345 for (k = 0; k < keys_pressed_length; ++k) {
316 memmove(keys_pressed + k, keys_pressed + k + 1, sizeof*keys_pressed * (--head - k)); 346 memmove(keys_pressed + k, keys_pressed + k + 1, sizeof*keys_pressed * (--keys_pressed_length - k));
347 keys_pressed[keys_pressed_length] = 0;
317 break; 348 break;
318 } 349 }
319 } 350 }
@@ -333,84 +364,67 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
333 static wlc_handle prev_handle = 0; 364 static wlc_handle prev_handle = 0;
334 mouse_origin = *origin; 365 mouse_origin = *origin;
335 bool changed_floating = false; 366 bool changed_floating = false;
336 int i = 0;
337 if (!active_workspace) { 367 if (!active_workspace) {
338 return false; 368 return false;
339 } 369 }
340 // Do checks to determine if proper keys are being held 370 // Do checks to determine if proper keys are being held
341 swayc_t *view = active_workspace->focused; 371 swayc_t *view = get_focused_view(active_workspace);
342 uint32_t edge = 0; 372 uint32_t edge = 0;
343 if (dragging && view) { 373 if (dragging && view && view->is_floating) {
344 if (view->is_floating) { 374 int dx = mouse_origin.x - prev_pos.x;
345 while (keys_pressed[i++]) { 375 int dy = mouse_origin.y - prev_pos.y;
346 if (keys_pressed[i] == config->floating_mod) { 376 view->x += dx;
347 int dx = mouse_origin.x - prev_pos.x; 377 view->y += dy;
348 int dy = mouse_origin.y - prev_pos.y; 378 changed_floating = true;
349 view->x += dx; 379 } else if (resizing && view && view->is_floating) {
350 view->y += dy; 380 int dx = mouse_origin.x - prev_pos.x;
351 changed_floating = true; 381 int dy = mouse_origin.y - prev_pos.y;
352 break; 382
353 } 383 // Move and resize the view based on the dx/dy and mouse position
384 int midway_x = view->x + view->width/2;
385 int midway_y = view->y + view->height/2;
386 if (dx < 0) {
387 changed_floating = true;
388 if (mouse_origin.x > midway_x) {
389 view->width += dx;
390 edge += WLC_RESIZE_EDGE_RIGHT;
391 } else {
392 view->x += dx;
393 view->width -= dx;
394 edge += WLC_RESIZE_EDGE_LEFT;
395 }
396 } else if (dx > 0){
397 changed_floating = true;
398 if (mouse_origin.x > midway_x) {
399 view->width += dx;
400 edge += WLC_RESIZE_EDGE_RIGHT;
401 } else {
402 view->x += dx;
403 view->width -= dx;
404 edge += WLC_RESIZE_EDGE_LEFT;
354 } 405 }
355 } 406 }
356 } else if (resizing && view) {
357 if (view->is_floating) {
358 while (keys_pressed[i++]) {
359 if (keys_pressed[i] == config->floating_mod) {
360 int dx = mouse_origin.x - prev_pos.x;
361 int dy = mouse_origin.y - prev_pos.y;
362
363 // Move and resize the view based on the dx/dy and mouse position
364 int midway_x = view->x + view->width/2;
365 int midway_y = view->y + view->height/2;
366
367
368 if (dx < 0) {
369 changed_floating = true;
370 if (mouse_origin.x > midway_x) {
371 view->width += dx;
372 edge += WLC_RESIZE_EDGE_RIGHT;
373 } else {
374 view->x += dx;
375 view->width -= dx;
376 edge += WLC_RESIZE_EDGE_LEFT;
377 }
378 } else if (dx > 0){
379 changed_floating = true;
380 if (mouse_origin.x > midway_x) {
381 view->width += dx;
382 edge += WLC_RESIZE_EDGE_RIGHT;
383 } else {
384 view->x += dx;
385 view->width -= dx;
386 edge += WLC_RESIZE_EDGE_LEFT;
387 }
388 }
389 407
390 if (dy < 0) { 408 if (dy < 0) {
391 changed_floating = true; 409 changed_floating = true;
392 if (mouse_origin.y > midway_y) { 410 if (mouse_origin.y > midway_y) {
393 view->height += dy; 411 view->height += dy;
394 edge += WLC_RESIZE_EDGE_BOTTOM; 412 edge += WLC_RESIZE_EDGE_BOTTOM;
395 } else { 413 } else {
396 view->y += dy; 414 view->y += dy;
397 view->height -= dy; 415 view->height -= dy;
398 edge += WLC_RESIZE_EDGE_TOP; 416 edge += WLC_RESIZE_EDGE_TOP;
399 } 417 }
400 } else if (dy > 0) { 418 } else if (dy > 0) {
401 changed_floating = true; 419 changed_floating = true;
402 if (mouse_origin.y > midway_y) { 420 if (mouse_origin.y > midway_y) {
403 view->height += dy; 421 view->height += dy;
404 edge += WLC_RESIZE_EDGE_BOTTOM; 422 edge += WLC_RESIZE_EDGE_BOTTOM;
405 } else { 423 } else {
406 edge = WLC_RESIZE_EDGE_BOTTOM; 424 edge = WLC_RESIZE_EDGE_BOTTOM;
407 view->y += dy; 425 view->y += dy;
408 view->height -= dy; 426 view->height -= dy;
409 edge += WLC_RESIZE_EDGE_TOP; 427 edge += WLC_RESIZE_EDGE_TOP;
410 }
411 }
412 break;
413 }
414 } 428 }
415 } 429 }
416 } 430 }
@@ -467,8 +481,12 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
467 } 481 }
468 } 482 }
469 arrange_windows(pointer->parent, -1, -1); 483 arrange_windows(pointer->parent, -1, -1);
470 dragging = m1_held; 484 if (floating_mod_pressed()) {
471 resizing = m2_held; 485 dragging = m1_held;
486 resizing = m2_held;
487 }
488 //Dont want pointer sent to window while dragging or resizing
489 return (dragging || resizing);
472 } 490 }
473 return (pointer && pointer != focused); 491 return (pointer && pointer != focused);
474 } else { 492 } else {
diff --git a/sway/layout.c b/sway/layout.c
index e2e12901..7125ffc3 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -38,6 +38,17 @@ void add_child(swayc_t *parent, swayc_t *child) {
38 } 38 }
39} 39}
40 40
41void add_floating(swayc_t *ws, swayc_t *child) {
42 sway_log(L_DEBUG, "Adding %p (%d, %dx%d) to %p (%d, %dx%d)", child, child->type,
43 child->width, child->height, ws, ws->type, ws->width, ws->height);
44 list_add(ws->floating, child);
45 child->parent = ws;
46 child->is_floating = true;
47 if (!ws->focused) {
48 ws->focused = child;
49 }
50}
51
41swayc_t *add_sibling(swayc_t *sibling, swayc_t *child) { 52swayc_t *add_sibling(swayc_t *sibling, swayc_t *child) {
42 swayc_t *parent = sibling->parent; 53 swayc_t *parent = sibling->parent;
43 int i = index_child(parent, sibling); 54 int i = index_child(parent, sibling);
@@ -76,6 +87,7 @@ swayc_t *remove_child(swayc_t *child) {
76 break; 87 break;
77 } 88 }
78 } 89 }
90 i = 0;
79 } else { 91 } else {
80 for (i = 0; i < parent->children->length; ++i) { 92 for (i = 0; i < parent->children->length; ++i) {
81 if (parent->children->items[i] == child) { 93 if (parent->children->items[i] == child) {
diff --git a/sway/log.c b/sway/log.c
index 5bd3c8dc..9b9a9dc0 100644
--- a/sway/log.c
+++ b/sway/log.c
@@ -82,3 +82,62 @@ bool sway_assert(bool condition, const char* format, ...) {
82 82
83 return false; 83 return false;
84} 84}
85
86#include "workspace.h"
87
88/* XXX:DEBUG:XXX */
89static void container_log(const swayc_t *c) {
90 fprintf(stderr, "focus:%c|",
91 c->is_focused ? 'F' : //Focused
92 c == active_workspace ? 'W' : //active workspace
93 c == &root_container ? 'R' : //root
94 'X');//not any others
95 fprintf(stderr,"(%p)",c);
96 fprintf(stderr,"(p:%p)",c->parent);
97 fprintf(stderr,"(f:%p)",c->focused);
98 fprintf(stderr,"(h:%ld)",c->handle);
99 fprintf(stderr,"Type:");
100 fprintf(stderr,
101 c->type == C_ROOT ? "Root|" :
102 c->type == C_OUTPUT ? "Output|" :
103 c->type == C_WORKSPACE ? "Workspace|" :
104 c->type == C_CONTAINER ? "Container|" :
105 c->type == C_VIEW ? "View|" : "Unknown|");
106 fprintf(stderr,"layout:");
107 fprintf(stderr,
108 c->layout == L_NONE ? "NONE|" :
109 c->layout == L_HORIZ ? "Horiz|":
110 c->layout == L_VERT ? "Vert|":
111 c->layout == L_STACKED ? "Stacked|":
112 c->layout == L_FLOATING ? "Floating|":
113 "Unknown|");
114 fprintf(stderr, "w:%d|h:%d|", c->width, c->height);
115 fprintf(stderr, "x:%d|y:%d|", c->x, c->y);
116 fprintf(stderr, "vis:%c|", c->visible?'t':'f');
117 fprintf(stderr, "wgt:%d|", c->weight);
118 fprintf(stderr, "name:%.16s|", c->name);
119 fprintf(stderr, "children:%d\n",c->children?c->children->length:0);
120}
121void layout_log(const swayc_t *c, int depth) {
122 int i, d;
123 int e = c->children ? c->children->length : 0;
124 container_log(c);
125 if (e) {
126 for (i = 0; i < e; ++i) {
127 fputc('|',stderr);
128 for (d = 0; d < depth; ++d) fputc('-', stderr);
129 layout_log(c->children->items[i], depth + 1);
130 }
131 }
132 if (c->type == C_WORKSPACE) {
133 e = c->floating?c->floating->length:0;
134 if (e) {
135 for (i = 0; i < e; ++i) {
136 fputc('|',stderr);
137 for (d = 0; d < depth; ++d) fputc('=', stderr);
138 layout_log(c->floating->items[i], depth + 1);
139 }
140 }
141 }
142}
143/* XXX:DEBUG:XXX */
diff --git a/sway/workspace.c b/sway/workspace.c
index 180c8a66..a690e3ae 100644
--- a/sway/workspace.c
+++ b/sway/workspace.c
@@ -187,60 +187,3 @@ void workspace_switch(swayc_t *workspace) {
187 set_focused_container(get_focused_view(workspace)); 187 set_focused_container(get_focused_view(workspace));
188 arrange_windows(workspace, -1, -1); 188 arrange_windows(workspace, -1, -1);
189} 189}
190
191/* XXX:DEBUG:XXX */
192static void container_log(const swayc_t *c) {
193 fprintf(stderr, "focus:%c|",
194 c->is_focused ? 'F' : //Focused
195 c == active_workspace ? 'W' : //active workspace
196 c == &root_container ? 'R' : //root
197 'X');//not any others
198 fprintf(stderr,"(%p)",c);
199 fprintf(stderr,"(p:%p)",c->parent);
200 fprintf(stderr,"(f:%p)",c->focused);
201 fprintf(stderr,"(h:%ld)",c->handle);
202 fprintf(stderr,"Type:");
203 fprintf(stderr,
204 c->type == C_ROOT ? "Root|" :
205 c->type == C_OUTPUT ? "Output|" :
206 c->type == C_WORKSPACE ? "Workspace|" :
207 c->type == C_CONTAINER ? "Container|" :
208 c->type == C_VIEW ? "View|" : "Unknown|");
209 fprintf(stderr,"layout:");
210 fprintf(stderr,
211 c->layout == L_NONE ? "NONE|" :
212 c->layout == L_HORIZ ? "Horiz|":
213 c->layout == L_VERT ? "Vert|":
214 c->layout == L_STACKED ? "Stacked|":
215 c->layout == L_FLOATING ? "Floating|":
216 "Unknown|");
217 fprintf(stderr, "w:%d|h:%d|", c->width, c->height);
218 fprintf(stderr, "x:%d|y:%d|", c->x, c->y);
219 fprintf(stderr, "vis:%c|", c->visible?'t':'f');
220 fprintf(stderr, "wgt:%d|", c->weight);
221 fprintf(stderr, "name:%.16s|", c->name);
222 fprintf(stderr, "children:%d\n",c->children?c->children->length:0);
223}
224void layout_log(const swayc_t *c, int depth) {
225 int i, d;
226 int e = c->children ? c->children->length : 0;
227 container_log(c);
228 if (e) {
229 for (i = 0; i < e; ++i) {
230 fputc('|',stderr);
231 for (d = 0; d < depth; ++d) fputc('-', stderr);
232 layout_log(c->children->items[i], depth + 1);
233 }
234 }
235 if (c->type == C_WORKSPACE) {
236 e = c->floating?c->floating->length:0;
237 if (e) {
238 for (i = 0; i < e; ++i) {
239 fputc('|',stderr);
240 for (d = 0; d < depth; ++d) fputc('-', stderr);
241 layout_log(c->floating->items[i], depth + 1);
242 }
243 }
244 }
245}
246/* XXX:DEBUG:XXX */